Update dependency yuku-parser to v0.17.0 (#20201)
Co-authored-by: fisker <lionkay@gmail.com>
This commit is contained in:
1 parent
8dafda772d
commit
55303a4557
9 files changed
+97
-149
No files matched your search
@@ -23,8 +23,6 @@ const mainModule = {
|
||||
input: "index.js",
|
||||
output: "index.mjs",
|
||||
build: createJavascriptModuleBuilder({
|
||||
input: "index.js",
|
||||
output: "index.mjs",
|
||||
format: "esm",
|
||||
platform: "node",
|
||||
external: ["oxc-parser"],
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { outdent } from "outdent";
|
||||
import { DIST_DIR, PACKAGES_DIRECTORY } from "../../utilities/index.js";
|
||||
import { createJavascriptModuleBuilder } from "../builders/javascript-module.js";
|
||||
import { getPackageFile } from "../utilities.js";
|
||||
import {
|
||||
createPackageMetaFilesConfig,
|
||||
createTypesConfig,
|
||||
@@ -23,8 +20,6 @@ const mainModule = {
|
||||
input: "index.js",
|
||||
output: "index.mjs",
|
||||
build: createJavascriptModuleBuilder({
|
||||
input: "index.js",
|
||||
output: "index.mjs",
|
||||
format: "esm",
|
||||
platform: "node",
|
||||
external: ["yuku-parser"],
|
||||
@@ -38,49 +33,6 @@ const mainModule = {
|
||||
format: "esm",
|
||||
platform: "universal",
|
||||
addDefaultExport: true,
|
||||
replaceModule: [
|
||||
{
|
||||
module: getPackageFile("yuku-parser"),
|
||||
path: getPackageFile("@yuku-parser/wasm"),
|
||||
},
|
||||
{
|
||||
module: getPackageFile("@yuku-parser/wasm"),
|
||||
async process(text, file) {
|
||||
const wasmUrlPattern =
|
||||
/const wasmUrl = new URL\("(?<wasmUrl>.\/[a-z0-9.-]+\.wasm)", import\.meta\.url\);/;
|
||||
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('import("node:fs/promises")', "whatever");
|
||||
text = text.replace(wasmUrlPattern, "");
|
||||
text = text.replace(
|
||||
"(await instantiate())",
|
||||
outdent`
|
||||
new WebAssembly.Instance(
|
||||
new WebAssembly.Module(
|
||||
__base64ToArrayBuffer(
|
||||
/* "${wasmUrl}" */ ${JSON.stringify(wasmBase64String)}
|
||||
)
|
||||
)
|
||||
)
|
||||
`,
|
||||
);
|
||||
|
||||
return text;
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
playground: true,
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user