feat(angular): set angular devkit packages as peer deps (#14723)

This commit is contained in:
Colum Ferry 2023-02-01 17:09:29 +00:00 committed by GitHub
parent b7fe0a2311
commit fe6ffa20d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 314 additions and 42 deletions

View File

@ -1,6 +1,6 @@
import { import {
cleanupProject, cleanupProject,
newProject, newAngularProject,
runCLI, runCLI,
uniq, uniq,
updateFile, updateFile,
@ -9,7 +9,7 @@ import * as path from 'path';
describe('Angular Package', () => { describe('Angular Package', () => {
describe('linting', () => { describe('linting', () => {
beforeAll(() => newProject()); beforeAll(() => newAngularProject());
afterAll(() => cleanupProject()); afterAll(() => cleanupProject());
it('should support eslint and pass linting on the standard generated code', async () => { it('should support eslint and pass linting on the standard generated code', async () => {

View File

@ -1,20 +1,16 @@
import { import {
expectTestsPass,
newProject,
cleanupProject, cleanupProject,
expectTestsPass,
newAngularProject,
readJson,
runCLI, runCLI,
runCLIAsync, runCLIAsync,
uniq, uniq,
updateFile, updateFile,
removeFile,
checkFilesDoNotExist,
isNotWindows,
readJson,
createFile,
} from '@nrwl/e2e/utils'; } from '@nrwl/e2e/utils';
describe('Angular Config', () => { describe('Angular Config', () => {
beforeAll(() => newProject()); beforeAll(() => newAngularProject());
afterAll(() => cleanupProject()); afterAll(() => cleanupProject());
it('should upgrade the config correctly', async () => { it('should upgrade the config correctly', async () => {

View File

@ -1,6 +1,6 @@
import { import {
cleanupProject, cleanupProject,
newProject, newAngularProject,
promisifiedTreeKill, promisifiedTreeKill,
readProjectConfig, readProjectConfig,
runCLI, runCLI,
@ -16,7 +16,7 @@ import { names } from '@nrwl/devkit';
describe('Angular Projects', () => { describe('Angular Projects', () => {
let proj: string; let proj: string;
beforeAll(() => (proj = newProject())); beforeAll(() => (proj = newAngularProject()));
afterAll(() => cleanupProject()); afterAll(() => cleanupProject());
it('should serve the host and remote apps successfully, even with a shared library with a secondary entry point between them', async () => { it('should serve the host and remote apps successfully, even with a shared library with a secondary entry point between them', async () => {

View File

@ -3,7 +3,7 @@ import {
cleanupProject, cleanupProject,
getSize, getSize,
killPorts, killPorts,
newProject, newAngularProject,
promisifiedTreeKill, promisifiedTreeKill,
readFile, readFile,
runCLI, runCLI,
@ -20,7 +20,7 @@ import { names } from '@nrwl/devkit';
describe('Angular Projects', () => { describe('Angular Projects', () => {
let proj: string; let proj: string;
beforeAll(() => (proj = newProject())); beforeAll(() => (proj = newAngularProject()));
afterAll(() => cleanupProject()); afterAll(() => cleanupProject());
it('should generate an app, a lib, link them, build, serve and test both correctly', async () => { it('should generate an app, a lib, link them, build, serve and test both correctly', async () => {

View File

@ -2,7 +2,7 @@ import {
checkFilesDoNotExist, checkFilesDoNotExist,
cleanupProject, cleanupProject,
createFile, createFile,
newProject, newAngularProject,
runCLI, runCLI,
uniq, uniq,
updateFile, updateFile,
@ -17,7 +17,7 @@ describe('Angular Cypress Component Tests', () => {
const buildableLibName = uniq('cy-angular-buildable-lib'); const buildableLibName = uniq('cy-angular-buildable-lib');
beforeAll(async () => { beforeAll(async () => {
projectName = newProject({ name: uniq('cy-ng') }); projectName = newAngularProject({ name: uniq('cy-ng') });
runCLI(`generate @nrwl/angular:app ${appName} --no-interactive`); runCLI(`generate @nrwl/angular:app ${appName} --no-interactive`);
runCLI( runCLI(
`generate @nrwl/angular:component fancy-component --project=${appName} --no-interactive` `generate @nrwl/angular:component fancy-component --project=${appName} --no-interactive`

View File

@ -1,13 +1,9 @@
import { import {
checkFilesExist,
cleanupProject, cleanupProject,
newProject, newAngularProject,
readFile,
runCLI, runCLI,
uniq, uniq,
updateFile,
} from '@nrwl/e2e/utils'; } from '@nrwl/e2e/utils';
import { classify } from '@nrwl/workspace/src/utils/strings';
describe('Move Angular Project', () => { describe('Move Angular Project', () => {
let proj: string; let proj: string;
@ -16,7 +12,7 @@ describe('Move Angular Project', () => {
let newPath: string; let newPath: string;
beforeAll(() => { beforeAll(() => {
proj = newProject(); proj = newAngularProject();
app1 = uniq('app1'); app1 = uniq('app1');
app2 = uniq('app2'); app2 = uniq('app2');
newPath = `subfolder/${app2}`; newPath = `subfolder/${app2}`;

View File

@ -2,7 +2,7 @@ import {
cleanupProject, cleanupProject,
expectTestsPass, expectTestsPass,
getSelectedPackageManager, getSelectedPackageManager,
newProject, newAngularProject,
readJson, readJson,
runCLI, runCLI,
runCLIAsync, runCLIAsync,
@ -10,15 +10,12 @@ import {
} from '@nrwl/e2e/utils'; } from '@nrwl/e2e/utils';
describe('Angular Package', () => { describe('Angular Package', () => {
let previousPM = process.env.SELECTED_PM;
describe('ngrx', () => { describe('ngrx', () => {
beforeAll(() => { beforeAll(() => {
process.env.SELECTED_PM = 'npm'; newAngularProject();
newProject();
}); });
afterAll(() => { afterAll(() => {
cleanupProject(); cleanupProject();
process.env.SELECTED_PM = previousPM;
}); });
it('should work', async () => { it('should work', async () => {

View File

@ -3,7 +3,7 @@ process.env.SELECTED_CLI = 'angular';
import { import {
cleanupProject, cleanupProject,
listFiles, listFiles,
newProject, newAngularProject,
readFile, readFile,
removeFile, removeFile,
runCLI, runCLI,
@ -118,10 +118,8 @@ describe('Tailwind support', () => {
updateFile(tailwindConfigPath, tailwindConfigUpdated); updateFile(tailwindConfigPath, tailwindConfigUpdated);
}; };
let previousPM = process.env.SELECTED_PM;
beforeAll(() => { beforeAll(() => {
process.env.SELECTED_PM = 'npm'; project = newAngularProject();
project = newProject();
// Create tailwind config in the workspace root // Create tailwind config in the workspace root
createWorkspaceTailwindConfigFile(); createWorkspaceTailwindConfigFile();
@ -129,7 +127,6 @@ describe('Tailwind support', () => {
afterAll(() => { afterAll(() => {
cleanupProject(); cleanupProject();
process.env.SELECTED_PM = previousPM;
}); });
describe('Libraries', () => { describe('Libraries', () => {

View File

@ -1,4 +1,10 @@
import { newProject, runCLI, uniq, runCLIAsync } from '@nrwl/e2e/utils'; import {
newAngularProject,
newProject,
runCLI,
runCLIAsync,
uniq,
} from '@nrwl/e2e/utils';
describe('Jest root projects', () => { describe('Jest root projects', () => {
const myapp = uniq('myapp'); const myapp = uniq('myapp');
@ -6,7 +12,7 @@ describe('Jest root projects', () => {
describe('angular', () => { describe('angular', () => {
beforeAll(() => { beforeAll(() => {
newProject(); newAngularProject();
}); });
it('should test root level app projects', async () => { it('should test root level app projects', async () => {

View File

@ -3,6 +3,7 @@ import {
checkFilesExist, checkFilesExist,
cleanupProject, cleanupProject,
createFile, createFile,
newAngularProject,
newProject, newProject,
readFile, readFile,
readJson, readJson,
@ -185,7 +186,7 @@ describe('Linter', () => {
}, 1000000); }, 1000000);
it('lint plugin should ensure module boundaries', () => { it('lint plugin should ensure module boundaries', () => {
const proj = newProject(); const proj = newAngularProject();
const myapp = uniq('myapp'); const myapp = uniq('myapp');
const myapp2 = uniq('myapp2'); const myapp2 = uniq('myapp2');
const mylib = uniq('mylib'); const mylib = uniq('mylib');
@ -515,7 +516,7 @@ export function tslibC(): string {
const myapp = uniq('myapp'); const myapp = uniq('myapp');
const mylib = uniq('mylib'); const mylib = uniq('mylib');
newProject(); newAngularProject();
runCLI(`generate @nrwl/angular:app ${myapp} --rootProject=true`); runCLI(`generate @nrwl/angular:app ${myapp} --rootProject=true`);
let rootEslint = readJson('.eslintrc.json'); let rootEslint = readJson('.eslintrc.json');

View File

@ -2,7 +2,6 @@ import {
joinPathFragments, joinPathFragments,
parseJson, parseJson,
ProjectConfiguration, ProjectConfiguration,
ProjectsConfigurations,
readJsonFile, readJsonFile,
workspaceRoot, workspaceRoot,
} from '@nrwl/devkit'; } from '@nrwl/devkit';
@ -365,6 +364,21 @@ export function newProject({
} }
} }
export function newAngularProject({
name = uniq('proj'),
packageManager = getSelectedPackageManager(),
} = {}): string {
const projScope = newProject({ name, packageManager });
const angularPackages = [
'@angular-devkit/core',
'@angular-devkit/schematics',
'@schematics/angular',
];
packageInstall(angularPackages.join(` `), projScope, 'latest');
return projScope;
}
export function newLernaWorkspace({ export function newLernaWorkspace({
name = uniq('lerna-proj'), name = uniq('lerna-proj'),
packageManager = getSelectedPackageManager(), packageManager = getSelectedPackageManager(),

View File

@ -197,6 +197,12 @@
"version": "15.5.0-beta.0", "version": "15.5.0-beta.0",
"description": "Update the @angular/cli package version to ~15.1.0.", "description": "Update the @angular/cli package version to ~15.1.0.",
"factory": "./src/migrations/update-15-5-0/update-angular-cli" "factory": "./src/migrations/update-15-5-0/update-angular-cli"
},
"install-required-packages": {
"cli": "nx",
"version": "15.7.0-beta.1",
"description": "Install the required angular-devkit packages as we do not directly depend on them anymore",
"factory": "./src/migrations/update-15-7-0/install-required-packages"
} }
}, },
"packageJsonUpdates": { "packageJsonUpdates": {

View File

@ -36,7 +36,6 @@
"migrations": "./migrations.json" "migrations": "./migrations.json"
}, },
"dependencies": { "dependencies": {
"@angular-devkit/schematics": "~15.1.0",
"@nrwl/cypress": "file:../cypress", "@nrwl/cypress": "file:../cypress",
"@nrwl/devkit": "file:../devkit", "@nrwl/devkit": "file:../devkit",
"@nrwl/jest": "file:../jest", "@nrwl/jest": "file:../jest",
@ -44,7 +43,6 @@
"@nrwl/webpack": "file:../webpack", "@nrwl/webpack": "file:../webpack",
"@nrwl/workspace": "file:../workspace", "@nrwl/workspace": "file:../workspace",
"@phenomnomnominal/tsquery": "4.1.1", "@phenomnomnominal/tsquery": "4.1.1",
"@schematics/angular": "~15.1.0",
"chalk": "^4.1.0", "chalk": "^4.1.0",
"chokidar": "^3.5.1", "chokidar": "^3.5.1",
"http-server": "^14.1.0", "http-server": "^14.1.0",
@ -58,7 +56,12 @@
"webpack-merge": "5.7.3" "webpack-merge": "5.7.3"
}, },
"peerDependencies": { "peerDependencies": {
"@nguniversal/builders": "~15.1.0", "@angular-devkit/architect": ">= 0.1400.0 < 0.1600.0",
"@angular-devkit/build-angular": ">= 14.0.0 < 16.0.0",
"@angular-devkit/schematics": ">= 14.0.0 < 16.0.0",
"@schematics/angular": ">= 14.0.0 < 16.0.0",
"@angular-devkit/core": ">= 14.0.0 < 16.0.0",
"@nguniversal/builders": ">= 14.0.0 < 16.0.0",
"rxjs": "^6.5.3 || ^7.5.0" "rxjs": "^6.5.3 || ^7.5.0"
}, },
"peerDependenciesMeta": { "peerDependenciesMeta": {

View File

@ -0,0 +1,213 @@
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { readJson, updateJson } from '@nrwl/devkit';
import installRequiredPackages from './install-required-packages';
describe('installed-required-packages', () => {
it('should install the dependencies if they do not exist for v15', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
updateJson(tree, 'package.json', (pkg) => ({
...pkg,
dependencies: {
'@angular/core': '~15.0.0',
},
devDependencies: {
'@angular/cli': '~15.0.0',
},
}));
// ACT
await installRequiredPackages(tree);
// ASSERT
const pkgJson = readJson(tree, 'package.json');
expect(pkgJson.dependencies).toMatchInlineSnapshot(`
Object {
"@angular/core": "~15.0.0",
}
`);
expect(pkgJson.devDependencies).toMatchInlineSnapshot(`
Object {
"@angular-devkit/core": "~15.0.0",
"@angular-devkit/schematics": "~15.0.0",
"@angular/cli": "~15.0.0",
"@schematics/angular": "~15.0.0",
}
`);
});
it('should install the dependencies if they do not exist for v14', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
updateJson(tree, 'package.json', (pkg) => ({
...pkg,
dependencies: {
'@angular/core': '~14.0.0',
},
devDependencies: {
'@angular/cli': '~14.0.0',
},
}));
// ACT
await installRequiredPackages(tree);
// ASSERT
const pkgJson = readJson(tree, 'package.json');
expect(pkgJson.dependencies).toMatchInlineSnapshot(`
Object {
"@angular/core": "~14.0.0",
}
`);
expect(pkgJson.devDependencies).toMatchInlineSnapshot(`
Object {
"@angular-devkit/core": "~14.0.0",
"@angular-devkit/schematics": "~14.0.0",
"@angular/cli": "~14.0.0",
"@schematics/angular": "~14.0.0",
}
`);
});
it('should not install the dependencies if they exist for v15', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
updateJson(tree, 'package.json', (pkg) => ({
...pkg,
dependencies: {
'@angular/core': '~15.0.0',
},
devDependencies: {
'@angular/cli': '~15.0.0',
'@angular-devkit/core': '~15.0.0',
'@angular-devkit/schematics': '~15.0.0',
'@schematics/angular': '~15.0.0',
},
}));
// ACT
await installRequiredPackages(tree);
// ASSERT
const pkgJson = readJson(tree, 'package.json');
expect(pkgJson.dependencies).toMatchInlineSnapshot(`
Object {
"@angular/core": "~15.0.0",
}
`);
expect(pkgJson.devDependencies).toMatchInlineSnapshot(`
Object {
"@angular-devkit/core": "~15.0.0",
"@angular-devkit/schematics": "~15.0.0",
"@angular/cli": "~15.0.0",
"@schematics/angular": "~15.0.0",
}
`);
});
it('should not install the dependencies if they exist for v14', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
updateJson(tree, 'package.json', (pkg) => ({
...pkg,
dependencies: {
'@angular/core': '~14.0.0',
},
devDependencies: {
'@angular/cli': '~14.0.0',
'@angular-devkit/core': '~14.0.0',
'@angular-devkit/schematics': '~14.0.0',
'@schematics/angular': '~14.0.0',
},
}));
// ACT
await installRequiredPackages(tree);
// ASSERT
const pkgJson = readJson(tree, 'package.json');
expect(pkgJson.dependencies).toMatchInlineSnapshot(`
Object {
"@angular/core": "~14.0.0",
}
`);
expect(pkgJson.devDependencies).toMatchInlineSnapshot(`
Object {
"@angular-devkit/core": "~14.0.0",
"@angular-devkit/schematics": "~14.0.0",
"@angular/cli": "~14.0.0",
"@schematics/angular": "~14.0.0",
}
`);
});
it('should install the missing dependencies for v15', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
updateJson(tree, 'package.json', (pkg) => ({
...pkg,
dependencies: {
'@angular/core': '~15.0.0',
},
devDependencies: {
'@angular/cli': '~15.0.0',
'@angular-devkit/core': '~15.0.0',
'@schematics/angular': '~15.0.0',
},
}));
// ACT
await installRequiredPackages(tree);
// ASSERT
const pkgJson = readJson(tree, 'package.json');
expect(pkgJson.dependencies).toMatchInlineSnapshot(`
Object {
"@angular/core": "~15.0.0",
}
`);
expect(pkgJson.devDependencies).toMatchInlineSnapshot(`
Object {
"@angular-devkit/core": "~15.0.0",
"@angular-devkit/schematics": "~15.0.0",
"@angular/cli": "~15.0.0",
"@schematics/angular": "~15.0.0",
}
`);
});
it('should not install the missing dependencies for v14', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
updateJson(tree, 'package.json', (pkg) => ({
...pkg,
dependencies: {
'@angular/core': '~14.0.0',
},
devDependencies: {
'@angular/cli': '~14.0.0',
'@angular-devkit/core': '~14.0.0',
'@schematics/angular': '~14.0.0',
},
}));
// ACT
await installRequiredPackages(tree);
// ASSERT
const pkgJson = readJson(tree, 'package.json');
expect(pkgJson.dependencies).toMatchInlineSnapshot(`
Object {
"@angular/core": "~14.0.0",
}
`);
expect(pkgJson.devDependencies).toMatchInlineSnapshot(`
Object {
"@angular-devkit/core": "~14.0.0",
"@angular-devkit/schematics": "~14.0.0",
"@angular/cli": "~14.0.0",
"@schematics/angular": "~14.0.0",
}
`);
});
});

View File

@ -0,0 +1,32 @@
import type { Tree } from '@nrwl/devkit';
import { addDependenciesToPackageJson, readJson } from '@nrwl/devkit';
import { getInstalledAngularMajorVersion } from '../../generators/utils/version-utils';
import { getPkgVersionForAngularMajorVersion } from '../../utils/version-utils';
export default async function (tree: Tree) {
const packagesToInstall = [
'@angular-devkit/core',
'@angular-devkit/schematics',
'@schematics/angular',
];
const pkgJson = readJson(tree, 'package.json');
const angularMajorVersion = getInstalledAngularMajorVersion(tree);
const angularDevkitVersion = getPkgVersionForAngularMajorVersion(
'angularDevkitVersion',
angularMajorVersion
);
const angularCliVersion =
pkgJson.devDependencies['@angular/cli'] ??
pkgJson.dependencies['@angular/cli'] ??
angularDevkitVersion;
const filteredPackages: Record<string, string> = packagesToInstall
.filter(
(pkg) => !pkgJson.devDependencies[pkg] && !pkgJson.dependencies[pkg]
)
.reduce((allPkgs, pkg) => ({ ...allPkgs, [pkg]: angularCliVersion }), {});
addDependenciesToPackageJson(tree, {}, { ...filteredPackages });
}

View File

@ -6,7 +6,10 @@ Object {
"@nrwl/angular": "0.0.1", "@nrwl/angular": "0.0.1",
}, },
"devDependencies": Object { "devDependencies": Object {
"@angular-devkit/core": "~15.1.0",
"@angular-devkit/schematics": "~15.1.0",
"@nrwl/workspace": "0.0.1", "@nrwl/workspace": "0.0.1",
"@schematics/angular": "~15.1.0",
"nx": "0.0.1", "nx": "0.0.1",
"prettier": "^2.6.2", "prettier": "^2.6.2",
"typescript": "~4.8.2", "typescript": "~4.8.2",

View File

@ -4,7 +4,7 @@ import {
Tree, Tree,
} from '@nrwl/devkit'; } from '@nrwl/devkit';
import { Preset } from '../utils/presets'; import { Preset } from '../utils/presets';
import { nxVersion } from '../../utils/versions'; import { angularCliVersion, nxVersion } from '../../utils/versions';
import { getNpmPackageVersion } from '../utils/get-npm-package-version'; import { getNpmPackageVersion } from '../utils/get-npm-package-version';
import { NormalizedSchema } from './new'; import { NormalizedSchema } from './new';
import { join } from 'path'; import { join } from 'path';
@ -89,7 +89,14 @@ function getPresetDependencies(preset: string, version?: string) {
case Preset.AngularMonorepo: case Preset.AngularMonorepo:
case Preset.AngularStandalone: case Preset.AngularStandalone:
return { dependencies: { '@nrwl/angular': nxVersion }, dev: {} }; return {
dependencies: { '@nrwl/angular': nxVersion },
dev: {
'@angular-devkit/core': angularCliVersion,
'@angular-devkit/schematics': angularCliVersion,
'@schematics/angular': angularCliVersion,
},
};
case Preset.Express: case Preset.Express:
return { dependencies: {}, dev: { '@nrwl/express': nxVersion } }; return { dependencies: {}, dev: { '@nrwl/express': nxVersion } };

View File

@ -33,6 +33,7 @@ function check() {
'packages/workspace/src/command-line/report.spec.ts', 'packages/workspace/src/command-line/report.spec.ts',
'packages/workspace/src/core/file-command-line-utils.ts', 'packages/workspace/src/core/file-command-line-utils.ts',
'packages/workspace/src/generators/preset/preset.ts', 'packages/workspace/src/generators/preset/preset.ts',
'packages/workspace/src/generators/new/generate-preset.ts',
'packages/workspace/src/generators/init/init.ts', 'packages/workspace/src/generators/init/init.ts',
'packages/workspace/src/utils/update-task.ts', 'packages/workspace/src/utils/update-task.ts',
'packages/workspace/src/migrations/update-8-3-0/update-8-3-0.spec.ts', 'packages/workspace/src/migrations/update-8-3-0/update-8-3-0.spec.ts',