@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.
- package/Bundler.js +450 -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 +261 -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 +427 -0
- package/config/EffectedConfigFile.js +160 -0
- package/config/merge.js +20 -0
- package/config/plugins.js +84 -0
- package/config-validation/ConfigValidator.js +67 -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 +3919 -0
- package/index.js +58 -0
- package/internal/causeMessage.js +57 -0
- package/journal/BuildJournal.js +108 -0
- package/jsx/config.js +51 -0
- package/manifest/emit-manifest.js +88 -0
- package/manifest/export-patterns.js +58 -0
- package/manifest/transform.js +323 -0
- package/meta/BundleManifest.js +208 -0
- package/meta/ManifestSource.js +37 -0
- package/meta/api-extractor.js +241 -0
- package/meta/config.js +24 -0
- package/meta/generate.js +246 -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 +117 -0
- package/meta/scrub-declaration-maps.js +63 -0
- package/meta/tsconfig-resolver.js +55 -0
- package/meta/tsdoc-config.js +47 -0
- package/meta/tsdoctor-config.js +22 -0
- package/meta/tsdoctor-manifest.js +134 -0
- package/meta/tsdoctor-source.js +94 -0
- package/package.json +85 -5
- package/passes/build-target-groups.js +346 -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 +39 -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 +155 -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 +18 -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,323 @@
|
|
|
1
|
+
import { ambientOutName, classifyDtsExport, mixedDtsExportError } from "../entries/ambient-dts.js";
|
|
2
|
+
import { createEntryName, resolveToTypeScript } from "../entries/extract.js";
|
|
3
|
+
import { ConfigValidationError } from "../errors.js";
|
|
4
|
+
import { PackageJsonFormat } from "@effected/package-json";
|
|
5
|
+
|
|
6
|
+
// src/manifest/transform.ts
|
|
7
|
+
const isDualKey = (dual, exportKey) => typeof dual === "boolean" ? dual : dual.has(exportKey);
|
|
8
|
+
/**
|
|
9
|
+
* Package.json fields that are never wanted in a published manifest: they describe
|
|
10
|
+
* how the package is BUILT/DEVELOPED, not how it is CONSUMED. The bundler reads
|
|
11
|
+
* everything it needs from the source manifest before transforms run (entry
|
|
12
|
+
* detection, `publishConfig.targets` for the byte-variant groups, catalog
|
|
13
|
+
* resolution), so dropping these from the emitted manifest is always safe.
|
|
14
|
+
*/
|
|
15
|
+
const NON_PUBLISHED_FIELDS = [
|
|
16
|
+
"devDependencies",
|
|
17
|
+
"bundleDependencies",
|
|
18
|
+
"scripts",
|
|
19
|
+
"publishConfig",
|
|
20
|
+
"packageManager",
|
|
21
|
+
"devEngines"
|
|
22
|
+
];
|
|
23
|
+
/**
|
|
24
|
+
* The default `transform` applied to every package's manifest when its
|
|
25
|
+
* build config does not provide one of its own. Strips the build/dev-only
|
|
26
|
+
* fields in `NON_PUBLISHED_FIELDS` from the emitted package.json.
|
|
27
|
+
*
|
|
28
|
+
* This is the pattern nearly every package repeated by hand (inherited from
|
|
29
|
+
* rslib-builder); `defineBuild` now applies it automatically so a package needs a
|
|
30
|
+
* `transform` only when it has genuinely custom manifest work to do (e.g. silk
|
|
31
|
+
* promoting workspace deps to peerDependencies). A custom transform REPLACES this
|
|
32
|
+
* default — re-export it and call it from a custom transform to keep the stripping.
|
|
33
|
+
*
|
|
34
|
+
* `targetGroup` is accepted (so this is assignable wherever the full transform
|
|
35
|
+
* signature is expected) but unused; the strip is identical for every group.
|
|
36
|
+
*
|
|
37
|
+
* `options.drop` names further top-level keys (for example `dependencies`) to delete after the
|
|
38
|
+
* standard stripping.
|
|
39
|
+
*
|
|
40
|
+
* Pure: the supplied `pkg` is NOT mutated — a shallow copy with the fields removed
|
|
41
|
+
* is returned, so external callers invoking this from a custom transform keep their
|
|
42
|
+
* input intact.
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
function defaultManifestTransform({ pkg }, options = {}) {
|
|
46
|
+
const out = { ...pkg };
|
|
47
|
+
for (const field of NON_PUBLISHED_FIELDS) delete out[field];
|
|
48
|
+
for (const key of options.drop ?? []) delete out[key];
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
const stripLeadingDotSlash = (p) => p.startsWith("./") ? p.slice(2) : p;
|
|
52
|
+
const sameSource = (a, b) => stripLeadingDotSlash(a) === stripLeadingDotSlash(b);
|
|
53
|
+
/**
|
|
54
|
+
* Whether a target names the exe source, in source form or in the built form the entry pass resolves to it
|
|
55
|
+
* (`./dist/bin.js` for `./src/bin.ts`). The entry pass leaves both out of the JS build, so both must point at the SEA.
|
|
56
|
+
*/
|
|
57
|
+
const namesExeSource = (target, source) => sameSource(target, source) || sameSource(resolveToTypeScript(target), source);
|
|
58
|
+
/** The export-path ("./bin/<file>") and files-entry ("bin/<file>") forms for a SEA. */
|
|
59
|
+
const exeRelPath = (r) => {
|
|
60
|
+
const filesEntry = `${r.dir}/${r.fileName}`;
|
|
61
|
+
return {
|
|
62
|
+
exportPath: `./${filesEntry}`,
|
|
63
|
+
filesEntry
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
/** Rewrite exports values that equal the exe source to a plain SEA-path string. */
|
|
67
|
+
const rewriteExeExports = (exports, r) => {
|
|
68
|
+
const { exportPath } = exeRelPath(r);
|
|
69
|
+
if (typeof exports === "string") return namesExeSource(exports, r.source) ? exportPath : exports;
|
|
70
|
+
if (exports && typeof exports === "object") {
|
|
71
|
+
const out = {};
|
|
72
|
+
for (const [key, value] of Object.entries(exports)) out[key] = typeof value === "string" && namesExeSource(value, r.source) ? exportPath : value;
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
return exports;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Built .js output basename for an export, derived from the entry NAME (the basename
|
|
79
|
+
* the build actually emits) rather than the source path. The entry namer flattens
|
|
80
|
+
* nested subpaths to a dash-joined basename (e.g. `./commitlint` to `commitlint.js`,
|
|
81
|
+
* `./changesets/markdownlint` to `changesets-markdownlint.js`), so the declared path
|
|
82
|
+
* always matches the file tsdown emits. The build never sets exportsAsIndexes, so the
|
|
83
|
+
* manifest mirrors the flat (false) naming here.
|
|
84
|
+
*/
|
|
85
|
+
const toBuiltJs = (exportKey, subdirExports) => subdirExports?.has(exportKey) ? `./${createEntryName(exportKey, false)}/index.js` : `./${createEntryName(exportKey, false)}.js`;
|
|
86
|
+
const toBuiltDts = (exportKey, subdirExports) => toBuiltJs(exportKey, subdirExports).replace(/\.js$/, ".d.ts");
|
|
87
|
+
const toBuiltCjs = (exportKey, subdirExports) => toBuiltJs(exportKey, subdirExports).replace(/\.js$/, ".cjs");
|
|
88
|
+
const isDeclarationFile = (p) => p.endsWith(".d.ts") || p.endsWith(".d.cts") || p.endsWith(".d.mts");
|
|
89
|
+
const isTs = (p) => !isDeclarationFile(p) && (p.endsWith(".ts") || p.endsWith(".tsx"));
|
|
90
|
+
/**
|
|
91
|
+
* Whether the entry pass builds `p` into a JS entry: a TS source, or a `./dist/<name>.js` reference it resolves to
|
|
92
|
+
* `./src/<name>.ts` (see `resolveToTypeScript`). Either way the emitted file is named after the export KEY, so the
|
|
93
|
+
* manifest rewrites both forms to the same conditions.
|
|
94
|
+
*/
|
|
95
|
+
const isBuildSource = (p) => isTs(resolveToTypeScript(p));
|
|
96
|
+
/**
|
|
97
|
+
* Build the conditions object for a TS export target (adds require when dual-format). `emitDts`
|
|
98
|
+
* gates the `types` condition: when `false` (the build's dts pass was skipped, see issue #198),
|
|
99
|
+
* omitting `types` avoids pointing the published manifest at a declaration file that was never
|
|
100
|
+
* written. Defaults to `true` (current behavior, byte-identical).
|
|
101
|
+
*
|
|
102
|
+
* The trailing `default` condition mirrors the ESM artifact so `require(esm)` resolves on the
|
|
103
|
+
* Node range every published package supports (engines >=24.11.0): Node's require() matches
|
|
104
|
+
* `node`/`require`/`default` but never `import`, so an import-only map dies with
|
|
105
|
+
* ERR_PACKAGE_PATH_NOT_EXPORTED even where require(esm) works. Dual-format entries keep their
|
|
106
|
+
* dedicated CJS artifact under `require`, which wins over `default` by condition order.
|
|
107
|
+
*/
|
|
108
|
+
const tsConditions = (exportKey, dual, subdirExports, emitDts = true) => ({
|
|
109
|
+
...emitDts ? { types: toBuiltDts(exportKey, subdirExports) } : {},
|
|
110
|
+
import: toBuiltJs(exportKey, subdirExports),
|
|
111
|
+
...dual ? { require: toBuiltCjs(exportKey, subdirExports) } : {},
|
|
112
|
+
default: toBuiltJs(exportKey, subdirExports)
|
|
113
|
+
});
|
|
114
|
+
/**
|
|
115
|
+
* A `./public/<path>` export value points into the staged `public/` dir, whose CONTENTS `copyPublicDir`
|
|
116
|
+
* copies into the package root (only the `public/` segment is dropped; substructure is kept). So the
|
|
117
|
+
* published manifest value drops that same `public/` segment: `./public/tsconfig/ecma.json` becomes
|
|
118
|
+
* `./tsconfig/ecma.json`, resolving the file copyPublicDir placed at `<pkg>/tsconfig/ecma.json`.
|
|
119
|
+
* Non-strings and non-public values pass through unchanged.
|
|
120
|
+
*/
|
|
121
|
+
function stripPublicPrefix(value) {
|
|
122
|
+
return typeof value === "string" && value.startsWith("./public/") ? `./${value.slice(9)}` : value;
|
|
123
|
+
}
|
|
124
|
+
/** The conditions the entry pass reads a source from, in its order (`resolveSourcePath` in `entries/extract.ts`). */
|
|
125
|
+
const ENTRY_SOURCE_CONDITIONS = [
|
|
126
|
+
"import",
|
|
127
|
+
"default",
|
|
128
|
+
"types"
|
|
129
|
+
];
|
|
130
|
+
/** Every string target under an export value, at any depth. */
|
|
131
|
+
const stringTargets = (value) => typeof value === "string" ? [value] : value !== null && typeof value === "object" ? Object.values(value).flatMap(stringTargets) : [];
|
|
132
|
+
/** Whether `value`, at any depth, holds a build source (a TS source or a `./dist/*.js` reference). */
|
|
133
|
+
const holdsTsSource = (value) => stringTargets(value).some(isBuildSource);
|
|
134
|
+
const conditionObjectError = (exportKey, reason) => new ConfigValidationError({
|
|
135
|
+
path: `exports."${exportKey}"`,
|
|
136
|
+
reason
|
|
137
|
+
});
|
|
138
|
+
/**
|
|
139
|
+
* The TS source a condition-object export value names, when it names one the manifest can rewrite;
|
|
140
|
+
* `undefined` when it holds no TS source at all (it passes through as authored).
|
|
141
|
+
*
|
|
142
|
+
* The entry pass builds a condition object from ONE source, the first of `import`, `default` and
|
|
143
|
+
* `types` that is set, and names the output after the export KEY (`"./foo": { "import": "./src/foo.ts" }`
|
|
144
|
+
* emits `foo.js`). So a condition object whose every condition is one of those three, each naming that
|
|
145
|
+
* same TS source, maps unambiguously onto the export key's own conditions and is rewritten exactly as
|
|
146
|
+
* the bare-string form is. Any other shape holding a TS source is refused with a
|
|
147
|
+
* {@link ConfigValidationError} rather than rewritten, because the manifest would point at files the
|
|
148
|
+
* build never writes: two different sources (only the first is built), a condition the entry pass
|
|
149
|
+
* does not read (`node`, `browser`, `require`, ...; write the bare string and configure dual output
|
|
150
|
+
* instead of a hand-written `require`), or a nested condition object.
|
|
151
|
+
*/
|
|
152
|
+
const conditionObjectSource = (exportKey, value) => {
|
|
153
|
+
if (value === null || typeof value !== "object" || !holdsTsSource(value)) return void 0;
|
|
154
|
+
const conditions = value;
|
|
155
|
+
const sources = /* @__PURE__ */ new Set();
|
|
156
|
+
for (const [condition, target] of Object.entries(conditions)) {
|
|
157
|
+
if (!ENTRY_SOURCE_CONDITIONS.includes(condition) || typeof target !== "string") throw conditionObjectError(exportKey, `a condition object holding a TypeScript source may use only flat ${ENTRY_SOURCE_CONDITIONS.join("/")} conditions; "${condition}" is not one the build reads its entry from`);
|
|
158
|
+
sources.add(target);
|
|
159
|
+
}
|
|
160
|
+
const [source] = sources;
|
|
161
|
+
if (sources.size !== 1 || typeof source !== "string" || !isBuildSource(source)) throw conditionObjectError(exportKey, "every condition of a condition object holding a TypeScript source must name that one source; the build emits one entry per export key");
|
|
162
|
+
return source;
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Refuse a build source holding a `*`. The entry pass builds one entry per export key from one literal source path,
|
|
166
|
+
* so a pattern such as `./dist/*.js` or `./src/*.ts` names no file it can build, and the files a consumer would
|
|
167
|
+
* resolve through it are never written. A `*` in the export KEY over a literal build source is refused too: the output
|
|
168
|
+
* is named after the key, so it would be named with the `*` in it.
|
|
169
|
+
*/
|
|
170
|
+
const assertNoWildcardSource = (exportKey, value) => {
|
|
171
|
+
const targets = stringTargets(value);
|
|
172
|
+
const pattern = targets.find((target) => target.includes("*") && isBuildSource(target));
|
|
173
|
+
if (pattern !== void 0) throw conditionObjectError(exportKey, `"${pattern}" is a pattern over build sources; the build emits one entry per export key from one source, so list each subpath with its own source`);
|
|
174
|
+
const source = exportKey.includes("*") ? targets.find(isBuildSource) : void 0;
|
|
175
|
+
if (source !== void 0) throw conditionObjectError(exportKey, `a pattern export key cannot name the build source "${source}"; the build names each entry's output after its key, so give the subpath a literal key`);
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Refuse, before any build work, every subpath export {@link transformExports} would refuse as an
|
|
179
|
+
* unbuildable condition object (see {@link conditionObjectSource}), every build source written as a
|
|
180
|
+
* `*` pattern, and, for an exe build, every condition object naming the exe source. `Bundler.build`
|
|
181
|
+
* calls it beside the ambient `.d.ts` validation, so the refusal is a {@link ConfigValidationError} up
|
|
182
|
+
* front rather than a throw from inside the JS pass's manifest plugin; the transform keeps its own
|
|
183
|
+
* throws as a backstop. Walks the same keys the transform rewrites, skipping `.json`/`.d.ts` keys and
|
|
184
|
+
* ambient exports; a mixed `.d.ts` export is left to `extractAmbientDts`, which runs first.
|
|
185
|
+
*
|
|
186
|
+
* The exe source is compiled into the SEA and left out of the JS pass, and only a bare-string export of
|
|
187
|
+
* it is rewritten to the binary's path, so a condition object naming it would point at JS the build
|
|
188
|
+
* never writes.
|
|
189
|
+
*
|
|
190
|
+
* @internal
|
|
191
|
+
*/
|
|
192
|
+
function assertBuildableConditionExports(exports, options = {}) {
|
|
193
|
+
if (exports === null || typeof exports !== "object") return;
|
|
194
|
+
const { exeSource } = options;
|
|
195
|
+
for (const [key, value] of Object.entries(exports)) {
|
|
196
|
+
if (key === "./package.json" || key.endsWith(".json") || isDeclarationFile(key)) continue;
|
|
197
|
+
if (exeSource !== void 0 && value !== null && typeof value === "object" && stringTargets(value).some((target) => namesExeSource(target, exeSource))) throw conditionObjectError(key, `the exe source "${exeSource}" is compiled into the binary, not a JS entry; export it as a bare string so the manifest points at the binary`);
|
|
198
|
+
if (classifyDtsExport(value).kind !== "none") continue;
|
|
199
|
+
assertNoWildcardSource(key, value);
|
|
200
|
+
conditionObjectSource(key, value);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Rewrite an exports map: TS string targets become a types/import conditions object.
|
|
205
|
+
* Each TS condition also gets a `require` entry when `dual` is `true` (uniform) or when
|
|
206
|
+
* the export key is in the `dual` Set (per-entry).
|
|
207
|
+
*
|
|
208
|
+
* The output path is derived from the export KEY via the shared entry-name function,
|
|
209
|
+
* never from the source path, so the manifest target always matches the emitted file.
|
|
210
|
+
*
|
|
211
|
+
* Export keys in `subdirExports` are built into an isolated `<key>/index.*` subdir (e.g. an
|
|
212
|
+
* RSPress `./runtime`), so their conditions gain an `/index` segment.
|
|
213
|
+
*
|
|
214
|
+
* `emitDts` gates the `types` condition on every GENERATED (non-ambient) TS export: pass `false`
|
|
215
|
+
* when the build's dts pass was skipped (issue #198) so the manifest does not point at a `.d.ts`
|
|
216
|
+
* that was never written. Defaults to `true`. Ambient `.d.ts` exports (hand-authored, copied
|
|
217
|
+
* verbatim regardless of the dts pass) are unaffected — their `types` condition is always kept.
|
|
218
|
+
*
|
|
219
|
+
* A condition-object value whose flat `import`/`default`/`types` conditions all name one TS source
|
|
220
|
+
* (`"./foo": { "import": "./src/foo.ts" }`) is rewritten like the bare string, named after the export
|
|
221
|
+
* key as the entry pass names it. Any other condition object holding a TS source throws
|
|
222
|
+
* {@link ConfigValidationError}, since its targets would never be built; one holding none passes
|
|
223
|
+
* through as authored.
|
|
224
|
+
*
|
|
225
|
+
* A subpath target written as the built path, `./dist/foo.js`, is a build source too: the entry pass
|
|
226
|
+
* builds it from `./src/foo.ts` and names the output after the export key, so it is rewritten exactly
|
|
227
|
+
* as `./src/foo.ts` would be. A build source holding a `*` (`./dist/*.js`, `./src/*.ts`) throws
|
|
228
|
+
* {@link ConfigValidationError}, since the build emits one entry per key from one literal source.
|
|
229
|
+
* @public
|
|
230
|
+
*/
|
|
231
|
+
function transformExports(exports, dual = false, subdirExports, emitDts = true) {
|
|
232
|
+
if (typeof exports === "string") return isTs(exports) ? tsConditions(".", isDualKey(dual, "."), subdirExports, emitDts) : stripPublicPrefix(exports);
|
|
233
|
+
if (exports && typeof exports === "object") {
|
|
234
|
+
const out = {};
|
|
235
|
+
for (const [key, value] of Object.entries(exports)) {
|
|
236
|
+
if (key === "./package.json" || key.endsWith(".json") || isDeclarationFile(key)) {
|
|
237
|
+
out[key] = stripPublicPrefix(value);
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const cls = classifyDtsExport(value);
|
|
241
|
+
if (cls.kind === "mixed") throw mixedDtsExportError(key, value);
|
|
242
|
+
if (cls.kind === "ambient") {
|
|
243
|
+
out[key] = { types: `./${ambientOutName(key, cls.source)}` };
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
assertNoWildcardSource(key, value);
|
|
247
|
+
if (typeof value === "string" && isBuildSource(value) || conditionObjectSource(key, value) !== void 0) out[key] = tsConditions(key, isDualKey(dual, key), subdirExports, emitDts);
|
|
248
|
+
else out[key] = transformExports(value, dual, subdirExports, emitDts);
|
|
249
|
+
}
|
|
250
|
+
return out;
|
|
251
|
+
}
|
|
252
|
+
return exports;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Rewrite bin: TS targets, and `./dist/*.js` targets the entry pass builds from `./src/*.ts`, to
|
|
256
|
+
* bin/[command].js (string to bin/cli.js); strip leading ./ otherwise.
|
|
257
|
+
*
|
|
258
|
+
* @public
|
|
259
|
+
*/
|
|
260
|
+
function transformBin(bin) {
|
|
261
|
+
if (typeof bin === "string") return isBuildSource(bin) ? "bin/cli.js" : stripLeadingDotSlash(bin);
|
|
262
|
+
if (bin && typeof bin === "object") {
|
|
263
|
+
const out = {};
|
|
264
|
+
for (const [command, p] of Object.entries(bin)) out[command] = isBuildSource(p) ? `bin/${command}.js` : stripLeadingDotSlash(p);
|
|
265
|
+
return out;
|
|
266
|
+
}
|
|
267
|
+
return bin;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* FINAL guard: strip leading ./ from bin paths (npm 11.x drops ./-prefixed bins).
|
|
271
|
+
*
|
|
272
|
+
* @public
|
|
273
|
+
*/
|
|
274
|
+
function normalizeBinPaths(bin) {
|
|
275
|
+
if (typeof bin === "string") return stripLeadingDotSlash(bin);
|
|
276
|
+
if (bin && typeof bin === "object") {
|
|
277
|
+
const out = {};
|
|
278
|
+
for (const [command, p] of Object.entries(bin)) out[command] = stripLeadingDotSlash(p);
|
|
279
|
+
return out;
|
|
280
|
+
}
|
|
281
|
+
return bin;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Apply the full standard manifest transform (excluding catalog resolution, done upstream).
|
|
285
|
+
*
|
|
286
|
+
* @public
|
|
287
|
+
*/
|
|
288
|
+
function transformManifest(pkg, options = {}) {
|
|
289
|
+
const { publishConfig, scripts, ...rest } = pkg;
|
|
290
|
+
const isPrivate = !(publishConfig?.access === "public");
|
|
291
|
+
let result = {
|
|
292
|
+
...rest,
|
|
293
|
+
private: isPrivate
|
|
294
|
+
};
|
|
295
|
+
if (options.exeRewrite) {
|
|
296
|
+
const r = options.exeRewrite;
|
|
297
|
+
const { exportPath, filesEntry } = exeRelPath(r);
|
|
298
|
+
if (result.exports !== void 0 && result.exports !== null) result.exports = rewriteExeExports(result.exports, r);
|
|
299
|
+
if (typeof result.bin === "string") {
|
|
300
|
+
if (namesExeSource(result.bin, r.source)) result.bin = exportPath;
|
|
301
|
+
} else if (result.bin && typeof result.bin === "object") {
|
|
302
|
+
const nextBin = {};
|
|
303
|
+
for (const [cmd, val] of Object.entries(result.bin)) nextBin[cmd] = namesExeSource(val, r.source) ? exportPath : val;
|
|
304
|
+
result.bin = nextBin;
|
|
305
|
+
}
|
|
306
|
+
const files = Array.isArray(result.files) ? result.files.slice() : [];
|
|
307
|
+
if (!files.includes(filesEntry)) files.push(filesEntry);
|
|
308
|
+
result.files = files;
|
|
309
|
+
}
|
|
310
|
+
if (result.exports !== void 0 && result.exports !== null) {
|
|
311
|
+
const original = result.exports;
|
|
312
|
+
const transformed = transformExports(original, options.dual ?? false, options.subdirExports, options.emitDts ?? true);
|
|
313
|
+
const asMap = typeof original === "string" ? { ".": transformed } : { ...transformed };
|
|
314
|
+
if (!("./package.json" in asMap)) asMap["./package.json"] = "./package.json";
|
|
315
|
+
result.exports = asMap;
|
|
316
|
+
}
|
|
317
|
+
if (result.bin) result.bin = transformBin(result.bin);
|
|
318
|
+
if (options.transform) result = options.transform(result);
|
|
319
|
+
if (result.bin) result.bin = normalizeBinPaths(result.bin);
|
|
320
|
+
return PackageJsonFormat.sortValue(result);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export { assertBuildableConditionExports, defaultManifestTransform, normalizeBinPaths, transformBin, transformExports, transformManifest };
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
// src/meta/BundleManifest.ts
|
|
4
|
+
/**
|
|
5
|
+
* The registry protocol families this reader knows how to do more than link
|
|
6
|
+
* to. `"npm"` means an npm-compatible registry — install commands and tarball
|
|
7
|
+
* fetching work against any instance of it — and `"jsr"` the jsr protocol.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* The manifest's `type` field is deliberately NOT constrained to these
|
|
11
|
+
* values: unknown future types must degrade to link-only rendering, not
|
|
12
|
+
* reject the manifest. Use {@link isKnownRegistryType} to branch.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
const KNOWN_REGISTRY_TYPES = ["npm", "jsr"];
|
|
17
|
+
/**
|
|
18
|
+
* Whether a registry `type` value is a protocol family this reader
|
|
19
|
+
* recognizes. `false` means the registry entry should degrade to link-only
|
|
20
|
+
* rendering — it is never a validation failure.
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
function isKnownRegistryType(type) {
|
|
25
|
+
return KNOWN_REGISTRY_TYPES.includes(type);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* One registry the documented package is published to.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* `type` is the PROTOCOL FAMILY (`"npm"` covers every npm-compatible
|
|
32
|
+
* registry), `name` the human instance label, `url` the package's page on
|
|
33
|
+
* that instance. Unknown `type` values decode successfully and degrade to
|
|
34
|
+
* link-only rendering (see {@link isKnownRegistryType}).
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
const RegistryRef = Schema.Struct({
|
|
39
|
+
/** The protocol family, e.g. `"npm"` or `"jsr"`. Unknown values are accepted. */
|
|
40
|
+
type: Schema.String,
|
|
41
|
+
/** The human instance label, e.g. `"npm"` or `"Savvy Web Registry"`. */
|
|
42
|
+
name: Schema.String,
|
|
43
|
+
/** The package's URL on that registry instance. */
|
|
44
|
+
url: Schema.String
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* One Open Graph image declared by the manifest.
|
|
48
|
+
*
|
|
49
|
+
* @remarks
|
|
50
|
+
* Exactly ONE of `path` (a bundle-relative asset the consuming platform
|
|
51
|
+
* publishes and resolves to a URL) or `url` (an absolute external URL used
|
|
52
|
+
* verbatim) must be present — the schema enforces the XOR. `type` is a MIME
|
|
53
|
+
* type, inferred from the file extension by the resolver when omitted; `alt`
|
|
54
|
+
* has a documented inference chain (tagline → description →
|
|
55
|
+
* `"<name> API documentation"`).
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
const OpenGraphImage = Schema.Struct({
|
|
60
|
+
/** Bundle-relative asset path. Mutually exclusive with `url`. */
|
|
61
|
+
path: Schema.optionalKey(Schema.String),
|
|
62
|
+
/** Absolute external URL, used verbatim. Mutually exclusive with `path`. */
|
|
63
|
+
url: Schema.optionalKey(Schema.String),
|
|
64
|
+
/** MIME type; inferred from the extension when omitted. */
|
|
65
|
+
type: Schema.optionalKey(Schema.String),
|
|
66
|
+
/** Pixel width; 1200×630 (1.91:1) is the cross-platform safe default. */
|
|
67
|
+
width: Schema.optionalKey(Schema.Int),
|
|
68
|
+
/** Pixel height. */
|
|
69
|
+
height: Schema.optionalKey(Schema.Int),
|
|
70
|
+
/** Alt text; inferred (tagline → description → fallback) when omitted. */
|
|
71
|
+
alt: Schema.optionalKey(Schema.String)
|
|
72
|
+
}).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" }));
|
|
73
|
+
/**
|
|
74
|
+
* The manifest's Open Graph block: the asset-ish pieces only — most OG tags
|
|
75
|
+
* are page-level and derive at render time in the consuming platform.
|
|
76
|
+
*
|
|
77
|
+
* @remarks
|
|
78
|
+
* Multiple images follow OG array semantics: the first declared wins, extras
|
|
79
|
+
* are alternates (e.g. a portrait 1000×1500 variant).
|
|
80
|
+
*
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
const OpenGraphConfig = Schema.Struct({
|
|
84
|
+
/** Declared images, first-wins per OG array semantics. */
|
|
85
|
+
images: Schema.optionalKey(Schema.Array(OpenGraphImage)),
|
|
86
|
+
/** Embed accent color (e.g. Discord), a CSS color string. */
|
|
87
|
+
themeColor: Schema.optionalKey(Schema.String)
|
|
88
|
+
});
|
|
89
|
+
/**
|
|
90
|
+
* A pointer to the bundle's SBOM, computed by the bundler at publish and
|
|
91
|
+
* served as a downloadable static asset.
|
|
92
|
+
*
|
|
93
|
+
* @public
|
|
94
|
+
*/
|
|
95
|
+
const SbomRef = Schema.Struct({
|
|
96
|
+
/** Bundle-relative path to the SBOM file. */
|
|
97
|
+
path: Schema.String,
|
|
98
|
+
/** SBOM format label, e.g. `"spdx-json"`. Unknown values are accepted. */
|
|
99
|
+
format: Schema.optionalKey(Schema.String)
|
|
100
|
+
});
|
|
101
|
+
/**
|
|
102
|
+
* The inherited project tier, flattened into the emitted manifest by the
|
|
103
|
+
* bundler (a fetched bundle has no parent directory to walk). Kept nested —
|
|
104
|
+
* structurally distinguishable from the leaf fields — because provenance is
|
|
105
|
+
* load-bearing for override detection.
|
|
106
|
+
*
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
const ProjectIdentity = Schema.Struct({
|
|
110
|
+
/** The project display name, e.g. `"Effected"` over leaf `@effected/store`. */
|
|
111
|
+
name: Schema.optionalKey(Schema.String),
|
|
112
|
+
/** The project tagline. */
|
|
113
|
+
tagline: Schema.optionalKey(Schema.String)
|
|
114
|
+
});
|
|
115
|
+
/**
|
|
116
|
+
* The versioned `tsdoctor.json` sidecar manifest — bundle layer 3.
|
|
117
|
+
*
|
|
118
|
+
* @remarks
|
|
119
|
+
* `spec` is the only required field; every other field enriches. Unknown
|
|
120
|
+
* top-level fields are ignored on decode (additive fields are minor spec
|
|
121
|
+
* revisions) and unknown enum-ish values (registry `type`, sbom `format`)
|
|
122
|
+
* degrade gracefully instead of rejecting — an old reader must be able to
|
|
123
|
+
* consume a new bundle.
|
|
124
|
+
*
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
const BundleManifest = Schema.Struct({
|
|
128
|
+
/** The integer spec version. This reader understands spec 1. */
|
|
129
|
+
spec: Schema.Literal(1),
|
|
130
|
+
/** Human display name (the npm name is dry; this one is SEO-friendly). */
|
|
131
|
+
name: Schema.optionalKey(Schema.String),
|
|
132
|
+
/** Short tagline. */
|
|
133
|
+
tagline: Schema.optionalKey(Schema.String),
|
|
134
|
+
/** Long description; overrides the package.json description when present. */
|
|
135
|
+
description: Schema.optionalKey(Schema.String),
|
|
136
|
+
/** The inherited project tier, flattened in at emit time. */
|
|
137
|
+
project: Schema.optionalKey(ProjectIdentity),
|
|
138
|
+
/** Open Graph assets. */
|
|
139
|
+
openGraph: Schema.optionalKey(OpenGraphConfig),
|
|
140
|
+
/** SBOM pointer. */
|
|
141
|
+
sbom: Schema.optionalKey(SbomRef),
|
|
142
|
+
/** Registries the package is published to. */
|
|
143
|
+
registries: Schema.optionalKey(Schema.Array(RegistryRef))
|
|
144
|
+
});
|
|
145
|
+
/**
|
|
146
|
+
* Raised when a present `tsdoctor.json` cannot be parsed or does not satisfy
|
|
147
|
+
* the {@link (BundleManifest:variable)} schema.
|
|
148
|
+
*
|
|
149
|
+
* @remarks
|
|
150
|
+
* Absence of the manifest is NEVER this error — layers enrich, never gate,
|
|
151
|
+
* so a missing sidecar is the normal case and reads as `Option.none()`.
|
|
152
|
+
*
|
|
153
|
+
* @public
|
|
154
|
+
*/
|
|
155
|
+
var BundleManifestError = class extends Schema.TaggedError()("BundleManifestError", {
|
|
156
|
+
/** The manifest file path, when the failure is tied to a file on disk. */
|
|
157
|
+
path: Schema.optionalKey(Schema.String),
|
|
158
|
+
/** The underlying failure (JSON syntax or schema decode), preserved structurally. */
|
|
159
|
+
cause: Schema.Defect()
|
|
160
|
+
}) {
|
|
161
|
+
get message() {
|
|
162
|
+
return `Invalid tsdoctor.json manifest${this.path !== void 0 ? ` at ${this.path}` : ""}`;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* Decode an unknown value into a {@link (BundleManifest:type)}.
|
|
167
|
+
*
|
|
168
|
+
* @remarks
|
|
169
|
+
* The typed boundary for manifest input that has already been parsed from
|
|
170
|
+
* JSON (plugin options, fetched payloads). File-based reading lives in
|
|
171
|
+
* `readBundle`, which routes through this after parsing.
|
|
172
|
+
*
|
|
173
|
+
* @public
|
|
174
|
+
*/
|
|
175
|
+
function decodeBundleManifest(input, path) {
|
|
176
|
+
return Schema.decodeUnknownEffect(BundleManifest)(input).pipe(Effect.mapError((cause) => new BundleManifestError({
|
|
177
|
+
...path !== void 0 ? { path } : {},
|
|
178
|
+
cause
|
|
179
|
+
})));
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The manifest spec version this package reads and writes.
|
|
183
|
+
*
|
|
184
|
+
* @public
|
|
185
|
+
*/
|
|
186
|
+
const MANIFEST_SPEC = 1;
|
|
187
|
+
/**
|
|
188
|
+
* The sidecar manifest's file name inside a bundle folder.
|
|
189
|
+
*
|
|
190
|
+
* @public
|
|
191
|
+
*/
|
|
192
|
+
const TSDOCTOR_MANIFEST_FILENAME = "tsdoctor.json";
|
|
193
|
+
/**
|
|
194
|
+
* Encode a {@link (BundleManifest:type)} into the JSON-ready value a writer
|
|
195
|
+
* serializes as `tsdoctor.json`.
|
|
196
|
+
*
|
|
197
|
+
* @remarks
|
|
198
|
+
* The writer's boundary. Going through the schema rather than
|
|
199
|
+
* `JSON.stringify` means an emitted file is by construction what
|
|
200
|
+
* {@link decodeBundleManifest} accepts.
|
|
201
|
+
*
|
|
202
|
+
* @public
|
|
203
|
+
*/
|
|
204
|
+
function encodeBundleManifest(manifest) {
|
|
205
|
+
return Schema.encodeEffect(BundleManifest)(manifest).pipe(Effect.mapError((cause) => new BundleManifestError({ cause })));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export { BundleManifest, BundleManifestError, KNOWN_REGISTRY_TYPES, MANIFEST_SPEC, OpenGraphConfig, OpenGraphImage, ProjectIdentity, RegistryRef, SbomRef, TSDOCTOR_MANIFEST_FILENAME, decodeBundleManifest, encodeBundleManifest, isKnownRegistryType };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BundleManifest, BundleManifestError } from "./BundleManifest.js";
|
|
2
|
+
import { Effect, Schema } from "effect";
|
|
3
|
+
|
|
4
|
+
// src/meta/ManifestSource.ts
|
|
5
|
+
/**
|
|
6
|
+
* The shape an author checks in as a `tsdoctor.json` SOURCE file, at a
|
|
7
|
+
* package root (the leaf tier) or a workspace root (the project tier).
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* `BundleManifest` minus `spec` and `project`: a source file never declares
|
|
11
|
+
* its own spec version, and it never declares its inherited tier — the
|
|
12
|
+
* bundler supplies both when it flattens the hierarchy at emit time. Decoded
|
|
13
|
+
* only by writers; readers never see this shape.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
const ManifestSource = Schema.Struct({
|
|
18
|
+
name: BundleManifest.fields.name,
|
|
19
|
+
tagline: BundleManifest.fields.tagline,
|
|
20
|
+
description: BundleManifest.fields.description,
|
|
21
|
+
openGraph: BundleManifest.fields.openGraph,
|
|
22
|
+
sbom: BundleManifest.fields.sbom,
|
|
23
|
+
registries: BundleManifest.fields.registries
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* Decode an unknown value into a {@link (ManifestSource:type)}.
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
function decodeManifestSource(input, path) {
|
|
31
|
+
return Schema.decodeUnknownEffect(ManifestSource)(input).pipe(Effect.mapError((cause) => new BundleManifestError({
|
|
32
|
+
...path !== void 0 ? { path } : {},
|
|
33
|
+
cause
|
|
34
|
+
})));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { ManifestSource, decodeManifestSource };
|