Skip to content

Commit

Permalink
fix(angular): do not use ngcc for new workspaces and projects #12386
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Oct 11, 2022
1 parent eedbd9d commit 19818ca
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 69 deletions.
5 changes: 0 additions & 5 deletions docs/generated/packages/angular.json
Expand Up @@ -718,11 +718,6 @@
"type": "boolean",
"default": false,
"description": "Do not add dependencies to `package.json`."
},
"skipPostInstall": {
"type": "boolean",
"default": false,
"description": "Do not add or append `ngcc` to the `postinstall` script in `package.json`."
}
},
"additionalProperties": false,
Expand Down
32 changes: 0 additions & 32 deletions packages/angular/src/generators/init/init.spec.ts
Expand Up @@ -4,7 +4,6 @@ import { Linter } from '@nrwl/linter';

import init from './init';
import { E2eTestRunner, UnitTestRunner } from '../../utils/test-runners';
import { Styles } from '../utils/types';

describe('init', () => {
let host: Tree;
Expand Down Expand Up @@ -42,37 +41,6 @@ describe('init', () => {
expect(devDependencies['codelyzer']).toBeUndefined();
});

it('should add a postinstall script for ngcc by default', async () => {
// ACT
await init(host, {
unitTestRunner: UnitTestRunner.Karma,
linter: Linter.EsLint,
skipFormat: false,
});

const packageJson = readJson(host, 'package.json');

// ASSERT
expect(packageJson.scripts.postinstall).toEqual(
'ngcc --properties es2020 browser module main'
);
});

it('should not add a postinstall script for ngcc if skipPostInstall=true', async () => {
// ACT
await init(host, {
unitTestRunner: UnitTestRunner.Karma,
linter: Linter.EsLint,
skipFormat: false,
skipPostInstall: true,
});

const packageJson = readJson(host, 'package.json');

// ASSERT
expect(packageJson?.scripts?.postinstall).toBeFalsy();
});

describe('--unit-test-runner', () => {
describe('karma', () => {
it('should add karma dependencies', async () => {
Expand Down
35 changes: 9 additions & 26 deletions packages/angular/src/generators/init/init.ts
@@ -1,29 +1,30 @@
import { cypressInitGenerator } from '@nrwl/cypress';
import { GeneratorCallback, logger, Tree } from '@nrwl/devkit';
import {
addDependenciesToPackageJson,
formatFiles,
GeneratorCallback,
logger,
readWorkspaceConfiguration,
updateJson,
Tree,
updateWorkspaceConfiguration,
} from '@nrwl/devkit';
import { jestInitGenerator } from '@nrwl/jest';
import { Linter } from '@nrwl/linter';
import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial';
import { E2eTestRunner, UnitTestRunner } from '../../utils/test-runners';
import {
angularVersion,
angularDevkitVersion,
angularVersion,
jasmineCoreVersion,
jasmineSpecReporterVersion,
jestPresetAngularVersion,
protractorVersion,
rxjsVersion,
tsNodeVersion,
tsLibVersion,
zoneJsVersion,
protractorVersion,
jasmineCoreVersion,
jasmineSpecReporterVersion,
tsNodeVersion,
typesJasmineVersion,
typesJasminewd2Version,
zoneJsVersion,
} from '../../utils/versions';
import { karmaGenerator } from '../karma/karma';
import { Schema } from './schema';
Expand All @@ -35,10 +36,6 @@ export async function angularInitGenerator(
const options = normalizeOptions(rawOptions);
setDefaults(host, options);

if (!options.skipPostInstall) {
addPostInstall(host);
}

const depsTask = !options.skipPackageJson
? updateDependencies(host)
: () => {};
Expand All @@ -59,7 +56,6 @@ function normalizeOptions(options: Schema): Required<Schema> {
linter: options.linter ?? Linter.EsLint,
skipFormat: options.skipFormat ?? false,
skipInstall: options.skipInstall ?? false,
skipPostInstall: options.skipPostInstall ?? false,
skipPackageJson: options.skipPackageJson ?? false,
style: options.style ?? 'css',
unitTestRunner: options.unitTestRunner ?? UnitTestRunner.Jest,
Expand Down Expand Up @@ -90,19 +86,6 @@ function setDefaults(host: Tree, options: Schema) {
updateWorkspaceConfiguration(host, workspace);
}

function addPostInstall(host: Tree) {
updateJson(host, 'package.json', (pkgJson) => {
pkgJson.scripts = pkgJson.scripts ?? {};
const command = 'ngcc --properties es2020 browser module main';
if (!pkgJson.scripts.postinstall) {
pkgJson.scripts.postinstall = command;
} else if (!pkgJson.scripts.postinstall.includes('ngcc')) {
pkgJson.scripts.postinstall = `${pkgJson.scripts.postinstall} && ${command}`;
}
return pkgJson;
});
}

function updateDependencies(host: Tree): GeneratorCallback {
return addDependenciesToPackageJson(
host,
Expand Down
1 change: 0 additions & 1 deletion packages/angular/src/generators/init/schema.d.ts
Expand Up @@ -10,5 +10,4 @@ export interface Schema {
style?: Styles;
linter?: Linter;
skipPackageJson?: boolean;
skipPostInstall?: boolean;
}
5 changes: 0 additions & 5 deletions packages/angular/src/generators/init/schema.json
Expand Up @@ -72,11 +72,6 @@
"type": "boolean",
"default": false,
"description": "Do not add dependencies to `package.json`."
},
"skipPostInstall": {
"type": "boolean",
"default": false,
"description": "Do not add or append `ngcc` to the `postinstall` script in `package.json`."
}
},
"additionalProperties": false
Expand Down

0 comments on commit 19818ca

Please sign in to comment.