Skip to content

Commit 6850f6c

Browse files
fix: compatibility with ECMA modules less version (#578)
1 parent 8906924 commit 6850f6c

File tree

12 files changed

+152
-98
lines changed

12 files changed

+152
-98
lines changed

babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = (api) => {
1212
targets: {
1313
node: "18.12.0",
1414
},
15+
exclude: ["transform-dynamic-import"],
1516
},
1617
],
1718
],

package-lock.json

Lines changed: 56 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"fix:js": "npm run lint:js -- --fix",
3939
"fix:prettier": "npm run lint:prettier -- --write",
4040
"fix": "npm-run-all -l fix:js fix:prettier",
41-
"test:only": "cross-env NODE_ENV=test jest",
41+
"test:only": "node --experimental-vm-modules node_modules/jest-cli/bin/jest.js",
4242
"test:watch": "npm run test:only -- --watch",
4343
"test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage",
4444
"pretest": "npm run lint",
@@ -71,7 +71,7 @@
7171
"globals": "^16.3.0",
7272
"husky": "^9.1.3",
7373
"jest": "^30.0.0",
74-
"less": "^4.2.0",
74+
"less": "^4.6.2",
7575
"less-plugin-glob": "^3.0.0",
7676
"lint-staged": "^15.2.7",
7777
"memfs": "^4.9.3",

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async function lessLoader(source) {
1515
let implementation;
1616

1717
try {
18-
implementation = getLessImplementation(this, options.implementation);
18+
implementation = await getLessImplementation(this, options.implementation);
1919
} catch (error) {
2020
callback(error);
2121

@@ -38,7 +38,9 @@ async function lessLoader(source) {
3838

3939
if (useSourceMap) {
4040
lessOptions.sourceMap = {
41+
sourceMapBasepath: "",
4142
outputSourceFiles: true,
43+
disableSourcemapAnnotation: true,
4244
};
4345
}
4446

@@ -123,7 +125,7 @@ async function lessLoader(source) {
123125
typeof result.map === "string" ? JSON.parse(result.map) : result.map;
124126

125127
if (map && useSourceMap) {
126-
map = normalizeSourceMap(map, this.rootContext);
128+
map = normalizeSourceMap(map);
127129
}
128130

129131
callback(null, css, map);

src/utils.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,20 +223,19 @@ function normalizeSourceMap(map) {
223223

224224
newMap.sourceRoot = "";
225225

226-
// `less` returns POSIX paths, that's why we need to transform them back to native paths.
227-
226+
// `less` (old versions) returns POSIX paths, that's why we need to transform them back to native paths.
228227
newMap.sources = newMap.sources.map((source) => path.normalize(source));
229228

230229
return newMap;
231230
}
232231

233-
function getLessImplementation(loaderContext, implementation) {
232+
async function getLessImplementation(loaderContext, implementation) {
234233
let resolvedImplementation = implementation;
235234

236235
if (!implementation || typeof implementation === "string") {
237236
const lessImplPkg = implementation || "less";
238237

239-
resolvedImplementation = require(lessImplPkg);
238+
resolvedImplementation = (await import(lessImplPkg)).default;
240239
}
241240

242241
return resolvedImplementation;

0 commit comments

Comments
 (0)