Skip to content

Commit

Permalink
fix(core): do not attempt to remove non-existent package from package…
Browse files Browse the repository at this point in the history
….json (#16399)
  • Loading branch information
meeroslav authored Apr 19, 2023
1 parent 2e97962 commit 1b7587f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
30 changes: 24 additions & 6 deletions e2e/nx-init/src/nx-init-react.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,18 @@ describe('nx init (for React)', () => {
expect(craToNxOutput).toContain('🎉 Done!');

const packageJson = readJson('package.json');
expect(packageJson.devDependencies['@nrwl/jest']).toBeDefined();
expect(packageJson.devDependencies['@nrwl/vite']).toBeUndefined();
expect(packageJson.devDependencies['@nrwl/webpack']).toBeDefined();
expect(
packageJson.devDependencies['@nrwl/jest'] ||
packageJson.devDependencies['@nx/jest']
).toBeDefined();
expect(
packageJson.devDependencies['@nrwl/vite'] ||
packageJson.devDependencies['@nx/vite']
).toBeUndefined();
expect(
packageJson.devDependencies['@nrwl/webpack'] ||
packageJson.devDependencies['@nx/webpack']
).toBeDefined();

runCLI(`build ${appName}`, {
env: {
Expand Down Expand Up @@ -68,9 +77,18 @@ describe('nx init (for React)', () => {
expect(craToNxOutput).toContain('🎉 Done!');

const packageJson = readJson('package.json');
expect(packageJson.devDependencies['@nrwl/jest']).toBeUndefined();
expect(packageJson.devDependencies['@nrwl/vite']).toBeDefined();
expect(packageJson.devDependencies['@nrwl/webpack']).toBeUndefined();
expect(
packageJson.devDependencies['@nrwl/jest'] ||
packageJson.devDependencies['@nx/jest']
).toBeUndefined();
expect(
packageJson.devDependencies['@nrwl/vite'] ||
packageJson.devDependencies['@nx/vite']
).toBeDefined();
expect(
packageJson.devDependencies['@nrwl/webpack'] ||
packageJson.devDependencies['@nx/webpack']
).toBeUndefined();

const viteConfig = readFile(`apps/${appName}/vite.config.js`);
expect(viteConfig).toContain('port: 4200'); // default port
Expand Down
8 changes: 7 additions & 1 deletion packages/nx/src/nx-init/react/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,13 @@ function cleanUpUnusedFilesAndAddConfigFiles(options: NormalizedOptions) {
setupE2eProject(options.reactAppName);
} else {
removeSync(join('apps', `${options.reactAppName}-e2e`));
execSync(`${options.pmc.rm} @nrwl/cypress eslint-plugin-cypress`);
const packageJson = readJsonFile('package.json');
const cypressPkgName =
packageJson.devDependencies?.['@nrwl/cypress'] ||
packageJson.dependencies?.['@nrwl/cypress']
? '@nrwl/cypress'
: '@nx/cypress';
execSync(`${options.pmc.rm} ${cypressPkgName} eslint-plugin-cypress`);
}

if (options.isStandalone) {
Expand Down

0 comments on commit 1b7587f

Please sign in to comment.