diff --git a/src/utils.js b/src/utils.js index aa79b795..22e203aa 100644 --- a/src/utils.js +++ b/src/utils.js @@ -245,24 +245,25 @@ function getPossibleRequests( forWebpackResolver = false, rootContext = false ) { - // Maybe it is server-relative URLs - const root = forWebpackResolver && rootContext; let request; - if (typeof root === "string" && /^\//.test(url)) { - request = root + url; - } else { - request = url; - } + // In case there is module request, send this to webpack resolver + if (forWebpackResolver) { + // Maybe it is server-relative URLs + request = + typeof rootContext === "string" && /^\//.test(url) + ? rootContext + url + : url; - // A `~` makes the url an module - if (moduleRequestRegex.test(request)) { request = request.replace(moduleRequestRegex, ""); - } - // In case there is module request, send this to webpack resolver - if (forWebpackResolver && isModuleImport.test(url)) { - return [...new Set([request, url])]; + if (isModuleImport.test(url)) { + request = request[request.length - 1] === "/" ? request : `${request}/`; + + return [...new Set([request, url])]; + } + } else { + request = url; } // Keep in mind: ext can also be something like '.datepicker' when the true extension is omitted and the filename contains a dot. diff --git a/test/helpers/getCodeFromSass.js b/test/helpers/getCodeFromSass.js index f25cd090..bb11b72c 100644 --- a/test/helpers/getCodeFromSass.js +++ b/test/helpers/getCodeFromSass.js @@ -217,6 +217,10 @@ function getCodeFromSass(testId, options) { testFolder, "node_modules/@org/pkg/index.scss" ); + const pathToScopedNpmFile = path.resolve( + testFolder, + "node_modules/@org/style.scss" + ); const pathToSCSSCustomSassField = path.resolve( testFolder, "node_modules/scss-custom-sass-field/nested/style.scss" @@ -726,6 +730,7 @@ function getCodeFromSass(testId, options) { pathToSassIndexAlias ) .replace(/^~@org\/pkg/, pathToScopedNpmPkg) + .replace(/^@org\/style/, pathToScopedNpmFile) .replace(/^~bootstrap-sass$/, pathToBootstrap3Entry) .replace(/^~bootstrap-sass/, pathToBootstrap3Package) .replace(/^~bootstrap$/, pathToBootstrap4Entry) diff --git a/test/loader.test.js b/test/loader.test.js index c7b15d24..6badbaad 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -638,7 +638,7 @@ describe("loader", () => { }); it(`should work with the "bootstrap" package, import as a package (${implementationName}) (${syntax})`, async () => { - const testId = getTestId("bootstrap-package", syntax); + const testId = getTestId("bootstrap", syntax); const options = { implementation: getImplementationByName(implementationName), }; diff --git a/test/sass/bootstrap-package.sass b/test/sass/bootstrap.sass similarity index 100% rename from test/sass/bootstrap-package.sass rename to test/sass/bootstrap.sass diff --git a/test/sass/imports.sass b/test/sass/imports.sass index bc5402d3..11dea9cf 100644 --- a/test/sass/imports.sass +++ b/test/sass/imports.sass @@ -25,4 +25,4 @@ /* @import ~another */ @import ~another // Should prefer `scss` -@import "~@org/style" +@import "@org/style" diff --git a/test/sass/uses.sass b/test/sass/uses.sass index f803c3d5..2ab573c1 100644 --- a/test/sass/uses.sass +++ b/test/sass/uses.sass @@ -20,4 +20,4 @@ /* @use ~another */ @use "~another" as another // Should prefer `scss` -@use "~@org/style" +@use "@org/style" diff --git a/test/scss/bootstrap-package.scss b/test/scss/bootstrap.scss similarity index 100% rename from test/scss/bootstrap-package.scss rename to test/scss/bootstrap.scss diff --git a/test/scss/imports.scss b/test/scss/imports.scss index 670c433a..f887ff01 100644 --- a/test/scss/imports.scss +++ b/test/scss/imports.scss @@ -26,4 +26,4 @@ @import "~another"; /* @import "~@org/style"; */ // Should prefer `scss` -@import "~@org/style"; +@import "@org/style"; diff --git a/test/scss/uses.scss b/test/scss/uses.scss index 295fc2f1..01f9e528 100644 --- a/test/scss/uses.scss +++ b/test/scss/uses.scss @@ -20,4 +20,4 @@ @use "~another" as another; /* @use "~@org/style"; */ // Should prefer `scss` -@use "~@org/style"; +@use "@org/style";