Skip to content

Commit b49c2d0

Browse files
committed
find root dir
1 parent 4a4133c commit b49c2d0

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

packages/app-builder-lib/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"dotenv-expand": "^11.0.6",
6767
"ejs": "^3.1.8",
6868
"electron-publish": "workspace:*",
69+
"find-up": "^5.0.0",
6970
"fs-extra": "^10.1.0",
7071
"hosted-git-info": "^4.1.0",
7172
"isbinaryfile": "^5.0.0",
@@ -104,6 +105,7 @@
104105
"@babel/preset-react": "7.24.7",
105106
"@types/debug": "4.1.7",
106107
"@types/ejs": "3.1.0",
108+
"@types/find-up": "^4.0.2",
107109
"@types/hosted-git-info": "3.0.2",
108110
"@types/js-yaml": "4.0.3",
109111
"@types/plist": "3.0.5",

packages/app-builder-lib/src/asar/asarUtil.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { PlatformPackager } from "../platformPackager"
99
import { ResolvedFileSet, getDestinationPath } from "../util/appFileCopier"
1010
import { detectUnpackedDirs } from "./unpackDetector"
1111
import { Readable } from "stream"
12+
import * as findUp from "find-up"
13+
import { readdir } from "fs/promises"
1214

1315
/** @internal */
1416
export class AsarPackager {
@@ -143,8 +145,9 @@ export class AsarPackager {
143145
return { path: destination, streamGenerator, unpacked, type: "file", stat: { mode: stat.mode, size } }
144146
}
145147

148+
const rootDir = (await findWorkspaceRoot(fileSet.src)) ?? fileSet.src
146149
const realPathFile = await fs.realpath(file)
147-
const realPathRelative = path.relative(fileSet.src, realPathFile)
150+
const realPathRelative = path.relative(rootDir, realPathFile)
148151
const isOutsidePackage = realPathRelative.startsWith("..")
149152
if (isOutsidePackage) {
150153
log.error({ source: log.filePath(file), realPathFile: log.filePath(realPathFile) }, `unable to copy, file is symlinked outside the package`)
@@ -231,3 +234,34 @@ export class AsarPackager {
231234
}
232235
}
233236
}
237+
238+
async function findWorkspaceRoot(startDir: string): Promise<string | undefined> {
239+
// Look for the workspace marker files
240+
const file = await findUp(
241+
async directory => {
242+
const dirContents = await readdir(directory)
243+
const marker = ["pnpm-workspace.yaml", "package.json"].find(marker => dirContents.includes(marker))
244+
return dirContents.includes(".git") && !marker ? findUp.stop : marker
245+
},
246+
{ cwd: startDir }
247+
)
248+
249+
if (!file) {
250+
return undefined
251+
}
252+
253+
// If it's package.json, make sure it has "workspaces"
254+
if (file.endsWith("package.json")) {
255+
const pkg = await fs.readJson(file)
256+
const newDir = path.dirname(file)
257+
if (pkg.workspaces || pkg.pnpm || pkg.workspaces?.packages) {
258+
return newDir
259+
} else {
260+
// Keep looking up in case a parent has it
261+
return findWorkspaceRoot(path.dirname(newDir))
262+
}
263+
}
264+
265+
// If it's pnpm-workspace.yaml, assume root
266+
return path.dirname(file)
267+
}

pnpm-lock.yaml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)