Skip to content

Commit

Permalink
fix: fix the main matcher patterns for !node_modules/@test/xxxx (elec…
Browse files Browse the repository at this point in the history
…tron-userland#8547)

fix electron-userland#8460

Reproducible demo
```
{
  "name": "TestApp",
  "productName": "Test App ßW",
  "description": "My Electron application description",
  "keywords": [],
  "main": "./main.js",
  "version": "1.0.0",
  "author": "beyondkmp",
  "scripts": {
    "start": "electron .",
    "dist": "electron-builder"
  },
  "license": "MIT",
  "build": {
    "appId": "electron-blog-example",
       "files": [
        "!node_modules/@electron/remote/*"
       ],
    "win": {
      "target": "nsis"
    }
  },
  "devDependencies": {
    "electron": "32.1.0",
    "electron-builder": "25.1.6"
  },
  "dependencies": {
     "tar": "7.4.3",
     "@electron/remote": "2.1.2"
  }
}
```

---------

Co-authored-by: beyondkmp <[email protected]>
  • Loading branch information
2 people authored and xyloflake committed Oct 2, 2024
1 parent acbc60f commit 7487c0d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
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

0 comments on commit 7487c0d

Please sign in to comment.