Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix the main matcher patterns for !node_modules/@test/xxxx #8547

Merged
merged 11 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/three-fans-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-lib": patch
---

fix the main matcher patterns for !node_modules/xxxx
24 changes: 17 additions & 7 deletions packages/app-builder-lib/src/util/appFileCopier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,32 +188,42 @@ export async function computeNodeModuleFileSets(platformPackager: PlatformPackag
const result = new Array<ResolvedFileSet>()
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
Expand Down
1 change: 1 addition & 0 deletions test/src/globTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
Loading