cleanup(angular): remove remaining angular cli helpers and set version target for existing deprecations helpers (#10791)

This commit is contained in:
Leosvel Pérez Espinosa 2022-06-17 18:00:42 +01:00 committed by GitHub
parent 6bca146ebf
commit e507d7b4cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 90 deletions

View File

@ -1,13 +1,6 @@
import { Tree } from '@angular-devkit/schematics'; import { readJson, writeJson } from '@nrwl/devkit';
import { createEmptyWorkspace } from '@nrwl/workspace/testing'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { runMigration } from '../../utils/testing'; import updateNgccPostinstall from './update-ngcc-postinstall';
function createAngularCLIPoweredWorkspace() {
const tree = createEmptyWorkspace(Tree.empty());
tree.delete('workspace.json');
tree.create('angular.json', '{}');
return tree;
}
describe('Remove ngcc flags from postinstall script', () => { describe('Remove ngcc flags from postinstall script', () => {
[ [
@ -33,21 +26,17 @@ describe('Remove ngcc flags from postinstall script', () => {
}, },
].forEach((testEntry) => { ].forEach((testEntry) => {
it(`should adjust ngcc for: "${testEntry.test}"`, async () => { 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( await updateNgccPostinstall(tree);
'/package.json',
JSON.stringify({
scripts: {
postinstall: testEntry.test,
},
})
);
const result = await runMigration('update-ngcc-postinstall', {}, tree); const { scripts } = readJson(tree, 'package.json');
expect(scripts.postinstall).toEqual(testEntry.expected);
const packageJson = JSON.parse(result.read('/package.json').toString());
expect(packageJson.scripts.postinstall).toEqual(testEntry.expected);
}); });
}); });
}); });

View File

@ -1,24 +1,22 @@
import { chain, SchematicContext, Tree } from '@angular-devkit/schematics'; import type { Tree } from '@nrwl/devkit';
import { updateJsonInTree } from '@nrwl/workspace'; import { formatFiles, updateJson } from '@nrwl/devkit';
import { formatFiles } from '@nrwl/workspace';
const udpateNgccPostinstallScript = (host: Tree, context: SchematicContext) => { export default async function (tree: Tree) {
updateJsonInTree('package.json', (json) => { let shouldFormat = false;
if (
json.scripts && updateJson(tree, 'package.json', (json) => {
json.scripts.postinstall && if (json.scripts?.postinstall?.includes('ngcc')) {
json.scripts.postinstall.includes('ngcc')
) {
// if exists, add execution of this script
json.scripts.postinstall = json.scripts.postinstall.replace( json.scripts.postinstall = json.scripts.postinstall.replace(
/(.*)(ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points)(.*)/, /(.*)(ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points)(.*)/,
'$1ngcc --properties es2015 browser module main$3' '$1ngcc --properties es2015 browser module main$3'
); );
shouldFormat = true;
} }
return json;
})(host, context);
};
export default function () { return json;
return chain([udpateNgccPostinstallScript, formatFiles()]); });
if (shouldFormat) {
await formatFiles(tree);
}
} }

View File

@ -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<SchemaOptions extends object = any>(
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();
}

View File

@ -6,19 +6,19 @@ import {
} from 'jasmine-marbles'; } 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; 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; 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; 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; export const time = rxjsMarblesTime;