Skip to content

refactor(@schematics/angular): sync schematics dependencies using Renovate #21330

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

Merged
merged 2 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/goldens/public-api
/packages/angular_devkit/build_angular/test/
/packages/angular_devkit/build_webpack/test/
/packages/angular_devkit/schematics_cli/blank/project-files/
/packages/angular_devkit/schematics_cli/blank/schematic-files/
/packages/angular_devkit/schematics_cli/schematic/files/
/tests/
.yarn/
Expand Down
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
/goldens/public-api
/packages/angular_devkit/build_angular/test/
/packages/angular_devkit/core/src/workspace/json/test/
/packages/angular_devkit/schematics_cli/blank/project-files/
/packages/angular_devkit/schematics_cli/blank/schematic-files/
/packages/angular_devkit/schematics_cli/schematic/files/
/README.md
/CONTRIBUTING.md
.yarn/
Expand Down
6 changes: 3 additions & 3 deletions packages/angular_devkit/schematics_cli/blank/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import {
Tree,
UpdateRecorder,
apply,
applyTemplates,
chain,
mergeWith,
move,
template,
url,
} from '@angular-devkit/schematics';
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
Expand Down Expand Up @@ -116,7 +116,7 @@ export default function (options: Schema): Rule {
} catch {}

let source = apply(url('./schematic-files'), [
applyTemplates({
template({
...options,
coreVersion,
schematicsVersion,
Expand All @@ -130,7 +130,7 @@ export default function (options: Schema): Rule {
if (!collectionPath) {
collectionPath = normalize('/' + options.name + '/src/collection.json');
source = apply(url('./project-files'), [
applyTemplates({
template({
...(options as object),
coreVersion,
schematicsVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This repository is a basic Schematic implementation that serves as a starting po
To test locally, install `@angular-devkit/schematics-cli` globally and use the `schematics` command line tool. That tool acts the same as the `generate` command of the Angular CLI, but also has a debug mode.

Check the documentation with

```bash
schematics --help
```
Expand All @@ -25,4 +26,3 @@ npm publish
```

That's it!

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Outputs
src/**/*.js
src/**/*.js.map
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Ignores TypeScript files, but keeps definitions.
*.ts
!*.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
"schematics": {
}
"schematics": {}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"compilerOptions": {
"baseUrl": "tsconfig",
"lib": [
"es2018",
"dom"
],
"lib": ["es2018", "dom"],
"declaration": true,
"module": "commonjs",
"moduleResolution": "node",
Expand All @@ -20,15 +17,8 @@
"sourceMap": true,
"strictNullChecks": true,
"target": "es6",
"types": [
"jasmine",
"node"
]
"types": ["jasmine", "node"]
},
"include": [
"src/**/*"
],
"exclude": [
"src/*/files/**/*"
]
"include": ["src/**/*"],
"exclude": ["src/*/files/**/*"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Tree } from '@angular-devkit/schematics';
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import * as path from 'path';


const collectionPath = path.join(__dirname, '../collection.json');


describe('<%= dasherize(name) %>', () => {
it('works', async () => {
const runner = new SchematicTestRunner('schematics', collectionPath);
const tree = await runner.runSchematicAsync('<%= dasherize(name) %>', {}, Tree.empty()).toPromise();
const tree = await runner
.runSchematicAsync('<%= dasherize(name) %>', {}, Tree.empty())
.toPromise();

expect(tree.files).toEqual([]);
});
Expand Down
1 change: 1 addition & 0 deletions packages/schematics/angular/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ ts_library(
include = [
"collection.json",
"package.json",
"utility/latest-versions/package.json",
"migrations/migration-collection.json",
"*/schema.json",
"*/files/**/*",
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/angular/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function addDependenciesToPackageJson(options: ApplicationOptions) {
{
type: NodeDependencyType.Dev,
name: 'typescript',
version: latestVersions.TypeScript,
version: latestVersions['typescript'],
},
].forEach((dependency) => addPackageJsonDependency(host, dependency));

Expand Down
4 changes: 2 additions & 2 deletions packages/schematics/angular/application/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,15 @@ describe('Application Schematic', () => {
.toPromise();
const pkg = JSON.parse(tree.readContent('/package.json'));
expect(pkg.devDependencies['@angular/compiler-cli']).toEqual(latestVersions.Angular);
expect(pkg.devDependencies['typescript']).toEqual(latestVersions.TypeScript);
expect(pkg.devDependencies['typescript']).toEqual(latestVersions['typescript']);
});

it(`should not override existing users dependencies`, async () => {
const oldPackageJson = workspaceTree.readContent('package.json');
workspaceTree.overwrite(
'package.json',
oldPackageJson.replace(
`"typescript": "${latestVersions.TypeScript}"`,
`"typescript": "${latestVersions['typescript']}"`,
`"typescript": "~2.5.2"`,
),
);
Expand Down
10 changes: 5 additions & 5 deletions packages/schematics/angular/library/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ function addDependenciesToPackageJson() {
{
type: NodeDependencyType.Dev,
name: 'ng-packagr',
version: latestVersions.ngPackagr,
version: latestVersions['ng-packagr'],
},
{
type: NodeDependencyType.Default,
name: 'tslib',
version: latestVersions.TsLib,
version: latestVersions['tslib'],
},
{
type: NodeDependencyType.Dev,
name: 'typescript',
version: latestVersions.TypeScript,
version: latestVersions['typescript'],
},
].forEach((dependency) => addPackageJsonDependency(host, dependency));

Expand Down Expand Up @@ -162,8 +162,8 @@ export default function (options: LibraryOptions): Rule {
distRoot,
relativePathToWorkspaceRoot: relativePathToWorkspaceRoot(projectRoot),
prefix,
angularLatestVersion: latestVersions.Angular.replace('~', '').replace('^', ''),
tsLibLatestVersion: latestVersions.TsLib.replace('~', '').replace('^', ''),
angularLatestVersion: latestVersions.Angular.replace(/\~|\^/, ''),
tsLibLatestVersion: latestVersions['tslib'].replace(/\~|\^/, ''),
folderName,
}),
move(projectRoot),
Expand Down
6 changes: 3 additions & 3 deletions packages/schematics/angular/library/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ describe('Library Schematic', () => {
.toPromise();

const packageJson = getJsonFileContent(tree, 'package.json');
expect(packageJson.devDependencies['ng-packagr']).toEqual(latestVersions.ngPackagr);
expect(packageJson.devDependencies['ng-packagr']).toEqual(latestVersions['ng-packagr']);
});

it('should use the latest known versions in package.json', async () => {
Expand All @@ -192,15 +192,15 @@ describe('Library Schematic', () => {
.toPromise();
const pkg = JSON.parse(tree.readContent('/package.json'));
expect(pkg.devDependencies['@angular/compiler-cli']).toEqual(latestVersions.Angular);
expect(pkg.devDependencies['typescript']).toEqual(latestVersions.TypeScript);
expect(pkg.devDependencies['typescript']).toEqual(latestVersions['typescript']);
});

it(`should not override existing users dependencies`, async () => {
const oldPackageJson = workspaceTree.readContent('package.json');
workspaceTree.overwrite(
'package.json',
oldPackageJson.replace(
`"typescript": "${latestVersions.TypeScript}"`,
`"typescript": "${latestVersions['typescript']}"`,
`"typescript": "~2.5.2"`,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function (): Rule {
'karma-jasmine': '~4.0.0',
'karma-jasmine-html-reporter': '^1.5.0',
'protractor': '~7.0.0',
'ng-packagr': latestVersions.ngPackagr,
'ng-packagr': latestVersions['ng-packagr'],
'tslib': '^2.0.0',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import { Rule } from '@angular-devkit/schematics';
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
import { addPackageJsonDependency, getPackageJsonDependency } from '../../utility/dependencies';
import { latestVersions } from '../../utility/latest-versions';

export default function (): Rule {
return (host, context) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function addTsLib(): Rule {

addPackageJsonDependency(host, {
name: 'tslib',
version: latestVersions.TsLib,
version: latestVersions['tslib'],
type: NodeDependencyType.Default,
overwrite: true,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
getPackageJsonDependency,
removePackageJsonDependency,
} from '../../utility/dependencies';
import { latestVersions } from '../../utility/latest-versions';

export function updateDependencies(): Rule {
return (host, context) => {
Expand Down
15 changes: 8 additions & 7 deletions packages/schematics/angular/utility/latest-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
* found in the LICENSE file at https://angular.io/license
*/

export const latestVersions = {
export const latestVersions: Record<string, string> & {
Angular: string;
DevkitBuildAngular: string;
} = {
// We could have used TypeScripts' `resolveJsonModule` to make the `latestVersion` object typesafe,
// but ts_library doesn't support JSON inputs.
...require('./latest-versions/package.json')['dependencies'],

// These versions should be kept up to date with latest Angular peer dependencies.
Angular: '~12.2.0-next.2',
RxJs: '~6.6.0',
ZoneJs: '~0.11.4',
TypeScript: '~4.3.2',
TsLib: '^2.2.0',

// Since @angular-devkit/build-angular and @schematics/angular are always
// published together from the same monorepo, and they are both
// non-experimental, they will always have the same version.
DevkitBuildAngular: '~' + require('../package.json')['version'],

ngPackagr: '^12.1.0',
};
20 changes: 20 additions & 0 deletions packages/schematics/angular/utility/latest-versions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"description": "Package versions used by schematics in @schematics/angular.",
"comment": "This file is needed so that depedencies are synced by Renovate.",
"private": true,
"dependencies": {
"@types/jasmine": "~3.8.0",
"@types/node": "^12.11.1",
"jasmine-core": "~3.8.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine-html-reporter": "~1.7.0",
"karma-jasmine": "~4.0.0",
"karma": "~6.3.0",
"ng-packagr": "^12.1.1",
"rxjs": "~6.6.0",
"tslib": "^2.3.0",
"typescript": "~4.3.5",
"zone.js": "~0.11.4"
}
}
24 changes: 12 additions & 12 deletions packages/schematics/angular/workspace/files/package.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
"@angular/platform-browser": "<%= latestVersions.Angular %>",
"@angular/platform-browser-dynamic": "<%= latestVersions.Angular %>",
"@angular/router": "<%= latestVersions.Angular %>",
"rxjs": "<%= latestVersions.RxJs %>",
"tslib": "<%= latestVersions.TsLib %>",
"zone.js": "<%= latestVersions.ZoneJs %>"
"rxjs": "<%= latestVersions['rxjs'] %>",
"tslib": "<%= latestVersions['tslib'] %>",
"zone.js": "<%= latestVersions['zone.js'] %>"
},
"devDependencies": {
"@angular/cli": "<%= '~' + version %>",
"@angular/compiler-cli": "<%= latestVersions.Angular %>",<% if (!minimal) { %>
"@types/jasmine": "~3.8.0",<% } %>
"@types/node": "^12.11.1",<% if (!minimal) { %>
"jasmine-core": "~3.8.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "~1.7.0",<% } %>
"typescript": "<%= latestVersions.TypeScript %>"
"@types/jasmine": "<%= latestVersions['@types/jasmine'] %>",<% } %>
"@types/node": "<%= latestVersions['@types/node'] %>",<% if (!minimal) { %>
"jasmine-core": "<%= latestVersions['jasmine-core'] %>",
"karma": "<%= latestVersions['karma'] %>",
"karma-chrome-launcher": "<%= latestVersions['karma-chrome-launcher'] %>",
"karma-coverage": "<%= latestVersions['karma-coverage'] %>",
"karma-jasmine": "<%= latestVersions['karma-jasmine'] %>",
"karma-jasmine-html-reporter": "<%= latestVersions['karma-jasmine-html-reporter'] %>",<% } %>
"typescript": "<%= latestVersions['typescript'] %>"
}
}
6 changes: 3 additions & 3 deletions packages/schematics/angular/workspace/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ describe('Workspace Schematic', () => {
const tree = await schematicRunner.runSchematicAsync('workspace', defaultOptions).toPromise();
const pkg = JSON.parse(tree.readContent('/package.json'));
expect(pkg.dependencies['@angular/core']).toEqual(latestVersions.Angular);
expect(pkg.dependencies['rxjs']).toEqual(latestVersions.RxJs);
expect(pkg.dependencies['zone.js']).toEqual(latestVersions.ZoneJs);
expect(pkg.devDependencies['typescript']).toEqual(latestVersions.TypeScript);
expect(pkg.dependencies['rxjs']).toEqual(latestVersions['rxjs']);
expect(pkg.dependencies['zone.js']).toEqual(latestVersions['zone.js']);
expect(pkg.devDependencies['typescript']).toEqual(latestVersions['typescript']);
});

it('should create correct files when using minimal', async () => {
Expand Down
16 changes: 15 additions & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,21 @@
"enabled": false
},
{
"excludePackagePatterns": ["^@angular/.*"],
"matchPaths": [
"packages/angular_devkit/schematics_cli/blank/project-files/package.json",
"packages/angular_devkit/schematics_cli/schematic/files/package.json",
"packages/schematics/angular/utility/latest-versions/package.json"
],
"matchPackagePatterns": ["*"],
"groupName": "schematics dependencies",
"groupSlug": "all-schematics-dependencies"
},
{
"matchPaths": [
"!packages/angular_devkit/schematics_cli/blank/project-files/package.json",
"!packages/angular_devkit/schematics_cli/schematic/files/package.json",
"!packages/schematics/angular/utility/latest-versions/package.json"
],
"matchPackagePatterns": ["*"],
"matchUpdateTypes": ["minor", "patch"],
"groupName": "all non-major dependencies",
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"goldens/**/*",
"**/node_modules/**/*",
"**/third_party/**/*",
"packages/angular_devkit/schematics_cli/*/files/**/*",
"packages/angular_devkit/schematics_cli/blank/*-files/**/*",
"packages/angular_devkit/schematics_cli/schematic/files/**/*",
"packages/angular_devkit/*/test/**/*",
"packages/schematics/*/*/*files/**/*",
"tests/**/*",
Expand Down