xbintsc 0.6.22 → 0.6.24
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/AGENTS.md +5 -0
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/driver/build-key.js +2 -1
- package/dist/src/driver/build-key.js.map +1 -1
- package/dist/src/driver/bundler/concatenate.d.ts +23 -0
- package/dist/src/driver/bundler/concatenate.js +210 -0
- package/dist/src/driver/bundler/concatenate.js.map +1 -0
- package/dist/src/driver/bundler/merge.d.ts +4 -4
- package/dist/src/driver/bundler/merge.js +24 -207
- package/dist/src/driver/bundler/merge.js.map +1 -1
- package/dist/src/driver/bundler/{namespace-import.d.ts → namespace-object.d.ts} +5 -1
- package/dist/src/driver/bundler/{namespace-import.js → namespace-object.js} +6 -2
- package/dist/src/driver/bundler/namespace-object.js.map +1 -0
- package/dist/src/driver/bundler/{reexport-fixup.d.ts → reexport-resolution.d.ts} +9 -3
- package/dist/src/driver/bundler/{reexport-fixup.js → reexport-resolution.js} +16 -6
- package/dist/src/driver/bundler/reexport-resolution.js.map +1 -0
- package/dist/src/driver/fingerprint.d.ts +11 -0
- package/dist/src/driver/fingerprint.js +25 -0
- package/dist/src/driver/fingerprint.js.map +1 -1
- package/dist/src/driver/link-features.js +36 -11
- package/dist/src/driver/link-features.js.map +1 -1
- package/dist/src/driver/modules.d.ts +12 -5
- package/dist/src/driver/modules.js +12 -5
- package/dist/src/driver/modules.js.map +1 -1
- package/dist/src/driver/paths.d.ts +10 -0
- package/dist/src/driver/paths.js +18 -0
- package/dist/src/driver/paths.js.map +1 -1
- package/dist/src/driver/runtime-objects.d.ts +1 -1
- package/dist/src/driver/runtime-objects.js +22 -6
- package/dist/src/driver/runtime-objects.js.map +1 -1
- package/dist/src/driver/toolchain.d.ts +1 -1
- package/dist/src/driver/toolchain.js +10 -1
- package/dist/src/driver/toolchain.js.map +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/node/http2/feature.d.ts +14 -0
- package/dist/src/extensions/node/http2/feature.js +28 -0
- package/dist/src/extensions/node/http2/feature.js.map +1 -0
- package/dist/src/extensions/node/http2/index.d.ts +5 -1
- package/dist/src/extensions/node/http2/index.js +6 -1
- package/dist/src/extensions/node/http2/index.js.map +1 -1
- package/dist/src/extensions/node/index.js +3 -1
- package/dist/src/extensions/node/index.js.map +1 -1
- package/dist/src/extensions/node/tls/feature.d.ts +12 -0
- package/dist/src/extensions/node/tls/feature.js +24 -0
- package/dist/src/extensions/node/tls/feature.js.map +1 -0
- package/dist/src/extensions/node/tls/index.d.ts +5 -1
- package/dist/src/extensions/node/tls/index.js +5 -1
- package/dist/src/extensions/node/tls/index.js.map +1 -1
- package/dist/src/extensions/node/zlib/compression.js +11 -6
- package/dist/src/extensions/node/zlib/compression.js.map +1 -1
- package/dist/src/extensions/registry.js +2 -1
- package/dist/src/extensions/registry.js.map +1 -1
- package/dist/src/extensions/storage.js +4 -3
- package/dist/src/extensions/storage.js.map +1 -1
- package/dist/src/extensions/tls.d.ts +26 -0
- package/dist/src/extensions/tls.js +46 -0
- package/dist/src/extensions/tls.js.map +1 -0
- package/dist/tests/driver/deferred-reexport.test.js +25 -0
- package/dist/tests/driver/deferred-reexport.test.js.map +1 -1
- package/dist/tests/driver/link-features.test.js +9 -0
- package/dist/tests/driver/link-features.test.js.map +1 -1
- package/dist/tests/e2e/fetch.test.js +3 -1
- package/dist/tests/e2e/fetch.test.js.map +1 -1
- package/dist/tests/e2e/http2.test.d.ts +7 -0
- package/dist/tests/e2e/http2.test.js +201 -0
- package/dist/tests/e2e/http2.test.js.map +1 -0
- package/dist/tests/e2e/net-helpers.d.ts +28 -0
- package/dist/tests/e2e/net-helpers.js +59 -0
- package/dist/tests/e2e/net-helpers.js.map +1 -0
- package/dist/tests/e2e/node-modules.test.js +3 -5
- package/dist/tests/e2e/node-modules.test.js.map +1 -1
- package/dist/tests/e2e/tls.test.d.ts +10 -0
- package/dist/tests/e2e/tls.test.js +197 -0
- package/dist/tests/e2e/tls.test.js.map +1 -0
- package/dist/tests/extensions/storage.test.js +3 -2
- package/dist/tests/extensions/storage.test.js.map +1 -1
- package/doc/ai/contributing.md +14 -0
- package/doc/ai/extensions.md +5 -3
- package/doc/ai/language-support.md +1 -1
- package/doc/ai/zh-CN/contributing.md +12 -0
- package/doc/ai/zh-CN/extensions.md +4 -2
- package/doc/ai/zh-CN/language-support.md +1 -1
- package/doc/gui/api.md +1 -1
- package/doc/gui/build.md +5 -3
- package/doc/gui/rendering.md +1 -1
- package/doc/gui.md +1 -1
- package/doc/implemented/async.md +1 -1
- package/doc/implemented/extensions.md +1 -0
- package/doc/implemented/fetch.md +19 -4
- package/doc/implemented/node/http2.md +51 -0
- package/doc/implemented/node/tls.md +56 -0
- package/doc/implemented/node.md +8 -0
- package/doc/implemented/storage.md +2 -1
- package/doc/implemented.md +2 -2
- package/doc/unimplemented/node/modules.md +6 -6
- package/doc/unimplemented/toolchain.md +1 -1
- package/doc/zh-CN/gui/api.md +1 -1
- package/doc/zh-CN/gui/build.md +4 -2
- package/doc/zh-CN/gui/rendering.md +1 -1
- package/doc/zh-CN/gui.md +1 -1
- package/doc/zh-CN/implemented/async.md +1 -1
- package/doc/zh-CN/implemented/extensions.md +1 -0
- package/doc/zh-CN/implemented/fetch.md +15 -3
- package/doc/zh-CN/implemented/node/http2.md +44 -0
- package/doc/zh-CN/implemented/node/tls.md +47 -0
- package/doc/zh-CN/implemented/node.md +7 -0
- package/doc/zh-CN/implemented/storage.md +2 -1
- package/doc/zh-CN/implemented.md +2 -2
- package/doc/zh-CN/unimplemented/node/modules.md +3 -3
- package/doc/zh-CN/unimplemented/toolchain.md +1 -1
- package/package.json +16 -8
- package/runtime/ext_node/http2/http2.c +25 -11
- package/runtime/ext_node/http2/http2_backend.c +48 -0
- package/runtime/ext_node/http2/http2_bridge.c +25 -0
- package/runtime/ext_node/http2/parts/api.inc +40 -0
- package/runtime/ext_node/http2/parts/client.inc +215 -0
- package/runtime/ext_node/http2/parts/common.inc +330 -0
- package/runtime/ext_node/http2/parts/events.inc +139 -0
- package/runtime/ext_node/http2/parts/server.inc +301 -0
- package/runtime/ext_node/http2/parts/streams.inc +254 -0
- package/runtime/ext_node/tls/parts/api.inc +38 -0
- package/runtime/ext_node/tls/parts/connect.inc +107 -0
- package/runtime/ext_node/tls/parts/helpers.inc +121 -0
- package/runtime/ext_node/tls/parts/server.inc +101 -0
- package/runtime/ext_node/tls/parts/socket.inc +171 -0
- package/runtime/ext_node/tls/tls.c +21 -13
- package/runtime/ext_node/tls/tls_backend.c +50 -0
- package/runtime/ext_node/zlib/{miniz/compression_bridge.c → compression_bridge.c} +1 -1
- package/runtime/xt_fetch/async.inc +19 -12
- package/runtime/xt_fetch/socket.inc +55 -0
- package/runtime/xt_fetch.c +3 -0
- package/runtime/xt_http2/nghttp2_compat.h +19 -0
- package/runtime/xt_http2/nghttp2_static.h +18 -0
- package/runtime/xt_http2_api.h +38 -0
- package/runtime/xt_node_tls_api.h +37 -0
- package/runtime/xt_protocol_registry.c +22 -0
- package/runtime/xt_storage/storage_internal.h +3 -3
- package/runtime/xt_tls/parts/api.inc +21 -0
- package/runtime/xt_tls/parts/client.inc +112 -0
- package/runtime/xt_tls/parts/io.inc +157 -0
- package/runtime/xt_tls/parts/server.inc +102 -0
- package/runtime/xt_tls/parts/setup.inc +146 -0
- package/runtime/xt_tls/tls_bridge.c +27 -0
- package/runtime/xt_tls/tls_core.c +39 -0
- package/runtime/xt_tls/tls_internal.h +73 -0
- package/runtime/xt_tls_api.h +73 -0
- package/scripts/build-gui.ts +8 -7
- package/scripts/build-tls.ts +248 -0
- package/scripts/check-file-length.ts +4 -25
- package/scripts/fetch-vendored.ts +244 -0
- package/scripts/package-release.ts +13 -3
- package/src/driver/build-key.ts +7 -1
- package/src/driver/bundler/README.md +55 -0
- package/src/driver/bundler/concatenate.ts +244 -0
- package/src/driver/bundler/merge.ts +24 -215
- package/src/driver/bundler/{namespace-import.ts → namespace-object.ts} +5 -1
- package/src/driver/bundler/{reexport-fixup.ts → reexport-resolution.ts} +15 -5
- package/src/driver/fingerprint.ts +24 -0
- package/src/driver/link-features.ts +33 -11
- package/src/driver/modules.ts +12 -5
- package/src/driver/paths.ts +20 -0
- package/src/driver/runtime-objects.ts +25 -6
- package/src/driver/toolchain.ts +11 -2
- package/src/driver/version.ts +1 -1
- package/src/extensions/node/http2/feature.ts +33 -0
- package/src/extensions/node/http2/index.ts +6 -1
- package/src/extensions/node/index.ts +3 -1
- package/src/extensions/node/tls/feature.ts +29 -0
- package/src/extensions/node/tls/index.ts +5 -1
- package/src/extensions/node/zlib/compression.ts +11 -6
- package/src/extensions/registry.ts +2 -1
- package/src/extensions/storage.ts +4 -3
- package/src/extensions/tls.ts +52 -0
- package/{runtime/ext_gui → vendor/stb}/stb_image.h +17 -1
- package/dist/src/driver/bundler/namespace-import.js.map +0 -1
- package/dist/src/driver/bundler/reexport-fixup.js.map +0 -1
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz.c +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz.h +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_common.h +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_export.h +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tdef.c +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tdef.h +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tinfl.c +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tinfl.h +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_zip.h +0 -0
- /package/{runtime/ext_gui → vendor/nanosvg}/nanosvg.h +0 -0
- /package/{runtime/ext_gui → vendor/nanosvg}/nanosvgrast.h +0 -0
- /package/{runtime/xt_storage → vendor}/sqlite3/sqlite3.c +0 -0
- /package/{runtime/xt_storage → vendor}/sqlite3/sqlite3.h +0 -0
- /package/{runtime/ext_gui → vendor/stb}/stb_truetype.h +0 -0
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
* the runtime's C, C++, Rust and `#include`d `.inc` fragments plus shell
|
|
8
8
|
* scripts, so *every* code file stays focused and small.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* Third-party sources are fetched into `vendor/` instead of being committed
|
|
11
|
+
* (see `scripts/fetch-vendored.ts`), so the walk skips that directory: nothing
|
|
12
|
+
* vendored is ours to split, and it is not part of the tree this check owns.
|
|
12
13
|
*
|
|
13
14
|
* Run via `npm run lint` (or `tsx scripts/check-file-length.ts`).
|
|
14
15
|
*/
|
|
@@ -35,28 +36,6 @@ const IGNORED_DIRECTORIES = new Set([
|
|
|
35
36
|
"vendor",
|
|
36
37
|
]);
|
|
37
38
|
|
|
38
|
-
/** Vendored third-party sources that ship verbatim and are not ours to split. */
|
|
39
|
-
const VENDORED_FILES = new Set([
|
|
40
|
-
join("runtime", "ext_gui", "stb_image.h"),
|
|
41
|
-
join("runtime", "ext_gui", "stb_truetype.h"),
|
|
42
|
-
join("runtime", "ext_gui", "nanosvg.h"),
|
|
43
|
-
join("runtime", "ext_gui", "nanosvgrast.h"),
|
|
44
|
-
// miniz, the single-file DEFLATE library used by the `compression` link
|
|
45
|
-
// feature (`node:zlib`), ships verbatim.
|
|
46
|
-
join("runtime", "ext_node", "zlib", "miniz", "miniz.c"),
|
|
47
|
-
join("runtime", "ext_node", "zlib", "miniz", "miniz.h"),
|
|
48
|
-
join("runtime", "ext_node", "zlib", "miniz", "miniz_tdef.c"),
|
|
49
|
-
join("runtime", "ext_node", "zlib", "miniz", "miniz_tdef.h"),
|
|
50
|
-
join("runtime", "ext_node", "zlib", "miniz", "miniz_tinfl.c"),
|
|
51
|
-
join("runtime", "ext_node", "zlib", "miniz", "miniz_tinfl.h"),
|
|
52
|
-
join("runtime", "ext_node", "zlib", "miniz", "miniz_common.h"),
|
|
53
|
-
join("runtime", "ext_node", "zlib", "miniz", "miniz_export.h"),
|
|
54
|
-
// SQLite, the single-file amalgamation backing the `storage` extension
|
|
55
|
-
// (localStorage / sessionStorage / indexedDB), ships verbatim.
|
|
56
|
-
join("runtime", "xt_storage", "sqlite3", "sqlite3.c"),
|
|
57
|
-
join("runtime", "xt_storage", "sqlite3", "sqlite3.h"),
|
|
58
|
-
]);
|
|
59
|
-
|
|
60
39
|
/** Machine-generated files: they are reproduced from their sources by a script,
|
|
61
40
|
* so their size is not a sign of a module that needs splitting. */
|
|
62
41
|
const GENERATED_FILES = new Set([join("runtime", "ext_gui", "renderer_shaders_data.h")]);
|
|
@@ -88,7 +67,7 @@ function collect(dir: string, offenses: Offense[]): void {
|
|
|
88
67
|
const dot = entry.name.lastIndexOf(".");
|
|
89
68
|
if (dot < 0 || !CODE_EXTENSIONS.has(entry.name.slice(dot))) continue;
|
|
90
69
|
const file = relative(root, full);
|
|
91
|
-
if (
|
|
70
|
+
if (GENERATED_FILES.has(file)) continue;
|
|
92
71
|
const lines = countLines(full);
|
|
93
72
|
if (lines > MAX_LINES) offenses.push({ file, lines });
|
|
94
73
|
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Fetch the third-party C sources that xbintsc compiles, into `vendor/`.
|
|
4
|
+
*
|
|
5
|
+
* Those libraries are vendored *by version*, not committed: the repository
|
|
6
|
+
* tracks neither their code nor their line count. Each entry pins an immutable
|
|
7
|
+
* upstream revision and the SHA-256 of the extracted file, so a changed pin is
|
|
8
|
+
* a reviewable change and a corrupted download can never reach a build.
|
|
9
|
+
*
|
|
10
|
+
* Layout (sibling of `runtime/`, so `findVendorDir()` can find it in a source
|
|
11
|
+
* checkout, an unpacked release and an npm install alike):
|
|
12
|
+
*
|
|
13
|
+
* vendor/stb/stb_image.h, stb_truetype.h
|
|
14
|
+
* vendor/nanosvg/nanosvg.h, nanosvgrast.h
|
|
15
|
+
* vendor/miniz/… the `compression` link feature
|
|
16
|
+
* vendor/sqlite3/sqlite3.{c,h} the `storage` link feature
|
|
17
|
+
*
|
|
18
|
+
* `build-gui.ts` fetches just `stb`/`nanosvg`; `npm test` fetches everything.
|
|
19
|
+
* CI caches the four directories keyed on this script.
|
|
20
|
+
*
|
|
21
|
+
* Note: miniz's upstream tree has no `miniz_export.h` (its CMake build generates
|
|
22
|
+
* one). The static-only shim below is written here rather than tracked.
|
|
23
|
+
*
|
|
24
|
+
* Run via `npm run vendor` (or `tsx scripts/fetch-vendored.ts`).
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { spawnSync } from "node:child_process";
|
|
28
|
+
import { createHash } from "node:crypto";
|
|
29
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
30
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
31
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
32
|
+
import { downloadTarball } from "./fetch-tarball.js";
|
|
33
|
+
|
|
34
|
+
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
35
|
+
export const vendorDir = join(root, "vendor");
|
|
36
|
+
|
|
37
|
+
/** The vendored packages, each a directory under `vendor/`. */
|
|
38
|
+
export const VENDOR_PACKAGES = ["stb", "nanosvg", "miniz", "sqlite3"] as const;
|
|
39
|
+
export type VendorPackage = (typeof VENDOR_PACKAGES)[number];
|
|
40
|
+
|
|
41
|
+
interface VendoredFile {
|
|
42
|
+
readonly package: Exclude<VendorPackage, "sqlite3">;
|
|
43
|
+
readonly name: string;
|
|
44
|
+
readonly url: string;
|
|
45
|
+
readonly sha256: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* Pinned upstream revisions. STB and NanoSVG have no releases, so the commit
|
|
49
|
+
* is the version; miniz is pinned to the commit whose files this tree uses. */
|
|
50
|
+
const STB_IMAGE = "013ac3beddff3dbffafd5177e7972067cd2b5083";
|
|
51
|
+
const STB_TRUETYPE = "c0c982601f40183e74d84a61237e968dca08380e";
|
|
52
|
+
const NANOSVG = "239e102ec2c691f2902e20ace2ed36ee4a35cfe6";
|
|
53
|
+
const MINIZ = "2c50092b3a4010760df02e7842960abdc3f25ee3";
|
|
54
|
+
|
|
55
|
+
const RAW = "https://raw.githubusercontent.com";
|
|
56
|
+
|
|
57
|
+
const FILES: readonly VendoredFile[] = [
|
|
58
|
+
{
|
|
59
|
+
package: "stb",
|
|
60
|
+
name: "stb_image.h",
|
|
61
|
+
url: `${RAW}/nothings/stb/${STB_IMAGE}/stb_image.h`,
|
|
62
|
+
sha256: "594c2fe35d49488b4382dbfaec8f98366defca819d916ac95becf3e75f4200b3",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
package: "stb",
|
|
66
|
+
name: "stb_truetype.h",
|
|
67
|
+
url: `${RAW}/nothings/stb/${STB_TRUETYPE}/stb_truetype.h`,
|
|
68
|
+
sha256: "a34d8d536ce7c11b9163ab2d524721c1f4df1452cce6595c4f11d3048384f925",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
package: "nanosvg",
|
|
72
|
+
name: "nanosvg.h",
|
|
73
|
+
url: `${RAW}/memononen/nanosvg/${NANOSVG}/src/nanosvg.h`,
|
|
74
|
+
sha256: "e34fd5d084be106cea972d19ce5d27fd96d17ba89f8d06bdceee058420c8b2b0",
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
package: "nanosvg",
|
|
78
|
+
name: "nanosvgrast.h",
|
|
79
|
+
url: `${RAW}/memononen/nanosvg/${NANOSVG}/src/nanosvgrast.h`,
|
|
80
|
+
sha256: "79a9c5f4db19debf9f3a648a1589e96d92854f245a5cb4f3d823f263785234d8",
|
|
81
|
+
},
|
|
82
|
+
...(
|
|
83
|
+
[
|
|
84
|
+
["miniz.c", "29a0c08c4610d20ab18381cbf18190f91b4b41d05c242376364756061b631f1d"],
|
|
85
|
+
["miniz.h", "2b9c48355793988f0d12b3cef357e52b741d744385157b59cb422237ea226501"],
|
|
86
|
+
["miniz_common.h", "d0770cc478923e33bf22820fc51bbe22b6b99c3230ce4f5fc10eea3debc75623"],
|
|
87
|
+
["miniz_tdef.c", "7b3baaa59f50116eb3e72a23302c505b76cb01cc456672f7957a74d9e7b44047"],
|
|
88
|
+
["miniz_tdef.h", "123050e3c876519828d3934899e0b003ad13a98114919d94f1e06b4b9d02a925"],
|
|
89
|
+
["miniz_tinfl.c", "7113a08a7722d671ce89b8de61fe6d02d0cadca0ff274ba357bf2a9dc85745ca"],
|
|
90
|
+
["miniz_tinfl.h", "2c89615a4cbc5de4eac5b861051849392ec698264ee7dd399ea587c592cf68d1"],
|
|
91
|
+
["miniz_zip.h", "43d09867f79993a9ba1627cb1f3bbd78d3bf5ee0c91cd6e7527aa9ca1e3aed44"],
|
|
92
|
+
] as const
|
|
93
|
+
).map(([name, sha256]) => ({
|
|
94
|
+
package: "miniz" as const,
|
|
95
|
+
name,
|
|
96
|
+
url: `${RAW}/richgel999/miniz/${MINIZ}/${name}`,
|
|
97
|
+
sha256,
|
|
98
|
+
})),
|
|
99
|
+
];
|
|
100
|
+
|
|
101
|
+
/** miniz's static-build export shim (upstream generates it with CMake). */
|
|
102
|
+
const MINIZ_EXPORT_H =
|
|
103
|
+
"/* Minimal export macro for a static miniz build (no DLL import/export). */\n" +
|
|
104
|
+
"#ifndef MINIZ_EXPORT\n" +
|
|
105
|
+
"#define MINIZ_EXPORT\n" +
|
|
106
|
+
"#endif\n";
|
|
107
|
+
|
|
108
|
+
/* SQLite publishes one amalgamation zip per release; only the two files below
|
|
109
|
+
* are compiled. The zip itself is pinned as well: a truncated download is a
|
|
110
|
+
* download to retry, not an amalgamation to build. */
|
|
111
|
+
const SQLITE_PACKAGE = "sqlite-amalgamation-3540100";
|
|
112
|
+
const SQLITE_URL = `https://www.sqlite.org/2026/${SQLITE_PACKAGE}.zip`;
|
|
113
|
+
const SQLITE_ZIP_SHA256 = "0a9c8e34352dad46006aa82836d5383bff9dc6bc9ce5a60553c05aa30e6ad1f9";
|
|
114
|
+
const SQLITE_FILES = [
|
|
115
|
+
{
|
|
116
|
+
name: "sqlite3.c",
|
|
117
|
+
sha256: "0c657666d819f261cc4007526ad57e1669de9949df7a8ea847aa284a2bf0ee52",
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "sqlite3.h",
|
|
121
|
+
sha256: "d6c84557261893439b341d2e6c35187ae3ea24fbfd843ad94616f72d89242b8c",
|
|
122
|
+
},
|
|
123
|
+
] as const;
|
|
124
|
+
|
|
125
|
+
function sha256(file: string): string {
|
|
126
|
+
return createHash("sha256").update(readFileSync(file)).digest("hex");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function isPinned(file: string, digest: string): boolean {
|
|
130
|
+
return existsSync(file) && sha256(file) === digest;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Download one file, refusing to leave a mismatched (stale or corrupted) file. */
|
|
134
|
+
function ensureFile(file: VendoredFile): void {
|
|
135
|
+
const target = join(vendorDir, file.package, file.name);
|
|
136
|
+
if (isPinned(target, file.sha256)) return;
|
|
137
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
138
|
+
rmSync(target, { force: true });
|
|
139
|
+
downloadTarball(target, file.url, `${file.package}/${file.name}`);
|
|
140
|
+
if (isPinned(target, file.sha256)) return;
|
|
141
|
+
const actual = sha256(target);
|
|
142
|
+
rmSync(target, { force: true });
|
|
143
|
+
throw new Error(
|
|
144
|
+
`${file.package}/${file.name}: expected sha256 ${file.sha256}, got ${actual}. ` +
|
|
145
|
+
"The upstream pin moved; update the URL and hash in scripts/fetch-vendored.ts deliberately.",
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Write the generated miniz export shim (no upstream file to download). */
|
|
150
|
+
function ensureMinizExportHeader(): void {
|
|
151
|
+
const target = join(vendorDir, "miniz", "miniz_export.h");
|
|
152
|
+
if (existsSync(target) && readFileSync(target, "utf8") === MINIZ_EXPORT_H) return;
|
|
153
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
154
|
+
writeFileSync(target, MINIZ_EXPORT_H);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Extract a zip archive; Windows' bsdtar and POSIX's unzip cover the hosts. */
|
|
158
|
+
function extractZip(zip: string, destination: string): void {
|
|
159
|
+
const attempts: readonly (readonly [string, readonly string[]])[] =
|
|
160
|
+
process.platform === "win32"
|
|
161
|
+
? [
|
|
162
|
+
["tar", ["-xf", zip, "-C", destination]],
|
|
163
|
+
["unzip", ["-q", "-o", zip, "-d", destination]],
|
|
164
|
+
]
|
|
165
|
+
: [
|
|
166
|
+
["unzip", ["-q", "-o", zip, "-d", destination]],
|
|
167
|
+
["tar", ["-xf", zip, "-C", destination]],
|
|
168
|
+
];
|
|
169
|
+
for (const [command, args] of attempts) {
|
|
170
|
+
if (spawnSync(command, args, { stdio: "ignore" }).status === 0) return;
|
|
171
|
+
}
|
|
172
|
+
throw new Error(`cannot extract ${basename(zip)}; install unzip (or a tar that reads zip archives)`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Fetch the pinned SQLite amalgamation and copy out its two sources. */
|
|
176
|
+
function ensureSqlite(): void {
|
|
177
|
+
const directory = join(vendorDir, "sqlite3");
|
|
178
|
+
if (SQLITE_FILES.every((file) => isPinned(join(directory, file.name), file.sha256))) return;
|
|
179
|
+
|
|
180
|
+
const cache = join(vendorDir, ".cache");
|
|
181
|
+
mkdirSync(cache, { recursive: true });
|
|
182
|
+
const zip = join(cache, `${SQLITE_PACKAGE}.zip`);
|
|
183
|
+
if (!isPinned(zip, SQLITE_ZIP_SHA256)) {
|
|
184
|
+
rmSync(zip, { force: true });
|
|
185
|
+
downloadTarball(zip, SQLITE_URL, `${SQLITE_PACKAGE}.zip`);
|
|
186
|
+
if (!isPinned(zip, SQLITE_ZIP_SHA256)) {
|
|
187
|
+
const actual = sha256(zip);
|
|
188
|
+
rmSync(zip, { force: true });
|
|
189
|
+
throw new Error(`${SQLITE_PACKAGE}.zip: expected sha256 ${SQLITE_ZIP_SHA256}, got ${actual}`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const extracted = join(cache, SQLITE_PACKAGE);
|
|
194
|
+
rmSync(extracted, { recursive: true, force: true });
|
|
195
|
+
mkdirSync(extracted, { recursive: true });
|
|
196
|
+
extractZip(zip, extracted);
|
|
197
|
+
const sourceDir = join(extracted, SQLITE_PACKAGE);
|
|
198
|
+
if (!existsSync(join(sourceDir, "sqlite3.c"))) {
|
|
199
|
+
throw new Error(`expected ${SQLITE_PACKAGE}/sqlite3.c after extracting ${basename(zip)}`);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
mkdirSync(directory, { recursive: true });
|
|
203
|
+
for (const file of SQLITE_FILES) {
|
|
204
|
+
const target = join(directory, file.name);
|
|
205
|
+
copyFileSync(join(sourceDir, file.name), target);
|
|
206
|
+
if (!isPinned(target, file.sha256)) {
|
|
207
|
+
const actual = sha256(target);
|
|
208
|
+
rmSync(target, { force: true });
|
|
209
|
+
throw new Error(`sqlite3/${file.name}: expected sha256 ${file.sha256}, got ${actual}`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
rmSync(extracted, { recursive: true, force: true });
|
|
213
|
+
rmSync(zip, { force: true });
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Ensure the requested vendored packages exist and match their pins.
|
|
218
|
+
* Downloads only what is missing; everything else is a content check.
|
|
219
|
+
*/
|
|
220
|
+
export function ensureVendoredSources(packages: readonly VendorPackage[] = VENDOR_PACKAGES): void {
|
|
221
|
+
for (const name of packages) {
|
|
222
|
+
if (name === "sqlite3") {
|
|
223
|
+
ensureSqlite();
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
for (const file of FILES) {
|
|
227
|
+
if (file.package === name) ensureFile(file);
|
|
228
|
+
}
|
|
229
|
+
if (name === "miniz") ensureMinizExportHeader();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const invokedDirectly =
|
|
234
|
+
process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href;
|
|
235
|
+
|
|
236
|
+
if (invokedDirectly) {
|
|
237
|
+
try {
|
|
238
|
+
ensureVendoredSources();
|
|
239
|
+
console.log("xbintsc: vendored sources are present and match their pins");
|
|
240
|
+
} catch (error) {
|
|
241
|
+
console.error(`xbintsc: ${error instanceof Error ? error.message : String(error)}`);
|
|
242
|
+
process.exit(1);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* xbintsc-<os>-<arch>/
|
|
22
22
|
* bin/xbintsc[.exe] the self-hosted compiler
|
|
23
23
|
* runtime/ C runtime sources + prebuilt runtime/lib/<slug>
|
|
24
|
+
* vendor/ pinned third-party sources (fetched, not committed)
|
|
24
25
|
* README.md
|
|
25
26
|
*
|
|
26
27
|
* The compiler locates `runtime/` relative to its own executable (see
|
|
@@ -108,13 +109,22 @@ console.log("xbintsc: copying runtime/ into the staging tree");
|
|
|
108
109
|
cpSync(findRuntimeDir(), join(stage, "runtime"), { recursive: true });
|
|
109
110
|
console.log("xbintsc: packaged runtime/");
|
|
110
111
|
|
|
111
|
-
// 3.
|
|
112
|
+
// 3. Vendored sources the driver compiles on demand (SQLite for `storage`,
|
|
113
|
+
// miniz for `compression`). They are fetched by `npm run vendor`, not committed.
|
|
114
|
+
for (const name of ["stb", "nanosvg", "miniz", "sqlite3"]) {
|
|
115
|
+
const source = join(root, "vendor", name);
|
|
116
|
+
if (!existsSync(source)) fail(`missing vendor/${name}; run \`npm run vendor\` before packaging`);
|
|
117
|
+
cpSync(source, join(stage, "vendor", name), { recursive: true });
|
|
118
|
+
}
|
|
119
|
+
console.log("xbintsc: packaged vendor/");
|
|
120
|
+
|
|
121
|
+
// 4. Human-facing notes.
|
|
112
122
|
for (const name of ["README.md", "LICENSE"]) {
|
|
113
123
|
const source = join(root, name);
|
|
114
124
|
if (existsSync(source)) copyFileSync(source, join(stage, name));
|
|
115
125
|
}
|
|
116
126
|
|
|
117
|
-
//
|
|
127
|
+
// 5. Archive it. Prefer zstd when available, otherwise gzip.
|
|
118
128
|
const hasZstd = !spawnSync("zstd", ["--version"], { stdio: "ignore" }).error;
|
|
119
129
|
const extension = releaseArchiveExtension(hasZstd);
|
|
120
130
|
const archive = join(releaseRoot, `${archiveBase}${extension}`);
|
|
@@ -128,7 +138,7 @@ const tar = spawnSync("tar", tarArgs, { stdio: "inherit" });
|
|
|
128
138
|
if (tar.error) fail(`failed to run tar: ${tar.error.message}`);
|
|
129
139
|
if (tar.status !== 0) fail(`tar exited with ${tar.status}`);
|
|
130
140
|
|
|
131
|
-
//
|
|
141
|
+
// 6. Checksum, so users can verify the download.
|
|
132
142
|
const digest = createHash("sha256").update(readFileSync(archive)).digest("hex");
|
|
133
143
|
writeFileSync(`${archive}.sha256`, `${digest} ${basename(archive)}\n`);
|
|
134
144
|
|
package/src/driver/build-key.ts
CHANGED
|
@@ -11,7 +11,12 @@
|
|
|
11
11
|
import type { ExtensionRegistry } from "../extensions/registry.js";
|
|
12
12
|
import { hashParts } from "./cache.js";
|
|
13
13
|
import type { AppConfig } from "./config.js";
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
compilerFingerprint,
|
|
16
|
+
registryFingerprint,
|
|
17
|
+
runtimeFingerprint,
|
|
18
|
+
vendoredRuntimeFingerprint,
|
|
19
|
+
} from "./fingerprint.js";
|
|
15
20
|
import { COMPILER_VERSION } from "./version.js";
|
|
16
21
|
import type { IconInfo } from "./icon.js";
|
|
17
22
|
import type { ResolvedStorage } from "./storage.js";
|
|
@@ -50,6 +55,7 @@ export function buildCacheKey(input: CacheKeyInput): string {
|
|
|
50
55
|
process.platform,
|
|
51
56
|
registryFingerprint(input.registry),
|
|
52
57
|
runtimeFingerprint(input.runtimeDir),
|
|
58
|
+
vendoredRuntimeFingerprint(input.runtimeDir),
|
|
53
59
|
icon ? hashParts(["icon", icon.format, Buffer.from(icon.bytes).toString("base64")]) : "",
|
|
54
60
|
app.name ?? "",
|
|
55
61
|
String(app.bundle ?? false),
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Source-level module bundler
|
|
2
|
+
|
|
3
|
+
xbintsc has no runtime module system and no module linker. The driver resolves
|
|
4
|
+
every reachable module, renames its top-level bindings to globally unique
|
|
5
|
+
`<prefix><name>` identifiers, rewrites imports to those final names, and
|
|
6
|
+
concatenates the whole graph into one source file for codegen.
|
|
7
|
+
|
|
8
|
+
The public entry point is `bundleModules()` in `../modules.ts`; everything in
|
|
9
|
+
this directory is an implementation detail of it.
|
|
10
|
+
|
|
11
|
+
## Pipeline
|
|
12
|
+
|
|
13
|
+
| Phase | Location | Work |
|
|
14
|
+
| --- | --- | --- |
|
|
15
|
+
| 1 | `merge.ts` | Record top-level bindings and pick a unique final name per symbol. |
|
|
16
|
+
| 1b | `commonjs.ts` | Give CommonJS `node_modules` files synthetic `module` / `exports` state. |
|
|
17
|
+
| 2 | `merge.ts` | Fill every module's `exports` map from declarations and re-exports. |
|
|
18
|
+
| 2b | `commonjs.ts` | Lower `require("…")` to the already-bundled dependency's exports. |
|
|
19
|
+
| 3 | `merge.ts` | Rewrite imported names; lower deferred imports and namespace bindings. |
|
|
20
|
+
| 3b | `reexport-resolution.ts` | Re-resolve re-export chains to a fixpoint; rebuild eager namespace objects. |
|
|
21
|
+
| 4 | `concatenate.ts` | Emit statements in dependency order, dropping local imports and export wrappers. |
|
|
22
|
+
| 5 | `concatenate.ts` | Apply the final rename to each top-level declaration and reference. |
|
|
23
|
+
|
|
24
|
+
Phases 4-5 live in `concatenate.ts` so `merge.ts` stays focused on name and
|
|
25
|
+
export resolution.
|
|
26
|
+
|
|
27
|
+
## Files
|
|
28
|
+
|
|
29
|
+
| File | Responsibility |
|
|
30
|
+
| --- | --- |
|
|
31
|
+
| `types.ts` | `ModuleRecord`, `BundleResult`, resolution types. |
|
|
32
|
+
| `resolve.ts` | Specifier resolution: relative paths, directory indexes, package `exports`, `node_modules`. |
|
|
33
|
+
| `graph.ts` | Load and bind the import graph in dependency order. |
|
|
34
|
+
| `symbols.ts` | Top-level symbol lookup, declaration/reference renaming, export-map remapping. |
|
|
35
|
+
| `merge.ts` | Orchestrates phases 1-3 and produces the resolved module records. |
|
|
36
|
+
| `reexport-resolution.ts` | Fixpoint over `export … from` chains; rebuilds namespace objects from final names. |
|
|
37
|
+
| `namespace-object.ts` | Synthesizes `const ns = { name: finalName, … }` for namespace imports/re-exports. |
|
|
38
|
+
| `deferred.ts` | `<script src>` deferred evaluation: wrapper functions, alias lowering, deferred-set computation. |
|
|
39
|
+
| `dynamic-import.ts` | Lowers string-literal `import()` to a promise over the target's wrapper. |
|
|
40
|
+
| `commonjs.ts` | CommonJS interop for `node_modules` sources. |
|
|
41
|
+
| `concatenate.ts` | Phases 4-5: emit the merged statement list and rename declarations. |
|
|
42
|
+
|
|
43
|
+
## Invariants
|
|
44
|
+
|
|
45
|
+
- **No live bindings.** An imported name is a snapshot of the exported value at
|
|
46
|
+
module-evaluation time.
|
|
47
|
+
- **The entry module is last** in the record order; dependencies are
|
|
48
|
+
post-order.
|
|
49
|
+
- **Deferred modules own their bindings.** A deferred module's top-level names
|
|
50
|
+
are local to its `__xt_deferred_*` wrapper. A namespace binding between two
|
|
51
|
+
deferred modules must stay an alias that reads the dependency's wrapper
|
|
52
|
+
(`deferred.ts`); it must not be rebuilt at top level from wrapper-local names
|
|
53
|
+
(TS3002). Regression coverage: `tests/driver/deferred-reexport.test.ts`.
|
|
54
|
+
- **Re-exports are settled before concatenation.** Phase 3b runs to a fixpoint
|
|
55
|
+
so multi-level `export … from` chains and cycle back-edges see final names.
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Concatenate the merged modules into one source file (bundle phases 4-5).
|
|
3
|
+
*
|
|
4
|
+
* Phase 4 walks every module in dependency order and copies its statements into
|
|
5
|
+
* a single statement list: external imports stay at top level, local imports are
|
|
6
|
+
* dropped (their bindings were rewritten in phase 3), and a deferred module's
|
|
7
|
+
* body is emitted inside its `__xt_deferred_*` wrapper. Phase 5 then renames
|
|
8
|
+
* every top-level declaration and reference to its final unique name.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { dirname } from "node:path";
|
|
12
|
+
import {
|
|
13
|
+
ModifierKind,
|
|
14
|
+
SyntaxKind,
|
|
15
|
+
type ExportAssignment,
|
|
16
|
+
type ExportDeclaration,
|
|
17
|
+
type Identifier,
|
|
18
|
+
type ImportDeclaration,
|
|
19
|
+
type Modifier,
|
|
20
|
+
type Node,
|
|
21
|
+
type SourceFileNode,
|
|
22
|
+
type Statement,
|
|
23
|
+
type VariableDeclaration,
|
|
24
|
+
type VariableDeclarationList,
|
|
25
|
+
} from "../../ast/nodes.js";
|
|
26
|
+
import { SymbolKind } from "../../binder/binder.js";
|
|
27
|
+
import { deferredModuleFunctions, eagerModuleFunctions, type DeferredAlias } from "./deferred.js";
|
|
28
|
+
import { classifyDependency } from "./resolve.js";
|
|
29
|
+
import { renameSymbol, topLevelSymbols } from "./symbols.js";
|
|
30
|
+
import type { ModuleRecord } from "./types.js";
|
|
31
|
+
|
|
32
|
+
export interface ConcatenateOptions {
|
|
33
|
+
readonly records: readonly ModuleRecord[];
|
|
34
|
+
readonly deferredModules: ReadonlySet<string>;
|
|
35
|
+
readonly deferredAliases: ReadonlyMap<string, readonly DeferredAlias[]>;
|
|
36
|
+
readonly markerTargets: ReadonlySet<string>;
|
|
37
|
+
readonly dynamicTargets: ReadonlySet<string>;
|
|
38
|
+
readonly namespaceStatements: ReadonlyMap<Statement, Statement>;
|
|
39
|
+
readonly externalSpecifiers: ReadonlySet<string>;
|
|
40
|
+
readonly moduleOverrides?: Readonly<Record<string, string>>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function concatenateModules(options: ConcatenateOptions): SourceFileNode {
|
|
44
|
+
const {
|
|
45
|
+
records,
|
|
46
|
+
deferredModules,
|
|
47
|
+
deferredAliases,
|
|
48
|
+
markerTargets,
|
|
49
|
+
dynamicTargets,
|
|
50
|
+
namespaceStatements,
|
|
51
|
+
externalSpecifiers,
|
|
52
|
+
moduleOverrides,
|
|
53
|
+
} = options;
|
|
54
|
+
const merged: Statement[] = [];
|
|
55
|
+
/* Every node keeps the module it was parsed from, so a later codegen
|
|
56
|
+
* diagnostic can name the right file and line instead of pointing into the
|
|
57
|
+
* entry module (whose text happens to start at the same offsets). */
|
|
58
|
+
const origins = new Map<object, string>();
|
|
59
|
+
/* A synthesized module (an extension asset loader such as the `gui` `.html`
|
|
60
|
+
* transform) may contain spans copied from another file — a `<script
|
|
61
|
+
* src="app.js">` body, say. Nodes inside such a span keep that file, so a
|
|
62
|
+
* diagnostic points at real source and a plain-`.js` script stays exempt
|
|
63
|
+
* from the type checker. */
|
|
64
|
+
const originOf = (record: ModuleRecord, node: Node): string => {
|
|
65
|
+
const ranges = record.originRanges;
|
|
66
|
+
if (ranges === undefined) return record.path;
|
|
67
|
+
for (const range of ranges) {
|
|
68
|
+
if (node.start >= range.start && node.end <= range.end) return range.file;
|
|
69
|
+
}
|
|
70
|
+
return record.path;
|
|
71
|
+
};
|
|
72
|
+
const trackOrigin = (record: ModuleRecord, root: Node): void => {
|
|
73
|
+
const visit = (node: Node): void => {
|
|
74
|
+
origins.set(node, originOf(record, node));
|
|
75
|
+
const fields = node as unknown as Record<string, unknown>;
|
|
76
|
+
for (const key of Object.keys(fields)) {
|
|
77
|
+
if (key === "kind" || key === "start" || key === "end" || key === "text" || key === "value" || key === "raw") {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const value = fields[key];
|
|
81
|
+
if (Array.isArray(value)) {
|
|
82
|
+
for (const child of value) if (isNode(child)) visit(child);
|
|
83
|
+
} else if (isNode(value)) {
|
|
84
|
+
visit(value);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
visit(root);
|
|
89
|
+
};
|
|
90
|
+
const push = (record: ModuleRecord, statement: Statement): void => {
|
|
91
|
+
trackOrigin(record, statement);
|
|
92
|
+
merged.push(statement);
|
|
93
|
+
};
|
|
94
|
+
const first = records[records.length - 1]!;
|
|
95
|
+
for (const record of records) {
|
|
96
|
+
if (deferredModules.has(record.path)) {
|
|
97
|
+
/* A deferred module is evaluated by the wrapper when a script runs. Its
|
|
98
|
+
* external imports stay top-level (codegen resolves them there); eager
|
|
99
|
+
* namespace objects likewise. */
|
|
100
|
+
const topLevel: Statement[] = [];
|
|
101
|
+
const body: Statement[] = [];
|
|
102
|
+
for (const statement of record.sourceFile.statements) {
|
|
103
|
+
if (statement.kind === SyntaxKind.ImportDeclaration) {
|
|
104
|
+
const declaration = statement as ImportDeclaration;
|
|
105
|
+
const resolution = classifyDependency(
|
|
106
|
+
dirname(record.path), declaration.moduleSpecifier.value, externalSpecifiers, moduleOverrides,
|
|
107
|
+
);
|
|
108
|
+
if (resolution.kind === "external") topLevel.push(statement);
|
|
109
|
+
const synthetic = namespaceStatements.get(statement);
|
|
110
|
+
if (synthetic) topLevel.push(synthetic);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (statement.kind === SyntaxKind.ExportDeclaration) {
|
|
114
|
+
const declaration = statement as ExportDeclaration;
|
|
115
|
+
const inner = (declaration as unknown as { declaration?: Statement }).declaration;
|
|
116
|
+
if (inner) body.push(inner);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (statement.kind === SyntaxKind.ExportAssignment) {
|
|
120
|
+
body.push(exportAssignmentToStatement(record, statement as ExportAssignment));
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
stripExportModifiers(statement);
|
|
124
|
+
body.push(statement);
|
|
125
|
+
}
|
|
126
|
+
for (const statement of topLevel) push(record, statement);
|
|
127
|
+
for (const statement of deferredModuleFunctions(
|
|
128
|
+
record,
|
|
129
|
+
deferredAliases.get(record.path) ?? [],
|
|
130
|
+
body,
|
|
131
|
+
)) {
|
|
132
|
+
push(record, statement);
|
|
133
|
+
}
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
for (const statement of record.sourceFile.statements) {
|
|
137
|
+
if (statement.kind === SyntaxKind.ImportDeclaration) {
|
|
138
|
+
// External (extension / built-in) imports stay in place for codegen.
|
|
139
|
+
const declaration = statement as ImportDeclaration;
|
|
140
|
+
const resolution = classifyDependency(
|
|
141
|
+
dirname(record.path), declaration.moduleSpecifier.value, externalSpecifiers, moduleOverrides,
|
|
142
|
+
);
|
|
143
|
+
if (resolution.kind === "external") {
|
|
144
|
+
push(record, statement);
|
|
145
|
+
} else {
|
|
146
|
+
const synthetic = namespaceStatements.get(statement);
|
|
147
|
+
if (synthetic) push(record, synthetic);
|
|
148
|
+
}
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (statement.kind === SyntaxKind.ExportDeclaration) {
|
|
152
|
+
const declaration = statement as ExportDeclaration;
|
|
153
|
+
const synthetic = namespaceStatements.get(statement);
|
|
154
|
+
if (synthetic) {
|
|
155
|
+
push(record, synthetic);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const inner = (declaration as unknown as { declaration?: Statement }).declaration;
|
|
159
|
+
if (inner) push(record, inner);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (statement.kind === SyntaxKind.ExportAssignment) {
|
|
163
|
+
const assignment = statement as ExportAssignment;
|
|
164
|
+
push(record, exportAssignmentToStatement(record, assignment));
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
push(record, statement);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/* A marker or dynamic-import target that stayed eager still needs a wrapper:
|
|
172
|
+
* its exports are already initialised. */
|
|
173
|
+
for (const record of records) {
|
|
174
|
+
if (deferredModules.has(record.path) || (!markerTargets.has(record.path) && !dynamicTargets.has(record.path))) continue;
|
|
175
|
+
for (const statement of eagerModuleFunctions(record)) push(record, statement);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
for (const record of records) {
|
|
179
|
+
for (const symbol of topLevelSymbols(record)) {
|
|
180
|
+
if (symbol.kind === SymbolKind.Import) continue;
|
|
181
|
+
const finalName = record.finalNames.get(symbol.id);
|
|
182
|
+
if (finalName) renameSymbol(symbol, finalName);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
kind: SyntaxKind.SourceFile,
|
|
188
|
+
statements: merged,
|
|
189
|
+
fileName: first.path,
|
|
190
|
+
origins,
|
|
191
|
+
moduleTexts: new Map(records.map((record) => [record.path, record.text])),
|
|
192
|
+
modulePrefixes: records.map((record) => record.prefix),
|
|
193
|
+
text: records.map((record) => record.text).join("\n"),
|
|
194
|
+
start: 0,
|
|
195
|
+
end: 0,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Drop `export` / `export default` from a statement moved into a wrapper. */
|
|
200
|
+
function stripExportModifiers(statement: Statement): void {
|
|
201
|
+
const modifiers = (statement as { modifiers?: Modifier[] }).modifiers;
|
|
202
|
+
if (!modifiers) return;
|
|
203
|
+
(statement as { modifiers: Modifier[] }).modifiers = modifiers.filter(
|
|
204
|
+
(modifier) => modifier.modifierKind !== ModifierKind.Export && modifier.modifierKind !== ModifierKind.Default,
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** True for anything shaped like an AST node (constructed nodes carry no trivia). */
|
|
209
|
+
function isNode(value: unknown): value is Node {
|
|
210
|
+
return !!value && typeof value === "object" && "kind" in (value as object);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** Turn `export default expr` into a synthetic `const` declaration. */
|
|
214
|
+
function exportAssignmentToStatement(record: ModuleRecord, assignment: ExportAssignment): Statement {
|
|
215
|
+
const name: Identifier = {
|
|
216
|
+
kind: SyntaxKind.Identifier,
|
|
217
|
+
text: `${record.prefix}default`,
|
|
218
|
+
start: assignment.start,
|
|
219
|
+
end: assignment.start,
|
|
220
|
+
};
|
|
221
|
+
record.exports.set("default", name.text);
|
|
222
|
+
const declaration: VariableDeclaration = {
|
|
223
|
+
kind: SyntaxKind.VariableDeclaration,
|
|
224
|
+
name,
|
|
225
|
+
exclamation: false,
|
|
226
|
+
initializer: assignment.expression,
|
|
227
|
+
start: assignment.start,
|
|
228
|
+
end: assignment.end,
|
|
229
|
+
};
|
|
230
|
+
const list: VariableDeclarationList = {
|
|
231
|
+
kind: SyntaxKind.VariableDeclarationList,
|
|
232
|
+
declarationKind: "const" as const,
|
|
233
|
+
declarations: [declaration],
|
|
234
|
+
start: assignment.start,
|
|
235
|
+
end: assignment.end,
|
|
236
|
+
};
|
|
237
|
+
return {
|
|
238
|
+
kind: SyntaxKind.VariableStatement,
|
|
239
|
+
declarationList: list,
|
|
240
|
+
modifiers: [],
|
|
241
|
+
start: assignment.start,
|
|
242
|
+
end: assignment.end,
|
|
243
|
+
};
|
|
244
|
+
}
|