Skip to content

Commit

Permalink
feat(nx): add migration to update Angular CLI devDependencies to 8.1.x
Browse files Browse the repository at this point in the history
Angular CLI 8.1.x is required in order to use the --allow-dirty option.
This also covers the additional build dependencies added when generating
libraries.
  • Loading branch information
brandonroberts authored and vsavkin committed Jul 18, 2019
1 parent 16a4e8d commit 4f7ec84
Show file tree
Hide file tree
Showing 20 changed files with 664 additions and 292 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
"documentation": "./scripts/documentation/documentation.sh && yarn format && ./scripts/documentation/check-documentation.sh"
},
"devDependencies": {
"@angular-devkit/architect": "0.800.1",
"@angular-devkit/build-angular": "0.800.1",
"@angular-devkit/build-ng-packagr": "0.800.1",
"@angular-devkit/build-webpack": "0.800.1",
"@angular-devkit/core": "8.0.1",
"@angular-devkit/schematics": "8.0.1",
"@angular/cli": "8.0.1",
"@angular-devkit/architect": "0.801.1",
"@angular-devkit/build-angular": "0.801.1",
"@angular-devkit/build-ng-packagr": "0.801.1",
"@angular-devkit/build-webpack": "0.801.1",
"@angular-devkit/core": "8.1.1",
"@angular-devkit/schematics": "8.1.1",
"@angular/cli": "8.1.1",
"@angular/common": "^8.0.0",
"@angular/compiler": "^8.0.0",
"@angular/compiler-cli": "^8.0.0",
Expand All @@ -50,6 +50,7 @@
"@ngrx/store": "8.1.0",
"@ngrx/store-devtools": "8.1.0",
"@schematics/angular": "8.0.0",
"@testing-library/react": "8.0.5",
"@types/express": "4.16.0",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
Expand Down Expand Up @@ -101,7 +102,6 @@
"prettier": "1.16.4",
"react": "16.8.6",
"react-dom": "16.8.6",
"@testing-library/react": "8.0.5",
"react-router-dom": "5.0.1",
"release-it": "^7.4.0",
"rxjs": "~6.4.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"dependencies": {
"@nrwl/cypress": "*",
"@nrwl/jest": "*",
"@angular-devkit/schematics": "8.0.1",
"@schematics/angular": "8.0.1",
"@angular-devkit/schematics": "8.1.1",
"@schematics/angular": "8.1.1",
"jasmine-marbles": "~0.6.0"
}
}
4 changes: 2 additions & 2 deletions packages/cypress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"@nrwl/workspace": "*"
},
"dependencies": {
"@angular-devkit/architect": "0.800.1",
"@angular-devkit/core": "8.0.1",
"@angular-devkit/architect": "0.801.1",
"@angular-devkit/core": "8.1.1",
"@cypress/webpack-preprocessor": "~4.1.0",
"tree-kill": "1.2.1",
"ts-loader": "5.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
"dependencies": {
"@nrwl/node": "*",
"@nrwl/jest": "*",
"@angular-devkit/schematics": "8.0.1"
"@angular-devkit/schematics": "8.1.1"
}
}
6 changes: 3 additions & 3 deletions packages/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"@nrwl/workspace": "*"
},
"dependencies": {
"@angular-devkit/architect": "0.800.1",
"@angular-devkit/core": "8.0.1",
"@angular-devkit/schematics": "8.0.1"
"@angular-devkit/architect": "0.801.1",
"@angular-devkit/core": "8.1.1",
"@angular-devkit/schematics": "8.1.1"
}
}
2 changes: 1 addition & 1 deletion packages/nest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
"dependencies": {
"@nrwl/node": "*",
"@nrwl/jest": "*",
"@angular-devkit/schematics": "8.0.1"
"@angular-devkit/schematics": "8.1.1"
}
}
8 changes: 4 additions & 4 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
},
"dependencies": {
"@nrwl/jest": "*",
"@angular-devkit/architect": "0.800.1",
"@angular-devkit/core": "8.0.1",
"@angular-devkit/schematics": "8.0.1",
"@angular-devkit/build-webpack": "0.800.1",
"@angular-devkit/architect": "0.801.1",
"@angular-devkit/core": "8.1.1",
"@angular-devkit/schematics": "8.1.1",
"@angular-devkit/build-webpack": "0.801.1",
"circular-dependency-plugin": "^5.0.2",
"copy-webpack-plugin": "4.6.0",
"fork-ts-checker-webpack-plugin": "0.4.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
"@nrwl/cypress": "*",
"@nrwl/jest": "*",
"@nrwl/web": "*",
"@angular-devkit/schematics": "8.0.1"
"@angular-devkit/schematics": "8.1.1"
}
}
10 changes: 5 additions & 5 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
"dependencies": {
"@nrwl/cypress": "*",
"@nrwl/jest": "*",
"@angular-devkit/architect": "0.800.1",
"@angular-devkit/build-angular": "0.800.1",
"@angular-devkit/build-webpack": "0.800.1",
"@angular-devkit/core": "8.0.1",
"@angular-devkit/schematics": "8.0.1",
"@angular-devkit/architect": "0.801.1",
"@angular-devkit/build-angular": "0.801.1",
"@angular-devkit/build-webpack": "0.801.1",
"@angular-devkit/core": "8.1.1",
"@angular-devkit/schematics": "8.1.1",
"copy-webpack-plugin": "4.6.0",
"fork-ts-checker-webpack-plugin": "0.4.9",
"identity-obj-proxy": "3.0.0",
Expand Down
5 changes: 3 additions & 2 deletions packages/web/src/builders/build/build.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface WebBuildBuilderOptions extends BuildBuilderOptions {

outputHashing?: any;
stylePreprocessingOptions?: any;
subresourceIntegrity?: boolean;
}

export default createBuilder<WebBuildBuilderOptions & JsonObject>(run);
Expand Down Expand Up @@ -107,8 +108,8 @@ export function run(
normalize(context.workspaceRoot),
options.index
),
ES5BuildFiles: result2.emittedFiles,
ES2015BuildFiles: result1.emittedFiles,
noModuleFiles: result2.emittedFiles,
moduleFiles: result1.emittedFiles,
baseHref: options.baseHref,
deployUrl: options.deployUrl,
scripts: options.scripts,
Expand Down
19 changes: 0 additions & 19 deletions packages/web/src/utils/web.config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { getWebConfig as getWebPartial } from './web.config';
jest.mock('tsconfig-paths-webpack-plugin');
import TsConfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
import * as StatsPlugin from 'stats-webpack-plugin';
import { createConsoleLogger } from '@angular-devkit/core/node';
import { Logger } from '@angular-devkit/core/src/logger';
import * as ts from 'typescript';
Expand Down Expand Up @@ -74,24 +73,6 @@ describe('getWebConfig', () => {
).toEqual('style-loader');
});

