Skip to content

Commit

Permalink
Fix ng add crash with Angular CLI 11.1
Browse files Browse the repository at this point in the history
Updated dev dependencies to test that everything works as expected.

Fixes #291
  • Loading branch information
devoto13 committed Feb 3, 2021
1 parent 38c999e commit b53107d
Show file tree
Hide file tree
Showing 7 changed files with 1,595 additions and 1,306 deletions.
53 changes: 46 additions & 7 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

Large diffs are not rendered by default.

55 changes: 0 additions & 55 deletions .yarn/releases/yarn-2.3.1.cjs

This file was deleted.

55 changes: 55 additions & 0 deletions .yarn/releases/yarn-2.4.0.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"

yarnPath: .yarn/releases/yarn-2.3.1.cjs
yarnPath: .yarn/releases/yarn-2.4.0.cjs
44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,41 @@
},
"homepage": "https://github.com/FortAwesome/angular-fontawesome",
"devDependencies": {
"@angular-devkit/build-angular": "~0.1100.0",
"@angular-devkit/core": "~11.0.0",
"@angular-devkit/schematics": "~11.0.0",
"@angular/cli": "~11.0.0",
"@angular/common": "~11.0.0",
"@angular/compiler": "~11.0.0",
"@angular/compiler-cli": "~11.0.0",
"@angular/core": "~11.0.0",
"@angular/language-service": "~11.0.0",
"@angular/platform-browser": "~11.0.0",
"@angular/platform-browser-dynamic": "~11.0.0",
"@angular-devkit/build-angular": "~0.1101.2",
"@angular-devkit/core": "~11.1.2",
"@angular-devkit/schematics": "~11.1.2",
"@angular/cli": "~11.1.2",
"@angular/common": "~11.1.1",
"@angular/compiler": "~11.1.1",
"@angular/compiler-cli": "~11.1.1",
"@angular/core": "~11.1.1",
"@angular/language-service": "~11.1.1",
"@angular/platform-browser": "~11.1.1",
"@angular/platform-browser-dynamic": "~11.1.1",
"@fortawesome/fontawesome-svg-core": "^1.2.32",
"@fortawesome/free-regular-svg-icons": "^5.15.1",
"@fortawesome/free-solid-svg-icons": "^5.15.1",
"@types/jasmine": "~3.6.1",
"@types/node": "~14.14.7",
"@types/jasmine": "~3.6.3",
"@types/node": "~14.14.22",
"codelyzer": "^6.0.1",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~6.0.0",
"karma": "~5.1.0",
"karma": "~5.2.3",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-coverage-istanbul-reporter": "~3.0.3",
"karma-jasmine": "~4.0.1",
"karma-jasmine-html-reporter": "^1.5.0",
"ng-packagr": "^11.0.1",
"prettier": "2.1.2",
"karma-jasmine-html-reporter": "^1.5.4",
"ng-packagr": "^11.1.3",
"prettier": "2.2.1",
"protractor": "~7.0.0",
"rxjs": "^6.6.3",
"ts-node": "~9.0.0",
"ts-node": "~9.1.1",
"tslint": "~6.1.3",
"typescript": "~4.0.5",
"zone.js": "~0.10.3"
"typescript": "~4.1.3",
"zone.js": "~0.11.3"
},
"dependencies": {
"tslib": "^2.0.3"
"tslib": "^2.1.0"
},
"keywords": [
"angular",
Expand Down
33 changes: 16 additions & 17 deletions projects/schematics/src/ng-add/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { workspaces } from '@angular-devkit/core';
import { chain, Rule, SchematicContext, SchematicsException, Tree } from '@angular-devkit/schematics';
import { NodePackageInstallTask, TslintFixTask } from '@angular-devkit/schematics/tasks';
import {
Expand All @@ -6,10 +7,9 @@ import {
} from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript';
import { addImportToModule } from '@schematics/angular/utility/ast-utils';
import { InsertChange } from '@schematics/angular/utility/change';
import { getWorkspace } from '@schematics/angular/utility/config';
import { addPackageJsonDependency, NodeDependencyType } from '@schematics/angular/utility/dependencies';
import { getAppModulePath } from '@schematics/angular/utility/ng-ast-utils';
import { WorkspaceProject } from '@schematics/angular/utility/workspace-models';
import { getWorkspace } from '@schematics/angular/utility/workspace';
import { Schema } from './schema';
import { angularFontawesomeVersion, iconPackVersion, svgCoreVersion } from './versions';

Expand Down Expand Up @@ -41,16 +41,20 @@ export default function (options: Schema): Rule {

return tree;
},
addModule(options.project),
addModule(options),
]);
}

function addModule(projectName?: string): Rule {
return (host: Tree, context: SchematicContext) => {
const workspace = getWorkspace(host);
const project = workspace.projects[projectName || workspace.defaultProject!];
function addModule(options: Schema): Rule {
return async (host: Tree, context: SchematicContext) => {
const workspace = await getWorkspace(host);
const projectName = options.project ?? (workspace.extensions.defaultProject as string);
const project = workspace.projects.get(projectName);
if (project == null) {
throw new SchematicsException(`Project with name ${projectName} does not exist.`);
}
const buildOptions = getProjectTargetOptions(project, 'build');
const modulePath = getAppModulePath(host, buildOptions.main);
const modulePath = getAppModulePath(host, buildOptions.main as string);
const moduleSource = getSourceFile(host, modulePath);
const changes = addImportToModule(
moduleSource,
Expand All @@ -73,8 +77,6 @@ function addModule(projectName?: string): Rule {
} catch (err) {
context.logger.warn('Formatting was skipped because tslint is not installed.');
}

return host;
};
}

Expand All @@ -87,13 +89,10 @@ function getSourceFile(host: Tree, path: string) {
return createSourceFile(path, content, ScriptTarget.Latest, true);
}

export function getProjectTargetOptions(project: WorkspaceProject, buildTarget: string) {
if (project.targets && project.targets[buildTarget] && project.targets[buildTarget].options) {
return project.targets[buildTarget].options;
}

if (project.architect && project.architect[buildTarget] && project.architect[buildTarget].options) {
return project.architect[buildTarget].options;
export function getProjectTargetOptions(project: workspaces.ProjectDefinition, buildTarget: string) {
const buildTargetObject = project.targets.get(buildTarget);
if (buildTargetObject && buildTargetObject.options) {
return buildTargetObject.options;
}

throw new SchematicsException(`Cannot determine project target configuration for: ${buildTarget}.`);
Expand Down
Loading

0 comments on commit b53107d

Please sign in to comment.