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
feat: App builder bin 5.0 #8147
Changes from 9 commits
3c857ba
ce3e7c3
341cb13
b63495c
5cc4902
8d7aa73
2c06361
62a5d55
e2af888
5bbf0f6
269e837
7f73cd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,26 +18,73 @@ const BOWER_COMPONENTS_PATTERN = `${path.sep}bower_components${path.sep}` | |
/** @internal */ | ||
export const ELECTRON_COMPILE_SHIM_FILENAME = "__shim.js" | ||
|
||
export function getDestinationPath(file: string, fileSet: ResolvedFileSet) { | ||
if (file === fileSet.src) { | ||
function removePnpmAndNextTwoFolders(file: string) { | ||
// Split the path into parts | ||
const parts = file.split(path.sep) | ||
|
||
// Find the index of the '.pnpm' folder | ||
const pnpmIndex = parts.findIndex(part => part === ".pnpm") | ||
|
||
// If '.pnpm' is found, and there are at least two more folders after it | ||
if (pnpmIndex >= 0 && parts.length > pnpmIndex + 2) { | ||
// Remove '.pnpm' and the next two folders from the parts array | ||
parts.splice(pnpmIndex, 3) | ||
} | ||
|
||
// Rejoin the remaining parts back into a path string | ||
return parts.join(path.sep) | ||
} | ||
|
||
function getHoistedModulePath(filePath: string, destination: string): string { | ||
const filePathParts: string[] = filePath.split(path.sep) | ||
const destinationParts: string[] = destination.split(path.sep) | ||
|
||
const nodeModulesIndicesFilePath: number[] = filePathParts.reduce((acc: number[], part: string, index: number) => { | ||
if (part === "node_modules") acc.push(index) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: Please move this to new line
Same comment applies to line 41 |
||
return acc | ||
}, []) | ||
|
||
const nodeModulesIndicesDestination: number[] = destinationParts.reduce((acc: number[], part: string, index: number) => { | ||
if (part === "node_modules") acc.push(index) | ||
return acc | ||
}, []) | ||
|
||
if (nodeModulesIndicesDestination.length === 0) { | ||
// If no 'node_modules' in destination, append from the first 'node_modules' in filePath | ||
if (nodeModulesIndicesFilePath.length > 0) { | ||
const firstNodeModulesIndexFilePath: number = nodeModulesIndicesFilePath[0] | ||
return path.join(destination, ...filePathParts.slice(firstNodeModulesIndexFilePath)) | ||
} | ||
// If also no 'node_modules' in filePath, return destination as is | ||
return destination | ||
} | ||
|
||
const targetNodeModulesIndex: number = nodeModulesIndicesDestination[nodeModulesIndicesFilePath.length - 1] || nodeModulesIndicesDestination.slice(-1)[0] | ||
|
||
if (nodeModulesIndicesFilePath.length === 0) { | ||
return 'Error: The specified file path does not contain "node_modules"' | ||
} | ||
|
||
const basePath: string = destinationParts.slice(0, targetNodeModulesIndex + 1).join(path.sep) | ||
const newPath: string = path.join(basePath, ...filePathParts.slice(nodeModulesIndicesFilePath.slice(-1)[0] + 1)) | ||
|
||
return newPath | ||
} | ||
|
||
export function getDestinationPath(filePath: string, fileSet: ResolvedFileSet) { | ||
if (filePath === fileSet.src) { | ||
return fileSet.destination | ||
} else { | ||
const src = fileSet.src | ||
const src = removePnpmAndNextTwoFolders(fileSet.src) | ||
const dest = fileSet.destination | ||
const file = removePnpmAndNextTwoFolders(filePath) | ||
if (file.length > src.length && file.startsWith(src) && file[src.length] === path.sep) { | ||
return dest + file.substring(src.length) | ||
} else { | ||
// hoisted node_modules | ||
// not lastIndexOf, to ensure that nested module (top-level module depends on) copied to parent node_modules, not to top-level directory | ||
// project https://github.com/angexis/punchcontrol/commit/cf929aba55c40d0d8901c54df7945e1d001ce022 | ||
let index = file.indexOf(NODE_MODULES_PATTERN) | ||
if (index < 0 && file.endsWith(`${path.sep}node_modules`)) { | ||
index = file.length - 13 | ||
} | ||
if (index < 0) { | ||
throw new Error(`File "${file}" not under the source directory "${fileSet.src}"`) | ||
} | ||
return dest + file.substring(index) | ||
return getHoistedModulePath(file, dest) | ||
} | ||
} | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ Object { | |
"foo": Object { | ||
"files": Object { | ||
"package.json": Object { | ||
"offset": "0", | ||
"offset": "4310", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an odd change. What's at offset |
||
"size": 127, | ||
}, | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we able to make this guarantee that the two nested folders within
.pnpm
folder are okay to be removed? Are they unnecessary symlinks or something?