describe('statsJson', () => {
it('should generate a stats json', () => {
const result = getWebPartial(
root,
sourceRoot,
{
...input,
statsJson: true
},
logger
);

expect(
result.plugins.find(plugin => plugin instanceof StatsPlugin)
).toBeTruthy();
});
});

describe('without differential loading', () => {
describe('polyfills', () => {
it('should set the polyfills entry', () => {
Expand Down
32 changes: 26 additions & 6 deletions packages/web/src/utils/web.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { getCommonConfig } from '@angular-devkit/build-angular/src/angular-cli-f
import { getStylesConfig } from '@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/styles';
import { Configuration } from 'webpack';
import { LoggerApi } from '@angular-devkit/core/src/logger';
import { resolve } from 'path';
import { resolve, basename } from 'path';
import { WebBuildBuilderOptions } from '../builders/build/build.impl';
import { convertBuildOptions } from './normalize';
import { readTsConfig } from '@nrwl/workspace';
import { getBaseWebpackPartial } from './config';
import { IndexHtmlWebpackPlugin } from '@angular-devkit/build-angular/src/angular-cli-files/plugins/index-html-webpack-plugin';
import { generateEntryPoints } from '@angular-devkit/build-angular/src/angular-cli-files/utilities/package-chunk-sort';
import { ScriptTarget } from 'typescript';

export function getWebConfig(
Expand Down Expand Up @@ -52,17 +53,36 @@ export function getWebConfig(
getPolyfillsPartial(options, overrideScriptTarget),
getStylesPartial(wco),
getCommonPartial(wco),
getBrowserPartial(wco)
getBrowserPartial(wco, options)
]);
}

function getBrowserPartial(wco: any) {
function getBrowserPartial(wco: any, options: WebBuildBuilderOptions) {
const config = getBrowserConfig(wco);
if (wco.buildOptions.differentialLoading) {
config.plugins = config.plugins.filter(
plugin => !(plugin instanceof IndexHtmlWebpackPlugin)

if (!wco.buildOptions.differentialLoading) {
const {
deployUrl,
subresourceIntegrity,
scripts = [],
styles = [],
index,
baseHref
} = options;

config.plugins.push(
new IndexHtmlWebpackPlugin({
input: resolve(wco.root, index),
output: basename(index),
baseHref,
entrypoints: generateEntryPoints({ scripts, styles }),
deployUrl: deployUrl,
sri: subresourceIntegrity,
noModuleEntrypoints: ['polyfills-es5']
})
);
}

return config;
}

Expand Down
5 changes: 5 additions & 0 deletions packages/workspace/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
"version": "8.3.0-beta.1",
"description": "Rename 'nx lint' into 'nx workspace-lint' to avoid confusion",
"factory": "./src/migrations/update-8-3-0/rename-lint"
},
"update-angular-cli-8-1": {
"version": "8.3.0-beta.1",
"description": "Update Angular CLI to 8.1.1",
"factory": "./src/migrations/update-8-3-0/update-ng-cli-8-1"
}
}
}
4 changes: 2 additions & 2 deletions packages/workspace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
]
},
"dependencies": {
"@angular-devkit/core": "8.0.1",
"@angular-devkit/schematics": "8.0.1",
"@angular-devkit/core": "8.1.1",
"@angular-devkit/schematics": "8.1.1",
"cosmiconfig": "4.0.0",
"fs-extra": "6.0.0",
"graphviz": "0.0.8",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Tree } from '@angular-devkit/schematics';
import { readJsonInTree } from '@nrwl/workspace';
import {
SchematicTestRunner,
UnitTestTree
} from '@angular-devkit/schematics/testing';
import { serializeJson } from '@nrwl/workspace';
import { join } from 'path';

describe('Update 8.3.0', () => {
let tree: Tree;
let schematicRunner: SchematicTestRunner;

beforeEach(() => {
tree = new UnitTestTree(Tree.empty());

tree.create(
'package.json',
serializeJson({
devDependencies: {
'@angular/cli': '8.0.0',
'@angular-devkit/build-angular': '^0.800.0',
'@angular-devkit/build-ng-packagr': '~0.800.0'
}
})
);

schematicRunner = new SchematicTestRunner(
'@nrwl/workspace',
join(__dirname, '../../../migrations.json')
);
});

describe('Update Angular CLI', () => {
it('should update @angular/cli', async () => {
const result = await schematicRunner
.runSchematicAsync('update-angular-cli-8-1', {}, tree)
.toPromise();

expect(
readJsonInTree(result, 'package.json').devDependencies['@angular/cli']
).toEqual('8.1.1');
});

it('should update @angular-devkit/build-angular', async () => {
const result = await schematicRunner
.runSchematicAsync('update-angular-cli-8-1', {}, tree)
.toPromise();

expect(
readJsonInTree(result, 'package.json').devDependencies[
'@angular-devkit/build-angular'
]
).toEqual('^0.801.1');
});

it('should update @angular-devkit/build-ng-packagr', async () => {
const result = await schematicRunner
.runSchematicAsync('update-angular-cli-8-1', {}, tree)
.toPromise();

expect(
readJsonInTree(result, 'package.json').devDependencies[
'@angular-devkit/build-ng-packagr'
]
).toEqual('~0.801.1');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { updateJsonInTree } from '@nrwl/workspace';
import { chain, SchematicContext } from '@angular-devkit/schematics';
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';

const updateCLI = updateJsonInTree('package.json', json => {
json.devDependencies = json.devDependencies || {};
const cliVersion = json.devDependencies['@angular/cli'];

if (
cliVersion &&
(cliVersion.startsWith('8.1') ||
cliVersion.startsWith('~8.1') ||
cliVersion.startsWith('^8.1'))
) {
return json;
}

if (json['devDependencies']['@angular/cli']) {
json['devDependencies']['@angular/cli'] = '8.1.1';
}

if (json['devDependencies']['@angular-devkit/build-angular']) {
json['devDependencies']['@angular-devkit/build-angular'] = '^0.801.1';
}

if (json['devDependencies']['@angular-devkit/build-ng-packagr']) {
json['devDependencies']['@angular-devkit/build-ng-packagr'] = '~0.801.1';
}

return json;
});

const addInstall = (_: any, context: SchematicContext) => {
context.addTask(new NodePackageInstallTask());
};

export default function() {
return chain([updateCLI, addInstall]);
}
2 changes: 1 addition & 1 deletion packages/workspace/src/utils/versions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const nxVersion = '*';

export const angularCliVersion = '8.0.0';
export const angularCliVersion = '8.1.1';
export const typescriptVersion = '~3.4.5';
export const prettierVersion = '1.16.4';
4 changes: 3 additions & 1 deletion scripts/check-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ function check() {
'packages/workspace/src/command-line/affected.ts',
'packages/workspace/src/schematics/preset/preset.ts',
'packages/workspace/src/schematics/ng-add/ng-add.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-ng-cli-8-1.ts'
];

const files = [
Expand Down
Loading

0 comments on commit 4f7ec84

Please sign in to comment.