33import './guard' ;
44import hook from './hook' ;
55import postcss from 'postcss' ;
6- import { basename , dirname , join , resolve } from 'path' ;
6+ import { basename , dirname , join , relative , resolve } from 'path' ;
77import { readFileSync } from 'fs' ;
88
99import extractImports from 'postcss-modules-extract-imports' ;
@@ -12,6 +12,7 @@ import scope from 'postcss-modules-scope';
1212import parser from './parser' ;
1313
1414let 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
3435hook ( 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