@yao-pkg/pkg 5.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +433 -0
- package/dictionary/angular-bridge.js +3 -0
- package/dictionary/any-promise.js +3 -0
- package/dictionary/async.js +3 -0
- package/dictionary/aws-sdk.js +7 -0
- package/dictionary/babel-core.js +3 -0
- package/dictionary/batch.js +3 -0
- package/dictionary/bcrypt.js +3 -0
- package/dictionary/better-sqlite3.js +3 -0
- package/dictionary/bignum.js +3 -0
- package/dictionary/bindings.js +3 -0
- package/dictionary/blessed.js +8 -0
- package/dictionary/body-parser.js +9 -0
- package/dictionary/browserify.js +7 -0
- package/dictionary/bson.js +3 -0
- package/dictionary/buffermaker.js +7 -0
- package/dictionary/bunyan.js +9 -0
- package/dictionary/busboy.js +7 -0
- package/dictionary/bytes.js +3 -0
- package/dictionary/callsites.js +3 -0
- package/dictionary/chokidar.js +3 -0
- package/dictionary/coffee-script.js +7 -0
- package/dictionary/colors.js +3 -0
- package/dictionary/compression.js +3 -0
- package/dictionary/compressjs.js +7 -0
- package/dictionary/connect-mongo.js +3 -0
- package/dictionary/connect-mongodb.js +3 -0
- package/dictionary/connect-redis.js +3 -0
- package/dictionary/connect.js +10 -0
- package/dictionary/consolidate.js +3 -0
- package/dictionary/cookie-parser.js +3 -0
- package/dictionary/cookie.js +3 -0
- package/dictionary/cors.js +3 -0
- package/dictionary/cron.js +3 -0
- package/dictionary/cross-env.js +11 -0
- package/dictionary/cross-spawn-async.js +3 -0
- package/dictionary/curve25519.js +3 -0
- package/dictionary/data-preflight.js +7 -0
- package/dictionary/debug.js +3 -0
- package/dictionary/denymount.js +3 -0
- package/dictionary/diff.js +3 -0
- package/dictionary/drivelist.js +22 -0
- package/dictionary/ed25519.js +3 -0
- package/dictionary/ejs.js +3 -0
- package/dictionary/elasticsearch.js +3 -0
- package/dictionary/electron.js +17 -0
- package/dictionary/emailjs.js +3 -0
- package/dictionary/engine.io.js +3 -0
- package/dictionary/epoll.js +3 -0
- package/dictionary/errorhandler.js +7 -0
- package/dictionary/errors.js +7 -0
- package/dictionary/eslint.js +7 -0
- package/dictionary/etcher-image-write.js +3 -0
- package/dictionary/exceljs.js +21 -0
- package/dictionary/exiftool.exe.js +13 -0
- package/dictionary/exiftool.pl.js +13 -0
- package/dictionary/express-load.js +12 -0
- package/dictionary/express-session.js +3 -0
- package/dictionary/express.js +14 -0
- package/dictionary/extender.js +11 -0
- package/dictionary/extsprintf.js +3 -0
- package/dictionary/faye-websocket.js +3 -0
- package/dictionary/feathers.js +3 -0
- package/dictionary/findup-sync.js +3 -0
- package/dictionary/floordate.js +3 -0
- package/dictionary/fmt.js +3 -0
- package/dictionary/formidable.js +3 -0
- package/dictionary/fs-extra.js +3 -0
- package/dictionary/fsevents.js +3 -0
- package/dictionary/geoip-lite.js +7 -0
- package/dictionary/github.js +7 -0
- package/dictionary/gm.js +3 -0
- package/dictionary/google-closure-compiler-java.js +13 -0
- package/dictionary/google-closure-compiler.js +13 -0
- package/dictionary/googleapis.js +7 -0
- package/dictionary/got.js +3 -0
- package/dictionary/graceful-fs.js +19 -0
- package/dictionary/grpc.js +11 -0
- package/dictionary/gulp.js +3 -0
- package/dictionary/hap-nodejs.js +3 -0
- package/dictionary/heapdump.js +3 -0
- package/dictionary/hoek.js +3 -0
- package/dictionary/homebridge.js +3 -0
- package/dictionary/http-proxy.js +3 -0
- package/dictionary/http-server.js +3 -0
- package/dictionary/image-size.js +3 -0
- package/dictionary/indexof.js +3 -0
- package/dictionary/inquirer.js +3 -0
- package/dictionary/j.js +16 -0
- package/dictionary/jade.js +3 -0
- package/dictionary/jsdom.js +3 -0
- package/dictionary/json-stringify-date.js +3 -0
- package/dictionary/json-stringify-safe.js +3 -0
- package/dictionary/jsonwebtoken.js +3 -0
- package/dictionary/kerberos.js +3 -0
- package/dictionary/knex.js +7 -0
- package/dictionary/later.js +7 -0
- package/dictionary/level.js +3 -0
- package/dictionary/leveldown.js +10 -0
- package/dictionary/levelup.js +3 -0
- package/dictionary/liftoff.js +12 -0
- package/dictionary/lodash.js +3 -0
- package/dictionary/log4js.js +7 -0
- package/dictionary/logform.js +7 -0
- package/dictionary/machinepack-urls.js +7 -0
- package/dictionary/markdown.js +3 -0
- package/dictionary/mdns.js +6 -0
- package/dictionary/method-override.js +3 -0
- package/dictionary/microjob.js +16 -0
- package/dictionary/mime-types.js +3 -0
- package/dictionary/mime.js +3 -0
- package/dictionary/minimatch.js +3 -0
- package/dictionary/minstache.js +3 -0
- package/dictionary/module-deps.js +3 -0
- package/dictionary/moment-timezone.js +3 -0
- package/dictionary/moment.js +7 -0
- package/dictionary/mongodb-core.js +22 -0
- package/dictionary/mongodb.js +7 -0
- package/dictionary/mongoose.js +7 -0
- package/dictionary/mongoskin.js +7 -0
- package/dictionary/ms.js +3 -0
- package/dictionary/msgpack.js +3 -0
- package/dictionary/multer.js +3 -0
- package/dictionary/muri.js +3 -0
- package/dictionary/native-or-bluebird.js +3 -0
- package/dictionary/natives.js +3 -0
- package/dictionary/nconf.js +7 -0
- package/dictionary/nedb.js +3 -0
- package/dictionary/negotiator.js +7 -0
- package/dictionary/newrelic.js +3 -0
- package/dictionary/nib.js +3 -0
- package/dictionary/nightmare.js +18 -0
- package/dictionary/node-forge.js +7 -0
- package/dictionary/node-libcurl.js +3 -0
- package/dictionary/node-notifier.js +30 -0
- package/dictionary/node-pre-gyp.js +7 -0
- package/dictionary/node-redis-pubsub.js +3 -0
- package/dictionary/node-sass.js +3 -0
- package/dictionary/node-uuid.js +3 -0
- package/dictionary/node-xlsx.js +3 -0
- package/dictionary/node-zookeeper-client.js +7 -0
- package/dictionary/nodegit.js +7 -0
- package/dictionary/nodemailer-sendmail-transport.js +3 -0
- package/dictionary/nodemailer.js +3 -0
- package/dictionary/npm-registry-client.js +7 -0
- package/dictionary/npm.js +7 -0
- package/dictionary/nssocket.js +3 -0
- package/dictionary/oauth2orize.js +7 -0
- package/dictionary/octobat.js +3 -0
- package/dictionary/open.js +13 -0
- package/dictionary/opn.js +4 -0
- package/dictionary/optimist.js +3 -0
- package/dictionary/passport-local.js +3 -0
- package/dictionary/passport.js +3 -0
- package/dictionary/pg-cursor.js +3 -0
- package/dictionary/pg-query-stream.js +3 -0
- package/dictionary/pg-types.js +7 -0
- package/dictionary/pg.js +7 -0
- package/dictionary/pg.js.js +7 -0
- package/dictionary/pgpass.js +7 -0
- package/dictionary/phantom.js +19 -0
- package/dictionary/phantomjs-prebuilt.js +16 -0
- package/dictionary/pkginfo.js +3 -0
- package/dictionary/pm2.js +7 -0
- package/dictionary/pmx.js +3 -0
- package/dictionary/pouchdb.js +3 -0
- package/dictionary/primus-emitter.js +3 -0
- package/dictionary/primus-spark-latency.js +3 -0
- package/dictionary/primus.js +3 -0
- package/dictionary/publicsuffixlist.js +15 -0
- package/dictionary/pug.js +3 -0
- package/dictionary/punt.js +3 -0
- package/dictionary/puppeteer.js +13 -0
- package/dictionary/pwd.js +3 -0
- package/dictionary/q.js +3 -0
- package/dictionary/raven.js +3 -0
- package/dictionary/rc.js +12 -0
- package/dictionary/readable-stream.js +3 -0
- package/dictionary/rechoir.js +3 -0
- package/dictionary/redis-parser.js +3 -0
- package/dictionary/redis.js +3 -0
- package/dictionary/regression.js +3 -0
- package/dictionary/reload.js +7 -0
- package/dictionary/request.js +3 -0
- package/dictionary/require-uncached.js +3 -0
- package/dictionary/require_optional.js +3 -0
- package/dictionary/s3.js +3 -0
- package/dictionary/safe_datejs.js +3 -0
- package/dictionary/sails.js +33 -0
- package/dictionary/sax.js +3 -0
- package/dictionary/scrypt.js +3 -0
- package/dictionary/semver.js +3 -0
- package/dictionary/sequelize.js +7 -0
- package/dictionary/serialport.js +3 -0
- package/dictionary/sha3.js +3 -0
- package/dictionary/sharp.js +11 -0
- package/dictionary/shelljs.js +7 -0
- package/dictionary/sinon.js +3 -0
- package/dictionary/socket.io-client.js +13 -0
- package/dictionary/socket.io.js +12 -0
- package/dictionary/sqip.js +7 -0
- package/dictionary/sqlite3.js +3 -0
- package/dictionary/steam-crypto.js +7 -0
- package/dictionary/steam-resources.js +19 -0
- package/dictionary/steam.js +3 -0
- package/dictionary/stripe-webhook-middleware.js +3 -0
- package/dictionary/stripe.js +3 -0
- package/dictionary/strong-globalize.js +3 -0
- package/dictionary/stylus.js +14 -0
- package/dictionary/supervisor.js +3 -0
- package/dictionary/svgo.js +8 -0
- package/dictionary/tabtab.js +3 -0
- package/dictionary/tesseract.js.js +7 -0
- package/dictionary/throng.js +3 -0
- package/dictionary/time.js +3 -0
- package/dictionary/tinify.js +7 -0
- package/dictionary/tiny-worker.js +7 -0
- package/dictionary/tmp.js +3 -0
- package/dictionary/transformers.js +3 -0
- package/dictionary/uglify-js.js +9 -0
- package/dictionary/umd.js +19 -0
- package/dictionary/underscore.js +3 -0
- package/dictionary/union.js +3 -0
- package/dictionary/update-notifier.js +3 -0
- package/dictionary/usage.js +7 -0
- package/dictionary/v8flags.js +13 -0
- package/dictionary/verror.js +3 -0
- package/dictionary/voc.js +3 -0
- package/dictionary/webdriverio.js +7 -0
- package/dictionary/winston-uber.js +7 -0
- package/dictionary/winston.js +7 -0
- package/dictionary/ws.js +3 -0
- package/dictionary/xlsx.js +16 -0
- package/dictionary/xml2js.js +3 -0
- package/dictionary/yargs.js +3 -0
- package/dictionary/zeromq.js +13 -0
- package/lib-es5/bin.js +19 -0
- package/lib-es5/chmod.js +15 -0
- package/lib-es5/common.js +235 -0
- package/lib-es5/compress_type.js +10 -0
- package/lib-es5/detector.js +420 -0
- package/lib-es5/fabricator.js +141 -0
- package/lib-es5/follow.js +91 -0
- package/lib-es5/help.js +53 -0
- package/lib-es5/index.d.ts +2 -0
- package/lib-es5/index.js +541 -0
- package/lib-es5/log.js +7 -0
- package/lib-es5/mach-o.js +61 -0
- package/lib-es5/packer.js +131 -0
- package/lib-es5/producer.js +343 -0
- package/lib-es5/refiner.js +87 -0
- package/lib-es5/types.js +9 -0
- package/lib-es5/walker.js +853 -0
- package/package.json +143 -0
- package/prelude/bootstrap.js +2256 -0
- package/prelude/diagnostic.js +136 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Vercel, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
**Disclaimer: `pkg` was created for use within containers and is not intended for use in serverless environments. For those using Vercel, this means that there is no requirement to use `pkg` in your projects as the benefits it provides are not applicable to the platform.**
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
[](https://github.com/yao-pkg/pkg/actions/workflows/ci.yml)
|
|
6
|
+
|
|
7
|
+
This command line interface enables you to package your Node.js project into an executable that can be run even on devices without Node.js installed.
|
|
8
|
+
|
|
9
|
+
## Use Cases
|
|
10
|
+
|
|
11
|
+
- Make a commercial version of your application without sources
|
|
12
|
+
- Make a demo/evaluation/trial version of your app without sources
|
|
13
|
+
- Instantly make executables for other platforms (cross-compilation)
|
|
14
|
+
- Make some kind of self-extracting archive or installer
|
|
15
|
+
- No need to install Node.js and npm to run the packaged application
|
|
16
|
+
- No need to download hundreds of files via `npm install` to deploy
|
|
17
|
+
your application. Deploy it as a single file
|
|
18
|
+
- Put your assets inside the executable to make it even more portable
|
|
19
|
+
- Test your app against new Node.js version without installing it
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npm install -g @yao-pkg/pkg
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
After installing it, run `pkg --help` without arguments to see list of options:
|
|
28
|
+
|
|
29
|
+
```console
|
|
30
|
+
pkg [options] <input>
|
|
31
|
+
|
|
32
|
+
Options:
|
|
33
|
+
|
|
34
|
+
-h, --help output usage information
|
|
35
|
+
-v, --version output pkg version
|
|
36
|
+
-t, --targets comma-separated list of targets (see examples)
|
|
37
|
+
-c, --config package.json or any json file with top-level config
|
|
38
|
+
--options bake v8 options into executable to run with them on
|
|
39
|
+
-o, --output output file name or template for several files
|
|
40
|
+
--out-path path to save output one or more executables
|
|
41
|
+
-d, --debug show more information during packaging process [off]
|
|
42
|
+
-b, --build don't download prebuilt base binaries, build them
|
|
43
|
+
--public speed up and disclose the sources of top-level project
|
|
44
|
+
--public-packages force specified packages to be considered public
|
|
45
|
+
--no-bytecode skip bytecode generation and include source files as plain js
|
|
46
|
+
--no-native-build skip native addons build
|
|
47
|
+
--no-signature skip signature of the final executable on macos
|
|
48
|
+
--no-dict comma-separated list of packages names to ignore dictionaries. Use --no-dict * to disable all dictionaries
|
|
49
|
+
-C, --compress [default=None] compression algorithm = Brotli or GZip
|
|
50
|
+
|
|
51
|
+
Examples:
|
|
52
|
+
|
|
53
|
+
– Makes executables for Linux, macOS and Windows
|
|
54
|
+
$ pkg index.js
|
|
55
|
+
– Takes package.json from cwd and follows 'bin' entry
|
|
56
|
+
$ pkg .
|
|
57
|
+
– Makes executable for particular target machine
|
|
58
|
+
$ pkg -t node16-win-arm64 index.js
|
|
59
|
+
– Makes executables for target machines of your choice
|
|
60
|
+
$ pkg -t node16-linux,node18-linux,node16-win index.js
|
|
61
|
+
– Bakes '--expose-gc' and '--max-heap-size=34' into executable
|
|
62
|
+
$ pkg --options "expose-gc,max-heap-size=34" index.js
|
|
63
|
+
– Consider packageA and packageB to be public
|
|
64
|
+
$ pkg --public-packages "packageA,packageB" index.js
|
|
65
|
+
– Consider all packages to be public
|
|
66
|
+
$ pkg --public-packages "*" index.js
|
|
67
|
+
– Bakes '--expose-gc' into executable
|
|
68
|
+
$ pkg --options expose-gc index.js
|
|
69
|
+
– reduce size of the data packed inside the executable with GZip
|
|
70
|
+
$ pkg --compress GZip index.js
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The entrypoint of your project is a mandatory CLI argument. It may be:
|
|
74
|
+
|
|
75
|
+
- Path to entry file. Suppose it is `/path/app.js`, then
|
|
76
|
+
packaged app will work the same way as `node /path/app.js`
|
|
77
|
+
- Path to `package.json`. `Pkg` will follow `bin` property of
|
|
78
|
+
the specified `package.json` and use it as entry file.
|
|
79
|
+
- Path to directory. `Pkg` will look for `package.json` in
|
|
80
|
+
the specified directory. See above.
|
|
81
|
+
|
|
82
|
+
### Targets
|
|
83
|
+
|
|
84
|
+
`pkg` can generate executables for several target machines at a
|
|
85
|
+
time. You can specify a comma-separated list of targets via `--targets`
|
|
86
|
+
option. A canonical target consists of 3 elements, separated by
|
|
87
|
+
dashes, for example `node18-macos-x64` or `node14-linux-arm64`:
|
|
88
|
+
|
|
89
|
+
- **nodeRange** (node8), node10, node12, node14, node16 or latest
|
|
90
|
+
- **platform** alpine, linux, linuxstatic, win, macos, (freebsd)
|
|
91
|
+
- **arch** x64, arm64, (armv6, armv7)
|
|
92
|
+
|
|
93
|
+
(element) is unsupported, but you may try to compile yourself.
|
|
94
|
+
|
|
95
|
+
You may omit any element (and specify just `node14` for example).
|
|
96
|
+
The omitted elements will be taken from current platform or
|
|
97
|
+
system-wide Node.js installation (its version and arch).
|
|
98
|
+
There is also an alias `host`, that means that all 3 elements
|
|
99
|
+
are taken from current platform/Node.js. By default targets are
|
|
100
|
+
`linux,macos,win` for current Node.js version and arch.
|
|
101
|
+
|
|
102
|
+
If you want to generate executable for different architectures,
|
|
103
|
+
note that by default `pkg` has to run the executable of the
|
|
104
|
+
**target** arch to generate bytecodes:
|
|
105
|
+
|
|
106
|
+
- Linux: configure binfmt with [QEMU](https://wiki.debian.org/QemuUserEmulation).
|
|
107
|
+
- macOS: possible to build `x64` on `arm64` with `Rosetta 2` but not opposite.
|
|
108
|
+
- Windows: possible to build `x64` on `arm64` with `x64 emulation` but not opposite.
|
|
109
|
+
- or, disable bytecode generation with `--no-bytecode --public-packages "*" --public`.
|
|
110
|
+
|
|
111
|
+
`macos-arm64` is experimental. Be careful about the [mandatory code signing requirement](https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11_0_1-universal-apps-release-notes).
|
|
112
|
+
The final executable has to be signed (ad-hoc signature is sufficient) with `codesign`
|
|
113
|
+
utility of macOS (or `ldid` utility on Linux). Otherwise, the executable will be killed
|
|
114
|
+
by kernel and the end-user has no way to permit it to run at all. `pkg` tries to ad-hoc
|
|
115
|
+
sign the final executable. If necessary, you can replace this signature with your own
|
|
116
|
+
trusted Apple Developer ID.
|
|
117
|
+
|
|
118
|
+
To be able to generate executables for all supported architectures and platforms, run
|
|
119
|
+
`pkg` on a Linux host with binfmt (`QEMU` emulation) configured and `ldid` installed.
|
|
120
|
+
|
|
121
|
+
### Config
|
|
122
|
+
|
|
123
|
+
During packaging process `pkg` parses your sources, detects
|
|
124
|
+
calls to `require`, traverses the dependencies of your project
|
|
125
|
+
and includes them into executable. In most cases you
|
|
126
|
+
don't need to specify anything manually.
|
|
127
|
+
|
|
128
|
+
However your code may have `require(variable)` calls (so called non-literal
|
|
129
|
+
argument to `require`) or use non-javascript files (for
|
|
130
|
+
example views, css, images etc).
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
require('./build/' + cmd + '.js');
|
|
134
|
+
path.join(__dirname, 'views/' + viewName);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Such cases are not handled by `pkg`. So you must specify the
|
|
138
|
+
files - scripts and assets - manually in `pkg` property of
|
|
139
|
+
your `package.json` file.
|
|
140
|
+
|
|
141
|
+
```json
|
|
142
|
+
"pkg": {
|
|
143
|
+
"scripts": "build/**/*.js",
|
|
144
|
+
"assets": "views/**/*",
|
|
145
|
+
"targets": [ "node14-linux-arm64" ],
|
|
146
|
+
"outputPath": "dist"
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The above example will include everything in `assets/` and
|
|
151
|
+
every .js file in `build/`, build only for `node14-linux-arm64`,
|
|
152
|
+
and place the executable inside `dist/`.
|
|
153
|
+
|
|
154
|
+
You may also specify arrays of globs:
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
"assets": [ "assets/**/*", "images/**/*" ]
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Just be sure to call `pkg package.json` or `pkg .` to make
|
|
161
|
+
use of `package.json` configuration.
|
|
162
|
+
|
|
163
|
+
### Scripts
|
|
164
|
+
|
|
165
|
+
`scripts` is a [glob](https://github.com/sindresorhus/globby)
|
|
166
|
+
or list of globs. Files specified as `scripts` will be compiled
|
|
167
|
+
using `v8::ScriptCompiler` and placed into executable without
|
|
168
|
+
sources. They must conform to the JS standards of those Node.js versions
|
|
169
|
+
you target (see [Targets](#targets)), i.e. be already transpiled.
|
|
170
|
+
|
|
171
|
+
### Assets
|
|
172
|
+
|
|
173
|
+
`assets` is a [glob](https://github.com/sindresorhus/globby)
|
|
174
|
+
or list of globs. Files specified as `assets` will be packaged
|
|
175
|
+
into executable as raw content without modifications. Javascript
|
|
176
|
+
files may also be specified as `assets`. Their sources will
|
|
177
|
+
not be stripped as it improves execution performance of the
|
|
178
|
+
files and simplifies debugging.
|
|
179
|
+
|
|
180
|
+
See also
|
|
181
|
+
[Detecting assets in source code](#detecting-assets-in-source-code) and
|
|
182
|
+
[Snapshot filesystem](#snapshot-filesystem).
|
|
183
|
+
|
|
184
|
+
### Options
|
|
185
|
+
|
|
186
|
+
Node.js application can be called with runtime options
|
|
187
|
+
(belonging to Node.js or V8). To list them type `node --help` or `node --v8-options`.
|
|
188
|
+
|
|
189
|
+
You can "bake" these runtime options into packaged application. The app will always run with the options
|
|
190
|
+
turned on. Just remove `--` from option name.
|
|
191
|
+
|
|
192
|
+
You can specify multiple options by joining them in a single string, comma (`,`) separated:
|
|
193
|
+
|
|
194
|
+
```sh
|
|
195
|
+
pkg app.js --options expose-gc
|
|
196
|
+
pkg app.js --options max_old_space_size=4096
|
|
197
|
+
pkg app.js --options max-old-space-size=1024,tls-min-v1.0,expose-gc
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Output
|
|
201
|
+
|
|
202
|
+
You may specify `--output` if you create only one executable
|
|
203
|
+
or `--out-path` to place executables for multiple targets.
|
|
204
|
+
|
|
205
|
+
### Debug
|
|
206
|
+
|
|
207
|
+
Pass `--debug` to `pkg` to get a log of packaging process.
|
|
208
|
+
If you have issues with some particular file (seems not packaged
|
|
209
|
+
into executable), it may be useful to look through the log.
|
|
210
|
+
|
|
211
|
+
In order to get more detailed logs on startup, after you packaged your application using `--debug`, you can start your application with the environment variable `DEBUG_PKG` set to `1` or `2` if you want more verbose debugging. This will load `prelude/diagnostic.js` that will print the snapshot tree and the symlink table, when set to `2` it will also mock `fs` in order to print logs when a method is called.
|
|
212
|
+
|
|
213
|
+
This is useful to see what's included in your bundle and detect possible missing files or large files that could be removed from it in order to reduce the size of the executable.
|
|
214
|
+
|
|
215
|
+
You can also use `SIZE_LIMIT_PKG` and `FOLDER_LIMIT_PKG` to print files/folders that are larger than the specified size limit (in bytes). By default, the size limit is set to 5MB for files and 10MB for folders.
|
|
216
|
+
|
|
217
|
+
### Bytecode (reproducibility)
|
|
218
|
+
|
|
219
|
+
By default, your source code is precompiled to v8 bytecode before being written
|
|
220
|
+
to the output file. To disable this feature, pass `--no-bytecode` to `pkg`.
|
|
221
|
+
|
|
222
|
+
#### Why would you want to do this?
|
|
223
|
+
|
|
224
|
+
If you need a reproducible build
|
|
225
|
+
process where your executable hashes (e.g. md5, sha1, sha256, etc.) are the
|
|
226
|
+
same value between builds. Because compiling bytecode is not deterministic
|
|
227
|
+
(see [here](https://ui.adsabs.harvard.edu/abs/2019arXiv191003478C/abstract) or
|
|
228
|
+
[here](https://medium.com/dailyjs/understanding-v8s-bytecode-317d46c94775)) it
|
|
229
|
+
results in executables with differing hashed values. Disabling bytecode
|
|
230
|
+
compilation allows a given input to always have the same output.
|
|
231
|
+
|
|
232
|
+
#### Why would you NOT want to do this?
|
|
233
|
+
|
|
234
|
+
While compiling to bytecode does not make your source code 100% secure, it does
|
|
235
|
+
add a small layer of security/privacy/obscurity to your source code. Turning
|
|
236
|
+
off bytecode compilation causes the raw source code to be written directly to
|
|
237
|
+
the executable file. If you're on \*nix machine and would like an example, run
|
|
238
|
+
`pkg` with the `--no-bytecode` flag, and use the GNU strings tool on the
|
|
239
|
+
output. You then should be able to grep your source code.
|
|
240
|
+
|
|
241
|
+
#### Other considerations
|
|
242
|
+
|
|
243
|
+
Specifying `--no-bytecode` will fail if there are any packages in your project that aren't explicitly marked
|
|
244
|
+
as public by the `license` in their `package.json`.
|
|
245
|
+
By default, `pkg` will check the license of each package and make sure that stuff that isn't meant for the public will
|
|
246
|
+
only be included as bytecode.
|
|
247
|
+
|
|
248
|
+
If you do require building pkg binaries for other architectures and/or depend on a package with a broken
|
|
249
|
+
`license` in its `package.json`, you can override this behaviour by either explicitly whitelisting packages to be public
|
|
250
|
+
using `--public-packages "packageA,packageB"` or setting all packages to public using `--public-packages "*"`
|
|
251
|
+
|
|
252
|
+
### Build
|
|
253
|
+
|
|
254
|
+
`pkg` has so called "base binaries" - they are actually same
|
|
255
|
+
`node` executables but with some patches applied. They are
|
|
256
|
+
used as a base for every executable `pkg` creates. `pkg`
|
|
257
|
+
downloads precompiled base binaries before packaging your
|
|
258
|
+
application. If you prefer to compile base binaries from
|
|
259
|
+
source instead of downloading them, you may pass `--build`
|
|
260
|
+
option to `pkg`. First ensure your computer meets the
|
|
261
|
+
requirements to compile original Node.js:
|
|
262
|
+
[BUILDING.md](https://github.com/nodejs/node/blob/HEAD/BUILDING.md)
|
|
263
|
+
|
|
264
|
+
See [pkg-fetch](https://github.com/yao-pkg/pkg-fetch) for more info.
|
|
265
|
+
|
|
266
|
+
### Compression
|
|
267
|
+
|
|
268
|
+
Pass `--compress Brotli` or `--compress GZip` to `pkg` to compress further the content of the files store in the exectable.
|
|
269
|
+
|
|
270
|
+
This option can reduce the size of the embedded file system by up to 60%.
|
|
271
|
+
|
|
272
|
+
The startup time of the application might be reduced slightly.
|
|
273
|
+
|
|
274
|
+
`-C` can be used as a shortcut for `--compress`.
|
|
275
|
+
|
|
276
|
+
### Environment
|
|
277
|
+
|
|
278
|
+
| Var | Description |
|
|
279
|
+
| -------------- | ----------------------------------------------------------------------------------------- |
|
|
280
|
+
| PKG_CACHE_PATH | Used to specify a custom path for node binaries cache folder. Default is `~/.pkg-cache` |
|
|
281
|
+
| PKG_IGNORE_TAG | Allows to ignore additional folder created on `PKG_CACHE_PATH` matching pkg-fetch version |
|
|
282
|
+
| MAKE_JOB_COUNT | Allow configuring number of processes used for compiling |
|
|
283
|
+
|
|
284
|
+
Examples
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
# 1 - Using export
|
|
288
|
+
export PKG_CACHE_PATH=/my/cache
|
|
289
|
+
pkg app.js
|
|
290
|
+
|
|
291
|
+
# 2 - Passing it before the script
|
|
292
|
+
PKG_CACHE_PATH=/my/cache pkg app.js
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## Usage of packaged app
|
|
296
|
+
|
|
297
|
+
Command line call to packaged app `./app a b` is equivalent
|
|
298
|
+
to `node app.js a b`
|
|
299
|
+
|
|
300
|
+
## Snapshot filesystem
|
|
301
|
+
|
|
302
|
+
During packaging process `pkg` collects project files and places
|
|
303
|
+
them into executable. It is called a snapshot. At run time the
|
|
304
|
+
packaged application has access to snapshot filesystem where all
|
|
305
|
+
that files reside.
|
|
306
|
+
|
|
307
|
+
Packaged files have `/snapshot/` prefix in their paths (or
|
|
308
|
+
`C:\snapshot\` in Windows). If you used `pkg /path/app.js` command line,
|
|
309
|
+
then `__filename` value will be likely `/snapshot/path/app.js`
|
|
310
|
+
at run time. `__dirname` will be `/snapshot/path` as well. Here is
|
|
311
|
+
the comparison table of path-related values:
|
|
312
|
+
|
|
313
|
+
| value | with `node` | packaged | comments |
|
|
314
|
+
| ----------------------------- | --------------- | ------------------------ | ------------------------------ |
|
|
315
|
+
| \_\_filename | /project/app.js | /snapshot/project/app.js |
|
|
316
|
+
| \_\_dirname | /project | /snapshot/project |
|
|
317
|
+
| process.cwd() | /project | /deploy | suppose the app is called ... |
|
|
318
|
+
| process.execPath | /usr/bin/nodejs | /deploy/app-x64 | `app-x64` and run in `/deploy` |
|
|
319
|
+
| process.argv[0] | /usr/bin/nodejs | /deploy/app-x64 |
|
|
320
|
+
| process.argv[1] | /project/app.js | /snapshot/project/app.js |
|
|
321
|
+
| process.pkg.entrypoint | undefined | /snapshot/project/app.js |
|
|
322
|
+
| process.pkg.defaultEntrypoint | undefined | /snapshot/project/app.js |
|
|
323
|
+
| require.main.filename | /project/app.js | /snapshot/project/app.js |
|
|
324
|
+
|
|
325
|
+
Hence, in order to make use of a file collected at packaging
|
|
326
|
+
time (`require` a javascript file or serve an asset) you should
|
|
327
|
+
take `__filename`, `__dirname`, `process.pkg.defaultEntrypoint`
|
|
328
|
+
or `require.main.filename` as a base for your path calculations.
|
|
329
|
+
For javascript files you can just `require` or `require.resolve`
|
|
330
|
+
because they use current `__dirname` by default. For assets use
|
|
331
|
+
`path.join(__dirname, '../path/to/asset')`. Learn more about
|
|
332
|
+
`path.join` in
|
|
333
|
+
[Detecting assets in source code](#detecting-assets-in-source-code).
|
|
334
|
+
|
|
335
|
+
On the other hand, in order to access real file system at run time
|
|
336
|
+
(pick up a user's external javascript plugin, json configuration or
|
|
337
|
+
even get a list of user's directory) you should take `process.cwd()`
|
|
338
|
+
or `path.dirname(process.execPath)`.
|
|
339
|
+
|
|
340
|
+
## Detecting assets in source code
|
|
341
|
+
|
|
342
|
+
When `pkg` encounters `path.join(__dirname, '../path/to/asset')`,
|
|
343
|
+
it automatically packages the file specified as an asset. See
|
|
344
|
+
[Assets](#assets). Pay attention that `path.join` must have two
|
|
345
|
+
arguments and the last one must be a string literal.
|
|
346
|
+
|
|
347
|
+
This way you may even avoid creating `pkg` config for your project.
|
|
348
|
+
|
|
349
|
+
## Native addons
|
|
350
|
+
|
|
351
|
+
Native addons (`.node` files) use is supported. When `pkg` encounters
|
|
352
|
+
a `.node` file in a `require` call, it will package this like an asset.
|
|
353
|
+
In some cases (like with the `bindings` package), the module path is generated
|
|
354
|
+
dynamicaly and `pkg` won't be able to detect it. In this case, you should
|
|
355
|
+
add the `.node` file directly in the `assets` field in `package.json`.
|
|
356
|
+
|
|
357
|
+
The way Node.js requires native addon is different from a classic JS
|
|
358
|
+
file. It needs to have a file on disk to load it, but `pkg` only generates
|
|
359
|
+
one file. To circumvent this, `pkg` will create a temporary file on the
|
|
360
|
+
disk. These files will stay on the disk after the process has exited
|
|
361
|
+
and will be used again on the next process launch.
|
|
362
|
+
|
|
363
|
+
When a package, that contains a native module, is being installed,
|
|
364
|
+
the native module is compiled against current system-wide Node.js
|
|
365
|
+
version. Then, when you compile your project with `pkg`, pay attention
|
|
366
|
+
to `--target` option. You should specify the same Node.js version
|
|
367
|
+
as your system-wide Node.js to make compiled executable compatible
|
|
368
|
+
with `.node` files.
|
|
369
|
+
|
|
370
|
+
Note that fully static Node binaries are not capable of loading native
|
|
371
|
+
bindings, so you may not use Node bindings with `linuxstatic`.
|
|
372
|
+
|
|
373
|
+
## API
|
|
374
|
+
|
|
375
|
+
`const { exec } = require('pkg')`
|
|
376
|
+
|
|
377
|
+
`exec(args)` takes an array of command line arguments and returns
|
|
378
|
+
a promise. For example:
|
|
379
|
+
|
|
380
|
+
```js
|
|
381
|
+
await exec(['app.js', '--target', 'host', '--output', 'app.exe']);
|
|
382
|
+
// do something with app.exe, run, test, upload, deploy, etc
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
## Troubleshooting
|
|
386
|
+
|
|
387
|
+
### Error: ENOENT: no such file or directory, uv_chdir
|
|
388
|
+
|
|
389
|
+
This error can be caused by deleting the directory the application is
|
|
390
|
+
run from. Or, generally, deleting `process.cwd()` directory when the
|
|
391
|
+
application is running.
|
|
392
|
+
|
|
393
|
+
### Error: ERR_INSPECTOR_NOT_AVAILABLE
|
|
394
|
+
|
|
395
|
+
This error can be caused by using `NODE_OPTIONS` variable to force to
|
|
396
|
+
run `node` with the debug mode enabled. Debugging options are disallowed
|
|
397
|
+
, as **pkg** executables are usually used for production environments.
|
|
398
|
+
If you do need to use inspector, you can [build a debuggable Node.js](https://github.com/vercel/pkg/issues/93#issuecomment-301210543) yourself.
|
|
399
|
+
|
|
400
|
+
### Error: require(...).internalModuleStat is not a function
|
|
401
|
+
|
|
402
|
+
This error can be caused by using `NODE_OPTIONS` variable with some
|
|
403
|
+
bootstrap or `node` options causing conflicts with **pkg**. Some
|
|
404
|
+
IDEs, such as **VS Code**, may add this env variable automatically.
|
|
405
|
+
|
|
406
|
+
You could check on **Unix systems** (Linux/macOS) in `bash`:
|
|
407
|
+
|
|
408
|
+
```bash
|
|
409
|
+
printenv | grep NODE
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
## Advanced
|
|
413
|
+
|
|
414
|
+
### exploring virtual file system embedded in debug mode
|
|
415
|
+
|
|
416
|
+
When you are using the `--debug` flag when building your executable,
|
|
417
|
+
`pkg` add the ability to display the content of the virtual file system
|
|
418
|
+
and the symlink table on the console, when the application starts,
|
|
419
|
+
providing that the environement variable DEBUG_PKG is set.
|
|
420
|
+
This feature can be useful to inspect if symlinks are correctly handled,
|
|
421
|
+
and check that all the required files for your application are properly
|
|
422
|
+
incorporated to the final executable.
|
|
423
|
+
|
|
424
|
+
pkg --debug app.js -o output
|
|
425
|
+
DEBUG_PKG=1 output
|
|
426
|
+
|
|
427
|
+
or
|
|
428
|
+
|
|
429
|
+
C:\> pkg --debug app.js -o output.exe
|
|
430
|
+
C:\> set DEBUG_PKG=1
|
|
431
|
+
C:\> output.exe
|
|
432
|
+
|
|
433
|
+
Note: make sure not to use --debug flag in production.
|