@gjsify/lightningcss-wasm 0.4.28 → 0.4.30
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/package.json +3 -3
- package/src/async.mjs +57 -51
- package/src/browserslistToTargets.js +35 -35
- package/src/composeVisitors.js +346 -346
- package/src/flags.js +24 -24
- package/src/index.mjs +47 -47
- package/src/napi-wasm.mjs +1338 -1323
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/lightningcss-wasm",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.30",
|
|
4
4
|
"description": "Phase D-2 POC: GJS-compatible loader for the lightningcss WASM bundle. Re-exports the `lightningcss-wasm` npm package's transform/bundle/bundleAsync API on top of SpiderMonkey 140's synchronous `new WebAssembly.Module/Instance` constructors. Reads the .wasm via @gjsify/fs (or Node's native fs), resolves randomness via globalThis.crypto. No WASI, no SharedArrayBuffer — single-shot CSS pipeline. Intended as the WASM-track counterpart to `@gjsify/lightningcss-native`; the better of the two wins the slot in `@gjsify/rolldown-plugin-gjsify`'s cssAsStringPlugin (see Phase D-2 decision matrix).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.mjs",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"napi-wasm"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@gjsify/fs": "^0.4.
|
|
33
|
-
"@gjsify/webcrypto": "^0.4.
|
|
32
|
+
"@gjsify/fs": "^0.4.30",
|
|
33
|
+
"@gjsify/webcrypto": "^0.4.30"
|
|
34
34
|
},
|
|
35
35
|
"author": "Pascal Garber <pascal@artandcode.studio>",
|
|
36
36
|
"license": "MIT"
|
package/src/async.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
let cur_await_promise_sync;
|
|
2
2
|
export function await_promise_sync(promise_addr, result_addr, error_addr) {
|
|
3
|
-
|
|
3
|
+
cur_await_promise_sync(promise_addr, result_addr, error_addr);
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
const State = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
None: 0,
|
|
8
|
+
Unwinding: 1,
|
|
9
|
+
Rewinding: 2,
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
// This uses Binaryen's Asyncify transform to suspend native code execution while a promise is resolving.
|
|
@@ -18,57 +18,63 @@ const State = {
|
|
|
18
18
|
// See the docs in https://github.com/WebAssembly/binaryen/blob/main/src/passes/Asyncify.cpp
|
|
19
19
|
// The code here is also partially based on https://github.com/GoogleChromeLabs/asyncify
|
|
20
20
|
export function createBundleAsync(env) {
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
let { instance, exports } = env;
|
|
22
|
+
let {
|
|
23
|
+
asyncify_get_state,
|
|
24
|
+
asyncify_start_unwind,
|
|
25
|
+
asyncify_stop_unwind,
|
|
26
|
+
asyncify_start_rewind,
|
|
27
|
+
asyncify_stop_rewind,
|
|
28
|
+
} = instance.exports;
|
|
23
29
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
// allocate __asyncify_data
|
|
31
|
+
// Stack data goes right after the initial descriptor.
|
|
32
|
+
let DATA_ADDR = instance.exports.napi_wasm_malloc(8 + 4096);
|
|
33
|
+
let DATA_START = DATA_ADDR + 8;
|
|
34
|
+
let DATA_END = DATA_ADDR + 8 + 4096;
|
|
35
|
+
new Int32Array(env.memory.buffer, DATA_ADDR).set([DATA_START, DATA_END]);
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
function assertNoneState() {
|
|
38
|
+
if (asyncify_get_state() !== State.None) {
|
|
39
|
+
throw new Error(`Invalid async state ${asyncify_get_state()}, expected 0.`);
|
|
40
|
+
}
|
|
34
41
|
}
|
|
35
|
-
}
|
|
36
42
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
let promise, result, error;
|
|
44
|
+
cur_await_promise_sync = (promise_addr, result_addr, error_addr) => {
|
|
45
|
+
let state = asyncify_get_state();
|
|
46
|
+
if (state === State.Rewinding) {
|
|
47
|
+
asyncify_stop_rewind();
|
|
48
|
+
if (result != null) {
|
|
49
|
+
env.createValue(result, result_addr);
|
|
50
|
+
}
|
|
51
|
+
if (error != null) {
|
|
52
|
+
env.createValue(error, error_addr);
|
|
53
|
+
}
|
|
54
|
+
promise = result = error = null;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
assertNoneState();
|
|
58
|
+
promise = env.get(promise_addr);
|
|
59
|
+
asyncify_start_unwind(DATA_ADDR);
|
|
60
|
+
};
|
|
55
61
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
return async function bundleAsync(options) {
|
|
63
|
+
assertNoneState();
|
|
64
|
+
let res = exports.bundle(options);
|
|
65
|
+
while (asyncify_get_state() === State.Unwinding) {
|
|
66
|
+
asyncify_stop_unwind();
|
|
67
|
+
try {
|
|
68
|
+
result = await promise;
|
|
69
|
+
} catch (err) {
|
|
70
|
+
error = err;
|
|
71
|
+
}
|
|
72
|
+
assertNoneState();
|
|
73
|
+
asyncify_start_rewind(DATA_ADDR);
|
|
74
|
+
res = exports.bundle(options);
|
|
75
|
+
}
|
|
70
76
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
assertNoneState();
|
|
78
|
+
return res;
|
|
79
|
+
};
|
|
74
80
|
}
|
|
@@ -1,48 +1,48 @@
|
|
|
1
1
|
const BROWSER_MAPPING = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
and_chr: 'chrome',
|
|
3
|
+
and_ff: 'firefox',
|
|
4
|
+
ie_mob: 'ie',
|
|
5
|
+
op_mob: 'opera',
|
|
6
|
+
and_qq: null,
|
|
7
|
+
and_uc: null,
|
|
8
|
+
baidu: null,
|
|
9
|
+
bb: null,
|
|
10
|
+
kaios: null,
|
|
11
|
+
op_mini: null,
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
function browserslistToTargets(browserslist) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
let targets = {};
|
|
16
|
+
for (let browser of browserslist) {
|
|
17
|
+
let [name, v] = browser.split(' ');
|
|
18
|
+
if (BROWSER_MAPPING[name] === null) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let version = parseVersion(v);
|
|
23
|
+
if (version == null) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (targets[name] == null || version < targets[name]) {
|
|
28
|
+
targets[name] = version;
|
|
29
|
+
}
|
|
20
30
|
}
|
|
21
31
|
|
|
22
|
-
|
|
23
|
-
if (version == null) {
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (targets[name] == null || version < targets[name]) {
|
|
28
|
-
targets[name] = version;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return targets;
|
|
32
|
+
return targets;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
function parseVersion(version) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
let [major, minor = 0, patch = 0] = version
|
|
37
|
+
.split('-')[0]
|
|
38
|
+
.split('.')
|
|
39
|
+
.map((v) => parseInt(v, 10));
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
return (major << 16) | (minor << 8) | patch;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
export {browserslistToTargets};
|
|
48
|
+
export { browserslistToTargets };
|