Skip to content

Commit 783e13f

Browse files
committed
glob resolver looks for files in modules
1 parent a3942e9 commit 783e13f

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

lib/resolve-glob.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ module.exports = function resolveGlob(id, base, opts) {
2121
var prefix = opts.prefix;
2222
var extensions = opts.extensions;
2323
var paths = [base].concat(opts.path);
24+
// search in modules if non-relative filepath given
25+
if (id[0] !== '.') {
26+
paths = paths.concat([
27+
'node_modules',
28+
'web_modules'
29+
]);
30+
}
2431
var prefixedId = prefix ? addPrefix(id, prefix) : null;
2532

2633
var patterns = reduce((acc, p) => {

test/easy-import.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,12 @@ test('should handle glob and module imports together', t => {
105105
t
106106
);
107107
});
108+
109+
test('should import glob from node_modules', t => {
110+
return preprocess(
111+
'@import "css.globtest/*.css"',
112+
'.bar {\n color: green;\n}\n.foo {\n color: tomato;\n}',
113+
{},
114+
t
115+
);
116+
});

test/node_modules/css.globtest/glob1.css

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/resolve-glob.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,14 @@ test('should resolve every match if prefix is not defined', t => { // eslint-dis
104104
].map(resolve));
105105
});
106106
});
107+
108+
test('should resolve globs in node_modules', t => {
109+
return resolveGlob('css.globtest/*.css', path.resolve('fixtures/glob'), {
110+
extensions: ['.css', '.scss'],
111+
path: []
112+
}).then(result => {
113+
t.deepEqual(result, [
114+
path.resolve('node_modules/css.globtest/glob1.css')
115+
]);
116+
});
117+
});

0 commit comments

Comments
 (0)