@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.
- package/Bundler.js +498 -0
- package/BundlerError.js +39 -0
- package/LICENSE +21 -0
- package/README.md +84 -2
- package/action/ActionBuilder.js +108 -0
- package/action/ActionBundle.js +272 -0
- package/action/ActionErrors.js +83 -0
- package/action/ActionValidation.js +195 -0
- package/action/ActionYml.js +366 -0
- package/action/PersistLocal.js +186 -0
- package/action/entries.js +23 -0
- package/action/ignore-stub-plugin.js +25 -0
- package/action/import-check.js +134 -0
- package/assets/Inter-SemiBold.ttf +0 -0
- package/assets/LICENSE-Inter.txt +92 -0
- package/catalog/resolve-catalogs.js +32 -0
- package/changesets/next-versions.js +50 -0
- package/config/ActionConfig.js +102 -0
- package/config/BuildConfig.js +438 -0
- package/config/EffectedConfigFile.js +171 -0
- package/config/merge.js +20 -0
- package/config/plugins.js +84 -0
- package/config-validation/ConfigValidator.js +73 -0
- package/dts/bundled-siblings.js +108 -0
- package/dts/parse.js +28 -0
- package/dts/reexport-stub.js +94 -0
- package/dts/relative-imports.js +33 -0
- package/dts/resolved-tsconfig.js +238 -0
- package/entries/ambient-dts.js +108 -0
- package/entries/export-paths.js +16 -0
- package/entries/extract.js +79 -0
- package/entries/package-json-entries.js +19 -0
- package/errors.js +37 -0
- package/exe/build.js +55 -0
- package/exe/config.js +54 -0
- package/exe/filename.js +13 -0
- package/index.d.ts +3619 -0
- package/index.js +57 -0
- package/internal/causeMessage.js +57 -0
- package/journal/BuildJournal.js +107 -0
- package/jsx/config.js +44 -0
- package/manifest/built-condition.js +120 -0
- package/manifest/emit-manifest.js +93 -0
- package/manifest/export-patterns.js +56 -0
- package/manifest/manifest-set.js +101 -0
- package/manifest/transform.js +324 -0
- package/meta/api-extractor.js +241 -0
- package/meta/bundle-config.js +22 -0
- package/meta/bundle-manifest.js +134 -0
- package/meta/bundle-source.js +106 -0
- package/meta/config.js +24 -0
- package/meta/generate.js +249 -0
- package/meta/merge-models.js +43 -0
- package/meta/message-suppressor.js +43 -0
- package/meta/og-image.js +137 -0
- package/meta/og-satori.js +140 -0
- package/meta/optimistic.js +32 -0
- package/meta/run-pass.js +124 -0
- package/meta/scrub-declaration-maps.js +63 -0
- package/meta/tsconfig-resolver.js +55 -0
- package/meta/tsdoc-config.js +47 -0
- package/package.json +86 -5
- package/passes/build-target-groups.js +347 -0
- package/passes/cjs-default-interop.js +98 -0
- package/passes/loose-files.js +57 -0
- package/passes/node-builtin-default-interop.js +79 -0
- package/passes/strip-maps.js +40 -0
- package/passes/sync-public.js +100 -0
- package/passes/target-groups.js +112 -0
- package/report/ci-annotations.js +36 -0
- package/report/collector.js +140 -0
- package/report/issues-artifact.js +149 -0
- package/report/metrics-plugin.js +76 -0
- package/report/schema.js +77 -0
- package/report/timer.js +19 -0
- package/report/tsdown-logger.js +58 -0
- package/targets/binding.js +19 -0
- package/targets/config.js +21 -0
- package/targets/resolve-targets.js +165 -0
- package/tsconfig/sync-options.js +20 -0
- package/tsdoc-metadata.json +11 -0
|
@@ -0,0 +1,438 @@
|
|
|
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
|
+
* Top-level string keys written over the emitted `package.json`, after `drop`.
|
|
108
|
+
*
|
|
109
|
+
* @remarks
|
|
110
|
+
* `name` renames the package everywhere the build names it: every publish group without its own name override,
|
|
111
|
+
* `targets.json` and the API model, so two workspace packages can emit as one published name. Keys the build or the
|
|
112
|
+
* release owns, such as `version`, `private`, `exports` and the dependency maps, fail validation, as does a key also
|
|
113
|
+
* listed in `drop`.
|
|
114
|
+
*/
|
|
115
|
+
set: Schema.Record(Schema.String, Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed({})))
|
|
116
|
+
}) {};
|
|
117
|
+
/**
|
|
118
|
+
* An API Extractor message-suppression rule.
|
|
119
|
+
*
|
|
120
|
+
* @remarks
|
|
121
|
+
* `messageId` matches exactly and `pattern`, a regex or substring, matches the message text. A rule with
|
|
122
|
+
* both needs both to match.
|
|
123
|
+
*
|
|
124
|
+
* @public
|
|
125
|
+
*/
|
|
126
|
+
var WarningSuppressionRule = class extends Schema.Class("WarningSuppressionRule")({
|
|
127
|
+
/** The exact API Extractor message id. */
|
|
128
|
+
messageId: Schema.optionalKey(Schema.String),
|
|
129
|
+
/** A regex or substring matched against the message text. */
|
|
130
|
+
pattern: Schema.optionalKey(Schema.String)
|
|
131
|
+
}) {};
|
|
132
|
+
/**
|
|
133
|
+
* A single TSDoc tag definition, as API Extractor's TSDoc config takes it.
|
|
134
|
+
*
|
|
135
|
+
* @public
|
|
136
|
+
*/
|
|
137
|
+
var TsdocTagDefinition = class extends Schema.Class("TsdocTagDefinition")({
|
|
138
|
+
/** The tag's name, with its leading `@`. */
|
|
139
|
+
tagName: Schema.String,
|
|
140
|
+
/** The tag's syntax. */
|
|
141
|
+
syntaxKind: Schema.Literals([
|
|
142
|
+
"block",
|
|
143
|
+
"inline",
|
|
144
|
+
"modifier"
|
|
145
|
+
]),
|
|
146
|
+
/** Whether a declaration may carry the tag more than once. */
|
|
147
|
+
allowMultiple: Schema.optionalKey(Schema.Boolean)
|
|
148
|
+
}) {};
|
|
149
|
+
/**
|
|
150
|
+
* TSDoc and documentation-warning settings.
|
|
151
|
+
*
|
|
152
|
+
* @public
|
|
153
|
+
*/
|
|
154
|
+
var TsdocConfig = class extends Schema.Class("TsdocConfig")({
|
|
155
|
+
/**
|
|
156
|
+
* API Extractor messages to suppress.
|
|
157
|
+
*
|
|
158
|
+
* @remarks
|
|
159
|
+
* Defaults to the `_base` forgotten-export every `Schema.Class` synthesizes. A list replaces the default
|
|
160
|
+
* rather than adding to it, so an empty list suppresses nothing.
|
|
161
|
+
*/
|
|
162
|
+
suppressWarnings: Schema.Array(WarningSuppressionRule).pipe(Schema.withDecodingDefaultKey(Effect.succeed([{
|
|
163
|
+
messageId: "ae-forgotten-export",
|
|
164
|
+
pattern: "_base"
|
|
165
|
+
}]))),
|
|
166
|
+
/** Custom TSDoc tags to register. */
|
|
167
|
+
tagDefinitions: Schema.Array(TsdocTagDefinition).pipe(Schema.withDecodingDefaultKey(Effect.succeed([])))
|
|
168
|
+
}) {};
|
|
169
|
+
/**
|
|
170
|
+
* API model generation settings, the `[package.build.meta]` table.
|
|
171
|
+
*
|
|
172
|
+
* @public
|
|
173
|
+
*/
|
|
174
|
+
var MetaConfig = class extends Schema.Class("MetaConfig")({
|
|
175
|
+
/**
|
|
176
|
+
* Directories, relative to the package directory, that the canonical group's API model is copied into.
|
|
177
|
+
*
|
|
178
|
+
* @remarks
|
|
179
|
+
* For a docs site reading the model from its own tree. Each one receives the `.api.json`, the meta `package.json`
|
|
180
|
+
* and `tsconfig.json`, and `bundle.json` when one was emitted.
|
|
181
|
+
*/
|
|
182
|
+
localPaths: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
|
|
183
|
+
/**
|
|
184
|
+
* Forward-looks the meta bundle's own version and its workspace siblings' dependency versions to their
|
|
185
|
+
* next release versions from pending changesets.
|
|
186
|
+
*
|
|
187
|
+
* @remarks
|
|
188
|
+
* `"auto"` is `false` under CI and `true` locally, so a local bundle matches the CI release build.
|
|
189
|
+
*/
|
|
190
|
+
optimistic: Schema.Union([Schema.Literal("auto"), Schema.Boolean]).pipe(Schema.withDecodingDefaultKey(Effect.succeed("auto"))),
|
|
191
|
+
/** TSDoc and documentation-warning settings. */
|
|
192
|
+
tsdoc: TsdocConfig.pipe(Schema.withDecodingDefaultKey(Effect.succeed({})))
|
|
193
|
+
}) {};
|
|
194
|
+
/**
|
|
195
|
+
* A single-executable (SEA) target platform and architecture.
|
|
196
|
+
*
|
|
197
|
+
* @public
|
|
198
|
+
*/
|
|
199
|
+
var ExeTargetConfig = class extends Schema.Class("ExeTargetConfig")({
|
|
200
|
+
/** The platform, using tsdown's `win` token rather than `win32`. */
|
|
201
|
+
platform: Schema.Literals([
|
|
202
|
+
"darwin",
|
|
203
|
+
"linux",
|
|
204
|
+
"win"
|
|
205
|
+
]),
|
|
206
|
+
/** The CPU architecture. */
|
|
207
|
+
arch: Schema.Literals(["arm64", "x64"])
|
|
208
|
+
}) {};
|
|
209
|
+
/**
|
|
210
|
+
* Single-executable `seaConfig` overrides, merged over the defaults.
|
|
211
|
+
*
|
|
212
|
+
* @public
|
|
213
|
+
*/
|
|
214
|
+
var ExeSeaConfig = class extends Schema.Class("ExeSeaConfig")({
|
|
215
|
+
/** Whether to silence Node's experimental SEA warning. */
|
|
216
|
+
disableExperimentalSEAWarning: Schema.optionalKey(Schema.Boolean),
|
|
217
|
+
/** Whether to embed V8's code cache. */
|
|
218
|
+
useCodeCache: Schema.optionalKey(Schema.Boolean),
|
|
219
|
+
/** Whether to embed a V8 startup snapshot. */
|
|
220
|
+
useSnapshot: Schema.optionalKey(Schema.Boolean)
|
|
221
|
+
}) {};
|
|
222
|
+
/**
|
|
223
|
+
* One single-executable (SEA) binary to compile.
|
|
224
|
+
*
|
|
225
|
+
* @public
|
|
226
|
+
*/
|
|
227
|
+
var ExeConfig = class extends Schema.Class("ExeConfig")({
|
|
228
|
+
/** Output binary basename, with no extension or suffix. */
|
|
229
|
+
fileName: Schema.String,
|
|
230
|
+
/** The bin entry; `./src/bin.ts` when absent. */
|
|
231
|
+
entry: Schema.optionalKey(Schema.String),
|
|
232
|
+
/** The Node runtime to embed. */
|
|
233
|
+
nodeVersion: Schema.optionalKey(Schema.String),
|
|
234
|
+
/** `seaConfig` overrides merged over the defaults. */
|
|
235
|
+
seaConfig: Schema.optionalKey(ExeSeaConfig),
|
|
236
|
+
/** Explicit targets; inferred from the package's `os` and `cpu` when absent. */
|
|
237
|
+
targets: Schema.optionalKey(Schema.Array(ExeTargetConfig))
|
|
238
|
+
}) {};
|
|
239
|
+
/**
|
|
240
|
+
* The build settings of one package, the `[package.build]` table.
|
|
241
|
+
*
|
|
242
|
+
* @remarks
|
|
243
|
+
* Every field has a default or is absent, so an empty table is a complete config.
|
|
244
|
+
*
|
|
245
|
+
* @public
|
|
246
|
+
*/
|
|
247
|
+
var PackageBuildConfig = class extends Schema.Class("PackageBuildConfig")({
|
|
248
|
+
/** Output module formats. ESM-only by default; add `"cjs"` for a dual-format build. */
|
|
249
|
+
format: Schema.Array(BuildFormat).pipe(Schema.withDecodingDefaultKey(Effect.succeed(["esm"]))),
|
|
250
|
+
/** Packages kept external. */
|
|
251
|
+
externals: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
|
|
252
|
+
/**
|
|
253
|
+
* Packages force-bundled into the JS output, even ones declared in `package.json` that would otherwise be
|
|
254
|
+
* external.
|
|
255
|
+
*
|
|
256
|
+
* @remarks
|
|
257
|
+
* The inverse of `externals`. Declarations are not inlined by this; use `bundledPackages` to roll a
|
|
258
|
+
* package's types into the emitted `.d.ts` too.
|
|
259
|
+
*/
|
|
260
|
+
bundle: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
|
|
261
|
+
/**
|
|
262
|
+
* External packages whose declarations are inlined into the bundled `.d.ts`; all others stay external.
|
|
263
|
+
*
|
|
264
|
+
* @remarks
|
|
265
|
+
* A workspace sibling inlines from its built declarations, so it has to be built first; the build fails naming it
|
|
266
|
+
* when they are absent.
|
|
267
|
+
*/
|
|
268
|
+
bundledPackages: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
|
|
269
|
+
/**
|
|
270
|
+
* Packages externalized in the declaration pass only: imported from the emitted `.d.ts` rather than
|
|
271
|
+
* inlined, while the JS pass still bundles them per `bundleNodeModules`.
|
|
272
|
+
*
|
|
273
|
+
* @remarks
|
|
274
|
+
* For a dependency whose types cannot be safely inlined, such as `effect`'s cross-module `declare module`
|
|
275
|
+
* augmentations. Declare these as package dependencies so consumers can resolve the emitted imports.
|
|
276
|
+
*/
|
|
277
|
+
dtsExternals: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
|
|
278
|
+
/**
|
|
279
|
+
* Bundles `node_modules` and workspace dependencies that are not externalized into the JS output and the
|
|
280
|
+
* bundled declarations alike.
|
|
281
|
+
*/
|
|
282
|
+
bundleNodeModules: Schema.Boolean.pipe(Schema.withDecodingDefaultKey(Effect.succeed(false))),
|
|
283
|
+
/**
|
|
284
|
+
* Minifies the output.
|
|
285
|
+
*
|
|
286
|
+
* @remarks
|
|
287
|
+
* Off by default: minified Node libraries trip security scanners and degrade stack traces.
|
|
288
|
+
*/
|
|
289
|
+
minify: Schema.Boolean.pipe(Schema.withDecodingDefaultKey(Effect.succeed(false))),
|
|
290
|
+
/**
|
|
291
|
+
* Runs the bundled `.d.ts` pass and, with it, the meta pass that reads those declarations.
|
|
292
|
+
*
|
|
293
|
+
* @remarks
|
|
294
|
+
* `false` is for JS-only artifacts that never consume declarations. It differs from `meta = false`, which
|
|
295
|
+
* disables only the API model and still runs the declaration pass.
|
|
296
|
+
*/
|
|
297
|
+
emitDts: Schema.Boolean.pipe(Schema.withDecodingDefaultKey(Effect.succeed(true))),
|
|
298
|
+
/**
|
|
299
|
+
* Compile-time global replacements forwarded to the build's `define`.
|
|
300
|
+
*
|
|
301
|
+
* @remarks
|
|
302
|
+
* Values are inserted verbatim, so a string literal must carry its own quotes.
|
|
303
|
+
*/
|
|
304
|
+
define: Schema.Record(Schema.String, Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed({}))),
|
|
305
|
+
/** Modules whose default export is a rolldown plugin or a factory of one, as package-relative paths. */
|
|
306
|
+
plugins: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
|
|
307
|
+
/** Per-entry format and bundling overrides, layered onto the base build. */
|
|
308
|
+
overrides: Schema.Array(EntryOverride).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
|
|
309
|
+
/**
|
|
310
|
+
* Standalone bundled output files emitted at literal paths, outside the exports, declaration and meta graph.
|
|
311
|
+
*
|
|
312
|
+
* @remarks
|
|
313
|
+
* Keys are literal output filenames; values are a source path or a {@link LooseFileSpec}. Pair with
|
|
314
|
+
* `bundleNodeModules` to make each file self-contained.
|
|
315
|
+
*/
|
|
316
|
+
looseFiles: Schema.Record(Schema.String, Schema.Union([Schema.String, LooseFileSpec])).pipe(Schema.withDecodingDefaultKey(Effect.succeed({}))),
|
|
317
|
+
/**
|
|
318
|
+
* Non-module assets copied into each group's `pkg/` directory by the JS pass.
|
|
319
|
+
*
|
|
320
|
+
* @remarks
|
|
321
|
+
* tsdown's `copy` option as data: a string is a path or glob relative to the package directory, copied into the
|
|
322
|
+
* `pkg/` root, and {@link CopyEntry} adds a destination. A directory keeps its basename, so `"../../schemas"` ships
|
|
323
|
+
* `pkg/schemas/...`. A `public/` directory is already copied verbatim with no
|
|
324
|
+
* config; this is the explicit way, for files that live elsewhere. A package that compiles only a binary runs no JS
|
|
325
|
+
* pass, so setting this there fails validation.
|
|
326
|
+
*/
|
|
327
|
+
copy: Schema.Array(Schema.Union([Schema.String, CopyEntry])).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
|
|
328
|
+
/** JSX transform settings; inferred from the package's tsconfig when absent. */
|
|
329
|
+
jsx: Schema.optionalKey(JsxConfig),
|
|
330
|
+
/** What the build changes in the emitted `package.json`. */
|
|
331
|
+
manifest: ManifestConfig.pipe(Schema.withDecodingDefaultKey(Effect.succeed({}))),
|
|
332
|
+
/** API model generation: its settings, or `false` to opt out. Generated with defaults when absent. */
|
|
333
|
+
meta: Schema.Union([Schema.Literal(false), MetaConfig]).pipe(Schema.withDecodingDefaultKey(Effect.succeed({}))),
|
|
334
|
+
/** Single-executable binaries to compile: one, or a list. */
|
|
335
|
+
exe: Schema.optionalKey(Schema.Union([ExeConfig, Schema.Array(ExeConfig)]))
|
|
336
|
+
}) {};
|
|
337
|
+
/**
|
|
338
|
+
* One Open Graph image a package's API docs declare.
|
|
339
|
+
*
|
|
340
|
+
* @remarks
|
|
341
|
+
* Exactly one of `path` and `url` must be present.
|
|
342
|
+
*
|
|
343
|
+
* @public
|
|
344
|
+
*/
|
|
345
|
+
var BundleOpenGraphImage = class extends Schema.Class("BundleOpenGraphImage")(Schema.Struct({
|
|
346
|
+
/** Bundle-relative asset path. Mutually exclusive with `url`. */
|
|
347
|
+
path: Schema.optionalKey(Schema.String),
|
|
348
|
+
/** Absolute external URL, used verbatim. Mutually exclusive with `path`. */
|
|
349
|
+
url: Schema.optionalKey(Schema.String),
|
|
350
|
+
/** MIME type; inferred from the extension when absent. */
|
|
351
|
+
type: Schema.optionalKey(Schema.String),
|
|
352
|
+
/** Pixel width. */
|
|
353
|
+
width: Schema.optionalKey(Schema.Int),
|
|
354
|
+
/** Pixel height. */
|
|
355
|
+
height: Schema.optionalKey(Schema.Int),
|
|
356
|
+
/** Alt text; inferred when absent. */
|
|
357
|
+
alt: Schema.optionalKey(Schema.String)
|
|
358
|
+
}).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" }))) {};
|
|
359
|
+
/**
|
|
360
|
+
* One registry a documented package is published to.
|
|
361
|
+
*
|
|
362
|
+
* @public
|
|
363
|
+
*/
|
|
364
|
+
var BundleRegistryRef = class extends Schema.Class("BundleRegistryRef")({
|
|
365
|
+
/** The protocol family, e.g. `"npm"` or `"jsr"`. Unknown values are accepted. */
|
|
366
|
+
type: Schema.String,
|
|
367
|
+
/** The human instance label, e.g. `"npm"`. */
|
|
368
|
+
name: Schema.String,
|
|
369
|
+
/** The package's URL on that registry instance. */
|
|
370
|
+
url: Schema.String
|
|
371
|
+
}) {};
|
|
372
|
+
/**
|
|
373
|
+
* The Open Graph settings of a package's API docs.
|
|
374
|
+
*
|
|
375
|
+
* @public
|
|
376
|
+
*/
|
|
377
|
+
var BundleOpenGraphConfig = class extends Schema.Class("BundleOpenGraphConfig")({
|
|
378
|
+
/** Static images, by path or url. Listed after a generated image. */
|
|
379
|
+
images: Schema.optionalKey(Schema.Array(BundleOpenGraphImage)),
|
|
380
|
+
/** Embed accent color, a CSS color string. */
|
|
381
|
+
themeColor: Schema.optionalKey(Schema.String),
|
|
382
|
+
/** Renders an image at build time, listed first. `"satori"` is the only renderer. */
|
|
383
|
+
generate: Schema.optionalKey(Schema.Literal("satori")),
|
|
384
|
+
/**
|
|
385
|
+
* The cross-build image cache's salt.
|
|
386
|
+
*
|
|
387
|
+
* @remarks
|
|
388
|
+
* A string caches under it, so change it whenever the renderer's output changes for the same input.
|
|
389
|
+
* `false` always regenerates. Absent, the renderer's own salt is used.
|
|
390
|
+
*/
|
|
391
|
+
cacheSalt: Schema.optionalKey(Schema.Union([Schema.String, Schema.Literal(false)]))
|
|
392
|
+
}) {};
|
|
393
|
+
/**
|
|
394
|
+
* The config tier of a package's emitted `bundle.json`, the `[package.bundle]` table.
|
|
395
|
+
*
|
|
396
|
+
* @public
|
|
397
|
+
*/
|
|
398
|
+
var BundleConfig = class extends Schema.Class("BundleConfig")({
|
|
399
|
+
/** The display name. */
|
|
400
|
+
name: Schema.optionalKey(Schema.String),
|
|
401
|
+
/** A one-line tagline. */
|
|
402
|
+
tagline: Schema.optionalKey(Schema.String),
|
|
403
|
+
/** A description. */
|
|
404
|
+
description: Schema.optionalKey(Schema.String),
|
|
405
|
+
/** The Open Graph settings. */
|
|
406
|
+
openGraph: Schema.optionalKey(BundleOpenGraphConfig),
|
|
407
|
+
/** Registries; `false` disables the default derived from `targets.json`. */
|
|
408
|
+
registries: Schema.optionalKey(Schema.Union([Schema.Array(BundleRegistryRef), Schema.Literal(false)]))
|
|
409
|
+
}) {};
|
|
410
|
+
/**
|
|
411
|
+
* The `[package]` table of `effected.toml`.
|
|
412
|
+
*
|
|
413
|
+
* @public
|
|
414
|
+
*/
|
|
415
|
+
var PackageConfig = class extends Schema.Class("PackageConfig")({
|
|
416
|
+
/** The build settings. */
|
|
417
|
+
build: PackageBuildConfig.pipe(Schema.withDecodingDefaultKey(Effect.succeed({}))),
|
|
418
|
+
/** The `bundle.json` config tier. */
|
|
419
|
+
bundle: Schema.optionalKey(BundleConfig)
|
|
420
|
+
}) {};
|
|
421
|
+
/**
|
|
422
|
+
* A decoded `effected.toml`.
|
|
423
|
+
*
|
|
424
|
+
* @remarks
|
|
425
|
+
* Decode it with `onExcessProperty: "error"`: a struct's decode drops
|
|
426
|
+
* unknown keys by default, and a typo in a human-written config must fail naming its path rather than
|
|
427
|
+
* silently taking the default.
|
|
428
|
+
*
|
|
429
|
+
* @public
|
|
430
|
+
*/
|
|
431
|
+
var EffectedConfig = class extends Schema.Class("EffectedConfig")({
|
|
432
|
+
/** The package tables. */
|
|
433
|
+
package: Schema.optionalKey(PackageConfig),
|
|
434
|
+
/** The GitHub Action table. Absent for a library. */
|
|
435
|
+
action: Schema.optionalKey(ActionConfig)
|
|
436
|
+
}) {};
|
|
437
|
+
|
|
438
|
+
export { BuildFormat, BuildPlatform, BundleConfig, BundleOpenGraphConfig, BundleOpenGraphImage, BundleRegistryRef, CopyEntry, EffectedConfig, EntryOverride, ExeConfig, ExeSeaConfig, ExeTargetConfig, JsxConfig, LooseFileSpec, ManifestConfig, MetaConfig, PackageBuildConfig, PackageConfig, TsdocConfig, TsdocTagDefinition, WarningSuppressionRule };
|
|
@@ -0,0 +1,171 @@
|
|
|
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
|
+
/**
|
|
103
|
+
* Tables that were renamed, by old dotted path. Never an alias: the old key still fails the decode, and the
|
|
104
|
+
* reason only names where its settings moved.
|
|
105
|
+
*/
|
|
106
|
+
const RENAMED_TABLES = { "package.tsdoctor": "[package.bundle]" };
|
|
107
|
+
/** An issue's reason, with a rename hint when the key is a renamed table. */
|
|
108
|
+
const reasonOf = ({ keys, message }) => {
|
|
109
|
+
const at = dotted(keys);
|
|
110
|
+
const renamed = RENAMED_TABLES[at];
|
|
111
|
+
return renamed !== void 0 ? `${at}: ${message} (renamed to ${renamed})` : `${at}: ${message}`;
|
|
112
|
+
};
|
|
113
|
+
/** Every issue under a schema failure, as its property keys and message. */
|
|
114
|
+
const issuesOf = (issue) => SchemaIssue.makeFormatterStandardSchemaV1()(issue).issues.map(({ message, path = [] }) => ({
|
|
115
|
+
message,
|
|
116
|
+
keys: path.map((segment) => typeof segment === "object" ? segment.key : segment)
|
|
117
|
+
}));
|
|
118
|
+
/**
|
|
119
|
+
* Finds, merges and decodes `effected.toml`.
|
|
120
|
+
*
|
|
121
|
+
* @public
|
|
122
|
+
*/
|
|
123
|
+
var EffectedConfigFile = class {
|
|
124
|
+
constructor() {}
|
|
125
|
+
/**
|
|
126
|
+
* Loads the config that applies to the package at `cwd`.
|
|
127
|
+
*
|
|
128
|
+
* @remarks
|
|
129
|
+
* The root tier is the first of `.config/effected.toml` and `effected.toml` under the workspace root. The
|
|
130
|
+
* package tier is the first of those two and `lib/configs/effected.toml` under `cwd`; it applies only when
|
|
131
|
+
* `cwd` is not the root. The package tier merges over the root tier per {@link merge}, and the merged
|
|
132
|
+
* document decodes once, so defaults apply after precedence.
|
|
133
|
+
*
|
|
134
|
+
* Decoding rejects unknown keys and reports all of them. When no workspace root sits above `cwd`, `cwd`
|
|
135
|
+
* is the root. No file anywhere is not a failure: `config.package` holds every default and `sources` has no
|
|
136
|
+
* keys.
|
|
137
|
+
*
|
|
138
|
+
* @param options - `cwd` is the package directory; `root` skips workspace discovery.
|
|
139
|
+
*/
|
|
140
|
+
static load = Effect.fn("EffectedConfigFile.load")(function* (options) {
|
|
141
|
+
const pathService = yield* Path.Path;
|
|
142
|
+
const cwd = pathService.resolve(options.cwd);
|
|
143
|
+
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({
|
|
144
|
+
path: Predicate.hasProperty(error, "path") && Predicate.isString(error.path) ? error.path : cwd,
|
|
145
|
+
reason: causeMessage(error) ?? String(error)
|
|
146
|
+
})));
|
|
147
|
+
const root = yield* readFirst(rootDirectory, ROOT_CANDIDATES);
|
|
148
|
+
const pkg = rootDirectory === cwd ? void 0 : yield* readFirst(cwd, PACKAGE_CANDIDATES);
|
|
149
|
+
const config = yield* Schema.decodeUnknownEffect(ResolvedConfig)(merge(root?.document ?? {}, pkg?.document ?? {}), {
|
|
150
|
+
onExcessProperty: "error",
|
|
151
|
+
errors: "all"
|
|
152
|
+
}).pipe(Effect.mapError((error) => {
|
|
153
|
+
const issues = issuesOf(error.issue);
|
|
154
|
+
const first = issues[0]?.keys ?? [];
|
|
155
|
+
return new EffectedConfigError({
|
|
156
|
+
path: blame(first, root, pkg, cwd),
|
|
157
|
+
reason: issues.map(reasonOf).join("; "),
|
|
158
|
+
...first.length > 0 ? { issuePath: dotted(first) } : {}
|
|
159
|
+
});
|
|
160
|
+
}));
|
|
161
|
+
return ResolvedEffectedConfig.make({
|
|
162
|
+
config,
|
|
163
|
+
sources: {
|
|
164
|
+
...root !== void 0 ? { root: root.path } : {},
|
|
165
|
+
...pkg !== void 0 ? { package: pkg.path } : {}
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export { EffectedConfigError, EffectedConfigFile, ResolvedConfig, ResolvedEffectedConfig };
|
package/config/merge.js
ADDED
|
@@ -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 };
|