@effected/bundler 0.0.0-stage → 0.2.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 +498 -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 +272 -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 +438 -0
  20. package/config/EffectedConfigFile.js +171 -0
  21. package/config/merge.js +20 -0
  22. package/config/plugins.js +84 -0
  23. package/config-validation/ConfigValidator.js +73 -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 +3619 -0
  38. package/index.js +57 -0
  39. package/internal/causeMessage.js +57 -0
  40. package/journal/BuildJournal.js +107 -0
  41. package/jsx/config.js +44 -0
  42. package/manifest/built-condition.js +120 -0
  43. package/manifest/emit-manifest.js +93 -0
  44. package/manifest/export-patterns.js +56 -0
  45. package/manifest/manifest-set.js +101 -0
  46. package/manifest/transform.js +324 -0
  47. package/meta/api-extractor.js +241 -0
  48. package/meta/bundle-config.js +22 -0
  49. package/meta/bundle-manifest.js +134 -0
  50. package/meta/bundle-source.js +106 -0
  51. package/meta/config.js +24 -0
  52. package/meta/generate.js +249 -0
  53. package/meta/merge-models.js +43 -0
  54. package/meta/message-suppressor.js +43 -0
  55. package/meta/og-image.js +137 -0
  56. package/meta/og-satori.js +140 -0
  57. package/meta/optimistic.js +32 -0
  58. package/meta/run-pass.js +124 -0
  59. package/meta/scrub-declaration-maps.js +63 -0
  60. package/meta/tsconfig-resolver.js +55 -0
  61. package/meta/tsdoc-config.js +47 -0
  62. package/package.json +86 -5
  63. package/passes/build-target-groups.js +347 -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 +40 -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 +149 -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 +19 -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,77 @@
