Skip to content

Commit bb4a8c0

Browse files
authored
feat: allow onNodeModuleFile to return a boolean to force include the package to be copied (#8043)
1 parent 63a0044 commit bb4a8c0

File tree

8 files changed

+3707
-95
lines changed

8 files changed

+3707
-95
lines changed

.changeset/little-pumas-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"app-builder-lib": minor
3+
---
4+
5+
feat: allow `onNodeModuleFile` to return a boolean to force include the package to be copied

docs/configuration/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Env file `electron-builder.env` in the current dir ([example](https://github.com
169169
<p><code id="Configuration-appxManifestCreated">appxManifestCreated</code> module:app-builder-lib/out/configuration.__type | String | “undefined” - Appx manifest created on disk - not packed into .appx package yet.</p>
170170
</li>
171171
<li>
172-
<p><code id="Configuration-onNodeModuleFile">onNodeModuleFile</code> - The function (or path to file or module id) to be <a href="#onnodemodulefile">run on each node module</a> file.</p>
172+
<p><code id="Configuration-onNodeModuleFile">onNodeModuleFile</code> - The function (or path to file or module id) to be <a href="#onnodemodulefile">run on each node module</a> file. Returning <code>true</code>/<code>false</code> will determine whether to force include or to use the default copier logic</p>
173173
</li>
174174
<li>
175175
<p><code id="Configuration-beforeBuild">beforeBuild</code> (context: BeforeBuildContext) =&gt; Promise | null - The function (or path to file or module id) to be run before dependencies are installed or rebuilt. Works when <code>npmRebuild</code> is set to <code>true</code>. Resolving to <code>false</code> will skip dependencies install or rebuild.</p>

packages/app-builder-lib/scheme.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7529,7 +7529,7 @@
75297529
]
75307530
}
75317531
],
7532-
"description": "The function (or path to file or module id) to be [run on each node module](#onnodemodulefile) file."
7532+
"description": "The function (or path to file or module id) to be [run on each node module](#onnodemodulefile) file. Returning `true`/`false` will determine whether to force include or to use the default copier logic"
75337533
},
75347534
"p5p": {
75357535
"anyOf": [

packages/app-builder-lib/src/configuration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ export interface Configuration extends PlatformSpecificBuildOptions {
245245
*/
246246
readonly appxManifestCreated?: ((path: string) => Promise<any> | any) | string | null
247247
/**
248-
* The function (or path to file or module id) to be [run on each node module](#onnodemodulefile) file.
248+
* The function (or path to file or module id) to be [run on each node module](#onnodemodulefile) file. Returning `true`/`false` will determine whether to force include or to use the default copier logic
249249
*/
250-
readonly onNodeModuleFile?: ((file: string) => void) | string | null
250+
readonly onNodeModuleFile?: ((path: string) => void | boolean) | string | null
251251
/**
252252
* The function (or path to file or module id) to be run before dependencies are installed or rebuilt. Works when `npmRebuild` is set to `true`. Resolving to `false` will skip dependencies install or rebuild.
253253
*

packages/app-builder-lib/src/util/NodeModuleCopyHelper.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const topLevelExcludedFiles = new Set([
2323
"Readme",
2424
"readme",
2525
"test",
26-
"__tests__",
2726
"tests",
27+
"__tests__",
2828
"powered-test",
2929
"example",
3030
"examples",
@@ -64,38 +64,39 @@ export class NodeModuleCopyHelper extends FileCopyHelper {
6464
const sortedFilePaths = await BluebirdPromise.map(
6565
childNames,
6666
name => {
67-
if (onNodeModuleFile != null) {
68-
onNodeModuleFile(dirPath + path.sep + name)
69-
}
67+
const filePath = dirPath + path.sep + name
68+
69+
const forceIncluded = onNodeModuleFile != null && !!onNodeModuleFile(filePath)
7070

7171
if (excludedFiles.has(name) || name.startsWith("._")) {
7272
return null
7373
}
7474

75-
for (const ext of nodeModuleExcludedExts) {
76-
if (name.endsWith(ext)) {
77-
return null
75+
if (!forceIncluded) {
76+
for (const ext of nodeModuleExcludedExts) {
77+
if (name.endsWith(ext)) {
78+
return null
79+
}
7880
}
79-
}
8081

81-
// noinspection SpellCheckingInspection
82-
if (isTopLevel && (topLevelExcludedFiles.has(name) || (moduleName === "libui-node" && (name === "build" || name === "docs" || name === "src")))) {
83-
return null
84-
}
82+
// noinspection SpellCheckingInspection
83+
if (isTopLevel && (topLevelExcludedFiles.has(name) || (moduleName === "libui-node" && (name === "build" || name === "docs" || name === "src")))) {
84+
return null
85+
}
8586

86-
if (dirPath.endsWith("build")) {
87-
if (name === "gyp-mac-tool" || name === "Makefile" || name.endsWith(".mk") || name.endsWith(".gypi") || name.endsWith(".Makefile")) {
87+
if (dirPath.endsWith("build")) {
88+
if (name === "gyp-mac-tool" || name === "Makefile" || name.endsWith(".mk") || name.endsWith(".gypi") || name.endsWith(".Makefile")) {
89+
return null
90+
}
91+
} else if (dirPath.endsWith("Release") && (name === ".deps" || name === "obj.target")) {
92+
return null
93+
} else if (name === "src" && (dirPath.endsWith("keytar") || dirPath.endsWith("keytar-prebuild"))) {
94+
return null
95+
} else if (dirPath.endsWith("lzma-native") && (name === "build" || name === "deps")) {
8896
return null
8997
}
90-
} else if (dirPath.endsWith("Release") && (name === ".deps" || name === "obj.target")) {
91-
return null
92-
} else if (name === "src" && (dirPath.endsWith("keytar") || dirPath.endsWith("keytar-prebuild"))) {
93-
return null
94-
} else if (dirPath.endsWith("lzma-native") && (name === "build" || name === "deps")) {
95-
return null
9698
}
9799

98-
const filePath = dirPath + path.sep + name
99100
return lstat(filePath).then(stat => {
100101
if (filter != null && !filter(filePath, stat)) {
101102
return null

0 commit comments

Comments
 (0)