@effected/bundler 0.1.0 → 0.2.1

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.
@@ -1,7 +1,7 @@
1
- import { mkdtempSync, realpathSync, rmSync } from "node:fs";
2
- import { join } from "node:path";
3
1
  import { execFile } from "node:child_process";
2
+ import { mkdtempSync, realpathSync, rmSync } from "node:fs";
4
3
  import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
5
  import { pathToFileURL } from "node:url";
6
6
 
7
7
  // src/action/import-check.ts
@@ -100,9 +100,20 @@ var JsxConfig = class extends Schema.Class("JsxConfig")({
100
100
  *
101
101
  * @public
102
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([]))) }) {};
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
+ }) {};
106
117
  /**
107
118
  * An API Extractor message-suppression rule.
108
119
  *
@@ -166,7 +177,7 @@ var MetaConfig = class extends Schema.Class("MetaConfig")({
166
177
  *
167
178
  * @remarks
168
179
  * 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.
180
+ * and `tsconfig.json`, and `bundle.json` when one was emitted.
170
181
  */
171
182
  localPaths: Schema.Array(Schema.String).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
172
183
  /**
@@ -331,7 +342,7 @@ var PackageBuildConfig = class extends Schema.Class("PackageBuildConfig")({
331
342
  *
332
343
  * @public
333
344
  */
