@yao-pkg/pkg 5.11.4 → 5.12.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/README.md CHANGED
@@ -50,23 +50,23 @@ pkg [options] <input>
50
50
 
51
51
  Examples:
52
52
 
53
- Makes executables for Linux, macOS and Windows
53
+ - Makes executables for Linux, macOS and Windows
54
54
  $ pkg index.js
55
- Takes package.json from cwd and follows 'bin' entry
55
+ - Takes package.json from cwd and follows 'bin' entry
56
56
  $ pkg .
57
- Makes executable for particular target machine
57
+ - Makes executable for particular target machine
58
58
  $ pkg -t node16-win-arm64 index.js
59
- Makes executables for target machines of your choice
59
+ - Makes executables for target machines of your choice
60
60
  $ pkg -t node16-linux,node18-linux,node16-win index.js
61
- Bakes '--expose-gc' and '--max-heap-size=34' into executable
61
+ - Bakes '--expose-gc' and '--max-heap-size=34' into executable
62
62
  $ pkg --options "expose-gc,max-heap-size=34" index.js
63
- Consider packageA and packageB to be public
63
+ - Consider packageA and packageB to be public
64
64
  $ pkg --public-packages "packageA,packageB" index.js
65
- Consider all packages to be public
65
+ - Consider all packages to be public
66
66
  $ pkg --public-packages "*" index.js
67
- Bakes '--expose-gc' into executable
67
+ - Bakes '--expose-gc' into executable
68
68
  $ pkg --options expose-gc index.js
69
- reduce size of the data packed inside the executable with GZip
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
- dynamicaly and `pkg` won't be able to detect it. In this case, you should
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 create a temporary file on the
362
- disk. These files will stay on the disk after the process has exited
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
- ### exploring virtual file system embedded in debug mode
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
@@ -1,3 +1,7 @@
1
1
  'use strict';
2
2
 
3
- module.exports = {};
3
+ module.exports = {
4
+ pkg: {
5
+ assets: ['build/Release/*.node'],
6
+ },
7
+ };
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ pkg: {
5
+ scripts: ['lib/worker.js'],
6
+ },
7
+ };
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
@@ -133,6 +133,9 @@ function nativePrebuildInstall(target, nodeFile) {
133
133
  // TODO: consider target node version and supported n-api version
134
134
  options.push('--target', nodeVersion);
135
135
  }
136
+ else {
137
+ options.push('--runtime', 'napi');
138
+ }
136
139
  // run prebuild
137
140
  (0, child_process_1.execFileSync)(prebuildInstall, options, { cwd: dir });
138
141
  // move the prebuild to a new name with a platform/version extension
package/lib-es5/walker.js CHANGED
@@ -33,10 +33,12 @@ const is_core_module_1 = __importDefault(require("is-core-module"));
33
33
  const globby_1 = __importDefault(require("globby"));
34
34
  const path_1 = __importDefault(require("path"));
35
35
  const chalk_1 = __importDefault(require("chalk"));
36
+ const minimatch_1 = require("minimatch");
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
@@ -331,6 +333,15 @@ class Walker {
331
333
  (0, assert_1.default)(task.store === common_1.STORE_BLOB || task.store === common_1.STORE_CONTENT);
332
334
  (0, assert_1.default)(typeof task.file === 'string');
333
335
  const realFile = (0, common_1.toNormalizedRealPath)(task.file);
336
+ const { ignore } = options_1.default.get();
337
+ if (ignore) {
338
+ // check if the file matches one of the ignore regex patterns
339
+ const match = ignore.some((pattern) => (0, minimatch_1.minimatch)(realFile, pattern));
340
+ if (match) {
341
+ log_1.log.debug(`Ignoring file: ${realFile} due to top level config ignore pattern`);
342
+ return;
343
+ }
344
+ }
334
345
  if (realFile === task.file) {
335
346
  this.append(task);
336
347
  return;
@@ -569,7 +580,11 @@ class Walker {
569
580
  };
570
581
  const catchPackageFilter = (config, base) => {
571
582
  const newPackage = newPackages[newPackages.length - 1];
572
- newPackage.marker = { config, configPath: newPackage.packageJson, base };
583
+ newPackage.marker = {
584
+ config,
585
+ configPath: newPackage.packageJson,
586
+ base,
587
+ };
573
588
  };
574
589
  let newFile = '';
575
590
  let failure;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yao-pkg/pkg",
3
- "version": "5.11.4",
3
+ "version": "5.12.0",
4
4
  "description": "Package your Node.js project into an executable",
5
5
  "main": "lib-es5/index.js",
6
6
  "license": "MIT",
@@ -31,6 +31,7 @@
31
31
  "globby": "^11.1.0",
32
32
  "into-stream": "^6.0.0",
33
33
  "is-core-module": "2.9.0",
34
+ "minimatch": "9.0.4",
34
35
  "minimist": "^1.2.6",
35
36
  "multistream": "^4.1.0",
36
37
  "prebuild-install": "7.1.1",
@@ -43,6 +44,7 @@
43
44
  "@types/babel__generator": "7.6.5",
44
45
  "@types/fs-extra": "9.0.13",
45
46
  "@types/is-core-module": "2.2.0",
47
+ "@types/minimatch": "^5.1.2",
46
48
  "@types/minimist": "1.2.2",
47
49
  "@types/multistream": "4.1.0",
48
50
  "@types/node": "14.18.20",
@@ -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 { tmpdir } = require('os');
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: /tmp/pkg/<hash>
2214
- const tmpFolder = path.join(tmpdir(), 'pkg', hash);
2213
+ // Example: /home/john/.cache/pkg/<hash>
2214
+ const tmpFolder = path.join(homedir(), '.cache/pkg', hash);
2215
2215
 
2216
2216
  createDirRecursively(tmpFolder);
2217
2217