@yao-pkg/pkg 5.11.5 → 5.12.1
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/README.md +30 -14
- package/lib-es5/index.js +3 -0
- package/lib-es5/options.js +18 -0
- package/lib-es5/producer.js +19 -2
- package/lib-es5/walker.js +29 -3
- package/package.json +5 -4
- package/prelude/bootstrap.js +3 -3
package/README.md
CHANGED
|
@@ -50,23 +50,23 @@ pkg [options] <input>
|
|
|
50
50
|
|
|
51
51
|
Examples:
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
- Makes executables for Linux, macOS and Windows
|
|
54
54
|
$ pkg index.js
|
|
55
|
-
|
|
55
|
+
- Takes package.json from cwd and follows 'bin' entry
|
|
56
56
|
$ pkg .
|
|
57
|
-
|
|
57
|
+
- Makes executable for particular target machine
|
|
58
58
|
$ pkg -t node16-win-arm64 index.js
|
|
59
|
-
|
|
59
|
+
- Makes executables for target machines of your choice
|
|
60
60
|
$ pkg -t node16-linux,node18-linux,node16-win index.js
|
|
61
|
-
|
|
61
|
+
- Bakes '--expose-gc' and '--max-heap-size=34' into executable
|
|
62
62
|
$ pkg --options "expose-gc,max-heap-size=34" index.js
|
|
63
|
-
|
|
63
|
+
- Consider packageA and packageB to be public
|
|
64
64
|
$ pkg --public-packages "packageA,packageB" index.js
|
|
65
|
-
|
|
65
|
+
- Consider all packages to be public
|
|
66
66
|
$ pkg --public-packages "*" index.js
|
|
67
|
-
|
|
67
|
+
- Bakes '--expose-gc' into executable
|
|
68
68
|
$ pkg --options expose-gc index.js
|
|
69
|
-
|
|
69
|
+
- reduce size of the data packed inside the executable with GZip
|
|
70
70
|
$ pkg --compress GZip index.js
|
|
71
71
|
```
|
|
72
72
|
|
|
@@ -181,6 +181,22 @@ See also
|
|
|
181
181
|
[Detecting assets in source code](#detecting-assets-in-source-code) and
|
|
182
182
|
[Snapshot filesystem](#snapshot-filesystem).
|
|
183
183
|
|
|
184
|
+
### Ignore files
|
|
185
|
+
|
|
186
|
+
`ignore` is a list of globs. Files matching the paths specified as `ignore`
|
|
187
|
+
will be excluded from the final executable.
|
|
188
|
+
|
|
189
|
+
This is useful when you want to exclude some files from the final executable,
|
|
190
|
+
like tests, documentation or build files that could have been included by a dependency.
|
|
191
|
+
|
|
192
|
+
```json
|
|
193
|
+
"pkg": {
|
|
194
|
+
"ignore": [ "**/*/dependency-name/build.c" ]
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
To see if you have unwanted files in your executable, read the [Exploring virtual file system embedded in debug mode](#exploring-virtual-file-system-embedded-in-debug-mode) section.
|
|
199
|
+
|
|
184
200
|
### Options
|
|
185
201
|
|
|
186
202
|
Node.js application can be called with runtime options
|
|
@@ -353,14 +369,14 @@ This way you may even avoid creating `pkg` config for your project.
|
|
|
353
369
|
Native addons (`.node` files) use is supported. When `pkg` encounters
|
|
354
370
|
a `.node` file in a `require` call, it will package this like an asset.
|
|
355
371
|
In some cases (like with the `bindings` package), the module path is generated
|
|
356
|
-
|
|
372
|
+
dynamically and `pkg` won't be able to detect it. In this case, you should
|
|
357
373
|
add the `.node` file directly in the `assets` field in `package.json`.
|
|
358
374
|
|
|
359
375
|
The way Node.js requires native addon is different from a classic JS
|
|
360
376
|
file. It needs to have a file on disk to load it, but `pkg` only generates
|
|
361
|
-
one file. To circumvent this, `pkg` will
|
|
362
|
-
|
|
363
|
-
and will be used again on the next process launch.
|
|
377
|
+
one file. To circumvent this, `pkg` will extract native addon files to
|
|
378
|
+
`$HOME/.cache/pkg/`. These files will stay on the disk after the process has
|
|
379
|
+
exited and will be used again on the next process launch.
|
|
364
380
|
|
|
365
381
|
When a package, that contains a native module, is being installed,
|
|
366
382
|
the native module is compiled against current system-wide Node.js
|
|
@@ -413,7 +429,7 @@ printenv | grep NODE
|
|
|
413
429
|
|
|
414
430
|
## Advanced
|
|
415
431
|
|
|
416
|
-
###
|
|
432
|
+
### Exploring virtual file system embedded in debug mode
|
|
417
433
|
|
|
418
434
|
When you are using the `--debug` flag when building your executable,
|
|
419
435
|
`pkg` add the ability to display the content of the virtual file system
|
package/lib-es5/index.js
CHANGED
|
@@ -21,6 +21,7 @@ const fabricator_1 = require("./fabricator");
|
|
|
21
21
|
const walker_1 = __importDefault(require("./walker"));
|
|
22
22
|
const compress_type_1 = require("./compress_type");
|
|
23
23
|
const mach_o_1 = require("./mach-o");
|
|
24
|
+
const options_1 = __importDefault(require("./options"));
|
|
24
25
|
const { version } = JSON.parse((0, fs_extra_1.readFileSync)(path_1.default.join(__dirname, '../package.json'), 'utf-8'));
|
|
25
26
|
function isConfiguration(file) {
|
|
26
27
|
return (0, common_1.isPackageJson)(file) || file.endsWith('.config.json');
|
|
@@ -439,6 +440,7 @@ async function exec(argv2) {
|
|
|
439
440
|
// marker
|
|
440
441
|
let marker;
|
|
441
442
|
if (configJson) {
|
|
443
|
+
options_1.default.set(configJson === null || configJson === void 0 ? void 0 : configJson.pkg);
|
|
442
444
|
marker = {
|
|
443
445
|
config: configJson,
|
|
444
446
|
base: path_1.default.dirname(config),
|
|
@@ -446,6 +448,7 @@ async function exec(argv2) {
|
|
|
446
448
|
};
|
|
447
449
|
}
|
|
448
450
|
else {
|
|
451
|
+
options_1.default.set(inputJson === null || inputJson === void 0 ? void 0 : inputJson.pkg);
|
|
449
452
|
marker = {
|
|
450
453
|
config: inputJson || {},
|
|
451
454
|
base: path_1.default.dirname(input),
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class Options {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.options = {
|
|
6
|
+
dictionary: {},
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
set(options) {
|
|
10
|
+
this.options = options !== null && options !== void 0 ? options : this.options;
|
|
11
|
+
}
|
|
12
|
+
get() {
|
|
13
|
+
return this.options;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const options = new Options();
|
|
17
|
+
exports.default = options;
|
|
18
|
+
//# sourceMappingURL=options.js.map
|
package/lib-es5/producer.js
CHANGED
|
@@ -105,10 +105,27 @@ function findPackageJson(nodeFile) {
|
|
|
105
105
|
}
|
|
106
106
|
return dir;
|
|
107
107
|
}
|
|
108
|
+
function getPrebuildEnvPrefix(pkgName) {
|
|
109
|
+
return `npm_config_${(pkgName || '')
|
|
110
|
+
.replace(/[^a-zA-Z0-9]/g, '_')
|
|
111
|
+
.replace(/^_/, '')}`;
|
|
112
|
+
}
|
|
108
113
|
function nativePrebuildInstall(target, nodeFile) {
|
|
109
114
|
var _a, _b;
|
|
110
115
|
const prebuildInstall = path_1.default.join(__dirname, '../node_modules/.bin/prebuild-install');
|
|
111
116
|
const dir = findPackageJson(nodeFile);
|
|
117
|
+
const packageJson = JSON.parse(fs_extra_1.default.readFileSync(path_1.default.join(dir, 'package.json'), { encoding: 'utf-8' }));
|
|
118
|
+
// only try prebuild-install for packages that actually use it or if
|
|
119
|
+
// explicitly configured via environment variables
|
|
120
|
+
const envPrefix = getPrebuildEnvPrefix(packageJson.name);
|
|
121
|
+
if (((_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a['prebuild-install']) == null &&
|
|
122
|
+
![
|
|
123
|
+
`${envPrefix}_binary_host`,
|
|
124
|
+
`${envPrefix}_binary_host_mirror`,
|
|
125
|
+
`${envPrefix}_local_prebuilds`,
|
|
126
|
+
].some((i) => i in process.env)) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
112
129
|
// parse the target node version from the binaryPath
|
|
113
130
|
const nodeVersion = path_1.default.basename(target.binaryPath).split('-')[1];
|
|
114
131
|
if (!/^v[0-9]+\.[0-9]+\.[0-9]+$/.test(nodeVersion)) {
|
|
@@ -122,7 +139,7 @@ function nativePrebuildInstall(target, nodeFile) {
|
|
|
122
139
|
if (!fs_extra_1.default.existsSync(`${nodeFile}.bak`)) {
|
|
123
140
|
fs_extra_1.default.copyFileSync(nodeFile, `${nodeFile}.bak`);
|
|
124
141
|
}
|
|
125
|
-
const napiVersions = (_b =
|
|
142
|
+
const napiVersions = (_b = packageJson === null || packageJson === void 0 ? void 0 : packageJson.binary) === null || _b === void 0 ? void 0 : _b.napi_versions;
|
|
126
143
|
const options = [
|
|
127
144
|
'--platform',
|
|
128
145
|
types_1.platform[target.platform],
|
|
@@ -289,7 +306,7 @@ function producer({ backpack, bakes, slash, target, symLinks, doCompress, native
|
|
|
289
306
|
if ((0, common_1.isDotNODE)(stripe.file) && nativeBuild) {
|
|
290
307
|
try {
|
|
291
308
|
const platformFile = nativePrebuildInstall(target, stripe.file);
|
|
292
|
-
if (fs_extra_1.default.existsSync(platformFile)) {
|
|
309
|
+
if (platformFile && fs_extra_1.default.existsSync(platformFile)) {
|
|
293
310
|
return cb(null, pipeMayCompressToNewMeter(fs_extra_1.default.createReadStream(platformFile)));
|
|
294
311
|
}
|
|
295
312
|
}
|
package/lib-es5/walker.js
CHANGED
|
@@ -29,14 +29,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
30
|
const assert_1 = __importDefault(require("assert"));
|
|
31
31
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
32
|
-
const is_core_module_1 = __importDefault(require("is-core-module"));
|
|
33
32
|
const globby_1 = __importDefault(require("globby"));
|
|
34
33
|
const path_1 = __importDefault(require("path"));
|
|
35
34
|
const chalk_1 = __importDefault(require("chalk"));
|
|
35
|
+
const minimatch_1 = require("minimatch");
|
|
36
|
+
const module_1 = require("module");
|
|
36
37
|
const common_1 = require("./common");
|
|
37
38
|
const follow_1 = require("./follow");
|
|
38
39
|
const log_1 = require("./log");
|
|
39
40
|
const detector = __importStar(require("./detector"));
|
|
41
|
+
const options_1 = __importDefault(require("./options"));
|
|
40
42
|
// Note: as a developer, you can set the PKG_STRICT_VER variable.
|
|
41
43
|
// this will turn on some assertion in the walker code below
|
|
42
44
|
// to assert that each file content/state that we appending
|
|
@@ -46,6 +48,17 @@ const detector = __importStar(require("./detector"));
|
|
|
46
48
|
// performance hit.
|
|
47
49
|
const strictVerify = Boolean(process.env.PKG_STRICT_VER);
|
|
48
50
|
const win32 = process.platform === 'win32';
|
|
51
|
+
/**
|
|
52
|
+
* Checks if a module is a core module
|
|
53
|
+
* module.isBuiltin is available in Node.js 16.17.0 or later. Once we drop support for older
|
|
54
|
+
* versions of Node.js, we can use module.isBuiltin instead of this function.
|
|
55
|
+
*/
|
|
56
|
+
function isBuiltin(moduleName) {
|
|
57
|
+
const moduleNameWithoutPrefix = moduleName.startsWith('node:')
|
|
58
|
+
? moduleName.slice(5)
|
|
59
|
+
: moduleName;
|
|
60
|
+
return module_1.builtinModules.includes(moduleNameWithoutPrefix);
|
|
61
|
+
}
|
|
49
62
|
function unlikelyJavascript(file) {
|
|
50
63
|
return ['.css', '.html', '.json', '.vue'].includes(path_1.default.extname(file));
|
|
51
64
|
}
|
|
@@ -331,6 +344,15 @@ class Walker {
|
|
|
331
344
|
(0, assert_1.default)(task.store === common_1.STORE_BLOB || task.store === common_1.STORE_CONTENT);
|
|
332
345
|
(0, assert_1.default)(typeof task.file === 'string');
|
|
333
346
|
const realFile = (0, common_1.toNormalizedRealPath)(task.file);
|
|
347
|
+
const { ignore } = options_1.default.get();
|
|
348
|
+
if (ignore) {
|
|
349
|
+
// check if the file matches one of the ignore regex patterns
|
|
350
|
+
const match = ignore.some((pattern) => (0, minimatch_1.minimatch)(realFile, pattern));
|
|
351
|
+
if (match) {
|
|
352
|
+
log_1.log.debug(`Ignoring file: ${realFile} due to top level config ignore pattern`);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
334
356
|
if (realFile === task.file) {
|
|
335
357
|
this.append(task);
|
|
336
358
|
return;
|
|
@@ -569,7 +591,11 @@ class Walker {
|
|
|
569
591
|
};
|
|
570
592
|
const catchPackageFilter = (config, base) => {
|
|
571
593
|
const newPackage = newPackages[newPackages.length - 1];
|
|
572
|
-
newPackage.marker = {
|
|
594
|
+
newPackage.marker = {
|
|
595
|
+
config,
|
|
596
|
+
configPath: newPackage.packageJson,
|
|
597
|
+
base,
|
|
598
|
+
};
|
|
573
599
|
};
|
|
574
600
|
let newFile = '';
|
|
575
601
|
let failure;
|
|
@@ -651,7 +677,7 @@ class Walker {
|
|
|
651
677
|
async stepDerivatives(record, marker, derivatives) {
|
|
652
678
|
for (const derivative of derivatives) {
|
|
653
679
|
// TODO: actually use the target node version
|
|
654
|
-
if ((
|
|
680
|
+
if (isBuiltin(derivative.alias))
|
|
655
681
|
continue;
|
|
656
682
|
switch (derivative.aliasType) {
|
|
657
683
|
case common_1.ALIAS_AS_RELATIVE:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yao-pkg/pkg",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.12.1",
|
|
4
4
|
"description": "Package your Node.js project into an executable",
|
|
5
5
|
"main": "lib-es5/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"fs-extra": "^9.1.0",
|
|
31
31
|
"globby": "^11.1.0",
|
|
32
32
|
"into-stream": "^6.0.0",
|
|
33
|
-
"
|
|
33
|
+
"minimatch": "9.0.4",
|
|
34
34
|
"minimist": "^1.2.6",
|
|
35
35
|
"multistream": "^4.1.0",
|
|
36
36
|
"prebuild-install": "7.1.1",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@release-it/conventional-changelog": "7.0.2",
|
|
43
43
|
"@types/babel__generator": "7.6.5",
|
|
44
44
|
"@types/fs-extra": "9.0.13",
|
|
45
|
-
"@types/
|
|
45
|
+
"@types/minimatch": "^5.1.2",
|
|
46
46
|
"@types/minimist": "1.2.2",
|
|
47
47
|
"@types/multistream": "4.1.0",
|
|
48
48
|
"@types/node": "14.18.20",
|
|
@@ -139,5 +139,6 @@
|
|
|
139
139
|
},
|
|
140
140
|
"publishConfig": {
|
|
141
141
|
"access": "public"
|
|
142
|
-
}
|
|
142
|
+
},
|
|
143
|
+
"packageManager": "yarn@1.22.22"
|
|
143
144
|
}
|
package/prelude/bootstrap.js
CHANGED
|
@@ -24,7 +24,7 @@ const Module = require('module');
|
|
|
24
24
|
const path = require('path');
|
|
25
25
|
const { promisify, _extend } = require('util');
|
|
26
26
|
const { Script } = require('vm');
|
|
27
|
-
const {
|
|
27
|
+
const { homedir } = require('os');
|
|
28
28
|
const util = require('util');
|
|
29
29
|
const {
|
|
30
30
|
brotliDecompress,
|
|
@@ -2210,8 +2210,8 @@ function payloadFileSync(pointer) {
|
|
|
2210
2210
|
// the hash is needed to be sure we reload the module in case it changes
|
|
2211
2211
|
const hash = createHash('sha256').update(moduleContent).digest('hex');
|
|
2212
2212
|
|
|
2213
|
-
// Example: /
|
|
2214
|
-
const tmpFolder = path.join(
|
|
2213
|
+
// Example: /home/john/.cache/pkg/<hash>
|
|
2214
|
+
const tmpFolder = path.join(homedir(), '.cache/pkg', hash);
|
|
2215
2215
|
|
|
2216
2216
|
createDirRecursively(tmpFolder);
|
|
2217
2217
|
|