@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,427 @@
1
+ import { ActionConfig } from "./ActionConfig.js";
2
+ import { Effect, Schema } from "effect";
3
+
4
+ // src/config/BuildConfig.ts
5
+ /**
6
+ * A module format the build can emit.
7
+ *
8
+ * @public
9
+ */
10
+ const BuildFormat = Schema.Literals(["esm", "cjs"]);
11
+ /**
12
+ * The platform a JS pass targets.
13
+ *
14
+ * @public
15
+ */
16
+ const BuildPlatform = Schema.Literals([
17
+ "node",
18
+ "browser",
19
+ "neutral"
20
+ ]);
21
+ /**
22
+ * Format and bundling settings pinned to some of a package's export paths, layered onto the base build.
23
+ *
24
+ * @remarks
25
+ * Use one to keep a single entry CJS in an otherwise ESM-only package, or to build an entry as an isolated
26
+ * browser sub-package. Every setting except `entries` is absent unless written, and absent means the base
27
+ * build's value.
28
+ *
29
+ * @public
30
+ */
31
+ var EntryOverride = class extends Schema.Class("EntryOverride")({
32
+ /** Export paths to pin to this partition, e.g. `"./changesets/markdownlint"`, or `"."` for the root. */
33
+ entries: Schema.Array(Schema.String),
34
+ /** Output module formats for this partition. */
35
+ format: Schema.optionalKey(Schema.Array(BuildFormat)),
36
+ /** Packages force-bundled into this partition's JS output. */
37
+ bundle: Schema.optionalKey(Schema.Array(Schema.String)),
38
+ /** Packages kept external in this partition. */
39
+ externals: Schema.optionalKey(Schema.Array(Schema.String)),
40
+ /** Whether this partition bundles its `node_modules` dependencies. */
41
+ bundleNodeModules: Schema.optionalKey(Schema.Boolean),
42
+ /** Packages whose declarations are inlined into this partition's `.d.ts`; a workspace sibling must be built first. */
43
+ bundledPackages: Schema.optionalKey(Schema.Array(Schema.String)),
44
+ /** Packages externalized in this partition's declaration pass only. */
45
+ dtsExternals: Schema.optionalKey(Schema.Array(Schema.String)),
46
+ /** The JS pass's platform for this partition, `"node"` when absent. Use `"browser"` for a browser runtime. */
47
+ platform: Schema.optionalKey(BuildPlatform),
48
+ /** CSS handling forwarded to tsdown's `css` option on the JS pass; tsdown owns the shape. */
49
+ css: Schema.optionalKey(Schema.Unknown),
50
+ /**
51
+ * Builds this partition into a `pkg/<outSubdir>/` subdirectory as an isolated sub-package.
52
+ *
53
+ * @remarks
54
+ * The export's built path becomes `./<outSubdir>/index.{js,d.ts}`. Exactly one export path may be pinned
55
+ * per `outSubdir` override.
56
+ */
57
+ outSubdir: Schema.optionalKey(Schema.String)
58
+ }) {};
59
+ /**
60
+ * One standalone output file's source and format.
61
+ *
62
+ * @public
63
+ */
64
+ var LooseFileSpec = class extends Schema.Class("LooseFileSpec")({
65
+ /** Source module to bundle into the file. */
66
+ source: Schema.String,
67
+ /** Module format. Required only for an ambiguous `.js` key; inferred from `.mjs` and `.cjs`. */
68
+ format: Schema.optionalKey(BuildFormat)
69
+ }) {};
70
+ /**
71
+ * One non-module asset to copy into each publish group's `pkg/` directory, in the shape of tsdown's `copy` option.
72
+ *
73
+ * @public
74
+ */
75
+ var CopyEntry = class extends Schema.Class("CopyEntry")({
76
+ /**
77
+ * Source paths or globs, relative to the package directory. A directory is copied whole and keeps its own basename
78
+ * under `to`, so `{ from: "../../schemas", to: "schemas" }` emits `pkg/schemas/schemas/...`; use the bare string
79
+ * `"../../schemas"` to ship `schemas/` at the package root.
80
+ */
81
+ from: Schema.Union([Schema.String, Schema.Array(Schema.String)]),
82
+ /** The destination directory, relative to the group's `pkg/` root, which is the default. It may not leave `pkg/`. */
83
+ to: Schema.optionalKey(Schema.String),
84
+ /** Whether to drop each source's directory structure. tsdown defaults this to `true`. */
85
+ flatten: Schema.optionalKey(Schema.Boolean)
86
+ }) {};
87
+ /**
88
+ * JSX transform settings.
89
+ *
90
+ * @public
91
+ */
92
+ var JsxConfig = class extends Schema.Class("JsxConfig")({
93
+ /** `"automatic"` auto-imports the JSX factories; `"classic"` compiles to `React.createElement`. */
94
+ runtime: Schema.optionalKey(Schema.Literals(["automatic", "classic"])),
95
+ /** The JSX import source for the automatic runtime, e.g. `"react"` or `"preact"`. */
96
+ importSource: Schema.optionalKey(Schema.String)
97
+ }) {};
98
+ /**
99
+ * What the build changes in the emitted `package.json`.
100
+ *
101
+ * @public
102
+ */
103
+ var ManifestConfig = class extends Schema.Class("ManifestConfig")({
104
+ /** Top-level manifest keys to drop from the emitted `package.json`, beyond the ones always stripped. */
105
+ drop: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))) }) {};
106
+ /**
107
+ * An API Extractor message-suppression rule.
108
+ *
109
+ * @remarks
110
+ * `messageId` matches exactly and `pattern`, a regex or substring, matches the message text. A rule with
111
+ * both needs both to match.
112
+ *
113
+ * @public
114
+ */
115
+ var WarningSuppressionRule = class extends Schema.Class("WarningSuppressionRule")({
116
+ /** The exact API Extractor message id. */
117
+ messageId: Schema.optionalKey(Schema.String),
118
+ /** A regex or substring matched against the message text. */
119
+ pattern: Schema.optionalKey(Schema.String)
120
+ }) {};
121
+ /**
122
+ * A single TSDoc tag definition, as API Extractor's TSDoc config takes it.
123
+ *
124
+ * @public
125
+ */
126
+ var TsdocTagDefinition = class extends Schema.Class("TsdocTagDefinition")({
127
+ /** The tag's name, with its leading `@`. */
128
+ tagName: Schema.String,
129
+ /** The tag's syntax. */
130
+ syntaxKind: Schema.Literals([
131
+ "block",
132
+ "inline",
133
+ "modifier"
134
+ ]),
135
+ /** Whether a declaration may carry the tag more than once. */
136
+ allowMultiple: Schema.optionalKey(Schema.Boolean)
137
+ }) {};
138
+ /**
139
+ * TSDoc and documentation-warning settings.
140
+ *
141
+ * @public
142
+ */
143
+ var TsdocConfig = class extends Schema.Class("TsdocConfig")({
144
+ /**
145
+ * API Extractor messages to suppress.
146
+ *
147
+ * @remarks
148
+ * Defaults to the `_base` forgotten-export every `Schema.Class` synthesizes. A list replaces the default
149
+ * rather than adding to it, so an empty list suppresses nothing.
150
+ */
151
+ suppressWarnings: Schema.Array(WarningSuppressionRule).pipe(Schema.withDecodingDefaultKey(Effect.succeed([{
152
+ messageId: "ae-forgotten-export",
153
+ pattern: "_base"
154
+ }]))),
155
+ /** Custom TSDoc tags to register. */
156
+ tagDefinitions: Schema.Array(TsdocTagDefinition).pipe(Schema.withDecodingDefaultKey(Effect.succeed([])))
157
+ }) {};
158
+ /**
159
+ * API model generation settings, the `[package.build.meta]` table.
160
+ *
161
+ * @public
162
+ */
163
+ var MetaConfig = class extends Schema.Class("MetaConfig")({
164
+ /**
165
+ * Directories, relative to the package directory, that the canonical group's API model is copied into.
166
+ *
167
+ * @remarks
168
+ * For a docs site reading the model from its own tree. Each one receives the `.api.json`, the meta `package.json`
169
+ * and `tsconfig.json`, and `tsdoctor.json` when one was emitted.
170
+ */
171
+ localPaths: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
172
+ /**
173
+ * Forward-looks the meta bundle's own version and its workspace siblings' dependency versions to their
174
+ * next release versions from pending changesets.
175
+ *
176
+ * @remarks
177
+ * `"auto"` is `false` under CI and `true` locally, so a local bundle matches the CI release build.
178
+ */
179
+ optimistic: Schema.Union([Schema.Literal("auto"), Schema.Boolean]).pipe(Schema.withDecodingDefaultKey(Effect.succeed("auto"))),
180
+ /** TSDoc and documentation-warning settings. */
181
+ tsdoc: TsdocConfig.pipe(Schema.withDecodingDefaultKey(Effect.succeed({})))
182
+ }) {};
183
+ /**
184
+ * A single-executable (SEA) target platform and architecture.
185
+ *
186
+ * @public
187
+ */
188
+ var ExeTargetConfig = class extends Schema.Class("ExeTargetConfig")({
189
+ /** The platform, using tsdown's `win` token rather than `win32`. */
190
+ platform: Schema.Literals([
191
+ "darwin",
192
+ "linux",
193
+ "win"
194
+ ]),
195
+ /** The CPU architecture. */
196
+ arch: Schema.Literals(["arm64", "x64"])
197
+ }) {};
198
+ /**
199
+ * Single-executable `seaConfig` overrides, merged over the defaults.
200
+ *
201
+ * @public
202
+ */
203
+ var ExeSeaConfig = class extends Schema.Class("ExeSeaConfig")({
204
+ /** Whether to silence Node's experimental SEA warning. */
205
+ disableExperimentalSEAWarning: Schema.optionalKey(Schema.Boolean),
206
+ /** Whether to embed V8's code cache. */
207
+ useCodeCache: Schema.optionalKey(Schema.Boolean),
208
+ /** Whether to embed a V8 startup snapshot. */
209
+ useSnapshot: Schema.optionalKey(Schema.Boolean)
210
+ }) {};
211
+ /**
212
+ * One single-executable (SEA) binary to compile.
213
+ *
214
+ * @public
215
+ */
216
+ var ExeConfig = class extends Schema.Class("ExeConfig")({
217
+ /** Output binary basename, with no extension or suffix. */
218
+ fileName: Schema.String,
219
+ /** The bin entry; `./src/bin.ts` when absent. */
220
+ entry: Schema.optionalKey(Schema.String),
221
+ /** The Node runtime to embed. */
222
+ nodeVersion: Schema.optionalKey(Schema.String),
223
+ /** `seaConfig` overrides merged over the defaults. */
224
+ seaConfig: Schema.optionalKey(ExeSeaConfig),
225
+ /** Explicit targets; inferred from the package's `os` and `cpu` when absent. */
226
+ targets: Schema.optionalKey(Schema.Array(ExeTargetConfig))
227
+ }) {};
228
+ /**
229
+ * The build settings of one package, the `[package.build]` table.
230
+ *
231
+ * @remarks
232
+ * Every field has a default or is absent, so an empty table is a complete config.
233
+ *
234
+ * @public
235
+ */
236
+ var PackageBuildConfig = class extends Schema.Class("PackageBuildConfig")({
237
+ /** Output module formats. ESM-only by default; add `"cjs"` for a dual-format build. */
238
+ format: Schema.Array(BuildFormat).pipe(Schema.withDecodingDefaultKey(Effect.succeed(["esm"]))),
239
+ /** Packages kept external. */
240
+ externals: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
241
+ /**
242
+ * Packages force-bundled into the JS output, even ones declared in `package.json` that would otherwise be
243
+ * external.
244
+ *
245
+ * @remarks
246
+ * The inverse of `externals`. Declarations are not inlined by this; use `bundledPackages` to roll a
247
+ * package's types into the emitted `.d.ts` too.
248
+ */
249
+ bundle: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
250
+ /**
251
+ * External packages whose declarations are inlined into the bundled `.d.ts`; all others stay external.
252
+ *
253
+ * @remarks
254
+ * A workspace sibling inlines from its built declarations, so it has to be built first; the build fails naming it
255
+ * when they are absent.
256
+ */
257
+ bundledPackages: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
258
+ /**
259
+ * Packages externalized in the declaration pass only: imported from the emitted `.d.ts` rather than
260
+ * inlined, while the JS pass still bundles them per `bundleNodeModules`.
261
+ *
262
+ * @remarks
263
+ * For a dependency whose types cannot be safely inlined, such as `effect`'s cross-module `declare module`
264
+ * augmentations. Declare these as package dependencies so consumers can resolve the emitted imports.
265
+ */
266
+ dtsExternals: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
267
+ /**
268
+ * Bundles `node_modules` and workspace dependencies that are not externalized into the JS output and the
269
+ * bundled declarations alike.
270
+ */
271
+ bundleNodeModules: Schema.Boolean.pipe(Schema.withDecodingDefaultKey(Effect.succeed(false))),
272
+ /**
273
+ * Minifies the output.
274
+ *
275
+ * @remarks
276
+ * Off by default: minified Node libraries trip security scanners and degrade stack traces.
277
+ */
278
+ minify: Schema.Boolean.pipe(Schema.withDecodingDefaultKey(Effect.succeed(false))),
279
+ /**
280
+ * Runs the bundled `.d.ts` pass and, with it, the meta pass that reads those declarations.
281
+ *
282
+ * @remarks
283
+ * `false` is for JS-only artifacts that never consume declarations. It differs from `meta = false`, which
284
+ * disables only the API model and still runs the declaration pass.
285
+ */
286
+ emitDts: Schema.Boolean.pipe(Schema.withDecodingDefaultKey(Effect.succeed(true))),
287
+ /**
288
+ * Compile-time global replacements forwarded to the build's `define`.
289
+ *
290
+ * @remarks
291
+ * Values are inserted verbatim, so a string literal must carry its own quotes.
292
+ */
293
+ define: Schema.Record(Schema.String, Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed({}))),
294
+ /** Modules whose default export is a rolldown plugin or a factory of one, as package-relative paths. */
295
+ plugins: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
296
+ /** Per-entry format and bundling overrides, layered onto the base build. */
297
+ overrides: Schema.Array(EntryOverride).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
298
+ /**
299
+ * Standalone bundled output files emitted at literal paths, outside the exports, declaration and meta graph.
300
+ *
301
+ * @remarks
302
+ * Keys are literal output filenames; values are a source path or a {@link LooseFileSpec}. Pair with
303
+ * `bundleNodeModules` to make each file self-contained.
304
+ */
305
+ looseFiles: Schema.Record(Schema.String, Schema.Union([Schema.String, LooseFileSpec])).pipe(Schema.withDecodingDefaultKey(Effect.succeed({}))),
306
+ /**
307
+ * Non-module assets copied into each group's `pkg/` directory by the JS pass.
308
+ *
309
+ * @remarks
310
+ * tsdown's `copy` option as data: a string is a path or glob relative to the package directory, copied into the
311
+ * `pkg/` root, and {@link CopyEntry} adds a destination. A directory keeps its basename, so `"../../schemas"` ships
312
+ * `pkg/schemas/...`. A `public/` directory is already copied verbatim with no
313
+ * config; this is the explicit way, for files that live elsewhere. A package that compiles only a binary runs no JS
314
+ * pass, so setting this there fails validation.
315
+ */
316
+ copy: Schema.Array(Schema.Union([Schema.String, CopyEntry])).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
317
+ /** JSX transform settings; inferred from the package's tsconfig when absent. */
318
+ jsx: Schema.optionalKey(JsxConfig),
319
+ /** What the build changes in the emitted `package.json`. */
320
+ manifest: ManifestConfig.pipe(Schema.withDecodingDefaultKey(Effect.succeed({}))),
321
+ /** API model generation: its settings, or `false` to opt out. Generated with defaults when absent. */
322
+ meta: Schema.Union([Schema.Literal(false), MetaConfig]).pipe(Schema.withDecodingDefaultKey(Effect.succeed({}))),
323
+ /** Single-executable binaries to compile: one, or a list. */
324
+ exe: Schema.optionalKey(Schema.Union([ExeConfig, Schema.Array(ExeConfig)]))
325
+ }) {};
326
+ /**
327
+ * One Open Graph image a package's API docs declare.
328
+ *
329
+ * @remarks
330
+ * Exactly one of `path` and `url` must be present.
331
+ *
332
+ * @public
333
+ */
334
+ var TsdoctorOpenGraphImage = class extends Schema.Class("TsdoctorOpenGraphImage")(Schema.Struct({
335
+ /** Bundle-relative asset path. Mutually exclusive with `url`. */
336
+ path: Schema.optionalKey(Schema.String),
337
+ /** Absolute external URL, used verbatim. Mutually exclusive with `path`. */
338
+ url: Schema.optionalKey(Schema.String),
339
+ /** MIME type; inferred from the extension when absent. */
340
+ type: Schema.optionalKey(Schema.String),
341
+ /** Pixel width. */
342
+ width: Schema.optionalKey(Schema.Int),
343
+ /** Pixel height. */
344
+ height: Schema.optionalKey(Schema.Int),
345
+ /** Alt text; inferred when absent. */
346
+ alt: Schema.optionalKey(Schema.String)
347
+ }).check(Schema.makeFilter((image) => image.path === void 0 !== (image.url === void 0) ? void 0 : "exactly one of \"path\" or \"url\" must be present", { title: "openGraph image source" }))) {};
348
+ /**
349
+ * One registry a documented package is published to.
350
+ *
351
+ * @public
352
+ */
353
+ var TsdoctorRegistryRef = class extends Schema.Class("TsdoctorRegistryRef")({
354
+ /** The protocol family, e.g. `"npm"` or `"jsr"`. Unknown values are accepted. */
355
+ type: Schema.String,
356
+ /** The human instance label, e.g. `"npm"`. */
357
+ name: Schema.String,
358
+ /** The package's URL on that registry instance. */
359
+ url: Schema.String
360
+ }) {};
361
+ /**
362
+ * The Open Graph settings of a package's API docs.
363
+ *
364
+ * @public
365
+ */
366
+ var TsdoctorOpenGraphConfig = class extends Schema.Class("TsdoctorOpenGraphConfig")({
367
+ /** Static images, by path or url. Listed after a generated image. */
368
+ images: Schema.optionalKey(Schema.Array(TsdoctorOpenGraphImage)),
369
+ /** Embed accent color, a CSS color string. */
370
+ themeColor: Schema.optionalKey(Schema.String),
371
+ /** Renders an image at build time, listed first. `"satori"` is the only renderer. */
372
+ generate: Schema.optionalKey(Schema.Literal("satori")),
373
+ /**
374
+ * The cross-build image cache's salt.
375
+ *
376
+ * @remarks
377
+ * A string caches under it, so change it whenever the renderer's output changes for the same input.
378
+ * `false` always regenerates. Absent, the renderer's own salt is used.
379
+ */
380
+ cacheSalt: Schema.optionalKey(Schema.Union([Schema.String, Schema.Literal(false)]))
381
+ }) {};
382
+ /**
383
+ * The config tier of a package's emitted `tsdoctor.json`, the `[package.tsdoctor]` table.
384
+ *
385
+ * @public
386
+ */
387
+ var TsdoctorConfig = class extends Schema.Class("TsdoctorConfig")({
388
+ /** The display name. */
389
+ name: Schema.optionalKey(Schema.String),
390
+ /** A one-line tagline. */
391
+ tagline: Schema.optionalKey(Schema.String),
392
+ /** A description. */
393
+ description: Schema.optionalKey(Schema.String),
394
+ /** The Open Graph settings. */
395
+ openGraph: Schema.optionalKey(TsdoctorOpenGraphConfig),
396
+ /** Registries; `false` disables the default derived from `targets.json`. */
397
+ registries: Schema.optionalKey(Schema.Union([Schema.Array(TsdoctorRegistryRef), Schema.Literal(false)]))
398
+ }) {};
399
+ /**
400
+ * The `[package]` table of `effected.toml`.
401
+ *
402
+ * @public
403
+ */
404
+ var PackageConfig = class extends Schema.Class("PackageConfig")({
405
+ /** The build settings. */
406
+ build: PackageBuildConfig.pipe(Schema.withDecodingDefaultKey(Effect.succeed({}))),
407
+ /** The `tsdoctor.json` config tier. */
408
+ tsdoctor: Schema.optionalKey(TsdoctorConfig)
409
+ }) {};
410
+ /**
411
+ * A decoded `effected.toml`.
412
+ *
413
+ * @remarks
414
+ * Decode it with `onExcessProperty: "error"`: a struct's decode drops
415
+ * unknown keys by default, and a typo in a human-written config must fail naming its path rather than
416
+ * silently taking the default.
417
+ *
418
+ * @public
419
+ */
420
+ var EffectedConfig = class extends Schema.Class("EffectedConfig")({
421
+ /** The package tables. */
422
+ package: Schema.optionalKey(PackageConfig),
423
+ /** The GitHub Action table. Absent for a library. */
424
+ action: Schema.optionalKey(ActionConfig)
425
+ }) {};
426
+
427
+ export { BuildFormat, BuildPlatform, CopyEntry, EffectedConfig, EntryOverride, ExeConfig, ExeSeaConfig, ExeTargetConfig, JsxConfig, LooseFileSpec, ManifestConfig, MetaConfig, PackageBuildConfig, PackageConfig, TsdocConfig, TsdocTagDefinition, TsdoctorConfig, TsdoctorOpenGraphConfig, TsdoctorOpenGraphImage, TsdoctorRegistryRef, WarningSuppressionRule };
@@ -0,0 +1,160 @@
1
+ import { causeMessage } from "../internal/causeMessage.js";
2
+ import { EffectedConfig, PackageConfig } from "./BuildConfig.js";
3
+ import { merge } from "./merge.js";
4
+ import { Effect, FileSystem, Path, Predicate, Schema, SchemaIssue } from "effect";
5
+ import { WorkspaceDiscovery } from "@effected/workspaces";
6
+ import { TomlCodec } from "@effected/config-file/toml";
7
+
8
+ // src/config/EffectedConfigFile.ts
9
+ /** Root tier candidates, first found wins. */
10
+ const ROOT_CANDIDATES = [".config/effected.toml", "effected.toml"];
11
+ /** Package tier candidates, first found wins. */
12
+ const PACKAGE_CANDIDATES = [
13
+ ".config/effected.toml",
14
+ "effected.toml",
15
+ "lib/configs/effected.toml"
16
+ ];
17
+ /**
18
+ * An `effected.toml` could not be read, parsed or decoded, or the workspace around it could not be discovered.
19
+ *
20
+ * @public
21
+ */
22
+ var EffectedConfigError = class extends Schema.TaggedError()("EffectedConfigError", {
23
+ /** The file at fault. */
24
+ path: Schema.String,
25
+ /** The TOML parser's message, or every schema issue rendered with its path. */
26
+ reason: Schema.String,
27
+ /** The dotted path of the first schema issue, e.g. `package.build.formats`, when decoding failed. */
28
+ issuePath: Schema.optionalKey(Schema.String)
29
+ }) {
30
+ get message() {
31
+ return `Invalid effected config at ${this.path}: ${this.reason}`;
32
+ }
33
+ };
34
+ /**
35
+ * The effective config {@link EffectedConfigFile.load} answers: an {@link EffectedConfig} whose `package` table
36
+ * is always present, with every default when no file wrote one, so a consumer never branches on its absence.
37
+ *
38
+ * @public
39
+ */
40
+ var ResolvedConfig = class extends EffectedConfig.extend("ResolvedConfig")({
41
+ /** The package tables. */
42
+ package: PackageConfig.pipe(Schema.withDecodingDefaultKey(Effect.succeed({}))) }) {};
43
+ /**
44
+ * A package's effective `effected.toml` config and the files it came from.
45
+ *
46
+ * @public
47
+ */
48
+ var ResolvedEffectedConfig = class extends Schema.Class("ResolvedEffectedConfig")({
49
+ /** The merged, decoded config. */
50
+ config: ResolvedConfig,
51
+ /** The file each tier read, absent for a tier that found none. */
52
+ sources: Schema.Struct({
53
+ /** The workspace root tier's file. */
54
+ root: Schema.optionalKey(Schema.String),
55
+ /** The package tier's file. */
56
+ package: Schema.optionalKey(Schema.String)
57
+ })
58
+ }) {};
59
+ /** The first candidate that exists, parsed. Absence moves on; any other read failure is the file's fault. */
60
+ const readFirst = Effect.fnUntraced(function* (directory, candidates) {
61
+ const fs = yield* FileSystem.FileSystem;
62
+ const pathService = yield* Path.Path;
63
+ for (const candidate of candidates) {
64
+ const path = pathService.join(directory, candidate);
65
+ const raw = yield* fs.readFileString(path).pipe(Effect.map((text) => text), Effect.catchTag("PlatformError", (error) => error.reason._tag === "NotFound" ? Effect.succeed(void 0) : Effect.fail(new EffectedConfigError({
66
+ path,
67
+ reason: causeMessage(error) ?? String(error)
68
+ }))));
69
+ if (raw !== void 0) return {
70
+ path,
71
+ document: yield* TomlCodec.parse(raw).pipe(Effect.mapError((error) => new EffectedConfigError({
72
+ path,
73
+ reason: causeMessage(error) ?? String(error)
74
+ })))
75
+ };
76
+ }
77
+ });
78
+ /** How many leading segments of `segments` a raw document actually has. */
79
+ const depthIn = (document, segments) => {
80
+ let node = document;
81
+ let depth = 0;
82
+ for (const segment of segments) {
83
+ if (typeof node !== "object" || node === null || !Object.hasOwn(node, segment)) break;
84
+ node = node[segment];
85
+ depth++;
86
+ }
87
+ return depth;
88
+ };
89
+ /**
90
+ * The tier that wrote what an issue points at: the one reaching furthest along its path.
91
+ *
92
+ * @remarks
93
+ * A tier that contains the key reaches further than one that does not, so a tie means both contain it or
94
+ * neither does. The package takes a tie: when both contain it the package's value is the one that decoded, and
95
+ * for a missing required key both tables are equally incomplete.
96
+ */
97
+ const blame = (segments, root, pkg, fallback) => {
98
+ if (root === void 0 || pkg === void 0) return pkg?.path ?? root?.path ?? fallback;
99
+ return depthIn(root.document, segments) > depthIn(pkg.document, segments) ? root.path : pkg.path;
100
+ };
101
+ const dotted = (segments) => segments.map(String).join(".");
102
+ /** Every issue under a schema failure, as its property keys and message. */
103
+ const issuesOf = (issue) => SchemaIssue.makeFormatterStandardSchemaV1()(issue).issues.map(({ message, path = [] }) => ({
104
+ message,
105
+ keys: path.map((segment) => typeof segment === "object" ? segment.key : segment)
106
+ }));
107
+ /**
108
+ * Finds, merges and decodes `effected.toml`.
109
+ *
110
+ * @public
111
+ */
112
+ var EffectedConfigFile = class {
113
+ constructor() {}
114
+ /**
115
+ * Loads the config that applies to the package at `cwd`.
116
+ *
117
+ * @remarks
118
+ * The root tier is the first of `.config/effected.toml` and `effected.toml` under the workspace root. The
119
+ * package tier is the first of those two and `lib/configs/effected.toml` under `cwd`; it applies only when
120
+ * `cwd` is not the root. The package tier merges over the root tier per {@link merge}, and the merged
121
+ * document decodes once, so defaults apply after precedence.
122
+ *
123
+ * Decoding rejects unknown keys and reports all of them. When no workspace root sits above `cwd`, `cwd`
124
+ * is the root. No file anywhere is not a failure: `config.package` holds every default and `sources` has no
125
+ * keys.
126
+ *
127
+ * @param options - `cwd` is the package directory; `root` skips workspace discovery.
128
+ */
129
+ static load = Effect.fn("EffectedConfigFile.load")(function* (options) {
130
+ const pathService = yield* Path.Path;
131
+ const cwd = pathService.resolve(options.cwd);
132
+ const rootDirectory = options.root !== void 0 ? pathService.resolve(options.root) : yield* WorkspaceDiscovery.use((discovery) => discovery.infoIn(cwd)).pipe(Effect.map((info) => info.root), Effect.catchTag("WorkspaceRootNotFoundError", () => Effect.succeed(cwd)), Effect.mapError((error) => new EffectedConfigError({
133
+ path: Predicate.hasProperty(error, "path") && Predicate.isString(error.path) ? error.path : cwd,
134
+ reason: causeMessage(error) ?? String(error)
135
+ })));
136
+ const root = yield* readFirst(rootDirectory, ROOT_CANDIDATES);
137
+ const pkg = rootDirectory === cwd ? void 0 : yield* readFirst(cwd, PACKAGE_CANDIDATES);
138
+ const config = yield* Schema.decodeUnknownEffect(ResolvedConfig)(merge(root?.document ?? {}, pkg?.document ?? {}), {
139
+ onExcessProperty: "error",
140
+ errors: "all"
141
+ }).pipe(Effect.mapError((error) => {
142
+ const issues = issuesOf(error.issue);
143
+ const first = issues[0]?.keys ?? [];
144
+ return new EffectedConfigError({
145
+ path: blame(first, root, pkg, cwd),
146
+ reason: issues.map(({ keys, message }) => `${dotted(keys)}: ${message}`).join("; "),
147
+ ...first.length > 0 ? { issuePath: dotted(first) } : {}
148
+ });
149
+ }));
150
+ return ResolvedEffectedConfig.make({
151
+ config,
152
+ sources: {
153
+ ...root !== void 0 ? { root: root.path } : {},
154
+ ...pkg !== void 0 ? { package: pkg.path } : {}
155
+ }
156
+ });
157
+ });
158
+ };
159
+
160
+ export { EffectedConfigError, EffectedConfigFile, ResolvedConfig, ResolvedEffectedConfig };
@@ -0,0 +1,20 @@
1
+ import { ConfigMerge } from "@effected/config-file";
2
+
3
+ // src/config/merge.ts
4
+ /**
5
+ * Merges a package's raw `effected.toml` document over the workspace root's.
6
+ *
7
+ * @remarks
8
+ * Two tables merge per key; an array or a scalar replaces whatever the root had, whole. It runs on the raw
9
+ * documents, before any decoding, so a default can never outrank a value the root wrote. Neither input is
10
+ * modified, and `__proto__`, `constructor` and `prototype` keys are dropped.
11
+ *
12
+ * @param root - The root tier's document.
13
+ * @param pkg - The package tier's document, which wins every conflict.
14
+ * @returns The merged document.
15
+ *
16
+ * @public
17
+ */
18
+ const merge = (root, pkg) => ConfigMerge.deep(root, pkg);
19
+
20
+ export { merge };
@@ -0,0 +1,84 @@
1
+ import { causeMessage } from "../internal/causeMessage.js";
2
+ import { Effect, Predicate, Schema } from "effect";
3
+ import { resolve } from "node:path";
4
+ import { createJiti } from "jiti";
5
+
6
+ // src/config/plugins.ts
7
+ /**
8
+ * A module named in `package.build.plugins` could not be loaded as a rolldown plugin.
9
+ *
10
+ * @public
11
+ */
12
+ var PluginLoadError = class extends Schema.TaggedError()("PluginLoadError", {
13
+ /** The module's resolved path. */
14
+ path: Schema.String,
15
+ /** What was wrong with it. */
16
+ reason: Schema.String
17
+ }) {
18
+ get message() {
19
+ return `Failed to load plugin ${this.path}: ${this.reason}`;
20
+ }
21
+ };
22
+ /**
23
+ * The default importer's jiti, with the options the schema config loader uses, so a `.ts` module loads.
24
+ *
25
+ * @remarks
26
+ * Built per load because `moduleCache` and `fsCache` are off and the importer's base path is the module's own.
27
+ */
28
+ const importWithJiti = (path) => createJiti(path, {
29
+ interopDefault: true,
30
+ moduleCache: false,
31
+ fsCache: false
32
+ }).import(path);
33
+ const isPlugin = (value) => typeof value === "object" && Predicate.hasProperty(value, "name") && Predicate.isString(value.name);
34
+ /** Turns a module's default export into its plugin. */
35
+ const pluginOf = (path, value) => {
36
+ if (!Predicate.hasProperty(value, "default")) return Effect.fail(new PluginLoadError({
37
+ path,
38
+ reason: "the module has no default export"
39
+ }));
40
+ const exported = value.default;
41
+ if (isPlugin(exported)) return Effect.succeed(exported);
42
+ if (typeof exported !== "function") return Effect.fail(new PluginLoadError({
43
+ path,
44
+ reason: "the default export is not a rolldown plugin or a factory of one"
45
+ }));
46
+ return Effect.try({
47
+ try: () => exported(),
48
+ catch: (cause) => new PluginLoadError({
49
+ path,
50
+ reason: `the default export factory threw: ${causeMessage(cause) ?? String(cause)}`
51
+ })
52
+ }).pipe(Effect.flatMap((made) => isPlugin(made) ? Effect.succeed(made) : Effect.fail(new PluginLoadError({
53
+ path,
54
+ reason: "the default export factory did not return a rolldown plugin"
55
+ }))));
56
+ };
57
+ /**
58
+ * Loads the rolldown plugins named in `package.build.plugins`, in order.
59
+ *
60
+ * @remarks
61
+ * Each module path resolves against `cwd`, so a bare `build/plugin.ts` is a file in the package rather than a
62
+ * package name. A module's default export is a plugin, or a factory of one that is called once. Loading runs
63
+ * the module's code, and stops at the first module that fails.
64
+ *
65
+ * @param options - `cwd` is the package directory and `modules` the paths to load. `importModule` replaces the
66
+ * default importer, jiti, which loads TypeScript directly.
67
+ *
68
+ * @public
69
+ */
70
+ const loadPlugins = Effect.fn("loadPlugins")(function* (options) {
71
+ const importModule = options.importModule ?? importWithJiti;
72
+ return yield* Effect.forEach(options.modules, (module) => {
73
+ const path = resolve(options.cwd, module);
74
+ return Effect.tryPromise({
75
+ try: () => importModule(path),
76
+ catch: (cause) => new PluginLoadError({
77
+ path,
78
+ reason: causeMessage(cause) ?? String(cause)
79
+ })
80
+ }).pipe(Effect.flatMap((value) => pluginOf(path, value)));
81
+ });
82
+ });
83
+
84
+ export { PluginLoadError, loadPlugins };