From 86021a0910495e61ec8bc539001b3755e928173d Mon Sep 17 00:00:00 2001 From: Mike Brocchi Date: Tue, 25 Oct 2016 11:05:28 -0400 Subject: [PATCH] bug(generate): fix import path for directives & pipes when importing into a module (#2883) Fixes #2762 --- packages/angular-cli/blueprints/directive/index.js | 6 ++++-- packages/angular-cli/blueprints/pipe/index.js | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/angular-cli/blueprints/directive/index.js b/packages/angular-cli/blueprints/directive/index.js index 790c34890acf..ba53e7e95442 100644 --- a/packages/angular-cli/blueprints/directive/index.js +++ b/packages/angular-cli/blueprints/directive/index.js @@ -85,8 +85,10 @@ module.exports = { const returns = []; const className = stringUtils.classify(`${options.entity.name}Directive`); const fileName = stringUtils.dasherize(`${options.entity.name}.directive`); - const componentDir = path.relative(this.dynamicPath.appRoot, this.generatePath); - const importPath = componentDir ? `./${componentDir}/${fileName}` : `./${fileName}`; + const fullGeneratePath = path.join(this.project.root, this.generatePath); + const moduleDir = path.parse(this.pathToModule).dir; + const relativeDir = path.relative(moduleDir, fullGeneratePath); + const importPath = relativeDir ? `./${relativeDir}/${fileName}` : `./${fileName}`; if (!options['skip-import']) { returns.push( diff --git a/packages/angular-cli/blueprints/pipe/index.js b/packages/angular-cli/blueprints/pipe/index.js index d4a65b158641..12f957add718 100644 --- a/packages/angular-cli/blueprints/pipe/index.js +++ b/packages/angular-cli/blueprints/pipe/index.js @@ -73,8 +73,10 @@ module.exports = { const returns = []; const className = stringUtils.classify(`${options.entity.name}Pipe`); const fileName = stringUtils.dasherize(`${options.entity.name}.pipe`); - const componentDir = path.relative(this.dynamicPath.appRoot, this.generatePath); - const importPath = componentDir ? `./${componentDir}/${fileName}` : `./${fileName}`; + const fullGeneratePath = path.join(this.project.root, this.generatePath); + const moduleDir = path.parse(this.pathToModule).dir; + const relativeDir = path.relative(moduleDir, fullGeneratePath); + const importPath = relativeDir ? `./${relativeDir}/${fileName}` : `./${fileName}`; if (!options['skip-import']) { returns.push(