Skip to content

Commit da1fc81

Browse files
committed
fix(@angular/cli): fix import path for component when importing into a module
This is similar to 86021a0. Fix #7135
1 parent 694deb9 commit da1fc81

File tree

1 file changed

+5
-3
lines changed
  • packages/@angular/cli/blueprints/component

1 file changed

+5
-3
lines changed

packages/@angular/cli/blueprints/component/index.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,11 @@ export default Blueprint.extend({
238238
const returns: Array<any> = [];
239239
const className = stringUtils.classify(`${options.entity.name}Component`);
240240
const fileName = stringUtils.dasherize(`${options.entity.name}.component`);
241-
const componentDir = path.relative(path.dirname(this.pathToModule), this.generatePath);
242-
const normalizeRelativeDir = componentDir.startsWith('.') ? componentDir : `./${componentDir}`;
243-
const importPath = componentDir ? `${normalizeRelativeDir}/${fileName}` : `./${fileName}`;
241+
const fullGeneratePath = path.join(this.project.root, this.generatePath);
242+
const moduleDir = path.parse(this.pathToModule).dir;
243+
const relativeDir = path.relative(moduleDir, fullGeneratePath);
244+
const normalizeRelativeDir = relativeDir.startsWith('.') ? relativeDir : `./${relativeDir}`;
245+
const importPath = relativeDir ? `${normalizeRelativeDir}/${fileName}` : `./${fileName}`;
244246

245247
if (!options.skipImport) {
246248
if (options.dryRun) {

0 commit comments

Comments
 (0)