diff --git a/node_modules/cool-styles/bar.css b/node_modules/cool-styles/bar.css new file mode 100644 index 0000000..71c33de --- /dev/null +++ b/node_modules/cool-styles/bar.css @@ -0,0 +1,4 @@ +.example +{ + background: #F00; +} diff --git a/node_modules/cool-styles/foo.css b/node_modules/cool-styles/foo.css index 65f95db..e584fbf 100644 --- a/node_modules/cool-styles/foo.css +++ b/node_modules/cool-styles/foo.css @@ -1,3 +1,4 @@ .example { color: #F00; + composes: example from './bar.css'; } diff --git a/package.json b/package.json index ecec1f9..649518f 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,9 @@ "directories": { "test": "test" }, + "engines": { + "node": ">=0.12" + }, "dependencies": { "postcss": "^4.1.11", "postcss-modules-extract-imports": "^0.0.5", diff --git a/src/file-system-loader.js b/src/file-system-loader.js index 2a3f47d..4cf3d8e 100644 --- a/src/file-system-loader.js +++ b/src/file-system-loader.js @@ -33,26 +33,26 @@ export default class FileSystemLoader { trace = _trace || String.fromCharCode( this.importNr++ ) return new Promise( ( resolve, reject ) => { let relativeDir = path.dirname( relativeTo ), - rootRelativePath = path.resolve( relativeDir, newPath ), - fileRelativePath = path.resolve( path.join( this.root, relativeDir ), newPath ) + filename = path.resolve( this.root + relativeDir, newPath ) // if the path is not relative or absolute, try to resolve it in node_modules - if (newPath[0] !== '.' && newPath[0] !== '/') { + if ( newPath[0] !== '.' && newPath[0] !== path.sep ) { try { - fileRelativePath = require.resolve(newPath); + filename = require.resolve( newPath ); } catch (e) {} } - const tokens = this.tokensByFile[fileRelativePath] - if (tokens) { return resolve(tokens) } + const rootRelativePath = path.sep + path.relative( this.root, filename ) + const tokens = this.tokensByFile[filename] + if ( tokens ) { return resolve( tokens ) } - fs.readFile( fileRelativePath, "utf-8", ( err, source ) => { + fs.readFile( filename, "utf-8", ( err, source ) => { if ( err ) reject( err ) this.core.load( source, rootRelativePath, trace, this.fetch.bind( this ) ) .then( ( { injectableSource, exportTokens } ) => { this.sources[trace] = injectableSource - this.tokensByFile[fileRelativePath] = exportTokens + this.tokensByFile[filename] = exportTokens resolve( exportTokens ) }, reject ) } ) diff --git a/test/test-cases/compose-node-module/expected.css b/test/test-cases/compose-node-module/expected.css index 0667b94..20f498c 100644 --- a/test/test-cases/compose-node-module/expected.css +++ b/test/test-cases/compose-node-module/expected.css @@ -1,4 +1,7 @@ -._compose_node_module_cool_styles_foo__example { +:import("./bar.css") { + i__imported_example_0: example; +} +._node_modules_cool_styles_foo__example { color: #F00; } ._compose_node_module_source__foo { diff --git a/test/test-cases/compose-node-module/expected.json b/test/test-cases/compose-node-module/expected.json index a57448c..0da68b2 100644 --- a/test/test-cases/compose-node-module/expected.json +++ b/test/test-cases/compose-node-module/expected.json @@ -1,3 +1,3 @@ { - "foo": "_compose_node_module_source__foo _compose_node_module_cool_styles_foo__example" + "foo": "_compose_node_module_source__foo _node_modules_cool_styles_foo__example _node_modules_cool_styles_foo__example i__imported_example_0" }