diff --git a/packages/schematics/index.ts b/packages/schematics/index.ts deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/packages/schematics/migrations/legacy-migrations/20171129-change-schema.ts b/packages/schematics/migrations/legacy-migrations/20171129-change-schema.ts deleted file mode 100644 index ed3458f836459..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20171129-change-schema.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { updateJsonFile } from '@nrwl/workspace'; - -export default { - description: 'Update the schema file to point to the nrwl schema.', - run: () => { - updateJsonFile('.angular-cli.json', json => { - json['$schema'] = './node_modules/@nrwl/schematics/src/schema.json'; - }); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20171202-change-schema.ts b/packages/schematics/migrations/legacy-migrations/20171202-change-schema.ts deleted file mode 100644 index 1f668791af789..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20171202-change-schema.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { updateJsonFile } from '@nrwl/workspace'; - -export default { - description: - 'Update the schema file to reflect the `allow` option for `nx-enforce-module-boundaries`.', - run: () => { - updateJsonFile('tslint.json', json => { - const ruleName = 'nx-enforce-module-boundaries'; - const ruleOptionName = 'allow'; - const rule = ruleName in json.rules ? json.rules[ruleName] : null; - - // Only modify when the rule is configured with optional arguments - if ( - Array.isArray(rule) && - typeof rule[1] === 'object' && - rule[1] !== null - ) { - rule[1][ruleOptionName] = []; - } - }); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20171205-remove-npmscope-from-tslintjson.ts b/packages/schematics/migrations/legacy-migrations/20171205-remove-npmscope-from-tslintjson.ts deleted file mode 100644 index 4796c436af4e7..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20171205-remove-npmscope-from-tslintjson.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { updateJsonFile } from '@nrwl/workspace'; - -export default { - description: 'Remove npmScope from tslint.json', - run: () => { - updateJsonFile('tslint.json', json => { - const ruleName = 'nx-enforce-module-boundaries'; - const rule = ruleName in json.rules ? json.rules[ruleName] : null; - - // Only modify when the rule is configured with optional arguments - if ( - Array.isArray(rule) && - typeof rule[1] === 'object' && - rule[1] !== null - ) { - rule[1].npmScope = undefined; - } - }); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20171211-create-tsconfigapp-per-app.ts b/packages/schematics/migrations/legacy-migrations/20171211-create-tsconfigapp-per-app.ts deleted file mode 100644 index 952dfe7c02b09..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20171211-create-tsconfigapp-per-app.ts +++ /dev/null @@ -1,140 +0,0 @@ -import { readWorkspaceConfigPath, updateJsonFile } from '@nrwl/workspace'; -import { writeFileSync, unlinkSync } from 'fs'; -import { offsetFromRoot } from '@nrwl/workspace'; -import * as path from 'path'; - -export default { - description: 'Create tsconfig.app.json for every app', - run: () => { - const config = readWorkspaceConfigPath(); - config.apps.forEach(app => { - if (!app.root.startsWith('apps/')) return; - const offset = offsetFromRoot(app.root); - writeFileSync( - `${app.root}/tsconfig.app.json`, - `{ - "extends": "${offset}tsconfig.json", - "compilerOptions": { - "outDir": "${offset}dist/out-tsc/apps/${app.name}", - "module": "es2015" - }, - "include": [ - "**/*.ts" - /* add all lazy-loaded libraries here: "${offset}libs/my-lib/index.ts" */ - ], - "exclude": [ - "**/*.spec.ts" - ] -}` - ); - - writeFileSync( - `${path.dirname(app.root)}/e2e/tsconfig.e2e.json`, - `{ - "extends": "${offset}tsconfig.json", - "compilerOptions": { - "outDir": "${offset}dist/out-tsc/e2e/${app.name}", - "module": "commonjs", - "target": "es5", - "types": [ - "jasmine", - "jasminewd2", - "node" - ] - }, - "include": [ - "../**/*.ts" - /* add all lazy-loaded libraries here: "${offset}libs/my-lib/index.ts" */ - ], - "exclude": [ - "**/*.spec.ts" - ] -}` - ); - }); - - writeFileSync( - 'protractor.conf.js', - ` -// Protractor configuration file, see link for more information -// https://github.com/angular/protractor/blob/master/lib/config.ts - -const { SpecReporter } = require('jasmine-spec-reporter'); -const { getAppDirectoryUsingCliConfig } = require('@nrwl/schematics/src/utils/cli-config-utils'); -const appDir = getAppDirectoryUsingCliConfig(); - -exports.config = { - allScriptsTimeout: 11000, - specs: [ - appDir + '/e2e/**/*.e2e-spec.ts' - ], - capabilities: { - 'browserName': 'chrome' - }, - directConnect: true, - baseUrl: 'http://localhost:4200/', - framework: 'jasmine', - jasmineNodeOpts: { - showColors: true, - defaultTimeoutInterval: 30000, - print: function() {} - }, - onPrepare() { - require('ts-node').register({ - project: appDir + '/e2e/tsconfig.e2e.json' - }); - jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); - } -};` - ); - - writeFileSync( - `tsconfig.spec.json`, - `{ - "extends": "./tsconfig.json", - "compilerOptions": { - "outDir": "./dist/out-tsc/spec", - "module": "commonjs", - "target": "es5", - "types": [ - "jasmine", - "node" - ] - }, - "include": [ - "**/*.ts" - ], - "exclude": [ - "node_modules", - "tmp" - ] -}` - ); - - unlinkSync('tsconfig.app.json'); - unlinkSync('tsconfig.e2e.json'); - - updateJsonFile('.angular-cli.json', json => { - json.apps.forEach(app => { - app['tsconfig'] = 'tsconfig.app.json'; - }); - json.lint = [ - { - project: './tsconfig.spec.json', - exclude: '**/node_modules/**' - } - ]; - json.apps.forEach(app => { - if (!app.root.startsWith('apps/')) return; - json.lint.push({ - project: `./${app.root}/tsconfig.app.json`, - exclude: '**/node_modules/**' - }); - json.lint.push({ - project: `./apps/${app.name}/e2e/tsconfig.e2e.json`, - exclude: '**/node_modules/**' - }); - }); - }); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20171213-update-tsconfig-spec-to-exclude-e2e.ts b/packages/schematics/migrations/legacy-migrations/20171213-update-tsconfig-spec-to-exclude-e2e.ts deleted file mode 100644 index de1dd6f4133bf..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20171213-update-tsconfig-spec-to-exclude-e2e.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { updateJsonFile } from '@nrwl/workspace'; - -export default { - description: 'Update tsconfig.spec.json to exclude e2e specs', - run: () => { - updateJsonFile('tsconfig.spec.json', json => { - if (!json.exclude) { - json.exclude = ['node_modules', 'tmp']; - } - json.exclude = [ - ...json.exclude, - '**/e2e/*.ts', - '**/*.e2e-spec.ts', - '**/*.po.ts' - ]; - }); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20171219-add-affected-commands.ts b/packages/schematics/migrations/legacy-migrations/20171219-add-affected-commands.ts deleted file mode 100644 index 89d12098430a9..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20171219-add-affected-commands.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { updateJsonFile } from '@nrwl/workspace'; - -export default { - description: - 'Update package.json to include apps:affected, build:affected, e2e:affected', - run: () => { - updateJsonFile('package.json', json => { - json.scripts = { - ...json.scripts, - 'apps:affected': - 'node ./node_modules/@nrwl/schematics/src/affected/run-affected.js apps', - 'build:affected': - 'node ./node_modules/@nrwl/schematics/src/affected/run-affected.js build', - 'e2e:affected': - 'node ./node_modules/@nrwl/schematics/src/affected/run-affected.js e2e' - }; - }); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180103-update-command-line-scripts.ts b/packages/schematics/migrations/legacy-migrations/20180103-update-command-line-scripts.ts deleted file mode 100644 index 2b7325431b3d4..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180103-update-command-line-scripts.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { updateJsonFile } from '@nrwl/workspace'; - -export default { - description: 'Add format:write and format:check to npm scripts', - run: () => { - updateJsonFile('package.json', json => { - json.scripts = { - ...json.scripts, - 'apps:affected': - 'node ./node_modules/@nrwl/schematics/src/command-line/affected.js apps', - 'build:affected': - 'node ./node_modules/@nrwl/schematics/src/command-line/affected.js build', - 'e2e:affected': - 'node ./node_modules/@nrwl/schematics/src/command-line/affected.js e2e', - - 'affected:apps': - 'node ./node_modules/@nrwl/schematics/src/command-line/affected.js apps', - 'affected:build': - 'node ./node_modules/@nrwl/schematics/src/command-line/affected.js build', - 'affected:e2e': - 'node ./node_modules/@nrwl/schematics/src/command-line/affected.js e2e', - - format: - 'node ./node_modules/@nrwl/schematics/src/command-line/format.js write', - 'format:write': - 'node ./node_modules/@nrwl/schematics/src/command-line/format.js write', - 'format:check': - 'node ./node_modules/@nrwl/schematics/src/command-line/format.js check', - - 'nx-migrate': - 'node ./node_modules/@nrwl/schematics/src/command-line/nx-migrate.js' - }; - }); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180116-update-command-line-scripts-to-use-nx-command.ts b/packages/schematics/migrations/legacy-migrations/20180116-update-command-line-scripts-to-use-nx-command.ts deleted file mode 100644 index 61cfae5533975..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180116-update-command-line-scripts-to-use-nx-command.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { updateJsonFile } from '@nrwl/workspace'; - -export default { - description: 'Update npm scripts to use the nx command', - run: () => { - updateJsonFile('package.json', json => { - json.scripts = { - ...json.scripts, - - 'apps:affected': './node_modules/.bin/nx affected apps', - 'build:affected': './node_modules/.bin/nx affected build', - 'e2e:affected': './node_modules/.bin/nx affected e2e', - - 'affected:apps': './node_modules/.bin/nx affected apps', - 'affected:build': './node_modules/.bin/nx affected build', - 'affected:e2e': './node_modules/.bin/nx affected e2e', - - format: './node_modules/.bin/nx format write', - 'format:write': './node_modules/.bin/nx format write', - 'format:check': './node_modules/.bin/nx format check', - - 'nx-migrate': './node_modules/.bin/nx migrate' - }; - }); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180120-update-prettier.ts b/packages/schematics/migrations/legacy-migrations/20180120-update-prettier.ts deleted file mode 100644 index 2fef12d7c5a3a..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180120-update-prettier.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { updateJsonFile } from '@nrwl/workspace'; - -export default { - description: 'Update the version of prettier', - run: () => { - updateJsonFile('package.json', json => { - json.devDependencies = { - ...json.devDependencies, - prettier: '1.10.2' - }; - }); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180121-update-angular.ts b/packages/schematics/migrations/legacy-migrations/20180121-update-angular.ts deleted file mode 100644 index fa0538b0e8fae..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180121-update-angular.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { copyFile, updateJsonFile } from '@nrwl/workspace'; -import * as path from 'path'; - -export default { - description: 'Upgrade Angular and the CLI', - run: () => { - updateJsonFile('package.json', json => { - json.dependencies = { - ...json.dependencies, - '@angular/animations': '^5.2.0', - '@angular/common': '^5.2.0', - '@angular/compiler': '^5.2.0', - '@angular/core': '^5.2.0', - '@angular/forms': '^5.2.0', - '@angular/platform-browser': '^5.2.0', - '@angular/platform-browser-dynamic': '^5.2.0', - '@angular/router': '^5.2.0', - 'core-js': '^2.4.1', - rxjs: '^5.5.6', - 'zone.js': '^0.8.19', - '@ngrx/effects': '4.1.1', - '@ngrx/router-store': '4.1.1', - '@ngrx/store': '4.1.1' - }; - - json.devDependencies = { - ...json.devDependencies, - '@angular/cli': 'file:.angular_cli165.tgz', - '@angular/compiler-cli': '^5.2.0', - '@angular/language-service': '^5.2.0', - 'jasmine-core': '~2.8.0', - 'jasmine-spec-reporter': '~4.2.1', - karma: '~2.0.0', - 'karma-chrome-launcher': '~2.2.0', - 'ts-node': '~4.1.0', - tslint: '~5.9.1', - typescript: '2.6.2' - }; - }); - - updateJsonFile('tslint.json', json => { - json.rules['deprecation'] = { severity: 'warn' }; - json.rules['typeof-compare'] = undefined; - json.rules['whitespace'] = undefined; - }); - - copyFile( - path.join( - __dirname, - '..', - 'src', - 'collection', - 'application', - 'files', - '__directory__', - '.angular_cli165.tgz' - ), - '.' - ); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180121-update-testjs.ts b/packages/schematics/migrations/legacy-migrations/20180121-update-testjs.ts deleted file mode 100644 index 8a60f0f013c34..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180121-update-testjs.ts +++ /dev/null @@ -1,37 +0,0 @@ -import * as fs from 'fs'; - -export default { - description: 'Update test.js', - run: () => { - fs.writeFileSync( - 'test.js', - ` -// This file is required by karma.conf.js and loads recursively all the .spec and framework files -require('zone.js/dist/zone-testing'); -const getTestBed = require('@angular/core/testing').getTestBed; -const BrowserDynamicTestingModule = require('@angular/platform-browser-dynamic/testing').BrowserDynamicTestingModule; -const platformBrowserDynamicTesting = require('@angular/platform-browser-dynamic/testing').platformBrowserDynamicTesting; - -// Prevent Karma from running prematurely. -__karma__.loaded = function () {}; - -// First, initialize the Angular testing environment. -getTestBed().initTestEnvironment( - BrowserDynamicTestingModule, - platformBrowserDynamicTesting() -); -// Then we find all the tests. -const contextApps = require.context('./apps', true, /\\.spec\\.ts$/); -// And load the modules. -contextApps.keys().map(contextApps); - -const contextLibs = require.context('./libs', true, /\\.spec\\.ts$/); -// And load the modules. -contextLibs.keys().map(contextLibs); - -// Finally, start Karma to run the tests. -__karma__.start(); - ` - ); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180122-add-angular-devkit-core.ts b/packages/schematics/migrations/legacy-migrations/20180122-add-angular-devkit-core.ts deleted file mode 100644 index 3b6bb0e2a6bfd..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180122-add-angular-devkit-core.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { updateJsonFile } from '@nrwl/workspace'; - -export default { - description: 'Add @angular-devkit/core as a dev dependency', - run: () => { - updateJsonFile('package.json', json => { - json.devDependencies = { - ...json.devDependencies, - ['@angular-devkit/core']: '^0.0.29' - }; - }); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180130-add-migration-check-and-skip.ts b/packages/schematics/migrations/legacy-migrations/20180130-add-migration-check-and-skip.ts deleted file mode 100644 index 421df968d0465..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180130-add-migration-check-and-skip.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { updateJsonFile } from '@nrwl/workspace'; - -export default { - description: 'Add nx-migrate:check and nx-migrate:skip to npm scripts', - run: () => { - updateJsonFile('package.json', json => { - json.scripts = { - ...json.scripts, - - 'nx-migrate': './node_modules/.bin/nx migrate', - 'nx-migrate:check': './node_modules/.bin/nx migrate check', - 'nx-migrate:skip': './node_modules/.bin/nx migrate skip' - }; - }); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180130-add-postinstall.ts b/packages/schematics/migrations/legacy-migrations/20180130-add-postinstall.ts deleted file mode 100644 index cfcb0fbb0ce00..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180130-add-postinstall.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { updateJsonFile } from '@nrwl/workspace'; - -export default { - description: 'Add postinstall script to run nx-migrate:check', - run: () => { - updateJsonFile('package.json', json => { - if (!json.scripts.postinstall) { - json.scripts = { - ...json.scripts, - postinstall: './node_modules/.bin/nx migrate check' - }; - } - }); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180130-angular-devkit-schematics.ts b/packages/schematics/migrations/legacy-migrations/20180130-angular-devkit-schematics.ts deleted file mode 100644 index 325ce7b2f6f36..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180130-angular-devkit-schematics.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { updateJsonFile } from '@nrwl/workspace'; - -export default { - description: 'Add @angular-devkit/schematics as a dev dependency', - run: () => { - updateJsonFile('package.json', json => { - json.devDependencies = { - ...json.devDependencies, - ['@angular-devkit/schematics']: '0.0.52', - ['@schematics/angular']: '0.1.17' - }; - }); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180225-switch-to-cli17.ts b/packages/schematics/migrations/legacy-migrations/20180225-switch-to-cli17.ts deleted file mode 100644 index 1ef78de0aae85..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180225-switch-to-cli17.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { updateJsonFile } from '@nrwl/workspace'; -import { unlinkSync } from 'fs'; - -export default { - description: 'Switch to Angular CLI 1.7', - run: () => { - updateJsonFile('package.json', json => { - json.devDependencies = { - ...json.devDependencies, - '@angular/cli': '1.7.1', - '@angular/compiler-cli': '5.2.7', - '@angular/language-service': '5.2.7', - '@types/jasmine': '~2.5.53', - ['@angular-devkit/core']: undefined, - ['@angular-devkit/schematics']: undefined, - ['@schematics/angular']: undefined, - ['karma-cli']: undefined - }; - - json.dependencies = { - ...json.dependencies, - '@angular/animations': '5.2.7', - '@angular/common': '5.2.7', - '@angular/compiler': '5.2.7', - '@angular/core': '5.2.7', - '@angular/forms': '5.2.7', - '@angular/platform-browser': '5.2.7', - '@angular/platform-browser-dynamic': '5.2.7', - '@angular/router': '5.2.7', - '@ngrx/effects': '5.1.0', - '@ngrx/router-store': '5.0.1', - '@ngrx/store': '5.1.0', - '@ngrx/store-devtools': '5.1.0' - }; - - if (json.dependencies['@angular/http']) { - json.dependencies['@angular/http'] = '5.2.7'; - } - }); - - try { - unlinkSync('.angular_cli165.tgz'); - } catch (e) {} - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180227-cleanup-scripts.ts b/packages/schematics/migrations/legacy-migrations/20180227-cleanup-scripts.ts deleted file mode 100644 index b5a1d468ad86b..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180227-cleanup-scripts.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { updateJsonFile } from '@nrwl/workspace'; - -export default { - description: 'Add update, update:skip, update:check scripts', - run: () => { - updateJsonFile('package.json', json => { - json.scripts = { - ...json.scripts, - update: './node_modules/.bin/nx update', - 'update:check': './node_modules/.bin/nx update check', - 'update:skip': './node_modules/.bin/nx update skip', - 'nx-migrate': undefined, - 'nx-migrate:check': undefined, - 'nx-migrate:skip': undefined, - 'apps:affected': undefined, - 'build:affected': undefined, - 'e2e:affected': undefined - }; - - if (json.scripts.postinstall === './node_modules/.bin/nx migrate check') { - json.scripts.postinstall = './node_modules/.bin/nx postinstall'; - } - }); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180309-create-or-update-prettierrc-file.ts b/packages/schematics/migrations/legacy-migrations/20180309-create-or-update-prettierrc-file.ts deleted file mode 100644 index 92d39fcaa265a..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180309-create-or-update-prettierrc-file.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { writeFileSync, unlinkSync } from 'fs'; -import { join } from 'path'; - -import { updateJsonFile } from '@nrwl/workspace'; -import { - ExistingPrettierConfig, - resolveUserExistingPrettierConfig -} from '@nrwl/workspace'; - -export default { - description: 'Create or update prettier configuration', - run: async () => { - const resolvedExisting = await resolveUserExistingPrettierConfig(); - const existingUserConfig = { - ...(resolvedExisting ? resolvedExisting.config : null) - }; - const PREVIOUSLY_HARDCODED_NRWL_CONFIG = { - singleQuote: true, - printWidth: 120 - }; - const finalConfig = { - ...existingUserConfig, - ...PREVIOUSLY_HARDCODED_NRWL_CONFIG - }; - // cleanup old configuration source, if applicable - if (resolvedExisting) { - cleanUpExistingConfig(resolvedExisting); - } - // create new configuration file - writeFileSync('.prettierrc', JSON.stringify(finalConfig, null, 2)); - } -}; - -function cleanUpExistingConfig(resolvedExisting: ExistingPrettierConfig): void { - switch (resolvedExisting.sourceFilepath) { - case join(process.cwd(), 'package.json'): - return updateJsonFile('package.json', json => { - delete json.prettier; - }); - default: - return unlinkSync(resolvedExisting.sourceFilepath); - } -} diff --git a/packages/schematics/migrations/legacy-migrations/20180313-add-tags.ts b/packages/schematics/migrations/legacy-migrations/20180313-add-tags.ts deleted file mode 100644 index 8668a7f56ee95..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180313-add-tags.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { updateJsonFile } from '@nrwl/workspace'; - -export default { - description: 'Add tags to all app and libs', - run: async () => { - updateJsonFile('.angular-cli.json', json => { - json.apps = json.apps.map(app => ({ ...app, tags: [] })); - }); - - updateJsonFile('tslint.json', json => { - if (json.rules['nx-enforce-module-boundaries']) { - json.rules['nx-enforce-module-boundaries'][1].depConstraints = [ - { sourceTag: '*', onlyDependOnLibsWithTags: ['*'] } - ]; - json.rules['nx-enforce-module-boundaries'][1].lazyLoad = undefined; - } - }); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180321-add-karma-app-check.ts b/packages/schematics/migrations/legacy-migrations/20180321-add-karma-app-check.ts deleted file mode 100644 index ffc72b078586a..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180321-add-karma-app-check.ts +++ /dev/null @@ -1,50 +0,0 @@ -import * as fs from 'fs'; -import * as ts from 'typescript'; -import { stripIndents } from '@angular-devkit/core/src/utils/literals'; -import { getSourceNodes } from '@nrwl/workspace/src/utils/ast-utils'; - -export default { - description: 'Add makeSureNoAppIsSelected(); to karma conf', - run: async () => { - const contents = fs.readFileSync('karma.conf.js').toString(); - const sourceFile = ts.createSourceFile( - 'karma.conf.js', - contents, - ts.ScriptTarget.Latest - ); - const nodes = getSourceNodes(sourceFile); - const isPresent = nodes - .filter(ts.isCallExpression) - .filter((callExpr: ts.CallExpression) => - ts.isIdentifier(callExpr.expression) - ) - .some((callExpr: ts.CallExpression) => { - const identifier = callExpr.expression as ts.Identifier; - return identifier.escapedText === 'makeSureNoAppIsSelected'; - }); - - if (isPresent) { - return; - } - - const snippet = stripIndents` - const { makeSureNoAppIsSelected } = require('@nrwl/schematics/src/utils/cli-config-utils'); - // Nx only supports running unit tests for all apps and libs. - makeSureNoAppIsSelected(); - `; - - const karmaComment = stripIndents` - // Karma configuration file, see link for more information - // https://karma-runner.github.io/1.0/config/configuration-file.html - `; - - let res: string; - if (contents.includes(karmaComment)) { - res = contents.replace(karmaComment, karmaComment + '\n\n' + snippet); - } else { - res = snippet + '\n\n' + contents; - } - - fs.writeFileSync('karma.conf.js', res); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180328-add-nx-lint.ts b/packages/schematics/migrations/legacy-migrations/20180328-add-nx-lint.ts deleted file mode 100644 index 85b87d608ebce..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180328-add-nx-lint.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { updateJsonFile } from '@nrwl/workspace'; - -export default { - description: 'Run lint checks ensuring the integrity of the workspace', - run: () => { - updateJsonFile('package.json', json => { - json.scripts = { - ...json.scripts, - lint: './node_modules/.bin/nx lint && ng lint' - }; - }); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180404-adding-dep-graph.ts b/packages/schematics/migrations/legacy-migrations/20180404-adding-dep-graph.ts deleted file mode 100644 index feee47fb195a6..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180404-adding-dep-graph.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { updateJsonFile } from '@nrwl/workspace'; - -export default { - description: 'Update npm scripts to use the nx command', - run: () => { - updateJsonFile('package.json', json => { - json.scripts = { - ...json.scripts, - 'dep-graph': './node_modules/.bin/nx dep-graph', - 'affected:dep-graph': './node_modules/.bin/nx affected dep-graph' - }; - }); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180405-add-tools-directory.ts b/packages/schematics/migrations/legacy-migrations/20180405-add-tools-directory.ts deleted file mode 100644 index ca02322cf2803..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180405-add-tools-directory.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { mkdirSync, writeFileSync } from 'fs'; -import * as path from 'path'; - -export default { - description: 'Add tools directory', - run: () => { - try { - mkdirSync('tools'); - } catch (e) {} - try { - mkdirSync(path.join('tools', 'schematics')); - } catch (e) {} - writeFileSync(path.join('tools', 'schematics', '.gitkeep'), ''); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180405-add-workspace-schematic-command.ts b/packages/schematics/migrations/legacy-migrations/20180405-add-workspace-schematic-command.ts deleted file mode 100644 index 66e0fddc7dc6e..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180405-add-workspace-schematic-command.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { updateJsonFile } from '@nrwl/workspace'; - -export default { - description: 'Add a command to generate workspace-specific schematics', - run: () => { - updateJsonFile('package.json', json => { - json.scripts = { - ...json.scripts, - 'workspace-schematic': './node_modules/.bin/nx workspace-schematic' - }; - }); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180412-nx-update-scripts.ts b/packages/schematics/migrations/legacy-migrations/20180412-nx-update-scripts.ts deleted file mode 100644 index 38e7e6bafade5..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180412-nx-update-scripts.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { updateJsonFile } from '@nrwl/workspace'; - -export default { - description: 'Update script to use an updated way of invoking Nx commands', - run: () => { - updateJsonFile('package.json', json => { - json.scripts = { - ...json.scripts, - 'affected:apps': './node_modules/.bin/nx affected:apps', - 'affected:build': './node_modules/.bin/nx affected:build', - 'affected:e2e': './node_modules/.bin/nx affected:e2e', - 'affected:dep-graph': './node_modules/.bin/nx affected:dep-graph', - format: './node_modules/.bin/nx format:write', - 'format:write': './node_modules/.bin/nx format:write', - 'format:check': './node_modules/.bin/nx format:check', - update: './node_modules/.bin/nx update', - 'update:check': './node_modules/.bin/nx update:check', - 'update:skip': './node_modules/.bin/nx update:skip', - 'workspace-schematic': './node_modules/.bin/nx workspace-schematic', - 'dep-graph': './node_modules/.bin/nx dep-graph', - help: './node_modules/.bin/nx help' - }; - }); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180424-add-tsconfig-tools.ts b/packages/schematics/migrations/legacy-migrations/20180424-add-tsconfig-tools.ts deleted file mode 100644 index a19086a01a130..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180424-add-tsconfig-tools.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { writeFileSync } from 'fs'; -import * as path from 'path'; - -export default { - description: 'Add tsconfig.tools.json', - run: () => { - writeFileSync( - path.join('tools', 'tsconfig.tools.json'), - JSON.stringify( - { - extends: '../tsconfig.json', - compilerOptions: { - outDir: '../dist/out-tsc/tools', - rootDir: '.', - module: 'commonjs', - target: 'es5', - types: ['jasmine', 'node'] - }, - include: ['**/*.ts'] - }, - null, - 2 - ) - ); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180507-create-nx-json.ts b/packages/schematics/migrations/legacy-migrations/20180507-create-nx-json.ts deleted file mode 100644 index 6975065b8dde8..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180507-create-nx-json.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { existsSync, writeFileSync } from 'fs'; -import { readJsonFile, serializeJson } from '@nrwl/workspace'; -import { stripIndents } from '@angular-devkit/core/src/utils/literals'; - -export default { - description: `Create nx.json before migrating to Angular CLI 6.`, - run: () => { - if (!existsSync('.angular-cli.json') && existsSync('angular.json')) { - console.warn(stripIndents` - You have already upgraded to Angular CLI 6. - We will not be able to recover information about your project's tags for you. - `); - return; - } - - const workspaceJson = readJsonFile('.angular-cli.json'); - const projects = workspaceJson.apps.reduce((projects, app) => { - if (app.name === '$workspaceRoot') { - return projects; - } - const normalizedName = app.name.replace(new RegExp('/', 'g'), '-'); - projects[normalizedName] = { - tags: app.tags - }; - if (app.root.startsWith('apps/')) { - projects[`${normalizedName}-e2e`] = { - tags: [] - }; - } - - return projects; - }, {}); - writeFileSync( - 'nx.json', - serializeJson({ - npmScope: workspaceJson.project.npmScope, - projects: projects - }) - ); - } -}; diff --git a/packages/schematics/migrations/legacy-migrations/20180515-switch-to-nx6.ts b/packages/schematics/migrations/legacy-migrations/20180515-switch-to-nx6.ts deleted file mode 100644 index 03d511e373a6d..0000000000000 --- a/packages/schematics/migrations/legacy-migrations/20180515-switch-to-nx6.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { existsSync } from 'fs'; -import { readJsonFile, updateJsonFile } from '@nrwl/workspace'; -import { stripIndents } from '@angular-devkit/core/src/utils/literals'; -import { execSync } from 'child_process'; -import { join } from 'path'; - -export default { - description: `Switch to Nx 6.0`, - run: () => { - if (!existsSync('.angular-cli.json') && existsSync('angular.json')) { - console.warn(stripIndents` - You have already upgraded to Angular CLI 6. - We will not be able to recover information about your project's tags for you. - `); - return; - } - - updateJsonFile('package.json', json => { - json.devDependencies['@angular/cli'] = '6.1.2'; - }); - - updateJsonFile('package.json', json => { - delete json.scripts.postinstall; - }); - - try { - if (existsSync('yarn.lock')) { - execSync('yarn install', { stdio: [0, 1, 2] }); - } else { - execSync('npm install', { stdio: [0, 1, 2] }); - } - - execSync( - 'ng update @angular/cli --from 1.7.4 --to 6.0.1 --migrate-only', - { - stdio: [0, 1, 2] - } - ); - - const currentVersion = readJsonFile(join(__dirname, '../../package.json')) - .version; - execSync( - `ng generate @schematics/update:migrate --package @nrwl/schematics --collection @nrwl/schematics/migrations/migrations.json --from 1.0.3 --to ${currentVersion}`, - { - stdio: [0, 1, 2] - } - ); - } catch (e) { - console.warn(stripIndents` - The automatic upgrade to Nx 6 has failed with the following error: ${e}. - - You can upgrade it manually by running: - - * yarn install or npm install - * ng update @angular/cli@6.0.1 - * ng update @nrwl/schematics@6.0.0 - - The upgrade process creates a test target for every library. If you have a library - that does not have specs, either set failOnEmptyTestSuite to false in karma.conf.js of the library, - or remove the test target in angular.json. - `); - throw e; - } - - console.log(stripIndents` - The upgrade process creates a test target for every library. If you have a library - that does not have specs, either set failOnEmptyTestSuite to false in karma.conf.js of the library, - or remove the test target in angular.json. - `); - } -}; diff --git a/packages/schematics/migrations/migrations.json b/packages/schematics/migrations/migrations.json deleted file mode 100644 index dff5224d8bdd7..0000000000000 --- a/packages/schematics/migrations/migrations.json +++ /dev/null @@ -1,79 +0,0 @@ -{ - "schematics": { - "update-6.0.0": { - "version": "6", - "description": "Update to Angular CLI 6 and Nx6", - "factory": "./update-6-0-0/update-6-0-0" - }, - "update-6.0.5": { - "version": "6.0.5", - "description": "Add affected:lint npm script", - "factory": "./update-6-0-5/update-6-0-5" - }, - "update-6.1.0": { - "version": "6.1.0", - "description": "Add implicitDependencies to nx.json", - "factory": "./update-6-1-0/update-6-1-0" - }, - "update-6.2.0": { - "version": "6.2.0", - "description": "Add Global Karma Conf", - "factory": "./update-6-2-0/update-6-2-0" - }, - "update-6.3.2": { - "version": "6.3.2", - "description": "Update jest-preset-angular", - "factory": "./update-6-3-2/update-6-3-2" - }, - "update-6.4.0": { - "version": "6.4.0", - "description": "Update to @angular/cli@6.2.3", - "factory": "./update-6-4-0/update-6-4-0" - }, - "update-7.0.0": { - "version": "7.0.0", - "description": "Update to @angular v7", - "factory": "./update-7-0-0/update-7-0-0" - }, - "update-7.0.2": { - "version": "7.0.2", - "description": "Fix karma conf", - "factory": "./update-7-0-2/update-7-0-2" - }, - "update-7.1.0": { - "version": "7.1.0", - "description": "Add generic affected command", - "factory": "./update-7-1-0/update-7-1-0" - }, - "update-7.2.0": { - "version": "7.2.0", - "description": "Create tsconfig.jsons in project roots", - "factory": "./update-7-2-0/update-7-2-0" - }, - "update-7.5.0": { - "version": "7.5.0", - "description": "Updated Angular CLI and Typescript", - "factory": "./update-7-5-0/update-7-5-0" - }, - "update-7.6.0": { - "version": "7.6.0", - "description": "Add VSCode Extensions and Update NgRx", - "factory": "./update-7-6-0/update-7-6-0" - }, - "update-7.7.0": { - "version": "7.7.0", - "description": "Default library framework to Angular", - "factory": "./update-7-7-0/update-7-7-0" - }, - "update-7.8.1": { - "version": "7.8.1", - "description": "Update prettier", - "factory": "./update-7-8-1/update-7-8-1" - }, - "update-8.0.0": { - "version": "8.0.0-beta.3", - "description": "V8 migrations", - "factory": "./update-8-0-0/update-8-0-0" - } - } -} diff --git a/packages/schematics/migrations/update-6-0-0/helpers.ts b/packages/schematics/migrations/update-6-0-0/helpers.ts deleted file mode 100644 index 283cb8c1e6da9..0000000000000 --- a/packages/schematics/migrations/update-6-0-0/helpers.ts +++ /dev/null @@ -1,94 +0,0 @@ -import * as ts from 'typescript'; - -export function findFunctionCallExpressionStatement( - nodes: ts.Node[], - functionName: string -): ts.ExpressionStatement { - return nodes.find( - node => - ts.isExpressionStatement(node) && - ts.isCallExpression(node.expression) && - ts.isIdentifier(node.expression.expression) && - node.expression.expression.escapedText === functionName - ) as ts.ExpressionStatement; -} - -export function findFunctionCalls( - sourceFile: ts.SourceFile, - functionName: string -) { - return sourceFile.statements.filter(statement => { - if (!ts.isVariableStatement(statement)) { - return false; - } - const declarations = statement.declarationList.declarations; - - return declarations.some(declaration => { - if ( - !ts.isCallExpression(declaration.initializer) || - !ts.isIdentifier(declaration.initializer.expression) - ) { - return false; - } - - return declaration.initializer.expression.text === functionName; - }); - }) as ts.VariableStatement[]; -} - -export function findRequireStatement(nodes: ts.Node[]): ts.VariableStatement { - return nodes.find(node => { - if (!ts.isVariableStatement(node)) { - return false; - } - - const requireDeclaration = node.declarationList.declarations.find( - declaration => { - if (!ts.isCallExpression(declaration.initializer)) { - return false; - } - - const callExpression = declaration.initializer; - if ( - ts.isIdentifier(callExpression.expression) && - callExpression.expression.escapedText === 'require' && - ts.isStringLiteral(callExpression.arguments[0]) - ) { - const argument = callExpression.arguments[0] as ts.StringLiteral; - return ( - argument.text === '@nrwl/schematics/src/utils/cli-config-utils' - ); - } - return false; - } - ) as ts.VariableDeclaration; - - return !!requireDeclaration; - }) as ts.VariableStatement; -} - -export function findSpecDeclaration(nodes: ts.Node[]) { - return nodes.find( - node => - ts.isPropertyAssignment(node) && - ts.isIdentifier(node.name) && - node.name.text === 'specs' && - ts.isArrayLiteralExpression(node.initializer) - ) as ts.PropertyAssignment; -} - -export function findTsNodeRegisterExpression(nodes: ts.Node[]) { - return nodes.find( - node => - ts.isCallExpression(node) && - ts.isPropertyAccessExpression(node.expression) && - ts.isIdentifier(node.expression.name) && - node.expression.name.text === 'register' && - ts.isCallExpression(node.expression.expression) && - ts.isIdentifier(node.expression.expression.expression) && - node.expression.expression.expression.text === 'require' && - ts.isStringLiteral(node.expression.expression.arguments[0]) && - (node.expression.expression.arguments[0] as ts.StringLiteral).text === - 'ts-node' - ) as ts.CallExpression; -} diff --git a/packages/schematics/migrations/update-6-0-0/update-6-0-0.ts b/packages/schematics/migrations/update-6-0-0/update-6-0-0.ts deleted file mode 100644 index 6e65a9017e385..0000000000000 --- a/packages/schematics/migrations/update-6-0-0/update-6-0-0.ts +++ /dev/null @@ -1,700 +0,0 @@ -import { - chain, - Rule, - SchematicContext, - Tree -} from '@angular-devkit/schematics'; -import { stripIndents } from '@angular-devkit/core/src/utils/literals'; -import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks'; - -import { - createOrUpdate, - readJsonInTree, - updateJsonInTree, - updateWorkspaceInTree -} from '@nrwl/workspace'; -import { serializeJson, renameSync } from '@nrwl/workspace'; -import { parseTarget, serializeTarget } from '@nrwl/workspace'; -import { offsetFromRoot } from '@nrwl/workspace'; -import { formatFiles } from '@nrwl/workspace'; -import { NxJson } from '@nrwl/workspace'; - -function createKarma(host: Tree, project: any) { - const offset = offsetFromRoot(project.root); - - createOrUpdate( - host, - `${project.root}/karma.conf.js`, - ` -// Karma configuration file, see link for more information -// https://karma-runner.github.io/1.0/config/configuration-file.html - -module.exports = function (config) { - config.set({ - basePath: '', - frameworks: ['jasmine', '@angular-devkit/build-angular'], - plugins: [ - require('karma-jasmine'), - require('karma-chrome-launcher'), - require('karma-jasmine-html-reporter'), - require('karma-coverage-istanbul-reporter'), - require('@angular-devkit/build-angular/plugins/karma') - ], - client: { - clearContext: false // leave Jasmine Spec Runner output visible in browser - }, - coverageIstanbulReporter: { - dir: require('path').join(__dirname, '${offset}coverage'), - reports: ['html', 'lcovonly'], - fixWebpackSourcePaths: true - }, - reporters: ['progress', 'kjhtml'], - port: 9876, - colors: true, - logLevel: config.LOG_INFO, - autoWatch: true, - browsers: ['Chrome'], - singleRun: false - }); -}; - ` - ); -} - -function createProtractor(host: Tree, project: any) { - createOrUpdate( - host, - `${project.root}/protractor.conf.js`, - ` -// Protractor configuration file, see link for more information -// https://github.com/angular/protractor/blob/master/lib/config.ts - -const { SpecReporter } = require('jasmine-spec-reporter'); - -exports.config = { - allScriptsTimeout: 11000, - specs: [ - './src/**/*.e2e-spec.ts' - ], - capabilities: { - 'browserName': 'chrome' - }, - directConnect: true, - baseUrl: 'http://localhost:4200/', - framework: 'jasmine', - jasmineNodeOpts: { - showColors: true, - defaultTimeoutInterval: 30000, - print: function() {} - }, - onPrepare() { - require('ts-node').register({ - project: require('path').join(__dirname, './tsconfig.e2e.json') - }); - jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); - } -}; - ` - ); -} - -function createTestTs(host: Tree, project: any) { - if (project.projectType === 'library') { - createOrUpdate( - host, - `${project.sourceRoot}/test.ts`, - ` -// This file is required by karma.conf.js and loads recursively all the .spec and framework files - -import 'core-js/es7/reflect'; -import 'zone.js/dist/zone'; -import 'zone.js/dist/zone-testing'; -import { getTestBed } from '@angular/core/testing'; -import { - BrowserDynamicTestingModule, - platformBrowserDynamicTesting -} from '@angular/platform-browser-dynamic/testing'; - -declare const require: any; - -// First, initialize the Angular testing environment. -getTestBed().initTestEnvironment( - BrowserDynamicTestingModule, - platformBrowserDynamicTesting() -); -// Then we find all the tests. -const context = require.context('./', true, /\\.spec\\.ts$/); -// And load the modules. -context.keys().map(context); - ` - ); - } else { - createOrUpdate( - host, - `${project.sourceRoot}/test.ts`, - ` -// This file is required by karma.conf.js and loads recursively all the .spec and framework files - - import 'zone.js/dist/zone-testing'; - import { getTestBed } from '@angular/core/testing'; - import { - BrowserDynamicTestingModule, - platformBrowserDynamicTesting - } from '@angular/platform-browser-dynamic/testing'; - - declare const require: any; - -// First, initialize the Angular testing environment. - getTestBed().initTestEnvironment( - BrowserDynamicTestingModule, - platformBrowserDynamicTesting() - ); -// Then we find all the tests. - const context = require.context('./', true, /\.spec\.ts$/); -// And load the modules. - context.keys().map(context); - ` - ); - } - return host; -} - -function createBrowserlist(host: Tree, project: any) { - createOrUpdate( - host, - `${project.root}/browserslist`, - stripIndents` - # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers - # For additional information regarding the format and rule options, please see: - # https://github.com/browserslist/browserslist#queries - # For IE 9-11 support, please uncomment the last line of the file and adjust as needed - > 0.5% - last 2 versions - Firefox ESR - not dead - # IE 9-11 - ` - ); -} - -function createTsconfigSpecJson(host: Tree, project: any) { - const files = ['src/test.ts']; - - const offset = offsetFromRoot(project.root); - - const compilerOptions = { - outDir: `${offset}dist/out-tsc/${project.root}`, - types: ['jasmine', 'node'] - }; - - if (project.projectType === 'application') { - files.push('src/polyfills.ts'); - compilerOptions['module'] = 'commonjs'; - } - - createOrUpdate( - host, - `${project.root}/tsconfig.spec.json`, - serializeJson({ - extends: `${offset}tsconfig.json`, - compilerOptions, - files, - include: ['**/*.spec.ts', '**/*.d.ts'] - }) - ); -} - -function createTslintJson(host: Tree, project: any) { - const offset = offsetFromRoot(project.root); - - createOrUpdate( - host, - `${project.root}/tslint.json`, - serializeJson({ - extends: `${offset}tslint.json`, - rules: { - 'directive-selector': [true, 'attribute', project.prefix, 'camelCase'], - 'component-selector': [true, 'element', project.prefix, 'kebab-case'] - } - }) - ); -} - -function createTsconfigLibJson(host: Tree, project: any) { - const offset = offsetFromRoot(project.root); - - createOrUpdate( - host, - `${project.root}/tsconfig.lib.json`, - serializeJson({ - extends: `${offset}tsconfig.json`, - compilerOptions: { - outDir: `${offset}out-tsc/${project.root}`, - target: 'es2015', - module: 'es2015', - moduleResolution: 'node', - declaration: true, - sourceMap: true, - inlineSources: true, - emitDecoratorMetadata: true, - experimentalDecorators: true, - importHelpers: true, - types: [], - lib: ['dom', 'es2015'] - }, - angularCompilerOptions: { - annotateForClosureCompiler: true, - skipTemplateCodegen: true, - strictMetadataEmit: true, - fullTemplateTypeCheck: true, - strictInjectionParameters: true, - flatModuleId: 'AUTOGENERATED', - flatModuleOutFile: 'AUTOGENERATED' - }, - exclude: ['src/test.ts', '**/*.spec.ts'] - }) - ); -} - -function createAdditionalFiles(host: Tree) { - const workspaceJson = readJsonInTree(host, 'angular.json'); - Object.entries(workspaceJson.projects).forEach(([key, project]) => { - if (project.architect.test) { - createTsconfigSpecJson(host, project); - createKarma(host, project); - createTestTs(host, project); - } - - if (project.projectType === 'application' && !project.architect.e2e) { - createBrowserlist(host, project); - createTslintJson(host, project); - } - - if (project.projectType === 'application' && project.architect.e2e) { - createProtractor(host, project); - } - - if (project.projectType === 'library') { - createTsconfigLibJson(host, project); - createTslintJson(host, project); - } - }); - return host; -} - -function moveE2eTests(host: Tree, context: SchematicContext) { - const workspaceJson = readJsonInTree(host, 'angular.json'); - - Object.entries(workspaceJson.projects).forEach(([key, p]) => { - if (p.projectType === 'application' && !p.architect.e2e) { - renameSync(`${p.root}/e2e`, `${p.root}-e2e/src`, err => { - if (!err) { - context.logger.info(`Moved ${p.root}/e2e to ${p.root}-e2e/src`); - return; - } - - context.logger.info( - `We could not find e2e tests for the ${key} project.` - ); - context.logger.info( - `Ignore this if there are no e2e tests for ${key} project.` - ); - context.logger.warn(err.message); - context.logger.warn( - `If there are e2e tests for the ${key} project, we recommend manually moving them to ${p.root}-e2e/src.` - ); - }); - } - }); -} - -function deleteUnneededFiles(host: Tree) { - try { - host.delete('karma.conf.js'); - host.delete('protractor.conf.js'); - host.delete('tsconfig.spec.json'); - host.delete('test.js'); - } catch (e) {} - return host; -} - -function patchLibIndexFiles(host: Tree, context: SchematicContext) { - const workspaceJson = readJsonInTree(host, 'angular.json'); - - Object.entries(workspaceJson.projects).forEach(([key, p]) => { - if (p.projectType === 'library') { - try { - // TODO: incorporate this into fileutils.renameSync - renameSync(p.sourceRoot, `${p.root}/lib`, err => { - if (err) { - context.logger.warn( - `We could not resolve the "sourceRoot" of the ${key} library.` - ); - throw err; - } - renameSync(`${p.root}/lib`, `${p.sourceRoot}/lib`, err => { - // This should never error - context.logger.info(`Moved ${p.sourceRoot} to ${p.sourceRoot}/lib`); - context.logger.warn( - 'Deep imports may have been affected. Always try to import from the index of the lib.' - ); - }); - }); - const npmScope = readJsonInTree(host, 'nx.json').npmScope; - host = updateJsonInTree('tsconfig.json', json => { - json.compilerOptions.paths = json.compilerOptions.paths || {}; - json.compilerOptions.paths[ - `@${npmScope}/${p.root.replace('libs/', '')}` - ] = [`${p.sourceRoot}/index.ts`]; - return json; - })(host, context) as Tree; - const content = host.read(`${p.root}/index.ts`).toString(); - host.create( - `${p.sourceRoot}/index.ts`, - content.replace(new RegExp('/src/', 'g'), '/lib/') - ); - host.delete(`${p.root}/index.ts`); - } catch (e) { - context.logger.warn(`Nx failed to successfully update '${p.root}'.`); - context.logger.warn(`Error message: ${e.message}`); - context.logger.warn(`Please update the library manually.`); - } - } - }); - - return host; -} - -const updatePackageJson = updateJsonInTree('package.json', json => { - json.dependencies = json.dependencies || {}; - json.devDependencies = json.devDependencies || {}; - - json.scripts = { - ...json.scripts, - 'affected:test': './node_modules/.bin/nx affected:test' - }; - - json.dependencies = { - ...json.dependencies, - // Migrating Angular Dependencies because ng update @angular/core doesn't work well right now - '@angular/animations': '6.0.1', - '@angular/common': '6.0.1', - '@angular/compiler': '6.0.1', - '@angular/core': '6.0.1', - '@angular/forms': '6.0.1', - '@angular/platform-browser': '6.0.1', - '@angular/platform-browser-dynamic': '6.0.1', - '@angular/router': '6.0.1', - rxjs: '6.0.0', - 'rxjs-compat': '6.0.0', - 'zone.js': '^0.8.26', - 'core-js': '^2.5.4', - // End Angular Versions - '@ngrx/effects': '6.0.1', - '@ngrx/router-store': '6.0.1', - '@ngrx/store': '6.0.1', - '@ngrx/store-devtools': '6.0.1', - '@nrwl/nx': '6.0.2' - }; - json.devDependencies = { - ...json.devDependencies, - // Migrating Angular Dependencies because ng update @angular/core doesn't work well right now - '@angular/compiler-cli': '6.0.1', - '@angular/language-service': '6.0.1', - // End Angular Versions - typescript: '2.7.2', - 'jasmine-marbles': '0.3.1', - '@types/jasmine': '~2.8.6', - '@types/jasminewd2': '~2.0.3', - '@types/node': '~8.9.4', - codelyzer: '~4.2.1', - 'jasmine-core': '~2.99.1', - 'jasmine-spec-reporter': '~4.2.1', - karma: '~2.0.0', - 'karma-chrome-launcher': '~2.2.0', - 'karma-coverage-istanbul-reporter': '~1.4.2', - 'karma-jasmine': '~1.1.0', - 'karma-jasmine-html-reporter': '^0.2.2', - protractor: '~5.3.0', - 'ts-node': '~5.0.1', - tslint: '~5.9.1', - prettier: '1.10.2' - }; - - if (json.dependencies['@angular/http']) { - json.dependencies['@angular/http'] = '6.0.1'; - } - - if (json.dependencies['@angular/platform-server']) { - json.dependencies['@angular/platform-server'] = '6.0.1'; - } - - if (json.dependencies['@angular/service-worker']) { - json.dependencies['@angular/service-worker'] = '6.0.1'; - } - - if (json.dependencies['@angular/platform-webworker']) { - json.dependencies['@angular/platform-webworker'] = '6.0.1'; - } - - if (json.dependencies['@angular/platform-webworker-dynamic']) { - json.dependencies['@angular/platform-webworker-dynamic'] = '6.0.1'; - } - - if (json.dependencies['@angular/upgrade']) { - json.dependencies['@angular/upgrade'] = '6.0.1'; - } - - return json; -}); - -function createDefaultAppTsConfig(host: Tree, project: any) { - const offset = offsetFromRoot(project.root); - - const defaultAppTsConfig = { - extends: `${offset}tsconfig.json`, - compilerOptions: { - outDir: `${offset}dist/out-tsc/${project.root}`, - module: 'es2015' - }, - include: ['**/*.ts'], - exclude: ['src/test.ts', '**/*.spec.ts'] - }; - createOrUpdate( - host, - `${project.root}/tsconfig.app.json`, - serializeJson(defaultAppTsConfig) - ); -} - -function createDefaultE2eTsConfig(host: Tree, project: any) { - const offset = offsetFromRoot(project.root); - - const defaultE2eTsConfig = { - extends: `${offset}tsconfig.json`, - compilerOptions: { - outDir: `${offset}dist/out-tsc/${project.root}`, - module: 'commonjs', - target: 'es5', - types: ['jasmine', 'jasminewd2', 'node'] - } - }; - createOrUpdate( - host, - - `${project.root}/tsconfig.e2e.json`, - serializeJson(defaultE2eTsConfig) - ); -} - -function updateTsConfigs(host: Tree) { - const workspaceJson = readJsonInTree(host, 'angular.json'); - Object.entries(workspaceJson.projects).forEach(([key, project]) => { - if ( - project.architect.build && - project.architect.build.options.main.startsWith('apps') - ) { - const offset = offsetFromRoot(project.root); - const originalTsConfigPath = `${project.root}/src/tsconfig.app.json`; - if (host.exists(originalTsConfigPath)) { - const tsConfig = readJsonInTree(host, originalTsConfigPath); - if (!(tsConfig.exclude as string[]).includes('src/test.ts')) { - tsConfig.exclude.push('src/test.ts'); - } - - createOrUpdate( - host, - - `${project.root}/tsconfig.app.json`, - serializeJson({ - ...tsConfig, - extends: `${offset}tsconfig.json`, - compilerOptions: { - ...tsConfig.compilerOptions, - outDir: `${offset}dist/out-tsc/${project.root}` - }, - include: tsConfig.include.map((include: string) => { - if (include.startsWith('../../../')) { - include = include.substring(3); - } - - if (include.includes('/libs/') && include.endsWith('index.ts')) { - include = include.replace('index.ts', 'src/index.ts'); - } - return include; - }) - }) - ); - host.delete(`${project.root}/src/tsconfig.app.json`); - } else { - createDefaultAppTsConfig(host, project); - } - } - - if (project.architect.e2e) { - const offset = offsetFromRoot(project.root); - - if (host.exists(`${project.root}/src/tsconfig.e2e.json`)) { - const tsConfig = readJsonInTree( - host, - `${project.root}/src/tsconfig.e2e.json` - ); - tsConfig.extends = `${offset}tsconfig.json`; - tsConfig.compilerOptions = { - ...tsConfig.compilerOptions, - outDir: `${offset}dist/out-tsc/${project.root}` - }; - delete tsConfig.include; - delete tsConfig.exclude; - createOrUpdate( - host, - - `${project.root}/tsconfig.e2e.json`, - serializeJson(tsConfig) - ); - host.delete(`${project.root}/src/tsconfig.e2e.json`); - } else { - createDefaultE2eTsConfig(host, project); - } - } - }); - return host; -} - -const updateworkspaceJson = updateWorkspaceInTree(json => { - json.newProjectRoot = ''; - json.cli = { - ...json.cli, - defaultCollection: '@nrwl/schematics' - }; - delete json.projects.$workspaceRoot; - delete json.projects['$workspaceRoot-e2e']; - const prefix = json.schematics['@nrwl/schematics:component'].prefix; - delete json.schematics; - json.defaultProject = pathToName(json.defaultProject); - - const projects = {}; - - Object.entries(json.projects).forEach(([key, project]) => { - const type = !project.architect.build - ? 'e2e' - : project.architect.build.options.main.startsWith('apps') - ? 'application' - : 'library'; - if (type !== 'e2e') { - project.projectType = type; - } - - switch (type) { - case 'application': - project.prefix = prefix; - - project.architect.build.options.tsConfig = `${project.root}/tsconfig.app.json`; - project.architect.test.options.karmaConfig = `${project.root}/karma.conf.js`; - project.architect.test.options.tsConfig = `${project.root}/tsconfig.spec.json`; - - project.architect.test.options.main = `${project.sourceRoot}/test.ts`; - - project.architect.lint.options.tsConfig = [ - `${project.root}/tsconfig.app.json`, - `${project.root}/tsconfig.spec.json` - ]; - - project.architect.serve.options.browserTarget = serializeTarget( - parseAndNormalizeTarget(project.architect.serve.options.browserTarget) - ); - project.architect.serve.configurations.production.browserTarget = serializeTarget( - parseAndNormalizeTarget( - project.architect.serve.configurations.production.browserTarget - ) - ); - project.architect[ - 'extract-i18n' - ].options.browserTarget = serializeTarget( - parseAndNormalizeTarget( - project.architect['extract-i18n'].options.browserTarget - ) - ); - projects[pathToName(key)] = project; - break; - - case 'library': - project.prefix = prefix; - - project.projectType = 'library'; - project.architect.test.options.karmaConfig = `${project.root}/karma.conf.js`; - project.architect.test.options.tsConfig = `${project.root}/tsconfig.spec.json`; - project.architect.test.options.main = `${project.sourceRoot}/test.ts`; - - project.architect.lint.options.tsConfig = [ - `${project.root}/tsconfig.lib.json`, - `${project.root}/tsconfig.spec.json` - ]; - delete project.architect.build; - delete project.architect.serve; - delete project.architect['extract-i18n']; - projects[pathToName(key)] = project; - break; - - case 'e2e': - const appProjectKey = parseTarget( - project.architect.e2e.options.devServerTarget - ).project; - const appProject = json.projects[appProjectKey]; - if (appProject.projectType === 'library') { - break; - } - project.root = `${appProject.root}-e2e`; - project.sourceRoot = `${project.root}/src`; - project.prefix = prefix; - - project.architect.e2e.options.protractorConfig = `${project.root}/protractor.conf.js`; - project.architect.lint.options.tsConfig = [ - `${project.root}/tsconfig.e2e.json` - ]; - project.architect.e2e.options.devServerTarget = serializeTarget( - parseAndNormalizeTarget(project.architect.e2e.options.devServerTarget) - ); - projects[pathToName(key)] = project; - break; - } - }); - json.projects = projects; - return json; -}); - -function addInstallTask(host: Tree, context: SchematicContext) { - context.addTask(new NodePackageInstallTask()); -} - -function checkCli6Upgraded(host: Tree) { - if (!host.exists('angular.json') && host.exists('.angular-cli.json')) { - throw new Error( - 'Please install the latest version and run ng update @angular/cli first' - ); - } -} - -function parseAndNormalizeTarget(s: string) { - const r = parseTarget(s); - return { ...r, project: pathToName(r.project) }; -} - -function pathToName(s: string) { - return s.replace(new RegExp('/', 'g'), '-'); -} - -export default function(): Rule { - return chain([ - checkCli6Upgraded, - updatePackageJson, - updateworkspaceJson, - moveE2eTests, - updateTsConfigs, - createAdditionalFiles, - deleteUnneededFiles, - patchLibIndexFiles, - addInstallTask, - formatFiles() - ]); -} diff --git a/packages/schematics/migrations/update-6-0-5/update-6-0-5.ts b/packages/schematics/migrations/update-6-0-5/update-6-0-5.ts deleted file mode 100644 index 93492f553edec..0000000000000 --- a/packages/schematics/migrations/update-6-0-5/update-6-0-5.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { - Rule, - Tree, - SchematicContext, - chain -} from '@angular-devkit/schematics'; -import { updateJsonInTree } from '@nrwl/workspace'; - -export default function(): Rule { - return updateJsonInTree('package.json', packageJson => { - packageJson.scripts['affected:lint'] = - './node_modules/.bin/nx affected:lint'; - return packageJson; - }); -} diff --git a/packages/schematics/migrations/update-6-1-0/update-6-1-0.ts b/packages/schematics/migrations/update-6-1-0/update-6-1-0.ts deleted file mode 100644 index 34047c2f2727e..0000000000000 --- a/packages/schematics/migrations/update-6-1-0/update-6-1-0.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { - Rule, - Tree, - SchematicContext, - chain -} from '@angular-devkit/schematics'; -import { updateJsonInTree } from '@nrwl/workspace'; -import { stripIndents } from '@angular-devkit/core/src/utils/literals'; -import { NxJson } from '@nrwl/workspace'; - -function displayInformation(host: Tree, context: SchematicContext) { - context.logger.info(stripIndents` - "implicitDependencies" have been added to your nx.json. - `); - context.logger.warn(stripIndents` - Files not defined in implicitDependencies will NOT affect your projects. - - .ie yarn affected:apps --files=README.md will return no apps since it is not defined. - - You should add additional files which you expect to affect your projects into this configuration. - `); -} - -const addImplicitDependencies = updateJsonInTree('nx.json', nxJson => { - return { - ...nxJson, - implicitDependencies: { - 'angular.json': '*', - 'package.json': '*', - 'tsconfig.json': '*', - 'tslint.json': '*', - 'nx.json': '*' - } - }; -}); - -const changeNpmRunUpdate = updateJsonInTree('package.json', packageJson => { - packageJson.scripts.update = 'ng update @nrwl/schematics'; - packageJson.scripts['update:check'] = 'ng update'; - delete packageJson.scripts['update:skip']; - return packageJson; -}); - -export default function(): Rule { - return chain([ - displayInformation, - addImplicitDependencies, - changeNpmRunUpdate - ]); -} diff --git a/packages/schematics/migrations/update-6-2-0/files/karma.conf.js b/packages/schematics/migrations/update-6-2-0/files/karma.conf.js deleted file mode 100644 index 18f3c3fd06536..0000000000000 --- a/packages/schematics/migrations/update-6-2-0/files/karma.conf.js +++ /dev/null @@ -1,34 +0,0 @@ -// Karma configuration file, see link for more information -// https://karma-runner.github.io/1.0/config/configuration-file.html - -const { join } = require('path'); -const { constants } = require('karma'); - -module.exports = () => { - return { - basePath: '', - frameworks: ['jasmine', '@angular-devkit/build-angular'], - plugins: [ - require('karma-jasmine'), - require('karma-chrome-launcher'), - require('karma-jasmine-html-reporter'), - require('karma-coverage-istanbul-reporter'), - require('@angular-devkit/build-angular/plugins/karma') - ], - client: { - clearContext: false // leave Jasmine Spec Runner output visible in browser - }, - coverageIstanbulReporter: { - dir: join(__dirname, '../../coverage'), - reports: ['html', 'lcovonly'], - fixWebpackSourcePaths: true - }, - reporters: ['progress', 'kjhtml'], - port: 9876, - colors: true, - logLevel: constants.LOG_INFO, - autoWatch: false, - browsers: ['Chrome'], - singleRun: true - }; -}; diff --git a/packages/schematics/migrations/update-6-2-0/update-6-2-0.spec.ts b/packages/schematics/migrations/update-6-2-0/update-6-2-0.spec.ts deleted file mode 100644 index 1b9551488af9b..0000000000000 --- a/packages/schematics/migrations/update-6-2-0/update-6-2-0.spec.ts +++ /dev/null @@ -1,133 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; -import { serializeJson } from '@nrwl/workspace'; - -import * as path from 'path'; - -describe('Update 6.2.0', () => { - let initialTree: Tree; - let schematicRunner: SchematicTestRunner; - - beforeEach(() => { - initialTree = Tree.empty(); - initialTree.create( - 'package.json', - serializeJson({ - dependencies: { - '@angular/animations': '6.0.1', - '@angular/common': '6.0.1', - '@angular/compiler': '6.0.1', - '@angular/core': '6.0.1', - '@angular/forms': '6.0.1', - '@angular/platform-browser': '6.0.1', - '@angular/platform-browser-dynamic': '6.0.1', - '@angular/router': '6.0.1', - 'core-js': '^2.5.4', - rxjs: '6.0.0', - 'zone.js': '^0.8.26', - '@nrwl/nx': '6.1.0', - '@ngrx/effects': '5.2.0', - '@ngrx/router-store': '5.2.0', - '@ngrx/store': '5.2.0', - '@ngrx/store-devtools': '5.2.0', - 'ngrx-store-freeze': '0.2.2' - }, - devDependencies: { - '@angular/cli': '6.0.1', - '@angular/compiler-cli': '6.0.1', - '@angular/language-service': '6.0.1', - '@angular-devkit/build-angular': '~0.6.1', - '@ngrx/schematics': '5.2.0', - '@nrwl/schematics': '6.1.0', - 'jasmine-marbles': '0.3.1', - '@types/jasmine': '~2.8.6', - '@types/jasminewd2': '~2.0.3', - '@types/node': '~8.9.4', - codelyzer: '~4.2.1', - 'jasmine-core': '~2.99.1', - 'jasmine-spec-reporter': '~4.2.1', - karma: '~2.0.0', - 'karma-chrome-launcher': '~2.2.0', - 'karma-coverage-istanbul-reporter': '~1.4.2', - 'karma-jasmine': '~1.1.0', - 'karma-jasmine-html-reporter': '^0.2.2', - protractor: '~5.3.0', - 'ts-node': '~5.0.1', - tslint: '~5.9.1', - typescript: '2.7.2', - prettier: '1.10.2' - } - }) - ); - schematicRunner = new SchematicTestRunner( - '@nrwl/schematics', - path.join(__dirname, '../migrations.json') - ); - }); - - it('should create a karma.conf.js', () => { - const result = schematicRunner.runSchematic( - 'update-6.2.0', - {}, - initialTree - ); - expect(result.files).toContain('/karma.conf.js'); - }); - - it('should update dependencies', () => { - const result = schematicRunner.runSchematic( - 'update-6.2.0', - {}, - initialTree - ); - - expect(JSON.parse(result.readContent('package.json'))).toEqual({ - scripts: { - 'affected:libs': './node_modules/.bin/nx affected:libs' - }, - dependencies: { - '@angular/animations': '^6.1.0', - '@angular/common': '^6.1.0', - '@angular/compiler': '^6.1.0', - '@angular/core': '^6.1.0', - '@angular/forms': '^6.1.0', - '@angular/platform-browser': '^6.1.0', - '@angular/platform-browser-dynamic': '^6.1.0', - '@angular/router': '^6.1.0', - 'core-js': '^2.5.4', - rxjs: '6.2.2', - 'zone.js': '^0.8.26', - '@nrwl/nx': '6.1.0', - '@ngrx/effects': '6.0.1', - '@ngrx/store': '6.0.1', - '@ngrx/router-store': '6.0.1' - }, - devDependencies: { - '@angular/cli': '6.1.2', - '@angular/compiler-cli': '^6.1.0', - '@angular/language-service': '^6.1.0', - '@angular-devkit/build-angular': '~0.7.0', - '@ngrx/store-devtools': '6.0.1', - '@nrwl/schematics': '6.1.0', - 'jasmine-marbles': '0.3.1', - '@types/jasmine': '~2.8.6', - '@types/jasminewd2': '~2.0.3', - '@types/node': '~8.9.4', - codelyzer: '~4.2.1', - 'jasmine-core': '~2.99.1', - 'jasmine-spec-reporter': '~4.2.1', - karma: '~2.0.0', - 'karma-chrome-launcher': '~2.2.0', - 'karma-coverage-istanbul-reporter': '~1.4.2', - 'karma-jasmine': '~1.1.0', - 'karma-jasmine-html-reporter': '^0.2.2', - 'ngrx-store-freeze': '0.2.4', - protractor: '~5.3.0', - 'ts-node': '~5.0.1', - tslint: '~5.9.1', - typescript: '~2.7.2', - prettier: '1.10.2' - } - }); - }); -}); diff --git a/packages/schematics/migrations/update-6-2-0/update-6-2-0.ts b/packages/schematics/migrations/update-6-2-0/update-6-2-0.ts deleted file mode 100644 index 5bfb8ecc138c1..0000000000000 --- a/packages/schematics/migrations/update-6-2-0/update-6-2-0.ts +++ /dev/null @@ -1,122 +0,0 @@ -import { - Rule, - SchematicContext, - chain, - template, - apply, - mergeWith, - url -} from '@angular-devkit/schematics'; -import { stripIndents } from '@angular-devkit/core/src/utils/literals'; -import { updateJsonInTree } from '@nrwl/workspace'; -import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks'; - -function displayInformation(_, context: SchematicContext) { - context.logger.info(stripIndents` - A global base karma config has been added at karma.conf.js - - This file exports a karma config to be extended in each project - - This new file is not being used yet! - - Generate a new project to see an example of how it might be used. - `); -} - -function setDependencyVersionIfExisting( - packageNames: string[], - version: string, - areDev: boolean -) { - return updateJsonInTree('package.json', json => { - const dependencies = areDev ? json.devDependencies : json.dependencies; - packageNames - .filter(packageName => !!dependencies[packageName]) - .forEach(packageName => { - dependencies[packageName] = version; - }); - return json; - }); -} - -function updateDependencies() { - return chain([ - updateJsonInTree('package.json', json => { - json.scripts = json.scripts || {}; - json.dependencies = json.dependencies || {}; - json.devDependencies = json.devDependencies || {}; - - json.scripts['affected:libs'] = './node_modules/.bin/nx affected:libs'; - if (json.dependencies['@ngrx/store-devtools']) { - json.devDependencies['@ngrx/store-devtools'] = - json.dependencies['@ngrx/store-devtools']; - delete json.dependencies['@ngrx/store-devtools']; - } - if (json.dependencies['ngrx-store-freeze']) { - json.devDependencies['ngrx-store-freeze'] = - json.dependencies['ngrx-store-freeze']; - delete json.dependencies['ngrx-store-freeze']; - } - delete json.devDependencies['@ngrx/schematics']; - return json; - }), - setDependencyVersionIfExisting( - [ - '@angular/animations', - '@angular/common', - '@angular/compiler', - '@angular/core', - '@angular/forms', - '@angular/http', - '@angular/platform-browser', - '@angular/platform-browser-dynamic', - '@angular/platform-server', - '@angular/platform-webworker', - '@angular/platform-webworker-dynamic', - '@angular/router', - '@angular/service-worker', - '@angular/upgrade' - ], - '^6.1.0', - false - ), - setDependencyVersionIfExisting(['rxjs'], '6.2.2', false), - setDependencyVersionIfExisting( - ['@ngrx/effects', '@ngrx/store', '@ngrx/router-store'], - '6.0.1', - false - ), - setDependencyVersionIfExisting(['@angular/cli'], '6.1.2', true), - setDependencyVersionIfExisting( - ['@angular/compiler-cli', '@angular/language-service'], - '^6.1.0', - true - ), - setDependencyVersionIfExisting( - ['@angular-devkit/build-angular'], - '~0.7.0', - true - ), - setDependencyVersionIfExisting(['ngrx-store-freeze'], '0.2.4', true), - setDependencyVersionIfExisting(['@ngrx/store-devtools'], '6.0.1', true), - setDependencyVersionIfExisting(['typescript'], '~2.7.2', true) - ]); -} - -function addGlobalKarmaConf() { - const templateSource = url('./files'); - return mergeWith(templateSource); -} - -const addInstall = (_, context: SchematicContext) => { - context.addTask(new NodePackageInstallTask()); -}; - -export default function(): Rule { - return chain([ - displayInformation, - updateDependencies(), - addGlobalKarmaConf(), - addInstall - ]); -} diff --git a/packages/schematics/migrations/update-6-3-2/update-6-3-2.spec.ts b/packages/schematics/migrations/update-6-3-2/update-6-3-2.spec.ts deleted file mode 100644 index d8cc87cf8550d..0000000000000 --- a/packages/schematics/migrations/update-6-3-2/update-6-3-2.spec.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; -import { serializeJson } from '@nrwl/workspace'; - -import * as path from 'path'; - -describe('Update 6.2.0', () => { - let initialTree: Tree; - let schematicRunner: SchematicTestRunner; - - beforeEach(() => { - initialTree = Tree.empty(); - initialTree.create( - 'package.json', - serializeJson({ - devDependencies: { - 'jest-preset-angular': '6.0.0' - } - }) - ); - schematicRunner = new SchematicTestRunner( - '@nrwl/schematics', - path.join(__dirname, '../migrations.json') - ); - }); - - it('should update jest-preset-angular', () => { - const result = schematicRunner.runSchematic( - 'update-6.3.2', - {}, - initialTree - ); - expect(JSON.parse(result.readContent('package.json'))).toEqual({ - devDependencies: { - 'jest-preset-angular': '6.0.1' - } - }); - }); - - it('should not update jest-preset-angular if it does not exist', () => { - initialTree.overwrite( - 'package.json', - serializeJson({ - devDependencies: {} - }) - ); - const result = schematicRunner.runSchematic( - 'update-6.3.2', - {}, - initialTree - ); - expect(JSON.parse(result.readContent('package.json'))).toEqual({ - devDependencies: {} - }); - }); -}); diff --git a/packages/schematics/migrations/update-6-3-2/update-6-3-2.ts b/packages/schematics/migrations/update-6-3-2/update-6-3-2.ts deleted file mode 100644 index 457fd02a8d842..0000000000000 --- a/packages/schematics/migrations/update-6-3-2/update-6-3-2.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Rule, Tree, SchematicContext } from '@angular-devkit/schematics'; -import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks'; -import { updateJsonInTree } from '@nrwl/workspace'; - -export default function(): Rule { - return (host: Tree, context: SchematicContext) => { - return updateJsonInTree('package.json', json => { - const devDependencies = json.devDependencies; - - if (!devDependencies) { - return json; - } - - if (devDependencies['jest-preset-angular']) { - devDependencies['jest-preset-angular'] = '6.0.1'; - context.addTask(new NodePackageInstallTask()); - } - - return json; - })(host, context); - }; -} diff --git a/packages/schematics/migrations/update-6-4-0/update-6-4-0.spec.ts b/packages/schematics/migrations/update-6-4-0/update-6-4-0.spec.ts deleted file mode 100644 index afe0590468380..0000000000000 --- a/packages/schematics/migrations/update-6-4-0/update-6-4-0.spec.ts +++ /dev/null @@ -1,122 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; -import { serializeJson } from '@nrwl/workspace'; - -import * as path from 'path'; - -describe('Update 6.4.0', () => { - let initialTree: Tree; - let schematicRunner: SchematicTestRunner; - - beforeEach(() => { - initialTree = Tree.empty(); - initialTree.create( - 'package.json', - serializeJson({ - dependencies: { - '@angular/animations': '^6.1.0', - '@angular/common': '^6.1.0', - '@angular/compiler': '^6.1.0', - '@angular/core': '^6.1.0', - '@angular/forms': '^6.1.0', - '@angular/platform-browser': '^6.1.0', - '@angular/platform-browser-dynamic': '^6.1.0', - '@angular/router': '^6.1.0', - 'core-js': '^2.5.4', - rxjs: '^6.0.0', - 'zone.js': '^0.8.26', - '@nrwl/nx': '6.1.0', - '@ngrx/effects': '6.0.1', - '@ngrx/store': '6.0.1', - '@ngrx/router-store': '6.0.1' - }, - devDependencies: { - '@angular/cli': '6.1.2', - '@angular/compiler-cli': '^6.1.0', - '@angular/language-service': '^6.1.0', - '@angular-devkit/build-angular': '~0.7.0', - '@angular-devkit/build-ng-packagr': '~0.7.0', - '@ngrx/store-devtools': '6.0.1', - '@nrwl/schematics': '6.1.0', - 'jasmine-marbles': '0.3.1', - '@types/jasmine': '~2.8.6', - '@types/jasminewd2': '~2.0.3', - '@types/node': '~8.9.4', - codelyzer: '~4.2.1', - 'jasmine-core': '~2.99.1', - 'jasmine-spec-reporter': '~4.2.1', - karma: '~2.0.0', - 'karma-chrome-launcher': '~2.2.0', - 'karma-coverage-istanbul-reporter': '~1.4.2', - 'karma-jasmine': '~1.1.0', - 'karma-jasmine-html-reporter': '^0.2.2', - 'ngrx-store-freeze': '0.2.4', - protractor: '~5.3.0', - 'ts-node': '~5.0.1', - tslint: '~5.9.1', - typescript: '~2.7.2', - prettier: '1.10.2' - } - }) - ); - schematicRunner = new SchematicTestRunner( - '@nrwl/schematics', - path.join(__dirname, '../migrations.json') - ); - }); - - it('should update dependencies', () => { - const result = schematicRunner.runSchematic( - 'update-6.4.0', - {}, - initialTree - ); - - expect(JSON.parse(result.readContent('package.json'))).toEqual({ - dependencies: { - '@angular/animations': '^6.1.0', - '@angular/common': '^6.1.0', - '@angular/compiler': '^6.1.0', - '@angular/core': '^6.1.0', - '@angular/forms': '^6.1.0', - '@angular/platform-browser': '^6.1.0', - '@angular/platform-browser-dynamic': '^6.1.0', - '@angular/router': '^6.1.0', - 'core-js': '^2.5.4', - rxjs: '^6.0.0', - 'zone.js': '^0.8.26', - '@nrwl/nx': '6.1.0', - '@ngrx/effects': '6.1.0', - '@ngrx/store': '6.1.0', - '@ngrx/router-store': '6.1.0' - }, - devDependencies: { - '@angular/cli': '6.2.4', - '@angular/compiler-cli': '^6.1.0', - '@angular/language-service': '^6.1.0', - '@angular-devkit/build-angular': '~0.8.0', - '@angular-devkit/build-ng-packagr': '~0.8.0', - '@ngrx/store-devtools': '6.1.0', - '@nrwl/schematics': '6.1.0', - 'jasmine-marbles': '0.3.1', - '@types/jasmine': '~2.8.6', - '@types/jasminewd2': '~2.0.3', - '@types/node': '~8.9.4', - codelyzer: '~4.2.1', - 'jasmine-core': '~2.99.1', - 'jasmine-spec-reporter': '~4.2.1', - karma: '~3.0.0', - 'karma-chrome-launcher': '~2.2.0', - 'karma-coverage-istanbul-reporter': '~2.0.1', - 'karma-jasmine': '~1.1.0', - 'karma-jasmine-html-reporter': '^0.2.2', - 'ngrx-store-freeze': '0.2.4', - protractor: '~5.4.0', - 'ts-node': '~7.0.0', - tslint: '~5.11.0', - typescript: '~2.9.2', - prettier: '1.10.2' - } - }); - }); -}); diff --git a/packages/schematics/migrations/update-6-4-0/update-6-4-0.ts b/packages/schematics/migrations/update-6-4-0/update-6-4-0.ts deleted file mode 100644 index d4529b5646272..0000000000000 --- a/packages/schematics/migrations/update-6-4-0/update-6-4-0.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { Rule, SchematicContext, chain } from '@angular-devkit/schematics'; -import { updateJsonInTree } from '@nrwl/workspace'; -import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks'; - -function updateDependencies() { - return updateJsonInTree('package.json', json => { - json.dependencies = json.dependencies || {}; - json.dependencies = { - ...json.dependencies, - '@ngrx/effects': '6.1.0', - '@ngrx/store': '6.1.0', - '@ngrx/router-store': '6.1.0' - }; - json.devDependencies = json.devDependencies || {}; - json.devDependencies = { - ...json.devDependencies, - '@angular/cli': '6.2.4', - '@angular-devkit/build-angular': '~0.8.0', - '@ngrx/store-devtools': '6.1.0', - karma: '~3.0.0', - 'karma-coverage-istanbul-reporter': '~2.0.1', - protractor: '~5.4.0', - 'ts-node': '~7.0.0', - tslint: '~5.11.0', - typescript: '~2.9.2' - }; - - if (json.devDependencies['@angular-devkit/build-ng-packagr']) { - json.devDependencies['@angular-devkit/build-ng-packagr'] = '~0.8.0'; - } - - return json; - }); -} - -const addInstall = (_, context: SchematicContext) => { - context.addTask(new NodePackageInstallTask()); -}; - -export default function(): Rule { - return chain([updateDependencies(), addInstall]); -} diff --git a/packages/schematics/migrations/update-7-0-0/update-7-0-0.spec.ts b/packages/schematics/migrations/update-7-0-0/update-7-0-0.spec.ts deleted file mode 100644 index 962f3ef081a7b..0000000000000 --- a/packages/schematics/migrations/update-7-0-0/update-7-0-0.spec.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; -import { serializeJson } from '@nrwl/workspace'; - -import * as path from 'path'; -import { updateJsonInTree } from '@nrwl/workspace'; - -describe('Update 7.0.0', () => { - let initialTree: Tree; - let schematicRunner: SchematicTestRunner; - - beforeEach(() => { - initialTree = Tree.empty(); - initialTree.create( - 'package.json', - serializeJson({ - devDependencies: { - codelyzer: '~4.2.1' - } - }) - ); - schematicRunner = new SchematicTestRunner( - '@nrwl/schematics', - path.join(__dirname, '../migrations.json') - ); - }); - - it('should update codeylzer', async () => { - const result = await schematicRunner - .runSchematicAsync('update-7.0.0', {}, initialTree) - .toPromise(); - - const devDependencies = JSON.parse(result.readContent('package.json')) - .devDependencies; - - expect(devDependencies.codelyzer).toEqual('~4.5.0'); - expect(devDependencies['jasmine-marbles']).toEqual('0.4.0'); - }); - - it('should update ng-packagr dependencies', async () => { - initialTree = await schematicRunner - .callRule( - updateJsonInTree('package.json', json => { - json.devDependencies = { - ...json.devDependencies, - 'ng-packagr': '^3.0.0' - }; - - return json; - }), - initialTree - ) - .toPromise(); - const result = await schematicRunner - .runSchematicAsync('update-7.0.0', {}, initialTree) - .toPromise(); - - const devDependencies = JSON.parse(result.readContent('package.json')) - .devDependencies; - - expect(devDependencies['ng-packagr']).toEqual('^4.2.0'); - }); -}); diff --git a/packages/schematics/migrations/update-7-0-0/update-7-0-0.ts b/packages/schematics/migrations/update-7-0-0/update-7-0-0.ts deleted file mode 100644 index 2ae1617930618..0000000000000 --- a/packages/schematics/migrations/update-7-0-0/update-7-0-0.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { Rule, chain } from '@angular-devkit/schematics'; -import { updateJsonInTree, addUpdateTask } from '@nrwl/workspace'; - -export default function(): Rule { - return chain([ - updateJsonInTree('package.json', json => { - json.devDependencies = json.devDependencies || {}; - json.devDependencies = { - ...json.devDependencies, - codelyzer: '~4.5.0', - 'jasmine-marbles': '0.4.0' - }; - - if (json.devDependencies['ng-packagr']) { - json.devDependencies['ng-packagr'] = '^4.2.0'; - } - - return json; - }), - addUpdateTask('@angular/core', '7.0.0'), - addUpdateTask('@angular/cli', '7.0.1') - ]); -} diff --git a/packages/schematics/migrations/update-7-0-2/test-files/karma.conf.js b/packages/schematics/migrations/update-7-0-2/test-files/karma.conf.js deleted file mode 100644 index 18f3c3fd06536..0000000000000 --- a/packages/schematics/migrations/update-7-0-2/test-files/karma.conf.js +++ /dev/null @@ -1,34 +0,0 @@ -// Karma configuration file, see link for more information -// https://karma-runner.github.io/1.0/config/configuration-file.html - -const { join } = require('path'); -const { constants } = require('karma'); - -module.exports = () => { - return { - basePath: '', - frameworks: ['jasmine', '@angular-devkit/build-angular'], - plugins: [ - require('karma-jasmine'), - require('karma-chrome-launcher'), - require('karma-jasmine-html-reporter'), - require('karma-coverage-istanbul-reporter'), - require('@angular-devkit/build-angular/plugins/karma') - ], - client: { - clearContext: false // leave Jasmine Spec Runner output visible in browser - }, - coverageIstanbulReporter: { - dir: join(__dirname, '../../coverage'), - reports: ['html', 'lcovonly'], - fixWebpackSourcePaths: true - }, - reporters: ['progress', 'kjhtml'], - port: 9876, - colors: true, - logLevel: constants.LOG_INFO, - autoWatch: false, - browsers: ['Chrome'], - singleRun: true - }; -}; diff --git a/packages/schematics/migrations/update-7-0-2/update-7-0-2.spec.ts b/packages/schematics/migrations/update-7-0-2/update-7-0-2.spec.ts deleted file mode 100644 index f018d996c4766..0000000000000 --- a/packages/schematics/migrations/update-7-0-2/update-7-0-2.spec.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { Tree, mergeWith, url } from '@angular-devkit/schematics'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; - -import * as path from 'path'; -import { readFileSync } from 'fs'; - -describe('Update 7.0.2', () => { - let initialTree: Tree; - let schematicRunner: SchematicTestRunner; - - beforeEach(async () => { - initialTree = Tree.empty(); - schematicRunner = new SchematicTestRunner( - '@nrwl/schematics', - path.join(__dirname, '../migrations.json') - ); - }); - - it('should changeAutoWatch to true in the shared karma.conf.js', async () => { - initialTree.create( - 'karma.conf.js', - readFileSync( - path.join(__dirname, './test-files/karma.conf.js') - ).toString() - ); - - const result = await schematicRunner - .runSchematicAsync('update-7.0.2', {}, initialTree) - .toPromise(); - - expect(result.readContent('karma.conf.js')).toContain('autoWatch: true'); - }); -}); diff --git a/packages/schematics/migrations/update-7-0-2/update-7-0-2.ts b/packages/schematics/migrations/update-7-0-2/update-7-0-2.ts deleted file mode 100644 index f0710c723b54d..0000000000000 --- a/packages/schematics/migrations/update-7-0-2/update-7-0-2.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics'; - -function fixKarmaConf(host: Tree, context: SchematicContext) { - if (!host.exists('karma.conf.js')) { - context.logger.warn(`Could not find ./karma.conf.js`); - context.logger.warn( - 'It is recommended that your karma configuration sets autoWatch: true' - ); - return host; - } - - const originalContent = host.read('karma.conf.js').toString(); - const content = originalContent.replace( - 'autoWatch: false', - 'autoWatch: true' - ); - if (content.includes('autoWatch: true')) { - host.overwrite('karma.conf.js', content); - } else { - context.logger.warn('Could not alter ./karma.conf.js'); - context.logger.warn( - 'It is recommended that your karma configuration sets autoWatch: true' - ); - } - - return host; -} - -export default function(): Rule { - return fixKarmaConf; -} diff --git a/packages/schematics/migrations/update-7-1-0/update-7-1-0.spec.ts b/packages/schematics/migrations/update-7-1-0/update-7-1-0.spec.ts deleted file mode 100644 index 8b7e4d0858576..0000000000000 --- a/packages/schematics/migrations/update-7-1-0/update-7-1-0.spec.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; -import { serializeJson } from '@nrwl/workspace'; - -import * as path from 'path'; - -describe('Update 7.1.0', () => { - let initialTree: Tree; - let schematicRunner: SchematicTestRunner; - - beforeEach(() => { - initialTree = Tree.empty(); - initialTree.create( - 'package.json', - serializeJson({ - scripts: {} - }) - ); - schematicRunner = new SchematicTestRunner( - '@nrwl/schematics', - path.join(__dirname, '../migrations.json') - ); - }); - - it('should add generic affected script', async () => { - const result = await schematicRunner - .runSchematicAsync('update-7.1.0', {}, initialTree) - .toPromise(); - - const { scripts } = JSON.parse(result.readContent('package.json')); - - expect(scripts.affected).toEqual('./node_modules/.bin/nx affected'); - }); - - it('should update prettier', async () => { - const result = await schematicRunner - .runSchematicAsync('update-7.1.0', {}, initialTree) - .toPromise(); - - const { devDependencies } = JSON.parse(result.readContent('package.json')); - - expect(devDependencies.prettier).toEqual('1.15.2'); - }); - - describe('.prettierignore', () => { - it('should not be touched if one exists', async () => { - initialTree.create('.prettierignore', '**/*.json'); - const result = await schematicRunner - .runSchematicAsync('update-7.1.0', {}, initialTree) - .toPromise(); - - expect(result.readContent('.prettierignore')).toEqual('**/*.json'); - }); - - it('should be created if one does not exist', async () => { - const result = await schematicRunner - .runSchematicAsync('update-7.1.0', {}, initialTree) - .toPromise(); - - expect(result.exists('.prettierignore')).toEqual(true); - }); - }); -}); diff --git a/packages/schematics/migrations/update-7-1-0/update-7-1-0.ts b/packages/schematics/migrations/update-7-1-0/update-7-1-0.ts deleted file mode 100644 index 986731ccb0ec2..0000000000000 --- a/packages/schematics/migrations/update-7-1-0/update-7-1-0.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { - Rule, - chain, - SchematicContext, - Tree -} from '@angular-devkit/schematics'; -import { updateJsonInTree } from '@nrwl/workspace'; -import { stripIndents } from '@angular-devkit/core/src/utils/literals'; - -function displayInformation(host: Tree, context: SchematicContext) { - context.logger.info( - stripIndents`Prettier has been updated to 1.15.1 which has support for formatting html! - Formatting of your code might change as you are working on each file. - - Optional: You may want to run "npm run format" as part of this update to reformat all files in your workspace. - - You can also opt out of formatting in files by adding them to the .prettierignore file in the root of your workspace.` - ); -} - -function createPrettierIgnore(host: Tree, context: SchematicContext) { - if (!host.exists('.prettierignore')) { - host.create( - '.prettierignore', - '# Add files here to ignore them from prettier formatting\n' - ); - } -} - -export default function(): Rule { - return chain([ - updateJsonInTree('package.json', json => { - json.scripts = json.scripts || {}; - json.devDependencies = json.devDependencies || {}; - - json.scripts = { - ...json.scripts, - affected: './node_modules/.bin/nx affected' - }; - json.devDependencies = { - ...json.devDependencies, - prettier: '1.15.2' - }; - - return json; - }), - createPrettierIgnore, - displayInformation - ]); -} diff --git a/packages/schematics/migrations/update-7-2-0/update-7-2-0.spec.ts b/packages/schematics/migrations/update-7-2-0/update-7-2-0.spec.ts deleted file mode 100644 index 00a22ab5fb91c..0000000000000 --- a/packages/schematics/migrations/update-7-2-0/update-7-2-0.spec.ts +++ /dev/null @@ -1,481 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; -import { serializeJson } from '@nrwl/workspace'; - -import * as path from 'path'; -import { readJsonInTree, updateJsonInTree } from '@nrwl/workspace'; - -describe('Update 7.2.0', () => { - let initialTree: Tree; - let schematicRunner: SchematicTestRunner; - - beforeEach(() => { - initialTree = Tree.empty(); - createJson('package.json', { - scripts: {} - }); - createJson('tsconfig.json', {}); - createJson('angular.json', { - projects: { - app1: { - root: 'apps/app1', - architect: { - build: { - builder: '@angular-devkit/build-angular:browser', - options: { - tsConfig: 'apps/app1/tsconfig.app.json' - } - }, - test: { - builder: '@angular-devkit/build-angular:karma', - options: { - tsConfig: 'apps/app1/tsconfig.spec.json' - } - }, - lint: { - builder: '@angular-devkit/build-angular:tslint', - options: { - tsConfig: [ - 'apps/app1/tsconfig.app.json', - 'apps/app1/tsconfig.spec.json' - ] - } - } - } - }, - 'app1-e2e': { - root: 'apps/app1-e2e', - architect: { - e2e: { - builder: '@angular-devkit/build-angular:protractor', - options: { - tsConfig: 'apps/app1-e2e/tsconfig.e2e.json' - } - }, - lint: { - builder: '@angular-devkit/build-angular:tslint', - options: { - tsConfig: 'apps/app1-e2e/tsconfig.e2e.json' - } - } - } - }, - app2: { - root: 'apps/app2', - architect: { - build: { - builder: '@angular-devkit/build-angular:browser', - options: { - tsConfig: 'apps/app2/tsconfig.app.json' - } - }, - test: { - builder: '@nrwl/schematics:jest', - options: { - tsConfig: 'apps/app2/tsconfig.spec.json' - } - }, - lint: { - builder: '@angular-devkit/build-angular:tslint', - options: { - tsConfig: [ - 'apps/app2/tsconfig.app.json', - 'apps/app2/tsconfig.spec.json' - ] - } - } - } - }, - 'app2-e2e': { - root: 'apps/app2-e2e', - architect: { - e2e: { - builder: '@nrwl/builders:cypress', - options: { - tsConfig: 'apps/app2-e2e/tsconfig.e2e.json' - } - }, - lint: { - builder: '@angular-devkit/build-angular:tslint', - options: { - tsConfig: 'apps/app2-e2e/tsconfig.e2e.json' - } - } - } - }, - 'node-app': { - root: 'apps/node-app', - architect: { - build: { - builder: '@nrwl/builders:node-build', - options: { - tsConfig: 'apps/node-app/tsconfig.app.json' - } - }, - test: { - builder: '@nrwl/schematics:jest', - options: { - tsConfig: 'apps/node-app/tsconfig.spec.json' - } - }, - lint: { - builder: '@angular-devkit/build-angular:tslint', - options: { - tsConfig: [ - 'apps/node-app/tsconfig.app.json', - 'apps/node-app/tsconfig.spec.json' - ] - } - } - } - }, - 'weird-app': { - root: 'apps/weird/app', - architect: { - build: { - builder: '@nrwl/builders:node-build', - options: { - tsConfig: 'apps/weird/app/src/tsconfig.app.json' - } - }, - test: { - builder: '@nrwl/schematics:jest', - options: { - tsConfig: 'apps/weird/app/src/tsconfig.spec.json' - } - }, - lint: { - builder: '@angular-devkit/build-angular:tslint', - options: { - tsConfig: [ - 'apps/weird/app/src/tsconfig.app.json', - 'apps/weird/app/src/tsconfig.spec.json' - ] - } - } - } - }, - lib1: { - root: 'libs/lib1', - architect: { - test: { - builder: '@angular-devkit/build-angular:karma', - options: { - tsConfig: 'libs/lib1/tsconfig.spec.json' - } - }, - lint: { - builder: '@angular-devkit/build-angular:tslint', - options: { - tsConfig: [ - 'libs/lib1/tsconfig.lib.json', - 'libs/lib1/tsconfig.spec.json' - ] - } - } - } - }, - lib2: { - root: 'libs/lib2', - architect: { - test: { - builder: '@angular-devkit/build-angular:jest', - options: { - tsConfig: 'libs/lib2/tsconfig.spec.json' - } - }, - lint: { - builder: '@angular-devkit/build-angular:tslint', - options: { - tsConfig: [ - 'libs/lib2/tsconfig.lib.json', - 'libs/lib2/tsconfig.spec.json' - ] - } - } - } - } - } - }); - createJson('apps/app1/tsconfig.app.json', { - extends: '../../tsconfig.json', - compilerOptions: { - types: ['jquery'] - } - }); - createJson('apps/app1/tsconfig.spec.json', { - extends: '../../tsconfig.json', - compilerOptions: { - types: ['jasmine', 'node', 'sinon'] - } - }); - createJson('apps/app1-e2e/tsconfig.e2e.json', { - extends: '../../tsconfig.json', - compilerOptions: { - types: ['jasmine', 'jasminewd2', 'node'] - } - }); - createJson('apps/app2/tsconfig.app.json', { - extends: '../../tsconfig.json', - compilerOptions: { - types: [] - } - }); - createJson('apps/app2/tsconfig.spec.json', { - extends: '../../tsconfig.json', - compilerOptions: { - types: ['jest', 'node'] - } - }); - createJson('apps/app2-e2e/tsconfig.e2e.json', { - extends: '../../tsconfig.json', - compilerOptions: { - types: ['cypress', 'node'] - } - }); - createJson('apps/node-app/tsconfig.app.json', { - extends: '../../tsconfig.json', - compilerOptions: { - types: ['node'] - } - }); - createJson('apps/node-app/tsconfig.spec.json', { - extends: '../../tsconfig.json', - compilerOptions: { - types: ['jest', 'node'] - } - }); - createJson('apps/weird/app/src/tsconfig.app.json', { - extends: '../../../tsconfig.json', - compilerOptions: {} - }); - createJson('apps/weird/app/src/tsconfig.spec.json', { - extends: '../../../tsconfig.json', - compilerOptions: {} - }); - createJson('libs/lib1/tsconfig.lib.json', { - extends: '../../tsconfig.json', - compilerOptions: { - types: [] - } - }); - createJson('libs/lib1/tsconfig.spec.json', { - extends: '../../tsconfig.json', - compilerOptions: { - types: ['jasmine', 'node'] - } - }); - createJson('libs/lib2/tsconfig.lib.json', { - extends: '../../tsconfig.json', - compilerOptions: { - types: [] - } - }); - createJson('libs/lib2/tsconfig.spec.json', { - extends: '../../tsconfig.json', - compilerOptions: { - types: ['jest', 'node'] - } - }); - - function createJson(path: string, value: any) { - initialTree.create(path, serializeJson(value)); - } - - schematicRunner = new SchematicTestRunner( - '@nrwl/schematics', - path.join(__dirname, '../migrations.json') - ); - }); - - it('should create tsconfigs for existing projects', async () => { - const result = await schematicRunner - .runSchematicAsync('update-7.2.0', {}, initialTree) - .toPromise(); - expect(result.files).toContain('/tsconfig.json'); - expect(result.files).toContain('/apps/app1/tsconfig.json'); - expect(result.files).toContain('/apps/app1-e2e/tsconfig.json'); - expect(result.files).toContain('/apps/app2/tsconfig.json'); - expect(result.files).toContain('/apps/app2-e2e/tsconfig.json'); - expect(result.files).toContain('/apps/node-app/tsconfig.json'); - expect(result.files).toContain('/apps/weird/app/tsconfig.json'); - expect(result.files).toContain('/libs/lib1/tsconfig.json'); - expect(result.files).toContain('/libs/lib2/tsconfig.json'); - [ - '/apps/app1/tsconfig.json', - '/apps/app1-e2e/tsconfig.json', - '/apps/app2/tsconfig.json', - '/apps/app2-e2e/tsconfig.json', - '/apps/node-app/tsconfig.json', - '/libs/lib1/tsconfig.json', - '/libs/lib2/tsconfig.json' - ].forEach(tsConfig => { - const value = readJsonInTree(result, tsConfig); - expect(value.extends).toEqual('../../tsconfig.json'); - }); - expect( - readJsonInTree(result, 'apps/weird/app/tsconfig.json').extends - ).toEqual('../../../tsconfig.json'); - }); - - it('should fix cypress lint configs', async () => { - initialTree = await schematicRunner - .callRule( - updateJsonInTree('angular.json', json => { - json.projects['app2-e2e'].architect.lint.options.tsConfig = - 'e2e/tsconfig.e2e.json'; - return json; - }), - initialTree - ) - .toPromise(); - const result = await schematicRunner - .runSchematicAsync('update-7.2.0', {}, initialTree) - .toPromise(); - expect( - readJsonInTree(result, 'angular.json').projects['app2-e2e'].architect.lint - .options.tsConfig - ).toEqual('apps/app2-e2e/tsconfig.e2e.json'); - [ - '/apps/app1/tsconfig.app.json', - '/apps/app1/tsconfig.spec.json', - '/apps/app1-e2e/tsconfig.e2e.json', - '/apps/app2/tsconfig.app.json', - '/apps/app2/tsconfig.spec.json', - '/apps/app2-e2e/tsconfig.e2e.json', - '/apps/node-app/tsconfig.app.json', - '/apps/node-app/tsconfig.spec.json', - '/libs/lib1/tsconfig.lib.json', - '/libs/lib1/tsconfig.spec.json', - '/libs/lib2/tsconfig.lib.json', - '/libs/lib2/tsconfig.spec.json' - ].forEach(tsConfig => { - const value = readJsonInTree(result, tsConfig); - expect(value.extends).toEqual('./tsconfig.json'); - }); - }); - - it('should not fail for non-existing tsconfigs', async () => { - initialTree = await schematicRunner - .callRule( - updateJsonInTree('angular.json', json => { - json.projects['app2'].architect.lint.options.tsConfig = - 'apps/nonexistent/tsconfig.app.json'; - return json; - }), - initialTree - ) - .toPromise(); - await schematicRunner - .runSchematicAsync('update-7.2.0', {}, initialTree) - .toPromise(); - }); - - it('should edit existing tsconfigs to extend the new one', async () => { - const result = await schematicRunner - .runSchematicAsync('update-7.2.0', {}, initialTree) - .toPromise(); - [ - '/apps/app1/tsconfig.app.json', - '/apps/app1/tsconfig.spec.json', - '/apps/app1-e2e/tsconfig.e2e.json', - '/apps/app2/tsconfig.app.json', - '/apps/app2/tsconfig.spec.json', - '/apps/app2-e2e/tsconfig.e2e.json', - '/apps/node-app/tsconfig.app.json', - '/apps/node-app/tsconfig.spec.json', - '/libs/lib1/tsconfig.lib.json', - '/libs/lib1/tsconfig.spec.json', - '/libs/lib2/tsconfig.lib.json', - '/libs/lib2/tsconfig.spec.json' - ].forEach(tsConfig => { - const value = readJsonInTree(result, tsConfig); - expect(value.extends).toEqual('./tsconfig.json'); - }); - expect( - readJsonInTree(result, 'apps/weird/app/src/tsconfig.app.json').extends - ).toEqual('../tsconfig.json'); - expect( - readJsonInTree(result, 'apps/weird/app/src/tsconfig.spec.json').extends - ).toEqual('../tsconfig.json'); - }); - - it('should edit existing tsconfigs to have a union of all types being used', async () => { - const result = await schematicRunner - .runSchematicAsync('update-7.2.0', {}, initialTree) - .toPromise(); - - function getTypes(path: string) { - return readJsonInTree(result, path).compilerOptions.types; - } - - expect(getTypes('apps/app1/tsconfig.json')).toEqual([ - 'jquery', - 'jasmine', - 'node', - 'sinon' - ]); - expect(getTypes('apps/app1-e2e/tsconfig.json')).toEqual([ - 'jasmine', - 'jasminewd2', - 'node' - ]); - expect(getTypes('apps/app2/tsconfig.json')).toEqual(['jest', 'node']); - expect(getTypes('apps/app2-e2e/tsconfig.json')).toEqual([ - 'cypress', - 'node' - ]); - expect(getTypes('apps/node-app/tsconfig.json')).toEqual(['node', 'jest']); - expect(getTypes('apps/weird/app/tsconfig.json')).toBeUndefined(); - expect(getTypes('libs/lib1/tsconfig.json')).toEqual(['jasmine', 'node']); - expect(getTypes('libs/lib2/tsconfig.json')).toEqual(['jest', 'node']); - }); - - it("should not set types if one of the project's tsconfigs do not have types defined", async () => { - initialTree = await schematicRunner - .callRule( - updateJsonInTree('apps/app1/tsconfig.app.json', json => { - delete json.compilerOptions.types; - return json; - }), - initialTree - ) - .toPromise(); - const result = await schematicRunner - .runSchematicAsync('update-7.2.0', {}, initialTree) - .toPromise(); - - function getTypes(path: string) { - return readJsonInTree(result, path).compilerOptions.types; - } - - expect(getTypes('apps/app1/tsconfig.json')).toBeUndefined(); - }); - - describe('tsconfig.json', () => { - it('should be updated with es2015 modules', async () => { - const result = await schematicRunner - .runSchematicAsync('update-7.2.0', {}, initialTree) - .toPromise(); - - const tsConfig = readJsonInTree(result, 'tsconfig.json'); - expect(tsConfig.compilerOptions.module).toEqual('es2015'); - }); - }); - - it('should update @ngrx dependencies to 6.1.2', async () => { - const result = await schematicRunner - .runSchematicAsync('update-7.2.0', {}, initialTree) - .toPromise(); - - const { dependencies, devDependencies } = JSON.parse( - result.readContent('package.json') - ); - - expect(dependencies['@ngrx/effects']).toEqual('6.1.2'); - expect(dependencies['@ngrx/router-store']).toEqual('6.1.2'); - expect(dependencies['@ngrx/store']).toEqual('6.1.2'); - expect(devDependencies['@ngrx/schematics']).toEqual('6.1.2'); - expect(devDependencies['@ngrx/store-devtools']).toEqual('6.1.2'); - }); -}); diff --git a/packages/schematics/migrations/update-7-2-0/update-7-2-0.ts b/packages/schematics/migrations/update-7-2-0/update-7-2-0.ts deleted file mode 100644 index f9f101a22573a..0000000000000 --- a/packages/schematics/migrations/update-7-2-0/update-7-2-0.ts +++ /dev/null @@ -1,248 +0,0 @@ -import { - Rule, - chain, - noop, - SchematicContext, - Tree, - externalSchematic -} from '@angular-devkit/schematics'; -import { normalize, join, Path, dirname } from '@angular-devkit/core'; - -import { relative } from 'path'; - -import { - updateJsonInTree, - readJsonInTree, - updateWorkspaceInTree -} from '@nrwl/workspace'; -import { getWorkspacePath } from '@nrwl/workspace'; -import { offsetFromRoot, addUpdateTask } from '@nrwl/workspace'; -import { stripIndents } from '@angular-devkit/core/src/utils/literals'; - -function getBuilders(project: any): string[] { - return Array.from( - new Set(Object.values(project.architect).map(target => target.builder)) - ); -} - -const builderTypes: { [key: string]: string[] } = { - '@angular-devkit/build-angular:karma': ['jasmine'], - '@angular-devkit/build-angular:protractor': ['jasmine', 'jasminewd2'], - '@nrwl/builders:jest': ['jest', 'node'], - '@nrwl/builers:cypress': ['cypress'] -}; - -function getTypes(host: Tree, project: any, context: SchematicContext) { - let types = []; - - const tsConfigPaths = getTsConfigs(project, host); - - const tsConfigs = tsConfigPaths.map(tsconfigPath => - readJsonInTree(host, tsconfigPath) - ); - - const tsConfigsWithNoTypes = tsConfigPaths.filter(tsconfigPath => { - const tsconfig = readJsonInTree(host, tsconfigPath); - return !tsconfig.compilerOptions.types; - }); - - if (tsConfigsWithNoTypes.length > 0) { - context.logger.warn( - stripIndents`The following tsconfigs had no types defined: ${tsConfigsWithNoTypes.join( - ',' - )}` - ); - return undefined; - } - - types = types.concat( - ...tsConfigs.map(tsconfig => tsconfig.compilerOptions.types || []) - ); - - types = types.concat( - ...getBuilders(project) - .filter(builder => builder in builderTypes) - .map(builder => builderTypes[builder]) - ); - - return types.filter((type, i, arr) => arr.indexOf(type) === i); // dedupe the array; -} - -function createTsConfig(project: any): Rule { - return (host: Tree, context: SchematicContext) => { - const tsConfigPath = join(normalize(project.root), 'tsconfig.json'); - if (host.exists(tsConfigPath)) { - return noop(); - } - host.create(tsConfigPath, '{}'); - const types = getTypes(host, project, context); - if (types === undefined) { - context.logger.warn( - stripIndents`No types array was added to ${tsConfigPath} meaning the editor might encounter conflicts for types.}` - ); - } - return updateJsonInTree(tsConfigPath, () => { - return { - extends: `${offsetFromRoot(project.root)}tsconfig.json`, - compilerOptions: { - types - } - }; - }); - }; -} - -function getTsConfigs( - project: any, - host: Tree, - context?: SchematicContext -): Path[] { - return Array.from( - new Set( - Object.values(project.architect) - .reduce( - (arr: any[], target) => { - return [ - ...arr, - ...(target.options ? [target.options] : []), - ...Object.values(target.configurations || {}) - ] as any[]; - }, - [] - ) - .reduce((arr: string[], options) => { - if (!options.tsConfig) { - return arr; - } - if (!Array.isArray(options.tsConfig)) { - return arr.includes(options.tsConfig) - ? arr - : [...arr, options.tsConfig]; - } - return [ - ...arr, - ...options.tsConfig.filter(tsconfig => !arr.includes(tsconfig)) - ]; - }, []) - .filter(tsconfig => { - if (!host.exists(tsconfig)) { - if (context) { - context.logger.warn( - `${tsconfig} does not exist but is set as a "tsConfig" in /angular.json` - ); - } - return false; - } - return true; - }) - .map(tsconfig => { - return normalize(tsconfig); - }) - ) - ); -} - -function updateTsConfig(project: any, tsconfig: Path): Rule { - return updateJsonInTree(tsconfig, json => { - json.extends = - dirname(tsconfig) === normalize(project.root) - ? './tsconfig.json' - : relative(dirname(tsconfig), join(project.root, 'tsconfig.json')); - return json; - }); -} - -function updateTsConfigs(project: any): Rule { - return (host: Tree, context: SchematicContext) => { - return chain( - getTsConfigs(project, host, context).map(tsconfig => - updateTsConfig(project, tsconfig) - ) - ); - }; -} - -function fixCypressConfigs(host: Tree, context: SchematicContext): Rule { - const workspaceJson = readJsonInTree(host, 'angular.json'); - return chain( - Object.entries(workspaceJson.projects) - .filter( - ([key, project]) => - project.architect.e2e && - project.architect.e2e.builder === '@nrwl/builders:cypress' && - project.architect.lint && - !host.exists(project.architect.lint.options.tsConfig) && - host.exists(join(project.root, 'tsconfig.e2e.json')) - ) - .map(([key, project]) => fixCypressConfig(project, key)) - ); -} - -function fixCypressConfig(project: any, projectKey: string): Rule { - return updateWorkspaceInTree(workspaceJson => { - workspaceJson.projects[projectKey].architect.lint.options.tsConfig = join( - project.root, - 'tsconfig.e2e.json' - ); - return workspaceJson; - }); -} - -function updateProjects(host: Tree) { - const { projects } = readJsonInTree(host, getWorkspacePath(host)); - return chain( - Object.entries(projects).map(([key, project]) => { - return chain([createTsConfig(project), updateTsConfigs(project)]); - }) - ); -} - -function displayInformation(host: Tree, context: SchematicContext) { - context.logger - .info(stripIndents`With this update, we are changing the structure of the tsconfig files. - A tsconfig.json has been added to all project roots which is used by editors to provide intellisense. - The tsconfig.(app|lib|spec|e2e).json files now all extend off of the tsconfig.json in the project root. - To find out more, visit our wiki: https://github.com/nrwl/nx/wiki/Workspace-Organization#tsconfigs`); -} - -function switchToEs2015(host: Tree, context: SchematicContext) { - return updateJsonInTree('tsconfig.json', json => { - json.compilerOptions = json.compilerOptions || {}; - json.compilerOptions.module = 'es2015'; - - context.logger.info( - 'Typescript has been set to compile with es2015 modules' - ); - return json; - }); -} - -const updateAngularCLI = addUpdateTask('@angular/cli', '7.1.0'); - -export default function(): Rule { - return chain([ - updateJsonInTree('package.json', json => { - json.dependencies = json.dependencies || {}; - json.dependencies = { - ...json.dependencies, - '@ngrx/effects': '6.1.2', - '@ngrx/router-store': '6.1.2', - '@ngrx/store': '6.1.2' - }; - - json.devDependencies = json.devDependencies || {}; - json.devDependencies = { - ...json.devDependencies, - '@ngrx/schematics': '6.1.2', - '@ngrx/store-devtools': '6.1.2' - }; - - return json; - }), - fixCypressConfigs, - switchToEs2015, - updateProjects, - displayInformation, - updateAngularCLI - ]); -} diff --git a/packages/schematics/migrations/update-7-5-0/update-7-5-0.spec.ts b/packages/schematics/migrations/update-7-5-0/update-7-5-0.spec.ts deleted file mode 100644 index c9bf69bf57da7..0000000000000 --- a/packages/schematics/migrations/update-7-5-0/update-7-5-0.spec.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; - -import * as path from 'path'; - -import { serializeJson } from '@nrwl/workspace'; -import { readJsonInTree } from '@nrwl/workspace'; -import { createEmptyWorkspace } from '@nrwl/workspace/testing'; - -describe('Update 7.5.0', () => { - let initialTree: Tree; - let schematicRunner: SchematicTestRunner; - - beforeEach(() => { - initialTree = createEmptyWorkspace(Tree.empty()); - - initialTree.overwrite( - 'package.json', - serializeJson({ - devDependencies: { - typescript: '~3.1.0' - } - }) - ); - - schematicRunner = new SchematicTestRunner( - '@nrwl/schematics', - path.join(__dirname, '../migrations.json') - ); - }); - - it('should update typescript', async () => { - const result = await schematicRunner - .runSchematicAsync('update-7.5.0', {}, initialTree) - .toPromise(); - - expect( - readJsonInTree(result, 'package.json').devDependencies.typescript - ).toEqual('~3.2.2'); - }); -}); diff --git a/packages/schematics/migrations/update-7-5-0/update-7-5-0.ts b/packages/schematics/migrations/update-7-5-0/update-7-5-0.ts deleted file mode 100644 index e30ef20fb58b8..0000000000000 --- a/packages/schematics/migrations/update-7-5-0/update-7-5-0.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Rule, chain, externalSchematic } from '@angular-devkit/schematics'; - -import { updateJsonInTree, addUpdateTask } from '@nrwl/workspace'; - -const updateAngularCLI = addUpdateTask('@angular/cli', '7.2.2'); - -const updateTypescript = updateJsonInTree('package.json', json => { - json.devDependencies = json.devDependencies || {}; - json.devDependencies = { - ...json.devDependencies, - typescript: '~3.2.2' - }; - return json; -}); - -export default function(): Rule { - return chain([updateTypescript, updateAngularCLI]); -} diff --git a/packages/schematics/migrations/update-7-6-0/update-7-6-0.spec.ts b/packages/schematics/migrations/update-7-6-0/update-7-6-0.spec.ts deleted file mode 100644 index 00bd15cbf6818..0000000000000 --- a/packages/schematics/migrations/update-7-6-0/update-7-6-0.spec.ts +++ /dev/null @@ -1,274 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { - SchematicTestRunner, - UnitTestTree -} from '@angular-devkit/schematics/testing'; - -import { join } from 'path'; - -import { serializeJson } from '@nrwl/workspace'; -import { readJsonInTree, updateJsonInTree } from '@nrwl/workspace'; -import { stripIndents } from '@angular-devkit/core/src/utils/literals'; -import { createEmptyWorkspace } from '@nrwl/workspace/testing'; - -const effectContents = ` -import { Injectable } from '@angular/core'; -import { Store } from '@ngrx/store'; -import { Effect, Actions } from '@ngrx/effects'; -import { DataPersistence } from '@nrwl/nx'; - -import { UserPartialState } from './user.reducer'; -import { - LoadUser, - UserLoaded, - UserLoadError, - UserActionTypes -} from './user.actions'; - -@Injectable() -export class UserEffects { - @Effect() effect$ = this.actions$.ofType(LoadUser).pipe(mapTo(UserLoaded)); - @Effect() effect2$ = this.actions$.ofType(LoadUser).pipe(mapTo(UserLoaded)); - @Effect() effect3$ = this.actions$.ofType(LoadUser).pipe(withLatestFrom(this.store.select(selector)), mapTo(UserLoaded)); - - constructor( - private actions$: Actions, - private dataPersistence: DataPersistence, - private store: Store - ) {} -} - -`; - -const selectorContents = ` -import { Store } from '@ngrx/store'; -import { Component } from '@angular/core'; -import { AppState, selector } from '../+state'; - -@Component({ - selector: 'app', - template: '', - styles: [] -}) -export class AppComponent { - slice$ = this.store.select(selector).pipe( - map(a => a) - ); - - slice2$: Observable; - - slice3$ = Observable.from([]).pipe( - withLatestFrom(this.store.select(selector5)) - ); - - constructor( - private store: Store - ) {} - - ngOnInit() { - this.slice2$ = this.store.select(selector2); - this.store.select(selector3).subscribe(console.log); - } -} - -`; - -describe('Update 7.6.0', () => { - let initialTree: Tree; - let schematicRunner: SchematicTestRunner; - - beforeEach(() => { - initialTree = createEmptyWorkspace(Tree.empty()); - - initialTree.overwrite( - 'package.json', - serializeJson({ - dependencies: { - '@ngrx/effects': '6.1.2', - '@ngrx/router-store': '6.1.2', - '@ngrx/store': '6.1.2' - }, - devDependencies: { - '@ngrx/schematics': '6.1.2', - '@ngrx/store-devtools': '6.1.2' - } - }) - ); - - schematicRunner = new SchematicTestRunner( - '@nrwl/schematics', - join(__dirname, '../migrations.json') - ); - }); - - describe('VSCode Extension Recommendations', () => { - it('should be added', async () => { - const result = await schematicRunner - .runSchematicAsync('update-7.6.0', {}, initialTree) - .toPromise(); - - expect(readJsonInTree(result, '.vscode/extensions.json')).toEqual({ - recommendations: [ - 'nrwl.angular-console', - 'angular.ng-template', - 'esbenp.prettier-vscode' - ] - }); - }); - - it('should be added to existing recommendations', async () => { - initialTree = await schematicRunner - .callRule( - updateJsonInTree('.vscode/extensions.json', () => ({ - recommendations: ['eamodio.gitlens', 'angular.ng-template'] - })), - initialTree - ) - .toPromise(); - - const result = await schematicRunner - .runSchematicAsync('update-7.6.0', {}, initialTree) - .toPromise(); - - expect(readJsonInTree(result, '.vscode/extensions.json')).toEqual({ - recommendations: [ - 'eamodio.gitlens', - 'angular.ng-template', - 'nrwl.angular-console', - 'esbenp.prettier-vscode' - ] - }); - }); - }); - - describe('adding dotenv', () => { - it('should add dotenv as a dev dependency', async () => { - const result = await schematicRunner - .runSchematicAsync('update-7.6.0', {}, initialTree) - .toPromise(); - - expect( - readJsonInTree(result, 'package.json').devDependencies['dotenv'] - ).toEqual('6.2.0'); - }); - }); - - describe('setting defaults to karma, protractor, express', () => { - it('should default to karma, protractor and express', async () => { - const result = await schematicRunner - .runSchematicAsync('update-7.6.0', {}, initialTree) - .toPromise(); - - expect( - readJsonInTree(result, 'workspace.json').schematics[ - '@nrwl/schematics:library' - ].unitTestRunner - ).toEqual('karma'); - expect( - readJsonInTree(result, 'workspace.json').schematics[ - '@nrwl/schematics:application' - ].unitTestRunner - ).toEqual('karma'); - expect( - readJsonInTree(result, 'workspace.json').schematics[ - '@nrwl/schematics:application' - ].e2eTestRunner - ).toEqual('protractor'); - expect( - readJsonInTree(result, 'workspace.json').schematics[ - '@nrwl/schematics:node-application' - ].framework - ).toEqual('express'); - }); - }); - - describe('NgRx Migration', () => { - it('should update ngrx to 7.1.0', async () => { - const result = await schematicRunner - .runSchematicAsync('update-7.6.0', {}, initialTree) - .toPromise(); - - const json = readJsonInTree(result, 'package.json'); - expect(json.dependencies['@ngrx/effects']).toEqual('7.2.0'); - expect(json.dependencies['@ngrx/router-store']).toEqual('7.2.0'); - expect(json.dependencies['@ngrx/store']).toEqual('7.2.0'); - expect(json.devDependencies['@ngrx/schematics']).toEqual('7.2.0'); - expect(json.devDependencies['@ngrx/store-devtools']).toEqual('7.2.0'); - }); - - it('should convert ofType code', async () => { - initialTree.create('user.effects.ts', effectContents); - const result = await schematicRunner - .runSchematicAsync('update-7.6.0', {}, initialTree) - .toPromise(); - const contents = result.readContent('user.effects.ts'); - expect(contents).toContain( - "import { Effect, Actions, ofType } from '@ngrx/effects';" - ); - expect(stripIndents`${contents}`).toContain( - stripIndents` - @Effect() effect$ = this.actions$.pipe( - ofType(LoadUser), - mapTo(UserLoaded) - );` - ); - expect(stripIndents`${contents}`).toContain( - stripIndents` - @Effect() effect2$ = this.actions$.pipe( - ofType(LoadUser), - mapTo(UserLoaded) - );` - ); - expect(stripIndents`${contents}`).toContain( - stripIndents` - @Effect() effect3$ = this.actions$.pipe( - ofType(LoadUser), - withLatestFrom(this.store.pipe(select(selector))), - mapTo(UserLoaded) - );` - ); - }); - - it('should convert select code', async () => { - initialTree.create('app.component.ts', selectorContents); - const result = await schematicRunner - .runSchematicAsync('update-7.6.0', {}, initialTree) - .toPromise(); - const contents = result.readContent('app.component.ts'); - expect(contents).toContain( - "import { Store, select } from '@ngrx/store';" - ); - expect(stripIndents`${contents}`).toContain( - stripIndents` - slice$ = this.store.pipe( - select(selector), - map(a => a) - );` - ); - expect(contents).toContain( - 'this.slice2$ = this.store.pipe(select(selector2))' - ); - expect(contents).toContain( - 'this.store.pipe(select(selector3)).subscribe(console.log);' - ); - - expect(stripIndents`${contents}`).toContain(stripIndents` - slice3$ = Observable.from([]).pipe( - withLatestFrom(this.store.pipe(select(selector5))) - );`); - }); - }); - - describe('Update Angular CLI', () => { - it('should update @angular-devkit/build-angular', async () => { - const result = await schematicRunner - .runSchematicAsync('update-7.6.0', {}, initialTree) - .toPromise(); - expect( - readJsonInTree(result, 'package.json').devDependencies[ - '@angular-devkit/build-angular' - ] - ).toEqual('~0.13.1'); - }); - }); -}); diff --git a/packages/schematics/migrations/update-7-6-0/update-7-6-0.ts b/packages/schematics/migrations/update-7-6-0/update-7-6-0.ts deleted file mode 100644 index 9ba073301e584..0000000000000 --- a/packages/schematics/migrations/update-7-6-0/update-7-6-0.ts +++ /dev/null @@ -1,424 +0,0 @@ -import { chain, Rule, Tree } from '@angular-devkit/schematics'; - -import * as ts from 'typescript'; - -import { - addDepsToPackageJson, - addUpdateTask, - formatFiles, - insert, - readJsonInTree, - updateJsonInTree, - updateWorkspaceInTree -} from '@nrwl/workspace'; -import { - getSourceNodes, - ReplaceChange -} from '@nrwl/workspace/src/utils/ast-utils'; - -const addExtensionRecommendations = updateJsonInTree( - '.vscode/extensions.json', - (json: { recommendations?: string[] }) => { - json.recommendations = json.recommendations || []; - [ - 'nrwl.angular-console', - 'angular.ng-template', - 'esbenp.prettier-vscode' - ].forEach(extension => { - if (!json.recommendations.includes(extension)) { - json.recommendations.push(extension); - } - }); - - return json; - } -); - -function addItemToImport( - path: string, - sourceFile: ts.SourceFile, - printer: ts.Printer, - importStatement: ts.ImportDeclaration, - symbol: string -) { - const newImport = ts.createImportDeclaration( - importStatement.decorators, - importStatement.modifiers, - ts.createImportClause( - importStatement.importClause.name, - ts.createNamedImports([ - ...(importStatement.importClause.namedBindings as ts.NamedImports) - .elements, - ts.createImportSpecifier(undefined, ts.createIdentifier(symbol)) - ]) - ), - importStatement.moduleSpecifier - ); - return new ReplaceChange( - path, - importStatement.getStart(sourceFile), - importStatement.getText(sourceFile), - printer.printNode(ts.EmitHint.Unspecified, newImport, sourceFile) - ); -} - -function isEffectDecorator(decorator: ts.Decorator) { - return ( - ts.isCallExpression(decorator.expression) && - ts.isIdentifier(decorator.expression.expression) && - decorator.expression.expression.text === 'Effect' - ); -} - -function getImport(sourceFile: ts.SourceFile, path: string, symbol: string) { - return sourceFile.statements - .filter(ts.isImportDeclaration) - .filter(statement => - statement.moduleSpecifier.getText(sourceFile).includes(path) - ) - .find(statement => { - if (!ts.isNamedImports(statement.importClause.namedBindings)) { - return false; - } - - return statement.importClause.namedBindings.elements.some( - element => element.getText(sourceFile) === symbol - ); - }); -} - -function updateOfTypeCode(path: string, sourceFile: ts.SourceFile) { - const effectsImport = getImport(sourceFile, '@ngrx/effects', 'Effect'); - if (!effectsImport) { - return []; - } - - const effects: ts.PropertyDeclaration[] = []; - const changes: ReplaceChange[] = []; - - const printer = ts.createPrinter(); - - sourceFile.statements - .filter(ts.isClassDeclaration) - .map(clazz => - clazz.members - .filter(ts.isPropertyDeclaration) - .filter( - member => - member.decorators && member.decorators.some(isEffectDecorator) - ) - ) - .forEach(properties => { - effects.push(...properties); - }); - - effects.forEach(effect => { - if ( - ts.isCallExpression(effect.initializer) && - ts.isPropertyAccessExpression(effect.initializer.expression) && - effect.initializer.expression.name.text === 'pipe' && - ts.isCallExpression(effect.initializer.expression.expression) && - ts.isPropertyAccessExpression( - effect.initializer.expression.expression.expression - ) && - effect.initializer.expression.expression.expression.name.text === 'ofType' - ) { - const originalText = effect.initializer.getText(sourceFile); - - const ofTypeExpression = ts.createCall( - ts.createIdentifier('ofType'), - effect.initializer.expression.expression.typeArguments, - effect.initializer.expression.expression.arguments - ); - - const node = ts.createCall( - ts.createPropertyAccess( - effect.initializer.expression.expression.expression.expression, - 'pipe' - ), - effect.initializer.typeArguments, - ts.createNodeArray([ - ofTypeExpression, - ...(effect.initializer as ts.CallExpression).arguments - ]) - ); - const newEffect = printer.printNode( - ts.EmitHint.Expression, - node, - sourceFile - ); - - const change = new ReplaceChange( - path, - effect.initializer.getStart(sourceFile), - originalText, - newEffect - ); - changes.push(change); - } - }); - - if (changes.length > 0) { - changes.unshift( - addItemToImport(path, sourceFile, printer, effectsImport, 'ofType') - ); - } - - return changes; -} - -function getConstructor( - classDeclaration: ts.ClassDeclaration -): ts.ConstructorDeclaration { - return classDeclaration.members.find(ts.isConstructorDeclaration); -} - -function getStoreProperty( - sourceFile: ts.SourceFile, - constructor: ts.ConstructorDeclaration -): string { - const storeParameter = constructor.parameters.find( - parameter => - parameter.type && parameter.type.getText(sourceFile).includes('Store') - ); - return storeParameter ? storeParameter.name.getText(sourceFile) : null; -} - -function updateSelectorCode(path: string, sourceFile: ts.SourceFile) { - const storeImport = getImport(sourceFile, '@ngrx/store', 'Store'); - if (!storeImport) { - return []; - } - const changes: ReplaceChange[] = []; - - const printer = ts.createPrinter(); - - sourceFile.statements - .filter(ts.isClassDeclaration) - .forEach(classDeclaration => { - const constructor = getConstructor(classDeclaration); - if (!constructor) { - return; - } - - const storeProperty = getStoreProperty(sourceFile, constructor); - getSourceNodes(sourceFile).forEach(node => { - if ( - ts.isCallExpression(node) && - ts.isPropertyAccessExpression(node.expression) && - ts.isPropertyAccessExpression(node.expression.expression) && - ts.isIdentifier(node.expression.name) && - ts.isIdentifier(node.expression.expression.name) && - node.expression.name.getText(sourceFile) === 'select' && - node.expression.expression.name.getText(sourceFile) === - storeProperty && - node.expression.expression.expression.kind === - ts.SyntaxKind.ThisKeyword - ) { - const newExpression = ts.createCall( - ts.createPropertyAccess( - ts.createPropertyAccess( - ts.createIdentifier('this'), - ts.createIdentifier(storeProperty) - ), - ts.createIdentifier('pipe') - ), - [], - [ - ts.createCall( - ts.createIdentifier('select'), - node.typeArguments, - node.arguments - ) - ] - ); - const newNode = printer.printNode( - ts.EmitHint.Expression, - newExpression, - sourceFile - ); - changes.push( - new ReplaceChange( - path, - node.getStart(sourceFile), - node.getText(sourceFile), - newNode - ) - ); - } - }); - }); - - if (changes.length > 0) { - changes.unshift( - addItemToImport(path, sourceFile, printer, storeImport, 'select') - ); - } - - return changes; -} - -function migrateNgrx(host: Tree) { - const ngrxVersion = readJsonInTree(host, 'package.json').dependencies[ - '@ngrx/store' - ]; - if ( - ngrxVersion && - !( - ngrxVersion.startsWith('6.') || - ngrxVersion.startsWith('~6.') || - ngrxVersion.startsWith('^6.') - ) - ) { - return host; - } - - host.visit(path => { - if (!path.endsWith('.ts')) { - return; - } - - let sourceFile = ts.createSourceFile( - path, - host.read(path).toString(), - ts.ScriptTarget.Latest - ); - - if (sourceFile.isDeclarationFile) { - return; - } - - insert(host, path, updateOfTypeCode(path, sourceFile)); - - sourceFile = ts.createSourceFile( - path, - host.read(path).toString(), - ts.ScriptTarget.Latest - ); - - insert(host, path, updateSelectorCode(path, sourceFile)); - - sourceFile = ts.createSourceFile( - path, - host.read(path).toString(), - ts.ScriptTarget.Latest - ); - - insert(host, path, cleanUpDoublePipes(path, sourceFile)); - }); -} - -function cleanUpDoublePipes( - path: string, - sourceFile: ts.SourceFile -): ReplaceChange[] { - const changes: ReplaceChange[] = []; - - const printer = ts.createPrinter(); - - getSourceNodes(sourceFile).forEach(node => { - if ( - ts.isCallExpression(node) && - ts.isPropertyAccessExpression(node.expression) && - ts.isCallExpression(node.expression.expression) && - ts.isPropertyAccessExpression(node.expression.expression.expression) && - node.expression.name.text === 'pipe' && - node.expression.expression.expression.name.text === 'pipe' - ) { - const singlePipe = ts.createCall( - node.expression.expression.expression, - node.typeArguments, - [...node.expression.expression.arguments, ...node.arguments] - ); - changes.push( - new ReplaceChange( - path, - node.getStart(sourceFile), - node.getText(sourceFile), - printer.printNode(ts.EmitHint.Expression, singlePipe, sourceFile) - ) - ); - } - }); - - return changes; -} - -const updateNgrx = updateJsonInTree('package.json', json => { - json.devDependencies = json.devDependencies || {}; - json.dependencies = json.dependencies || {}; - - json.dependencies = { - ...json.dependencies, - '@ngrx/effects': '7.2.0', - '@ngrx/router-store': '7.2.0', - '@ngrx/store': '7.2.0' - }; - - json.devDependencies = { - ...json.devDependencies, - '@ngrx/schematics': '7.2.0', - '@ngrx/store-devtools': '7.2.0' - }; - return json; -}); - -const addDotEnv = updateJsonInTree('package.json', json => { - json.devDependencies = json.devDependencies || {}; - json.devDependencies = { - ...json.devDependencies, - dotenv: '6.2.0' - }; - return json; -}); - -const setDefaults = updateWorkspaceInTree(json => { - if (!json.schematics) { - json.schematics = {}; - } - if (!json.schematics['@nrwl/schematics:library']) { - json.schematics['@nrwl/schematics:library'] = {}; - } - if (!json.schematics['@nrwl/schematics:library'].unitTestRunner) { - json.schematics['@nrwl/schematics:library'].unitTestRunner = 'karma'; - } - if (!json.schematics['@nrwl/schematics:application']) { - json.schematics['@nrwl/schematics:application'] = {}; - } - if (!json.schematics['@nrwl/schematics:application'].unitTestRunner) { - json.schematics['@nrwl/schematics:application'].unitTestRunner = 'karma'; - } - if (!json.schematics['@nrwl/schematics:application'].e2eTestRunner) { - json.schematics['@nrwl/schematics:application'].e2eTestRunner = - 'protractor'; - } - if (!json.schematics['@nrwl/schematics:node-application']) { - json.schematics['@nrwl/schematics:node-application'] = {}; - } - if (!json.schematics['@nrwl/schematics:node-application'].framework) { - json.schematics['@nrwl/schematics:node-application'].framework = 'express'; - } - return json; -}); - -const updateAngularCLI = chain([ - addUpdateTask('@angular/cli', '7.3.1'), - addDepsToPackageJson( - {}, - { - '@angular-devkit/build-angular': '~0.13.1' - } - ) -]); - -export default function(): Rule { - return chain([ - addExtensionRecommendations, - addDotEnv, - updateAngularCLI, - migrateNgrx, - updateNgrx, - setDefaults, - formatFiles() - ]); -} diff --git a/packages/schematics/migrations/update-7-7-0/update-7-7-0.spec.ts b/packages/schematics/migrations/update-7-7-0/update-7-7-0.spec.ts deleted file mode 100644 index b58cc1a4a9781..0000000000000 --- a/packages/schematics/migrations/update-7-7-0/update-7-7-0.spec.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { - SchematicTestRunner, - UnitTestTree -} from '@angular-devkit/schematics/testing'; - -import { join } from 'path'; -import { readJsonInTree } from '@nrwl/workspace'; -import { serializeJson } from '@nrwl/workspace'; -import { createEmptyWorkspace } from '@nrwl/workspace/testing'; - -describe('Update 7.7.0', () => { - let initialTree: Tree; - let schematicRunner: SchematicTestRunner; - - beforeEach(() => { - initialTree = createEmptyWorkspace(Tree.empty()); - - schematicRunner = new SchematicTestRunner( - '@nrwl/schematics', - join(__dirname, '../migrations.json') - ); - }); - - describe('setting defaults to angular', () => { - it('should set default lib framework to Angular', async () => { - const result = await schematicRunner - .runSchematicAsync('update-7.7.0', {}, initialTree) - .toPromise(); - - expect( - readJsonInTree(result, 'workspace.json').schematics[ - '@nrwl/schematics:library' - ].framework - ).toEqual('angular'); - }); - }); - - describe('jest update', () => { - beforeEach(() => { - initialTree.overwrite( - 'package.json', - serializeJson({ - devDependencies: { - jest: '23.10.5', - 'jest-preset-angular': '6.0.2' - } - }) - ); - initialTree.create( - 'jest.config.js', - `module.exports = { - testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'], - transform: { - '^.+\\.(ts|js|html)$': 'jest-preset-angular/preprocessor.js' - }, - resolver: '@nrwl/builders/plugins/jest/resolver', - moduleFileExtensions: ['ts', 'js', 'html'], - coverageReporters: ['html'] - };` - ); - }); - - it('should update jest dependencies', async () => { - const result = await schematicRunner - .runSchematicAsync('update-7.7.0', {}, initialTree) - .toPromise(); - - const { devDependencies } = readJsonInTree(result, 'package.json'); - expect(devDependencies.jest).toEqual('24.1.0'); - expect(devDependencies['jest-preset-angular']).toEqual('7.0.0'); - }); - - it('should update jest.config.js', async () => { - const result = await schematicRunner - .runSchematicAsync('update-7.7.0', {}, initialTree) - .toPromise(); - - expect(result.readContent('jest.config.js')).not.toContain( - 'jest-preset-angular/preprocessor.js' - ); - }); - }); -}); diff --git a/packages/schematics/migrations/update-7-7-0/update-7-7-0.ts b/packages/schematics/migrations/update-7-7-0/update-7-7-0.ts deleted file mode 100644 index 9a5fa7b271bbf..0000000000000 --- a/packages/schematics/migrations/update-7-7-0/update-7-7-0.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { chain, Rule, Tree } from '@angular-devkit/schematics'; - -import { updateJsonInTree, insert } from '@nrwl/workspace'; -import { formatFiles, updateWorkspaceInTree } from '@nrwl/workspace'; - -import * as ts from 'typescript'; -import { - getSourceNodes, - ReplaceChange -} from '@nrwl/workspace/src/utils/ast-utils'; - -const setDefaults = updateWorkspaceInTree(json => { - if (!json.schematics) { - json.schematics = {}; - } - if (!json.schematics['@nrwl/schematics:library']) { - json.schematics['@nrwl/schematics:library'] = {}; - } - if (!json.schematics['@nrwl/schematics:library'].framework) { - json.schematics['@nrwl/schematics:library'].framework = 'angular'; - } - return json; -}); - -const updateDependencies = updateJsonInTree('package.json', json => { - json.devDependencies = json.devDependencies || {}; - if (json.devDependencies['jest']) { - json.devDependencies['jest'] = '24.1.0'; - } - if (json.devDependencies['@types/jest']) { - json.devDependencies['@types/jest'] = '24.0.9'; - } - if (json.devDependencies['jest-preset-angular']) { - json.devDependencies['jest-preset-angular'] = '7.0.0'; - } - return json; -}); - -function updateJestConfig(host: Tree) { - if (host.exists('jest.config.js')) { - const contents = host.read('jest.config.js').toString(); - const sourceFile = ts.createSourceFile( - 'jest.config.js', - contents, - ts.ScriptTarget.Latest - ); - const changes: ReplaceChange[] = []; - getSourceNodes(sourceFile).forEach(node => { - if ( - ts.isPropertyAssignment(node) && - ts.isStringLiteral(node.initializer) && - node.initializer.text === 'jest-preset-angular/preprocessor.js' - ) { - changes.push( - new ReplaceChange( - 'jest.config.js', - node.initializer.getStart(sourceFile), - node.initializer.getText(sourceFile), - "'ts-jest'" - ) - ); - } - }); - insert(host, 'jest.config.js', changes); - } -} - -export default function(): Rule { - return chain([ - setDefaults, - updateDependencies, - updateJestConfig, - formatFiles() - ]); -} diff --git a/packages/schematics/migrations/update-7-8-1/update-7-8-1.spec.ts b/packages/schematics/migrations/update-7-8-1/update-7-8-1.spec.ts deleted file mode 100644 index e2fb9090ef5f3..0000000000000 --- a/packages/schematics/migrations/update-7-8-1/update-7-8-1.spec.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; -import { serializeJson } from '@nrwl/workspace'; - -import * as path from 'path'; -import { createEmptyWorkspace } from '@nrwl/workspace/testing'; - -describe('Update 7.8.1', () => { - let initialTree: Tree; - let schematicRunner: SchematicTestRunner; - - beforeEach(() => { - initialTree = createEmptyWorkspace(Tree.empty()); - initialTree.overwrite( - 'package.json', - serializeJson({ - scripts: {} - }) - ); - schematicRunner = new SchematicTestRunner( - '@nrwl/schematics', - path.join(__dirname, '../migrations.json') - ); - }); - - it('should update prettier', async () => { - const result = await schematicRunner - .runSchematicAsync('update-7.8.1', {}, initialTree) - .toPromise(); - - const { devDependencies } = JSON.parse(result.readContent('package.json')); - - expect(devDependencies.prettier).toEqual('1.16.4'); - }); - - describe('.prettierignore', () => { - it('should not be touched if one exists', async () => { - initialTree.create('.prettierignore', '**/*.json'); - const result = await schematicRunner - .runSchematicAsync('update-7.8.1', {}, initialTree) - .toPromise(); - - expect(result.readContent('.prettierignore')).toEqual('**/*.json'); - }); - }); -}); diff --git a/packages/schematics/migrations/update-7-8-1/update-7-8-1.ts b/packages/schematics/migrations/update-7-8-1/update-7-8-1.ts deleted file mode 100644 index 28b8f6b175c6e..0000000000000 --- a/packages/schematics/migrations/update-7-8-1/update-7-8-1.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { - Rule, - chain, - SchematicContext, - Tree -} from '@angular-devkit/schematics'; -import { updateJsonInTree } from '@nrwl/workspace'; -import { stripIndents } from '@angular-devkit/core/src/utils/literals'; -import { addDepsToPackageJson } from '@nrwl/workspace/src/utils/ast-utils'; - -function displayInformation(host: Tree, context: SchematicContext) { - context.logger.info( - stripIndents`Prettier has been updated to 1.16.4 which has a lot of small improvements - Formatting of your code might change as you are working on each file. - Prettier will now format *.less files you can disable this by adding '*.less' to your .prettierignore - - Optional: You may want to run "npm run format" as part of this update to reformat all files in your workspace. - - You can also opt out of formatting in files by adding them to the .prettierignore file in the root of your workspace.` - ); -} - -export default function(): Rule { - return chain([ - addDepsToPackageJson( - {}, - { - prettier: '1.16.4' - } - ), - displayInformation - ]); -} diff --git a/packages/schematics/migrations/update-8-0-0/update-8-0-0.spec.ts b/packages/schematics/migrations/update-8-0-0/update-8-0-0.spec.ts deleted file mode 100644 index 5a1a25d9c929a..0000000000000 --- a/packages/schematics/migrations/update-8-0-0/update-8-0-0.spec.ts +++ /dev/null @@ -1,405 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; -import { updateJsonInTree, readJsonInTree } from '@nrwl/workspace'; - -import * as path from 'path'; -import { createEmptyWorkspace } from '@nrwl/workspace/testing'; - -describe('Update 8-0-0', () => { - let initialTree: Tree; - let schematicRunner: SchematicTestRunner; - - beforeEach(async () => { - initialTree = createEmptyWorkspace(Tree.empty()); - schematicRunner = new SchematicTestRunner( - '@nrwl/schematics', - path.join(__dirname, '../migrations.json') - ); - initialTree = await schematicRunner - .callRule( - updateJsonInTree('package.json', json => ({ - scripts: { - update: 'ng update @nrwl/schematics' - }, - dependencies: { - '@nrwl/nx': '7.8.1', - '@nestjs/core': '5.6.0', - express: '4.16.3', - react: '16.8.3', - '@angular/core': '^7.0.0' - }, - devDependencies: { - '@nrwl/schematics': '7.8.1', - cypress: '3.1.0', - jest: '24.1.0' - } - })), - initialTree - ) - .toPromise(); - initialTree = await schematicRunner - .callRule( - updateJsonInTree('tsconfig.json', json => ({ - compilerOptions: {} - })), - initialTree - ) - .toPromise(); - initialTree = await schematicRunner - .callRule( - updateJsonInTree('tsconfig.app.json', json => ({ - compilerOptions: { - outDir: '../../dist/out-tsc/apps/blah' - } - })), - initialTree - ) - .toPromise(); - initialTree = await schematicRunner - .callRule( - updateJsonInTree('workspace.json', json => ({ - projects: { - 'my-app': { - architect: { - cypress: { - builder: '@nrwl/builders:cypress', - options: {} - }, - jest: { - builder: '@nrwl/builders:jest', - options: {} - }, - nodeBuild: { - builder: '@nrwl/builders:node-build', - options: {} - }, - nodeServe: { - builder: '@nrwl/builders:node-execute', - options: {} - }, - webBuild: { - builder: '@nrwl/builders:web-build', - options: {} - }, - webServe: { - builder: '@nrwl/builders:web-dev-server', - options: {} - }, - runCommands: { - builder: '@nrwl/builders:run-commands', - options: {} - } - } - } - }, - cli: { - defaultCollection: '@nrwl/schematics' - } - })), - initialTree - ) - .toPromise(); - initialTree = await schematicRunner - .callRule( - updateJsonInTree('tslint.json', json => ({ - rulesDirectory: ['node_modules/@nrwl/schematics/src/tslint'], - rules: {} - })), - initialTree - ) - .toPromise(); - }); - - describe('imports', () => { - it(`should be migrated from '@nrwl/nx' to '@nrwl/angular'`, async () => { - initialTree.create( - 'file.ts', - ` - import * from '@nrwl/nx'; - import * from '@nrwl/nx/testing'; - import { NxModule } from '@nrwl/nx'; - import { hot } from '@nrwl/nx/testing'; - ` - ); - - const tree = await schematicRunner - .runSchematicAsync('update-8.0.0', {}, initialTree) - .toPromise(); - expect(tree.readContent('file.ts')).toEqual(` - import * from '@nrwl/angular'; - import * from '@nrwl/angular/testing'; - import { NxModule } from '@nrwl/angular'; - import { hot } from '@nrwl/angular/testing'; - `); - }); - - it(`should be migrated from '@nrwl/schematics' to '@nrwl/workspace'`, async () => { - initialTree.create( - 'file.ts', - ` - import * from '@nrwl/schematics/src/utils/fileutils'; - import { fileExists } from '@nrwl/schematics/src/utils/fileutils'; - ` - ); - - const tree = await schematicRunner - .runSchematicAsync('update-8.0.0', {}, initialTree) - .toPromise(); - expect(tree.readContent('file.ts')).toEqual( - ` - import * from '@nrwl/workspace/src/utils/fileutils'; - import { fileExists } from '@nrwl/workspace/src/utils/fileutils'; - ` - ); - }); - }); - - describe('builders', () => { - it('should be migrated', async () => { - const tree = await schematicRunner - .runSchematicAsync('update-8.0.0', {}, initialTree) - .toPromise(); - const { projects } = readJsonInTree(tree, 'workspace.json'); - const { architect } = projects['my-app']; - expect(architect.cypress.builder).toEqual('@nrwl/cypress:cypress'); - expect(architect.jest.builder).toEqual('@nrwl/jest:jest'); - expect(architect.nodeBuild.builder).toEqual('@nrwl/node:build'); - expect(architect.nodeServe.builder).toEqual('@nrwl/node:execute'); - expect(architect.webBuild.builder).toEqual('@nrwl/web:build'); - expect(architect.webServe.builder).toEqual('@nrwl/web:dev-server'); - expect(architect.runCommands.builder).toEqual( - '@nrwl/workspace:run-commands' - ); - }); - }); - - describe('update npm script', () => { - it('should do ng update @nrwl/workspace', async () => { - const tree = await schematicRunner - .runSchematicAsync('update-8.0.0', {}, initialTree) - .toPromise(); - const packageJson = readJsonInTree(tree, 'package.json'); - expect(packageJson.scripts.update).toEqual('ng update @nrwl/workspace'); - }); - }); - - describe('set root dir', () => { - it('should set root dir and update out dirs', async () => { - const tree = await schematicRunner - .runSchematicAsync('update-8.0.0', {}, initialTree) - .toPromise(); - const rootTsConfig = readJsonInTree(tree, 'tsconfig.json'); - expect(rootTsConfig.compilerOptions.rootDir).toEqual('.'); - - const appTsConfig = readJsonInTree(tree, 'tsconfig.app.json'); - expect(appTsConfig.compilerOptions.outDir).toEqual('../../dist/out-tsc'); - }); - }); - - describe('jest config', () => { - it('should have the plugin path migrated', async () => { - initialTree.create( - 'jest.config.js', - ` - module.exports = { - resolver: '@nrwl/builders/plugins/jest/resolver', - }; - ` - ); - const tree = await schematicRunner - .runSchematicAsync('update-8.0.0', {}, initialTree) - .toPromise(); - expect(tree.readContent('jest.config.js')).toContain( - '@nrwl/jest/plugins/resolver' - ); - }); - }); - - describe('dependencies', () => { - it('should change to the new dependencies', async () => { - const tree = await schematicRunner - .runSchematicAsync('update-8.0.0', {}, initialTree) - .toPromise(); - - const { dependencies, devDependencies } = readJsonInTree( - tree, - 'package.json' - ); - expect(dependencies['@nrwl/nx']).not.toBeDefined(); - expect(devDependencies['@nrwl/schematics']).not.toBeDefined(); - expect(devDependencies['@nrwl/builders']).not.toBeDefined(); - expect(dependencies['@nrwl/angular']).toBeDefined(); - expect(devDependencies['@nrwl/express']).toBeDefined(); - expect(devDependencies['@nrwl/cypress']).toBeDefined(); - expect(devDependencies['@nrwl/jest']).toBeDefined(); - expect(devDependencies['@nrwl/nest']).toBeDefined(); - expect(devDependencies['@nrwl/node']).toBeDefined(); - expect(devDependencies['@nrwl/react']).toBeDefined(); - expect(devDependencies['@nrwl/web']).toBeDefined(); - expect(devDependencies['@nrwl/workspace']).toBeDefined(); - }); - }); - - describe('lint rules', () => { - it('should be migrated to `@nrwl/workspace`', async () => { - const tree = await schematicRunner - .runSchematicAsync('update-8.0.0', {}, initialTree) - .toPromise(); - - const { rulesDirectory } = readJsonInTree(tree, 'tslint.json'); - expect(rulesDirectory).not.toContain( - 'node_modules/@nrwl/schematics/src/tslint' - ); - expect(rulesDirectory).toContain( - 'node_modules/@nrwl/workspace/src/tslint' - ); - }); - }); - - describe('Nest dependencies', () => { - it('should be updated to 6.x', async () => { - const tree = await schematicRunner - .runSchematicAsync('update-8.0.0', {}, initialTree) - .toPromise(); - - const { dependencies, devDependencies } = readJsonInTree( - tree, - 'package.json' - ); - - expect(dependencies['@nestjs/common']).toEqual('^6.2.4'); - expect(dependencies['@nestjs/core']).toEqual('^6.2.4'); - expect(dependencies['@nestjs/platform-express']).toEqual('^6.2.4'); - expect(dependencies['reflect-metadata']).toEqual('^0.1.12'); - expect(devDependencies['@nestjs/schematics']).toEqual('^6.3.0'); - expect(devDependencies['@nestjs/testing']).toEqual('^6.2.4'); - }); - }); - - describe('defaultCollection', () => { - it('should be set to @nrwl/angular if @angular/core is present', async () => { - const tree = await schematicRunner - .runSchematicAsync('update-8.0.0', {}, initialTree) - .toPromise(); - - const defaultCollection = readJsonInTree(tree, 'workspace.json').cli - .defaultCollection; - expect(defaultCollection).toEqual('@nrwl/angular'); - }); - - it('should be set to @nrwl/react if react is present', async () => { - initialTree = await schematicRunner - .callRule( - updateJsonInTree('package.json', json => ({ - ...json, - dependencies: { - '@nestjs/core': '5.6.0', - express: '4.16.3', - react: '16.8.3' - } - })), - initialTree - ) - .toPromise(); - const tree = await schematicRunner - .runSchematicAsync('update-8.0.0', {}, initialTree) - .toPromise(); - - const defaultCollection = readJsonInTree(tree, 'workspace.json').cli - .defaultCollection; - expect(defaultCollection).toEqual('@nrwl/react'); - }); - - it('should be set to @nrwl/nest if @nestjs/core is present', async () => { - initialTree = await schematicRunner - .callRule( - updateJsonInTree('package.json', json => ({ - ...json, - dependencies: { - '@nestjs/core': '5.6.0', - express: '4.16.3' - } - })), - initialTree - ) - .toPromise(); - const tree = await schematicRunner - .runSchematicAsync('update-8.0.0', {}, initialTree) - .toPromise(); - - const defaultCollection = readJsonInTree(tree, 'workspace.json').cli - .defaultCollection; - expect(defaultCollection).toEqual('@nrwl/nest'); - }); - - it('should be set to @nrwl/express if express is present', async () => { - initialTree = await schematicRunner - .callRule( - updateJsonInTree('package.json', json => ({ - ...json, - dependencies: { - express: '4.16.3' - } - })), - initialTree - ) - .toPromise(); - const tree = await schematicRunner - .runSchematicAsync('update-8.0.0', {}, initialTree) - .toPromise(); - - const defaultCollection = readJsonInTree(tree, 'workspace.json').cli - .defaultCollection; - expect(defaultCollection).toEqual('@nrwl/express'); - }); - - it('should be set to @nrwl/express if express is present', async () => { - initialTree = await schematicRunner - .callRule( - updateJsonInTree('package.json', json => ({ - ...json, - dependencies: { - express: '4.16.3' - } - })), - initialTree - ) - .toPromise(); - const tree = await schematicRunner - .runSchematicAsync('update-8.0.0', {}, initialTree) - .toPromise(); - - const defaultCollection = readJsonInTree(tree, 'workspace.json').cli - .defaultCollection; - expect(defaultCollection).toEqual('@nrwl/express'); - }); - - it('should fallback to @nrwl/workspace', async () => { - initialTree = await schematicRunner - .callRule( - updateJsonInTree('package.json', json => ({ - ...json, - dependencies: {} - })), - initialTree - ) - .toPromise(); - initialTree = await schematicRunner - .callRule( - updateJsonInTree('workspace.json', json => ({ - ...json, - projects: {} - })), - initialTree - ) - .toPromise(); - const tree = await schematicRunner - .runSchematicAsync('update-8.0.0', {}, initialTree) - .toPromise(); - - const defaultCollection = readJsonInTree(tree, 'workspace.json').cli - .defaultCollection; - expect(defaultCollection).toEqual('@nrwl/workspace'); - }); - }); -}); diff --git a/packages/schematics/migrations/update-8-0-0/update-8-0-0.ts b/packages/schematics/migrations/update-8-0-0/update-8-0-0.ts deleted file mode 100644 index e136876338747..0000000000000 --- a/packages/schematics/migrations/update-8-0-0/update-8-0-0.ts +++ /dev/null @@ -1,409 +0,0 @@ -import { - chain, - Rule, - SchematicContext, - Tree -} from '@angular-devkit/schematics'; -import { stripIndents } from '@angular-devkit/core/src/utils/literals'; -import { - addDepsToPackageJson, - formatFiles, - insert, - readJsonInTree, - updateJsonInTree, - addUpdateTask, - updateWorkspaceInTree, - readWorkspace -} from '@nrwl/workspace'; -import { - createSourceFile, - isImportDeclaration, - isStringLiteral, - ScriptTarget -} from 'typescript'; -import { - getSourceNodes, - ReplaceChange -} from '@nrwl/workspace/src/utils/ast-utils'; -import { relative } from 'path'; - -const ignore = require('ignore'); - -function addDependencies() { - return (host: Tree, context: SchematicContext) => { - const dependencies = readJsonInTree(host, 'package.json').dependencies; - const builders = new Set(); - const projects = readWorkspace(host).projects; - Object.values(projects) - .filter( - project => - typeof project === 'object' && project.hasOwnProperty('architect') - ) - .forEach(project => { - Object.values(project.architect).forEach(target => { - const [builderDependency] = target.builder.split(':'); - builders.add(builderDependency); - }); - }); - const newDependencies = {}; - const newDevDependencies = { - '@nrwl/workspace': '8.0.0' - }; - context.logger.info(`Adding @nrwl/workspace as a dependency`); - if (dependencies['@angular/core']) { - newDependencies['@nrwl/angular'] = '8.0.0'; - context.logger.info(`Adding @nrwl/angular as a dependency`); - } - if (dependencies['react']) { - newDevDependencies['@nrwl/react'] = '8.0.0'; - context.logger.info(`Adding @nrwl/react as a dependency`); - } - if (dependencies['@nestjs/core']) { - newDevDependencies['@nrwl/nest'] = '8.0.0'; - context.logger.info(`Adding @nrwl/nest as a dependency`); - } - if (dependencies.express) { - newDevDependencies['@nrwl/express'] = '8.0.0'; - newDevDependencies['@nrwl/node'] = '8.0.0'; - context.logger.info(`Adding @nrwl/express as a dependency`); - } - if (builders.has('@nrwl/web')) { - newDevDependencies['@nrwl/web'] = '8.0.0'; - context.logger.info(`Adding @nrwl/web as a dependency`); - } - if (builders.has('@nrwl/node')) { - newDevDependencies['@nrwl/node'] = '8.0.0'; - context.logger.info(`Adding @nrwl/node as a dependency`); - } - if (builders.has('@nrwl/jest')) { - newDevDependencies['@nrwl/jest'] = '8.0.0'; - context.logger.info(`Adding @nrwl/jest as a dependency`); - } - if (builders.has('@nrwl/cypress')) { - newDevDependencies['@nrwl/cypress'] = '8.0.0'; - context.logger.info(`Adding @nrwl/cypress as a dependency`); - } - return chain([addDepsToPackageJson(newDependencies, newDevDependencies)]); - }; -} - -const removeOldDependencies = updateJsonInTree( - 'package.json', - (json, context: SchematicContext) => { - json.dependencies = json.dependencies || {}; - json.devDependencies = json.devDependencies || {}; - delete json.dependencies['@nrwl/nx']; - delete json.devDependencies['@nrwl/nx']; - delete json.dependencies['@nrwl/schematics']; - delete json.devDependencies['@nrwl/schematics']; - delete json.dependencies['@nrwl/builders']; - delete json.devDependencies['@nrwl/builders']; - context.logger.info(`Removing @nrwl/schematics as a dependency`); - context.logger.info(`Removing @nrwl/builders as a dependency`); - context.logger.info(`Removing @nrwl/nx as a dependency`); - - return json; - } -); - -const updateUpdateScript = updateJsonInTree('package.json', json => { - json.scripts = json.scripts || {}; - json.scripts.update = 'ng update @nrwl/workspace'; - return json; -}); - -const updateBuilders = updateWorkspaceInTree(json => { - if (!json.projects) { - return json; - } - Object.entries(json.projects).forEach(([projectKey, project]) => { - if (!project.architect) { - return; - } - - Object.entries(project.architect).forEach(([targetKey, target]) => { - if (target.builder === '@nrwl/builders:jest') { - json.projects[projectKey].architect[targetKey].builder = - '@nrwl/jest:jest'; - } - if (target.builder === '@nrwl/builders:cypress') { - json.projects[projectKey].architect[targetKey].builder = - '@nrwl/cypress:cypress'; - } - if (target.builder === '@nrwl/builders:web-build') { - json.projects[projectKey].architect[targetKey].builder = - '@nrwl/web:build'; - } - if (target.builder === '@nrwl/builders:web-dev-server') { - json.projects[projectKey].architect[targetKey].builder = - '@nrwl/web:dev-server'; - } - if (target.builder === '@nrwl/builders:node-build') { - json.projects[projectKey].architect[targetKey].builder = - '@nrwl/node:build'; - } - if (target.builder === '@nrwl/builders:node-execute') { - json.projects[projectKey].architect[targetKey].builder = - '@nrwl/node:execute'; - } - if (target.builder === '@nrwl/builders:run-commands') { - json.projects[projectKey].architect[targetKey].builder = - '@nrwl/workspace:run-commands'; - } - }); - }); - return json; -}); - -const displayInformation = (host: Tree, context: SchematicContext) => { - context.logger.info(stripIndents` - Nx has been repackaged. We are installing and migrating your dependencies to the ones necessary. - - If you have workspace schematics, we tried to migrate your imports from "@nrwl/schematics" to "@nrwl/workspace" but your externalSchematics may be broken. - - Read this guide to see where to find familiar features: https://nx.dev/guides/nx7-to-nx8 - - This migration may take a few minutes. - `); -}; - -const updateNxModuleImports = (host: Tree) => { - let ig; - - if (host.exists('.gitignore')) { - ig = ignore(); - ig.add(host.read('.gitignore').toString()); - } - - host.visit(path => { - if (!path.endsWith('.ts')) { - return; - } - - if (ig && ig.ignores(relative('/', path))) { - return; - } - - const sourceFile = createSourceFile( - path, - host.read(path).toString(), - ScriptTarget.Latest, - true - ); - const changes = []; - sourceFile.statements.forEach(statement => { - if ( - isImportDeclaration(statement) && - isStringLiteral(statement.moduleSpecifier) - ) { - const nodeText = statement.moduleSpecifier.getText(sourceFile); - const modulePath = statement.moduleSpecifier - .getText(sourceFile) - .substr(1, nodeText.length - 2); - if (modulePath === '@nrwl/nx') { - changes.push( - new ReplaceChange( - path, - statement.moduleSpecifier.getStart(sourceFile), - nodeText, - `'@nrwl/angular'` - ) - ); - } - - if (modulePath === '@nrwl/nx/testing') { - changes.push( - new ReplaceChange( - path, - statement.moduleSpecifier.getStart(sourceFile), - nodeText, - `'@nrwl/angular/testing'` - ) - ); - } - - if (modulePath.startsWith('@nrwl/schematics')) { - changes.push( - new ReplaceChange( - path, - statement.moduleSpecifier.getStart(sourceFile), - nodeText, - nodeText.replace('@nrwl/schematics', '@nrwl/workspace') - ) - ); - } - } - }); - insert(host, path, changes); - }); -}; - -const updateJestPlugin = (host: Tree) => { - if (!host.exists('jest.config.js')) { - return host; - } - - const sourceFile = createSourceFile( - 'jest.config.js', - host.read('jest.config.js').toString(), - ScriptTarget.Latest, - true - ); - const changes = []; - - getSourceNodes(sourceFile).forEach(node => { - if (isStringLiteral(node)) { - const value = node - .getText(sourceFile) - .substr(1, node.getText(sourceFile).length - 2); - if (value === '@nrwl/builders/plugins/jest/resolver') { - changes.push( - new ReplaceChange( - 'jest.config.js', - node.getStart(sourceFile), - node.getText(sourceFile), - `'@nrwl/jest/plugins/resolver'` - ) - ); - } - } - }); - insert(host, 'jest.config.js', changes); -}; - -const updateTslintRules = updateJsonInTree('tslint.json', json => { - const { rulesDirectory } = json; - json.rulesDirectory = rulesDirectory.map(directory => { - return directory === 'node_modules/@nrwl/schematics/src/tslint' - ? 'node_modules/@nrwl/workspace/src/tslint' - : directory; - }); - return json; -}); - -const updateDefaultCollection = (host: Tree, context: SchematicContext) => { - const { dependencies, devDependencies } = readJsonInTree( - host, - 'package.json' - ); - - return updateWorkspaceInTree(json => { - json.cli = json.cli || {}; - if (dependencies['@nrwl/angular']) { - json.cli.defaultCollection = '@nrwl/angular'; - } else if (devDependencies['@nrwl/react']) { - json.cli.defaultCollection = '@nrwl/react'; - } else if (devDependencies['@nrwl/nest']) { - json.cli.defaultCollection = '@nrwl/nest'; - } else if (devDependencies['@nrwl/express']) { - json.cli.defaultCollection = '@nrwl/express'; - } else if (devDependencies['@nrwl/web']) { - json.cli.defaultCollection = '@nrwl/web'; - } else if (devDependencies['@nrwl/node']) { - json.cli.defaultCollection = '@nrwl/node'; - } else { - json.cli.defaultCollection = '@nrwl/workspace'; - } - context.logger.info( - `Default collection is now set to ${json.cli.defaultCollection}` - ); - return json; - }); -}; - -const setRootDirAndUpdateOurDir = (host: Tree) => { - let ig; - - if (host.exists('.gitignore')) { - ig = ignore(); - ig.add(host.read('.gitignore').toString()); - } - - host.visit(path => { - if (!path.endsWith('.json')) { - return; - } - - if (ig && ig.ignores(relative('/', path))) { - return; - } - - const json = host.read(path).toString(); - const match = json.match(/"outDir"\s*:\s*"([^"]+)"/); - if (match) { - const outParts = match[1].split('out-tsc'); - if (outParts.length > 1) { - const updatedJson = json.replace( - /"outDir"\s*:\s*"([^"]+)"/, - `"outDir": "${outParts[0]}out-tsc"` - ); - host.overwrite(path, updatedJson); - } - } - }); - - updateJsonInTree('tsconfig.json', json => { - json.compilerOptions = json.compilerOptions || {}; - json.compilerOptions.rootDir = '.'; - return json; - })(host, null); -}; - -export const runAngularMigrations: Rule = ( - host: Tree, - context: SchematicContext -) => { - const { dependencies } = readJsonInTree(host, 'package.json'); - - return chain([ - addUpdateTask('@angular/cli', '8.0.1'), - ...(dependencies['@angular/core'] - ? [addUpdateTask('@angular/core', '8.0.0')] - : []) - ]); -}; - -const updateNestDependencies = updateJsonInTree('package.json', json => { - json.dependencies = json.dependencies || {}; - json.devDependencies = json.devDependencies || {}; - - if (!json.devDependencies['@nrwl/nest']) { - return json; - } - - const nestFrameworkVersion = '^6.2.4'; - - json.dependencies = { - ...json.dependencies, - '@nestjs/common': nestFrameworkVersion, - '@nestjs/core': nestFrameworkVersion, - '@nestjs/platform-express': nestFrameworkVersion, - 'reflect-metadata': '^0.1.12' - }; - - json.devDependencies = { - ...json.devDependencies, - '@nestjs/schematics': '^6.3.0', - '@nestjs/testing': nestFrameworkVersion - }; - - return json; -}); - -export default function(): Rule { - return chain([ - displayInformation, - runAngularMigrations, - removeOldDependencies, - updateUpdateScript, - updateBuilders, - updateJestPlugin, - updateNxModuleImports, - updateTslintRules, - addDependencies(), - updateNestDependencies, - updateDefaultCollection, - setRootDirAndUpdateOurDir, - formatFiles() - ]); -} diff --git a/packages/schematics/package.json b/packages/schematics/package.json deleted file mode 100644 index e7d708621b54d..0000000000000 --- a/packages/schematics/package.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "name": "@nrwl/schematics", - "version": "0.0.2", - "description": "Extensible Dev Tools for Monorepos: Schematics", - "repository": { - "type": "git", - "url": "git+https://github.com/nrwl/nx.git" - }, - "keywords": [ - "Monorepo", - "Angular", - "React", - "Web", - "Node", - "Nest", - "Jest", - "Cypress", - "CLI" - ], - "main": "index.js", - "types": "index.d.js", - "author": "Victor Savkin", - "license": "MIT", - "bugs": { - "url": "https://github.com/nrwl/nx/issues" - }, - "homepage": "https://nx.dev", - "schematics": "./src/collection.json", - "ng-update": { - "requirements": {}, - "migrations": "./migrations/migrations.json" - }, - "dependencies": { - "@nrwl/workspace": "*", - "@nrwl/angular": "*", - "app-root-path": "^2.0.1", - "cosmiconfig": "4.0.0", - "fs-extra": "6.0.0", - "graphviz": "0.0.8", - "ignore": "5.0.4", - "opn": "^5.3.0", - "rxjs": "6.5.3", - "semver": "5.4.1", - "strip-json-comments": "2.0.1", - "tmp": "0.0.33", - "viz.js": "^1.8.1", - "yargs-parser": "10.0.0", - "yargs": "^11.0.0", - "prettier": "1.16.4" - } -} diff --git a/packages/schematics/src/README.md b/packages/schematics/src/README.md deleted file mode 100644 index ac78eeff33861..0000000000000 --- a/packages/schematics/src/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# @nrwl/schematics - -The sources for this package are in the main [nrwl/nx](https://github.com/nrwl/nx) repo. Please file issues and pull requests against that repo. - -License: MIT diff --git a/packages/schematics/src/collection.json b/packages/schematics/src/collection.json deleted file mode 100644 index 7066e7e02c1a1..0000000000000 --- a/packages/schematics/src/collection.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "nx", - "version": "0.1", - "extends": "@nrwl/angular", - "schematics": { - "ng-add": { - "factory": "./schematics/ng-add/ng-add", - "schema": "./schematics/ng-add/schema.json", - "description": "Convert an existing CLI project into an Nx Workspace", - "hidden": true - } - } -} diff --git a/packages/schematics/src/migrator/migrator.ts b/packages/schematics/src/migrator/migrator.ts deleted file mode 100644 index 5b1edd6a353a2..0000000000000 --- a/packages/schematics/src/migrator/migrator.ts +++ /dev/null @@ -1,84 +0,0 @@ -import * as fs from 'fs'; -import * as path from 'path'; - -import { updateJsonFile, readWorkspaceConfigPath } from '@nrwl/workspace'; - -type Migration = { description: string; run(): void }; -type MigrationName = { name: string; migration: Migration }; - -const allMigrations = fs - .readdirSync(path.join(__dirname, '/../../migrations')) - .filter(f => f.endsWith('.js') && !f.endsWith('.d.js')) - .map(file => ({ - migration: require(`../../migrations/${file}`).default, - name: path.parse(file).name - })); - -const latestMigration = readLatestMigration(); -const migrationsToRun = calculateMigrationsToRun( - allMigrations, - latestMigration -); - -if (migrationsToRun.length === 0) { - console.log('No migrations to run'); - process.exit(0); -} - -printMigrationsNames(latestMigration, migrationsToRun); -runMigrations(migrationsToRun); -updateLatestMigration(); - -console.log('All migrations run successfully'); - -function readLatestMigration(): string { - const angularCli = readWorkspaceConfigPath(); - return angularCli.project.latestMigration; -} - -function calculateMigrationsToRun( - migrations: MigrationName[], - latestMigration: string -) { - const startingWith = latestMigration - ? migrations.findIndex(item => item.name === latestMigration) + 1 - : 0; - return migrations.slice(startingWith); -} - -function printMigrationsNames( - latestMigration: string, - migrations: MigrationName[] -): void { - console.log( - `Nx will run the following migrations (after ${latestMigration}):` - ); - migrations.forEach(m => { - console.log(`- ${m.name}`); - }); - console.log('---------------------------------------------'); -} - -function runMigrations(migrations: MigrationName[]): void { - migrations.forEach(m => { - try { - console.log(`Running ${m.name}`); - console.log(m.migration.description); - m.migration.run(); - console.log('---------------------------------------------'); - } catch (e) { - console.error(`Migration ${m.name} failed`); - console.error(e); - console.error(`Please run 'git checkout .'`); - process.exit(1); - } - }); -} - -function updateLatestMigration(): void { - // we must reread .angular-cli.json because some of the migrations could have modified it - updateJsonFile('.angular-cli.json', angularCliJson => { - angularCliJson.project.latestMigration = - migrationsToRun[migrationsToRun.length - 1].name; - }); -} diff --git a/packages/schematics/src/schematics/ng-add/ng-add.ts b/packages/schematics/src/schematics/ng-add/ng-add.ts deleted file mode 100644 index fc40506ce06d5..0000000000000 --- a/packages/schematics/src/schematics/ng-add/ng-add.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { externalSchematic } from '@angular-devkit/schematics'; - -interface Schema { - npmScope: string; - name: string; - skipInstall: boolean; -} - -export default function(schema: Schema) { - return externalSchematic('@nrwl/workspace', 'ng-add', schema); -} diff --git a/packages/schematics/src/schematics/ng-add/schema.json b/packages/schematics/src/schematics/ng-add/schema.json deleted file mode 100644 index eb29753b01555..0000000000000 --- a/packages/schematics/src/schematics/ng-add/schema.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema", - "id": "NxSchematicsAdd", - "title": "Add Nx Schematics to Project and Convert Workspace", - "description": "NOTE: Does not work in the --dry-run mode", - "type": "object", - "properties": { - "npmScope": { - "type": "string", - "description": "Npm scope for importing libs." - }, - "skipInstall": { - "type": "boolean", - "description": "Skip installing after adding @nrwl/workspace", - "default": false - }, - "name": { - "type": "string", - "description": "Project name.", - "$default": { - "$source": "projectName" - } - } - } -} diff --git a/packages/schematics/testing.ts b/packages/schematics/testing.ts deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/scripts/build.sh b/scripts/build.sh index db2d5c37f936d..6e0a4b87c000a 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -39,8 +39,6 @@ cp packages/react/typings/* build/packages/react/typings rm -rf build/packages/nx/dist rm -rf build/packages/install rm -rf build/packages/nx/spec -cp README.md build/packages/builders -cp README.md build/packages/schematics cp README.md build/packages/nx cp README.md build/packages/create-nx-workspace cp README.md build/packages/create-nx-plugin @@ -62,8 +60,6 @@ cp README.md build/packages/linter cp README.md build/packages/bazel cp README.md build/packages/nx-plugin -cp LICENSE build/packages/builders -cp LICENSE build/packages/schematics cp LICENSE build/packages/nx cp LICENSE build/packages/create-nx-workspace cp LICENSE build/packages/create-nx-plugin diff --git a/scripts/nx-release.js b/scripts/nx-release.js index 6751b7e73a16b..179b148c14e23 100755 --- a/scripts/nx-release.js +++ b/scripts/nx-release.js @@ -149,7 +149,6 @@ const options = { */ pkgFiles: [ 'package.json', - 'build/npm/schematics/package.json', 'build/npm/create-nx-workspace/package.json', 'build/npm/create-nx-plugin/package.json', 'build/npm/jest/package.json', diff --git a/scripts/package.sh b/scripts/package.sh index 91eb12487cc9e..85968b6e40a29 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -18,7 +18,7 @@ cd build/packages if [[ "$OSTYPE" == "darwin"* ]]; then sed -i "" "s|exports.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" {react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace}/src/utils/versions.js - sed -i "" "s|\*|$NX_VERSION|g" {schematics,react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace,cli,linter,bazel,tao,eslint-plugin-nx,create-nx-workspace,create-nx-plugin,nx-plugin}/package.json + sed -i "" "s|\*|$NX_VERSION|g" {react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace,cli,linter,bazel,tao,eslint-plugin-nx,create-nx-workspace,create-nx-plugin,nx-plugin}/package.json sed -i "" "s|NX_VERSION|$NX_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js sed -i "" "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js sed -i "" "s|TYPESCRIPT_VERSION|$TYPESCRIPT_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js @@ -29,7 +29,7 @@ if [[ "$OSTYPE" == "darwin"* ]]; then sed -i "" "s|PRETTIER_VERSION|$PRETTIER_VERSION|g" create-nx-plugin/bin/create-nx-plugin.js else sed -i "s|exports.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" {react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace}/src/utils/versions.js - sed -i "s|\*|$NX_VERSION|g" {schematics,react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace,cli,linter,bazel,tao,eslint-plugin-nx,create-nx-workspace,create-nx-plugin,nx-plugin}/package.json + sed -i "s|\*|$NX_VERSION|g" {react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace,cli,linter,bazel,tao,eslint-plugin-nx,create-nx-workspace,create-nx-plugin,nx-plugin}/package.json sed -i "s|NX_VERSION|$NX_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js sed -i "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js sed -i "s|TYPESCRIPT_VERSION|$TYPESCRIPT_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js @@ -42,9 +42,9 @@ fi if [[ $NX_VERSION == "*" ]]; then if [[ "$OSTYPE" == "darwin"* ]]; then - sed -E -i "" "s|\"@nrwl\/([^\"]+)\": \"\\*\"|\"@nrwl\/\1\": \"file:$PWD\/\1\"|" {schematics,jest,web,react,next,node,express,nest,cypress,storybook,angular,workspace,linter,bazel,cli,tao,eslint-plugin-nx,create-nx-workspace,create-nx-plugin,nx-plugin}/package.json + sed -E -i "" "s|\"@nrwl\/([^\"]+)\": \"\\*\"|\"@nrwl\/\1\": \"file:$PWD\/\1\"|" {jest,web,react,next,node,express,nest,cypress,storybook,angular,workspace,linter,bazel,cli,tao,eslint-plugin-nx,create-nx-workspace,create-nx-plugin,nx-plugin}/package.json else echo $PWD - sed -E -i "s|\"@nrwl\/([^\"]+)\": \"\\*\"|\"@nrwl\/\1\": \"file:$PWD\/\1\"|" {schematics,jest,web,react,next,node,express,nest,cypress,storybook,angular,workspace,linter,bazel,cli,tao,eslint-plugin-nx,create-nx-workspace,create-nx-plugin,nx-plugin}/package.json + sed -E -i "s|\"@nrwl\/([^\"]+)\": \"\\*\"|\"@nrwl\/\1\": \"file:$PWD\/\1\"|" {jest,web,react,next,node,express,nest,cypress,storybook,angular,workspace,linter,bazel,cli,tao,eslint-plugin-nx,create-nx-workspace,create-nx-plugin,nx-plugin}/package.json fi fi diff --git a/scripts/test.sh b/scripts/test.sh index b20758056b44c..9afc3eb971e94 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -3,5 +3,5 @@ if [ -n "$1" ]; then jest --maxWorkers=1 ./build/packages/$1.spec.js else - jest --maxWorkers=1 ./build/packages/{schematics,bazel,builders,react,jest,web,node,express,nest,cypress,storybook,angular,workspace,tao,eslint-plugin-nx,next,nx-plugin} --passWithNoTests + jest --maxWorkers=1 ./build/packages/{bazel,react,jest,web,node,express,nest,cypress,storybook,angular,workspace,tao,eslint-plugin-nx,next,nx-plugin} --passWithNoTests fi