diff --git a/packages/angular/src/migrations/update-12-0-0/update-ngcc-postinstall.spec.ts b/packages/angular/src/migrations/update-12-0-0/update-ngcc-postinstall.spec.ts index 8fd07607db..53888482a3 100644 --- a/packages/angular/src/migrations/update-12-0-0/update-ngcc-postinstall.spec.ts +++ b/packages/angular/src/migrations/update-12-0-0/update-ngcc-postinstall.spec.ts @@ -1,13 +1,6 @@ -import { Tree } from '@angular-devkit/schematics'; -import { createEmptyWorkspace } from '@nrwl/workspace/testing'; -import { runMigration } from '../../utils/testing'; - -function createAngularCLIPoweredWorkspace() { - const tree = createEmptyWorkspace(Tree.empty()); - tree.delete('workspace.json'); - tree.create('angular.json', '{}'); - return tree; -} +import { readJson, writeJson } from '@nrwl/devkit'; +import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; +import updateNgccPostinstall from './update-ngcc-postinstall'; describe('Remove ngcc flags from postinstall script', () => { [ @@ -33,21 +26,17 @@ describe('Remove ngcc flags from postinstall script', () => { }, ].forEach((testEntry) => { it(`should adjust ngcc for: "${testEntry.test}"`, async () => { - const tree = createAngularCLIPoweredWorkspace(); + const tree = createTreeWithEmptyWorkspace(2); + tree.delete('workspace.json'); + tree.write('angular.json', '{}'); + writeJson(tree, 'package.json', { + scripts: { postinstall: testEntry.test }, + }); - tree.overwrite( - '/package.json', - JSON.stringify({ - scripts: { - postinstall: testEntry.test, - }, - }) - ); + await updateNgccPostinstall(tree); - const result = await runMigration('update-ngcc-postinstall', {}, tree); - - const packageJson = JSON.parse(result.read('/package.json').toString()); - expect(packageJson.scripts.postinstall).toEqual(testEntry.expected); + const { scripts } = readJson(tree, 'package.json'); + expect(scripts.postinstall).toEqual(testEntry.expected); }); }); }); diff --git a/packages/angular/src/migrations/update-12-0-0/update-ngcc-postinstall.ts b/packages/angular/src/migrations/update-12-0-0/update-ngcc-postinstall.ts index db12abf3fb..8e4d199454 100644 --- a/packages/angular/src/migrations/update-12-0-0/update-ngcc-postinstall.ts +++ b/packages/angular/src/migrations/update-12-0-0/update-ngcc-postinstall.ts @@ -1,24 +1,22 @@ -import { chain, SchematicContext, Tree } from '@angular-devkit/schematics'; -import { updateJsonInTree } from '@nrwl/workspace'; -import { formatFiles } from '@nrwl/workspace'; +import type { Tree } from '@nrwl/devkit'; +import { formatFiles, updateJson } from '@nrwl/devkit'; -const udpateNgccPostinstallScript = (host: Tree, context: SchematicContext) => { - updateJsonInTree('package.json', (json) => { - if ( - json.scripts && - json.scripts.postinstall && - json.scripts.postinstall.includes('ngcc') - ) { - // if exists, add execution of this script +export default async function (tree: Tree) { + let shouldFormat = false; + + updateJson(tree, 'package.json', (json) => { + if (json.scripts?.postinstall?.includes('ngcc')) { json.scripts.postinstall = json.scripts.postinstall.replace( /(.*)(ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points)(.*)/, '$1ngcc --properties es2015 browser module main$3' ); + shouldFormat = true; } - return json; - })(host, context); -}; -export default function () { - return chain([udpateNgccPostinstallScript, formatFiles()]); + return json; + }); + + if (shouldFormat) { + await formatFiles(tree); + } } diff --git a/packages/angular/src/utils/testing.ts b/packages/angular/src/utils/testing.ts deleted file mode 100644 index d860a190ba..0000000000 --- a/packages/angular/src/utils/testing.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { join } from 'path'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; -import { Rule, Tree } from '@angular-devkit/schematics'; - -const testRunner = new SchematicTestRunner( - '@nrwl/angular', - join(__dirname, '../../generators.json') -); - -testRunner.registerCollection( - '@nrwl/jest', - join(__dirname, '../../../jest/generators.json') -); - -testRunner.registerCollection( - '@nrwl/workspace', - join(__dirname, '../../../workspace/generators.json') -); - -testRunner.registerCollection( - '@nrwl/cypress', - join(__dirname, '../../../cypress/generators.json') -); - -testRunner.registerCollection( - '@nrwl/storybook', - join(__dirname, '../../../storybook/generators.json') -); - -const migrationTestRunner = new SchematicTestRunner( - '@nrwl/workspace', - join(__dirname, '../../migrations.json') -); - -export function runMigration( - schematicName: string, - options: SchemaOptions, - tree: Tree -) { - return migrationTestRunner - .runSchematicAsync(schematicName, options, tree) - .toPromise(); -} - -export function callRule(rule: Rule, tree: Tree) { - return testRunner.callRule(rule, tree).toPromise(); -} diff --git a/packages/angular/testing/index.ts b/packages/angular/testing/index.ts index 078a269351..42b102d44a 100644 --- a/packages/angular/testing/index.ts +++ b/packages/angular/testing/index.ts @@ -6,19 +6,19 @@ import { } from 'jasmine-marbles'; /** - * @deprecated Import from 'jasmine-marbles' instead + * @deprecated Import from 'jasmine-marbles' instead. Will be removed in Nx v15. */ export const cold = rxjsMarblesCold; /** - * @deprecated Import from 'jasmine-marbles' instead + * @deprecated Import from 'jasmine-marbles' instead. Will be removed in Nx v15. */ export const hot = rxjsMarblesHot; /** - * @deprecated Import from 'jasmine-marbles' instead + * @deprecated Import from 'jasmine-marbles' instead. Will be removed in Nx v15. */ export const getTestScheduler = rxjsMarblesTestScheduler; /** - * @deprecated Import from 'jasmine-marbles' instead + * @deprecated Import from 'jasmine-marbles' instead. Will be removed in Nx v15. */ export const time = rxjsMarblesTime;