Skip to content

Commit 169dc9e

Browse files
sumitaroraBrocco
authored andcommitted
fix(@angular/cli): fix package name fetching from package.json
1 parent 7bd4074 commit 169dc9e

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

packages/@angular/cli/commands/generate.ts

+2
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,14 @@ export default Command.extend({
103103
const blueprint = this.blueprints.find((bp: any) => bp.name === name
104104
|| (bp.aliases && bp.aliases.includes(name)));
105105

106+
const projectName = CliConfig.getValue('project.name');
106107
const blueprintOptions = {
107108
target: this.project.root,
108109
entity: {
109110
name: rawArgs[1],
110111
options: parseOptions(rawArgs.slice(2))
111112
},
113+
projectName,
112114
ui: this.ui,
113115
project: this.project,
114116
settings: this.settings,

packages/@angular/cli/ember-cli/lib/models/blueprint.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ Blueprint.prototype._generateFileMapVariables = function(moduleName, locals, opt
856856
@return {Object}
857857
*/
858858
Blueprint.prototype._locals = function(options) {
859-
var packageName = options.project.name();
859+
var packageName = options.project.name() || options.projectName;
860860
var moduleName = options.entity && options.entity.name || packageName;
861861
var sanitizedModuleName = moduleName.replace(/\//g, '-');
862862

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {join} from 'path';
2+
import {ng} from '../../utils/process';
3+
import {expectFileToExist} from '../../utils/fs';
4+
import {updateJsonFile} from '../../utils/project';
5+
6+
7+
export default function() {
8+
const compDir = join('src', 'app', 'test-component');
9+
10+
return Promise.resolve()
11+
.then(() => updateJsonFile('package.json', configJson => {
12+
delete configJson.name;
13+
return configJson;
14+
}))
15+
.then(() => ng('generate', 'component', 'test-component'))
16+
.then(() => expectFileToExist(compDir))
17+
.then(() => expectFileToExist(join(compDir, 'test-component.component.ts')))
18+
.then(() => expectFileToExist(join(compDir, 'test-component.component.spec.ts')))
19+
.then(() => expectFileToExist(join(compDir, 'test-component.component.html')))
20+
.then(() => expectFileToExist(join(compDir, 'test-component.component.css')))
21+
22+
// Try to run the unit tests.
23+
.then(() => ng('test', '--single-run'));
24+
}

0 commit comments

Comments
 (0)