Skip to content

Commit

Permalink
feat: Support Yarn PnP
Browse files Browse the repository at this point in the history
  • Loading branch information
jclab-joseph committed Dec 14, 2023
1 parent 5fa7ff5 commit 977f624
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/api/core/src/api/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export default autoTrace(
} as NodeJS.ProcessEnv,
};

spawnOpts.env.NODE_OPTIONS = removePnpLoaderArguments(spawnOpts.env.NODE_OPTIONS);
if (runAsNode) {
spawnOpts.env.ELECTRON_RUN_AS_NODE = 'true';
} else {
Expand Down Expand Up @@ -231,3 +232,11 @@ export default autoTrace(
return spawned;
}
);

export function removePnpLoaderArguments(input: string | undefined): string | undefined {
if (!input) return input;
return input.replace(
/(--require\s+[^"].+\.pnp\.cjs)|(--experimental-loader\s+[^"].+\.pnp\.loader\.mjs)|(--require\s+".+\.pnp\.cjs")|(--experimental-loader\s+".+\.pnp\.loader\.mjs")/g,
''
);
}
7 changes: 7 additions & 0 deletions packages/utils/core-utils/src/electron-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ function getElectronModuleName(packageJSON: PackageJSONWithDeps): string {
async function getElectronPackageJSONPath(dir: string, packageName: string): Promise<string | undefined> {
const nodeModulesPath = await determineNodeModulesPath(dir, packageName);
if (!nodeModulesPath) {
try {
// Yarn PnP
// eslint-disable-next-line node/no-missing-require
return require.resolve('electron/package.json');
} catch (e) {
// Ignore
}
throw new PackageNotFoundError(packageName, dir);
}

Expand Down

0 comments on commit 977f624

Please sign in to comment.