Skip to content

Commit 03a680d

Browse files
committed
more accurate way for resolving files in node_modules
1 parent b99eaee commit 03a680d

File tree

6 files changed

+21
-4
lines changed

6 files changed

+21
-4
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
"dependencies": {
1010
"icss-replace-symbols": "1.0.2",
1111
"postcss": "5.0.10",
12-
"postcss-modules-values": "1.1.1",
1312
"postcss-modules-extract-imports": "1.0.0",
1413
"postcss-modules-local-by-default": "1.0.1",
15-
"postcss-modules-scope": "1.0.0"
14+
"postcss-modules-scope": "1.0.0",
15+
"postcss-modules-values": "1.1.1",
16+
"resolve": "^1.1.7"
1617
},
1718
"devDependencies": {
1819
"babel": "5.8.29",

src/file-system-loader.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Core from './index.js'
22
import fs from 'fs'
33
import path from 'path'
4+
import nodeResolve from 'resolve'
45

56
// Sorts dependencies in the following way:
67
// AAA comes before AA and A
@@ -34,12 +35,13 @@ export default class FileSystemLoader {
3435
return new Promise( ( resolve, reject ) => {
3536
let relativeDir = path.dirname( relativeTo ),
3637
rootRelativePath = path.resolve( relativeDir, newPath ),
37-
fileRelativePath = path.resolve( path.join( this.root, relativeDir ), newPath )
38+
rootRelativeDir = path.join( this.root, relativeDir ),
39+
fileRelativePath = path.resolve( rootRelativeDir, newPath )
3840

3941
// if the path is not relative or absolute, try to resolve it in node_modules
4042
if (newPath[0] !== '.' && newPath[0] !== '/') {
4143
try {
42-
fileRelativePath = require.resolve(newPath);
44+
fileRelativePath = nodeResolve.sync(newPath, { basedir: rootRelativeDir });
4345
}
4446
catch (e) {}
4547
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
._compose_local_node_module_cool_local_styles_foo__example {
2+
color: #F00;
3+
}
4+
._compose_local_node_module_source__foo {
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"foo": "_compose_local_node_module_source__foo _compose_local_node_module_cool_local_styles_foo__example"
3+
}

test/test-cases/compose-local-node-module/node_modules/cool-local-styles/foo.css

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.foo {
2+
composes: example from "cool-local-styles/foo.css";
3+
}

0 commit comments

Comments
 (0)