Skip to content

Commit 86021a0

Browse files
authored
bug(generate): fix import path for directives & pipes when importing into a module (#2883)
Fixes #2762
1 parent de0329a commit 86021a0

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ module.exports = {
8585
const returns = [];
8686
const className = stringUtils.classify(`${options.entity.name}Directive`);
8787
const fileName = stringUtils.dasherize(`${options.entity.name}.directive`);
88-
const componentDir = path.relative(this.dynamicPath.appRoot, this.generatePath);
89-
const importPath = componentDir ? `./${componentDir}/${fileName}` : `./${fileName}`;
88+
const fullGeneratePath = path.join(this.project.root, this.generatePath);
89+
const moduleDir = path.parse(this.pathToModule).dir;
90+
const relativeDir = path.relative(moduleDir, fullGeneratePath);
91+
const importPath = relativeDir ? `./${relativeDir}/${fileName}` : `./${fileName}`;
9092

9193
if (!options['skip-import']) {
9294
returns.push(

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ module.exports = {
7373
const returns = [];
7474
const className = stringUtils.classify(`${options.entity.name}Pipe`);
7575
const fileName = stringUtils.dasherize(`${options.entity.name}.pipe`);
76-
const componentDir = path.relative(this.dynamicPath.appRoot, this.generatePath);
77-
const importPath = componentDir ? `./${componentDir}/${fileName}` : `./${fileName}`;
76+
const fullGeneratePath = path.join(this.project.root, this.generatePath);
77+
const moduleDir = path.parse(this.pathToModule).dir;
78+
const relativeDir = path.relative(moduleDir, fullGeneratePath);
79+
const importPath = relativeDir ? `./${relativeDir}/${fileName}` : `./${fileName}`;
7880

7981
if (!options['skip-import']) {
8082
returns.push(

0 commit comments

Comments
 (0)