1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | const sass_1 = require("sass");
|
11 | const worker_threads_1 = require("worker_threads");
|
12 | if (!worker_threads_1.parentPort) {
|
13 | throw new Error('Sass worker must be executed as a Worker.');
|
14 | }
|
15 |
|
16 | let { workerImporterPort, importerSignal } = (worker_threads_1.workerData || {});
|
17 | worker_threads_1.parentPort.on('message', (message) => {
|
18 |
|
19 | if (message.init) {
|
20 | workerImporterPort = message.workerImporterPort;
|
21 | importerSignal = message.importerSignal;
|
22 | return;
|
23 | }
|
24 | const { id, hasImporter, options } = message;
|
25 | try {
|
26 | if (hasImporter) {
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | options.importer = function (url, prev) {
|
33 | var _a;
|
34 | Atomics.store(importerSignal, 0, 0);
|
35 |
|
36 | const { fromImport } = this;
|
37 | workerImporterPort.postMessage({ id, url, prev, fromImport });
|
38 | Atomics.wait(importerSignal, 0, 0);
|
39 | return (_a = worker_threads_1.receiveMessageOnPort(workerImporterPort)) === null || _a === void 0 ? void 0 : _a.message;
|
40 | };
|
41 | }
|
42 |
|
43 | const result = sass_1.renderSync(options);
|
44 | worker_threads_1.parentPort === null || worker_threads_1.parentPort === void 0 ? void 0 : worker_threads_1.parentPort.postMessage({ id, result });
|
45 | }
|
46 | catch (error) {
|
47 |
|
48 | const { formatted, file, line, column, message, stack } = error;
|
49 | worker_threads_1.parentPort === null || worker_threads_1.parentPort === void 0 ? void 0 : worker_threads_1.parentPort.postMessage({ id, error: { formatted, file, line, column, message, stack } });
|
50 | }
|
51 | });
|