Skip to content

Commit b4549b7

Browse files
committed
Resolve absolute paths, remove file argument from resolver as a result
1 parent 98f551f commit b4549b7

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ Default value: `null`
7676

7777
A function to be called instead of normal rewriting.
7878

79-
Takes two arguments:
80-
* A string containing imported file path,
81-
* File object for currently processed file containing some meta information, see [karma preprocessor documentation](http://karma-runner.github.io/3.0/dev/plugins.html).
79+
Takes a single argument: A string containing imported file path.
8280

8381
Return value: string.
8482

index.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ const createModuleResolverPreprocessor = (karmaConfig, args = {}, config = {}, l
2626
options.aliases[alias] = path.resolve(karmaConfig.basePath, options.aliases[alias]);
2727
}
2828

29-
const resolvePath = (modulePath, file) => {
29+
const resolvePath = (modulePath) => {
3030
if (options.customResolver) {
31-
return options.customResolver(modulePath, file);
31+
return options.customResolver(modulePath);
3232
}
3333

3434
let result = modulePath;
@@ -41,12 +41,7 @@ const createModuleResolverPreprocessor = (karmaConfig, args = {}, config = {}, l
4141
for (const alias of sortedAliases) {
4242
if (result.startsWith(alias)) {
4343
const pathUnderAlias = path.relative(alias, result);
44-
const fullImportPath = path.resolve(options.aliases[alias], pathUnderAlias);
45-
46-
result = path.relative(path.dirname(file.path), fullImportPath);
47-
if (!isLocalPath(result)) {
48-
result = './' + result;
49-
}
44+
result = path.resolve(options.aliases[alias], pathUnderAlias);
5045
}
5146
}
5247
}
@@ -71,7 +66,7 @@ const createModuleResolverPreprocessor = (karmaConfig, args = {}, config = {}, l
7166
for (const node of ast.body.reverse()) {
7267
// Imports can only be at top level as per specification
7368
if (node.type === 'ImportDeclaration' && node.source.type === 'Literal') {
74-
const resolved = resolvePath(node.source.value, file);
69+
const resolved = resolvePath(node.source.value);
7570
if (resolved !== node.source.value) {
7671
const replacement = node.source.raw.replace(node.source.value, resolved);
7772
log.debug('Replacing import from "%s" with "%s"', node.source.value, resolved);

0 commit comments

Comments
 (0)