Slide 1

Slide 1 text

Node.js Compiler Minqi Pan

Slide 2

Slide 2 text

I’m Minqi Pan one of Node.js Collaborators

Slide 3

Slide 3 text

before Node.js Compiler

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Slow Installation • “npm install fengdie” took 2m12.560s • Great-Wall’ed in China • Remembered to use npm -g with sudo?

Slide 7

Slide 7 text

Too much complexities • “Should I care about those WARN’s?” • “or should I not?”

Slide 8

Slide 8 text

Node.js Runtime? • Making sure your user used the correct Node.js • Could multiple Node.js versions co-exist? • Wish to use ECMAScript 2017?

Slide 9

Slide 9 text

after Node.js Compiler

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

How to Compile

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

How it Works

Slide 29

Slide 29 text

Introducing /__enclose_io_memfs__ a “mounted” disk in RAM for your project

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

Basic Idea System calls on paths starting with
 /__enclose_io_memfs__
 are redirected to the RAM while others to the FS

Slide 32

Slide 32 text

/__enclose_io_memfs__/… others Image Curtesy: Evan-Amos

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

But there are so many API’s • require, require.resolve • fs.readFile, fs.readFileSync, fs.ReadStream • fs.readlink, fs.stat, fs.statSync, fs.readlinkSync • …

Slide 37

Slide 37 text

Yet we did this in 8 files only

Slide 38

Slide 38 text

That’s because… https://github.com/pmq20/libsquash libsquash https://github.com/pmq20/node-compiler Node.js Compiler

Slide 39

Slide 39 text

Introducing SquashFS

Slide 40

Slide 40 text

SquashFS • a compressed read-only file system • used by the Live CD versions of Arch Linux, Debian, Fedora, Gentoo, Mint, Salix, Ubuntu • used on OpenWrt and DD-WRT router firmware

Slide 41

Slide 41 text

fengdie’s
 node_modules/ 148M fengdie.squashfs 16M

Slide 42

Slide 42 text

SquashFS • Introduced in 2009 with Linux 2.6.29 • File format very stabilized • Unsquashfs and mksquashfs have win32 ports; 7-Zip on win32 also supports SquashFS • Part of kernel; GPL Licensed

Slide 43

Slide 43 text

Introducing libsquash

Slide 44

Slide 44 text

https://github.com/pmq20/libsquash libsquash • MIT licensed • Super embeddable • 1 dependency only, which could be statically linked • Compiles on 3 platforms, even Windows XP with VC++ 2010 • Introduces VFD - virtual file descriptor, intercepting system calls unobtrusively libsquash

Slide 45

Slide 45 text

API of libsuqash mirroring system calls

Slide 46

Slide 46 text

Virtual File Descriptor generated by a duplicating file descriptor 0

Slide 47

Slide 47 text

Use libsquash unobtrusively Just include a header and it’s done!

Slide 48

Slide 48 text

Use libsquash unobtrusively Win32 API works as well

Slide 49

Slide 49 text

Hard-code an Entrance

Slide 50

Slide 50 text

node ~/fengdie/bin/cli.js (argv[1] preset to /__enclose_io_memfs__/bin/cli.js) ./fengdie

Slide 51

Slide 51 text

fengdie/*

Slide 52

Slide 52 text

fengdie/* fengdie.squashfs mksquashfs

Slide 53

Slide 53 text

fengdie/* fengdie.squashfs libsquash compile

Slide 54

Slide 54 text

fengdie/* fengdie.squashfs libsquash Node.js Runtime compile

Slide 55

Slide 55 text

fengdie/* fengdie.squashfs libsquash Node.js Runtime

Slide 56

Slide 56 text

fengdie/* fengdie.squashfs libsquash Node.js Runtime

Slide 57

Slide 57 text

fengdie/* fengdie.squashfs libsquash Node.js Runtime fengdie.exe Statically Link Statically Link

Slide 58

Slide 58 text

fengdie/* fengdie.squashfs libsquash Node.js Runtime fengdie.exe Statically Link Statically Link

Slide 59

Slide 59 text

fengdie.exe Distribute and Enjoy

Slide 60

Slide 60 text

Download & Install

Slide 61

Slide 61 text

nodec is also enclosed Operating System Architecture Download Link Windows x86 https://sourceforge.net/projects/ node-compiler/files/v0.9.4/ nodec.exe/download macOS x86-64 https://sourceforge.net/projects/ node-compiler/files/v0.9.4/nodec- darwin-x64/download Linux x86-64 https://sourceforge.net/projects/ node-compiler/files/v0.9.4/nodec- linux-x64/download

Slide 62

Slide 62 text

Install on Windows • SquashFS Tools 4.3 • Python 2.6 or 2.7 • Visual Studio 2015 Update 3, all editions including the Community edition (remember to select "Common Tools for Visual C++ 2015" feature during installation). • Then download the executable nodec.exe and run it from the VC++ or VS Command Prompt.

Slide 63

Slide 63 text

Install on macOS • SquashFS Tools 4.3: brew install squashfs • Xcode + Command Line Tools • Python 2.6 or 2.7 • GNU Make 3.81 or newer

Slide 64

Slide 64 text

Install on macOS • curl -L https://sourceforge.net/projects/node- compiler/files/v0.9.4/nodec-darwin-x64/ download > nodec • chmod +x nodec • ./nodec

Slide 65

Slide 65 text

Install on Linux • SquashFS Tools 4.3 • gcc and g++ 4.8 or newer, or • clang and clang++ 3.4 or newer • Python 2.6 or 2.7 • GNU Make 3.81 or newer

Slide 66

Slide 66 text

Install on Linux • curl -L https://sourceforge.net/projects/node- compiler/files/v0.9.4/nodec-linux-x64/download > nodec • chmod +x nodec • ./nodec

Slide 67

Slide 67 text

Licensing

Slide 68

Slide 68 text

Commercial-license-free

Slide 69

Slide 69 text

Proprietary-license-free

Slide 70

Slide 70 text

GPL-free

Slide 71

Slide 71 text

Super Redistributable libsquash MIT Node.js MIT libuv MIT v8 BSD

Slide 72

Slide 72 text

Super Redistributable zlib zlib License openssl Apache
 4-clause BSD HTTP Parser MIT c-ares MIT

Slide 73

Slide 73 text

Applications

Slide 74

Slide 74 text

Quicker Install / Upgrade • Quicker upgrading embedded node.js applications / plugins • Quicker upgrading embedded node.js applications / plugins • E.g. fengdie inside the Tea IDE

Slide 75

Slide 75 text

Enabling Node.js Developers • Build softwares instead of modules • Distribute to non-technical users • Merchandise by building personal / enterprise softwares

Slide 76

Slide 76 text

Code Protection • Enable code signing for the entire application; guarantee not being altered or corrupted • Prevent hacking by users modifying exposed Javascript source code • Applicable to NW.js applications (DingTalk) and Electron applications (Tea)

Slide 77

Slide 77 text

Tips

Slide 78

Slide 78 text

Use --tmpdir=/a/fixed/location

Slide 79

Slide 79 text

Use CentOS release 5.8
 with gcc and g++ 4.8
 (possibly from devtoolset-2 of slc5-devtoolset)

Slide 80

Slide 80 text

Use Windows
 with a big Virtual Memory

Slide 81

Slide 81 text

Check dependencies using Dependency Walker, otool, ldd
 before releasing

Slide 82

Slide 82 text

https://github.com/pmq20/node-compiler Thank You