@effected/bundler 0.0.0-stage → 0.1.0

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.
Files changed (81) hide show
  1. package/Bundler.js +450 -0
  2. package/BundlerError.js +39 -0
  3. package/LICENSE +21 -0
  4. package/README.md +84 -2
  5. package/action/ActionBuilder.js +108 -0
  6. package/action/ActionBundle.js +261 -0
  7. package/action/ActionErrors.js +83 -0
  8. package/action/ActionValidation.js +195 -0
  9. package/action/ActionYml.js +366 -0
  10. package/action/PersistLocal.js +186 -0
  11. package/action/entries.js +23 -0
  12. package/action/ignore-stub-plugin.js +25 -0
  13. package/action/import-check.js +134 -0
  14. package/assets/Inter-SemiBold.ttf +0 -0
  15. package/assets/LICENSE-Inter.txt +92 -0
  16. package/catalog/resolve-catalogs.js +32 -0
  17. package/changesets/next-versions.js +50 -0
  18. package/config/ActionConfig.js +102 -0
  19. package/config/BuildConfig.js +427 -0
  20. package/config/EffectedConfigFile.js +160 -0
  21. package/config/merge.js +20 -0
  22. package/config/plugins.js +84 -0
  23. package/config-validation/ConfigValidator.js +67 -0
  24. package/dts/bundled-siblings.js +108 -0
  25. package/dts/parse.js +28 -0
  26. package/dts/reexport-stub.js +94 -0
  27. package/dts/relative-imports.js +33 -0
  28. package/dts/resolved-tsconfig.js +238 -0
  29. package/entries/ambient-dts.js +108 -0
  30. package/entries/export-paths.js +16 -0
  31. package/entries/extract.js +79 -0
  32. package/entries/package-json-entries.js +19 -0
  33. package/errors.js +37 -0
  34. package/exe/build.js +55 -0
  35. package/exe/config.js +54 -0
  36. package/exe/filename.js +13 -0
  37. package/index.d.ts +3919 -0
  38. package/index.js +58 -0
  39. package/internal/causeMessage.js +57 -0
  40. package/journal/BuildJournal.js +108 -0
  41. package/jsx/config.js +51 -0
  42. package/manifest/emit-manifest.js +88 -0
  43. package/manifest/export-patterns.js +58 -0
  44. package/manifest/transform.js +323 -0
  45. package/meta/BundleManifest.js +208 -0
  46. package/meta/ManifestSource.js +37 -0
  47. package/meta/api-extractor.js +241 -0
  48. package/meta/config.js +24 -0
  49. package/meta/generate.js +246 -0
  50. package/meta/merge-models.js +43 -0
  51. package/meta/message-suppressor.js +43 -0
  52. package/meta/og-image.js +137 -0
  53. package/meta/og-satori.js +140 -0
  54. package/meta/optimistic.js +32 -0
  55. package/meta/run-pass.js +117 -0
  56. package/meta/scrub-declaration-maps.js +63 -0
  57. package/meta/tsconfig-resolver.js +55 -0
  58. package/meta/tsdoc-config.js +47 -0
  59. package/meta/tsdoctor-config.js +22 -0
  60. package/meta/tsdoctor-manifest.js +134 -0
  61. package/meta/tsdoctor-source.js +94 -0
  62. package/package.json +85 -5
  63. package/passes/build-target-groups.js +346 -0
  64. package/passes/cjs-default-interop.js +98 -0
  65. package/passes/loose-files.js +57 -0
  66. package/passes/node-builtin-default-interop.js +79 -0
  67. package/passes/strip-maps.js +39 -0
  68. package/passes/sync-public.js +100 -0
  69. package/passes/target-groups.js +112 -0
  70. package/report/ci-annotations.js +36 -0
  71. package/report/collector.js +140 -0
  72. package/report/issues-artifact.js +155 -0
  73. package/report/metrics-plugin.js +76 -0
  74. package/report/schema.js +77 -0
  75. package/report/timer.js +19 -0
  76. package/report/tsdown-logger.js +58 -0
  77. package/targets/binding.js +18 -0
  78. package/targets/config.js +21 -0
  79. package/targets/resolve-targets.js +165 -0
  80. package/tsconfig/sync-options.js +20 -0
  81. package/tsdoc-metadata.json +11 -0
