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 { 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);
});
});
});

View File

@ -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);
}
}

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';
/**
* @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;