fix(core): do not create projects twice from package.json (#26700)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> NPM scripts show up twice in the project details view.  ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> NPM scripts only show up once in the project details view.  ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
This commit is contained in:
parent
a0e8f83672
commit
c2c6a13514
@ -18,9 +18,13 @@ describe('nx project.json plugin', () => {
|
||||
};
|
||||
});
|
||||
|
||||
it('should build projects from project.json', () => {
|
||||
it('should build projects from package.json next to project.json', () => {
|
||||
memfs.vol.fromJSON(
|
||||
{
|
||||
'package.json': JSON.stringify({
|
||||
name: 'lib-a',
|
||||
description: 'lib-a project description',
|
||||
}),
|
||||
'packages/lib-a/project.json': JSON.stringify({
|
||||
name: 'lib-a',
|
||||
description: 'lib-a project description',
|
||||
@ -85,4 +89,38 @@ describe('nx project.json plugin', () => {
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('should not build package manager workspace projects from package.json next to project.json', () => {
|
||||
memfs.vol.fromJSON(
|
||||
{
|
||||
'package.json': JSON.stringify({
|
||||
name: 'lib-a',
|
||||
description: 'lib-a project description',
|
||||
workspaces: ['packages/lib-a'],
|
||||
}),
|
||||
'packages/lib-a/project.json': JSON.stringify({
|
||||
name: 'lib-a',
|
||||
description: 'lib-a project description',
|
||||
targets: {
|
||||
build: {
|
||||
executor: 'nx:run-commands',
|
||||
options: {},
|
||||
},
|
||||
},
|
||||
}),
|
||||
'packages/lib-a/package.json': JSON.stringify({
|
||||
name: 'lib-a',
|
||||
description: 'lib-a package description',
|
||||
scripts: {
|
||||
test: 'jest',
|
||||
},
|
||||
}),
|
||||
},
|
||||
'/root'
|
||||
);
|
||||
|
||||
expect(
|
||||
createNodesFunction('packages/lib-a/project.json', undefined, context)
|
||||
).toMatchInlineSnapshot(`{}`);
|
||||
});
|
||||
});
|
||||
|
||||
@ -9,6 +9,7 @@ import {
|
||||
getTagsFromPackageJson,
|
||||
readTargetsFromPackageJson,
|
||||
} from '../../../utils/package-json';
|
||||
import { buildPackageJsonWorkspacesMatcher } from '../../package-json-workspaces';
|
||||
|
||||
// TODO: Remove this one day, this should not need to be done.
|
||||
|
||||
@ -42,8 +43,16 @@ function createProjectFromPackageJsonNextToProjectJson(
|
||||
workspaceRoot: string
|
||||
): ProjectConfiguration | null {
|
||||
const root = dirname(projectJsonPath);
|
||||
const packageJsonPath = join(workspaceRoot, root, 'package.json');
|
||||
if (!existsSync(packageJsonPath)) {
|
||||
const relativePackageJsonPath = join(root, 'package.json');
|
||||
const packageJsonPath = join(workspaceRoot, relativePackageJsonPath);
|
||||
const readJson = (f) => readJsonFile(join(workspaceRoot, f));
|
||||
|
||||
// Do not create projects for package.json files
|
||||
// that are part of the package manager workspaces
|
||||
// Those package.json files will be processed later on
|
||||
const matcher = buildPackageJsonWorkspacesMatcher(workspaceRoot, readJson);
|
||||
|
||||
if (!existsSync(packageJsonPath) || matcher(relativePackageJsonPath)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user