@@ -0,0 +1,16 @@
1
+ // src/entries/export-paths.ts
2
+ /**
3
+ * Maps each build entry to its `package.json` export key: the key whose target is the entry's source, else `.`
4
+ * for `index` and `./<name>` for the rest.
5
+ *
6
+ * @public
7
+ */
8
+ function deriveExportPaths(entries, exportsMap) {
9
+ const out = {};
10
+ const sourceToKey = /* @__PURE__ */ new Map();
11
+ if (exportsMap) for (const [key, src] of Object.entries(exportsMap)) sourceToKey.set(src, key);
12
+ for (const [entryName, src] of Object.entries(entries)) out[entryName] = sourceToKey.get(src) ?? (entryName === "index" ? "." : `./${entryName}`);
13
+ return out;
14
+ }
15
+
16
+ export { deriveExportPaths };
@@ -0,0 +1,79 @@
1
+ // src/entries/extract.ts
2
+ const isDeclarationFile = (p) => p.endsWith(".d.ts") || p.endsWith(".d.cts") || p.endsWith(".d.mts");
3
+ const isTypeScriptFile = (p) => !isDeclarationFile(p) && (p.endsWith(".ts") || p.endsWith(".tsx"));
4
+ /**
5
+ * `/dist/*.js` to `/src/*.ts`; otherwise unchanged. The entry pass builds a `./dist/foo.js` export from
6
+ * `./src/foo.ts`, and the manifest transform reads the same mapping to point that export at the emitted file.
7
+ *
8
+ * @internal
9
+ */
10
+ const resolveToTypeScript = (p) => p.endsWith(".js") && p.includes("/dist/") ? p.replace("/dist/", "/src/").replace(/\.js$/, ".ts") : p;
11
+ /** Resolve an export value to a source path: import || default || types (NOT require). */
12
+ const resolveSourcePath = (value) => {
13
+ if (typeof value === "string") return value;
14
+ if (value && typeof value === "object") {
15
+ const o = value;
16
+ return o.import || o.default || o.types || void 0;
17
+ }
18
+ };
19
+ /**
20
+ * Map an export key to the tsdown entry name (the emitted output basename).
21
+ *
22
+ * `.` becomes `index`; otherwise the leading `./` is stripped and, unless
23
+ * `exportsAsIndexes` is set, nested slashes are flattened to dashes
24
+ * (e.g. `./changesets/markdownlint` to `changesets-markdownlint`). The manifest
25
+ * transform reuses this so the declared output path always matches the emitted file.
26
+ *
27
+ * @internal
28
+ */
29
+ const createEntryName = (exportKey, exportsAsIndexes) => {
30
+ if (exportKey === ".") return "index";
31
+ const withoutPrefix = exportKey.replace(/^\.\//, "");
32
+ return exportsAsIndexes ? `${withoutPrefix}/index` : withoutPrefix.replace(/\//g, "-");
33
+ };
34
+ /** @public */
35
+ function extractEntries(pkg, options = {}) {
36
+ const entries = {};
37
+ const exportPaths = {};
38
+ const exportsAsIndexes = options.exportsAsIndexes ?? false;
39
+ const stripDot = (p) => p.replace(/^\.\//, "");
40
+ const excluded = new Set((options.excludeSources ?? []).map(stripDot));
41
+ const isExcluded = (src) => excluded.has(stripDot(src));
42
+ const exports = pkg.exports;
43
+ if (typeof exports === "string") {
44
+ if (isTypeScriptFile(exports) && !isExcluded(exports)) {
45
+ entries.index = exports;
46
+ exportPaths.index = ".";
47
+ }
48
+ } else if (exports && typeof exports === "object") for (const [key, value] of Object.entries(exports)) {
49
+ if (key === "./package.json" || key.endsWith(".json")) continue;
50
+ const sourcePath = resolveSourcePath(value);
51
+ if (!sourcePath) continue;
52
+ const resolved = resolveToTypeScript(sourcePath);
53
+ if (!isTypeScriptFile(resolved)) continue;
54
+ if (isExcluded(sourcePath) || isExcluded(resolved)) continue;
55
+ const name = createEntryName(key, exportsAsIndexes);
56
+ if (name in entries) {
57
+ const previousKey = exportPaths[name];
58
+ throw new Error(`Export key "${key}" flattens to entry name "${name}", which collides with export key "${previousKey}". Rename one of the conflicting exports so each produces a distinct entry name.`);
59
+ }
60
+ entries[name] = resolved;
61
+ exportPaths[name] = key;
62
+ }
63
+ const bin = pkg.bin;
64
+ if (typeof bin === "string") {
65
+ const resolved = resolveToTypeScript(bin);
66
+ if (isTypeScriptFile(resolved) && !isExcluded(bin) && !isExcluded(resolved)) entries["bin/cli"] = resolved;
67
+ } else if (bin && typeof bin === "object") for (const [command, p] of Object.entries(bin)) {
68
+ if (typeof p !== "string") continue;
69
+ const resolved = resolveToTypeScript(p);
70
+ if (isExcluded(p) || isExcluded(resolved)) continue;
71
+ if (isTypeScriptFile(resolved)) entries[`bin/${command}`] = resolved;
72
+ }
73
+ return {
74
+ entries,
75
+ exportPaths
76
+ };
77
+ }
78
+
79
+ export { createEntryName, extractEntries, resolveToTypeScript };
@@ -0,0 +1,19 @@
1
+ import { extractEntries } from "./extract.js";
2
+ import { readFileSync } from "node:fs";
3
+ import { resolve } from "node:path";
4
+
5
+ // src/entries/package-json-entries.ts
6
+ /**
7
+ * Derive a tsdown `entry` record (name to source path) from a package.json.
8
+ *
9
+ * @public
10
+ */
11
+ function packageJsonEntries(options = {}) {
12
+ const pkg = options.pkg ?? JSON.parse(readFileSync(resolve(options.cwd ?? process.cwd(), "package.json"), "utf-8"));
13
+ return extractEntries(pkg, {
14
+ exportsAsIndexes: options.exportsAsIndexes,
15
+ excludeSources: options.excludeSources
16
+ }).entries;
17
+ }
18
+
19
+ export { packageJsonEntries };
package/errors.js ADDED
@@ -0,0 +1,37 @@
1
+ import { Data } from "effect";
2
+
3
+ // src/errors.ts
4
+ /**
5
+ * A build config is structurally invalid; raised before any build work.
6
+ *
7
+ * @public
8
+ */
9
+ var ConfigValidationError = class extends Data.TaggedError("ConfigValidationError") {
10
+ get message() {
11
+ return `Config validation failed at "${this.path}": ${this.reason}`;
12
+ }
13
+ };
14
+ /**
15
+ * API Extractor meta generation failed for an entry.
16
+ *
17
+ * @public
18
+ */
19
+ var MetaGenerationError = class extends Data.TaggedError("MetaGenerationError") {
20
+ get message() {
21
+ return `Meta generation failed for entry "${this.entry}": ${this.reason}`;
22
+ }
23
+ };
24
+ /**
25
+ * Writing the `tsdoctor.json` sidecar failed: the composed manifest did not encode, or the file could not be
26
+ * written (a read-only or full disk). Recorded in `issues.json` as a `meta` error.
27
+ *
28
+ * @public
29
+ */
30
+ var TsdoctorEmitError = class extends Data.TaggedError("TsdoctorEmitError") {
31
+ get message() {
32
+ const reason = this.cause instanceof Error ? this.cause.message : String(this.cause);
33
+ return `Could not emit ${this.path} for ${this.packageName}: ${reason}`;
34
+ }
35
+ };
36
+
37
+ export { ConfigValidationError, MetaGenerationError, TsdoctorEmitError };
package/exe/build.js ADDED
@@ -0,0 +1,55 @@
1
+ import { buildMetricsPlugin } from "../report/metrics-plugin.js";
2
+ import { createTimer } from "../report/timer.js";
3
+ import { createTsdownLogger } from "../report/tsdown-logger.js";
4
+ import { mkdtempSync, rmSync } from "node:fs";
5
+ import { join } from "node:path";
6
+ import { tmpdir } from "node:os";
7
+
8
+ // src/exe/build.ts
9
+ /**
10
+ * Compile each SEA binary via tsdown's exe mode. One tsdown build per spec.
11
+ *
12
+ * @public
13
+ */
14
+ async function runExeBuild(options) {
15
+ const build = options.build ?? (await import("tsdown")).build;
16
+ for (const spec of options.specs) {
17
+ const scratch = mkdtempSync(join(tmpdir(), "effected-exe-"));
18
+ const collector = options.collector;
19
+ const groupId = options.groupId;
20
+ const instrument = collector !== void 0 && groupId !== void 0 ? {
21
+ logLevel: "silent",
22
+ customLogger: createTsdownLogger(collector, groupId)
23
+ } : {};
24
+ const plugins = collector !== void 0 && groupId !== void 0 ? [buildMetricsPlugin(collector, groupId, "exe", options.verbose ?? false)] : [];
25
+ const timer = createTimer();
26
+ try {
27
+ await build({
28
+ cwd: options.cwd,
29
+ config: false,
30
+ entry: [spec.entry],
31
+ format: "esm",
32
+ platform: "node",
33
+ clean: false,
34
+ outDir: scratch,
35
+ deps: { alwaysBundle: (id) => !id.startsWith("node:") },
36
+ exe: {
37
+ fileName: spec.fileName,
38
+ outDir: options.outDir,
39
+ seaConfig: spec.seaConfig,
40
+ targets: spec.targets
41
+ },
42
+ ...instrument,
43
+ ...plugins.length > 0 ? { plugins } : {}
44
+ });
45
+ } finally {
46
+ if (collector !== void 0 && groupId !== void 0) collector.recordPassTiming(groupId, "exe", timer.elapsed());
47
+ rmSync(scratch, {
48
+ recursive: true,
49
+ force: true
50
+ });
51
+ }
52
+ }
53
+ }
54
+
55
+ export { runExeBuild };
package/exe/config.js ADDED
@@ -0,0 +1,54 @@
1
+ // src/exe/config.ts
2
+ /**
3
+ * Default Node runtime embedded in the SEA (parity with the vitest-agent reference).
4
+ *
5
+ * @public
6
+ */
7
+ const DEFAULT_EXE_NODE_VERSION = "25.9.0";
8
+ /** Map a package.json os value to the tsdown exe platform token. */
9
+ function platformToken(os) {
10
+ if (os === "darwin") return "darwin";
11
+ if (os === "linux") return "linux";
12
+ if (os === "win32") return "win";
13
+ }
14
+ /** Infer the default targets from the package's os/cpu (the zero-config, one-platform-per-package case). */
15
+ function inferTargets(pkg) {
16
+ const os = pkg.os[0];
17
+ const cpu = pkg.cpu[0];
18
+ if (os === void 0 || cpu === void 0) return [];
19
+ const platform = platformToken(os);
20
+ if (platform === void 0 || cpu !== "arm64" && cpu !== "x64") return [];
21
+ return [{
22
+ platform,
23
+ arch: cpu
24
+ }];
25
+ }
26
+ /**
27
+ * Normalize `exe` (object or array) into one fully-resolved spec per binary.
28
+ *
29
+ * Pure function; structural validation (missing fileName, empty targets) lives in the
30
+ * config-validation layer.
31
+ * @public
32
+ */
33
+ function normalizeExeOptions(exe, pkg) {
34
+ return (Array.isArray(exe) ? exe : [exe]).map((c) => {
35
+ const nodeVersion = c.nodeVersion ?? "25.9.0";
36
+ const targetInputs = c.targets ?? inferTargets(pkg);
37
+ return {
38
+ fileName: c.fileName,
39
+ entry: c.entry ?? "./src/bin.ts",
40
+ targets: targetInputs.map((t) => ({
41
+ platform: t.platform,
42
+ arch: t.arch,
43
+ nodeVersion
44
+ })),
45
+ seaConfig: {
46
+ disableExperimentalSEAWarning: c.seaConfig?.disableExperimentalSEAWarning ?? true,
47
+ useCodeCache: c.seaConfig?.useCodeCache ?? false,
48
+ useSnapshot: c.seaConfig?.useSnapshot ?? false
49
+ }
50
+ };
51
+ });
52
+ }
53
+
54
+ export { DEFAULT_EXE_NODE_VERSION, normalizeExeOptions };
@@ -0,0 +1,13 @@
1
+ // src/exe/filename.ts
2
+ /**
3
+ * The exact filename `@tsdown/exe` emits for a SEA target, mirroring tsdown's
4
+ * `resolveOutputFileName`: base fileName + `-<platform>-<arch>` + `.exe` on win.
5
+ * Single source of truth so the manifest value never drifts from the on-disk file.
6
+ *
7
+ * @public
8
+ */
9
+ function computeExeFileName(fileName, target) {
10
+ return `${fileName}${`-${target.platform}-${target.arch}`}${target.platform === "win" ? ".exe" : ""}`;
11
+ }
12
+
13
+ export { computeExeFileName };