Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/importsToResolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const path = require('path');
const utils = require('loader-utils');

const matchModuleImport = /^~([^/]+|@[^/]+[/][^/]+)$/;
const matchScopedNpmPackage = /^@.*\//;

/**
* When libsass tries to resolve an import, it uses a special algorithm.
Expand All @@ -25,6 +26,13 @@ function importsToResolve(url) {
return [request, url];
}

// In case there is a deep import from a scoped NPM package
// ex: @import '@component-lib/button'
// return nothing and let node-sass handle the import directly
if (matchScopedNpmPackage.test(url)) {
return [];
}

// libsass' import algorithm works like this:

// In case there is a file extension...
Expand Down
4 changes: 4 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ implementations.forEach((implementation) => {
execTest('bootstrap-sass'));
it('should correctly import scoped npm packages', () =>
execTest('import-from-npm-org-pkg'));
it('should directly import scoped npm packages', () =>
execTest('import-directly-from-npm-org-pkg', {
includePaths: [path.join(__dirname, 'node_modules')],
}));
it('should resolve aliases', () =>
execTest(
'import-alias',
Expand Down
3 changes: 3 additions & 0 deletions test/node_modules/@org/baz/qux.scss

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions test/sass/import-directly-from-npm-org-pkg.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* @import ~@org/pkg */
@import @org/baz/qux

.foo
background: #000
6 changes: 6 additions & 0 deletions test/scss/import-directly-from-npm-org-pkg.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* @import "~@org/pkg"; */
@import "@org/baz/qux";

.foo {
background: #000;
}
5 changes: 5 additions & 0 deletions test/tools/createSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ function createSpec(ext) {
const basePath = path.join(testFolder, ext);
const testNodeModules =
path.relative(basePath, path.join(testFolder, 'node_modules')) + path.sep;
const testDirectNodeModules = path.relative(
basePath,
path.join(testFolder, 'node_modules', '@')
);
const pathToBootstrap = path.relative(
basePath,
path.resolve(testFolder, '..', 'node_modules', 'bootstrap-sass')
Expand Down Expand Up @@ -84,6 +88,7 @@ function createSpec(ext) {
.replace(/^~module/, pathToModule)
.replace(/^~another/, pathToAnother)
.replace(/^~/, testNodeModules)
.replace(/^@/, testDirectNodeModules)
.replace(/^path-to-alias/, pathToFooAlias);
}
return {
Expand Down