Skip to content

Commit d610573

Browse files
authored
fix: imports schematic on Windows (#837)
1 parent e62f330 commit d610573

File tree

1 file changed

+10
-11
lines changed
  • libs/components/packages/src/schematics/migrations/update-7

1 file changed

+10
-11
lines changed

libs/components/packages/src/schematics/migrations/update-7/fix-imports.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { Path, dirname, join, normalize, split } from '@angular-devkit/core';
2+
import { relative, resolve } from '@angular-devkit/core/src/virtual-fs/path';
23
import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
34
import * as ts from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript';
45

5-
import * as path from 'path';
6-
76
import { getWorkspace } from '../../utility/workspace';
87

98
// Obfuscate the import statement regexp to avoid flagging by the missing peer dependency check.
@@ -14,7 +13,7 @@ const CORE_JS_OBJECT_VALUES_REQUIRE = `require('core-js/library/fn/object/values
1413

1514
function findChangesForLocalImports(
1615
localModulePaths: string[],
17-
filePath: string,
16+
filePath: Path,
1817
tree: Tree,
1918
context: SchematicContext
2019
): { find: string; replace: string }[] {
@@ -24,9 +23,7 @@ function findChangesForLocalImports(
2423
const normalizedModulePath = endsWithSlash
2524
? normalize(modulePath)
2625
: normalize(modulePath + '.ts');
27-
const absolutePath = normalize(
28-
join(dirname(normalize(filePath)), normalizedModulePath)
29-
);
26+
const absolutePath = resolve(dirname(filePath), normalizedModulePath);
3027
context.logger.debug(
3128
`Looking for local module ${modulePath} at ${absolutePath}...`
3229
);
@@ -73,10 +70,7 @@ function findChangesForLocalImports(
7370
return;
7471
}
7572
const newPathAbsolute = join(tree.root.path, ...newPath);
76-
let newPathRelative = path.relative(
77-
dirname(filePath as Path),
78-
newPathAbsolute
79-
);
73+
let newPathRelative = `${relative(dirname(filePath), newPathAbsolute)}`;
8074
if (!newPathRelative.startsWith('.')) {
8175
newPathRelative = `./${newPathRelative}`;
8276
}
@@ -191,7 +185,12 @@ function updateTypescriptImportsAndExports(
191185
.filter((moduleSpecifier) => moduleSpecifier.startsWith('.'));
192186
if (localModulePaths.length > 0) {
193187
transformers.push(
194-
...findChangesForLocalImports(localModulePaths, filePath, tree, context)
188+
...findChangesForLocalImports(
189+
localModulePaths,
190+
filePath as Path,
191+
tree,
192+
context
193+
)
195194
);
196195
}
197196

0 commit comments

Comments
 (0)