Skip to content

Commit 5d06e9d

Browse files
roman-vanesyanjoshwiens
authored andcommittedMay 10, 2017
fix: importing file directly from scoped npm package (#450)
* fix issue with importing file directly from scoped npm package * Try to fix appveyor
1 parent f01ae22 commit 5d06e9d

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed
 

‎lib/importsToResolve.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,21 @@ function importsToResolve(request) {
2828
const basename = path.basename(request);
2929
const dirname = path.dirname(request);
3030
const startsWithUnderscore = basename.charAt(0) === "_";
31-
// a module import is an identifier like 'bootstrap-sass'
32-
// Firstly check whether we importing scoped npm package (i.e. "@org/pkg")
33-
// We also need to check for dirname since it might also be a deep import like 'bootstrap-sass/something'
34-
const isModuleImport = dirname.charAt(0) === "@" && dirname.length > 1 ? true : request.charAt(0) !== "." && dirname === ".";
3531
const hasCssExt = ext === ".css";
3632
const hasSassExt = ext === ".scss" || ext === ".sass";
3733

34+
// a module import is an identifier like 'bootstrap-sass'
35+
// We also need to check for dirname since it might also be a deep import like 'bootstrap-sass/something'
36+
let isModuleImport = request.charAt(0) !== "." && dirname === ".";
37+
38+
if (dirname.charAt(0) === "@") {
Has conversations. Original line has conversations.
39+
// Check whether it is a deep import from scoped npm package
40+
// (i.e. @pkg/foo/file), if so, process import as file import;
41+
// otherwise, if we import from root npm scoped package (i.e. @pkg/foo)
42+
// process import as a module import.
43+
isModuleImport = !(dirname.indexOf("/") > -1);
44+
}
45+
3846
return (isModuleImport && [request]) || // Do not modify module imports
3947
(hasCssExt && []) || // Do not import css files
4048
(hasSassExt && [request]) || // Do not modify imports with explicit extensions

‎test/node_modules/@org/bar/_foo.scss

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
/* @import "~@org/pkg"; */
2-
@import "~@org/pkg";
1+
/* @import ~@org/pkg */
2+
@import ~@org/pkg
3+
/* @import ~@org/bar/foo */
4+
@import ~@org/bar/foo
35

46
.foo
57
background: #000;

‎test/scss/import-from-npm-org-pkg.scss

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* @import "~@org/pkg"; */
22
@import "~@org/pkg";
3+
/* @import "~@org/bar/foo"; */
4+
@import "~@org/bar/foo";
35

46
.foo {
57
background: #000;

0 commit comments

Comments
 (0)
Please sign in to comment.