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
|
@@ -1,54 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Bundling pass orchestrator (phases 1-3).
|
|
3
3
|
*
|
|
4
4
|
* Dependencies come first (post-order over the import graph), the entry module
|
|
5
|
-
* last.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* last. These passes record each module's exports, pick globally unique final
|
|
6
|
+
* names, rewrite imported names and lower deferred imports. `concatenate.ts`
|
|
7
|
+
* then emits the statement list and applies the final renames (phases 4-5).
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { dirname } from "node:path";
|
|
11
11
|
import {
|
|
12
12
|
ModifierKind,
|
|
13
13
|
SyntaxKind,
|
|
14
|
-
type ExportAssignment,
|
|
15
14
|
type ExportDeclaration,
|
|
16
15
|
type Identifier,
|
|
17
16
|
type ImportDeclaration,
|
|
18
|
-
type Modifier,
|
|
19
17
|
type Node,
|
|
20
|
-
type SourceFileNode,
|
|
21
18
|
type Statement,
|
|
22
|
-
type VariableDeclaration,
|
|
23
|
-
type VariableDeclarationList,
|
|
24
19
|
type VariableStatement,
|
|
25
20
|
} from "../../ast/nodes.js";
|
|
26
|
-
import { namespaceImportToStatement } from "./namespace-import.js";
|
|
27
|
-
import { resolveReexports } from "./reexport-fixup.js";
|
|
28
21
|
import type { BindingName } from "../../ast/declarations.js";
|
|
29
22
|
import { SymbolKind } from "../../binder/binder.js";
|
|
30
23
|
import type { DiagnosticBag } from "../../diagnostics/diagnostic.js";
|
|
31
24
|
import type { AssetLoader } from "../../extensions/registry.js";
|
|
32
|
-
import {
|
|
25
|
+
import { concatenateModules } from "./concatenate.js";
|
|
33
26
|
import { lowerCommonJSRequires, prepareCommonJS } from "./commonjs.js";
|
|
34
|
-
import { prepareDynamicImports } from "./dynamic-import.js";
|
|
35
|
-
import { classifyDependency } from "./resolve.js";
|
|
36
27
|
import {
|
|
37
28
|
computeDeferredModules,
|
|
38
29
|
deferredAliasName,
|
|
39
|
-
deferredModuleFunctions,
|
|
40
30
|
deferredWrapperName,
|
|
41
|
-
eagerModuleFunctions,
|
|
42
31
|
isDeferredMarkerImport,
|
|
43
32
|
type DeferredAlias,
|
|
44
33
|
} from "./deferred.js";
|
|
34
|
+
import { prepareDynamicImports } from "./dynamic-import.js";
|
|
35
|
+
import { loadGraph } from "./graph.js";
|
|
36
|
+
import { namespaceImportToStatement } from "./namespace-object.js";
|
|
37
|
+
import { resolveReexports } from "./reexport-resolution.js";
|
|
38
|
+
import { classifyDependency } from "./resolve.js";
|
|
45
39
|
import {
|
|
46
40
|
declarationName,
|
|
47
41
|
hasModifier,
|
|
48
42
|
moduleScope,
|
|
49
43
|
renameImport,
|
|
50
44
|
renameReferences,
|
|
51
|
-
renameSymbol,
|
|
52
45
|
topLevelSymbols,
|
|
53
46
|
} from "./symbols.js";
|
|
54
47
|
import type { BundleResult, ModuleRecord } from "./types.js";
|
|
@@ -304,7 +297,7 @@ export function bundleModules(
|
|
|
304
297
|
}
|
|
305
298
|
|
|
306
299
|
if (clause.name) {
|
|
307
|
-
const target = dependency.exports.get("default")
|
|
300
|
+
const target = dependency.exports.get("default");
|
|
308
301
|
const local = scope.symbols.get(clause.name.text);
|
|
309
302
|
if (target && local) renameImport(record, local, target);
|
|
310
303
|
}
|
|
@@ -347,152 +340,18 @@ export function bundleModules(
|
|
|
347
340
|
// the final renamed names (multi-level re-export chains and cycle back-edges).
|
|
348
341
|
resolveReexports(records, dependencyOf, namespaceStatements, deferredModules);
|
|
349
342
|
|
|
350
|
-
//
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
const ranges = record.originRanges;
|
|
363
|
-
if (ranges === undefined) return record.path;
|
|
364
|
-
for (const range of ranges) {
|
|
365
|
-
if (node.start >= range.start && node.end <= range.end) return range.file;
|
|
366
|
-
}
|
|
367
|
-
return record.path;
|
|
368
|
-
};
|
|
369
|
-
const trackOrigin = (record: ModuleRecord, root: Node): void => {
|
|
370
|
-
const visit = (node: Node): void => {
|
|
371
|
-
origins.set(node, originOf(record, node));
|
|
372
|
-
const fields = node as unknown as Record<string, unknown>;
|
|
373
|
-
for (const key of Object.keys(fields)) {
|
|
374
|
-
if (key === "kind" || key === "start" || key === "end" || key === "text" || key === "value" || key === "raw") {
|
|
375
|
-
continue;
|
|
376
|
-
}
|
|
377
|
-
const value = fields[key];
|
|
378
|
-
if (Array.isArray(value)) {
|
|
379
|
-
for (const child of value) if (isNode(child)) visit(child);
|
|
380
|
-
} else if (isNode(value)) {
|
|
381
|
-
visit(value);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
visit(root);
|
|
386
|
-
};
|
|
387
|
-
const push = (record: ModuleRecord, statement: Statement): void => {
|
|
388
|
-
trackOrigin(record, statement);
|
|
389
|
-
merged.push(statement);
|
|
390
|
-
};
|
|
391
|
-
const first = records[records.length - 1]!;
|
|
392
|
-
for (const record of records) {
|
|
393
|
-
if (deferredModules.has(record.path)) {
|
|
394
|
-
/* A deferred module is evaluated by the wrapper when a script runs. Its
|
|
395
|
-
* external imports stay top-level (codegen resolves them there); eager
|
|
396
|
-
* namespace objects likewise. */
|
|
397
|
-
const topLevel: Statement[] = [];
|
|
398
|
-
const body: Statement[] = [];
|
|
399
|
-
for (const statement of record.sourceFile.statements) {
|
|
400
|
-
if (statement.kind === SyntaxKind.ImportDeclaration) {
|
|
401
|
-
const declaration = statement as ImportDeclaration;
|
|
402
|
-
const resolution = classifyDependency(
|
|
403
|
-
dirname(record.path), declaration.moduleSpecifier.value, externalSpecifiers, moduleOverrides,
|
|
404
|
-
);
|
|
405
|
-
if (resolution.kind === "external") topLevel.push(statement);
|
|
406
|
-
const synthetic = namespaceStatements.get(statement);
|
|
407
|
-
if (synthetic) topLevel.push(synthetic);
|
|
408
|
-
continue;
|
|
409
|
-
}
|
|
410
|
-
if (statement.kind === SyntaxKind.ExportDeclaration) {
|
|
411
|
-
const declaration = statement as ExportDeclaration;
|
|
412
|
-
const inner = (declaration as unknown as { declaration?: Statement }).declaration;
|
|
413
|
-
if (inner) body.push(inner);
|
|
414
|
-
continue;
|
|
415
|
-
}
|
|
416
|
-
if (statement.kind === SyntaxKind.ExportAssignment) {
|
|
417
|
-
body.push(exportAssignmentToStatement(record, statement as ExportAssignment));
|
|
418
|
-
continue;
|
|
419
|
-
}
|
|
420
|
-
stripExportModifiers(statement);
|
|
421
|
-
body.push(statement);
|
|
422
|
-
}
|
|
423
|
-
for (const statement of topLevel) push(record, statement);
|
|
424
|
-
for (const statement of deferredModuleFunctions(
|
|
425
|
-
record,
|
|
426
|
-
deferredAliases.get(record.path) ?? [],
|
|
427
|
-
body,
|
|
428
|
-
)) {
|
|
429
|
-
push(record, statement);
|
|
430
|
-
}
|
|
431
|
-
continue;
|
|
432
|
-
}
|
|
433
|
-
for (const statement of record.sourceFile.statements) {
|
|
434
|
-
if (statement.kind === SyntaxKind.ImportDeclaration) {
|
|
435
|
-
// External (extension / built-in) imports stay in place for codegen.
|
|
436
|
-
const declaration = statement as ImportDeclaration;
|
|
437
|
-
const resolution = classifyDependency(
|
|
438
|
-
dirname(record.path), declaration.moduleSpecifier.value, externalSpecifiers, moduleOverrides,
|
|
439
|
-
);
|
|
440
|
-
if (resolution.kind === "external") {
|
|
441
|
-
push(record, statement);
|
|
442
|
-
} else {
|
|
443
|
-
const synthetic = namespaceStatements.get(statement);
|
|
444
|
-
if (synthetic) push(record, synthetic);
|
|
445
|
-
}
|
|
446
|
-
continue;
|
|
447
|
-
}
|
|
448
|
-
if (statement.kind === SyntaxKind.ExportDeclaration) {
|
|
449
|
-
const declaration = statement as ExportDeclaration;
|
|
450
|
-
const synthetic = namespaceStatements.get(statement);
|
|
451
|
-
if (synthetic) {
|
|
452
|
-
push(record, synthetic);
|
|
453
|
-
continue;
|
|
454
|
-
}
|
|
455
|
-
const inner = (declaration as unknown as { declaration?: Statement }).declaration;
|
|
456
|
-
if (inner) push(record, inner);
|
|
457
|
-
continue;
|
|
458
|
-
}
|
|
459
|
-
if (statement.kind === SyntaxKind.ExportAssignment) {
|
|
460
|
-
const assignment = statement as ExportAssignment;
|
|
461
|
-
push(record, exportAssignmentToStatement(record, assignment));
|
|
462
|
-
continue;
|
|
463
|
-
}
|
|
464
|
-
push(record, statement);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
/* A marker or dynamic-import target that stayed eager still needs a wrapper:
|
|
469
|
-
* its exports are already initialised. */
|
|
470
|
-
for (const record of records) {
|
|
471
|
-
if (deferredModules.has(record.path) || (!markerTargets.has(record.path) && !dynamicTargets.has(record.path))) continue;
|
|
472
|
-
for (const statement of eagerModuleFunctions(record)) push(record, statement);
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
// Phase 5: rename every top-level binding (declaration + references) to its
|
|
476
|
-
// unique final name, now that import references have been rewritten.
|
|
477
|
-
for (const record of records) {
|
|
478
|
-
for (const symbol of topLevelSymbols(record)) {
|
|
479
|
-
if (symbol.kind === SymbolKind.Import) continue;
|
|
480
|
-
const finalName = record.finalNames.get(symbol.id);
|
|
481
|
-
if (finalName) renameSymbol(symbol, finalName);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
const sourceFile: SourceFileNode = {
|
|
486
|
-
kind: SyntaxKind.SourceFile,
|
|
487
|
-
statements: merged,
|
|
488
|
-
fileName: first.path,
|
|
489
|
-
origins,
|
|
490
|
-
moduleTexts: new Map(records.map((record) => [record.path, record.text])),
|
|
491
|
-
modulePrefixes: records.map((record) => record.prefix),
|
|
492
|
-
text: records.map((record) => record.text).join("\n"),
|
|
493
|
-
start: 0,
|
|
494
|
-
end: 0,
|
|
495
|
-
};
|
|
343
|
+
// Phases 4-5: concatenate the modules into one file and give every top-level
|
|
344
|
+
// binding its final name.
|
|
345
|
+
const sourceFile = concatenateModules({
|
|
346
|
+
records,
|
|
347
|
+
deferredModules,
|
|
348
|
+
deferredAliases,
|
|
349
|
+
markerTargets,
|
|
350
|
+
dynamicTargets,
|
|
351
|
+
namespaceStatements,
|
|
352
|
+
externalSpecifiers,
|
|
353
|
+
moduleOverrides,
|
|
354
|
+
});
|
|
496
355
|
return { sourceFile, text: sourceFile.text, moduleCount: records.length };
|
|
497
356
|
}
|
|
498
357
|
|
|
@@ -514,57 +373,7 @@ function collectBindingIdentifiers(name: BindingName, out: string[]): void {
|
|
|
514
373
|
out.push(name.text);
|
|
515
374
|
return;
|
|
516
375
|
}
|
|
517
|
-
const
|
|
518
|
-
for (const element of elements) {
|
|
376
|
+
for (const element of name.elements) {
|
|
519
377
|
if (element) collectBindingIdentifiers(element.name, out);
|
|
520
378
|
}
|
|
521
379
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
/** Drop `export` / `export default` from a statement moved into a wrapper. */
|
|
525
|
-
function stripExportModifiers(statement: Statement): void {
|
|
526
|
-
const modifiers = (statement as { modifiers?: Modifier[] }).modifiers;
|
|
527
|
-
if (!modifiers) return;
|
|
528
|
-
(statement as { modifiers: Modifier[] }).modifiers = modifiers.filter(
|
|
529
|
-
(modifier) => modifier.modifierKind !== ModifierKind.Export && modifier.modifierKind !== ModifierKind.Default,
|
|
530
|
-
);
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
/** True for anything shaped like an AST node (constructed nodes carry no trivia). */
|
|
534
|
-
function isNode(value: unknown): value is Node {
|
|
535
|
-
return !!value && typeof value === "object" && "kind" in (value as object);
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
/** Turn `export default expr` into a synthetic `const` declaration. */
|
|
539
|
-
function exportAssignmentToStatement(record: ModuleRecord, assignment: ExportAssignment): Statement {
|
|
540
|
-
const name: Identifier = {
|
|
541
|
-
kind: SyntaxKind.Identifier,
|
|
542
|
-
text: `${record.prefix}default`,
|
|
543
|
-
start: assignment.start,
|
|
544
|
-
end: assignment.start,
|
|
545
|
-
};
|
|
546
|
-
record.exports.set("default", name.text);
|
|
547
|
-
const declaration: VariableDeclaration = {
|
|
548
|
-
kind: SyntaxKind.VariableDeclaration,
|
|
549
|
-
name,
|
|
550
|
-
exclamation: false,
|
|
551
|
-
initializer: assignment.expression,
|
|
552
|
-
start: assignment.start,
|
|
553
|
-
end: assignment.end,
|
|
554
|
-
};
|
|
555
|
-
const list: VariableDeclarationList = {
|
|
556
|
-
kind: SyntaxKind.VariableDeclarationList,
|
|
557
|
-
declarationKind: "const" as const,
|
|
558
|
-
declarations: [declaration],
|
|
559
|
-
start: assignment.start,
|
|
560
|
-
end: assignment.end,
|
|
561
|
-
};
|
|
562
|
-
const statement: VariableStatement = {
|
|
563
|
-
kind: SyntaxKind.VariableStatement,
|
|
564
|
-
declarationList: list,
|
|
565
|
-
modifiers: [],
|
|
566
|
-
start: assignment.start,
|
|
567
|
-
end: assignment.end,
|
|
568
|
-
};
|
|
569
|
-
return statement;
|
|
570
|
-
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Build the synthetic object literal that stands in for a namespace binding.
|
|
3
|
+
*
|
|
4
|
+
* `import * as ns from "./mod"` and `export * as ns from "./mod"` are lowered
|
|
5
|
+
* to `const <final> = { exportName: finalName, ... }`, because the merged
|
|
6
|
+
* module has no runtime namespace object to point at.
|
|
3
7
|
*/
|
|
4
8
|
|
|
5
9
|
import {
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Resolve re-export chains and rebuild namespace objects from final names.
|
|
3
3
|
*
|
|
4
4
|
* Phase 2 records `export { x } from "./dep"` by copying the dependency's
|
|
5
5
|
* export *value* at that moment; if `dep` re-exports an import, that value is
|
|
6
6
|
* the pre-rename local name and is only corrected by Phase 3's import rewrite.
|
|
7
7
|
* A multi-level chain (`index -> sdk -> tools`) therefore needs a second pass,
|
|
8
8
|
* and a namespace import reaching back across a cycle needs the final names.
|
|
9
|
-
* This
|
|
10
|
-
*
|
|
9
|
+
* This pass re-resolves module re-exports until the export maps stop changing,
|
|
10
|
+
* then rebuilds every eager namespace object from those final names.
|
|
11
|
+
*
|
|
12
|
+
* Deferred modules (`<script src>`) are the exception: their bindings live in a
|
|
13
|
+
* wrapper function, so Phase 3 already lowered any namespace binding between
|
|
14
|
+
* two deferred modules to an alias that calls `__xt_deferred_<dep>()`. Such a
|
|
15
|
+
* binding must be left alone; rebuilding it here would reference wrapper-local
|
|
16
|
+
* names from the top level (TS3002 `Cannot find name`).
|
|
11
17
|
*/
|
|
12
18
|
|
|
13
19
|
import {
|
|
@@ -18,7 +24,7 @@ import {
|
|
|
18
24
|
type Statement,
|
|
19
25
|
} from "../../ast/nodes.js";
|
|
20
26
|
import type { ModuleRecord } from "./types.js";
|
|
21
|
-
import { namespaceImportToStatement } from "./namespace-
|
|
27
|
+
import { namespaceImportToStatement } from "./namespace-object.js";
|
|
22
28
|
|
|
23
29
|
export function resolveReexports(
|
|
24
30
|
records: ModuleRecord[],
|
|
@@ -89,7 +95,11 @@ export function resolveReexports(
|
|
|
89
95
|
const bindings = clause?.namedBindings;
|
|
90
96
|
if (bindings?.kind === SyntaxKind.NamespaceImport) {
|
|
91
97
|
const dependency = dependencyOf(record, declaration.moduleSpecifier.value);
|
|
92
|
-
|
|
98
|
+
/* Phase 3 already lowered a deferred module's namespace import of
|
|
99
|
+
* another deferred module to an alias read from the dependency's
|
|
100
|
+
* wrapper. Rebuilding the object here would reference the
|
|
101
|
+
* dependency's final names, which are wrapper-local (TS3002). */
|
|
102
|
+
if (dependency && !(deferredModules.has(record.path) && deferredModules.has(dependency.path))) {
|
|
93
103
|
namespaceStatements.set(
|
|
94
104
|
statement,
|
|
95
105
|
namespaceImportToStatement(statement, `${record.prefix}${bindings.name.text}`, dependency),
|
|
@@ -34,6 +34,30 @@ export function runtimeFingerprint(runtimeDir: string): string {
|
|
|
34
34
|
return hashParts(parts);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Content hash of the vendored C sources a link feature compiles into the
|
|
39
|
+
* program (`vendor/miniz` for `compression`, `vendor/sqlite3` for `storage`).
|
|
40
|
+
*
|
|
41
|
+
* They live outside `runtime/` — the tree is fetched, not committed — so
|
|
42
|
+
* {@link runtimeFingerprint} cannot see them, yet changing one changes the
|
|
43
|
+
* linked binary. Only the two packages compiled at program-build time are
|
|
44
|
+
* hashed: `stb`/`nanosvg` are baked into `gui.a`, whose content the registry
|
|
45
|
+
* fingerprint already covers.
|
|
46
|
+
*/
|
|
47
|
+
export function vendoredRuntimeFingerprint(runtimeDir: string): string {
|
|
48
|
+
const vendorDir = resolve(runtimeDir, "..", "vendor");
|
|
49
|
+
const parts: string[] = [];
|
|
50
|
+
for (const name of ["miniz", "sqlite3"]) {
|
|
51
|
+
const dir = join(vendorDir, name);
|
|
52
|
+
if (!existsSync(dir)) continue;
|
|
53
|
+
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
54
|
+
if (!entry.isFile()) continue;
|
|
55
|
+
parts.push(name, entry.name, readFileSync(join(dir, entry.name)).toString("base64"));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return hashParts(parts);
|
|
59
|
+
}
|
|
60
|
+
|
|
37
61
|
/**
|
|
38
62
|
* Content hash of the compiler's own TypeScript sources, when they are present.
|
|
39
63
|
*
|
|
@@ -94,33 +94,55 @@ export function resolveLinkFeatures(
|
|
|
94
94
|
}
|
|
95
95
|
if (specificallyForced || (forceAll && !specificallyBlocked)) forced.add(feature.name);
|
|
96
96
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
/* `strict` records the features whose absence is an error: everything the
|
|
98
|
+
* user asked for, plus its `requires` closure. An auto-detected feature is
|
|
99
|
+
* allowed to be unavailable (the driver warns), but a feature the user named
|
|
100
|
+
* must either link or fail the build. */
|
|
101
|
+
const strict = new Set(forced);
|
|
102
|
+
const expand = (target: Set<string>, roots: readonly string[]): void => {
|
|
103
|
+
const queue = [...roots];
|
|
104
|
+
while (queue.length > 0) {
|
|
105
|
+
const name = queue.pop()!;
|
|
106
|
+
const feature = byName.get(name);
|
|
107
|
+
if (feature === undefined) continue;
|
|
102
108
|
for (const dependency of feature.requires ?? []) {
|
|
103
109
|
if (!byName.has(dependency)) {
|
|
104
110
|
diagnostics.error(
|
|
105
111
|
DiagnosticCode.LinkFeatureUnavailable,
|
|
106
|
-
`link feature '${
|
|
112
|
+
`link feature '${name}' requires unknown feature '${dependency}'`,
|
|
107
113
|
);
|
|
108
114
|
continue;
|
|
109
115
|
}
|
|
110
116
|
if (disabled.has(dependency)) {
|
|
111
117
|
diagnostics.error(
|
|
112
118
|
DiagnosticCode.LinkFeatureUnavailable,
|
|
113
|
-
`link feature '${
|
|
119
|
+
`link feature '${name}' requires '${dependency}', which --no-feature disables`,
|
|
114
120
|
);
|
|
115
121
|
continue;
|
|
116
122
|
}
|
|
117
|
-
if (!
|
|
118
|
-
|
|
119
|
-
|
|
123
|
+
if (!target.has(dependency)) {
|
|
124
|
+
target.add(dependency);
|
|
125
|
+
queue.push(dependency);
|
|
120
126
|
}
|
|
121
127
|
}
|
|
122
128
|
}
|
|
129
|
+
};
|
|
130
|
+
expand(strict, [...strict]);
|
|
131
|
+
for (const name of strict) forced.add(name);
|
|
132
|
+
|
|
133
|
+
/* Select the program's auto-detected features and pull in `requires`
|
|
134
|
+
* transitively. Dependencies are resolved for every selected feature, not
|
|
135
|
+
* just the explicitly forced ones: `node:tls` is auto-detected from the
|
|
136
|
+
* import, and the transport it builds on (`tls`) must be linked with it. */
|
|
137
|
+
const autoRoots: string[] = [];
|
|
138
|
+
for (const { feature } of declarations) {
|
|
139
|
+
if (forced.has(feature.name) || disabled.has(feature.name)) continue;
|
|
140
|
+
if (disableAll && !requested.has(feature.name)) continue;
|
|
141
|
+
if (!feature.used(usage)) continue;
|
|
142
|
+
forced.add(feature.name);
|
|
143
|
+
autoRoots.push(feature.name);
|
|
123
144
|
}
|
|
145
|
+
expand(forced, autoRoots);
|
|
124
146
|
if (diagnostics.hasErrors) return [];
|
|
125
147
|
|
|
126
148
|
const resolved: ResolvedLinkFeature[] = [];
|
|
@@ -139,7 +161,7 @@ export function resolveLinkFeatures(
|
|
|
139
161
|
nativeObjects = feature.nativeObjects?.() ?? [];
|
|
140
162
|
} catch (error) {
|
|
141
163
|
const message = error instanceof Error ? error.message : String(error);
|
|
142
|
-
if (
|
|
164
|
+
if (strict.has(feature.name)) {
|
|
143
165
|
diagnostics.error(DiagnosticCode.LinkFeatureUnavailable, message);
|
|
144
166
|
} else {
|
|
145
167
|
diagnostics.warning(
|
package/src/driver/modules.ts
CHANGED
|
@@ -6,11 +6,18 @@
|
|
|
6
6
|
* Each module's top-level bindings are renamed to a globally unique name and
|
|
7
7
|
* imported names are rewritten to the (renamed) exported binding.
|
|
8
8
|
*
|
|
9
|
-
* The implementation lives under `bundler/`
|
|
10
|
-
* resolve.ts
|
|
11
|
-
* graph.ts
|
|
12
|
-
*
|
|
13
|
-
*
|
|
9
|
+
* The implementation lives under `bundler/` (see `bundler/README.md`):
|
|
10
|
+
* resolve.ts specifier/path/package resolution
|
|
11
|
+
* graph.ts import-graph loading (parse + bind)
|
|
12
|
+
* merge.ts bundling pass orchestrator (phases 1-3)
|
|
13
|
+
* reexport-resolution.ts re-export chain fixpoint + namespace objects
|
|
14
|
+
* namespace-object.ts namespace object literal builder
|
|
15
|
+
* deferred.ts `<script src>` deferred module wrappers
|
|
16
|
+
* dynamic-import.ts `import()` lowering
|
|
17
|
+
* commonjs.ts CommonJS compatibility in `node_modules`
|
|
18
|
+
* concatenate.ts final concatenation (phases 4-5)
|
|
19
|
+
* symbols.ts top-level symbol renaming
|
|
20
|
+
* types.ts shared types
|
|
14
21
|
*
|
|
15
22
|
* This file remains the public entry point for the driver and tests.
|
|
16
23
|
*/
|
package/src/driver/paths.ts
CHANGED
|
@@ -22,6 +22,26 @@ export function findRuntimeDir(): string {
|
|
|
22
22
|
throw new Error("Unable to locate the xbintsc runtime directory (missing runtime/rt.h)");
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Directory holding the third-party sources fetched by `npm run vendor`
|
|
27
|
+
* (`vendor/` next to `runtime/`).
|
|
28
|
+
*
|
|
29
|
+
* They are not committed: the tree is rebuilt from pinned upstream releases by
|
|
30
|
+
* `scripts/fetch-vendored.ts`. `runtime/xt_storage` and the `compression`
|
|
31
|
+
* feature resolve their C sources here, so a build that needs them fails with
|
|
32
|
+
* the command to run when the directory is missing.
|
|
33
|
+
*/
|
|
34
|
+
export function findVendorDir(): string {
|
|
35
|
+
const candidate = resolve(findRuntimeDir(), "..", "vendor");
|
|
36
|
+
const markers = [join("sqlite3", "sqlite3.c"), join("miniz", "miniz.c")];
|
|
37
|
+
if (markers.some((marker) => existsSync(join(candidate, marker)))) return candidate;
|
|
38
|
+
throw new Error(
|
|
39
|
+
"Unable to locate the xbintsc vendor directory (missing vendor/miniz/miniz.c or " +
|
|
40
|
+
"vendor/sqlite3/sqlite3.c); run `npm run vendor` in a source checkout, or reinstall " +
|
|
41
|
+
"xbintsc so the package's vendored sources are present.",
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
25
45
|
/** Platform-architecture slug, e.g. `darwin-arm64`, `linux-x64`, `win32-x64`. */
|
|
26
46
|
export function platformSlug(): string {
|
|
27
47
|
return `${process.platform}-${process.arch}`;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
10
|
-
import { basename, join, resolve } from "node:path";
|
|
10
|
+
import { basename, join, resolve, sep } from "node:path";
|
|
11
11
|
import type { ExtensionRegistry } from "../extensions/registry.js";
|
|
12
12
|
import type { ResolvedLinkFeature } from "./link-features.js";
|
|
13
13
|
import { hashParts } from "./cache.js";
|
|
@@ -46,6 +46,7 @@ export const RUNTIME_SOURCES = [
|
|
|
46
46
|
"xt_url_object.c",
|
|
47
47
|
"xt_array_buffer.c",
|
|
48
48
|
"xt_io.c",
|
|
49
|
+
"xt_protocol_registry.c",
|
|
49
50
|
] as const;
|
|
50
51
|
|
|
51
52
|
export interface RuntimeObjects {
|
|
@@ -109,15 +110,24 @@ export function ensureRuntimeObjects(options: RuntimeObjectsOptions): RuntimeObj
|
|
|
109
110
|
}
|
|
110
111
|
};
|
|
111
112
|
collectHeaders(runtimeDir);
|
|
113
|
+
/* The link features compile vendors from `vendor/`, so their headers must
|
|
114
|
+
* invalidate objects just like the runtime's own (the packages are sibling to
|
|
115
|
+
* `runtime/`, and absent in a checkout that has not run `npm run vendor`). */
|
|
116
|
+
const vendorDir = resolve(runtimeDir, "..", "vendor");
|
|
117
|
+
for (const name of ["miniz", "sqlite3"]) {
|
|
118
|
+
const dir = join(vendorDir, name);
|
|
119
|
+
if (existsSync(dir)) collectHeaders(dir);
|
|
120
|
+
}
|
|
112
121
|
const headerStamp = hashParts(headerParts);
|
|
113
122
|
|
|
114
|
-
const compileOne = (sourcePath: string, tag: string): string => {
|
|
123
|
+
const compileOne = (sourcePath: string, tag: string, includeDirs: readonly string[]): string => {
|
|
115
124
|
const body = readFileSync(sourcePath, "utf8");
|
|
116
125
|
const key = hashParts([
|
|
117
126
|
"runtime",
|
|
118
127
|
COMPILER_VERSION,
|
|
119
128
|
RUNTIME_CFLAGS.join(" "),
|
|
120
129
|
compileFlags.join(" "),
|
|
130
|
+
includeDirs.join(";"),
|
|
121
131
|
tag,
|
|
122
132
|
headerStamp,
|
|
123
133
|
body,
|
|
@@ -126,15 +136,16 @@ export function ensureRuntimeObjects(options: RuntimeObjectsOptions): RuntimeObj
|
|
|
126
136
|
]);
|
|
127
137
|
const objectPath = join(cacheDir, `${tag}-${key}.o`);
|
|
128
138
|
if (!existsSync(objectPath)) {
|
|
129
|
-
compileC(runner, clang, sourcePath, objectPath,
|
|
139
|
+
compileC(runner, clang, sourcePath, objectPath, includeDirs, env, compileFlags);
|
|
130
140
|
}
|
|
131
141
|
return objectPath;
|
|
132
142
|
};
|
|
133
143
|
|
|
144
|
+
const runtimeInclude = [runtimeDir];
|
|
134
145
|
const coreArchive = preferPrebuilt ? findRuntimeLibrary("core", options.runtimeLibDirs) : undefined;
|
|
135
146
|
const runtimeObjects = coreArchive
|
|
136
147
|
? [coreArchive]
|
|
137
|
-
: RUNTIME_SOURCES.map((source) => compileOne(join(runtimeDir, source), basename(source, ".c")));
|
|
148
|
+
: RUNTIME_SOURCES.map((source) => compileOne(join(runtimeDir, source), basename(source, ".c"), runtimeInclude));
|
|
138
149
|
|
|
139
150
|
/** Prebuilt archives this link uses; the driver retries without them. */
|
|
140
151
|
const prebuiltArchives: string[] = coreArchive ? [coreArchive] : [];
|
|
@@ -156,12 +167,20 @@ export function ensureRuntimeObjects(options: RuntimeObjectsOptions): RuntimeObj
|
|
|
156
167
|
const dedupeKey = resolve(sourcePath);
|
|
157
168
|
if (seen.has(dedupeKey)) continue;
|
|
158
169
|
seen.add(dedupeKey);
|
|
159
|
-
extensionObjects.push(
|
|
170
|
+
extensionObjects.push(
|
|
171
|
+
compileOne(sourcePath, `ext_${extensionObjects.length}_${basename(sourcePath, ".c")}`, runtimeInclude),
|
|
172
|
+
);
|
|
160
173
|
}
|
|
161
174
|
}
|
|
162
175
|
// A native archive may be shared by several manifests; link each once.
|
|
163
176
|
const featureObjects: string[] = [];
|
|
164
177
|
for (const feature of options.features ?? []) {
|
|
178
|
+
/* A feature that compiles a vendored library needs `vendor/` on the include
|
|
179
|
+
* path for its bridge (`sqlite3/sqlite3.h`, `miniz/miniz.h`). */
|
|
180
|
+
const usesVendor = feature.runtimeSources.some((sourcePath) =>
|
|
181
|
+
resolve(sourcePath).startsWith(`${vendorDir}${sep}`),
|
|
182
|
+
);
|
|
183
|
+
const featureInclude = usesVendor ? [runtimeDir, vendorDir] : runtimeInclude;
|
|
165
184
|
/* Feature bridges are always compiled: they are not part of any prebuilt
|
|
166
185
|
* archive, and their references are what make the linker extract the
|
|
167
186
|
* feature's implementation. */
|
|
@@ -170,7 +189,7 @@ export function ensureRuntimeObjects(options: RuntimeObjectsOptions): RuntimeObj
|
|
|
170
189
|
if (seen.has(dedupeKey)) continue;
|
|
171
190
|
seen.add(dedupeKey);
|
|
172
191
|
extensionObjects.push(
|
|
173
|
-
compileOne(sourcePath, `feature_${feature.name}_${basename(sourcePath, ".c")}
|
|
192
|
+
compileOne(sourcePath, `feature_${feature.name}_${basename(sourcePath, ".c")}`, featureInclude),
|
|
174
193
|
);
|
|
175
194
|
}
|
|
176
195
|
featureObjects.push(...feature.nativeObjects);
|
package/src/driver/toolchain.ts
CHANGED
|
@@ -495,13 +495,22 @@ export function compileC(
|
|
|
495
495
|
clang: string,
|
|
496
496
|
sourcePath: string,
|
|
497
497
|
objectPath: string,
|
|
498
|
-
includeDir: string,
|
|
498
|
+
includeDir: string | readonly string[],
|
|
499
499
|
env?: Record<string, string>,
|
|
500
500
|
extraFlags: readonly string[] = [],
|
|
501
501
|
): void {
|
|
502
|
+
const includeDirs = typeof includeDir === "string" ? [includeDir] : includeDir;
|
|
502
503
|
const result = runner.run(
|
|
503
504
|
clang,
|
|
504
|
-
[
|
|
505
|
+
[
|
|
506
|
+
...RUNTIME_CFLAGS,
|
|
507
|
+
...extraFlags,
|
|
508
|
+
"-c",
|
|
509
|
+
sourcePath,
|
|
510
|
+
"-o",
|
|
511
|
+
objectPath,
|
|
512
|
+
...includeDirs.map((dir) => `-I${dir}`),
|
|
513
|
+
],
|
|
505
514
|
{ env },
|
|
506
515
|
);
|
|
507
516
|
if (result.status !== 0) throw new ToolchainError(`${clang} ${sourcePath}`, result.status, result.stderr);
|
package/src/driver/version.ts
CHANGED