Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(angular): add flag for skipping the postinstall script in relevant generators #10208

Merged
25 changes: 25 additions & 0 deletions docs/generated/packages/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@
"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`."
},
"unitTestRunner": {
"type": "string",
"enum": ["karma", "jest", "none"],
Expand Down Expand Up @@ -636,6 +641,11 @@
"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 Expand Up @@ -769,6 +779,11 @@
"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`."
},
"skipTsConfig": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -1217,6 +1232,11 @@
"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`."
},
"unitTestRunner": {
"type": "string",
"enum": ["karma", "jest", "none"],
Expand Down Expand Up @@ -1341,6 +1361,11 @@
"type": "boolean",
"default": false,
"description": "Do not add dependencies to `package.json`. NOTE: only used if running the generator in an Nx workspace."
},
"skipPostInstall": {
"type": "boolean",
"default": false,
"description": "Do not add or append `ngcc` to the `postinstall` script in `package.json`. NOTE: only used if running the generator in an Nx workspace."
}
},
"additionalProperties": false,
Expand Down
1 change: 1 addition & 0 deletions packages/angular/src/generators/application/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ export interface Schema {
host?: string;
setParserOptionsProject?: boolean;
skipPackageJson?: boolean;
skipPostInstall?: boolean;
federationType?: 'static' | 'dynamic';
}
5 changes: 5 additions & 0 deletions packages/angular/src/generators/application/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@
"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`."
},
"unitTestRunner": {
"type": "string",
"enum": ["karma", "jest", "none"],
Expand Down
1 change: 1 addition & 0 deletions packages/angular/src/generators/host/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface Schema {
dynamic?: boolean;
setParserOptionsProject?: boolean;
skipPackageJson?: boolean;
skipPostInstall?: boolean;
addTailwind?: boolean;
prefix?: string;
style?: Styles;
Expand Down
5 changes: 5 additions & 0 deletions packages/angular/src/generators/host/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@
"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`."
},
"unitTestRunner": {
"type": "string",
"enum": ["karma", "jest", "none"],
Expand Down
17 changes: 16 additions & 1 deletion packages/angular/src/generators/init/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('init', () => {
expect(devDependencies['codelyzer']).toBeUndefined();
});

it('should add a postinstall script for ngcc', async () => {
it('should add a postinstall script for ngcc by default', async () => {
// ACT
await init(host, {
unitTestRunner: UnitTestRunner.Karma,
Expand All @@ -58,6 +58,21 @@ describe('init', () => {
);
});

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
6 changes: 5 additions & 1 deletion packages/angular/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export async function angularInitGenerator(
): Promise<GeneratorCallback> {
const options = normalizeOptions(rawOptions);
setDefaults(host, options);
addPostInstall(host);

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

const depsTask = !options.skipPackageJson
? updateDependencies(host)
Expand All @@ -49,6 +52,7 @@ 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
1 change: 1 addition & 0 deletions packages/angular/src/generators/init/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export interface Schema {
style?: Styles;
linter?: Exclude<Linter, Linter.TsLint>;
skipPackageJson?: boolean;
skipPostInstall?: boolean;
}
5 changes: 5 additions & 0 deletions packages/angular/src/generators/init/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
"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
1 change: 1 addition & 0 deletions packages/angular/src/generators/library/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ export interface Schema {
setParserOptionsProject?: boolean;
skipModule?: boolean;
skipPackageJson?: boolean;
skipPostInstall?: boolean;
}
5 changes: 5 additions & 0 deletions packages/angular/src/generators/library/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
"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`."
},
"skipTsConfig": {
"type": "boolean",
"default": false,
Expand Down
1 change: 1 addition & 0 deletions packages/angular/src/generators/ng-add/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface GeneratorOptions {
e2eTestRunner?: E2eTestRunner;
skipFormat?: boolean;
skipInstall?: boolean;
skipPostInstall?: boolean;
style?: Styles;
linter?: Exclude<Linter, Linter.TsLint>;
skipPackageJson?: boolean;
Expand Down
5 changes: 5 additions & 0 deletions packages/angular/src/generators/ng-add/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
"type": "boolean",
"default": false,
"description": "Do not add dependencies to `package.json`. NOTE: only used if running the generator in an Nx workspace."
},
"skipPostInstall": {
"type": "boolean",
"default": false,
"description": "Do not add or append `ngcc` to the `postinstall` script in `package.json`. NOTE: only used if running the generator in an Nx workspace."
}
},
"additionalProperties": false
Expand Down