Node - Js Compiler

Download as pdf or txt
Download as pdf or txt
You are on page 1of 82

Node.

js Compiler
Minqi Pan
I’m Minqi Pan
one of Node.js Collaborators
before Node.js Compiler
Slow Installation
• “npm install fengdie” took 2m12.560s

• Great-Wall’ed in China

• Remembered to use npm -g with sudo?


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

• “or should I not?”


Node.js Runtime?
• Making sure your user used the correct Node.js

• Could multiple Node.js versions co-exist?

• Wish to use ECMAScript 2017?


after Node.js Compiler
How to Compile
How it Works
Introducing
/__enclose_io_memfs__

a “mounted” disk in RAM for your project


Basic Idea

System calls on paths starting with



/__enclose_io_memfs__

are redirected to the RAM while others to the FS
/__enclose_io_memfs__/… others

Image Curtesy: Evan-Amos


But there are so many API’s

• require, require.resolve

• fs.readFile, fs.readFileSync, fs.ReadStream

• fs.readlink, fs.stat, fs.statSync, fs.readlinkSync

• …
Yet we did this in 8 files only
That’s because…

Node.js Compiler
https://github.com/pmq20/node-compiler

libsquash
https://github.com/pmq20/libsquash
Introducing SquashFS
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
fengdie’s

node_modules/
148M

fengdie.squashfs
16M
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


Introducing libsquash
libsquash
• MIT licensed
libsquash • Super embeddable
https://github.com/pmq20/libsquash
• 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
API of libsuqash
mirroring system calls
Virtual File Descriptor
generated by a duplicating file descriptor 0
Use libsquash unobtrusively
Just include a header and it’s done!
Use libsquash unobtrusively
Win32 API works as well
Hard-code an Entrance
node ~/fengdie/bin/cli.js

./fengdie

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


fengdie/*
mksquashfs

fengdie.squashfs

fengdie/*
fengdie.squashfs

fengdie/* libsquash compile


fengdie.squashfs

fengdie/* libsquash

Node.js Runtime compile


fengdie.squashfs

fengdie/* libsquash

Node.js Runtime
fengdie.squashfs

fengdie/* libsquash

Node.js Runtime
Statically Link

fengdie.squashfs

fengdie/* libsquash fengdie.exe

Node.js Runtime

Statically Link
Statically Link

fengdie.squashfs

fengdie/* libsquash fengdie.exe

Node.js Runtime

Statically Link
Distribute and Enjoy

fengdie.exe
Download & Install
nodec is also enclosed
Operating Download Link
Architecture
System

https://sourceforge.net/projects/
Windows x86 node-compiler/files/v0.9.4/
nodec.exe/download
https://sourceforge.net/projects/
macOS x86-64 node-compiler/files/v0.9.4/nodec-
darwin-x64/download
https://sourceforge.net/projects/
Linux x86-64 node-compiler/files/v0.9.4/nodec-
linux-x64/download
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.
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


Install on macOS

• curl -L https://sourceforge.net/projects/node-
compiler/files/v0.9.4/nodec-darwin-x64/
download > nodec

• chmod +x nodec

• ./nodec
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


Install on Linux

• curl -L https://sourceforge.net/projects/node-
compiler/files/v0.9.4/nodec-linux-x64/download
> nodec

• chmod +x nodec

• ./nodec
Licensing
Commercial-license-free
Proprietary-license-free
GPL-free
Super Redistributable

libsquash MIT

Node.js MIT

libuv MIT

v8 BSD
Super Redistributable

zlib zlib License

Apache

openssl
4-clause BSD

HTTP Parser MIT

c-ares MIT
Applications
Quicker Install / Upgrade

• Quicker upgrading embedded node.js


applications / plugins

• Quicker upgrading embedded node.js


applications / plugins

• E.g. fengdie inside the Tea IDE


Enabling Node.js Developers

• Build softwares instead of modules

• Distribute to non-technical users

• Merchandise by building personal / enterprise


softwares
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)
Tips
Use --tmpdir=/a/fixed/location
Use CentOS release 5.8

with gcc and g++ 4.8

(possibly from devtoolset-2 of slc5-devtoolset)
Use Windows

with a big Virtual Memory
Check dependencies using
Dependency Walker, otool, ldd

before releasing
https://github.com/pmq20/node-compiler

Thank You

You might also like