Skip to content

Commit 7c8b7f0

Browse files
Broccohansl
authored andcommitted
bug(generate): skip-import flag not being respected (#3147)
Fixes #2973
1 parent 07e96ea commit 7c8b7f0

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

packages/angular-cli/blueprints/component/index.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ module.exports = {
1818
{ name: 'prefix', type: Boolean, default: true },
1919
{ name: 'spec', type: Boolean },
2020
{ name: 'view-encapsulation', type: String, aliases: ['ve'] },
21-
{ name: 'change-detection', type: String, aliases: ['cd'] }
21+
{ name: 'change-detection', type: String, aliases: ['cd'] },
22+
{ name: 'skip-import', type: Boolean, default: false }
2223
],
2324

24-
beforeInstall: function() {
25+
beforeInstall: function(options) {
2526
try {
2627
this.pathToModule = findParentModule(this.project, this.dynamicPath.dir);
2728
} catch(e) {
28-
throw `Error locating module for declaration\n\t${e}`;
29+
if (!options.skipImport) {
30+
throw `Error locating module for declaration\n\t${e}`;
31+
}
2932
}
3033
},
3134

@@ -139,7 +142,7 @@ module.exports = {
139142
const componentDir = path.relative(path.dirname(this.pathToModule), this.generatePath);
140143
const importPath = componentDir ? `./${componentDir}/${fileName}` : `./${fileName}`;
141144

142-
if (!options['skip-import']) {
145+
if (!options.skipImport) {
143146
returns.push(
144147
astUtils.addDeclarationToModule(this.pathToModule, className, importPath)
145148
.then(change => change.apply(NodeHost)));

packages/angular-cli/blueprints/directive/index.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ module.exports = {
1313
availableOptions: [
1414
{ name: 'flat', type: Boolean, default: true },
1515
{ name: 'prefix', type: Boolean, default: true },
16-
{ name: 'spec', type: Boolean }
16+
{ name: 'spec', type: Boolean },
17+
{ name: 'skip-import', type: Boolean, default: false }
1718
],
1819

19-
beforeInstall: function() {
20+
beforeInstall: function(options) {
2021
try {
2122
this.pathToModule = findParentModule(this.project, this.dynamicPath.dir);
2223
} catch(e) {
23-
throw `Error locating module for declaration\n\t${e}`;
24+
if (!options.skipImport) {
25+
throw `Error locating module for declaration\n\t${e}`;
26+
}
2427
}
2528
},
2629

@@ -90,7 +93,7 @@ module.exports = {
9093
const relativeDir = path.relative(moduleDir, fullGeneratePath);
9194
const importPath = relativeDir ? `./${relativeDir}/${fileName}` : `./${fileName}`;
9295

93-
if (!options['skip-import']) {
96+
if (!options.skipImport) {
9497
returns.push(
9598
astUtils.addDeclarationToModule(this.pathToModule, className, importPath)
9699
.then(change => change.apply(NodeHost)));

packages/angular-cli/blueprints/pipe/index.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ module.exports = {
1212

1313
availableOptions: [
1414
{ name: 'flat', type: Boolean, default: true },
15-
{ name: 'spec', type: Boolean }
15+
{ name: 'spec', type: Boolean },
16+
{ name: 'skip-import', type: Boolean, default: false }
1617
],
1718

18-
beforeInstall: function() {
19+
beforeInstall: function(options) {
1920
try {
2021
this.pathToModule = findParentModule(this.project, this.dynamicPath.dir);
2122
} catch(e) {
22-
throw `Error locating module for declaration\n\t${e}`;
23+
if (!options.skipImport) {
24+
throw `Error locating module for declaration\n\t${e}`;
25+
}
2326
}
2427
},
2528

@@ -78,7 +81,7 @@ module.exports = {
7881
const relativeDir = path.relative(moduleDir, fullGeneratePath);
7982
const importPath = relativeDir ? `./${relativeDir}/${fileName}` : `./${fileName}`;
8083

81-
if (!options['skip-import']) {
84+
if (!options.skipImport) {
8285
returns.push(
8386
astUtils.addDeclarationToModule(this.pathToModule, className, importPath)
8487
.then(change => change.apply(NodeHost)));

0 commit comments

Comments
 (0)