From dcc51bd0c2c17357693742f0e5f7d8025a891ebd Mon Sep 17 00:00:00 2001 From: Corentin Mors Date: Fri, 31 May 2024 13:24:48 +0200 Subject: [PATCH 01/10] Ignore patterns of included files --- lib/index.ts | 2 + lib/types.ts | 1 + lib/walker.ts | 23 ++++++++- test/test-50-ignore-files/.gitignore | 1 + test/test-50-ignore-files/main.js | 49 +++++++++++++++++++ .../node_modules/delta/index.js | 3 ++ .../node_modules/delta/needed.c | 1 + .../node_modules/delta/package.json | 5 ++ .../node_modules/delta/useless.c | 1 + test/test-50-ignore-files/package.json | 12 +++++ test/test-50-ignore-files/test-x-index.js | 5 ++ 11 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 test/test-50-ignore-files/.gitignore create mode 100644 test/test-50-ignore-files/main.js create mode 100644 test/test-50-ignore-files/node_modules/delta/index.js create mode 100644 test/test-50-ignore-files/node_modules/delta/needed.c create mode 100644 test/test-50-ignore-files/node_modules/delta/package.json create mode 100644 test/test-50-ignore-files/node_modules/delta/useless.c create mode 100644 test/test-50-ignore-files/package.json create mode 100644 test/test-50-ignore-files/test-x-index.js diff --git a/lib/index.ts b/lib/index.ts index ea575ce97..8deb72a43 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -600,12 +600,14 @@ export async function exec(argv2: string[]) { if (configJson) { marker = { config: configJson, + toplevelConfig: configJson, base: path.dirname(config), configPath: config, }; } else { marker = { config: inputJson || {}, // not `inputBin` because only `input` + toplevelConfig: inputJson || {}, base: path.dirname(input), // is the place for `inputJson` configPath: input, }; diff --git a/lib/types.ts b/lib/types.ts index 89c41fd62..66039569a 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -36,6 +36,7 @@ export interface PkgOptions { scripts?: string[]; log?: (logger: typeof log, context: Record) => void; assets?: string[]; + ignore?: string[]; deployFiles?: string[]; patches?: Patches; dictionary: ConfigDictionary; diff --git a/lib/walker.ts b/lib/walker.ts index 418f5ca84..6f9ebad59 100644 --- a/lib/walker.ts +++ b/lib/walker.ts @@ -38,6 +38,7 @@ export interface Marker { hasDictionary?: boolean; activated?: boolean; toplevel?: boolean; + toplevelConfig: PackageJson; public?: boolean; hasDeployFiles?: boolean; config?: PackageJson; @@ -450,6 +451,21 @@ class Walker { assert(typeof task.file === 'string'); const realFile = toNormalizedRealPath(task.file); + const ignore = task.marker?.toplevelConfig.pkg?.ignore; + if (ignore) { + // check if the file matches one of the ignore regex patterns + const match = ignore.some((pattern) => + new RegExp(pattern).test(realFile), + ); + + if (match) { + log.debug( + `Ignoring file: ${realFile} due to top level config ignore pattern`, + ); + return; + } + } + if (realFile === task.file) { this.append(task); return; @@ -747,7 +763,12 @@ class Walker { const catchPackageFilter = (config: PackageJson, base: string) => { const newPackage = newPackages[newPackages.length - 1]; - newPackage.marker = { config, configPath: newPackage.packageJson, base }; + newPackage.marker = { + config, + configPath: newPackage.packageJson, + base, + toplevelConfig: marker.toplevelConfig, + }; }; let newFile = ''; diff --git a/test/test-50-ignore-files/.gitignore b/test/test-50-ignore-files/.gitignore new file mode 100644 index 000000000..736e8ae58 --- /dev/null +++ b/test/test-50-ignore-files/.gitignore @@ -0,0 +1 @@ +!node_modules \ No newline at end of file diff --git a/test/test-50-ignore-files/main.js b/test/test-50-ignore-files/main.js new file mode 100644 index 000000000..d06fd1be3 --- /dev/null +++ b/test/test-50-ignore-files/main.js @@ -0,0 +1,49 @@ +#!/usr/bin/env node + +'use strict'; + +const path = require('path'); +const assert = require('assert'); +const utils = require('../utils.js'); +const standard = 'stdout'; + +assert(!module.parent); +assert(__dirname === process.cwd()); + +const target = process.argv[2] || 'host'; +const output = './test-output.exe'; + +let left, right; +utils.mkdirp.sync(path.dirname(output)); + +left = utils.spawn.sync('node', ['test-x-index.js']); + +const inspect = + standard === 'stdout' + ? ['inherit', 'pipe', 'inherit'] + : ['inherit', 'inherit', 'pipe']; + +const log = utils.pkg.sync( + ['--target', target, '--output', output, '.', '--debug'], + inspect, +); + +assert( + log.indexOf( + 'node_modules/delta/useless.c due to top level config ignore pattern', + ) > 0, + 'useless.c file is not ignored', +); +assert( + log.indexOf( + 'node_modules/delta/needed.c is added to queue', + 'needed.c file is not added to queue', + ), +); + +right = utils.spawn.sync('./' + path.basename(output), [], { + cwd: path.dirname(output), +}); + +assert.strictEqual(left, right); +utils.vacuum.sync(output); diff --git a/test/test-50-ignore-files/node_modules/delta/index.js b/test/test-50-ignore-files/node_modules/delta/index.js new file mode 100644 index 000000000..53a4bbf98 --- /dev/null +++ b/test/test-50-ignore-files/node_modules/delta/index.js @@ -0,0 +1,3 @@ +'use strict'; + +global.FOO = 'bar'; diff --git a/test/test-50-ignore-files/node_modules/delta/needed.c b/test/test-50-ignore-files/node_modules/delta/needed.c new file mode 100644 index 000000000..045d6c487 --- /dev/null +++ b/test/test-50-ignore-files/node_modules/delta/needed.c @@ -0,0 +1 @@ +// Needed file to include in bundle \ No newline at end of file diff --git a/test/test-50-ignore-files/node_modules/delta/package.json b/test/test-50-ignore-files/node_modules/delta/package.json new file mode 100644 index 000000000..1c5ed3a50 --- /dev/null +++ b/test/test-50-ignore-files/node_modules/delta/package.json @@ -0,0 +1,5 @@ +{ + "name": "delta", + "main": "index.js", + "files": ["*.c"] +} diff --git a/test/test-50-ignore-files/node_modules/delta/useless.c b/test/test-50-ignore-files/node_modules/delta/useless.c new file mode 100644 index 000000000..f527564a3 --- /dev/null +++ b/test/test-50-ignore-files/node_modules/delta/useless.c @@ -0,0 +1 @@ +// Some useless files \ No newline at end of file diff --git a/test/test-50-ignore-files/package.json b/test/test-50-ignore-files/package.json new file mode 100644 index 000000000..03df3fcfe --- /dev/null +++ b/test/test-50-ignore-files/package.json @@ -0,0 +1,12 @@ +{ + "bin": "test-x-index.js", + "license": "MIT", + "dependencies": { + "delta": "*" + }, + "pkg": { + "ignore": [ + "/node_modules/delta/useless.c" + ] + } +} diff --git a/test/test-50-ignore-files/test-x-index.js b/test/test-50-ignore-files/test-x-index.js new file mode 100644 index 000000000..259ec4f9b --- /dev/null +++ b/test/test-50-ignore-files/test-x-index.js @@ -0,0 +1,5 @@ +'use strict'; + +var dataPath = 'delta'; +require(dataPath); +console.log(global.FOO); From 275d6c716939682f38a9c73fab908a7d4db9c7c7 Mon Sep 17 00:00:00 2001 From: Corentin Mors Date: Fri, 31 May 2024 17:38:49 +0200 Subject: [PATCH 02/10] Applying recommendations --- README.md | 36 +++++++++++++++++++------- lib/index.ts | 5 ++-- lib/options.ts | 23 ++++++++++++++++ lib/walker.ts | 10 +++---- package.json | 1 + test/test-50-ignore-files/package.json | 2 +- yarn.lock | 14 ++++++++++ 7 files changed, 72 insertions(+), 19 deletions(-) create mode 100644 lib/options.ts diff --git a/README.md b/README.md index 304f445f3..3726addd5 100644 --- a/README.md +++ b/README.md @@ -50,23 +50,23 @@ pkg [options] Examples: - – Makes executables for Linux, macOS and Windows + - Makes executables for Linux, macOS and Windows $ pkg index.js - – Takes package.json from cwd and follows 'bin' entry + - Takes package.json from cwd and follows 'bin' entry $ pkg . - – Makes executable for particular target machine + - Makes executable for particular target machine $ pkg -t node16-win-arm64 index.js - – Makes executables for target machines of your choice + - Makes executables for target machines of your choice $ pkg -t node16-linux,node18-linux,node16-win index.js - – Bakes '--expose-gc' and '--max-heap-size=34' into executable + - Bakes '--expose-gc' and '--max-heap-size=34' into executable $ pkg --options "expose-gc,max-heap-size=34" index.js - – Consider packageA and packageB to be public + - Consider packageA and packageB to be public $ pkg --public-packages "packageA,packageB" index.js - – Consider all packages to be public + - Consider all packages to be public $ pkg --public-packages "*" index.js - – Bakes '--expose-gc' into executable + - Bakes '--expose-gc' into executable $ pkg --options expose-gc index.js - – reduce size of the data packed inside the executable with GZip + - reduce size of the data packed inside the executable with GZip $ pkg --compress GZip index.js ``` @@ -181,6 +181,22 @@ See also [Detecting assets in source code](#detecting-assets-in-source-code) and [Snapshot filesystem](#snapshot-filesystem). +### Ignore files + +`ignore` is a list of globs. Files matching the paths specified as `ignore` +will be excluded from the final executable. + +This is useful when you want to exclude some files from the final executable, +like tests, documentation or build files that could have been included by a dependency. + +```json + "pkg": { + "ignore": [ "**/*/dependency-name/build.c" ] + } +``` + +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. + ### Options Node.js application can be called with runtime options @@ -413,7 +429,7 @@ printenv | grep NODE ## Advanced -### exploring virtual file system embedded in debug mode +### Exploring virtual file system embedded in debug mode When you are using the `--debug` flag when building your executable, `pkg` add the ability to display the content of the virtual file system diff --git a/lib/index.ts b/lib/index.ts index 8deb72a43..970a6511d 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -27,6 +27,7 @@ import walk, { Marker, WalkerParams } from './walker'; import { Target, NodeTarget, SymLinks } from './types'; import { CompressType } from './compress_type'; import { patchMachOExecutable, signMachOExecutable } from './mach-o'; +import pkgOptions from './options'; const { version } = JSON.parse( readFileSync(path.join(__dirname, '../package.json'), 'utf-8'), @@ -598,16 +599,16 @@ export async function exec(argv2: string[]) { let marker: Marker; if (configJson) { + pkgOptions.set(configJson.pkg); marker = { config: configJson, - toplevelConfig: configJson, base: path.dirname(config), configPath: config, }; } else { + pkgOptions.set(inputJson.pkg); marker = { config: inputJson || {}, // not `inputBin` because only `input` - toplevelConfig: inputJson || {}, base: path.dirname(input), // is the place for `inputJson` configPath: input, }; diff --git a/lib/options.ts b/lib/options.ts new file mode 100644 index 000000000..29b0fcfc8 --- /dev/null +++ b/lib/options.ts @@ -0,0 +1,23 @@ +import { PkgOptions } from './types'; + +class Options { + private options: PkgOptions; + + constructor() { + this.options = { + dictionary: {}, + }; + } + + public set(options: PkgOptions): void { + this.options = options; + } + + public get(): PkgOptions { + return this.options; + } +} + +const options = new Options(); + +export default options; diff --git a/lib/walker.ts b/lib/walker.ts index 6f9ebad59..7daebf91d 100644 --- a/lib/walker.ts +++ b/lib/walker.ts @@ -6,6 +6,7 @@ import isCore from 'is-core-module'; import globby from 'globby'; import path from 'path'; import chalk from 'chalk'; +import { minimatch } from 'minimatch'; import { ALIAS_AS_RELATIVE, @@ -33,12 +34,12 @@ import { PackageJson, SymLinks, } from './types'; +import pkgOptions from './options'; export interface Marker { hasDictionary?: boolean; activated?: boolean; toplevel?: boolean; - toplevelConfig: PackageJson; public?: boolean; hasDeployFiles?: boolean; config?: PackageJson; @@ -451,12 +452,10 @@ class Walker { assert(typeof task.file === 'string'); const realFile = toNormalizedRealPath(task.file); - const ignore = task.marker?.toplevelConfig.pkg?.ignore; + const { ignore } = pkgOptions.get(); if (ignore) { // check if the file matches one of the ignore regex patterns - const match = ignore.some((pattern) => - new RegExp(pattern).test(realFile), - ); + const match = ignore.some((pattern) => minimatch(realFile, pattern)); if (match) { log.debug( @@ -767,7 +766,6 @@ class Walker { config, configPath: newPackage.packageJson, base, - toplevelConfig: marker.toplevelConfig, }; }; diff --git a/package.json b/package.json index 76f42a453..00a7a5a2e 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "globby": "^11.1.0", "into-stream": "^6.0.0", "is-core-module": "2.9.0", + "minimatch": "9.0.4", "minimist": "^1.2.6", "multistream": "^4.1.0", "prebuild-install": "7.1.1", diff --git a/test/test-50-ignore-files/package.json b/test/test-50-ignore-files/package.json index 03df3fcfe..88f7aa7ae 100644 --- a/test/test-50-ignore-files/package.json +++ b/test/test-50-ignore-files/package.json @@ -6,7 +6,7 @@ }, "pkg": { "ignore": [ - "/node_modules/delta/useless.c" + "**/*/node_modules/delta/useless.c" ] } } diff --git a/yarn.lock b/yarn.lock index c76bae004..0b62d8f88 100644 --- a/yarn.lock +++ b/yarn.lock @@ -947,6 +947,13 @@ brace-expansion@^1.1.7: balanced-match "^1.0.0" concat-map "0.0.1" +brace-expansion@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" + integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== + dependencies: + balanced-match "^1.0.0" + braces@^3.0.2: version "3.0.2" resolved "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz" @@ -3199,6 +3206,13 @@ mimic-response@^4.0.0: resolved "https://registry.npmjs.org/mimic-response/-/mimic-response-4.0.0.tgz" integrity sha512-e5ISH9xMYU0DzrT+jl8q2ze9D6eWBto+I8CNpe+VI+K2J/F/k3PdkdTdz4wvGVH4NTpo+NRYTVIuMQEMMcsLqg== +minimatch@9.0.4: + version "9.0.4" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.4.tgz#8e49c731d1749cbec05050ee5145147b32496a51" + integrity sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw== + dependencies: + brace-expansion "^2.0.1" + minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2: version "3.1.2" resolved "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz" From 8d18bb4eba080fa973bf1d7897bcd278767bc9e2 Mon Sep 17 00:00:00 2001 From: Corentin Mors Date: Mon, 3 Jun 2024 16:12:20 +0200 Subject: [PATCH 03/10] Fix pnpm version for tests --- test/test-10-pnpm/main.js | 2 +- test/test-11-pnpm/main.js | 2 +- test/test-80-compression-node-opcua/main.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test-10-pnpm/main.js b/test/test-10-pnpm/main.js index c1abca6a9..26b183788 100644 --- a/test/test-10-pnpm/main.js +++ b/test/test-10-pnpm/main.js @@ -29,7 +29,7 @@ const pnpmlog = utils.spawn.sync( path.dirname(process.argv[0]), 'npx' + (process.platform === 'win32' ? '.cmd' : ''), ), - ['pnpm', 'install'], + ['pnpm@8', 'install'], { cwd: path.dirname(output), expect: 0 }, ); console.log('pnpm log :', pnpmlog); diff --git a/test/test-11-pnpm/main.js b/test/test-11-pnpm/main.js index d4821e00d..86819f4a0 100644 --- a/test/test-11-pnpm/main.js +++ b/test/test-11-pnpm/main.js @@ -30,7 +30,7 @@ const pnpmlog = utils.spawn.sync( path.dirname(process.argv[0]), 'npx' + (process.platform === 'win32' ? '.cmd' : ''), ), - ['pnpm', 'install'], + ['pnpm@8', 'install'], { cwd: path.dirname(output), expect: 0 }, ); console.log('pnpm log :', pnpmlog); diff --git a/test/test-80-compression-node-opcua/main.js b/test/test-80-compression-node-opcua/main.js index c93558611..50aac0ab1 100644 --- a/test/test-80-compression-node-opcua/main.js +++ b/test/test-80-compression-node-opcua/main.js @@ -38,7 +38,7 @@ const pnpmlog = utils.spawn.sync( path.dirname(process.argv[0]), 'npx' + (process.platform === 'win32' ? '.cmd' : ''), ), - ['pnpm', 'install'], + ['pnpm@8', 'install'], { cwd: path.dirname(__filename), expect: 0 }, ); console.log('pnpm log :', pnpmlog); From 3a893db8b994ca4503a69538ccc2271224acca97 Mon Sep 17 00:00:00 2001 From: Corentin Mors Date: Mon, 3 Jun 2024 17:21:56 +0200 Subject: [PATCH 04/10] Fix options --- lib/options.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/options.ts b/lib/options.ts index 29b0fcfc8..8045d2426 100644 --- a/lib/options.ts +++ b/lib/options.ts @@ -10,7 +10,7 @@ class Options { } public set(options: PkgOptions): void { - this.options = options; + this.options = { ...this.options, ...options }; } public get(): PkgOptions { From 665aa8e0d9c198c25c1eef4708cf30004f3a2bdf Mon Sep 17 00:00:00 2001 From: Corentin Mors Date: Mon, 3 Jun 2024 17:52:38 +0200 Subject: [PATCH 05/10] Config can be empty --- lib/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index 970a6511d..6a2213071 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -599,14 +599,14 @@ export async function exec(argv2: string[]) { let marker: Marker; if (configJson) { - pkgOptions.set(configJson.pkg); + pkgOptions.set(configJson?.pkg ?? {}); marker = { config: configJson, base: path.dirname(config), configPath: config, }; } else { - pkgOptions.set(inputJson.pkg); + pkgOptions.set(inputJson?.pkg ?? {}); marker = { config: inputJson || {}, // not `inputBin` because only `input` base: path.dirname(input), // is the place for `inputJson` From 0916e994f515f07898e6e768c35b6d11337416e7 Mon Sep 17 00:00:00 2001 From: Corentin Mors Date: Mon, 3 Jun 2024 18:18:21 +0200 Subject: [PATCH 06/10] Move to class set the empty management --- lib/index.ts | 4 ++-- lib/options.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index 6a2213071..dd7beb7af 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -599,14 +599,14 @@ export async function exec(argv2: string[]) { let marker: Marker; if (configJson) { - pkgOptions.set(configJson?.pkg ?? {}); + pkgOptions.set(configJson?.pkg); marker = { config: configJson, base: path.dirname(config), configPath: config, }; } else { - pkgOptions.set(inputJson?.pkg ?? {}); + pkgOptions.set(inputJson?.pkg); marker = { config: inputJson || {}, // not `inputBin` because only `input` base: path.dirname(input), // is the place for `inputJson` diff --git a/lib/options.ts b/lib/options.ts index 8045d2426..df0a759bf 100644 --- a/lib/options.ts +++ b/lib/options.ts @@ -10,7 +10,7 @@ class Options { } public set(options: PkgOptions): void { - this.options = { ...this.options, ...options }; + this.options = { ...this.options, ...(options ?? {}) }; } public get(): PkgOptions { From 51f481c2665f0f953c9c006d17db859fa14b1acd Mon Sep 17 00:00:00 2001 From: Corentin Mors Date: Tue, 4 Jun 2024 10:37:37 +0200 Subject: [PATCH 07/10] Installing pnpm globally instead --- test/test-10-pnpm/main.js | 5 ++++- test/test-11-pnpm/main.js | 5 ++++- test/test-80-compression-node-opcua/main.js | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/test/test-10-pnpm/main.js b/test/test-10-pnpm/main.js index 26b183788..80455abad 100644 --- a/test/test-10-pnpm/main.js +++ b/test/test-10-pnpm/main.js @@ -23,13 +23,16 @@ console.log('target = ', target); utils.vacuum.sync('./node_modules'); utils.vacuum.sync('./pnpm-lock.yaml'); +const npmlog = utils.exec.sync('npm install -g pnpm@8'); +console.log('npm log :', npmlog); + // launch `pnpm install` const pnpmlog = utils.spawn.sync( path.join( path.dirname(process.argv[0]), 'npx' + (process.platform === 'win32' ? '.cmd' : ''), ), - ['pnpm@8', 'install'], + ['pnpm', 'install'], { cwd: path.dirname(output), expect: 0 }, ); console.log('pnpm log :', pnpmlog); diff --git a/test/test-11-pnpm/main.js b/test/test-11-pnpm/main.js index 86819f4a0..fb3a6e71b 100644 --- a/test/test-11-pnpm/main.js +++ b/test/test-11-pnpm/main.js @@ -24,13 +24,16 @@ console.log('target = ', target); utils.vacuum.sync('./node_modules'); utils.vacuum.sync('./pnpm-lock.yaml'); +const npmlog = utils.exec.sync('npm install -g pnpm@8'); +console.log('npm log :', npmlog); + // launch `pnpm install` const pnpmlog = utils.spawn.sync( path.join( path.dirname(process.argv[0]), 'npx' + (process.platform === 'win32' ? '.cmd' : ''), ), - ['pnpm@8', 'install'], + ['pnpm', 'install'], { cwd: path.dirname(output), expect: 0 }, ); console.log('pnpm log :', pnpmlog); diff --git a/test/test-80-compression-node-opcua/main.js b/test/test-80-compression-node-opcua/main.js index 50aac0ab1..175abc318 100644 --- a/test/test-80-compression-node-opcua/main.js +++ b/test/test-80-compression-node-opcua/main.js @@ -32,13 +32,16 @@ function clean() { // remove any possible left-over clean(); +const npmlog = utils.exec.sync('npm install -g pnpm@8'); +console.log('npm log :', npmlog); + // launch `pnpm install` const pnpmlog = utils.spawn.sync( path.join( path.dirname(process.argv[0]), 'npx' + (process.platform === 'win32' ? '.cmd' : ''), ), - ['pnpm@8', 'install'], + ['pnpm', 'install'], { cwd: path.dirname(__filename), expect: 0 }, ); console.log('pnpm log :', pnpmlog); From 119e5bd99b90f57a8c6113f4b16adb1101ddab12 Mon Sep 17 00:00:00 2001 From: Corentin Mors Date: Tue, 4 Jun 2024 10:56:12 +0200 Subject: [PATCH 08/10] Remove full path from test-50-ignore --- test/test-50-ignore-files/main.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/test-50-ignore-files/main.js b/test/test-50-ignore-files/main.js index d06fd1be3..1db8e2592 100644 --- a/test/test-50-ignore-files/main.js +++ b/test/test-50-ignore-files/main.js @@ -29,14 +29,12 @@ const log = utils.pkg.sync( ); assert( - log.indexOf( - 'node_modules/delta/useless.c due to top level config ignore pattern', - ) > 0, + log.indexOf('useless.c due to top level config ignore pattern') > 0, 'useless.c file is not ignored', ); assert( log.indexOf( - 'node_modules/delta/needed.c is added to queue', + 'needed.c is added to queue', 'needed.c file is not added to queue', ), ); From 3724171fc7b2a06c1b590513829f82997603af53 Mon Sep 17 00:00:00 2001 From: Corentin Mors Date: Tue, 4 Jun 2024 11:01:15 +0200 Subject: [PATCH 09/10] Force windows to use local shell --- test/test-10-pnpm/main.js | 2 +- test/test-11-pnpm/main.js | 2 +- test/test-80-compression-node-opcua/main.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test-10-pnpm/main.js b/test/test-10-pnpm/main.js index 80455abad..8878370e2 100644 --- a/test/test-10-pnpm/main.js +++ b/test/test-10-pnpm/main.js @@ -33,7 +33,7 @@ const pnpmlog = utils.spawn.sync( 'npx' + (process.platform === 'win32' ? '.cmd' : ''), ), ['pnpm', 'install'], - { cwd: path.dirname(output), expect: 0 }, + { cwd: path.dirname(output), expect: 0, shell: true }, ); console.log('pnpm log :', pnpmlog); diff --git a/test/test-11-pnpm/main.js b/test/test-11-pnpm/main.js index fb3a6e71b..b5ef61da3 100644 --- a/test/test-11-pnpm/main.js +++ b/test/test-11-pnpm/main.js @@ -34,7 +34,7 @@ const pnpmlog = utils.spawn.sync( 'npx' + (process.platform === 'win32' ? '.cmd' : ''), ), ['pnpm', 'install'], - { cwd: path.dirname(output), expect: 0 }, + { cwd: path.dirname(output), expect: 0, shell: true }, ); console.log('pnpm log :', pnpmlog); diff --git a/test/test-80-compression-node-opcua/main.js b/test/test-80-compression-node-opcua/main.js index 175abc318..f4af90cd0 100644 --- a/test/test-80-compression-node-opcua/main.js +++ b/test/test-80-compression-node-opcua/main.js @@ -42,7 +42,7 @@ const pnpmlog = utils.spawn.sync( 'npx' + (process.platform === 'win32' ? '.cmd' : ''), ), ['pnpm', 'install'], - { cwd: path.dirname(__filename), expect: 0 }, + { cwd: path.dirname(__filename), expect: 0, shell: true }, ); console.log('pnpm log :', pnpmlog); From 87342ba4882846385211c6b0204c2acb3333eb65 Mon Sep 17 00:00:00 2001 From: Corentin Mors Date: Tue, 4 Jun 2024 12:04:17 +0200 Subject: [PATCH 10/10] Fix windows shell issues --- lib/options.ts | 2 +- test/test-10-pnpm/main.js | 8 +++----- test/test-11-pnpm/main.js | 8 +++----- test/test-80-compression-node-opcua/main.js | 17 ++++++----------- 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/lib/options.ts b/lib/options.ts index df0a759bf..6e34d13ec 100644 --- a/lib/options.ts +++ b/lib/options.ts @@ -10,7 +10,7 @@ class Options { } public set(options: PkgOptions): void { - this.options = { ...this.options, ...(options ?? {}) }; + this.options = options ?? this.options; } public get(): PkgOptions { diff --git a/test/test-10-pnpm/main.js b/test/test-10-pnpm/main.js index 8878370e2..ae06890eb 100644 --- a/test/test-10-pnpm/main.js +++ b/test/test-10-pnpm/main.js @@ -13,6 +13,7 @@ if (utils.shouldSkipPnpm()) { assert(__dirname === process.cwd()); +const isWindows = process.platform === 'win32'; const target = process.argv[2] || 'host'; const input = './test.js'; const output = './test-output.exe'; @@ -28,12 +29,9 @@ console.log('npm log :', npmlog); // launch `pnpm install` const pnpmlog = utils.spawn.sync( - path.join( - path.dirname(process.argv[0]), - 'npx' + (process.platform === 'win32' ? '.cmd' : ''), - ), + path.join(path.dirname(process.argv[0]), 'npx' + (isWindows ? '.cmd' : '')), ['pnpm', 'install'], - { cwd: path.dirname(output), expect: 0, shell: true }, + { cwd: path.dirname(output), expect: 0, shell: isWindows }, ); console.log('pnpm log :', pnpmlog); diff --git a/test/test-11-pnpm/main.js b/test/test-11-pnpm/main.js index b5ef61da3..f708e6b42 100644 --- a/test/test-11-pnpm/main.js +++ b/test/test-11-pnpm/main.js @@ -14,6 +14,7 @@ if (utils.shouldSkipPnpm()) { console.log(__dirname, process.cwd()); assert(__dirname === process.cwd()); +const isWindows = process.platform === 'win32'; const target = process.argv[2] || 'host'; const input = './test.js'; const output = './test-output.exe'; @@ -29,12 +30,9 @@ console.log('npm log :', npmlog); // launch `pnpm install` const pnpmlog = utils.spawn.sync( - path.join( - path.dirname(process.argv[0]), - 'npx' + (process.platform === 'win32' ? '.cmd' : ''), - ), + path.join(path.dirname(process.argv[0]), 'npx' + (isWindows ? '.cmd' : '')), ['pnpm', 'install'], - { cwd: path.dirname(output), expect: 0, shell: true }, + { cwd: path.dirname(output), expect: 0, shell: isWindows }, ); console.log('pnpm log :', pnpmlog); diff --git a/test/test-80-compression-node-opcua/main.js b/test/test-80-compression-node-opcua/main.js index f4af90cd0..60a060f46 100644 --- a/test/test-80-compression-node-opcua/main.js +++ b/test/test-80-compression-node-opcua/main.js @@ -14,6 +14,7 @@ const assert = require('assert'); const utils = require('../utils.js'); const pkgJson = require('./package.json'); +const isWindows = process.platform === 'win32'; const buildDir = 'build'; assert(!module.parent); @@ -37,12 +38,9 @@ console.log('npm log :', npmlog); // launch `pnpm install` const pnpmlog = utils.spawn.sync( - path.join( - path.dirname(process.argv[0]), - 'npx' + (process.platform === 'win32' ? '.cmd' : ''), - ), + path.join(path.dirname(process.argv[0]), 'npx' + (isWindows ? '.cmd' : '')), ['pnpm', 'install'], - { cwd: path.dirname(__filename), expect: 0, shell: true }, + { cwd: path.dirname(__filename), expect: 0, shell: isWindows }, ); console.log('pnpm log :', pnpmlog); @@ -57,7 +55,7 @@ assert( /* eslint-disable no-unused-vars */ const input = 'package.json'; const target = process.argv[2] || 'host'; -const ext = process.platform === 'win32' ? '.exe' : ''; +const ext = isWindows ? '.exe' : ''; const outputRef = path.join(buildDir, 'test-output-empty' + ext); const outputNone = path.join(buildDir, 'test-output-None' + ext); const outputGZip = path.join(buildDir, 'test-output-GZip' + ext); @@ -98,10 +96,7 @@ function pkgCompress(compressMode, output) { function esbuildBuild(entryPoint) { const log = utils.spawn.sync( - path.join( - path.dirname(process.argv[0]), - 'npx' + (process.platform === 'win32' ? '.cmd' : ''), - ), + path.join(path.dirname(process.argv[0]), 'npx' + (isWindows ? '.cmd' : '')), [ 'esbuild', entryPoint, @@ -109,7 +104,7 @@ function esbuildBuild(entryPoint) { '--outfile=' + path.join(buildDir, pkgJson.main), '--platform=node', ], - { cwd: __dirname, expect: 0 }, + { cwd: __dirname, expect: 0, shell: isWindows }, ); console.log(log);