Skip to content

Commit f428ded

Browse files
committed
more accurate way for resolving files in node_modules
1 parent c5b66d7 commit f428ded

File tree

7 files changed

+21
-3
lines changed

7 files changed

+21
-3
lines changed

file-system-loader.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var DepGraph = require('dependency-graph').DepGraph;
4+
var nodeResolve = require('resolve');
45

56
Object.defineProperty(exports, '__esModule', {
67
value: true
@@ -64,12 +65,13 @@ var FileSystemLoader = (function () {
6465
return new Promise(function (resolve, reject) {
6566
var relativeDir = _path2['default'].dirname(relativeTo),
6667
rootRelativePath = _path2['default'].resolve(relativeDir, newPath),
67-
fileRelativePath = _path2['default'].resolve(_path2['default'].join(_this.root, relativeDir), newPath);
68+
rootRelativeDir = _path2['default'].join(_this.root, relativeDir),
69+
fileRelativePath = _path2['default'].resolve(rootRelativeDir, newPath);
6870

6971
// if the path is not relative or absolute, try to resolve it in node_modules
7072
if (newPath[0] !== '.' && newPath[0] !== '/') {
7173
try {
72-
fileRelativePath = require.resolve(newPath);
74+
fileRelativePath = nodeResolve.sync(newPath, { basedir: rootRelativeDir });
7375
} catch (e) {}
7476
}
7577

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"dependency-graph": "^0.4.1",
99
"object-assign": "^3.0.0",
1010
"promise-polyfill": "^2.1.0",
11+
"resolve": "^1.1.7",
1112
"string-hash": "^1.1.0",
1213
"through": "^2.3.7"
1314
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
._node_modules_cool_local_styles_styles__foo {
2+
color: #F00;
3+
}
4+
._styles__foo {
5+
background: black;
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var styles = require('./styles.css');
2+
module.exports = styles;

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

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

tests/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var path = require('path');
88
var casesDir = path.join(__dirname, 'cases');
99
var cssOutFilename = 'out.css';
1010

11-
var globalCases = ['compose-node-module', 'import-node-module'];
11+
var globalCases = ['compose-node-module', 'compose-local-node-module', 'import-node-module'];
1212

1313
function runTestCase (dir) {
1414
tape('case: ' + dir, function (t) {

0 commit comments

Comments
 (0)