Skip to content

Commit 997a255

Browse files
fix: handle module import ending / as module (#728)
1 parent 071fa88 commit 997a255

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

src/importsToResolve.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import path from 'path';
22

33
import utils from 'loader-utils';
44

5-
const matchModuleImport = /^~([^/]+|@[^/]+[/][^/]+)$/;
5+
// Examples:
6+
// - ~package
7+
// - ~package/
8+
// - ~@org
9+
// - ~@org/
10+
// - ~@org/package
11+
// - ~@org/package/
12+
const matchModuleImport = /^~([^/]+|[^/]+\/|@[^/]+[/][^/]+|@[^/]+\/?|@[^/]+[/][^/]+\/)$/;
613

714
/**
815
* When libsass tries to resolve an import, it uses a special algorithm.

test/helpers/getCodeFromSass.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,18 @@ function getCodeFromSass(testId, options) {
650650
/^~@path-to-scss-dir\/dir-with-underscore-index$/,
651651
pathToSCSSIndexAlias
652652
)
653+
.replace(
654+
/^~@path-to-scss-dir\/dir-with-underscore-index\/$/,
655+
pathToSCSSIndexAlias
656+
)
653657
.replace(
654658
/^~@path-to-sass-dir\/dir-with-underscore-index$/,
655659
pathToSassIndexAlias
656660
)
661+
.replace(
662+
/^~@path-to-sass-dir\/dir-with-underscore-index\/$/,
663+
pathToSassIndexAlias
664+
)
657665
.replace(
658666
/^~@\/path-to-scss-dir\/dir-with-underscore-index$/,
659667
pathToSCSSIndexAlias

test/sass/import-alias.sass

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import 'path-to-alias'
22
@import "~@sass"
33
@import "~@path-to-sass-dir/dir-with-underscore-index"
4+
@import "~@path-to-sass-dir/dir-with-underscore-index/"
45
@import "~@/path-to-sass-dir/dir-with-underscore-index"

test/scss/import-alias.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import 'path-to-alias';
22
@import "~@scss";
33
@import "~@path-to-scss-dir/dir-with-underscore-index";
4+
@import "~@path-to-scss-dir/dir-with-underscore-index/";
45
@import "~@/path-to-scss-dir/dir-with-underscore-index";

0 commit comments

Comments
 (0)