Skip to content

refactor(schematics): remove ng-add skipPackageJson option #13233

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/cdk/schematics/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
export * from './ast';
export * from './build-component';
export * from './get-project';
export * from './package-json';
export * from './parse5-element';
export * from './project-main-file';
export * from './project-style-file';
Expand Down
11 changes: 0 additions & 11 deletions src/lib/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,6 @@ describe('ng-add schematic', () => {
expect(runner.tasks.some(task => task.name === 'run-schematic')).toBe(true);
});

it('should not set up dependencies if skipPackageJson is specified', () => {
const tree = runner.runSchematic('ng-add', {skipPackageJson: true}, appTree);
const packageJson = JSON.parse(getFileContent(tree, '/package.json'));
const dependencies = packageJson.dependencies;

expect(dependencies['@angular/material']).toBeUndefined();
expect(dependencies['@angular/cdk']).toBeUndefined();

expect(runner.tasks.some(task => task.name === 'run-schematic')).toBe(true);
});

it('should add hammerjs import to project main file', () => {
const tree = runner.runSchematic('ng-add-setup-project', {}, appTree);
const fileContent = getFileContent(tree, '/projects/material/src/main.ts');
Expand Down
40 changes: 16 additions & 24 deletions src/lib/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Rule, Tree, SchematicContext, TaskId} from '@angular-devkit/schematics';
import {Rule, SchematicContext, Tree} from '@angular-devkit/schematics';
import {NodePackageInstallTask, RunSchematicTask} from '@angular-devkit/schematics/tasks';
import {addPackageToPackageJson, getPackageVersionFromPackageJson} from './package-json';
import {addPackageToPackageJson, getPackageVersionFromPackageJson} from './package-config';
import {Schema} from './schema';
import {hammerjsVersion, materialVersion, requiredAngularVersionRange} from './version-names';

Expand All @@ -21,32 +21,24 @@ import {hammerjsVersion, materialVersion, requiredAngularVersionRange} from './v
*/
export default function(options: Schema): Rule {
return (host: Tree, context: SchematicContext) => {
// Since the Angular Material schematics depend on the schematic utility functions from the
// CDK, we need to install the CDK before loading the schematic files that import from the CDK.
let installTaskId: TaskId;

if (!options.skipPackageJson) {
// Version tag of the `@angular/core` dependency that has been loaded from the `package.json`
// of the CLI project. This tag should be preferred because all Angular dependencies should
// have the same version tag if possible.
const ngCoreVersionTag = getPackageVersionFromPackageJson(host, '@angular/core');

addPackageToPackageJson(host, '@angular/cdk', `^${materialVersion}`);
addPackageToPackageJson(host, '@angular/material', `^${materialVersion}`);
addPackageToPackageJson(host, '@angular/animations',
ngCoreVersionTag || requiredAngularVersionRange);
// Version tag of the `@angular/core` dependency that has been loaded from the `package.json`
// of the CLI project. This tag should be preferred because all Angular dependencies should
// have the same version tag if possible.
const ngCoreVersionTag = getPackageVersionFromPackageJson(host, '@angular/core');

if (options.gestures) {
addPackageToPackageJson(host, 'hammerjs', hammerjsVersion);
}
addPackageToPackageJson(host, '@angular/cdk', `^${materialVersion}`);
addPackageToPackageJson(host, '@angular/material', `^${materialVersion}`);
addPackageToPackageJson(host, '@angular/animations',
ngCoreVersionTag || requiredAngularVersionRange);

installTaskId = context.addTask(new NodePackageInstallTask());
} else {
installTaskId = context.addTask(new NodePackageInstallTask({
packageName: `@angular/cdk@^${materialVersion}`
}));
if (options.gestures) {
addPackageToPackageJson(host, 'hammerjs', hammerjsVersion);
}

// Since the Angular Material schematics depend on the schematic utility functions from the
// CDK, we need to install the CDK before loading the schematic files that import from the CDK.
const installTaskId = context.addTask(new NodePackageInstallTask());

context.addTask(new RunSchematicTask('ng-add-setup-project', options), [installTaskId]);
};
}
61 changes: 0 additions & 61 deletions src/lib/schematics/ng-add/package-json.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/lib/schematics/ng-add/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
"$source": "projectName"
}
},
"skipPackageJson": {
"type": "boolean",
"default": false,
"description": "Do not add materials dependencies to package.json (e.g., --skipPackageJson)"
},
"theme": {
"enum": ["indigo-pink", "deeppurple-amber", "pink-bluegrey", "purple-green", "custom"],
"default": "indigo-pink",
Expand Down
3 changes: 0 additions & 3 deletions src/lib/schematics/ng-add/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ export interface Schema {
/** Name of the project to target. */
project: string;

/** Whether to skip package.json install. */
skipPackageJson: boolean;

/** Whether gesture support should be set up or not. */
gestures: boolean;

Expand Down