-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.js
75 lines (70 loc) · 2.08 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import path from "path";
import { fileURLToPath } from "url";
import { build } from "esbuild";
import { replace } from "esbuild-plugin-replace";
import generateBundlerConfig from "cloudflare-workers-compat/bundler-config";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
/** @type {import("esbuild").BuildOptions} */
const common = {
bundle: true,
format: "esm",
target: "esnext",
conditions: ["worker", "browser"],
treeShaking: true,
pure: ["decode"]
};
const compatConfig = await generateBundlerConfig({
denoObject: {
attributes: true,
global: "empty-object"
},
onIncompatible: "ignore"
});
await build({
...common,
entryPoints: [path.join(__dirname, "build", "postgres-deno.js")],
outfile: path.join(__dirname, "build", "postgres-tmp.js"),
plugins: [
replace({
delimiters: ['', ''],
values: {
"stdCrypto.subtle": "crypto.subtle",
"webCrypto.subtle": "crypto.subtle",
"stdCrypto": "unused_stdCrypto",
"webCrypto": "unused_webCrypto"
}
})
],
inject: [
...compatConfig.inject,
"./workers-override.ts",
],
define: {
...compatConfig.define,
"Deno.startTls": "workerDenoPostgres_startTls",
"Deno.connect": "workerDenoPostgres_connect",
},
});
await build({
...common,
entryPoints: [path.join(__dirname, "build", "postgres-tmp.js")],
outfile: path.join(__dirname, "build", "postgres.js"),
plugins: [
replace({
delimiters: ['', ''],
values: {
// Filter out crypto-related
"var unused_stdCrypto =": "var unused_stdCrypto = null &&",
"var unused_webCrypto =": "var unused_webCrypto = null &&",
// Filter out FinalizationRegistry-related
"var DigestContextFinalization =": "var DigestContextFinalization = null &&",
// Filter out Wasm-related
"var data = decode(\"": "var data = null && decode(\"",
"var wasm =": "var wasm = null &&",
"var wasmInstance =": "var wasmInstance = null &&",
"var wasmModule =": "var wasmModule = null &&"
}
})
],
});