Skip to content

Commit

Permalink
fix(core): custom executor package resolution should work when not us…
Browse files Browse the repository at this point in the history
…ing nx-plugin (#10624)
  • Loading branch information
AgentEnder committed Jun 7, 2022
1 parent 5809b8b commit adec3e0
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/nx/src/utils/package-json.ts
Expand Up @@ -110,10 +110,13 @@ export function readModulePackageJson(
path: string;
} {
let packageJsonPath: string;
let packageJson: PackageJson;

try {
packageJsonPath = require.resolve(`${moduleSpecifier}/package.json`, {
paths: requirePaths,
});
packageJson = readJsonFile(packageJsonPath);
} catch {
const entryPoint = require.resolve(moduleSpecifier, {
paths: requirePaths,
Expand All @@ -125,14 +128,13 @@ export function readModulePackageJson(
moduleRootPath = dirname(moduleRootPath);
packageJsonPath = join(moduleRootPath, 'package.json');
}
}

const packageJson = readJsonFile(packageJsonPath);

if (packageJson.name !== moduleSpecifier) {
throw new Error(
`Found module ${packageJson.name} while trying to locate ${moduleSpecifier}/package.json`
);
packageJson = readJsonFile(packageJsonPath);
if (packageJson.name && packageJson.name !== moduleSpecifier) {
throw new Error(
`Found module ${packageJson.name} while trying to locate ${moduleSpecifier}/package.json`
);
}
}

return {
Expand Down

0 comments on commit adec3e0

Please sign in to comment.