Skip to content

Commit 28753e8

Browse files
committed
tmp save
1 parent 27653af commit 28753e8

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

packages/app-builder-lib/src/node-module-collector/nodeModulesCollector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ export abstract class NodeModulesCollector<ProdDepType extends Dependency<ProdDe
323323
}
324324

325325
async asyncExec(command: string, args: string[], cwd: string = this.rootDir): Promise<{ stdout: string | undefined; stderr: string | undefined }> {
326-
const payload = await execAsync([`"${command}"`, ...args].join(" "), { cwd, maxBuffer: 100 * 1024 * 1024, encoding: "utf8" }).catch(err => {
326+
const payload = await execAsync([command, ...args].join(" "), { cwd, maxBuffer: 100 * 1024 * 1024, encoding: "utf8" }).catch(err => {
327327
log.error({ err }, "failed to execute command")
328328
return { stdout: undefined, stderr: err.message }
329329
})

packages/app-builder-lib/src/node-module-collector/yarnBerryNodeModulesCollector.ts

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ export class YarnBerryNodeModulesCollector extends NpmNodeModulesCollector {
4444
let nodeLinker: YarnSetupInfo["nodeLinker"] = null
4545
let nmHoistingLimits: YarnSetupInfo["nmHoistingLimits"] = null
4646

47-
const output = await this.asyncExec("yarn", ["config", "list", "--json"], rootDir)
47+
const output = await this.asyncExec("yarn", ["config", "--json"], rootDir)
4848

49-
if (output.stdout == null) {
50-
log.debug({ stderr: output.stderr }, "there was no config output, falling back to hoisted mode")
49+
if (!output.stdout) {
5150
return {
5251
yarnVersion,
5352
nodeLinker,
@@ -57,32 +56,45 @@ export class YarnBerryNodeModulesCollector extends NpmNodeModulesCollector {
5756
}
5857
}
5958

60-
// Yarn prints multiple JSON lines; find the one with type: 'inspect'
61-
const parsed = output.stdout
59+
// Yarn 1: multi-line stream with type:"inspect" (not used in this file anyways)
60+
// Yarn 2–3: multi-line stream with type:"inspect"
61+
// Yarn 4: single JSON object, no "type"
62+
const lines = output.stdout
6263
.split("\n")
6364
.map(l => l.trim())
6465
.filter(Boolean)
65-
.map(l => {
66-
try {
67-
return JSON.parse(l)
68-
} catch {
69-
return undefined
66+
67+
let data: any = null
68+
69+
for (const line of lines) {
70+
try {
71+
const parsed = JSON.parse(line)
72+
73+
// Yarn 4: direct object
74+
if (parsed.rc || parsed.manifest) {
75+
data = parsed
76+
break
7077
}
71-
})
72-
.filter(Boolean)
73-
.find(l => l.type === "inspect")
7478

75-
if (parsed) {
76-
const data = parsed.data?.["rc"] || parsed.data || {}
79+
// Yarn 1–3: inspect event
80+
if (parsed.type === "inspect") {
81+
data = parsed.data
82+
break
83+
}
84+
} catch {
85+
// ignore non-JSON lines
86+
}
87+
}
7788

78-
yarnVersion = parsed.data?.["manifest"]?.version ?? null
79-
nodeLinker = data["nodeLinker"] ?? null
80-
nmHoistingLimits = data["nmHoistingLimits"] ?? null
89+
if (data) {
90+
const rc = data.rc || data // Yarn 4: rc in root; Yarn 2–3: rc inside data
91+
yarnVersion = data.manifest?.version ?? null
92+
nodeLinker = rc.nodeLinker ?? null
93+
nmHoistingLimits = rc.nmHoistingLimits ?? null
8194
}
8295

83-
// Determine if using PnP
8496
const isPnP = nodeLinker === "pnp"
85-
const isHoisted = isPnP ? false : nmHoistingLimits === "dependencies" || nmHoistingLimits === "workspaces"
97+
const isHoisted = !isPnP && (nmHoistingLimits === "dependencies" || nmHoistingLimits === "workspaces")
8698

8799
return {
88100
yarnVersion,

0 commit comments

Comments
 (0)