Skip to content

Commit 9c83f3b

Browse files
sumitaroraBrocco
authored andcommitted
fix(@angular/cli): fix package name fetching from package.json
1 parent 54b7937 commit 9c83f3b

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as fs from 'fs';
33
import * as os from 'os';
44
import * as path from 'path';
55
import { oneLine } from 'common-tags';
6+
import { CliConfig } from '../models/config';
67

78
const Command = require('../ember-cli/lib/models/command');
89
const Blueprint = require('../ember-cli/lib/models/blueprint');
@@ -96,12 +97,14 @@ export default Command.extend({
9697
const blueprint = this.blueprints.find((bp: any) => bp.name === name
9798
|| (bp.aliases && bp.aliases.includes(name)));
9899

100+
const projectName = CliConfig.getValue('project.name');
99101
const blueprintOptions = {
100102
target: this.project.root,
101103
entity: {
102104
name: rawArgs[1],
103105
options: parseOptions(rawArgs.slice(2))
104106
},
107+
projectName,
105108
ui: this.ui,
106109
project: this.project,
107110
settings: this.settings,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ Blueprint.prototype._generateFileMapVariables = function(moduleName, locals, opt
848848
@return {Object}
849849
*/
850850
Blueprint.prototype._locals = function(options) {
851-
var packageName = options.project.name();
851+
var packageName = options.project.name() || options.projectName;
852852
var moduleName = options.entity && options.entity.name || packageName;
853853
var sanitizedModuleName = moduleName.replace(/\//g, '-');
854854

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)