-
-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: importing file directly from scoped npm package (#450)
* fix issue with importing file directly from scoped npm package * Try to fix appveyor
- Loading branch information
1 parent
f01ae22
commit 5d06e9d
Showing
4 changed files
with
21 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,13 +28,21 @@ function importsToResolve(request) { | |
const basename = path.basename(request); | ||
const dirname = path.dirname(request); | ||
const startsWithUnderscore = basename.charAt(0) === "_"; | ||
// a module import is an identifier like 'bootstrap-sass' | ||
// Firstly check whether we importing scoped npm package (i.e. "@org/pkg") | ||
// We also need to check for dirname since it might also be a deep import like 'bootstrap-sass/something' | ||
const isModuleImport = dirname.charAt(0) === "@" && dirname.length > 1 ? true : request.charAt(0) !== "." && dirname === "."; | ||
const hasCssExt = ext === ".css"; | ||
const hasSassExt = ext === ".scss" || ext === ".sass"; | ||
|
||
// a module import is an identifier like 'bootstrap-sass' | ||
// We also need to check for dirname since it might also be a deep import like 'bootstrap-sass/something' | ||
let isModuleImport = request.charAt(0) !== "." && dirname === "."; | ||
|
||
if (dirname.charAt(0) === "@") { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
michael-ciniawsky
Member
|
||
// Check whether it is a deep import from scoped npm package | ||
// (i.e. @pkg/foo/file), if so, process import as file import; | ||
// otherwise, if we import from root npm scoped package (i.e. @pkg/foo) | ||
// process import as a module import. | ||
isModuleImport = !(dirname.indexOf("/") > -1); | ||
} | ||
|
||
return (isModuleImport && [request]) || // Do not modify module imports | ||
(hasCssExt && []) || // Do not import css files | ||
(hasSassExt && [request]) || // Do not modify imports with explicit extensions | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
/* @import "~@org/pkg"; */ | ||
@import "~@org/pkg"; | ||
/* @import ~@org/pkg */ | ||
@import ~@org/pkg | ||
/* @import ~@org/bar/foo */ | ||
@import ~@org/bar/foo | ||
|
||
.foo | ||
background: #000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I think this breaks resolving webpack aliases that start with @ character. at least that's what happened to me on 6.0.5 upgrade