diff --git a/package-lock.json b/package-lock.json index 4d3d6f0c..a3e9a085 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10387,6 +10387,7 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, "requires": { "yallist": "^4.0.0" } @@ -12648,6 +12649,7 @@ "version": "7.3.4", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.4.tgz", "integrity": "sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==", + "dev": true, "requires": { "lru-cache": "^6.0.0" } @@ -14271,7 +14273,8 @@ "yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true }, "yaml": { "version": "1.10.0", diff --git a/package.json b/package.json index 4d5af0ee..f43789b7 100644 --- a/package.json +++ b/package.json @@ -57,8 +57,7 @@ }, "dependencies": { "klona": "^2.0.4", - "neo-async": "^2.6.2", - "semver": "^7.3.4" + "neo-async": "^2.6.2" }, "devDependencies": { "@babel/cli": "^7.12.10", @@ -91,6 +90,7 @@ "npm-run-all": "^4.1.5", "prettier": "^2.2.1", "sass": "^1.32.0", + "semver": "^7.3.4", "standard-version": "^9.1.0", "style-loader": "^2.0.0", "webpack": "^5.20.0" diff --git a/src/utils.js b/src/utils.js index 72d729a8..c2e21d0e 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,7 +1,6 @@ import url from "url"; import path from "path"; -import semver from "semver"; import { klona } from "klona/full"; import async from "neo-async"; @@ -59,26 +58,12 @@ function getSassImplementation(loaderContext, implementation) { return; } - const [implementationName, version] = infoParts; + const [implementationName] = infoParts; if (implementationName === "dart-sass") { - if (!semver.satisfies(version, "^1.3.0")) { - loaderContext.emitError( - new Error(`Dart Sass version ${version} is incompatible with ^1.3.0.`) - ); - } - // eslint-disable-next-line consistent-return return resolvedImplementation; } else if (implementationName === "node-sass") { - if (!semver.satisfies(version, "^4.0.0 || ^5.0.0")) { - loaderContext.emitError( - new Error( - `Node Sass version ${version} is incompatible with ^4.0.0 || ^5.0.0.` - ) - ); - } - // eslint-disable-next-line consistent-return return resolvedImplementation; } @@ -230,7 +215,7 @@ async function getSassOptions( // - ~@org/package // - ~@org/package/ const isModuleImport = /^~([^/]+|[^/]+\/|@[^/]+[/][^/]+|@[^/]+\/?|@[^/]+[/][^/]+\/)$/; -const moduleRequestRegex = /^[^?]*~/; +const MODULE_REQUEST_REGEX = /^[^?]*~/; /** * When `sass`/`node-sass` tries to resolve an import, it uses a special algorithm. @@ -255,7 +240,9 @@ function getPossibleRequests( // In case there is module request, send this to webpack resolver if (forWebpackResolver) { - request = request.replace(moduleRequestRegex, ""); + if (MODULE_REQUEST_REGEX.test(url)) { + request = request.replace(MODULE_REQUEST_REGEX, ""); + } if (isModuleImport.test(url)) { request = request[request.length - 1] === "/" ? request : `${request}/`; diff --git a/test/__snapshots__/implementation-option.test.js.snap b/test/__snapshots__/implementation-option.test.js.snap index f4651df8..20b62220 100644 --- a/test/__snapshots__/implementation-option.test.js.snap +++ b/test/__snapshots__/implementation-option.test.js.snap @@ -30,15 +30,6 @@ Unknown Sass implementation \\"strange-sass\\".", exports[`implementation option should throw an error on an unknown sass implementation: warnings 1`] = `Array []`; -exports[`implementation option should throw an error when the "info" is unparseable #2: errors 1`] = ` -Array [ - "ModuleError: Module Error (from ../src/cjs.js): -Node Sass version 1 is incompatible with ^4.0.0 || ^5.0.0.", -] -`; - -exports[`implementation option should throw an error when the "info" is unparseable #2: warnings 1`] = `Array []`; - exports[`implementation option should throw an error when the "info" is unparseable: errors 1`] = ` Array [ "ModuleError: Module Error (from ../src/cjs.js): @@ -48,24 +39,6 @@ Unknown Sass implementation \\"asdfj\\".", exports[`implementation option should throw an error when the "info" is unparseable: warnings 1`] = `Array []`; -exports[`implementation option should throw an error when the "node-sass" package is an incompatible version: errors 1`] = ` -Array [ - "ModuleError: Module Error (from ../src/cjs.js): -Node Sass version 3.0.0 is incompatible with ^4.0.0 || ^5.0.0.", -] -`; - -exports[`implementation option should throw an error when the "node-sass" package is an incompatible version: warnings 1`] = `Array []`; - -exports[`implementation option should throw an error when the "sass" package is an incompatible version: errors 1`] = ` -Array [ - "ModuleError: Module Error (from ../src/cjs.js): -Dart Sass version 1.2.0 is incompatible with ^1.3.0.", -] -`; - -exports[`implementation option should throw an error when the "sass" package is an incompatible version: warnings 1`] = `Array []`; - exports[`implementation option should throw error when the "info" does not exist: errors 1`] = ` Array [ "ModuleError: Module Error (from ../src/cjs.js): diff --git a/test/implementation-option.test.js b/test/implementation-option.test.js index 16e783fd..7ac7712b 100644 --- a/test/implementation-option.test.js +++ b/test/implementation-option.test.js @@ -74,36 +74,6 @@ describe("implementation option", () => { expect(dartSassSpy).toHaveBeenCalledTimes(1); }); - it('should throw an error when the "node-sass" package is an incompatible version', async () => { - const testId = getTestId("language", "scss"); - const options = { - implementation: Object.assign({}, nodeSass, { - info: "node-sass\t3.0.0", - }), - }; - - const compiler = getCompiler(testId, { loader: { options } }); - const stats = await compile(compiler); - - expect(getWarnings(stats)).toMatchSnapshot("warnings"); - expect(getErrors(stats)).toMatchSnapshot("errors"); - }); - - it('should throw an error when the "sass" package is an incompatible version', async () => { - const testId = getTestId("language", "scss"); - const options = { - implementation: Object.assign({}, dartSass, { - info: "dart-sass\t1.2.0", - }), - }; - - const compiler = getCompiler(testId, { loader: { options } }); - const stats = await compile(compiler); - - expect(getWarnings(stats)).toMatchSnapshot("warnings"); - expect(getErrors(stats)).toMatchSnapshot("errors"); - }); - it("should throw an error on an unknown sass implementation", async () => { const testId = getTestId("language", "scss"); const options = { @@ -132,19 +102,6 @@ describe("implementation option", () => { expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should throw an error when the "info" is unparseable #2', async () => { - const testId = getTestId("language", "scss"); - const options = { - implementation: Object.assign({}, nodeSass, { info: "node-sass\t1" }), - }; - - const compiler = getCompiler(testId, { loader: { options } }); - const stats = await compile(compiler); - - expect(getWarnings(stats)).toMatchSnapshot("warnings"); - expect(getErrors(stats)).toMatchSnapshot("errors"); - }); - it('should throw error when the "info" does not exist', async () => { const testId = getTestId("language", "scss"); const options = {