Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit 4ed2ee4

Browse files
robertsLandojesec
authored andcommitted
feat: add no-native-build option to skip native addons build
Fixes #1319
1 parent 85ccec3 commit 4ed2ee4

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,30 @@ pkg [options] <input>
4343
--public speed up and disclose the sources of top-level project
4444
--public-packages force specified packages to be considered public
4545
--no-bytecode skip bytecode generation and include source files as plain js
46+
--no-native-build skip native addons build
4647
--no-dict comma-separated list of packages names to ignore dictionaries. Use --no-dict * to disable all dictionaries
4748
-C, --compress [default=None] compression algorithm = Brotli or GZip
49+
50+
Examples:
51+
52+
– Makes executables for Linux, macOS and Windows
53+
$ pkg index.js
54+
– Takes package.json from cwd and follows 'bin' entry
55+
$ pkg .
56+
– Makes executable for particular target machine
57+
$ pkg -t node14-win-arm64 index.js
58+
– Makes executables for target machines of your choice
59+
$ pkg -t node12-linux,node14-linux,node14-win index.js
60+
– Bakes '--expose-gc' and '--max-heap-size=34' into executable
61+
$ pkg --options "expose-gc,max-heap-size=34" index.js
62+
– Consider packageA and packageB to be public
63+
$ pkg --public-packages "packageA,packageB" index.js
64+
– Consider all packages to be public
65+
$ pkg --public-packages "*" index.js
66+
– Bakes '--expose-gc' into executable
67+
$ pkg --options expose-gc index.js
68+
– reduce size of the data packed inside the executable with GZip
69+
$ pkg --compress GZip index.js
4870
```
4971
5072
The entrypoint of your project is a mandatory CLI argument. It may be:

lib/help.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default function help() {
1919
--public speed up and disclose the sources of top-level project
2020
--public-packages force specified packages to be considered public
2121
--no-bytecode skip bytecode generation and include source files as plain js
22+
--no-native-build skip native addons build
2223
--no-dict comma-separated list of packages names to ignore dictionaries. Use --no-dict * to disable all dictionaries
2324
-C, --compress [default=None] compression algorithm = Brotli or GZip
2425

lib/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ export async function exec(argv2: string[]) {
225225
'b',
226226
'build',
227227
'bytecode',
228+
'native-build',
228229
'd',
229230
'debug',
230231
'h',
@@ -251,7 +252,7 @@ export async function exec(argv2: string[]) {
251252
'C',
252253
'compress',
253254
],
254-
default: { bytecode: true },
255+
default: { bytecode: true, 'native-build': true },
255256
});
256257

257258
if (argv.h || argv.help) {
@@ -541,6 +542,8 @@ export async function exec(argv2: string[]) {
541542

542543
const { bytecode } = argv;
543544

545+
const nativeBuild = argv['native-build']
546+
544547
for (const target of targets) {
545548
target.forceBuild = forceBuild;
546549

@@ -677,6 +680,7 @@ export async function exec(argv2: string[]) {
677680
target: target as Target,
678681
symLinks,
679682
doCompress,
683+
nativeBuild
680684
});
681685

682686
if (target.platform !== 'win' && target.output) {

lib/producer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ interface ProducerOptions {
251251
target: Target;
252252
symLinks: SymLinks;
253253
doCompress: CompressType;
254+
nativeBuild: boolean;
254255
}
255256

256257
/**
@@ -314,6 +315,7 @@ export default function producer({
314315
target,
315316
symLinks,
316317
doCompress,
318+
nativeBuild
317319
}: ProducerOptions) {
318320
return new Promise<void>((resolve, reject) => {
319321
if (!Buffer.alloc) {
@@ -448,7 +450,7 @@ export default function producer({
448450

449451
assert.strictEqual(stripe.store, STORE_CONTENT); // others must be buffers from walker
450452

451-
if (isDotNODE(stripe.file)) {
453+
if (isDotNODE(stripe.file) && nativeBuild) {
452454
try {
453455
const platformFile = nativePrebuildInstall(target, stripe.file);
454456

0 commit comments

Comments
 (0)