@utoo/web 1.0.6 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/installServiceWorker.js +6 -3
- package/esm/serviceWorker.js +14 -17
- package/esm/utoo/index.d.ts +6 -6
- package/esm/utoo/index.js +38 -38
- package/esm/utoo/index_bg.wasm +0 -0
- package/esm/webpackLoaders/loaders/less-loader/index.js +7 -12
- package/esm/webpackLoaders/loaders/less-loader/options.json +1 -3
- package/esm/webpackLoaders/loaders/less-loader/utils.js +14 -34
- package/esm/webpackLoaders/workerContent.d.ts +1 -1
- package/esm/webpackLoaders/workerContent.js +1 -1
- package/package.json +1 -1
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { ServiceWorkerHandShake } from "./message";
|
|
2
2
|
export async function installServiceWorker(url, scope, targetDirToCwd) {
|
|
3
|
-
const
|
|
3
|
+
const swUrl = new URL(url, window.location.href);
|
|
4
|
+
swUrl.searchParams.set("scope", scope);
|
|
5
|
+
if (targetDirToCwd) {
|
|
6
|
+
swUrl.searchParams.set("targetDirToCwd", targetDirToCwd);
|
|
7
|
+
}
|
|
8
|
+
const registration = await navigator.serviceWorker.register(swUrl.toString(), {
|
|
4
9
|
scope: "/",
|
|
5
10
|
});
|
|
6
11
|
return new Promise((resolve) => {
|
|
7
12
|
function sendMessage(sw) {
|
|
8
13
|
sw.postMessage({
|
|
9
14
|
[ServiceWorkerHandShake]: true,
|
|
10
|
-
scope,
|
|
11
|
-
targetDirToCwd,
|
|
12
15
|
});
|
|
13
16
|
resolve();
|
|
14
17
|
}
|
package/esm/serviceWorker.js
CHANGED
|
@@ -5,8 +5,9 @@ let _promise = new Promise((resolve) => {
|
|
|
5
5
|
_resolve = resolve;
|
|
6
6
|
});
|
|
7
7
|
let _projectEndpoint;
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const params = new URLSearchParams(self.location.search);
|
|
9
|
+
const _serviceWorkerScope = params.get("scope");
|
|
10
|
+
const _targetDirToCwd = params.get("targetDirToCwd");
|
|
10
11
|
self.addEventListener("install", (event) => {
|
|
11
12
|
event.waitUntil(self.skipWaiting());
|
|
12
13
|
});
|
|
@@ -15,27 +16,23 @@ self.addEventListener("activate", (event) => {
|
|
|
15
16
|
});
|
|
16
17
|
self.addEventListener("message", (event) => {
|
|
17
18
|
if (event.data && event.data[ServiceWorkerHandShake] === true) {
|
|
18
|
-
_serviceWorkerScope = event.data.scope;
|
|
19
|
-
_targetDirToCwd = event.data.targetDirToCwd;
|
|
20
19
|
_projectEndpoint = Project.fork(new MessageChannel(), event.source);
|
|
21
20
|
_resolve();
|
|
22
21
|
}
|
|
23
22
|
});
|
|
24
23
|
self.addEventListener("fetch", (event) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
let { url: urlStr } = event.request;
|
|
25
|
+
let url = new URL(urlStr);
|
|
26
|
+
if (typeof _serviceWorkerScope === "string") {
|
|
27
|
+
if (url.pathname.startsWith(_serviceWorkerScope)) {
|
|
28
|
+
event.respondWith((async () => {
|
|
29
|
+
await _promise;
|
|
30
|
+
const relativePathToCwd = (_targetDirToCwd !== null && _targetDirToCwd !== void 0 ? _targetDirToCwd : ".") +
|
|
31
|
+
url.pathname.replace(_serviceWorkerScope, "");
|
|
32
|
+
return readFileFromProject(relativePathToCwd);
|
|
33
|
+
})());
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
return fetch(event.request);
|
|
37
|
-
}
|
|
38
|
-
})());
|
|
35
|
+
}
|
|
39
36
|
});
|
|
40
37
|
async function readFileFromProject(projectPath) {
|
|
41
38
|
try {
|
package/esm/utoo/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {number} worker_id
|
|
3
|
+
* @returns {Promise<string>}
|
|
4
|
+
*/
|
|
5
|
+
export function recvMessageInWorker(worker_id: number): Promise<string>;
|
|
1
6
|
/**
|
|
2
7
|
* @returns {Promise<WorkerTermination>}
|
|
3
8
|
*/
|
|
@@ -14,11 +19,6 @@ export function notifyWorkerAck(task_id: number, worker_id: number): Promise<voi
|
|
|
14
19
|
* @returns {Promise<void>}
|
|
15
20
|
*/
|
|
16
21
|
export function sendTaskMessage(task_id: number, message: string): Promise<void>;
|
|
17
|
-
/**
|
|
18
|
-
* @param {number} worker_id
|
|
19
|
-
* @returns {Promise<string>}
|
|
20
|
-
*/
|
|
21
|
-
export function recvMessageInWorker(worker_id: number): Promise<string>;
|
|
22
22
|
/**
|
|
23
23
|
* @param {string} pool_id
|
|
24
24
|
* @returns {Promise<number>}
|
|
@@ -28,11 +28,11 @@ export function recvWorkerRequest(pool_id: string): Promise<number>;
|
|
|
28
28
|
* @returns {Promise<PoolOptions>}
|
|
29
29
|
*/
|
|
30
30
|
export function recvPoolRequest(): Promise<PoolOptions>;
|
|
31
|
+
export function init_pack(): void;
|
|
31
32
|
/**
|
|
32
33
|
* @param {string} filter
|
|
33
34
|
*/
|
|
34
35
|
export function init_log_filter(filter: string): void;
|
|
35
|
-
export function init_pack(): void;
|
|
36
36
|
/**
|
|
37
37
|
* Entry point for web workers
|
|
38
38
|
* @param {number} ptr
|
package/esm/utoo/index.js
CHANGED
|
@@ -239,6 +239,14 @@ function makeClosure(arg0, arg1, dtor, f) {
|
|
|
239
239
|
CLOSURE_DTORS.register(real, state, state);
|
|
240
240
|
return real;
|
|
241
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* @param {number} worker_id
|
|
244
|
+
* @returns {Promise<string>}
|
|
245
|
+
*/
|
|
246
|
+
export function recvMessageInWorker(worker_id) {
|
|
247
|
+
const ret = wasm.recvMessageInWorker(worker_id);
|
|
248
|
+
return takeObject(ret);
|
|
249
|
+
}
|
|
242
250
|
/**
|
|
243
251
|
* @returns {Promise<WorkerTermination>}
|
|
244
252
|
*/
|
|
@@ -266,14 +274,6 @@ export function sendTaskMessage(task_id, message) {
|
|
|
266
274
|
const ret = wasm.sendTaskMessage(task_id, ptr0, len0);
|
|
267
275
|
return takeObject(ret);
|
|
268
276
|
}
|
|
269
|
-
/**
|
|
270
|
-
* @param {number} worker_id
|
|
271
|
-
* @returns {Promise<string>}
|
|
272
|
-
*/
|
|
273
|
-
export function recvMessageInWorker(worker_id) {
|
|
274
|
-
const ret = wasm.recvMessageInWorker(worker_id);
|
|
275
|
-
return takeObject(ret);
|
|
276
|
-
}
|
|
277
277
|
/**
|
|
278
278
|
* @param {string} pool_id
|
|
279
279
|
* @returns {Promise<number>}
|
|
@@ -291,6 +291,9 @@ export function recvPoolRequest() {
|
|
|
291
291
|
const ret = wasm.recvPoolRequest();
|
|
292
292
|
return takeObject(ret);
|
|
293
293
|
}
|
|
294
|
+
export function init_pack() {
|
|
295
|
+
wasm.init_pack();
|
|
296
|
+
}
|
|
294
297
|
/**
|
|
295
298
|
* @param {string} filter
|
|
296
299
|
*/
|
|
@@ -299,9 +302,6 @@ export function init_log_filter(filter) {
|
|
|
299
302
|
const len0 = WASM_VECTOR_LEN;
|
|
300
303
|
wasm.init_log_filter(ptr0, len0);
|
|
301
304
|
}
|
|
302
|
-
export function init_pack() {
|
|
303
|
-
wasm.init_pack();
|
|
304
|
-
}
|
|
305
305
|
function passArray8ToWasm0(arg, malloc) {
|
|
306
306
|
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
307
307
|
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
@@ -315,8 +315,8 @@ function passArray8ToWasm0(arg, malloc) {
|
|
|
315
315
|
export function wasm_thread_entry_point(ptr) {
|
|
316
316
|
wasm.wasm_thread_entry_point(ptr);
|
|
317
317
|
}
|
|
318
|
-
function
|
|
319
|
-
wasm.__wbindgen_export_6(arg0, arg1);
|
|
318
|
+
function __wbg_adapter_6(arg0, arg1, arg2) {
|
|
319
|
+
wasm.__wbindgen_export_6(arg0, arg1, addHeapObject(arg2));
|
|
320
320
|
}
|
|
321
321
|
let stack_pointer = 128;
|
|
322
322
|
function addBorrowedObject(obj) {
|
|
@@ -325,7 +325,7 @@ function addBorrowedObject(obj) {
|
|
|
325
325
|
heap[--stack_pointer] = obj;
|
|
326
326
|
return stack_pointer;
|
|
327
327
|
}
|
|
328
|
-
function
|
|
328
|
+
function __wbg_adapter_13(arg0, arg1, arg2) {
|
|
329
329
|
try {
|
|
330
330
|
wasm.__wbindgen_export_7(arg0, arg1, addBorrowedObject(arg2));
|
|
331
331
|
}
|
|
@@ -333,10 +333,10 @@ function __wbg_adapter_15(arg0, arg1, arg2) {
|
|
|
333
333
|
heap[stack_pointer++] = undefined;
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
|
-
function
|
|
337
|
-
wasm.__wbindgen_export_8(arg0, arg1
|
|
336
|
+
function __wbg_adapter_16(arg0, arg1) {
|
|
337
|
+
wasm.__wbindgen_export_8(arg0, arg1);
|
|
338
338
|
}
|
|
339
|
-
function
|
|
339
|
+
function __wbg_adapter_19(arg0, arg1, arg2) {
|
|
340
340
|
wasm.__wbindgen_export_9(arg0, arg1, addHeapObject(arg2));
|
|
341
341
|
}
|
|
342
342
|
function __wbg_adapter_94(arg0, arg1, arg2, arg3) {
|
|
@@ -1620,19 +1620,24 @@ function __wbg_get_imports() {
|
|
|
1620
1620
|
return ret;
|
|
1621
1621
|
}, arguments);
|
|
1622
1622
|
};
|
|
1623
|
+
imports.wbg.__wbindgen_cast_12af9e1632226a2a = function (arg0, arg1) {
|
|
1624
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 8603, function: Function { arguments: [Ref(NamedExternref("MessageEvent"))], shim_idx: 8626, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
1625
|
+
const ret = makeMutClosure(arg0, arg1, 8603, __wbg_adapter_13);
|
|
1626
|
+
return addHeapObject(ret);
|
|
1627
|
+
};
|
|
1623
1628
|
imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function (arg0, arg1) {
|
|
1624
1629
|
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
1625
1630
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
1626
1631
|
return addHeapObject(ret);
|
|
1627
1632
|
};
|
|
1628
|
-
imports.wbg.
|
|
1629
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx:
|
|
1630
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
1633
|
+
imports.wbg.__wbindgen_cast_26f8fe7fb5e9a165 = function (arg0, arg1) {
|
|
1634
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 8621, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 8622, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
1635
|
+
const ret = makeMutClosure(arg0, arg1, 8621, __wbg_adapter_19);
|
|
1631
1636
|
return addHeapObject(ret);
|
|
1632
1637
|
};
|
|
1633
|
-
imports.wbg.
|
|
1634
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx:
|
|
1635
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
1638
|
+
imports.wbg.__wbindgen_cast_341c6edfb226ca8c = function (arg0, arg1) {
|
|
1639
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 8621, function: Function { arguments: [Externref], shim_idx: 8622, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
1640
|
+
const ret = makeMutClosure(arg0, arg1, 8621, __wbg_adapter_19);
|
|
1636
1641
|
return addHeapObject(ret);
|
|
1637
1642
|
};
|
|
1638
1643
|
imports.wbg.__wbindgen_cast_4625c577ab2ec9ee = function (arg0) {
|
|
@@ -1642,12 +1647,12 @@ function __wbg_get_imports() {
|
|
|
1642
1647
|
};
|
|
1643
1648
|
imports.wbg.__wbindgen_cast_4c807b347a3d0cbf = function (arg0, arg1) {
|
|
1644
1649
|
// Cast intrinsic for `Closure(Closure { dtor_idx: 599, function: Function { arguments: [], shim_idx: 600, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
1645
|
-
const ret = makeMutClosure(arg0, arg1, 599,
|
|
1650
|
+
const ret = makeMutClosure(arg0, arg1, 599, __wbg_adapter_16);
|
|
1646
1651
|
return addHeapObject(ret);
|
|
1647
1652
|
};
|
|
1648
|
-
imports.wbg.
|
|
1649
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx:
|
|
1650
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
1653
|
+
imports.wbg.__wbindgen_cast_60ddcd55e3b8f21d = function (arg0, arg1) {
|
|
1654
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 8621, function: Function { arguments: [], shim_idx: 600, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
1655
|
+
const ret = makeMutClosure(arg0, arg1, 8621, __wbg_adapter_16);
|
|
1651
1656
|
return addHeapObject(ret);
|
|
1652
1657
|
};
|
|
1653
1658
|
imports.wbg.__wbindgen_cast_76322aab70622876 = function (arg0, arg1) {
|
|
@@ -1664,6 +1669,11 @@ function __wbg_get_imports() {
|
|
|
1664
1669
|
const ret = v0;
|
|
1665
1670
|
return addHeapObject(ret);
|
|
1666
1671
|
};
|
|
1672
|
+
imports.wbg.__wbindgen_cast_7d864cd0d8fe5a0e = function (arg0, arg1) {
|
|
1673
|
+
// Cast intrinsic for `Closure(Closure { dtor_idx: 8603, function: Function { arguments: [NamedExternref("Array<any>")], shim_idx: 8604, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
|
|
1674
|
+
const ret = makeClosure(arg0, arg1, 8603, __wbg_adapter_6);
|
|
1675
|
+
return addHeapObject(ret);
|
|
1676
|
+
};
|
|
1667
1677
|
imports.wbg.__wbindgen_cast_9ae0607507abb057 = function (arg0) {
|
|
1668
1678
|
// Cast intrinsic for `I64 -> Externref`.
|
|
1669
1679
|
const ret = arg0;
|
|
@@ -1674,16 +1684,6 @@ function __wbg_get_imports() {
|
|
|
1674
1684
|
const ret = arg0;
|
|
1675
1685
|
return addHeapObject(ret);
|
|
1676
1686
|
};
|
|
1677
|
-
imports.wbg.__wbindgen_cast_ded0188a991d8b3c = function (arg0, arg1) {
|
|
1678
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx: 8680, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 8681, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
1679
|
-
const ret = makeMutClosure(arg0, arg1, 8680, __wbg_adapter_18);
|
|
1680
|
-
return addHeapObject(ret);
|
|
1681
|
-
};
|
|
1682
|
-
imports.wbg.__wbindgen_cast_ffa04fbd359d627f = function (arg0, arg1) {
|
|
1683
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx: 8661, function: Function { arguments: [NamedExternref("Array<any>")], shim_idx: 8662, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
|
|
1684
|
-
const ret = makeClosure(arg0, arg1, 8661, __wbg_adapter_27);
|
|
1685
|
-
return addHeapObject(ret);
|
|
1686
|
-
};
|
|
1687
1687
|
imports.wbg.__wbindgen_link_dd5153a359f2e504 = function (arg0) {
|
|
1688
1688
|
const val = `onmessage = function (ev) {
|
|
1689
1689
|
let [ia, index, value] = ev.data;
|
|
@@ -1708,7 +1708,7 @@ function __wbg_get_imports() {
|
|
|
1708
1708
|
return imports;
|
|
1709
1709
|
}
|
|
1710
1710
|
function __wbg_init_memory(imports, memory) {
|
|
1711
|
-
imports.wbg.memory = memory || new WebAssembly.Memory({ initial:
|
|
1711
|
+
imports.wbg.memory = memory || new WebAssembly.Memory({ initial: 130, maximum: 16384, shared: true });
|
|
1712
1712
|
}
|
|
1713
1713
|
function __wbg_finalize_init(instance, module, thread_stack_size) {
|
|
1714
1714
|
wasm = instance.exports;
|
package/esm/utoo/index_bg.wasm
CHANGED
|
Binary file
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
3
|
+
value: true
|
|
4
4
|
});
|
|
5
5
|
exports.default = void 0;
|
|
6
6
|
var _path = _interopRequireDefault(require("path"));
|
|
7
7
|
var _options = _interopRequireDefault(require("./options.json"));
|
|
8
8
|
var _utils = require("./utils");
|
|
9
|
-
function _interopRequireDefault(e) {
|
|
10
|
-
return e && e.__esModule ? e : { default: e };
|
|
11
|
-
}
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
10
|
async function lessLoader(source) {
|
|
13
11
|
const options = this.getOptions(_options.default);
|
|
14
12
|
const callback = this.async();
|
|
@@ -28,15 +26,12 @@ async function lessLoader(source) {
|
|
|
28
26
|
const useSourceMap = typeof options.sourceMap === "boolean" ? options.sourceMap : this.sourceMap;
|
|
29
27
|
if (useSourceMap) {
|
|
30
28
|
lessOptions.sourceMap = {
|
|
31
|
-
outputSourceFiles: true
|
|
29
|
+
outputSourceFiles: true
|
|
32
30
|
};
|
|
33
31
|
}
|
|
34
32
|
let data = source;
|
|
35
33
|
if (typeof options.additionalData !== "undefined") {
|
|
36
|
-
data =
|
|
37
|
-
typeof options.additionalData === "function"
|
|
38
|
-
? `${await options.additionalData(data, this)}`
|
|
39
|
-
: `${options.additionalData}\n${data}`;
|
|
34
|
+
data = typeof options.additionalData === "function" ? `${await options.additionalData(data, this)}` : `${options.additionalData}\n${data}`;
|
|
40
35
|
}
|
|
41
36
|
const logger = this.getLogger("less-loader");
|
|
42
37
|
const loaderContext = this;
|
|
@@ -64,7 +59,7 @@ async function lessLoader(source) {
|
|
|
64
59
|
},
|
|
65
60
|
debug(message) {
|
|
66
61
|
logger.debug(message);
|
|
67
|
-
}
|
|
62
|
+
}
|
|
68
63
|
};
|
|
69
64
|
implementation.logger.addListener(loggerListener);
|
|
70
65
|
let result;
|
|
@@ -87,7 +82,7 @@ async function lessLoader(source) {
|
|
|
87
82
|
delete lessOptions.pluginManager;
|
|
88
83
|
}
|
|
89
84
|
const { css, imports } = result;
|
|
90
|
-
imports.forEach(
|
|
85
|
+
imports.forEach(item => {
|
|
91
86
|
if ((0, _utils.isUnsupportedUrl)(item)) {
|
|
92
87
|
return;
|
|
93
88
|
}
|
|
@@ -105,4 +100,4 @@ async function lessLoader(source) {
|
|
|
105
100
|
}
|
|
106
101
|
callback(null, css, map);
|
|
107
102
|
}
|
|
108
|
-
var _default =
|
|
103
|
+
var _default = exports.default = lessLoader;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const { type } = require("os");
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
4
|
+
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.errorFactory = errorFactory;
|
|
7
7
|
exports.getLessImplementation = getLessImplementation;
|
|
@@ -9,9 +9,7 @@ exports.getLessOptions = getLessOptions;
|
|
|
9
9
|
exports.isUnsupportedUrl = isUnsupportedUrl;
|
|
10
10
|
exports.normalizeSourceMap = normalizeSourceMap;
|
|
11
11
|
var _path = _interopRequireDefault(require("path"));
|
|
12
|
-
function _interopRequireDefault(e) {
|
|
13
|
-
return e && e.__esModule ? e : { default: e };
|
|
14
|
-
}
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
13
|
/* eslint-disable class-methods-use-this */
|
|
16
14
|
const trailingSlash = /[/\\]$/;
|
|
17
15
|
// This somewhat changed in Less 3.x. Now the file name comes without the
|
|
@@ -44,7 +42,7 @@ function createWebpackLessPlugin(loaderContext, implementation) {
|
|
|
44
42
|
mainFields: ["less", "style", "main", "..."],
|
|
45
43
|
mainFiles: ["index", "..."],
|
|
46
44
|
extensions: [".less", ".css"],
|
|
47
|
-
preferRelative: true
|
|
45
|
+
preferRelative: true
|
|
48
46
|
});
|
|
49
47
|
class WebpackFileManager extends implementation.FileManager {
|
|
50
48
|
supports(filename) {
|
|
@@ -97,8 +95,7 @@ function createWebpackLessPlugin(loaderContext, implementation) {
|
|
|
97
95
|
async loadFile(filename, ...args) {
|
|
98
96
|
let result;
|
|
99
97
|
try {
|
|
100
|
-
if (IS_SPECIAL_MODULE_IMPORT.test(filename) ||
|
|
101
|
-
lessOptions.webpackImporter === "only") {
|
|
98
|
+
if (IS_SPECIAL_MODULE_IMPORT.test(filename) || lessOptions.webpackImporter === "only") {
|
|
102
99
|
const error = new Error();
|
|
103
100
|
error.type = "Next";
|
|
104
101
|
throw error;
|
|
@@ -113,18 +110,13 @@ function createWebpackLessPlugin(loaderContext, implementation) {
|
|
|
113
110
|
result = await this.resolveFilename(filename, ...args);
|
|
114
111
|
}
|
|
115
112
|
catch (webpackResolveError) {
|
|
116
|
-
error.message =
|
|
117
|
-
`Less resolver error:\n${error.message}\n\n` +
|
|
118
|
-
`Webpack resolver error details:\n${webpackResolveError.details}\n\n` +
|
|
119
|
-
`Webpack resolver error missing:\n${webpackResolveError.missing}\n\n`;
|
|
113
|
+
error.message = `Less resolver error:\n${error.message}\n\n` + `Webpack resolver error details:\n${webpackResolveError.details}\n\n` + `Webpack resolver error missing:\n${webpackResolveError.missing}\n\n`;
|
|
120
114
|
return Promise.reject(error);
|
|
121
115
|
}
|
|
122
116
|
loaderContext.addDependency(result);
|
|
123
117
|
return super.loadFile(result, ...args);
|
|
124
118
|
}
|
|
125
|
-
const absoluteFilename = _path.default.isAbsolute(result.filename)
|
|
126
|
-
? result.filename
|
|
127
|
-
: _path.default.resolve(".", result.filename);
|
|
119
|
+
const absoluteFilename = _path.default.isAbsolute(result.filename) ? result.filename : _path.default.resolve(".", result.filename);
|
|
128
120
|
loaderContext.addDependency(_path.default.normalize(absoluteFilename));
|
|
129
121
|
return result;
|
|
130
122
|
}
|
|
@@ -133,7 +125,7 @@ function createWebpackLessPlugin(loaderContext, implementation) {
|
|
|
133
125
|
install(lessInstance, pluginManager) {
|
|
134
126
|
pluginManager.addFileManager(new WebpackFileManager());
|
|
135
127
|
},
|
|
136
|
-
minVersion: [3, 0, 0]
|
|
128
|
+
minVersion: [3, 0, 0]
|
|
137
129
|
};
|
|
138
130
|
}
|
|
139
131
|
/**
|
|
@@ -145,21 +137,16 @@ function createWebpackLessPlugin(loaderContext, implementation) {
|
|
|
145
137
|
* @returns {Object}
|
|
146
138
|
*/
|
|
147
139
|
function getLessOptions(loaderContext, loaderOptions, implementation) {
|
|
148
|
-
const options = typeof loaderOptions.lessOptions === "function"
|
|
149
|
-
? loaderOptions.lessOptions(loaderContext) || {}
|
|
150
|
-
: loaderOptions.lessOptions || {};
|
|
140
|
+
const options = typeof loaderOptions.lessOptions === "function" ? loaderOptions.lessOptions(loaderContext) || {} : loaderOptions.lessOptions || {};
|
|
151
141
|
const lessOptions = {
|
|
152
142
|
plugins: [],
|
|
153
143
|
relativeUrls: true,
|
|
154
144
|
// We need to set the filename because otherwise our WebpackFileManager will receive an undefined path for the entry
|
|
155
145
|
filename: loaderContext.resourcePath,
|
|
156
|
-
...options
|
|
146
|
+
...options
|
|
157
147
|
};
|
|
158
148
|
const plugins = lessOptions.plugins.slice();
|
|
159
|
-
const shouldUseWebpackImporter = typeof loaderOptions.webpackImporter === "boolean" ||
|
|
160
|
-
loaderOptions.webpackImporter === "only"
|
|
161
|
-
? loaderOptions.webpackImporter
|
|
162
|
-
: true;
|
|
149
|
+
const shouldUseWebpackImporter = typeof loaderOptions.webpackImporter === "boolean" || loaderOptions.webpackImporter === "only" ? loaderOptions.webpackImporter : true;
|
|
163
150
|
if (shouldUseWebpackImporter) {
|
|
164
151
|
plugins.unshift(createWebpackLessPlugin(loaderContext, implementation));
|
|
165
152
|
}
|
|
@@ -168,7 +155,7 @@ function getLessOptions(loaderContext, loaderOptions, implementation) {
|
|
|
168
155
|
// eslint-disable-next-line no-param-reassign
|
|
169
156
|
pluginManager.webpackLoaderContext = loaderContext;
|
|
170
157
|
lessOptions.pluginManager = pluginManager;
|
|
171
|
-
}
|
|
158
|
+
}
|
|
172
159
|
});
|
|
173
160
|
lessOptions.plugins = plugins;
|
|
174
161
|
return lessOptions;
|
|
@@ -192,7 +179,7 @@ function normalizeSourceMap(map) {
|
|
|
192
179
|
newMap.sourceRoot = "";
|
|
193
180
|
// `less` returns POSIX paths, that's why we need to transform them back to native paths.
|
|
194
181
|
// eslint-disable-next-line no-param-reassign
|
|
195
|
-
newMap.sources = newMap.sources.map(
|
|
182
|
+
newMap.sources = newMap.sources.map(source => _path.default.normalize(source));
|
|
196
183
|
return newMap;
|
|
197
184
|
}
|
|
198
185
|
function getLessImplementation(loaderContext, implementation) {
|
|
@@ -221,16 +208,9 @@ function getFileExcerptIfPossible(error) {
|
|
|
221
208
|
return excerpt;
|
|
222
209
|
}
|
|
223
210
|
function errorFactory(error) {
|
|
224
|
-
const message = [
|
|
225
|
-
"\n",
|
|
226
|
-
...getFileExcerptIfPossible(error),
|
|
227
|
-
error.message.charAt(0).toUpperCase() + error.message.slice(1),
|
|
228
|
-
error.filename
|
|
229
|
-
? ` Error in ${_path.default.normalize(error.filename)} (line ${error.line}, column ${error.column})`
|
|
230
|
-
: "",
|
|
231
|
-
].join("\n");
|
|
211
|
+
const message = ["\n", ...getFileExcerptIfPossible(error), error.message.charAt(0).toUpperCase() + error.message.slice(1), error.filename ? ` Error in ${_path.default.normalize(error.filename)} (line ${error.line}, column ${error.column})` : ""].join("\n");
|
|
232
212
|
const obj = new Error(message, {
|
|
233
|
-
cause: error
|
|
213
|
+
cause: error
|
|
234
214
|
});
|
|
235
215
|
obj.stack = null;
|
|
236
216
|
return obj;
|