Skip to content

Commit 35076a2

Browse files
committed
added root option, which fixed tests
1 parent 9b78d17 commit 35076a2

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import './guard';
44
import hook from './hook';
55
import postcss from 'postcss';
6-
import { basename, dirname, join, resolve } from 'path';
6+
import { basename, dirname, join, relative, resolve } from 'path';
77
import { readFileSync } from 'fs';
88

99
import extractImports from 'postcss-modules-extract-imports';
@@ -12,6 +12,7 @@ import scope from 'postcss-modules-scope';
1212
import parser from './parser';
1313

1414
let plugins = [localByDefault, extractImports, scope];
15+
let rootDir;
1516

1617
/**
1718
* @param {string} sourceString The file content
@@ -32,7 +33,7 @@ function load(sourceString, sourcePath, trace, pathFetcher) {
3233
}
3334

3435
hook(filename => {
35-
const root = dirname(filename);
36+
const root = rootDir || dirname(filename);
3637
const sources = {};
3738
const tokensByFile = {};
3839
let importNr = 0;
@@ -59,7 +60,7 @@ hook(filename => {
5960
return exportTokens;
6061
}
6162

62-
return fetch(basename(filename), '/');
63+
return fetch(relative(root, filename), '/');
6364
});
6465

6566
/**
@@ -74,4 +75,8 @@ export default function configure(opts) {
7475
plugins = Array.isArray(customPlugins)
7576
? customPlugins
7677
: [localByDefault, extractImports, scope];
78+
79+
if (opts.root && typeof opts.root === 'string') {
80+
rootDir = opts.root;
81+
}
7782
}

0 commit comments

Comments
 (0)