alchemy 0.22.0 → 0.22.1
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/lib/cloudflare/bundle/bundle-worker.d.ts.map +1 -1
- package/lib/cloudflare/bundle/bundle-worker.js +4 -0
- package/lib/cloudflare/bundle/bundle-worker.js.map +1 -1
- package/lib/cloudflare/bundle/wasm-plugin.d.ts +3 -0
- package/lib/cloudflare/bundle/wasm-plugin.d.ts.map +1 -0
- package/lib/cloudflare/bundle/wasm-plugin.js +53 -0
- package/lib/cloudflare/bundle/wasm-plugin.js.map +1 -0
- package/package.json +1 -1
- package/src/cloudflare/bundle/bundle-worker.ts +4 -0
- package/src/cloudflare/bundle/wasm-plugin.ts +57 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle-worker.d.ts","sourceRoot":"","sources":["../../../src/cloudflare/bundle/bundle-worker.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"bundle-worker.d.ts","sourceRoot":"","sources":["../../../src/cloudflare/bundle/bundle-worker.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAWhD,wBAAsB,kBAAkB,CAAC,CAAC,SAAS,QAAQ,EACzD,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,kBAAkB,EAAE,MAAM,EAAE,CAAC;CAC9B,mBA4EF"}
|
|
@@ -5,6 +5,7 @@ import { isBuildFailure, rewriteNodeCompatBuildFailure, } from "./build-failures
|
|
|
5
5
|
import { external, external_als } from "./external.js";
|
|
6
6
|
import { getNodeJSCompatMode } from "./nodejs-compat-mode.js";
|
|
7
7
|
import { nodeJsCompatPlugin } from "./nodejs-compat.js";
|
|
8
|
+
import { wasmPlugin } from "./wasm-plugin.js";
|
|
8
9
|
export async function bundleWorkerScript(props) {
|
|
9
10
|
const projectRoot = props.projectRoot ?? process.cwd();
|
|
10
11
|
const nodeJsCompatMode = await getNodeJSCompatMode(props.compatibilityDate, props.compatibilityFlags);
|
|
@@ -28,8 +29,11 @@ export async function bundleWorkerScript(props) {
|
|
|
28
29
|
loader: {
|
|
29
30
|
".sql": "text",
|
|
30
31
|
".json": "json",
|
|
32
|
+
...props.bundle?.loader,
|
|
33
|
+
...props.bundle?.options?.loader,
|
|
31
34
|
},
|
|
32
35
|
plugins: [
|
|
36
|
+
wasmPlugin,
|
|
33
37
|
...(props.bundle?.plugins ?? []),
|
|
34
38
|
...(nodeJsCompatMode === "v2" ? [await nodeJsCompatPlugin()] : []),
|
|
35
39
|
...(props.bundle?.alias
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle-worker.js","sourceRoot":"","sources":["../../../src/cloudflare/bundle/bundle-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EACL,cAAc,EACd,6BAA6B,GAC9B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"bundle-worker.js","sourceRoot":"","sources":["../../../src/cloudflare/bundle/bundle-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAA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MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,IAAI,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,uBAAuB,CAAC,EAAE,CAAC;YACjD,MAAM,IAAI,KAAK,CACb,GAAG,CAAC,CAAC,OAAO,2FAA2F,EACvG,EAAE,KAAK,EAAE,CAAC,EAAE,CACb,CAAC;QACJ,CAAC;QACD,IAAI,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;YACtB,6BAA6B,CAAC,CAAC,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;YAC1D,MAAM,CAAC,CAAC;QACV,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,CAAC,CAAC,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm-plugin.d.ts","sourceRoot":"","sources":["../../../src/cloudflare/bundle/wasm-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAInC,eAAO,MAAM,UAAU,EAAE,OAAO,CAAC,MAoDhC,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
export const wasmPlugin = {
|
|
4
|
+
name: "wasm",
|
|
5
|
+
setup(build) {
|
|
6
|
+
// Resolve ".wasm" files to a path with a namespace
|
|
7
|
+
build.onResolve({ filter: /\.wasm$/ }, (args) => {
|
|
8
|
+
// If this is the import inside the stub module, import the
|
|
9
|
+
// binary itself. Put the path in the "wasm-binary" namespace
|
|
10
|
+
// to tell our binary load callback to load the binary file.
|
|
11
|
+
if (args.namespace === "wasm-stub") {
|
|
12
|
+
return {
|
|
13
|
+
path: args.path,
|
|
14
|
+
namespace: "wasm-binary",
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
// Otherwise, generate the JavaScript stub module for this
|
|
18
|
+
// ".wasm" file. Put it in the "wasm-stub" namespace to tell
|
|
19
|
+
// our stub load callback to fill it with JavaScript.
|
|
20
|
+
//
|
|
21
|
+
// Resolve relative paths to absolute paths here since this
|
|
22
|
+
// resolve callback is given "resolveDir", the directory to
|
|
23
|
+
// resolve imports against.
|
|
24
|
+
if (args.resolveDir === "") {
|
|
25
|
+
return; // Ignore unresolvable paths
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
path: path.isAbsolute(args.path)
|
|
29
|
+
? args.path
|
|
30
|
+
: path.join(args.resolveDir, args.path),
|
|
31
|
+
namespace: "wasm-stub",
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
// Virtual modules in the "wasm-stub" namespace are filled with
|
|
35
|
+
// the JavaScript code for compiling the WebAssembly binary. The
|
|
36
|
+
// binary itself is imported from a second virtual module.
|
|
37
|
+
build.onLoad({ filter: /.*/, namespace: "wasm-stub" }, async (args) => ({
|
|
38
|
+
contents: `import wasm from ${JSON.stringify(args.path)}
|
|
39
|
+
export default (imports) =>
|
|
40
|
+
WebAssembly.instantiate(wasm, imports).then(
|
|
41
|
+
result => result.instance.exports)`,
|
|
42
|
+
}));
|
|
43
|
+
// Virtual modules in the "wasm-binary" namespace contain the
|
|
44
|
+
// actual bytes of the WebAssembly file. This uses esbuild's
|
|
45
|
+
// built-in "binary" loader instead of manually embedding the
|
|
46
|
+
// binary data inside JavaScript code ourselves.
|
|
47
|
+
build.onLoad({ filter: /.*/, namespace: "wasm-binary" }, async (args) => ({
|
|
48
|
+
contents: await fs.promises.readFile(args.path),
|
|
49
|
+
loader: "binary",
|
|
50
|
+
}));
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=wasm-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm-plugin.js","sourceRoot":"","sources":["../../../src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AC1C,CAAC,CAAC,CAAC;QAEJ,6DAA6D;QAC7D,4DAA4D;QAC5D,6DAA6D;QAC7D,gDAAgD;QAChD,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;YACxE,QAAQ,EAAE,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;YAC/C,MAAM,EAAE,QAAQ;SACjB,CAAC,CAAC,CAAC;IACN,CAAC;CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
import { external, external_als } from "./external.ts";
|
|
11
11
|
import { getNodeJSCompatMode } from "./nodejs-compat-mode.ts";
|
|
12
12
|
import { nodeJsCompatPlugin } from "./nodejs-compat.ts";
|
|
13
|
+
import { wasmPlugin } from "./wasm-plugin.ts";
|
|
13
14
|
|
|
14
15
|
export async function bundleWorkerScript<B extends Bindings>(
|
|
15
16
|
props: WorkerProps<B> & {
|
|
@@ -48,8 +49,11 @@ export async function bundleWorkerScript<B extends Bindings>(
|
|
|
48
49
|
loader: {
|
|
49
50
|
".sql": "text",
|
|
50
51
|
".json": "json",
|
|
52
|
+
...props.bundle?.loader,
|
|
53
|
+
...props.bundle?.options?.loader,
|
|
51
54
|
},
|
|
52
55
|
plugins: [
|
|
56
|
+
wasmPlugin,
|
|
53
57
|
...(props.bundle?.plugins ?? []),
|
|
54
58
|
...(nodeJsCompatMode === "v2" ? [await nodeJsCompatPlugin()] : []),
|
|
55
59
|
...(props.bundle?.alias
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type esbuild from "esbuild";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
export const wasmPlugin: esbuild.Plugin = {
|
|
6
|
+
name: "wasm",
|
|
7
|
+
setup(build) {
|
|
8
|
+
// Resolve ".wasm" files to a path with a namespace
|
|
9
|
+
build.onResolve({ filter: /\.wasm$/ }, (args) => {
|
|
10
|
+
// If this is the import inside the stub module, import the
|
|
11
|
+
// binary itself. Put the path in the "wasm-binary" namespace
|
|
12
|
+
// to tell our binary load callback to load the binary file.
|
|
13
|
+
if (args.namespace === "wasm-stub") {
|
|
14
|
+
return {
|
|
15
|
+
path: args.path,
|
|
16
|
+
namespace: "wasm-binary",
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Otherwise, generate the JavaScript stub module for this
|
|
21
|
+
// ".wasm" file. Put it in the "wasm-stub" namespace to tell
|
|
22
|
+
// our stub load callback to fill it with JavaScript.
|
|
23
|
+
//
|
|
24
|
+
// Resolve relative paths to absolute paths here since this
|
|
25
|
+
// resolve callback is given "resolveDir", the directory to
|
|
26
|
+
// resolve imports against.
|
|
27
|
+
if (args.resolveDir === "") {
|
|
28
|
+
return; // Ignore unresolvable paths
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
path: path.isAbsolute(args.path)
|
|
32
|
+
? args.path
|
|
33
|
+
: path.join(args.resolveDir, args.path),
|
|
34
|
+
namespace: "wasm-stub",
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Virtual modules in the "wasm-stub" namespace are filled with
|
|
39
|
+
// the JavaScript code for compiling the WebAssembly binary. The
|
|
40
|
+
// binary itself is imported from a second virtual module.
|
|
41
|
+
build.onLoad({ filter: /.*/, namespace: "wasm-stub" }, async (args) => ({
|
|
42
|
+
contents: `import wasm from ${JSON.stringify(args.path)}
|
|
43
|
+
export default (imports) =>
|
|
44
|
+
WebAssembly.instantiate(wasm, imports).then(
|
|
45
|
+
result => result.instance.exports)`,
|
|
46
|
+
}));
|
|
47
|
+
|
|
48
|
+
// Virtual modules in the "wasm-binary" namespace contain the
|
|
49
|
+
// actual bytes of the WebAssembly file. This uses esbuild's
|
|
50
|
+
// built-in "binary" loader instead of manually embedding the
|
|
51
|
+
// binary data inside JavaScript code ourselves.
|
|
52
|
+
build.onLoad({ filter: /.*/, namespace: "wasm-binary" }, async (args) => ({
|
|
53
|
+
contents: await fs.promises.readFile(args.path),
|
|
54
|
+
loader: "binary",
|
|
55
|
+
}));
|
|
56
|
+
},
|
|
57
|
+
};
|