diff --git a/.changeset/three-fans-worry.md b/.changeset/three-fans-worry.md new file mode 100644 index 00000000000..9500fea14bb --- /dev/null +++ b/.changeset/three-fans-worry.md @@ -0,0 +1,5 @@ +--- +"app-builder-lib": patch +--- + +fix the main matcher patterns for !node_modules/xxxx diff --git a/packages/app-builder-lib/src/util/appFileCopier.ts b/packages/app-builder-lib/src/util/appFileCopier.ts index 93a4a645693..cd3b8f82247 100644 --- a/packages/app-builder-lib/src/util/appFileCopier.ts +++ b/packages/app-builder-lib/src/util/appFileCopier.ts @@ -188,32 +188,42 @@ export async function computeNodeModuleFileSets(platformPackager: PlatformPackag const result = new Array() let index = 0 const NODE_MODULES = "node_modules" - const getRealSource = (source: string) => { - const parentDir = path.dirname(source) + const getRealSource = (name: string, source: string) => { + const normalizedName = name.split("/").join(path.sep) + if (!source.endsWith(normalizedName)) { + throw new Error("Path does not end with the package name") + } + + // get the parent dir of the package, input: /root/path/node_modules/@electron/remote, output: /root/path/node_modules + const parentDir = source.slice(0, -normalizedName.length - 1) + // for the local node modules which is not in node modules if (!parentDir.endsWith(path.sep + NODE_MODULES)) { return parentDir } - // use main matcher patterns, so, user can exclude some files !node_modules/xxxx + + // use main matcher patterns,return parent dir of the node_modules, so user can exclude some files !node_modules/xxxx return path.dirname(parentDir) } - const collectNodeModules = async (dep: NodeModuleInfo, destination: string) => { + + const collectNodeModules = async (dep: NodeModuleInfo, realSource: string, destination: string) => { const source = dep.dir - const matcher = new FileMatcher(getRealSource(source), destination, mainMatcher.macroExpander, mainMatcher.patterns) + const matcher = new FileMatcher(realSource, destination, mainMatcher.macroExpander, mainMatcher.patterns) const copier = new NodeModuleCopyHelper(matcher, platformPackager.info) const files = await copier.collectNodeModules(dep, nodeModuleExcludedExts) result[index++] = validateFileSet({ src: source, destination, files, metadata: copier.metadata }) if (dep.conflictDependency) { for (const c of dep.conflictDependency) { - await collectNodeModules(c, path.join(destination, NODE_MODULES, c.name)) + await collectNodeModules(c, realSource, path.join(destination, NODE_MODULES, c.name)) } } } for (const dep of deps) { const destination = path.join(mainMatcher.to, NODE_MODULES, dep.name) - await collectNodeModules(dep, destination) + const realSource = getRealSource(dep.name, dep.dir) + await collectNodeModules(dep, realSource, destination) } return result diff --git a/test/src/globTest.ts b/test/src/globTest.ts index f7abca6f329..613834277c2 100644 --- a/test/src/globTest.ts +++ b/test/src/globTest.ts @@ -168,6 +168,7 @@ test.ifAll.ifDevOrLinuxCi("ignore node_modules", () => { //noinspection SpellCheckingInspection data.dependencies = { "ci-info": "2.0.0", + "@electron/remote": "2.1.2", } }), packed: context => {