Skip to content

Commit dc5d7c8

Browse files
authoredJun 23, 2024··
fix: @electron/remote wrongly into Windows app.asar (#8254)
1 parent 14942b7 commit dc5d7c8

File tree

3 files changed

+22
-50
lines changed

3 files changed

+22
-50
lines changed
 

‎.changeset/nice-weeks-sip.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"app-builder-lib": patch
3+
---
4+
5+
fix: @electron/remote wrongly into Windows app.asar

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class NodeModuleCopyHelper extends FileCopyHelper {
6565
const sortedFilePaths = await BluebirdPromise.map(
6666
childNames,
6767
name => {
68-
const filePath = dirPath + path.sep + name
68+
const filePath = path.join(dirPath, name)
6969

7070
const forceIncluded = onNodeModuleFile != null && !!onNodeModuleFile(filePath)
7171

‎packages/app-builder-lib/src/util/appFileCopier.ts

+16-49
Original file line numberDiff line numberDiff line change
@@ -19,44 +19,18 @@ const BOWER_COMPONENTS_PATTERN = `${path.sep}bower_components${path.sep}`
1919
/** @internal */
2020
export const ELECTRON_COMPILE_SHIM_FILENAME = "__shim.js"
2121

22-
function extractPathAfterLastNodeModules(src: string, file: string) {
23-
const srcComponents = src.split(path.sep)
24-
const lastNodeModulesIndex = srcComponents.lastIndexOf("node_modules")
25-
26-
if (lastNodeModulesIndex === -1 || lastNodeModulesIndex === srcComponents.length - 1) {
27-
return ""
28-
}
29-
30-
const pathAfterNodeModules = srcComponents.slice(lastNodeModulesIndex + 1).join(path.sep)
31-
32-
const matchIndex = file.indexOf(pathAfterNodeModules)
33-
34-
if (matchIndex === -1) {
35-
return ""
36-
}
37-
38-
const remainingPathStartIndex = matchIndex + pathAfterNodeModules.length
39-
if (remainingPathStartIndex >= file.length) {
40-
return ""
41-
}
42-
43-
const remainingPath = file.substring(remainingPathStartIndex).trim()
44-
return remainingPath.startsWith(path.sep) ? remainingPath.substring(1) : remainingPath
45-
}
46-
4722
export function getDestinationPath(file: string, fileSet: ResolvedFileSet) {
4823
if (file === fileSet.src) {
4924
return fileSet.destination
50-
} else {
51-
const src = fileSet.src
52-
const dest = fileSet.destination
53-
if (file.length > src.length && file.startsWith(src) && file[src.length] === path.sep) {
54-
return dest + file.substring(src.length)
55-
} else {
56-
const e = extractPathAfterLastNodeModules(src, file)
57-
return path.join(dest, e)
58-
}
5925
}
26+
27+
const src = fileSet.src
28+
const dest = fileSet.destination
29+
// get node_modules path relative to src and then append to dest
30+
if (file.startsWith(src)) {
31+
return path.join(dest, path.relative(src, file))
32+
}
33+
return dest
6034
}
6135

6236
export async function copyAppFiles(fileSet: ResolvedFileSet, packager: Packager, transformer: FileTransformer) {
@@ -214,28 +188,21 @@ export async function computeNodeModuleFileSets(platformPackager: PlatformPackag
214188
// serial execution because copyNodeModules is concurrent and so, no need to increase queue/pressure
215189
const result = new Array<ResolvedFileSet>()
216190
let index = 0
191+
const NODE_MODULES = "node_modules"
217192
for (const info of deps) {
218-
const source = platformPackager.info.appDir + path.sep + "node_modules" + path.sep + info.name
219-
// const source = platformPackager.info.appDir
220-
const destination = getDestinationPath(source, { src: mainMatcher.from, destination: mainMatcher.to, files: [], metadata: null as any })
221-
222-
// use main matcher patterns, so, user can exclude some files in such hoisted node modules
223-
// source here includes node_modules, but pattern base should be without because users expect that pattern "!node_modules/loot-core/src{,/**/*}" will work
224-
const matcher = new FileMatcher(path.dirname(platformPackager.info.appDir + path.sep + "node_modules"), destination, mainMatcher.macroExpander, mainMatcher.patterns)
193+
const source = info.dir
194+
const destination = path.join(mainMatcher.to, NODE_MODULES, info.name)
195+
// use main matcher patterns, so, user can exclude some files !node_modules/xxxx
196+
const matcher = new FileMatcher(path.dirname(path.dirname(source)), destination, mainMatcher.macroExpander, mainMatcher.patterns)
225197
const copier = new NodeModuleCopyHelper(matcher, platformPackager.info)
226198
const files = await copier.collectNodeModules(info, nodeModuleExcludedExts)
227199
result[index++] = validateFileSet({ src: source, destination, files, metadata: copier.metadata })
228200

229201
if (info.conflictDependency) {
230202
for (const dep of info.conflictDependency) {
231-
const source = platformPackager.info.appDir + path.sep + "node_modules" + path.sep + info.name + path.sep + "node_modules" + path.sep + dep.name
232-
const destination = getDestinationPath(source, { src: mainMatcher.from, destination: mainMatcher.to, files: [], metadata: null as any })
233-
const matcher = new FileMatcher(
234-
path.dirname(platformPackager.info.appDir + path.sep + "node_modules" + path.sep + info.name + path.sep + "node_modules"),
235-
destination,
236-
mainMatcher.macroExpander,
237-
mainMatcher.patterns
238-
)
203+
const source = dep.dir
204+
const destination = path.join(mainMatcher.to, NODE_MODULES, info.name, NODE_MODULES, dep.name)
205+
const matcher = new FileMatcher(path.dirname(path.dirname(source)), destination, mainMatcher.macroExpander, mainMatcher.patterns)
239206
const copier = new NodeModuleCopyHelper(matcher, platformPackager.info)
240207
result[index++] = validateFileSet({ src: source, destination, files: await copier.collectNodeModules(dep, nodeModuleExcludedExts), metadata: copier.metadata })
241208
}

0 commit comments

Comments
 (0)
Please sign in to comment.