Simply Oxc plugin build script (#20208)
This commit is contained in:
1 parent
55303a4557
commit
eea6146027
4 files changed
+7
-32
No files matched your search
@@ -33,7 +33,6 @@ const config = {
|
|||||||
ignoreDependencies: [
|
ignoreDependencies: [
|
||||||
"ts-expect",
|
"ts-expect",
|
||||||
"buffer",
|
"buffer",
|
||||||
"base64-arraybuffer-es6",
|
|
||||||
"@yuku-core/wasm",
|
"@yuku-core/wasm",
|
||||||
"@oxc-parser/binding-wasm32-wasip1",
|
"@oxc-parser/binding-wasm32-wasip1",
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -143,7 +143,6 @@
|
|||||||
"@types/jsesc": "3.0.3",
|
"@types/jsesc": "3.0.3",
|
||||||
"@typescript-eslint/eslint-plugin": "8.70.1",
|
"@typescript-eslint/eslint-plugin": "8.70.1",
|
||||||
"@typescript-eslint/parser": "8.70.1",
|
"@typescript-eslint/parser": "8.70.1",
|
||||||
"base64-arraybuffer-es6": "3.1.0",
|
|
||||||
"browserslist": "4.29.0",
|
"browserslist": "4.29.0",
|
||||||
"browserslist-to-esbuild": "2.1.1",
|
"browserslist-to-esbuild": "2.1.1",
|
||||||
"buffer": "6.0.3",
|
"buffer": "6.0.3",
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import fs from "node:fs/promises";
|
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { outdent } from "outdent";
|
import { outdent } from "outdent";
|
||||||
import { DIST_DIR, PACKAGES_DIRECTORY } from "../../utilities/index.js";
|
import { DIST_DIR, PACKAGES_DIRECTORY } from "../../utilities/index.js";
|
||||||
@@ -57,35 +56,21 @@ const mainModule = {
|
|||||||
module: getPackageFile(
|
module: getPackageFile(
|
||||||
"@oxc-parser/binding-wasm32-wasip1/parser.wasip1-browser.js",
|
"@oxc-parser/binding-wasm32-wasip1/parser.wasip1-browser.js",
|
||||||
),
|
),
|
||||||
async process(text, file) {
|
process(text) {
|
||||||
const wasmUrlPattern =
|
const wasmUrlPattern =
|
||||||
/const __wasmUrl = new URL\('(?<wasmUrl>.\/[a-z0-9.-]+\.wasm)', import\.meta\.url\)\.href(?=\n)/;
|
/const __wasmUrl = new URL\('(?<wasmUrl>.\/[a-z0-9.-]+\.wasm)', import\.meta\.url\)\.href(?=\n)/;
|
||||||
const { wasmUrl } = text.match(wasmUrlPattern).groups;
|
const { wasmUrl } = text.match(wasmUrlPattern).groups;
|
||||||
const wasmFile = path.join(path.dirname(file), wasmUrl);
|
|
||||||
const wasmBase64String = await fs.readFile(wasmFile, "base64");
|
|
||||||
|
|
||||||
text = outdent`
|
|
||||||
import { decode as __decode } from "base64-arraybuffer-es6";
|
|
||||||
|
|
||||||
const __base64ToArrayBuffer = Uint8Array.fromBase64
|
|
||||||
? (string) => Uint8Array.fromBase64(string).buffer
|
|
||||||
: __decode;
|
|
||||||
|
|
||||||
${text}
|
|
||||||
`;
|
|
||||||
|
|
||||||
text = text.replace(wasmUrlPattern, "");
|
text = text.replace(wasmUrlPattern, "");
|
||||||
text = text.replace(
|
text = text.replace(
|
||||||
"const __wasmResponse = await globalThis.fetch(__wasmUrl)",
|
"const __wasmFile = await __wasmResponse.arrayBuffer()",
|
||||||
"const __wasmResponse = {ok: true}",
|
outdent`
|
||||||
|
import __wasmFile from ${JSON.stringify(wasmUrl)} with {type: "bytes"};
|
||||||
|
`,
|
||||||
);
|
);
|
||||||
text = text.replace(
|
text = text.replace(
|
||||||
"await __wasmResponse.arrayBuffer()",
|
"const __wasmResponse =",
|
||||||
outdent`
|
"const __wasmResponse = {ok: 1} ||",
|
||||||
__base64ToArrayBuffer(
|
|
||||||
/* "${wasmUrl}" */ ${JSON.stringify(wasmBase64String)}
|
|
||||||
)
|
|
||||||
`,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
text = text.replace("await __rollbackWasiInitialization()", "[]");
|
text = text.replace("await __rollbackWasiInitialization()", "[]");
|
||||||
|
|||||||
@@ -3613,13 +3613,6 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"base64-arraybuffer-es6@npm:3.1.0":
|
|
||||||
version: 3.1.0
|
|
||||||
resolution: "base64-arraybuffer-es6@npm:3.1.0"
|
|
||||||
checksum: 10/a623b7e396785b67e87ee92b474506a8ba1e26b977260bd2b97fde1332973de86689018dc847a7a4b1a238b09a5b3be0b51b9d3879815c220b2171c1722f3b6f
|
|
||||||
languageName: node
|
|
||||||
linkType: hard
|
|
||||||
|
|
||||||
"base64-js@npm:^1.3.1":
|
"base64-js@npm:^1.3.1":
|
||||||
version: 1.5.1
|
version: 1.5.1
|
||||||
resolution: "base64-js@npm:1.5.1"
|
resolution: "base64-js@npm:1.5.1"
|
||||||
@@ -8296,7 +8289,6 @@ __metadata:
|
|||||||
acorn-jsx: "npm:5.3.2"
|
acorn-jsx: "npm:5.3.2"
|
||||||
angular-estree-parser: "npm:15.5.0"
|
angular-estree-parser: "npm:15.5.0"
|
||||||
angular-html-parser: "npm:10.12.0"
|
angular-html-parser: "npm:10.12.0"
|
||||||
base64-arraybuffer-es6: "npm:3.1.0"
|
|
||||||
browserslist: "npm:4.29.0"
|
browserslist: "npm:4.29.0"
|
||||||
browserslist-to-esbuild: "npm:2.1.1"
|
browserslist-to-esbuild: "npm:2.1.1"
|
||||||
buffer: "npm:6.0.3"
|
buffer: "npm:6.0.3"
|
||||||
|
|||||||
Reference in new issue
Block a user