Skip to content
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

fix(core): custom executor package resolution should work when not using nx-plugin #10624

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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