Skip to content

Commit 4ca004b

Browse files
fix: disabled auto importing fiber on node >= 16 due incompatibility problems (#950)
1 parent 5ec86a5 commit 4ca004b

13 files changed

+143
-44
lines changed

.eslintrc.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
module.exports = {
22
root: true,
33
extends: ["@webpack-contrib/eslint-config-webpack", "prettier"],
4+
parserOptions: {
5+
ecmaVersion: 2020,
6+
},
47
};

.github/workflows/nodejs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
strategy:
5656
matrix:
5757
os: [ubuntu-latest, windows-latest, macos-latest]
58-
node-version: [10.x, 12.x, 14.x]
58+
node-version: [10.x, 12.x, 14.x, 16.x]
5959
webpack-version: [latest]
6060

6161
runs-on: ${{ matrix.os }}

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ module.exports = {
196196
Note that when using `sass` (`Dart Sass`), **synchronous compilation is twice as fast as asynchronous compilation** by default, due to the overhead of asynchronous callbacks.
197197
To avoid this overhead, you can use the [fibers](https://www.npmjs.com/package/fibers) package to call asynchronous importers from the synchronous code path.
198198

199-
We automatically inject the [`fibers`](https://github.com/laverdet/node-fibers) package (setup `sassOptions.fiber`) if is possible (i.e. you need install the [`fibers`](https://github.com/laverdet/node-fibers) package).
199+
We automatically inject the [`fibers`](https://github.com/laverdet/node-fibers) package (setup `sassOptions.fiber`) for `Node.js` less v16.0.0 if is possible (i.e. you need install the [`fibers`](https://github.com/laverdet/node-fibers) package).
200+
201+
> Fibers is not compatible with `Node.js` v16.0.0 or later ([see introduction to readme](https://github.com/laverdet/node-fibers)).
200202
201203
**package.json**
202204

package-lock.json

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"lint-staged": "^11.0.0",
8585
"material-components-web": "^8.0.0",
8686
"memfs": "^3.2.2",
87-
"node-sass": "^5.0.0",
87+
"node-sass": "^6.0.0",
8888
"node-sass-glob-importer": "^5.3.2",
8989
"npm-run-all": "^4.1.5",
9090
"prettier": "^2.3.0",

src/utils.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ function proxyCustomImporters(importers, loaderContext) {
8888
);
8989
}
9090

91+
function isSupportedFibers() {
92+
const [nodeVersion] = process.versions.node.split(".");
93+
94+
return Number(nodeVersion) < 16;
95+
}
96+
9197
/**
9298
* Derives the sass options from the loader context and normalizes its values with sane defaults.
9399
*
@@ -115,7 +121,7 @@ async function getSassOptions(
115121

116122
const isDartSass = implementation.info.includes("dart-sass");
117123

118-
if (isDartSass) {
124+
if (isDartSass && isSupportedFibers()) {
119125
const shouldTryToResolveFibers = !options.fiber && options.fiber !== false;
120126

121127
if (shouldTryToResolveFibers) {
@@ -569,4 +575,5 @@ export {
569575
getWebpackImporter,
570576
getRenderFunctionFromSassImplementation,
571577
normalizeSourceMap,
578+
isSupportedFibers,
572579
};

test/additionalData-option.test.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import nodeSass from "node-sass";
22
import dartSass from "sass";
3-
import Fiber from "fibers";
3+
4+
import { isSupportedFibers } from "../src/utils";
45

56
import {
67
compile,
@@ -13,13 +14,23 @@ import {
1314
getWarnings,
1415
} from "./helpers";
1516

17+
let Fiber;
1618
const implementations = [nodeSass, dartSass];
1719
const syntaxStyles = ["scss", "sass"];
1820

1921
describe("additionalData option", () => {
22+
beforeAll(async () => {
23+
if (isSupportedFibers()) {
24+
const { default: fibers } = await import("fibers");
25+
Fiber = fibers;
26+
}
27+
});
28+
2029
beforeEach(() => {
21-
// The `sass` (`Dart Sass`) package modify the `Function` prototype, but the `jest` lose a prototype
22-
Object.setPrototypeOf(Fiber, Function.prototype);
30+
if (isSupportedFibers()) {
31+
// The `sass` (`Dart Sass`) package modify the `Function` prototype, but the `jest` lose a prototype
32+
Object.setPrototypeOf(Fiber, Function.prototype);
33+
}
2334
});
2435

2536
implementations.forEach((implementation) => {

test/implementation-option.test.js

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import nodeSass from "node-sass";
22
import dartSass from "sass";
3-
import Fiber from "fibers";
3+
4+
import { isSupportedFibers } from "../src/utils";
45

56
import {
67
compile,
@@ -12,15 +13,24 @@ import {
1213
getWarnings,
1314
} from "./helpers";
1415

15-
const implementations = [nodeSass, dartSass];
16-
1716
jest.setTimeout(30000);
1817

18+
let Fiber;
19+
const implementations = [nodeSass, dartSass];
20+
1921
describe("implementation option", () => {
22+
beforeAll(async () => {
23+
if (isSupportedFibers()) {
24+
const { default: fibers } = await import("fibers");
25+
Fiber = fibers;
26+
}
27+
});
28+
2029
beforeEach(() => {
21-
// The `sass` (`Dart Sass`) package modify the `Function` prototype, but the `jest` lose a prototype
22-
Object.setPrototypeOf(Fiber, Function.prototype);
23-
jest.clearAllMocks();
30+
if (isSupportedFibers()) {
31+
// The `sass` (`Dart Sass`) package modify the `Function` prototype, but the `jest` lose a prototype
32+
Object.setPrototypeOf(Fiber, Function.prototype);
33+
}
2434
});
2535

2636
implementations.forEach((implementation) => {
@@ -51,6 +61,9 @@ describe("implementation option", () => {
5161
expect(nodeSassSpy).toHaveBeenCalledTimes(0);
5262
expect(dartSassSpy).toHaveBeenCalledTimes(1);
5363
}
64+
65+
nodeSassSpy.mockRestore();
66+
dartSassSpy.mockRestore();
5467
});
5568
});
5669

@@ -72,6 +85,9 @@ describe("implementation option", () => {
7285

7386
expect(nodeSassSpy).toHaveBeenCalledTimes(0);
7487
expect(dartSassSpy).toHaveBeenCalledTimes(1);
88+
89+
nodeSassSpy.mockRestore();
90+
dartSassSpy.mockRestore();
7591
});
7692

7793
it("should throw an error on an unknown sass implementation", async () => {

test/loader.test.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import path from "path";
22

33
import nodeSass from "node-sass";
44
import dartSass from "sass";
5-
import Fiber from "fibers";
65
import del from "del";
76

7+
import { isSupportedFibers } from "../src/utils";
8+
89
import {
910
compile,
1011
getCodeFromBundle,
@@ -16,15 +17,25 @@ import {
1617
getWarnings,
1718
} from "./helpers";
1819

20+
jest.setTimeout(60000);
21+
22+
let Fiber;
1923
const implementations = [nodeSass, dartSass];
2024
const syntaxStyles = ["scss", "sass"];
2125

22-
jest.setTimeout(60000);
23-
2426
describe("loader", () => {
27+
beforeAll(async () => {
28+
if (isSupportedFibers()) {
29+
const { default: fibers } = await import("fibers");
30+
Fiber = fibers;
31+
}
32+
});
33+
2534
beforeEach(() => {
26-
// The `sass` (`Dart Sass`) package modify the `Function` prototype, but the `jest` lose a prototype
27-
Object.setPrototypeOf(Fiber, Function.prototype);
35+
if (isSupportedFibers()) {
36+
// The `sass` (`Dart Sass`) package modify the `Function` prototype, but the `jest` lose a prototype
37+
Object.setPrototypeOf(Fiber, Function.prototype);
38+
}
2839
});
2940

3041
implementations.forEach((implementation) => {
@@ -420,7 +431,10 @@ describe("loader", () => {
420431
implementation: getImplementationByName(implementationName),
421432
};
422433
const compiler = getCompiler(testId, {
423-
loader: { options, resolve: { mainFields: ["custom-sass", "..."] } },
434+
loader: {
435+
options,
436+
resolve: { mainFields: ["custom-sass", "..."] },
437+
},
424438
});
425439
const stats = await compile(compiler);
426440
const codeFromBundle = getCodeFromBundle(stats, compiler);

test/sassOptions-option.test.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import globImporter from "node-sass-glob-importer";
44
import semver from "semver";
55
import nodeSass from "node-sass";
66
import dartSass from "sass";
7-
import Fiber from "fibers";
7+
8+
import { isSupportedFibers } from "../src/utils";
89

910
import {
1011
compile,
@@ -19,15 +20,25 @@ import {
1920
getCompiler,
2021
} from "./helpers";
2122

23+
jest.setTimeout(30000);
24+
25+
let Fiber;
2226
const implementations = [nodeSass, dartSass];
2327
const syntaxStyles = ["scss", "sass"];
2428

25-
jest.setTimeout(30000);
26-
2729
describe("sassOptions option", () => {
30+
beforeAll(async () => {
31+
if (isSupportedFibers()) {
32+
const { default: fibers } = await import("fibers");
33+
Fiber = fibers;
34+
}
35+
});
36+
2837
beforeEach(() => {
29-
// The `sass` (`Dart Sass`) package modify the `Function` prototype, but the `jest` lose a prototype
30-
Object.setPrototypeOf(Fiber, Function.prototype);
38+
if (isSupportedFibers()) {
39+
// The `sass` (`Dart Sass`) package modify the `Function` prototype, but the `jest` lose a prototype
40+
Object.setPrototypeOf(Fiber, Function.prototype);
41+
}
3142
});
3243

3344
implementations.forEach((implementation) => {
@@ -371,7 +382,8 @@ describe("sassOptions option", () => {
371382

372383
if (
373384
implementationName === "dart-sass" &&
374-
semver.satisfies(process.version, ">= 10")
385+
semver.satisfies(process.version, ">= 10") &&
386+
isSupportedFibers()
375387
) {
376388
expect(dartSassSpy.mock.calls[0][0]).toHaveProperty("fiber");
377389
}
@@ -398,7 +410,8 @@ describe("sassOptions option", () => {
398410

399411
if (
400412
implementationName === "dart-sass" &&
401-
semver.satisfies(process.version, ">= 10")
413+
semver.satisfies(process.version, ">= 10") &&
414+
isSupportedFibers()
402415
) {
403416
expect(dartSassSpy.mock.calls[0][0]).toHaveProperty("fiber");
404417
}

test/sourceMap-options.test.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import path from "path";
33

44
import nodeSass from "node-sass";
55
import dartSass from "sass";
6-
import Fiber from "fibers";
6+
7+
import { isSupportedFibers } from "../src/utils";
78

89
import {
910
compile,
@@ -15,13 +16,23 @@ import {
1516
getWarnings,
1617
} from "./helpers";
1718

19+
let Fiber;
1820
const implementations = [nodeSass, dartSass];
1921
const syntaxStyles = ["scss", "sass"];
2022

2123
describe("sourceMap option", () => {
24+
beforeAll(async () => {
25+
if (isSupportedFibers()) {
26+
const { default: fibers } = await import("fibers");
27+
Fiber = fibers;
28+
}
29+
});
30+
2231
beforeEach(() => {
23-
// The `sass` (`Dart Sass`) package modify the `Function` prototype, but the `jest` lose a prototype
24-
Object.setPrototypeOf(Fiber, Function.prototype);
32+
if (isSupportedFibers()) {
33+
// The `sass` (`Dart Sass`) package modify the `Function` prototype, but the `jest` lose a prototype
34+
Object.setPrototypeOf(Fiber, Function.prototype);
35+
}
2536
});
2637

2738
implementations.forEach((implementation) => {

test/validate-options.test.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Fiber from "fibers";
1+
import { isSupportedFibers } from "../src/utils";
22

33
import {
44
getCompiler,
@@ -7,10 +7,21 @@ import {
77
getImplementationByName,
88
} from "./helpers/index";
99

10+
let Fiber;
11+
1012
describe("validate options", () => {
13+
beforeAll(async () => {
14+
if (isSupportedFibers()) {
15+
const { default: fibers } = await import("fibers");
16+
Fiber = fibers;
17+
}
18+
});
19+
1120
beforeEach(() => {
12-
// The `sass` (`Dart Sass`) package modify the `Function` prototype, but the `jest` lose a prototype
13-
Object.setPrototypeOf(Fiber, Function.prototype);
21+
if (isSupportedFibers()) {
22+
// The `sass` (`Dart Sass`) package modify the `Function` prototype, but the `jest` lose a prototype
23+
Object.setPrototypeOf(Fiber, Function.prototype);
24+
}
1425
});
1526

1627
const tests = {

0 commit comments

Comments
 (0)