Skip to content

Commit

Permalink
feat(angular): add flag for skipping the postinstall script in releva…
Browse files Browse the repository at this point in the history
…nt generators (#10208)
  • Loading branch information
stianmorsund committed May 9, 2022
1 parent b513271 commit eb4243b
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 2 deletions.
25 changes: 25 additions & 0 deletions docs/generated/packages/angular.json
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
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
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
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
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
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
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
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
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
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
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
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
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

1 comment on commit eb4243b

@vercel
Copy link

@vercel vercel bot commented on eb4243b May 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app

Please sign in to comment.