1
+ import { Schema } from "effect";
2
+
3
+ // src/report/schema.ts
4
+ /** @public */
5
+ var ReportTimings = class extends Schema.Class("ReportTimings")({ totalMs: Schema.Number }) {};
6
+ /**
7
+ * A captured warning or error, from tsdown's logger, rolldown's onLog, API Extractor, the meta
8
+ * pass's own sidecar work (`bundle.json` sources, Open Graph generation), or an advisory finding
9
+ * about the build config itself (`config`, e.g. a `publishConfig.targets` set no final release reaches).
10
+ *
11
+ * @public
12
+ */
13
+ var DiagnosticEntry = class extends Schema.Class("DiagnosticEntry")({
14
+ source: Schema.Literals([
15
+ "tsdown",
16
+ "rolldown",
17
+ "api-extractor",
18
+ "meta",
19
+ "config"
20
+ ]),
21
+ level: Schema.Literals(["warn", "error"]),
22
+ text: Schema.String,
23
+ /**
24
+ * Diagnostic identifier — an API Extractor messageId (e.g. "ae-forgotten-export") or a
25
+ * rolldown warning code (e.g. "MIXED_EXPORTS"); used to group suppressed messages by type.
26
+ */
27
+ code: Schema.optional(Schema.String),
28
+ /** True when shown as `warn` locally but a hard error in CI (drives the "[fails CI]" nudge). */
29
+ ciFatal: Schema.optional(Schema.Boolean),
30
+ file: Schema.optional(Schema.String),
31
+ line: Schema.optional(Schema.Number),
32
+ column: Schema.optional(Schema.Number)
33
+ }) {};
34
+ /**
35
+ * One emitted output file with its in-memory byte size (gzip only when --verbose).
36
+ *
37
+ * @public
38
+ */
39
+ var EmittedFile = class extends Schema.Class("EmittedFile")({
40
+ path: Schema.String,
41
+ bytes: Schema.Number,
42
+ gzip: Schema.optional(Schema.Number)
43
+ }) {};
44
+ /**
45
+ * One build pass within a target group (js / dts / loose / exe / meta).
46
+ *
47
+ * @public
48
+ */
49
+ var PassReport = class extends Schema.Class("PassReport")({
50
+ id: Schema.Literals([
51
+ "js",
52
+ "dts",
53
+ "loose",
54
+ "exe",
55
+ "meta"
56
+ ]),
57
+ files: Schema.Array(EmittedFile),
58
+ ms: Schema.Number
59
+ }) {};
60
+ /** @public */
61
+ var TargetGroupReport = class extends Schema.Class("TargetGroupReport")({
62
+ id: Schema.String,
63
+ entries: Schema.Array(Schema.String),
64
+ passes: Schema.Array(PassReport),
65
+ warnings: Schema.Array(DiagnosticEntry),
66
+ errors: Schema.Array(DiagnosticEntry),
67
+ /** Messages matched by `suppressWarnings`, kept for accounting and `--verbose` expansion. */
68
+ suppressed: Schema.Array(DiagnosticEntry),
69
+ timings: ReportTimings
70
+ }) {};
71
+ /** @public */
72
+ var BuildReport = class extends Schema.Class("BuildReport")({
73
+ package: Schema.String,
74
+ targetGroups: Schema.Array(TargetGroupReport)
75
+ }) {};
76
+
77
+ export { BuildReport, DiagnosticEntry, EmittedFile, PassReport, ReportTimings, TargetGroupReport };
@@ -0,0 +1,19 @@
1
+ // src/report/timer.ts
2
+ /** @public */
3
+ function formatTime(ms) {
4
+ return ms < 1e3 ? `${Math.round(ms)}ms` : `${(ms / 1e3).toFixed(2)}s`;
5
+ }
6
+ /**
7
+ * Create a wall-clock timer. (Date.now is fine in runtime build code.)
8
+ *
9
+ * @public
10
+ */
11
+ function createTimer(now = Date.now) {
12
+ const start = now();
13
+ return {
14
+ elapsed: () => now() - start,
15
+ format: () => formatTime(now() - start)
16
+ };
17
+ }
18
+
19
+ export { createTimer, formatTime };
@@ -0,0 +1,58 @@
1
+ import { Sgr } from "@effected/env";
2
+
3
+ // src/report/tsdown-logger.ts
4
+ const join = (args) => Sgr.strip(args.map((a) => String(a)).join(" ")).trim();
5
+ /**
6
+ * Warnings that are advisory noise for THIS builder and go to the `suppressed` bucket (recorded
7
+ * for accounting, never surfaced). rolldown-plugin-dts announces its tsgo generator as experimental
8
+ * on every pass; the generator is the one this package deliberately pins, so the notice carries no
9
+ * action for a package author.
10
+ */
11
+ const SUPPRESSED_WARNINGS = /* @__PURE__ */ new Map([["TypeScript Go is experimental. Some options will be unavailable.", "TSGO_EXPERIMENTAL"]]);
12
+ /**
13
+ * A tsdown `customLogger` that routes warnings/errors into the BuildCollector instead of the
14
+ * console. Paired with `logLevel: "silent"` in the same build config: silent suppresses tsdown's
15
+ * own console output while this logger still receives every message (verified against tsdown 0.22.3).
16
+ * info/success are dropped — file metrics come from the writeBundle plugin and timing from our timer.
17
+ * @public
18
+ */
19
+ function createTsdownLogger(collector, groupId) {
20
+ const seenOnce = /* @__PURE__ */ new Set();
21
+ const warn = (text) => {
22
+ const code = SUPPRESSED_WARNINGS.get(text);
23
+ if (code !== void 0) {
24
+ collector.recordSuppressed(groupId, {
25
+ source: "tsdown",
26
+ level: "warn",
27
+ code,
28
+ text
29
+ });
30
+ return;
31
+ }
32
+ collector.recordWarning(groupId, {
33
+ source: "tsdown",
34
+ level: "warn",
35
+ text
36
+ });
37
+ };
38
+ return {
39
+ level: "info",
40
+ info: () => {},
41
+ success: () => {},
42
+ clearScreen: () => {},
43
+ warn: (...args) => warn(join(args)),
44
+ warnOnce: (...args) => {
45
+ const text = join(args);
46
+ if (seenOnce.has(text)) return;
47
+ seenOnce.add(text);
48
+ warn(text);
49
+ },
50
+ error: (...args) => collector.recordError(groupId, {
51
+ source: "tsdown",
52
+ level: "error",
53
+ text: join(args)
54
+ })
55
+ };
56
+ }
57
+
58
+ export { createTsdownLogger };
@@ -0,0 +1,19 @@
1
+ import { Effect, FileSystem, Path } from "effect";
2
+
3
+ // src/targets/binding.ts
4
+ /**
5
+ * Write the target-to-group binding to dist/prod/targets.json for the release action to consume. Returns the path.
6
+ *
7
+ * @public
8
+ */
9
+ const writeTargetsBinding = Effect.fnUntraced(function* (cwd, resolution) {
10
+ const fs = yield* FileSystem.FileSystem;
11
+ const path = yield* Path.Path;
12
+ const dir = path.join(cwd, "dist", "prod");
13
+ yield* fs.makeDirectory(dir, { recursive: true });
14
+ const file = path.join(dir, "targets.json");
15
+ yield* fs.writeFileString(file, `${JSON.stringify(resolution, null, " ")}\n`);
16
+ return file;
17
+ });
18
+
19
+ export { writeTargetsBinding };
@@ -0,0 +1,21 @@
1
+ // src/targets/config.ts
2
+ /**
3
+ * Every {@link ReleaseChannel} value, in declaration order.
4
+ *
5
+ * @public
6
+ */
7
+ const RELEASE_CHANNELS = [
8
+ "all",
9
+ "stable",
10
+ "prerelease"
11
+ ];
12
+ /**
13
+ * True when a target value is the object form (carries registry/name/from).
14
+ *
15
+ * @public
16
+ */
17
+ function isTargetObject(value) {
18
+ return typeof value === "object" && value !== null;
19
+ }
20
+
21
+ export { RELEASE_CHANNELS, isTargetObject };
@@ -0,0 +1,165 @@
1
+ import { ConfigValidationError } from "../errors.js";
2
+ import { RELEASE_CHANNELS, isTargetObject } from "./config.js";
3
+
4
+ // src/targets/resolve-targets.ts
5
+ /** Default registry endpoints for the well-known target keys. */
6
+ const DEFAULT_REGISTRIES = {
7
+ npm: "https://registry.npmjs.org",
8
+ github: "https://npm.pkg.github.com"
9
+ };
10
+ /**
11
+ * Resolve a `publishConfig.targets` map into the distinct groups to build and every target bound to one. Pure; throws ConfigValidationError on structurally-invalid config.
12
+ *
13
+ * @public
14
+ */
15
+ function resolveTargets(options) {
16
+ const { targets, baseName } = options;
17
+ const ids = Object.keys(targets);
18
+ if (ids.length === 0) throw new ConfigValidationError({
19
+ path: "publishConfig.targets",
20
+ reason: "publishConfig.targets must declare at least one target"
21
+ });
22
+ const trueIds = ids.filter((id) => targets[id] === true);
23
+ const canonicalId = trueIds.includes("npm") ? "npm" : trueIds[0];
24
+ const registryFor = (id, explicit) => {
25
+ const registry = explicit ?? DEFAULT_REGISTRIES[id];
26
+ if (registry === void 0) throw new ConfigValidationError({
27
+ path: `publishConfig.targets.${id}`,
28
+ reason: `Target "${id}" has no registry; custom targets must set { registry }`
29
+ });
30
+ return registry;
31
+ };
32
+ const optionsFor = (id, value) => {
33
+ if (!isTargetObject(value)) return { releases: "all" };
34
+ const { releases, provenance } = value;
35
+ if (releases !== void 0 && !RELEASE_CHANNELS.includes(releases)) throw new ConfigValidationError({
36
+ path: `publishConfig.targets.${id}.releases`,
37
+ reason: `Target "${id}" has releases "${String(releases)}"; expected one of ${RELEASE_CHANNELS.map((c) => `"${c}"`).join(", ")}`
38
+ });
39
+ if (provenance !== void 0 && typeof provenance !== "boolean") throw new ConfigValidationError({
40
+ path: `publishConfig.targets.${id}.provenance`,
41
+ reason: `Target "${id}" has a non-boolean provenance; expected true or false`
42
+ });
43
+ return {
44
+ releases: releases ?? "all",
45
+ ...provenance !== void 0 ? { provenance } : {}
46
+ };
47
+ };
48
+ const groups = /* @__PURE__ */ new Map();
49
+ const addGroup = (id, name) => {
50
+ if (!groups.has(id)) groups.set(id, {
51
+ id,
52
+ name,
53
+ dir: `dist/prod/${id}/pkg`
54
+ });
55
+ };
56
+ const resolved = [];
57
+ const deferredFrom = [];
58
+ for (const id of ids) {
59
+ const value = targets[id];
60
+ if (value === true) {
61
+ if (DEFAULT_REGISTRIES[id] === void 0) throw new ConfigValidationError({
62
+ path: `publishConfig.targets.${id}`,
63
+ reason: `Target "${id}: true" is not a known registry; use an object with { registry }`
64
+ });
65
+ if (id === "github" && !baseName.startsWith("@")) throw new ConfigValidationError({
66
+ path: "publishConfig.targets.github",
67
+ reason: `"github: true" needs a scoped base name; use a string/name override to rescope "${baseName}"`
68
+ });
69
+ const gid = canonicalId;
70
+ addGroup(gid, baseName);
71
+ resolved.push({
72
+ id,
73
+ group: gid,
74
+ name: baseName,
75
+ registry: registryFor(id, void 0),
76
+ ...optionsFor(id, value)
77
+ });
78
+ } else if (typeof value === "string") {
79
+ if (DEFAULT_REGISTRIES[id] === void 0) throw new ConfigValidationError({
80
+ path: `publishConfig.targets.${id}`,
81
+ reason: `Target "${id}" uses a string name override but has no known registry; use an object { registry, name }`
82
+ });
83
+ addGroup(id, value);
84
+ resolved.push({
85
+ id,
86
+ group: id,
87
+ name: value,
88
+ registry: registryFor(id, void 0),
89
+ ...optionsFor(id, value)
90
+ });
91
+ } else if (isTargetObject(value)) {
92
+ if (value.from !== void 0 && value.name !== void 0) throw new ConfigValidationError({
93
+ path: `publishConfig.targets.${id}`,
94
+ reason: `Target "${id}" sets both "from" and "name"; they are mutually exclusive`
95
+ });
96
+ if (value.from !== void 0) deferredFrom.push({
97
+ id,
98
+ obj: value
99
+ });
100
+ else if (value.name !== void 0) {
101
+ addGroup(id, value.name);
102
+ resolved.push({
103
+ id,
104
+ group: id,
105
+ name: value.name,
106
+ registry: registryFor(id, value.registry),
107
+ ...optionsFor(id, value)
108
+ });
109
+ } else {
110
+ addGroup(id, baseName);
111
+ resolved.push({
112
+ id,
113
+ group: id,
114
+ name: baseName,
115
+ registry: registryFor(id, value.registry),
116
+ ...optionsFor(id, value)
117
+ });
118
+ }
119
+ }
120
+ }
121
+ for (const { id, obj } of deferredFrom) {
122
+ const fromId = obj.from;
123
+ if (fromId === id) throw new ConfigValidationError({
124
+ path: `publishConfig.targets.${id}`,
125
+ reason: `Target "${id}" references itself in "from" (self-referencing from is not allowed)`
126
+ });
127
+ if (deferredFrom.some((d) => d.id === fromId)) throw new ConfigValidationError({
128
+ path: `publishConfig.targets.${id}`,
129
+ reason: `Target "${id}" reuses "from: ${fromId}", which itself uses "from" (no chained reuse)`
130
+ });
131
+ const ref = resolved.find((t) => t.id === fromId);
132
+ if (ref === void 0) throw new ConfigValidationError({
133
+ path: `publishConfig.targets.${id}`,
134
+ reason: `Target "${id}" has a dangling "from: ${fromId}" (no such target)`
135
+ });
136
+ resolved.push({
137
+ id,
138
+ group: ref.group,
139
+ name: ref.name,
140
+ registry: registryFor(id, obj.registry),
141
+ ...optionsFor(id, obj)
142
+ });
143
+ }
144
+ return {
145
+ groups: [...groups.values()],
146
+ targets: resolved
147
+ };
148
+ }
149
+ /**
150
+ * Advisory warnings for a resolved target set that is valid but probably not what was meant.
151
+ *
152
+ * @remarks
153
+ * Today the only one is a set whose every target is `releases: "prerelease"`, which leaves final
154
+ * versions with nowhere to publish. A warning rather than a {@link ConfigValidationError}, since a
155
+ * prerelease-only package is a legitimate if unusual setup. Pure; returns one message per finding.
156
+ *
157
+ * @public
158
+ */
159
+ function releaseWarnings(resolution) {
160
+ const { targets } = resolution;
161
+ if (targets.length > 0 && targets.every((t) => t.releases === "prerelease")) return [`Every publish target sets releases: "prerelease", so final versions publish nowhere; set "all" or "stable" on at least one target`];
162
+ return [];
163
+ }
164
+
165
+ export { releaseWarnings, resolveTargets };
@@ -0,0 +1,20 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import * as nodePath from "node:path";
3
+
4
+ // src/tsconfig/sync-options.ts
5
+ /**
6
+ * The consumer-supplied sync operations backing every `TsconfigLoaderSync` call in this
7
+ * package: Node's `existsSync`/`readFileSync` satisfy the loader's `SyncFileSystem`, and
8
+ * `node:path` satisfies `SyncPath` verbatim.
9
+ *
10
+ * @internal
11
+ */
12
+ const tsconfigSyncOptions = {
13
+ fileSystem: {
14
+ exists: existsSync,
15
+ readFile: (p) => readFileSync(p, "utf8")
16
+ },
17
+ path: nodePath
18
+ };
19
+
20
+ export { tsconfigSyncOptions };
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.60.1"
9
+ }
10
+ ]
11
+ }