Skip to content

Commit 2e1a976

Browse files
committed
Merge pull request #15 from joshwnj/compose-node-module
resolve paths to node_modules
2 parents 6792d5e + 6ba849e commit 2e1a976

File tree

6 files changed

+24
-1
lines changed

6 files changed

+24
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
node_modules
1+
node_modules/*
2+
!node_modules/cool-styles
23
lib

node_modules/cool-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.

src/file-system-loader.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ export default class FileSystemLoader {
3636
rootRelativePath = path.resolve( relativeDir, newPath ),
3737
fileRelativePath = path.resolve( path.join( this.root, relativeDir ), newPath )
3838

39+
// if the path is not relative or absolute, try to resolve it in node_modules
40+
if (newPath[0] !== '.' && newPath[0] !== '/') {
41+
try {
42+
fileRelativePath = require.resolve(newPath);
43+
}
44+
catch (e) {}
45+
}
46+
3947
const tokens = this.tokensByFile[fileRelativePath]
4048
if (tokens) { return resolve(tokens) }
4149

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
._compose_node_module_cool_styles_foo__example {
2+
color: #F00;
3+
}
4+
._compose_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_node_module_source__foo _compose_node_module_cool_styles_foo__example"
3+
}
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-styles/foo.css";
3+
}

0 commit comments

Comments
 (0)