@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,241 @@
|
|
|
1
|
+
import { MetaGenerationError } from "../errors.js";
|
|
2
|
+
import { tsconfigSyncOptions } from "../tsconfig/sync-options.js";
|
|
3
|
+
import { createMessageSuppressor } from "./message-suppressor.js";
|
|
4
|
+
import { existsSync, realpathSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
import { TsconfigLoaderSync } from "@effected/tsconfig-json";
|
|
9
|
+
import { Extractor, ExtractorConfig, ExtractorLogLevel } from "@microsoft/api-extractor";
|
|
10
|
+
import { TSDocConfigFile } from "@microsoft/tsdoc-config";
|
|
11
|
+
|
|
12
|
+
// src/meta/api-extractor.ts
|
|
13
|
+
/** messageIds that become a hard build error in CI (they corrupt the .api.json). */
|
|
14
|
+
const CI_FATAL_MESSAGE_IDS = /* @__PURE__ */ new Set(["ae-forgotten-export"]);
|
|
15
|
+
/**
|
|
16
|
+
* Derive the extractor-scoped tsconfig for ONE api-extractor run and return its path (#354).
|
|
17
|
+
*
|
|
18
|
+
* The compile tsconfig's `include` covers `src/**` — necessary for the dts-emit pass, poison for
|
|
19
|
+
* the extractor: a hand-authored `src/*.d.ts` shim matched by that glob survives api-extractor's
|
|
20
|
+
* .d.ts root filter, and a self-name import inside it resolves through the SOURCE manifest's
|
|
21
|
+
* `exports` to raw `.ts` sources under `src/`, putting non-declaration files in the Program and
|
|
22
|
+
* firing an unsuppressable `ae-wrong-input-file-type` on every build. The derived config keeps the
|
|
23
|
+
* base's `compilerOptions` (via an absolute-path `extends`) but replaces the input set with exactly
|
|
24
|
+
* what the extractor's Program should hold: the entry `.d.ts` (`files`) plus the `types/*.d.ts`
|
|
25
|
+
* legacy typings — the same effective roots as before minus everything under `src/`.
|
|
26
|
+
*
|
|
27
|
+
* The same failure class has a second route (#771): a self-name import (`import type * as Root from
|
|
28
|
+
* "@scope/pkg"`) inside an emitted per-module `.d.ts` resolves, from a declarations tree with no
|
|
29
|
+
* package.json, via TS package self-reference through the SOURCE manifest's `exports` into raw `.ts`
|
|
30
|
+
* (`ae-wrong-input-file-type`, or an `Unable to follow symbol` crash). Run B therefore supplies `paths`
|
|
31
|
+
* mapping each own export specifier to its declarations file, which wins over self-reference.
|
|
32
|
+
*
|
|
33
|
+
* Best-effort, mirroring `writeDtsEmitTsconfig`: a base that does not exist (e.g. a synthetic test
|
|
34
|
+
* path) gets no variant — the original path is returned unchanged. The filename is deterministic
|
|
35
|
+
* per (pid, base, entry) via a content hash (the two joined paths overflow a filename), so repeated
|
|
36
|
+
* calls within a process overwrite the same file; cross-process temp files are left for the OS to
|
|
37
|
+
* reap, consistent with the other tmpdir tsconfig writers.
|
|
38
|
+
*/
|
|
39
|
+
function writeApiExtractorTsconfig(options) {
|
|
40
|
+
const absBase = isAbsolute(options.tsconfigPath) ? options.tsconfigPath : resolve(options.tsconfigPath);
|
|
41
|
+
if (!existsSync(absBase)) return options.tsconfigPath;
|
|
42
|
+
const entryDts = isAbsolute(options.entryDtsPath) ? options.entryDtsPath : resolve(options.cwd, options.entryDtsPath);
|
|
43
|
+
const ownPaths = options.paths ?? {};
|
|
44
|
+
const hasPaths = Object.keys(ownPaths).length > 0;
|
|
45
|
+
const cfg = {
|
|
46
|
+
extends: absBase,
|
|
47
|
+
files: [entryDts],
|
|
48
|
+
include: [join(options.cwd, "types/*.d.ts")],
|
|
49
|
+
...hasPaths ? { compilerOptions: { paths: {
|
|
50
|
+
...readBasePaths(absBase),
|
|
51
|
+
...ownPaths
|
|
52
|
+
} } } : {}
|
|
53
|
+
};
|
|
54
|
+
const hash = createHash("sha256").update(`${absBase}\0${entryDts}${hasPaths ? `\0${JSON.stringify(ownPaths)}` : ""}`).digest("hex").slice(0, 16);
|
|
55
|
+
const path = join(tmpdir(), `tsconfig-api-extractor-${process.pid}-${hash}.json`);
|
|
56
|
+
writeFileSync(path, `${JSON.stringify(cfg, null, " ")}\n`, "utf-8");
|
|
57
|
+
return path;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The base tsconfig's effective `compilerOptions.paths`, with every relative target made absolute.
|
|
61
|
+
*
|
|
62
|
+
* A `compilerOptions.paths` in the derived config replaces the inherited one wholesale, so the base's
|
|
63
|
+
* mappings must be re-emitted, and they must keep resolving where they did. TypeScript resolves a
|
|
64
|
+
* relative target against `baseUrl` when one is in effect, and otherwise against the directory of the
|
|
65
|
+
* config that declared `paths`. Re-emitted verbatim from the derived config in the tmpdir, a target such
|
|
66
|
+
* as `./src/*` would resolve under the tmpdir instead. The chain is resolved with the same tsc-parity
|
|
67
|
+
* loader the portable-tsconfig resolver uses (`extends`, JSONC, an absolutized `baseUrl`, `pathsBase`),
|
|
68
|
+
* so `paths` inherited from further up the chain are kept too. Best-effort: a base that cannot be
|
|
69
|
+
* resolved contributes no paths.
|
|
70
|
+
*/
|
|
71
|
+
function readBasePaths(absBase) {
|
|
72
|
+
let resolved;
|
|
73
|
+
try {
|
|
74
|
+
resolved = TsconfigLoaderSync.resolve(absBase, tsconfigSyncOptions);
|
|
75
|
+
} catch {
|
|
76
|
+
return {};
|
|
77
|
+
}
|
|
78
|
+
const paths = resolved.compilerOptions.paths;
|
|
79
|
+
if (paths === void 0) return {};
|
|
80
|
+
const anchor = resolved.compilerOptions.baseUrl ?? resolved.pathsBase ?? dirname(absBase);
|
|
81
|
+
return Object.fromEntries(Object.entries(paths).map(([key, targets]) => [key, targets.map((target) => isAbsolute(target) ? target : resolve(anchor, target))]));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Map an API Extractor message to a collector DiagnosticInput, or undefined if not warn/error.
|
|
85
|
+
*
|
|
86
|
+
* Location (`file`/`line`/`column`) is preserved: diagnostics now come from a per-module declaration
|
|
87
|
+
* run (see generateMeta's two-input split), where each `.d.ts.map` references only its own source, so
|
|
88
|
+
* positions resolve to the true source declaration. Reverts the systems#154 mitigation. See systems#162.
|
|
89
|
+
*/
|
|
90
|
+
function mapExtractorMessage(message) {
|
|
91
|
+
const isError = message.logLevel === ExtractorLogLevel.Error;
|
|
92
|
+
const isWarning = message.logLevel === ExtractorLogLevel.Warning;
|
|
93
|
+
if (!isError && !isWarning) return void 0;
|
|
94
|
+
return {
|
|
95
|
+
source: "api-extractor",
|
|
96
|
+
level: isError ? "error" : "warn",
|
|
97
|
+
text: message.text,
|
|
98
|
+
...message.messageId !== void 0 ? { code: message.messageId } : {},
|
|
99
|
+
...message.sourceFilePath !== void 0 ? { file: message.sourceFilePath } : {},
|
|
100
|
+
...message.sourceFileLine !== void 0 ? { line: message.sourceFileLine } : {},
|
|
101
|
+
...message.sourceFileColumn !== void 0 ? { column: message.sourceFileColumn } : {}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* A path with its symlinks resolved. A tail that does not exist is kept on its deepest ancestor that does, so a missing
|
|
106
|
+
* file cannot read as outside a package whose own path resolved through a link.
|
|
107
|
+
*/
|
|
108
|
+
const canonicalPath = (path) => {
|
|
109
|
+
try {
|
|
110
|
+
return realpathSync.native(path);
|
|
111
|
+
} catch {
|
|
112
|
+
const parent = dirname(path);
|
|
113
|
+
return parent === path ? path : join(canonicalPath(parent), basename(path));
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Whether `path` belongs to the package at `cwd` rather than to something it imports: its realpath lies inside the
|
|
118
|
+
* package, and outside the package's `node_modules`. A workspace link realpaths to the sibling's own directory, and a
|
|
119
|
+
* dependency installed as a real directory under `node_modules` is no more the package's own source than a linked one.
|
|
120
|
+
* The one rule both own-vs-foreign judgements of `ae-wrong-input-file-type` read.
|
|
121
|
+
*/
|
|
122
|
+
const isOwnPath = (path, cwd) => {
|
|
123
|
+
const fromPackage = relative(canonicalPath(cwd), canonicalPath(resolve(cwd, path)));
|
|
124
|
+
if (fromPackage === ".." || fromPackage.startsWith(`..${sep}`) || isAbsolute(fromPackage)) return false;
|
|
125
|
+
return !fromPackage.split(sep).includes("node_modules");
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Whether a message says API Extractor followed an import to a `.ts` file outside this package, or into its
|
|
129
|
+
* `node_modules`. That is what a workspace link to a sibling's source, or a dependency shipping its sources, looks like,
|
|
130
|
+
* and the model does not change. The same message about the package's own file stays a warning: it means the package's
|
|
131
|
+
* own declarations reached its source.
|
|
132
|
+
*/
|
|
133
|
+
function isForeignInputFileMessage(message, cwd) {
|
|
134
|
+
if (message.messageId !== "ae-wrong-input-file-type" || message.sourceFilePath === void 0) return false;
|
|
135
|
+
return !isOwnPath(message.sourceFilePath, cwd);
|
|
136
|
+
}
|
|
137
|
+
/** A TypeScript source that is not a declaration file: what the declaration program must never hold. */
|
|
138
|
+
const isTsSource = (path) => /\.[cm]?tsx?$/.test(path) && !ExtractorConfig.hasDtsFileExtension(path);
|
|
139
|
+
/**
|
|
140
|
+
* Every TypeScript source of the package's own that reached a declaration program, in the program's own path form (the
|
|
141
|
+
* form API Extractor's messages carry): a non-declaration `.ts`/`.tsx`/`.mts`/`.cts` whose realpath lies inside `cwd`
|
|
142
|
+
* and outside its `node_modules`.
|
|
143
|
+
*
|
|
144
|
+
* API Extractor reports `ae-wrong-input-file-type` for only the FIRST non-declaration file of its program, so when a
|
|
145
|
+
* sibling's source sorts first, the one message names the sibling and an own-source leak behind it goes unseen. The
|
|
146
|
+
* program's file list holds every one, whatever the order.
|
|
147
|
+
*/
|
|
148
|
+
function ownSourceInputFiles(program, cwd) {
|
|
149
|
+
return program.getSourceFiles().map(({ fileName }) => resolve(cwd, fileName)).filter((path) => isTsSource(path) && isOwnPath(path, cwd));
|
|
150
|
+
}
|
|
151
|
+
/** Run API Extractor over a single entry's .d.ts, writing the .api.json (and optionally tsdoc-metadata.json). Throws on failure. */
|
|
152
|
+
function runApiExtractor(options) {
|
|
153
|
+
const suppressor = createMessageSuppressor(options.suppressWarnings);
|
|
154
|
+
const tsdocConfigFile = TSDocConfigFile.loadForFolder(dirname(options.tsdocConfigPath));
|
|
155
|
+
const namedOwnInputs = /* @__PURE__ */ new Set();
|
|
156
|
+
const extractorConfig = ExtractorConfig.prepare({
|
|
157
|
+
configObject: {
|
|
158
|
+
projectFolder: options.cwd,
|
|
159
|
+
mainEntryPointFilePath: options.entryDtsPath,
|
|
160
|
+
enumMemberOrder: "preserve",
|
|
161
|
+
compiler: { tsconfigFilePath: writeApiExtractorTsconfig({
|
|
162
|
+
cwd: options.cwd,
|
|
163
|
+
tsconfigPath: options.tsconfigPath,
|
|
164
|
+
entryDtsPath: options.entryDtsPath,
|
|
165
|
+
paths: options.selfReferencePaths
|
|
166
|
+
}) },
|
|
167
|
+
docModel: options.emitDocModel === false ? { enabled: false } : {
|
|
168
|
+
enabled: true,
|
|
169
|
+
apiJsonFilePath: options.apiJsonPath,
|
|
170
|
+
includeForgottenExports: true
|
|
171
|
+
},
|
|
172
|
+
...options.tsdocMetadataPath !== void 0 ? { tsdocMetadata: {
|
|
173
|
+
enabled: true,
|
|
174
|
+
tsdocMetadataFilePath: options.tsdocMetadataPath
|
|
175
|
+
} } : {},
|
|
176
|
+
dtsRollup: { enabled: false },
|
|
177
|
+
apiReport: { enabled: false },
|
|
178
|
+
messages: {
|
|
179
|
+
extractorMessageReporting: {
|
|
180
|
+
default: { logLevel: "warning" },
|
|
181
|
+
"ae-internal-missing-underscore": { logLevel: "none" },
|
|
182
|
+
...options.ci === true ? Object.fromEntries([...CI_FATAL_MESSAGE_IDS].map((id) => [id, { logLevel: "error" }])) : {}
|
|
183
|
+
},
|
|
184
|
+
tsdocMessageReporting: { default: { logLevel: "warning" } }
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
packageJsonFullPath: options.packageJsonPath,
|
|
188
|
+
configObjectFullPath: void 0,
|
|
189
|
+
tsdocConfigFile
|
|
190
|
+
});
|
|
191
|
+
const result = Extractor.invoke(extractorConfig, {
|
|
192
|
+
localBuild: true,
|
|
193
|
+
showVerboseMessages: false,
|
|
194
|
+
messageCallback: (message) => {
|
|
195
|
+
if (message.messageId === "ae-wrong-input-file-type" && message.sourceFilePath !== void 0) namedOwnInputs.add(canonicalPath(resolve(options.cwd, message.sourceFilePath)));
|
|
196
|
+
if (suppressor.matches(message.messageId, message.text) || isForeignInputFileMessage(message, options.cwd)) {
|
|
197
|
+
if (options.onSuppressed !== void 0) {
|
|
198
|
+
const entry = mapExtractorMessage(message);
|
|
199
|
+
if (entry !== void 0) options.onSuppressed(entry);
|
|
200
|
+
}
|
|
201
|
+
message.logLevel = ExtractorLogLevel.None;
|
|
202
|
+
message.handled = true;
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (message.messageId === "console-compiler-version-notice" || message.messageId === "console-preamble") {
|
|
206
|
+
message.logLevel = ExtractorLogLevel.None;
|
|
207
|
+
message.handled = true;
|
|
208
|
+
}
|
|
209
|
+
if (options.onMessage !== void 0) {
|
|
210
|
+
const entry = mapExtractorMessage(message);
|
|
211
|
+
if (entry !== void 0) {
|
|
212
|
+
const ciFatal = options.ci !== true && entry.level === "warn" && entry.code !== void 0 && CI_FATAL_MESSAGE_IDS.has(entry.code);
|
|
213
|
+
options.onMessage(ciFatal ? {
|
|
214
|
+
...entry,
|
|
215
|
+
ciFatal: true
|
|
216
|
+
} : entry);
|
|
217
|
+
message.handled = true;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
for (const file of ownSourceInputFiles(result.compilerState.program, options.cwd)) {
|
|
223
|
+
if (namedOwnInputs.has(canonicalPath(file))) continue;
|
|
224
|
+
const code = "ae-wrong-input-file-type";
|
|
225
|
+
const entry = {
|
|
226
|
+
source: "api-extractor",
|
|
227
|
+
level: "warn",
|
|
228
|
+
code,
|
|
229
|
+
text: `The package's own source "${relative(canonicalPath(options.cwd), canonicalPath(file))}" reached the declaration program; API Extractor expects to analyze compiler outputs with the .d.ts file extension.`,
|
|
230
|
+
file
|
|
231
|
+
};
|
|
232
|
+
if (suppressor.matches(code, entry.text)) options.onSuppressed?.(entry);
|
|
233
|
+
else options.onMessage?.(entry);
|
|
234
|
+
}
|
|
235
|
+
if (!result.succeeded) throw new MetaGenerationError({
|
|
236
|
+
entry: options.entryDtsPath,
|
|
237
|
+
reason: `API Extractor reported ${result.errorCount} error(s) and ${result.warningCount} warning(s)`
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export { isForeignInputFileMessage, mapExtractorMessage, ownSourceInputFiles, runApiExtractor, writeApiExtractorTsconfig };
|
package/meta/config.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/meta/config.ts
|
|
2
|
+
/** Resolve `"auto"` against the environment; explicit booleans pass through. */
|
|
3
|
+
function resolveOptimistic(value, env) {
|
|
4
|
+
if (value === true || value === false) return value;
|
|
5
|
+
return !(env.CI || env.GITHUB_ACTIONS);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Fill defaults so downstream code never branches on undefined.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
function normalizeMetaOptions(meta, env = process.env) {
|
|
13
|
+
return {
|
|
14
|
+
localPaths: meta.localPaths ?? [],
|
|
15
|
+
optimistic: resolveOptimistic(meta.optimistic, env),
|
|
16
|
+
tsdoc: {
|
|
17
|
+
suppressWarnings: meta.tsdoc?.suppressWarnings ?? [],
|
|
18
|
+
tagDefinitions: meta.tsdoc?.tagDefinitions ?? []
|
|
19
|
+
},
|
|
20
|
+
tsdoctor: meta.tsdoctor
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { normalizeMetaOptions };
|
package/meta/generate.js
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { TsdoctorEmitError } from "../errors.js";
|
|
2
|
+
import { runApiExtractor } from "./api-extractor.js";
|
|
3
|
+
import { TSDOCTOR_MANIFEST_FILENAME, encodeBundleManifest } from "./BundleManifest.js";
|
|
4
|
+
import { mergeApiModels } from "./merge-models.js";
|
|
5
|
+
import { resolveOgCacheSalt, writeGeneratedOgImage } from "./og-image.js";
|
|
6
|
+
import { scrubDeclarationMapsUnder } from "./scrub-declaration-maps.js";
|
|
7
|
+
import { resolvePortableTsconfig } from "./tsconfig-resolver.js";
|
|
8
|
+
import { writeTsdocConfig } from "./tsdoc-config.js";
|
|
9
|
+
import { composeTsdoctorManifest, ogImageInfoOf } from "./tsdoctor-manifest.js";
|
|
10
|
+
import { Effect } from "effect";
|
|
11
|
+
import { copyFileSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { join, resolve } from "node:path";
|
|
13
|
+
|
|
14
|
+
// src/meta/generate.ts
|
|
15
|
+
function unscopedName(name) {
|
|
16
|
+
const slash = name.lastIndexOf("/");
|
|
17
|
+
return slash >= 0 ? name.slice(slash + 1) : name;
|
|
18
|
+
}
|
|
19
|
+
/** Normalize the manifest's `repository` (string shorthand or object) to the composer's shape. */
|
|
20
|
+
function manifestRepositoryOf(value) {
|
|
21
|
+
if (typeof value === "string") return value.length > 0 ? { url: value } : void 0;
|
|
22
|
+
if (typeof value === "object" && value !== null && "url" in value && typeof value.url === "string") {
|
|
23
|
+
const directory = "directory" in value && typeof value.directory === "string" ? value.directory : void 0;
|
|
24
|
+
return {
|
|
25
|
+
url: value.url,
|
|
26
|
+
...directory !== void 0 ? { directory } : {}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Generate the api-model meta bundle from already-emitted .d.ts. Writes tsdoc.json (idempotent),
|
|
32
|
+
* runs the extractor per entry, merges if needed, and writes the "virtual TS env" trio to
|
|
33
|
+
* outMetaDir (`<unscoped>.api.json` + the final `package.json` + a portable `tsconfig.json`),
|
|
34
|
+
* copying that trio into each localPaths dir. The api-extractor `tsdoc-metadata.json` is a
|
|
35
|
+
* published-package artifact and is written into `dtsDir` (the built pkg/), not the meta bundle.
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
async function generateMeta(options) {
|
|
39
|
+
const { cwd, packageName, tsconfigPath, dtsDir, entries, exportPaths, outMetaDir, localPaths, tsdoc, manifestTransform, onMessage, ci, onSuppressed } = options;
|
|
40
|
+
const aeInputDir = options.aeInputDir ?? dtsDir;
|
|
41
|
+
const splitDiagnostics = aeInputDir !== dtsDir;
|
|
42
|
+
const tsdocConfigPath = writeTsdocConfig(cwd, tsdoc);
|
|
43
|
+
const packageJsonPath = join(cwd, "package.json");
|
|
44
|
+
mkdirSync(outMetaDir, { recursive: true });
|
|
45
|
+
const apiJsonFilename = `${unscopedName(packageName)}.api.json`;
|
|
46
|
+
const tsdocMetadataPath = join(dtsDir, "tsdoc-metadata.json");
|
|
47
|
+
const entryNames = Object.keys(entries);
|
|
48
|
+
const perEntryModels = /* @__PURE__ */ new Map();
|
|
49
|
+
const intermediateApiJsons = [];
|
|
50
|
+
let mainEntryDidTsdocMetadata = false;
|
|
51
|
+
const diagnosticKey = (e) => `${e.code ?? ""}\0${e.text}`;
|
|
52
|
+
const stripLocation = (e) => ({
|
|
53
|
+
source: e.source,
|
|
54
|
+
level: e.level,
|
|
55
|
+
text: e.text,
|
|
56
|
+
...e.code !== void 0 ? { code: e.code } : {},
|
|
57
|
+
...e.ciFatal !== void 0 ? { ciFatal: e.ciFatal } : {}
|
|
58
|
+
});
|
|
59
|
+
const exportPathFor = (entryName) => exportPaths[entryName] ?? (entryName === "index" ? "." : `./${entryName}`);
|
|
60
|
+
const selfReferencePaths = {};
|
|
61
|
+
if (splitDiagnostics) for (const name of entryNames) {
|
|
62
|
+
const exportPath = exportPathFor(name);
|
|
63
|
+
const specifier = exportPath === "." ? packageName : packageName + exportPath.slice(1);
|
|
64
|
+
selfReferencePaths[specifier] = [join(aeInputDir, `${entries[name]}.d.ts`)];
|
|
65
|
+
}
|
|
66
|
+
scrubDeclarationMapsUnder(dtsDir);
|
|
67
|
+
if (splitDiagnostics) scrubDeclarationMapsUnder(aeInputDir);
|
|
68
|
+
for (const entryName of entryNames) {
|
|
69
|
+
const modelEntryDts = join(dtsDir, `${entries[entryName]}.d.ts`);
|
|
70
|
+
const safeEntry = entryName.replace(/[\\/]/g, "__");
|
|
71
|
+
const perEntryApiJson = join(outMetaDir, `${safeEntry}.entry.api.json`);
|
|
72
|
+
intermediateApiJsons.push(perEntryApiJson);
|
|
73
|
+
const isMain = exportPathFor(entryName) === ".";
|
|
74
|
+
const captureRollupOnlyFatal = splitDiagnostics && onMessage !== void 0 && ci !== true;
|
|
75
|
+
const rollupFatal = [];
|
|
76
|
+
const runBReported = /* @__PURE__ */ new Set();
|
|
77
|
+
const captureRollupSuppressed = splitDiagnostics && onSuppressed !== void 0;
|
|
78
|
+
const rollupSuppressed = [];
|
|
79
|
+
const runBSuppressed = /* @__PURE__ */ new Set();
|
|
80
|
+
const runAOnMessage = captureRollupOnlyFatal ? (entry) => {
|
|
81
|
+
if (entry.ciFatal === true) rollupFatal.push(entry);
|
|
82
|
+
} : ci === true && onMessage !== void 0 ? (entry) => {
|
|
83
|
+
if (entry.level === "error") onMessage(stripLocation(entry));
|
|
84
|
+
} : () => {};
|
|
85
|
+
const flushRollupSuppressedOnThrow = (err) => {
|
|
86
|
+
if (onSuppressed !== void 0) for (const entry of rollupSuppressed) onSuppressed(stripLocation(entry));
|
|
87
|
+
throw err;
|
|
88
|
+
};
|
|
89
|
+
try {
|
|
90
|
+
runApiExtractor({
|
|
91
|
+
cwd,
|
|
92
|
+
packageJsonPath,
|
|
93
|
+
entryDtsPath: modelEntryDts,
|
|
94
|
+
tsconfigPath,
|
|
95
|
+
tsdocConfigPath,
|
|
96
|
+
apiJsonPath: perEntryApiJson,
|
|
97
|
+
...isMain && !mainEntryDidTsdocMetadata ? { tsdocMetadataPath } : {},
|
|
98
|
+
suppressWarnings: tsdoc.suppressWarnings,
|
|
99
|
+
...ci !== void 0 ? { ci } : {},
|
|
100
|
+
...splitDiagnostics ? {
|
|
101
|
+
onMessage: runAOnMessage,
|
|
102
|
+
...captureRollupSuppressed ? { onSuppressed: (entry) => {
|
|
103
|
+
rollupSuppressed.push(entry);
|
|
104
|
+
} } : {}
|
|
105
|
+
} : {
|
|
106
|
+
...onMessage !== void 0 ? { onMessage } : {},
|
|
107
|
+
...onSuppressed !== void 0 ? { onSuppressed } : {}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
} catch (err) {
|
|
111
|
+
flushRollupSuppressedOnThrow(err);
|
|
112
|
+
}
|
|
113
|
+
if (splitDiagnostics) {
|
|
114
|
+
const runBOnMessage = captureRollupOnlyFatal && onMessage !== void 0 ? (entry) => {
|
|
115
|
+
if (entry.ciFatal === true) runBReported.add(diagnosticKey(entry));
|
|
116
|
+
onMessage(entry);
|
|
117
|
+
} : onMessage;
|
|
118
|
+
try {
|
|
119
|
+
runApiExtractor({
|
|
120
|
+
cwd,
|
|
121
|
+
packageJsonPath,
|
|
122
|
+
entryDtsPath: join(aeInputDir, `${entries[entryName]}.d.ts`),
|
|
123
|
+
tsconfigPath,
|
|
124
|
+
tsdocConfigPath,
|
|
125
|
+
apiJsonPath: perEntryApiJson,
|
|
126
|
+
emitDocModel: false,
|
|
127
|
+
selfReferencePaths,
|
|
128
|
+
suppressWarnings: tsdoc.suppressWarnings,
|
|
129
|
+
...runBOnMessage !== void 0 ? { onMessage: runBOnMessage } : {},
|
|
130
|
+
...onSuppressed !== void 0 ? { onSuppressed: (entry) => {
|
|
131
|
+
runBSuppressed.add(diagnosticKey(entry));
|
|
132
|
+
onSuppressed(entry);
|
|
133
|
+
} } : {}
|
|
134
|
+
});
|
|
135
|
+
} catch (err) {
|
|
136
|
+
if (onMessage !== void 0) onMessage({
|
|
137
|
+
source: "api-extractor",
|
|
138
|
+
level: "warn",
|
|
139
|
+
code: "diagnostics-harvest-failed",
|
|
140
|
+
text: `Could not harvest per-module source locations for "${entryName}": ${String(err)}`
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
if (captureRollupOnlyFatal && onMessage !== void 0) for (const entry of rollupFatal) {
|
|
144
|
+
if (runBReported.has(diagnosticKey(entry))) continue;
|
|
145
|
+
onMessage(stripLocation(entry));
|
|
146
|
+
}
|
|
147
|
+
if (onSuppressed !== void 0) for (const entry of rollupSuppressed) {
|
|
148
|
+
if (runBSuppressed.has(diagnosticKey(entry))) continue;
|
|
149
|
+
onSuppressed(stripLocation(entry));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (isMain) mainEntryDidTsdocMetadata = true;
|
|
153
|
+
perEntryModels.set(entryName, JSON.parse(readFileSync(perEntryApiJson, "utf-8")));
|
|
154
|
+
}
|
|
155
|
+
const finalModel = perEntryModels.size === 1 ? perEntryModels.values().next().value : mergeApiModels({
|
|
156
|
+
perEntryModels,
|
|
157
|
+
packageName,
|
|
158
|
+
exportPaths
|
|
159
|
+
});
|
|
160
|
+
const apiJsonPath = join(outMetaDir, apiJsonFilename);
|
|
161
|
+
writeFileSync(apiJsonPath, `${JSON.stringify(finalModel, null, 2)}\n`, "utf-8");
|
|
162
|
+
for (const intermediate of intermediateApiJsons) rmSync(intermediate, { force: true });
|
|
163
|
+
const bundlePackageJson = join(outMetaDir, "package.json");
|
|
164
|
+
const builtPkg = JSON.parse(readFileSync(join(dtsDir, "package.json"), "utf-8"));
|
|
165
|
+
const finalPkg = manifestTransform ? manifestTransform(builtPkg) : builtPkg;
|
|
166
|
+
writeFileSync(bundlePackageJson, `${JSON.stringify(finalPkg, null, 2)}\n`, "utf-8");
|
|
167
|
+
const bundleTsconfig = join(outMetaDir, "tsconfig.json");
|
|
168
|
+
const portableTsconfig = resolvePortableTsconfig(cwd, tsconfigPath);
|
|
169
|
+
writeFileSync(bundleTsconfig, `${JSON.stringify(portableTsconfig, null, 2)}\n`, "utf-8");
|
|
170
|
+
rmSync(join(outMetaDir, TSDOCTOR_MANIFEST_FILENAME), { force: true });
|
|
171
|
+
rmSync(join(outMetaDir, "og"), {
|
|
172
|
+
recursive: true,
|
|
173
|
+
force: true
|
|
174
|
+
});
|
|
175
|
+
let manifestPath;
|
|
176
|
+
let generatedImageRelative;
|
|
177
|
+
if (options.tsdoctor !== void 0) {
|
|
178
|
+
const composeInput = {
|
|
179
|
+
config: options.tsdoctor.config,
|
|
180
|
+
leaf: options.tsdoctor.leaf,
|
|
181
|
+
project: options.tsdoctor.project,
|
|
182
|
+
packageName,
|
|
183
|
+
isPrivate: finalPkg.private === true,
|
|
184
|
+
targets: options.tsdoctor.targets,
|
|
185
|
+
generatedImage: void 0,
|
|
186
|
+
repository: manifestRepositoryOf(finalPkg.repository)
|
|
187
|
+
};
|
|
188
|
+
const generate = options.tsdoctor.config?.openGraph?.generate;
|
|
189
|
+
if (generate !== void 0) {
|
|
190
|
+
const cacheSalt = resolveOgCacheSalt(generate, options.tsdoctor.config?.openGraph?.cacheSalt);
|
|
191
|
+
const generated = await writeGeneratedOgImage({
|
|
192
|
+
generate,
|
|
193
|
+
info: ogImageInfoOf({
|
|
194
|
+
...composeInput,
|
|
195
|
+
version: String(finalPkg.version ?? "0.0.0")
|
|
196
|
+
}),
|
|
197
|
+
outMetaDir,
|
|
198
|
+
unscopedName: unscopedName(packageName),
|
|
199
|
+
...cacheSalt === void 0 ? {} : { cache: {
|
|
200
|
+
directory: join(cwd, "node_modules", ".cache", "effected", "og"),
|
|
201
|
+
salt: cacheSalt
|
|
202
|
+
} }
|
|
203
|
+
});
|
|
204
|
+
composeInput.generatedImage = generated;
|
|
205
|
+
generatedImageRelative = generated.path;
|
|
206
|
+
}
|
|
207
|
+
const manifest = composeTsdoctorManifest(composeInput);
|
|
208
|
+
if (manifest !== void 0) {
|
|
209
|
+
const path = join(outMetaDir, TSDOCTOR_MANIFEST_FILENAME);
|
|
210
|
+
try {
|
|
211
|
+
const encoded = await Effect.runPromise(encodeBundleManifest(manifest));
|
|
212
|
+
writeFileSync(path, `${JSON.stringify(encoded, null, 2)}\n`, "utf-8");
|
|
213
|
+
} catch (cause) {
|
|
214
|
+
throw new TsdoctorEmitError({
|
|
215
|
+
packageName,
|
|
216
|
+
path,
|
|
217
|
+
cause
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
manifestPath = path;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
for (const localPath of localPaths) {
|
|
224
|
+
const dest = resolve(cwd, localPath);
|
|
225
|
+
mkdirSync(dest, { recursive: true });
|
|
226
|
+
copyFileSync(apiJsonPath, join(dest, apiJsonFilename));
|
|
227
|
+
copyFileSync(bundlePackageJson, join(dest, "package.json"));
|
|
228
|
+
copyFileSync(bundleTsconfig, join(dest, "tsconfig.json"));
|
|
229
|
+
if (manifestPath !== void 0) copyFileSync(manifestPath, join(dest, TSDOCTOR_MANIFEST_FILENAME));
|
|
230
|
+
else rmSync(join(dest, TSDOCTOR_MANIFEST_FILENAME), { force: true });
|
|
231
|
+
rmSync(join(dest, "og"), {
|
|
232
|
+
recursive: true,
|
|
233
|
+
force: true
|
|
234
|
+
});
|
|
235
|
+
if (generatedImageRelative !== void 0) {
|
|
236
|
+
mkdirSync(join(dest, "og"), { recursive: true });
|
|
237
|
+
copyFileSync(join(outMetaDir, generatedImageRelative), join(dest, generatedImageRelative));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
apiJsonPath,
|
|
242
|
+
apiJsonFilename
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export { generateMeta };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// src/meta/merge-models.ts
|
|
2
|
+
/** Rewrite every nested member canonicalReference that starts with originalPrefix to use newPrefix. Skips the EntryPoint node itself. */
|
|
3
|
+
function rewriteCanonicalReferences(node, originalPrefix, newPrefix) {
|
|
4
|
+
if (!node || typeof node !== "object") return;
|
|
5
|
+
if (Array.isArray(node)) {
|
|
6
|
+
for (const item of node) rewriteCanonicalReferences(item, originalPrefix, newPrefix);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const obj = node;
|
|
10
|
+
if (typeof obj.canonicalReference === "string" && obj.kind !== "EntryPoint") {
|
|
11
|
+
const ref = obj.canonicalReference;
|
|
12
|
+
if (ref.startsWith(originalPrefix)) obj.canonicalReference = ref.replace(originalPrefix, newPrefix);
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(obj.members)) for (const member of obj.members) rewriteCanonicalReferences(member, originalPrefix, newPrefix);
|
|
15
|
+
}
|
|
16
|
+
/** Merge per-entry API models into one Package model. Each input is a Package with one EntryPoint; the output keeps the main entry (".") canonical and rewrites sub-entries to `${packageName}/${subpath}!`. */
|
|
17
|
+
function mergeApiModels(options) {
|
|
18
|
+
const { perEntryModels, packageName, exportPaths } = options;
|
|
19
|
+
if (perEntryModels.size === 0) throw new Error("Cannot merge zero API models");
|
|
20
|
+
const firstModel = perEntryModels.values().next().value;
|
|
21
|
+
const merged = JSON.parse(JSON.stringify(firstModel));
|
|
22
|
+
const entryPointMembers = [];
|
|
23
|
+
for (const [entryName, model] of perEntryModels) {
|
|
24
|
+
const entryPoints = model.members;
|
|
25
|
+
if (!entryPoints || entryPoints.length === 0) continue;
|
|
26
|
+
const entryPoint = JSON.parse(JSON.stringify(entryPoints[0]));
|
|
27
|
+
const exportPath = exportPaths[entryName] ?? (entryName === "index" ? "." : `./${entryName}`);
|
|
28
|
+
if (exportPath === ".") entryPointMembers.unshift(entryPoint);
|
|
29
|
+
else {
|
|
30
|
+
const subpath = exportPath.replace(/^\.\//, "");
|
|
31
|
+
const originalPrefix = `${packageName}!`;
|
|
32
|
+
const newPrefix = `${packageName}/${subpath}!`;
|
|
33
|
+
entryPoint.canonicalReference = newPrefix;
|
|
34
|
+
entryPoint.name = subpath;
|
|
35
|
+
rewriteCanonicalReferences(entryPoint, originalPrefix, newPrefix);
|
|
36
|
+
entryPointMembers.push(entryPoint);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
merged.members = entryPointMembers;
|
|
40
|
+
return merged;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { mergeApiModels };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// src/meta/message-suppressor.ts
|
|
2
|
+
function compileRule(rule) {
|
|
3
|
+
if (rule.pattern === void 0) return {
|
|
4
|
+
messageId: rule.messageId,
|
|
5
|
+
regex: void 0,
|
|
6
|
+
substring: void 0
|
|
7
|
+
};
|
|
8
|
+
try {
|
|
9
|
+
return {
|
|
10
|
+
messageId: rule.messageId,
|
|
11
|
+
regex: new RegExp(rule.pattern),
|
|
12
|
+
substring: void 0
|
|
13
|
+
};
|
|
14
|
+
} catch {
|
|
15
|
+
return {
|
|
16
|
+
messageId: rule.messageId,
|
|
17
|
+
regex: void 0,
|
|
18
|
+
substring: rule.pattern
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Build a suppressor that matches a message when its id matches exactly AND (if a pattern is set) the text matches the
|
|
24
|
+
* regex/substring. The config schema allows a pattern with no id, which matches on the text across every id; a rule
|
|
25
|
+
* with neither matches nothing, since it would otherwise silence every message.
|
|
26
|
+
*/
|
|
27
|
+
function createMessageSuppressor(rules) {
|
|
28
|
+
const compiled = rules.map(compileRule);
|
|
29
|
+
return { matches(messageId, text) {
|
|
30
|
+
for (const rule of compiled) {
|
|
31
|
+
if (rule.messageId !== void 0 && rule.messageId !== messageId) continue;
|
|
32
|
+
if (rule.regex === void 0 && rule.substring === void 0) {
|
|
33
|
+
if (rule.messageId !== void 0) return true;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (rule.regex?.test(text)) return true;
|
|
37
|
+
if (rule.substring !== void 0 && text.includes(rule.substring)) return true;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
} };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { createMessageSuppressor };
|