@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,137 @@
1
+ import { causeMessage } from "../internal/causeMessage.js";
2
+ import { Data, Effect, Layer, Option, Predicate, Result, Schema } from "effect";
3
+ import { mkdirSync, writeFileSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
6
+ import * as NodeServices from "@effect/platform-node/NodeServices";
7
+ import { ImageBackend, ImageCache, ImageCacheKey } from "@effected/images/cache";
8
+
9
+ // src/meta/og-image.ts
10
+ /**
11
+ * A configured `openGraph.generate` renderer threw, returned no bytes, or returned bytes that are
12
+ * not an image. Fails the build: a half-written OG image is worse than none.
13
+ *
14
+ * @public
15
+ */
16
+ var OgGenerateError = class extends Data.TaggedError("OgGenerateError") {
17
+ get message() {
18
+ const reason = this.cause instanceof Error ? this.cause.message : String(this.cause);
19
+ return `Open Graph image generation failed for ${this.packageName}: ${reason}`;
20
+ }
21
+ };
22
+ /**
23
+ * The renderer an `[package.tsdoctor.openGraph] generate` name selects.
24
+ *
25
+ * @remarks
26
+ * Nothing renders here, but a build asking for an image fails now rather than after its passes when a peer is absent.
27
+ * Both peers are optional, so the renderer's module and its peers load only for a package that asks. `importModule`
28
+ * replaces the dynamic import of a peer.
29
+ *
30
+ * @public
31
+ */
32
+ const resolveOgGenerator = (name, options) => Effect.tryPromise({
33
+ try: async () => {
34
+ const importModule = options.importModule ?? ((specifier) => import(specifier));
35
+ const peers = OG_RENDERER_PEERS[name];
36
+ await Promise.all(peers.map((peer) => importModule(peer).catch((cause) => {
37
+ throw new Error(isPeerNotFound(cause, peer) ? `generate = "${name}" needs the optional peers ${peers.join(" and ")}; install both to generate Open Graph images` : `generate = "${name}" could not load the installed peer ${peer}: ${causeMessage(cause) ?? String(cause)}`, { cause });
38
+ })));
39
+ const { ogImage } = await import("./og-satori.js");
40
+ return ogImage.satori();
41
+ },
42
+ catch: (cause) => new OgGenerateError({
43
+ packageName: options.packageName,
44
+ cause
45
+ })
46
+ });
47
+ /** Whether an import failed because the peer itself is not installed, rather than something it loads in turn. */
48
+ const isPeerNotFound = (cause, peer) => Predicate.hasProperty(cause, "code") && (cause.code === "ERR_MODULE_NOT_FOUND" || cause.code === "MODULE_NOT_FOUND") && (causeMessage(cause) ?? "").includes(`'${peer}'`);
49
+ /** The optional peers each renderer needs. */
50
+ const OG_RENDERER_PEERS = { satori: ["satori", "@resvg/resvg-js"] };
51
+ /** The image types an Open Graph consumer can render; anything else fails rather than shipping a mislabeled file. */
52
+ const ACCEPT = [
53
+ "png",
54
+ "jpeg",
55
+ "webp"
56
+ ];
57
+ /**
58
+ * The cache key's params: exactly what the generator receives, so any change to its input is a miss.
59
+ * `Schema.Struct` drops undeclared keys, so the `satisfies` clauses fail to compile when a field is
60
+ * added to {@link OgImageInfo} without being keyed here (or removed from it but kept here).
61
+ */
62
+ const OgImageInfoKey = Schema.Struct({
63
+ name: Schema.String,
64
+ packageName: Schema.String,
65
+ version: Schema.String,
66
+ tagline: Schema.optional(Schema.String),
67
+ description: Schema.optional(Schema.String),
68
+ project: Schema.optional(Schema.Struct({
69
+ name: Schema.optional(Schema.String),
70
+ tagline: Schema.optional(Schema.String)
71
+ }))
72
+ });
73
+ /**
74
+ * The cache is an optimization, never a reason to fail a build that rendered a valid image: an
75
+ * unreadable entry is a miss and a failed store is dropped. Generator and validation failures still
76
+ * surface, because those come from `ImageCache` itself, not the backend.
77
+ */
78
+ const tolerantDirectory = (directory) => Layer.effect(ImageBackend, Effect.gen(function* () {
79
+ const backend = yield* ImageBackend;
80
+ return {
81
+ get: (key) => backend.get(key).pipe(Effect.orElseSucceed(() => Option.none())),
82
+ set: (params) => backend.set(params).pipe(Effect.ignore)
83
+ };
84
+ })).pipe(Layer.provide(ImageBackend.layerDirectory({ directory })));
85
+ /**
86
+ * The salt the cross-build cache runs under, or `undefined` to always regenerate: an explicit
87
+ * `cacheSalt` string wins, `false` disables, and otherwise the generator's own salt applies.
88
+ *
89
+ * @public
90
+ */
91
+ function resolveOgCacheSalt(generate, cacheSalt) {
92
+ if (cacheSalt === false) return void 0;
93
+ return cacheSalt ?? generate.cacheSalt;
94
+ }
95
+ /**
96
+ * Run the generator (or reuse a cached render), size the bytes, and write `og/<unscoped>.<ext>`
97
+ * under the meta dir. Returns the manifest image entry (bundle-relative path, MIME type, dimensions).
98
+ *
99
+ * @public
100
+ */
101
+ async function writeGeneratedOgImage(options) {
102
+ const { packageName } = options.info;
103
+ const backend = options.cache === void 0 ? ImageBackend.layerNone : tolerantDirectory(options.cache.directory);
104
+ const result = await Effect.gen(function* () {
105
+ const key = yield* ImageCacheKey.fromParams(OgImageInfoKey, options.info, {
106
+ salt: options.cache?.salt ?? "",
107
+ namespace: "og"
108
+ });
109
+ return yield* (yield* ImageCache).getOrGenerate(key, () => Effect.tryPromise({
110
+ try: () => options.generate(options.info),
111
+ catch: (cause) => cause
112
+ }), { accept: ACCEPT });
113
+ }).pipe(Effect.provide(ImageCache.layer.pipe(Layer.provide(backend), Layer.provideMerge(Layer.merge(NodeServices.layer, NodeCrypto.layerDigest)))), Effect.result, Effect.runPromise);
114
+ if (Result.isFailure(result)) throw new OgGenerateError({
115
+ packageName,
116
+ cause: result.failure
117
+ });
118
+ const { bytes, facts } = result.success;
119
+ const relative = `og/${options.unscopedName}.${facts.extension}`;
120
+ try {
121
+ mkdirSync(join(options.outMetaDir, "og"), { recursive: true });
122
+ writeFileSync(join(options.outMetaDir, relative), bytes);
123
+ } catch (cause) {
124
+ throw new OgGenerateError({
125
+ packageName,
126
+ cause
127
+ });
128
+ }
129
+ return {
130
+ path: relative,
131
+ type: facts.mimeType,
132
+ width: facts.width,
133
+ height: facts.height
134
+ };
135
+ }
136
+
137
+ export { OgGenerateError, resolveOgCacheSalt, resolveOgGenerator, writeGeneratedOgImage };
@@ -0,0 +1,140 @@
1
+ import { createRequire } from "node:module";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { fileURLToPath } from "node:url";
4
+ import { readFile } from "node:fs/promises";
5
+
6
+ // src/meta/og-satori.ts
7
+ /**
8
+ * The bundled Inter SemiBold face (SIL OFL 1.1; see `assets/LICENSE-Inter.txt`). Resolved
9
+ * relative to THIS module: the built `meta/og-satori.js` reaches `assets/` at the package root, while
10
+ * the source `src/meta/og-satori.ts` reaches it through `public/`, so both candidates are tried.
11
+ */
12
+ const FONT_CANDIDATES = [new URL("../assets/Inter-SemiBold.ttf", import.meta.url), new URL("../../public/assets/Inter-SemiBold.ttf", import.meta.url)];
13
+ function fontPath() {
14
+ for (const candidate of FONT_CANDIDATES) {
15
+ const path = fileURLToPath(candidate);
16
+ if (existsSync(path)) return path;
17
+ }
18
+ throw new Error("ogImage.satori() could not locate its bundled font assets/Inter-SemiBold.ttf");
19
+ }
20
+ /** The installed version of an optional renderer peer, or `"absent"` (rendering then fails, and nothing is cached). */
21
+ function peerVersion(name) {
22
+ try {
23
+ const manifest = createRequire(import.meta.url).resolve(`${name}/package.json`);
24
+ return JSON.parse(readFileSync(manifest, "utf-8")).version ?? "unknown";
25
+ } catch {
26
+ return "absent";
27
+ }
28
+ }
29
+ async function loadRenderers() {
30
+ try {
31
+ const [{ default: satori }, { Resvg }] = await Promise.all([import("satori"), import("@resvg/resvg-js")]);
32
+ return {
33
+ satori,
34
+ Resvg
35
+ };
36
+ } catch (cause) {
37
+ throw new Error("ogImage.satori() needs the optional peers satori and @resvg/resvg-js; install both to generate Open Graph images", { cause });
38
+ }
39
+ }
40
+ function card(info, colors) {
41
+ const text = (style, children) => ({
42
+ type: "div",
43
+ props: {
44
+ style,
45
+ children
46
+ }
47
+ });
48
+ return {
49
+ type: "div",
50
+ props: {
51
+ style: {
52
+ display: "flex",
53
+ flexDirection: "column",
54
+ justifyContent: "space-between",
55
+ width: "100%",
56
+ height: "100%",
57
+ padding: 64,
58
+ background: colors.background,
59
+ color: colors.foreground,
60
+ fontFamily: "Inter"
61
+ },
62
+ children: [
63
+ text({
64
+ fontSize: 32,
65
+ color: colors.accent
66
+ }, info.project?.name ?? ""),
67
+ {
68
+ type: "div",
69
+ props: {
70
+ style: {
71
+ display: "flex",
72
+ flexDirection: "column",
73
+ gap: 16
74
+ },
75
+ children: [text({
76
+ fontSize: 72,
77
+ fontWeight: 600
78
+ }, info.name), text({
79
+ fontSize: 36,
80
+ opacity: .8
81
+ }, info.tagline ?? info.description ?? "")]
82
+ }
83
+ },
84
+ text({
85
+ fontSize: 28,
86
+ opacity: .7
87
+ }, `${info.packageName}@${info.version}`)
88
+ ]
89
+ }
90
+ };
91
+ }
92
+ /**
93
+ * Build-time Open Graph image renderers for `[package.tsdoctor.openGraph] generate`.
94
+ *
95
+ * @remarks
96
+ * `satori()` returns the default card: project name, package name and version, tagline,
97
+ * 1200×630 PNG, rendered through the optional peers `satori` and `@resvg/resvg-js`. The peers
98
+ * load lazily on first render, so a build that does not generate an image never needs them.
99
+ *
100
+ * The returned generator carries a `cacheSalt` (this package's version, the peers' versions and
101
+ * the colors), so its renders are cached across builds by default; `openGraph.cacheSalt: false`
102
+ * turns that off.
103
+ *
104
+ * @public
105
+ */
106
+ const ogImage = { satori(options = {}) {
107
+ const colors = {
108
+ accent: options.accent ?? "#38bdf8",
109
+ background: options.background ?? "#0f172a",
110
+ foreground: options.foreground ?? "#f8fafc"
111
+ };
112
+ const cacheSalt = JSON.stringify({
113
+ renderer: "@effected/bundler/og#satori",
114
+ version: "0.1.0",
115
+ satori: peerVersion("satori"),
116
+ resvg: peerVersion("@resvg/resvg-js"),
117
+ colors
118
+ });
119
+ const render = async (info) => {
120
+ const { satori, Resvg } = await loadRenderers();
121
+ const font = await readFile(fontPath());
122
+ const svg = await satori(card(info, colors), {
123
+ width: 1200,
124
+ height: 630,
125
+ fonts: [{
126
+ name: "Inter",
127
+ data: font,
128
+ weight: 600,
129
+ style: "normal"
130
+ }]
131
+ });
132
+ return new Uint8Array(new Resvg(svg, { fitTo: {
133
+ mode: "width",
134
+ value: 1200
135
+ } }).render().asPng());
136
+ };
137
+ return Object.assign(render, { cacheSalt });
138
+ } };
139
+
140
+ export { ogImage };
@@ -0,0 +1,32 @@
1
+ // src/meta/optimistic.ts
2
+ /** Dependency map fields whose workspace-sibling versions get the optimistic bump. */
3
+ const DEP_FIELDS = [
4
+ "dependencies",
5
+ "peerDependencies",
6
+ "optionalDependencies"
7
+ ];
8
+ /**
9
+ * Rewrite a meta `package.json` so the package's own `version` and any workspace-sibling
10
+ * dependency version reflect their NEXT release version from `versions`. Pure: returns a new
11
+ * object, never mutates the input. External/catalog-resolved deps (names absent from `versions`)
12
+ * are left as-is.
13
+ * @public
14
+ */
15
+ function rewriteMetaVersions(pkg, versions, selfName) {
16
+ const out = { ...pkg };
17
+ const selfNext = versions.get(selfName);
18
+ if (selfNext !== void 0) out.version = selfNext;
19
+ for (const field of DEP_FIELDS) {
20
+ const deps = pkg[field];
21
+ if (deps === null || typeof deps !== "object") continue;
22
+ const next = { ...deps };
23
+ for (const depName of Object.keys(next)) {
24
+ const v = versions.get(depName);
25
+ if (v !== void 0) next[depName] = v;
26
+ }
27
+ out[field] = next;
28
+ }
29
+ return out;
30
+ }
31
+
32
+ export { rewriteMetaVersions };
@@ -0,0 +1,117 @@
1
+ import { resolveNextVersions } from "../changesets/next-versions.js";
2
+ import { deriveExportPaths } from "../entries/export-paths.js";
3
+ import { createEntryName } from "../entries/extract.js";
4
+ import { TsdoctorEmitError } from "../errors.js";
5
+ import { declarationsDirFor } from "../passes/target-groups.js";
6
+ import { normalizeMetaOptions } from "./config.js";
7
+ import { generateMeta } from "./generate.js";
8
+ import { OgGenerateError } from "./og-image.js";
9
+ import { rewriteMetaVersions } from "./optimistic.js";
10
+ import { TsdoctorSourceError, loadTsdoctorSources } from "./tsdoctor-source.js";
11
+ import { join } from "node:path";
12
+
13
+ // src/meta/run-pass.ts
14
+ /**
15
+ * Meta-pass orchestrator: derives export paths, filters bin/ entries, resolves optimistic
16
+ * next-versions, and calls generateMeta once per publish group.
17
+ * @public
18
+ */
19
+ async function runMetaPass(o) {
20
+ const gen = o.generateMeta ?? generateMeta;
21
+ const norm = normalizeMetaOptions(o.meta);
22
+ const canonicalId = (o.groups.find((g) => g.name === o.packageName) ?? o.groups[0])?.id ?? "npm";
23
+ const dtsBasenames = {};
24
+ const nonBinEntries = {};
25
+ for (const [name, src] of Object.entries(o.entries)) if (!name.startsWith("bin/")) {
26
+ dtsBasenames[name] = name;
27
+ nonBinEntries[name] = src;
28
+ }
29
+ const exportPaths = deriveExportPaths(nonBinEntries, o.exportsMap);
30
+ applySubdirMetaEntries(o.overrides, dtsBasenames, exportPaths);
31
+ const resolveNext = o.resolveNextVersions ?? resolveNextVersions;
32
+ const nextVersions = norm.optimistic ? await resolveNext(o.cwd) : void 0;
33
+ const manifestTransform = nextVersions ? (m) => rewriteMetaVersions(m, nextVersions.versions, o.packageName) : void 0;
34
+ const loadSources = o.loadTsdoctorSources ?? loadTsdoctorSources;
35
+ let sources;
36
+ try {
37
+ sources = await loadSources(o.cwd);
38
+ } catch (err) {
39
+ if (err instanceof TsdoctorSourceError) for (const g of o.groups) o.collector.recordError(g.id, {
40
+ source: "meta",
41
+ level: "error",
42
+ code: "tsdoctor-source-invalid",
43
+ text: err.message,
44
+ file: err.path
45
+ });
46
+ throw err;
47
+ }
48
+ if (sources.discoveryFailure !== void 0) for (const g of o.groups) o.collector.recordWarning(g.id, {
49
+ source: "meta",
50
+ level: "warn",
51
+ code: "tsdoctor-workspace-discovery-failed",
52
+ text: `Workspace discovery failed, so tsdoctor.json has no project tier: ${sources.discoveryFailure}`
53
+ });
54
+ for (const g of o.groups) {
55
+ const targets = (o.targets ?? []).filter((t) => t.group === g.id).map((t) => ({
56
+ name: t.id,
57
+ registry: t.registry
58
+ }));
59
+ try {
60
+ await gen({
61
+ cwd: o.cwd,
62
+ packageName: o.packageName,
63
+ tsconfigPath: o.tsconfigPath,
64
+ dtsDir: join(o.cwd, "dist", "prod", g.id, "pkg"),
65
+ aeInputDir: declarationsDirFor(o.cwd, g.id),
66
+ entries: dtsBasenames,
67
+ exportPaths,
68
+ outMetaDir: join(o.cwd, "dist", "prod", g.id, "meta"),
69
+ localPaths: g.id === canonicalId ? norm.localPaths : [],
70
+ tsdoc: norm.tsdoc,
71
+ ...manifestTransform !== void 0 ? { manifestTransform } : {},
72
+ ci: o.ci,
73
+ tsdoctor: {
74
+ config: norm.tsdoctor,
75
+ leaf: sources.leaf,
76
+ project: sources.project,
77
+ targets
78
+ },
79
+ onMessage: (e) => e.level === "error" ? o.collector.recordError(g.id, e) : o.collector.recordWarning(g.id, e),
80
+ onSuppressed: (e) => o.collector.recordSuppressed(g.id, e)
81
+ });
82
+ } catch (err) {
83
+ if (err instanceof OgGenerateError) o.collector.recordError(g.id, {
84
+ source: "meta",
85
+ level: "error",
86
+ code: "og-generate-failed",
87
+ text: err.message
88
+ });
89
+ else if (err instanceof TsdoctorEmitError) o.collector.recordError(g.id, {
90
+ source: "meta",
91
+ level: "error",
92
+ code: "tsdoctor-emit-failed",
93
+ text: err.message,
94
+ file: err.path
95
+ });
96
+ throw err;
97
+ }
98
+ }
99
+ }
100
+ /**
101
+ * For each `outSubdir` override, point its meta entry at the isolated sub-package barrel.
102
+ *
103
+ * @public
104
+ */
105
+ function applySubdirMetaEntries(overrides, dtsBasenames, exportPaths) {
106
+ if (overrides === void 0) return;
107
+ for (const ov of overrides) {
108
+ if (ov.outSubdir === void 0) continue;
109
+ const exportPath = ov.entries[0];
110
+ if (exportPath === void 0) continue;
111
+ const flatName = createEntryName(exportPath, false);
112
+ dtsBasenames[flatName] = `${ov.outSubdir}/index`;
113
+ exportPaths[flatName] = exportPath;
114
+ }
115
+ }
116
+
117
+ export { applySubdirMetaEntries, runMetaPass };
@@ -0,0 +1,63 @@
1
+ import { Result } from "effect";
2
+ import { readFileSync, writeFileSync } from "node:fs";
3
+ import { join, resolve } from "node:path";
4
+ import { GlobPattern, GlobPatternOptions } from "@effected/glob";
5
+ import { descendSync } from "@effected/walker";
6
+ import { nodeWalkerSyncOps } from "@effected/walker/node-sync";
7
+ import { decode, encode } from "@jridgewell/sourcemap-codec";
8
+
9
+ // src/meta/scrub-declaration-maps.ts
10
+ /** Every declaration map, at any depth, dot-directories included. */
11
+ const DECLARATION_MAPS = Result.getOrThrow(GlobPattern.compileResult("**/*.d.{ts,cts,mts}.map", GlobPatternOptions.make({ dot: true })));
12
+ /**
13
+ * Drop every source-less segment (a generated position with no original position) from a
14
+ * declaration map, in place. Returns the number of segments removed.
15
+ *
16
+ * @remarks
17
+ * rolldown 1.2.15+ writes such segments for declarations TypeScript synthesizes with no source
18
+ * position — the `declare const X_base` hoisted for a class whose heritage clause is a call
19
+ * expression (Effect's `Schema.Class`/`Data.TaggedError`, any mixin factory). API Extractor's
20
+ * `SourceMapper` resolves a source-less mapping item to the `.d.ts`'s own directory and then
21
+ * `readFile`s it, so the meta pass dies with `EISDIR` (savvy-web/systems#817; upstream
22
+ * microsoft/rushstack#6156 / PR #6157, unreleased). Segments with no source carry no location a
23
+ * consumer can use, so removing them is lossless for every reader.
24
+ *
25
+ * @internal
26
+ */
27
+ function scrubSourcelessMappings(mapPath) {
28
+ const raw = JSON.parse(readFileSync(mapPath, "utf8"));
29
+ const lines = decode(raw.mappings);
30
+ let removed = 0;
31
+ const scrubbed = lines.map((segments) => segments.filter((segment) => {
32
+ if (segment.length === 1) {
33
+ removed += 1;
34
+ return false;
35
+ }
36
+ return true;
37
+ }));
38
+ if (removed > 0) writeFileSync(mapPath, `${JSON.stringify({
39
+ ...raw,
40
+ mappings: encode(scrubbed)
41
+ })}\n`, "utf8");
42
+ return removed;
43
+ }
44
+ /**
45
+ * Scrub every `.d.ts.map`/`.d.cts.map`/`.d.mts.map` under `dir` (recursively). Returns the total
46
+ * number of segments removed. Missing dir -> 0.
47
+ *
48
+ * @internal
49
+ */
50
+ function scrubDeclarationMapsUnder(dir) {
51
+ const maps = Result.getOrThrow(descendSync(DECLARATION_MAPS, {
52
+ cwd: resolve(dir),
53
+ prune: [],
54
+ followSymlinks: true,
55
+ onUnreadable: "skip",
56
+ ...nodeWalkerSyncOps
57
+ }));
58
+ let removed = 0;
59
+ for (const rel of maps) removed += scrubSourcelessMappings(join(dir, rel));
60
+ return removed;
61
+ }
62
+
63
+ export { scrubDeclarationMapsUnder, scrubSourcelessMappings };
@@ -0,0 +1,55 @@
1
+ import { tsconfigSyncOptions } from "../tsconfig/sync-options.js";
2
+ import { existsSync } from "node:fs";
3
+ import * as nodePath from "node:path";
4
+ import { PortableTsconfig, TsconfigLoaderSync } from "@effected/tsconfig-json";
5
+
6
+ // src/meta/tsconfig-resolver.ts
7
+ /**
8
+ * JSON schema URL for tsconfig.json files.
9
+ * @internal
10
+ */
11
+ const TSCONFIG_SCHEMA_URL = "https://json.schemastore.org/tsconfig";
12
+ /**
13
+ * Resolves the package's effective compiler options (following `extends`) into a
14
+ * portable, JSON-serializable tsconfig for the meta release bundle.
15
+ *
16
+ * @remarks
17
+ * Resolves the package's own `<cwd>/tsconfig.json` (which extends the shared
18
+ * `@effected/plugin/tsconfig/ecma.json` base) via `@effected/tsconfig-json`'s
19
+ * synchronous `TsconfigLoaderSync` (tsc-parity `extends` resolution) so the
20
+ * result carries the full effective options (target/module/strict/jsx/lib),
21
+ * then projects them through the kit's `PortableTsconfig.make` allow-list
22
+ * filter to a portable, compilerOptions-only shape with no absolute paths or
23
+ * emit/file-selection options.
24
+ *
25
+ * When the package has no own `tsconfig.json` (e.g. a minimal test fixture),
26
+ * falls back to `fallbackConfigPath` — the build's already-resolved dts tsconfig,
27
+ * which always exists during a build. If neither is present, returns a minimal
28
+ * portable config carrying only the virtual-environment flags.
29
+ *
30
+ * @param cwd - Absolute package root.
31
+ * @param fallbackConfigPath - Optional resolved tsconfig to use when the package has no own one.
32
+ * @returns The portable tsconfig object.
33
+ *
34
+ * @public
35
+ */
36
+ function resolvePortableTsconfig(cwd, fallbackConfigPath) {
37
+ const ownConfig = nodePath.join(cwd, "tsconfig.json");
38
+ const configPath = existsSync(ownConfig) ? ownConfig : fallbackConfigPath !== void 0 && existsSync(fallbackConfigPath) ? fallbackConfigPath : void 0;
39
+ if (configPath === void 0) return {
40
+ $schema: TSCONFIG_SCHEMA_URL,
41
+ compilerOptions: {
42
+ composite: false,
43
+ noEmit: true
44
+ }
45
+ };
46
+ try {
47
+ const resolved = TsconfigLoaderSync.resolve(configPath, tsconfigSyncOptions);
48
+ return PortableTsconfig.make(resolved, { includeTypes: true });
49
+ } catch (error) {
50
+ const message = error instanceof Error ? error.message : String(error);
51
+ throw new Error(`Cannot resolve portable tsconfig at ${configPath}: ${message}`, { cause: error });
52
+ }
53
+ }
54
+
55
+ export { resolvePortableTsconfig };
@@ -0,0 +1,47 @@
1
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { isDeepStrictEqual } from "node:util";
4
+ import { StandardTags } from "@microsoft/tsdoc";
5
+
6
+ // src/meta/tsdoc-config.ts
7
+ const TSDOC_SCHEMA = "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json";
8
+ const SYNTAX_KIND_MAP = {
9
+ block: "block",
10
+ inline: "inline",
11
+ modifier: "modifier"
12
+ };
13
+ /** Build the tsdoc.json object: standard tags enabled, every standard tag marked supported, plus any custom tags. */
14
+ function buildTsdocConfig(tsdoc) {
15
+ const supportForTags = {};
16
+ for (const def of StandardTags.allDefinitions) supportForTags[def.tagName] = true;
17
+ const tagDefinitions = tsdoc.tagDefinitions.map((t) => ({
18
+ tagName: t.tagName,
19
+ syntaxKind: SYNTAX_KIND_MAP[t.syntaxKind],
20
+ ...t.allowMultiple !== void 0 ? { allowMultiple: t.allowMultiple } : {}
21
+ }));
22
+ for (const t of tagDefinitions) supportForTags[t.tagName] = true;
23
+ const config = {
24
+ $schema: TSDOC_SCHEMA,
25
+ noStandardTags: false,
26
+ reportUnsupportedHtmlElements: true,
27
+ supportForTags
28
+ };
29
+ if (tagDefinitions.length > 0) config.tagDefinitions = tagDefinitions;
30
+ return config;
31
+ }
32
+ /** Write tsdoc.json to `cwd`. Deterministic and idempotent: skips the write when the existing file is byte-equal to the computed config. Returns the path. */
33
+ function writeTsdocConfig(cwd, tsdoc) {
34
+ const path = join(cwd, "tsdoc.json");
35
+ const config = buildTsdocConfig({
36
+ suppressWarnings: tsdoc.suppressWarnings ?? [],
37
+ tagDefinitions: tsdoc.tagDefinitions ?? []
38
+ });
39
+ if (existsSync(path)) try {
40
+ const existing = JSON.parse(readFileSync(path, "utf-8"));
41
+ if (isDeepStrictEqual(existing, config)) return path;
42
+ } catch {}
43
+ writeFileSync(path, `${JSON.stringify(config, null, " ")}\n`, "utf-8");
44
+ return path;
45
+ }
46
+
47
+ export { buildTsdocConfig, writeTsdocConfig };
@@ -0,0 +1,22 @@
1
+ // src/meta/tsdoctor-config.ts
2
+ /**
3
+ * The options the meta pass takes, from the decoded `[package.tsdoctor]` table. The table names a renderer, and the
4
+ * caller passes the generator it resolved to; a table that asks for none needs none.
5
+ */
6
+ function tsdoctorMetaOptionsOf(config, generate) {
7
+ const { name, tagline, description, registries, openGraph } = config;
8
+ return {
9
+ ...name !== void 0 ? { name } : {},
10
+ ...tagline !== void 0 ? { tagline } : {},
11
+ ...description !== void 0 ? { description } : {},
12
+ ...registries !== void 0 ? { registries: registries === false ? false : registries.map((r) => ({ ...r })) } : {},
13
+ ...openGraph !== void 0 ? { openGraph: {
14
+ ...openGraph.images !== void 0 ? { images: openGraph.images.map((image) => ({ ...image })) } : {},
15
+ ...openGraph.themeColor !== void 0 ? { themeColor: openGraph.themeColor } : {},
16
+ ...openGraph.cacheSalt !== void 0 ? { cacheSalt: openGraph.cacheSalt } : {},
17
+ ...generate !== void 0 ? { generate } : {}
18
+ } } : {}
19
+ };
20
+ }
21
+
22
+ export { tsdoctorMetaOptionsOf };