Skip to content

Commit

Permalink
fix(misc): prevent unexpected targets from root package.json when set…
Browse files Browse the repository at this point in the history
…ting up root project (#17805)
  • Loading branch information
AgentEnder committed Jun 26, 2023
1 parent 38101fd commit c6ad657
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
45 changes: 44 additions & 1 deletion packages/js/src/generators/setup-verdaccio/generator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { Tree, readJson, readProjectConfiguration } from '@nx/devkit';
import { Tree, readJson, updateJson } from '@nx/devkit';

import generator from './generator';
import { SetupVerdaccioGeneratorSchema } from './schema';
Expand Down Expand Up @@ -30,6 +30,49 @@ describe('setup-verdaccio generator', () => {
},
},
});
const packageJson = readJson<PackageJson>(tree, 'package.json');
expect(packageJson.nx).toEqual({
includedScripts: [],
});
});

it('should not override existing root project settings from package.json', async () => {
updateJson(tree, 'package.json', (json) => {
json.nx = {
includedScripts: ['test'],
targets: {
build: {
outputs: ['dist'],
},
},
};
return json;
});
await generator(tree, options);
const config = readJson(tree, 'project.json');
expect(config).toEqual({
name: 'test-name',
$schema: 'node_modules/nx/schemas/project-schema.json',
targets: {
'local-registry': {
executor: '@nx/js:verdaccio',
options: {
port: 4873,
config: '.verdaccio/config.yml',
storage: 'tmp/local-registry/storage',
},
},
},
});
const packageJson = readJson<PackageJson>(tree, 'package.json');
expect(packageJson.nx).toEqual({
includedScripts: ['test'],
targets: {
build: {
outputs: ['dist'],
},
},
});
});

it('should add local-registry target to project.json', async () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/js/src/generators/setup-verdaccio/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ export async function setupVerdaccio(
};
if (!tree.exists('project.json')) {
const { name } = readJson(tree, 'package.json');
updateJson(tree, 'package.json', (json) => {
if (!json.nx) {
json.nx = {
includedScripts: [],
};
}
return json;
});
addProjectConfiguration(tree, name, {
root: '.',
targets: {
Expand Down

1 comment on commit c6ad657

@vercel
Copy link

@vercel vercel bot commented on c6ad657 Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app

Please sign in to comment.