334
- var TsdoctorOpenGraphImage = class extends Schema.Class("TsdoctorOpenGraphImage")(Schema.Struct({
345
+ var BundleOpenGraphImage = class extends Schema.Class("BundleOpenGraphImage")(Schema.Struct({
335
346
  /** Bundle-relative asset path. Mutually exclusive with `url`. */
336
347
  path: Schema.optionalKey(Schema.String),
337
348
  /** Absolute external URL, used verbatim. Mutually exclusive with `path`. */
@@ -350,7 +361,7 @@ var TsdoctorOpenGraphImage = class extends Schema.Class("TsdoctorOpenGraphImage"
350
361
  *
351
362
  * @public
352
363
  */
353
- var TsdoctorRegistryRef = class extends Schema.Class("TsdoctorRegistryRef")({
364
+ var BundleRegistryRef = class extends Schema.Class("BundleRegistryRef")({
354
365
  /** The protocol family, e.g. `"npm"` or `"jsr"`. Unknown values are accepted. */
355
366
  type: Schema.String,
356
367
  /** The human instance label, e.g. `"npm"`. */
@@ -363,9 +374,9 @@ var TsdoctorRegistryRef = class extends Schema.Class("TsdoctorRegistryRef")({
363
374
  *
364
375
  * @public
365
376
  */
366
- var TsdoctorOpenGraphConfig = class extends Schema.Class("TsdoctorOpenGraphConfig")({
377
+ var BundleOpenGraphConfig = class extends Schema.Class("BundleOpenGraphConfig")({
367
378
  /** Static images, by path or url. Listed after a generated image. */
368
- images: Schema.optionalKey(Schema.Array(TsdoctorOpenGraphImage)),
379
+ images: Schema.optionalKey(Schema.Array(BundleOpenGraphImage)),
369
380
  /** Embed accent color, a CSS color string. */
370
381
  themeColor: Schema.optionalKey(Schema.String),
371
382
  /** Renders an image at build time, listed first. `"satori"` is the only renderer. */
@@ -380,11 +391,11 @@ var TsdoctorOpenGraphConfig = class extends Schema.Class("TsdoctorOpenGraphConfi
380
391
  cacheSalt: Schema.optionalKey(Schema.Union([Schema.String, Schema.Literal(false)]))
381
392
  }) {};
382
393
  /**
383
- * The config tier of a package's emitted `tsdoctor.json`, the `[package.tsdoctor]` table.
394
+ * The config tier of a package's emitted `bundle.json`, the `[package.bundle]` table.
384
395
  *
385
396
  * @public
386
397
  */
387
- var TsdoctorConfig = class extends Schema.Class("TsdoctorConfig")({
398
+ var BundleConfig = class extends Schema.Class("BundleConfig")({
388
399
  /** The display name. */
389
400
  name: Schema.optionalKey(Schema.String),
390
401
  /** A one-line tagline. */
@@ -392,9 +403,9 @@ var TsdoctorConfig = class extends Schema.Class("TsdoctorConfig")({
392
403
  /** A description. */
393
404
  description: Schema.optionalKey(Schema.String),
394
405
  /** The Open Graph settings. */
395
- openGraph: Schema.optionalKey(TsdoctorOpenGraphConfig),
406
+ openGraph: Schema.optionalKey(BundleOpenGraphConfig),
396
407
  /** Registries; `false` disables the default derived from `targets.json`. */
397
- registries: Schema.optionalKey(Schema.Union([Schema.Array(TsdoctorRegistryRef), Schema.Literal(false)]))
408
+ registries: Schema.optionalKey(Schema.Union([Schema.Array(BundleRegistryRef), Schema.Literal(false)]))
398
409
  }) {};
399
410
  /**
400
411
  * The `[package]` table of `effected.toml`.
@@ -404,8 +415,8 @@ var TsdoctorConfig = class extends Schema.Class("TsdoctorConfig")({
404
415
  var PackageConfig = class extends Schema.Class("PackageConfig")({
405
416
  /** The build settings. */
406
417
  build: PackageBuildConfig.pipe(Schema.withDecodingDefaultKey(Effect.succeed({}))),
407
- /** The `tsdoctor.json` config tier. */
408
- tsdoctor: Schema.optionalKey(TsdoctorConfig)
418
+ /** The `bundle.json` config tier. */
419
+ bundle: Schema.optionalKey(BundleConfig)
409
420
  }) {};
410
421
  /**
411
422
  * A decoded `effected.toml`.
@@ -424,4 +435,4 @@ var EffectedConfig = class extends Schema.Class("EffectedConfig")({
424
435
  action: Schema.optionalKey(ActionConfig)
425
436
  }) {};
426
437
 
427
- export { BuildFormat, BuildPlatform, CopyEntry, EffectedConfig, EntryOverride, ExeConfig, ExeSeaConfig, ExeTargetConfig, JsxConfig, LooseFileSpec, ManifestConfig, MetaConfig, PackageBuildConfig, PackageConfig, TsdocConfig, TsdocTagDefinition, TsdoctorConfig, TsdoctorOpenGraphConfig, TsdoctorOpenGraphImage, TsdoctorRegistryRef, WarningSuppressionRule };
438
+ export { BuildFormat, BuildPlatform, BundleConfig, BundleOpenGraphConfig, BundleOpenGraphImage, BundleRegistryRef, CopyEntry, EffectedConfig, EntryOverride, ExeConfig, ExeSeaConfig, ExeTargetConfig, JsxConfig, LooseFileSpec, ManifestConfig, MetaConfig, PackageBuildConfig, PackageConfig, TsdocConfig, TsdocTagDefinition, WarningSuppressionRule };
@@ -99,6 +99,17 @@ const blame = (segments, root, pkg, fallback) => {
99
99
  return depthIn(root.document, segments) > depthIn(pkg.document, segments) ? root.path : pkg.path;
100
100
  };
101
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
+ };
102
113
  /** Every issue under a schema failure, as its property keys and message. */
103
114
  const issuesOf = (issue) => SchemaIssue.makeFormatterStandardSchemaV1()(issue).issues.map(({ message, path = [] }) => ({
104
115
  message,
@@ -143,7 +154,7 @@ var EffectedConfigFile = class {
143
154
  const first = issues[0]?.keys ?? [];
144
155
  return new EffectedConfigError({
145
156
  path: blame(first, root, pkg, cwd),
146
- reason: issues.map(({ keys, message }) => `${dotted(keys)}: ${message}`).join("; "),
157
+ reason: issues.map(reasonOf).join("; "),
147
158
  ...first.length > 0 ? { issuePath: dotted(first) } : {}
148
159
  });
149
160
  }));
@@ -2,8 +2,7 @@ import { ConfigValidationError } from "../errors.js";
2
2
  import { normalizeExeOptions } from "../exe/config.js";
3
3
  import { normalizeLooseFiles } from "../passes/loose-files.js";
4
4
  import { resolveTargets } from "../targets/resolve-targets.js";
5
- import { Context, Effect, Layer } from "effect";
6
- import { existsSync, statSync } from "node:fs";
5
+ import { Context, Effect, FileSystem, Layer } from "effect";
7
6
 
8
7
  // src/config-validation/ConfigValidator.ts
9
8
  const VALID_SYNTAX_KINDS = /* @__PURE__ */ new Set([
@@ -11,7 +10,7 @@ const VALID_SYNTAX_KINDS = /* @__PURE__ */ new Set([
11
10
  "inline",
12
11
  "modifier"
13
12
  ]);
14
- /** Synchronous rule set; throws ConfigValidationError on the first violation. */
13
+ /** The synchronous rule set; throws ConfigValidationError on the first violation. */
15
14
  function check(input) {
16
15
  if (input.targets !== void 0 && Object.keys(input.targets).length > 0) resolveTargets({
17
16
  targets: input.targets,
@@ -42,11 +41,10 @@ function check(input) {
42
41
  path: "meta.tsdoc.tagDefinitions",
43
42
  reason: `tag "${tag.tagName}" has an invalid syntaxKind "${tag.syntaxKind}"`
44
43
  });
45
- for (const p of input.meta.localPaths ?? []) if (existsSync(p) && !statSync(p).isDirectory()) throw new ConfigValidationError({
46
- path: "meta.localPaths",
47
- reason: `"${p}" exists but is not a directory`
48
- });
49
44
  }
45
+ }
46
+ /** The rules after `meta.localPaths`, which the layer checks against the filesystem between the two. */
47
+ function checkLooseFiles(input) {
50
48
  if (input.looseFiles !== void 0) normalizeLooseFiles(input.looseFiles);
51
49
  }
52
50
  /**
@@ -55,13 +53,21 @@ function check(input) {
55
53
  * @public
56
54
  */
57
55
  var ConfigValidator = class extends Context.Service()("@savvy-web/tsdown-plugins/ConfigValidator") {
58
- static layer = Layer.succeed(this, { validate: (input) => Effect.try({
59
- try: () => check(input),
60
- catch: (e) => e instanceof ConfigValidationError ? e : new ConfigValidationError({
61
- path: "config",
62
- reason: String(e)
63
- })
64
- }) });
56
+ static layer = Layer.effect(this, Effect.gen(function* () {
57
+ const fs = yield* FileSystem.FileSystem;
58
+ const checkLocalPaths = (paths) => Effect.forEach(paths, (p) => fs.stat(p).pipe(Effect.option, Effect.flatMap((info) => info._tag === "Some" && info.value.type !== "Directory" ? Effect.fail(new ConfigValidationError({
59
+ path: "meta.localPaths",
60
+ reason: `"${p}" exists but is not a directory`
61
+ })) : Effect.void)));
62
+ const run = (rules) => Effect.try({
63
+ try: rules,
64
+ catch: (e) => e instanceof ConfigValidationError ? e : new ConfigValidationError({
65
+ path: "config",
66
+ reason: String(e)
67
+ })
68
+ });
69
+ return { validate: (input) => run(() => check(input)).pipe(Effect.andThen(checkLocalPaths(input.meta?.localPaths ?? [])), Effect.andThen(run(() => checkLooseFiles(input)))) };
70
+ }));
65
71
  };
66
72
 
67
73
  export { ConfigValidator };
@@ -1,8 +1,8 @@
1
1
  import { tsconfigSyncOptions } from "../tsconfig/sync-options.js";
2
2
  import { Result } from "effect";
3
3
  import { existsSync, realpathSync, writeFileSync } from "node:fs";
4
- import { dirname, isAbsolute, join, resolve } from "node:path";
5
4
  import { tmpdir } from "node:os";
5
+ import { dirname, isAbsolute, join, resolve } from "node:path";
6
6
  import { createHash } from "node:crypto";
7
7
  import { GlobPattern, GlobPatternOptions } from "@effected/glob";
8
8
  import { TsconfigLoaderSync } from "@effected/tsconfig-json";
package/errors.js CHANGED
@@ -22,16 +22,16 @@ var MetaGenerationError = class extends Data.TaggedError("MetaGenerationError")
22
22
  }
23
23
  };
24
24
  /**
25
- * Writing the `tsdoctor.json` sidecar failed: the composed manifest did not encode, or the file could not be
25
+ * Writing the `bundle.json` sidecar failed: the composed manifest did not encode, or the file could not be
26
26
  * written (a read-only or full disk). Recorded in `issues.json` as a `meta` error.
27
27
  *
28
28
  * @public
29
29
  */
30
- var TsdoctorEmitError = class extends Data.TaggedError("TsdoctorEmitError") {
30
+ var BundleManifestEmitError = class extends Data.TaggedError("BundleManifestEmitError") {
31
31
  get message() {
32
32
  const reason = this.cause instanceof Error ? this.cause.message : String(this.cause);
33
33
  return `Could not emit ${this.path} for ${this.packageName}: ${reason}`;
34
34
  }
35
35
  };
36
36
 
37
- export { ConfigValidationError, MetaGenerationError, TsdoctorEmitError };
37
+ export { BundleManifestEmitError, ConfigValidationError, MetaGenerationError };
package/exe/build.js CHANGED
@@ -2,8 +2,8 @@ import { buildMetricsPlugin } from "../report/metrics-plugin.js";
2
2
  import { createTimer } from "../report/timer.js";
3
3
  import { createTsdownLogger } from "../report/tsdown-logger.js";
4
4
  import { mkdtempSync, rmSync } from "node:fs";
5
- import { join } from "node:path";
6
5
  import { tmpdir } from "node:os";
6
+ import { join } from "node:path";
7
7
 
8
8
  // src/exe/build.ts
9
9
  /**