@effected/bundler 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Bundler.js +498 -0
- package/BundlerError.js +39 -0
- package/LICENSE +21 -0
- package/README.md +84 -2
- package/action/ActionBuilder.js +108 -0
- package/action/ActionBundle.js +272 -0
- package/action/ActionErrors.js +83 -0
- package/action/ActionValidation.js +195 -0
- package/action/ActionYml.js +366 -0
- package/action/PersistLocal.js +186 -0
- package/action/entries.js +23 -0
- package/action/ignore-stub-plugin.js +25 -0
- package/action/import-check.js +134 -0
- package/assets/Inter-SemiBold.ttf +0 -0
- package/assets/LICENSE-Inter.txt +92 -0
- package/catalog/resolve-catalogs.js +32 -0
- package/changesets/next-versions.js +50 -0
- package/config/ActionConfig.js +102 -0
- package/config/BuildConfig.js +438 -0
- package/config/EffectedConfigFile.js +171 -0
- package/config/merge.js +20 -0
- package/config/plugins.js +84 -0
- package/config-validation/ConfigValidator.js +73 -0
- package/dts/bundled-siblings.js +108 -0
- package/dts/parse.js +28 -0
- package/dts/reexport-stub.js +94 -0
- package/dts/relative-imports.js +33 -0
- package/dts/resolved-tsconfig.js +238 -0
- package/entries/ambient-dts.js +108 -0
- package/entries/export-paths.js +16 -0
- package/entries/extract.js +79 -0
- package/entries/package-json-entries.js +19 -0
- package/errors.js +37 -0
- package/exe/build.js +55 -0
- package/exe/config.js +54 -0
- package/exe/filename.js +13 -0
- package/index.d.ts +3619 -0
- package/index.js +57 -0
- package/internal/causeMessage.js +57 -0
- package/journal/BuildJournal.js +107 -0
- package/jsx/config.js +44 -0
- package/manifest/built-condition.js +120 -0
- package/manifest/emit-manifest.js +93 -0
- package/manifest/export-patterns.js +56 -0
- package/manifest/manifest-set.js +101 -0
- package/manifest/transform.js +324 -0
- package/meta/api-extractor.js +241 -0
- package/meta/bundle-config.js +22 -0
- package/meta/bundle-manifest.js +134 -0
- package/meta/bundle-source.js +106 -0
- package/meta/config.js +24 -0
- package/meta/generate.js +249 -0
- package/meta/merge-models.js +43 -0
- package/meta/message-suppressor.js +43 -0
- package/meta/og-image.js +137 -0
- package/meta/og-satori.js +140 -0
- package/meta/optimistic.js +32 -0
- package/meta/run-pass.js +124 -0
- package/meta/scrub-declaration-maps.js +63 -0
- package/meta/tsconfig-resolver.js +55 -0
- package/meta/tsdoc-config.js +47 -0
- package/package.json +86 -5
- package/passes/build-target-groups.js +347 -0
- package/passes/cjs-default-interop.js +98 -0
- package/passes/loose-files.js +57 -0
- package/passes/node-builtin-default-interop.js +79 -0
- package/passes/strip-maps.js +40 -0
- package/passes/sync-public.js +100 -0
- package/passes/target-groups.js +112 -0
- package/report/ci-annotations.js +36 -0
- package/report/collector.js +140 -0
- package/report/issues-artifact.js +149 -0
- package/report/metrics-plugin.js +76 -0
- package/report/schema.js +77 -0
- package/report/timer.js +19 -0
- package/report/tsdown-logger.js +58 -0
- package/targets/binding.js +19 -0
- package/targets/config.js +21 -0
- package/targets/resolve-targets.js +165 -0
- package/tsconfig/sync-options.js +20 -0
- package/tsdoc-metadata.json +11 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { MANIFEST_SPEC } from "@effected/manifest";
|
|
2
|
+
|
|
3
|
+
// src/meta/bundle-manifest.ts
|
|
4
|
+
const first = (...values) => values.find((v) => v !== void 0);
|
|
5
|
+
/**
|
|
6
|
+
* `owner/repo` from any of the GitHub URL spellings a `repository.url` carries (https, `git+https`,
|
|
7
|
+
* `git@`, `ssh://`, `git://`, the `github:` shorthand), or `undefined` for anything else.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
function githubOwnerRepo(url) {
|
|
12
|
+
const match = /^(?:git\+)?(?:https?:\/\/|git:\/\/|ssh:\/\/(?:git@)?|git@)?(?:www\.)?github\.com[/:]([^/]{1,214})\/([^/]{1,214}?)(?:\.git)?\/?$/i.exec(url.trim()) ?? /^github:([^/]{1,214})\/([^/]{1,214}?)(?:\.git)?$/i.exec(url.trim());
|
|
13
|
+
if (match === null) return void 0;
|
|
14
|
+
const owner = match[1];
|
|
15
|
+
const repo = match[2];
|
|
16
|
+
if (owner === void 0 || repo === void 0 || owner.length === 0 || repo.length === 0) return void 0;
|
|
17
|
+
return {
|
|
18
|
+
owner,
|
|
19
|
+
repo
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function unscopedName(name) {
|
|
23
|
+
const slash = name.lastIndexOf("/");
|
|
24
|
+
return slash >= 0 ? name.slice(slash + 1) : name;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The package's human page on a registry, or `undefined` when no real page can be derived. npmjs
|
|
28
|
+
* has a well-known page; GitHub Packages pages hang off the repository, so they need a parseable
|
|
29
|
+
* `repository.url` and are omitted rather than emitted as a dead link when it is missing.
|
|
30
|
+
*/
|
|
31
|
+
/** Strip trailing slashes without a `/\/+$/` regex, which backtracks polynomially on slash runs (CodeQL js/polynomial-redos). */
|
|
32
|
+
function stripTrailingSlashes(value) {
|
|
33
|
+
let end = value.length;
|
|
34
|
+
while (end > 0 && value.charCodeAt(end - 1) === 47) end -= 1;
|
|
35
|
+
return value.slice(0, end);
|
|
36
|
+
}
|
|
37
|
+
function packagePageUrl(registry, packageName, repository) {
|
|
38
|
+
const host = stripTrailingSlashes(registry);
|
|
39
|
+
if (host === "https://registry.npmjs.org") return `https://www.npmjs.com/package/${packageName}`;
|
|
40
|
+
if (/^https?:\/\/npm\.pkg\.github\.com$/i.test(host)) {
|
|
41
|
+
const gh = repository !== void 0 ? githubOwnerRepo(repository.url) : void 0;
|
|
42
|
+
return gh === void 0 ? void 0 : `https://github.com/${gh.owner}/${gh.repo}/pkgs/npm/${unscopedName(packageName)}`;
|
|
43
|
+
}
|
|
44
|
+
return `${host}/package/${packageName}`;
|
|
45
|
+
}
|
|
46
|
+
function projectIdentityOf(project) {
|
|
47
|
+
if (project === void 0) return void 0;
|
|
48
|
+
if (project.name === void 0 && project.tagline === void 0) return void 0;
|
|
49
|
+
return {
|
|
50
|
+
...project.name !== void 0 ? { name: project.name } : {},
|
|
51
|
+
...project.tagline !== void 0 ? { tagline: project.tagline } : {}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Derive the registries block from the build's targets. Only for a public
|
|
56
|
+
* package: a private one is published nowhere.
|
|
57
|
+
*
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
function registriesFromTargets(input) {
|
|
61
|
+
if (input.isPrivate) return [];
|
|
62
|
+
const out = [];
|
|
63
|
+
for (const t of input.targets) {
|
|
64
|
+
const url = packagePageUrl(t.registry, input.packageName, input.repository);
|
|
65
|
+
if (url !== void 0) out.push({
|
|
66
|
+
type: "npm",
|
|
67
|
+
name: t.name,
|
|
68
|
+
url
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Flatten the three authoring tiers into the emitted manifest. Pure.
|
|
75
|
+
*
|
|
76
|
+
* @remarks
|
|
77
|
+
* Config beats leaf beats project per FIELD; the project tier is emitted
|
|
78
|
+
* nested, never flattened, because the consumer's provenance ranking depends
|
|
79
|
+
* on telling the tiers apart. Returns `undefined` when there is nothing to
|
|
80
|
+
* say, so a package with no metadata emits no file. An `sbom` pointer is
|
|
81
|
+
* never written here — the release action upserts it at publish.
|
|
82
|
+
*
|
|
83
|
+
* @public
|
|
84
|
+
*/
|
|
85
|
+
function composeBundleManifest(input) {
|
|
86
|
+
const { config, leaf, project } = input;
|
|
87
|
+
const images = [
|
|
88
|
+
...input.generatedImage !== void 0 ? [input.generatedImage] : [],
|
|
89
|
+
...config?.openGraph?.images ?? [],
|
|
90
|
+
...leaf?.openGraph?.images ?? [],
|
|
91
|
+
...project?.openGraph?.images ?? []
|
|
92
|
+
];
|
|
93
|
+
const themeColor = first(config?.openGraph?.themeColor, leaf?.openGraph?.themeColor, project?.openGraph?.themeColor);
|
|
94
|
+
const openGraph = images.length > 0 || themeColor !== void 0 ? {
|
|
95
|
+
...images.length > 0 ? { images } : {},
|
|
96
|
+
...themeColor !== void 0 ? { themeColor } : {}
|
|
97
|
+
} : void 0;
|
|
98
|
+
const registries = config?.registries === false ? void 0 : first(config?.registries, leaf?.registries) ?? registriesFromTargets(input);
|
|
99
|
+
const name = first(config?.name, leaf?.name);
|
|
100
|
+
const tagline = first(config?.tagline, leaf?.tagline);
|
|
101
|
+
const description = first(config?.description, leaf?.description);
|
|
102
|
+
const projectIdentity = projectIdentityOf(project);
|
|
103
|
+
const manifest = {
|
|
104
|
+
spec: MANIFEST_SPEC,
|
|
105
|
+
...name !== void 0 ? { name } : {},
|
|
106
|
+
...tagline !== void 0 ? { tagline } : {},
|
|
107
|
+
...description !== void 0 ? { description } : {},
|
|
108
|
+
...projectIdentity !== void 0 ? { project: projectIdentity } : {},
|
|
109
|
+
...openGraph !== void 0 ? { openGraph } : {},
|
|
110
|
+
...registries !== void 0 && registries.length > 0 ? { registries } : {}
|
|
111
|
+
};
|
|
112
|
+
return Object.keys(manifest).length > 1 ? manifest : void 0;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* What the generator sees. Built from the same tiers as the manifest.
|
|
116
|
+
*
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
function ogImageInfoOf(input) {
|
|
120
|
+
const { config, leaf, project } = input;
|
|
121
|
+
const tagline = first(config?.tagline, leaf?.tagline, project?.tagline);
|
|
122
|
+
const description = first(config?.description, leaf?.description);
|
|
123
|
+
const projectIdentity = projectIdentityOf(project);
|
|
124
|
+
return {
|
|
125
|
+
name: first(config?.name, leaf?.name) ?? input.packageName,
|
|
126
|
+
packageName: input.packageName,
|
|
127
|
+
version: input.version,
|
|
128
|
+
...tagline !== void 0 ? { tagline } : {},
|
|
129
|
+
...description !== void 0 ? { description } : {},
|
|
130
|
+
...projectIdentity !== void 0 ? { project: projectIdentity } : {}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export { composeBundleManifest, githubOwnerRepo, ogImageInfoOf, registriesFromTargets };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { BUNDLE_MANIFEST_FILENAME, decodeManifestSource } from "@effected/manifest";
|
|
2
|
+
import { Data, Effect, Layer } from "effect";
|
|
3
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
|
+
import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
|
|
6
|
+
import * as NodePath from "@effect/platform-node/NodePath";
|
|
7
|
+
import { WorkspaceDiscovery, WorkspaceRootNotFoundError, Workspaces } from "@effected/workspaces";
|
|
8
|
+
|
|
9
|
+
// src/meta/bundle-source.ts
|
|
10
|
+
/**
|
|
11
|
+
* A present `bundle.json` source file that could not be parsed or decoded. Absence is never
|
|
12
|
+
* this error — a missing source tier is the normal case.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
var BundleManifestSourceError = class extends Data.TaggedError("BundleManifestSourceError") {
|
|
17
|
+
get message() {
|
|
18
|
+
return `Invalid ${BUNDLE_MANIFEST_FILENAME} at ${this.path}`;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The sidecar's and its source files' name before it became `bundle.json`. Nothing reads or writes it: a build
|
|
23
|
+
* deletes an emitted copy and reports an authored one.
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
const RETIRED_MANIFEST_FILENAME = "tsdoctor.json";
|
|
28
|
+
/** Bound once: the platform layer is stateless and layers memoize by reference. */
|
|
29
|
+
const platform = Layer.mergeAll(NodeFileSystem.layer, NodePath.layer);
|
|
30
|
+
/** The canonical absolute form of a directory, so a relative or symlinked `cwd` compares equal to the discovered root. */
|
|
31
|
+
function canonical(dir) {
|
|
32
|
+
const absolute = resolve(dir);
|
|
33
|
+
try {
|
|
34
|
+
return realpathSync(absolute);
|
|
35
|
+
} catch {
|
|
36
|
+
return absolute;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** `Effect.runPromise` rejects with the failure itself or with a `FiberFailure` wrapping it; check both. */
|
|
40
|
+
function isRootNotFound(cause) {
|
|
41
|
+
if (cause instanceof WorkspaceRootNotFoundError) return true;
|
|
42
|
+
return typeof cause === "object" && cause !== null && "_tag" in cause && cause._tag === "WorkspaceRootNotFoundError";
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The workspace root containing `cwd`, or the reason discovery failed. A package outside any
|
|
46
|
+
* workspace is the `root: undefined` case with no failure. Mirrors the `WorkspaceDiscovery`
|
|
47
|
+
* invocation in `changesets/next-versions.ts`.
|
|
48
|
+
*/
|
|
49
|
+
async function findWorkspaceRoot(cwd) {
|
|
50
|
+
try {
|
|
51
|
+
const packages = await Effect.runPromise(Effect.gen(function* () {
|
|
52
|
+
return yield* (yield* WorkspaceDiscovery).listPackages();
|
|
53
|
+
}).pipe(Effect.provide(Workspaces.layer({ cwd }).pipe(Layer.provide(platform)))));
|
|
54
|
+
return { root: packages[0]?.isRootWorkspace ? packages[0].path : void 0 };
|
|
55
|
+
} catch (cause) {
|
|
56
|
+
if (isRootNotFound(cause)) return { root: void 0 };
|
|
57
|
+
return {
|
|
58
|
+
root: void 0,
|
|
59
|
+
failure: cause instanceof Error ? cause.message : String(cause)
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async function readSource(path) {
|
|
64
|
+
if (!existsSync(path)) return void 0;
|
|
65
|
+
let parsed;
|
|
66
|
+
try {
|
|
67
|
+
parsed = JSON.parse(readFileSync(path, "utf-8"));
|
|
68
|
+
} catch (cause) {
|
|
69
|
+
throw new BundleManifestSourceError({
|
|
70
|
+
path,
|
|
71
|
+
cause
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const result = await Effect.runPromise(Effect.result(decodeManifestSource(parsed, path)));
|
|
75
|
+
if (result._tag === "Failure") throw new BundleManifestSourceError({
|
|
76
|
+
path,
|
|
77
|
+
cause: result.failure
|
|
78
|
+
});
|
|
79
|
+
return result.success;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Read the leaf (`<cwd>/bundle.json`) and project (`<workspaceRoot>/bundle.json`)
|
|
83
|
+
* source tiers. Absence is normal; a present file that does not decode throws
|
|
84
|
+
* {@link BundleManifestSourceError}. A package that IS the workspace root reads its file once, as the
|
|
85
|
+
* leaf, and has no project tier.
|
|
86
|
+
*
|
|
87
|
+
* @public
|
|
88
|
+
*/
|
|
89
|
+
async function loadBundleManifestSources(cwd) {
|
|
90
|
+
const leafDir = canonical(cwd);
|
|
91
|
+
const tierDirs = [leafDir];
|
|
92
|
+
const leaf = await readSource(join(leafDir, BUNDLE_MANIFEST_FILENAME));
|
|
93
|
+
const { root, failure } = await findWorkspaceRoot(leafDir);
|
|
94
|
+
const projectDir = root !== void 0 && canonical(root) !== leafDir ? root : void 0;
|
|
95
|
+
if (projectDir !== void 0) tierDirs.push(projectDir);
|
|
96
|
+
const project = projectDir !== void 0 ? await readSource(join(projectDir, BUNDLE_MANIFEST_FILENAME)) : void 0;
|
|
97
|
+
const retiredSources = tierDirs.filter((dir) => !existsSync(join(dir, BUNDLE_MANIFEST_FILENAME))).map((dir) => join(dir, RETIRED_MANIFEST_FILENAME)).filter((path) => existsSync(path));
|
|
98
|
+
return {
|
|
99
|
+
leaf,
|
|
100
|
+
project,
|
|
101
|
+
...failure !== void 0 ? { discoveryFailure: failure } : {},
|
|
102
|
+
...retiredSources.length > 0 ? { retiredSources } : {}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { BundleManifestSourceError, RETIRED_MANIFEST_FILENAME, loadBundleManifestSources };
|
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
|
+
bundle: meta.bundle
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { normalizeMetaOptions };
|
package/meta/generate.js
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { BundleManifestEmitError } from "../errors.js";
|
|
2
|
+
import { runApiExtractor } from "./api-extractor.js";
|
|
3
|
+
import { composeBundleManifest, ogImageInfoOf } from "./bundle-manifest.js";
|
|
4
|
+
import { RETIRED_MANIFEST_FILENAME } from "./bundle-source.js";
|
|
5
|
+
import { mergeApiModels } from "./merge-models.js";
|
|
6
|
+
import { resolveOgCacheSalt, writeGeneratedOgImage } from "./og-image.js";
|
|
7
|
+
import { scrubDeclarationMapsUnder } from "./scrub-declaration-maps.js";
|
|
8
|
+
import { resolvePortableTsconfig } from "./tsconfig-resolver.js";
|
|
9
|
+
import { writeTsdocConfig } from "./tsdoc-config.js";
|
|
10
|
+
import { BUNDLE_MANIFEST_FILENAME, encodeBundleManifest } from "@effected/manifest";
|
|
11
|
+
import { Effect } from "effect";
|
|
12
|
+
import { copyFileSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { join, resolve } from "node:path";
|
|
14
|
+
|
|
15
|
+
// src/meta/generate.ts
|
|
16
|
+
function unscopedName(name) {
|
|
17
|
+
const slash = name.lastIndexOf("/");
|
|
18
|
+
return slash >= 0 ? name.slice(slash + 1) : name;
|
|
19
|
+
}
|
|
20
|
+
/** Normalize the manifest's `repository` (string shorthand or object) to the composer's shape. */
|
|
21
|
+
function manifestRepositoryOf(value) {
|
|
22
|
+
if (typeof value === "string") return value.length > 0 ? { url: value } : void 0;
|
|
23
|
+
if (typeof value === "object" && value !== null && "url" in value && typeof value.url === "string") {
|
|
24
|
+
const directory = "directory" in value && typeof value.directory === "string" ? value.directory : void 0;
|
|
25
|
+
return {
|
|
26
|
+
url: value.url,
|
|
27
|
+
...directory !== void 0 ? { directory } : {}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Generate the api-model meta bundle from already-emitted .d.ts. Writes tsdoc.json (idempotent),
|
|
33
|
+
* runs the extractor per entry, merges if needed, and writes the "virtual TS env" trio to
|
|
34
|
+
* outMetaDir (`<unscoped>.api.json` + the final `package.json` + a portable `tsconfig.json`),
|
|
35
|
+
* copying that trio into each localPaths dir. The api-extractor `tsdoc-metadata.json` is a
|
|
36
|
+
* published-package artifact and is written into `dtsDir` (the built pkg/), not the meta bundle.
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
async function generateMeta(options) {
|
|
40
|
+
const { cwd, packageName, tsconfigPath, dtsDir, entries, exportPaths, outMetaDir, localPaths, tsdoc, manifestTransform, onMessage, ci, onSuppressed } = options;
|
|
41
|
+
const aeInputDir = options.aeInputDir ?? dtsDir;
|
|
42
|
+
const splitDiagnostics = aeInputDir !== dtsDir;
|
|
43
|
+
const tsdocConfigPath = writeTsdocConfig(cwd, tsdoc);
|
|
44
|
+
const packageJsonPath = join(cwd, "package.json");
|
|
45
|
+
mkdirSync(outMetaDir, { recursive: true });
|
|
46
|
+
const apiJsonFilename = `${unscopedName(packageName)}.api.json`;
|
|
47
|
+
const tsdocMetadataPath = join(dtsDir, "tsdoc-metadata.json");
|
|
48
|
+
const entryNames = Object.keys(entries);
|
|
49
|
+
const perEntryModels = /* @__PURE__ */ new Map();
|
|
50
|
+
const intermediateApiJsons = [];
|
|
51
|
+
let mainEntryDidTsdocMetadata = false;
|
|
52
|
+
const diagnosticKey = (e) => `${e.code ?? ""}\0${e.text}`;
|
|
53
|
+
const stripLocation = (e) => ({
|
|
54
|
+
source: e.source,
|
|
55
|
+
level: e.level,
|
|
56
|
+
text: e.text,
|
|
57
|
+
...e.code !== void 0 ? { code: e.code } : {},
|
|
58
|
+
...e.ciFatal !== void 0 ? { ciFatal: e.ciFatal } : {}
|
|
59
|
+
});
|
|
60
|
+
const exportPathFor = (entryName) => exportPaths[entryName] ?? (entryName === "index" ? "." : `./${entryName}`);
|
|
61
|
+
const selfReferencePaths = {};
|
|
62
|
+
if (splitDiagnostics) for (const name of entryNames) {
|
|
63
|
+
const exportPath = exportPathFor(name);
|
|
64
|
+
const specifier = exportPath === "." ? packageName : packageName + exportPath.slice(1);
|
|
65
|
+
selfReferencePaths[specifier] = [join(aeInputDir, `${entries[name]}.d.ts`)];
|
|
66
|
+
}
|
|
67
|
+
scrubDeclarationMapsUnder(dtsDir);
|
|
68
|
+
if (splitDiagnostics) scrubDeclarationMapsUnder(aeInputDir);
|
|
69
|
+
for (const entryName of entryNames) {
|
|
70
|
+
const modelEntryDts = join(dtsDir, `${entries[entryName]}.d.ts`);
|
|
71
|
+
const safeEntry = entryName.replace(/[\\/]/g, "__");
|
|
72
|
+
const perEntryApiJson = join(outMetaDir, `${safeEntry}.entry.api.json`);
|
|
73
|
+
intermediateApiJsons.push(perEntryApiJson);
|
|
74
|
+
const isMain = exportPathFor(entryName) === ".";
|
|
75
|
+
const captureRollupOnlyFatal = splitDiagnostics && onMessage !== void 0 && ci !== true;
|
|
76
|
+
const rollupFatal = [];
|
|
77
|
+
const runBReported = /* @__PURE__ */ new Set();
|
|
78
|
+
const captureRollupSuppressed = splitDiagnostics && onSuppressed !== void 0;
|
|
79
|
+
const rollupSuppressed = [];
|
|
80
|
+
const runBSuppressed = /* @__PURE__ */ new Set();
|
|
81
|
+
const runAOnMessage = captureRollupOnlyFatal ? (entry) => {
|
|
82
|
+
if (entry.ciFatal === true) rollupFatal.push(entry);
|
|
83
|
+
} : ci === true && onMessage !== void 0 ? (entry) => {
|
|
84
|
+
if (entry.level === "error") onMessage(stripLocation(entry));
|
|
85
|
+
} : () => {};
|
|
86
|
+
const flushRollupSuppressedOnThrow = (err) => {
|
|
87
|
+
if (onSuppressed !== void 0) for (const entry of rollupSuppressed) onSuppressed(stripLocation(entry));
|
|
88
|
+
throw err;
|
|
89
|
+
};
|
|
90
|
+
try {
|
|
91
|
+
runApiExtractor({
|
|
92
|
+
cwd,
|
|
93
|
+
packageJsonPath,
|
|
94
|
+
entryDtsPath: modelEntryDts,
|
|
95
|
+
tsconfigPath,
|
|
96
|
+
tsdocConfigPath,
|
|
97
|
+
apiJsonPath: perEntryApiJson,
|
|
98
|
+
...isMain && !mainEntryDidTsdocMetadata ? { tsdocMetadataPath } : {},
|
|
99
|
+
suppressWarnings: tsdoc.suppressWarnings,
|
|
100
|
+
...ci !== void 0 ? { ci } : {},
|
|
101
|
+
...splitDiagnostics ? {
|
|
102
|
+
onMessage: runAOnMessage,
|
|
103
|
+
...captureRollupSuppressed ? { onSuppressed: (entry) => {
|
|
104
|
+
rollupSuppressed.push(entry);
|
|
105
|
+
} } : {}
|
|
106
|
+
} : {
|
|
107
|
+
...onMessage !== void 0 ? { onMessage } : {},
|
|
108
|
+
...onSuppressed !== void 0 ? { onSuppressed } : {}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
} catch (err) {
|
|
112
|
+
flushRollupSuppressedOnThrow(err);
|
|
113
|
+
}
|
|
114
|
+
if (splitDiagnostics) {
|
|
115
|
+
const runBOnMessage = captureRollupOnlyFatal && onMessage !== void 0 ? (entry) => {
|
|
116
|
+
if (entry.ciFatal === true) runBReported.add(diagnosticKey(entry));
|
|
117
|
+
onMessage(entry);
|
|
118
|
+
} : onMessage;
|
|
119
|
+
try {
|
|
120
|
+
runApiExtractor({
|
|
121
|
+
cwd,
|
|
122
|
+
packageJsonPath,
|
|
123
|
+
entryDtsPath: join(aeInputDir, `${entries[entryName]}.d.ts`),
|
|
124
|
+
tsconfigPath,
|
|
125
|
+
tsdocConfigPath,
|
|
126
|
+
apiJsonPath: perEntryApiJson,
|
|
127
|
+
emitDocModel: false,
|
|
128
|
+
selfReferencePaths,
|
|
129
|
+
suppressWarnings: tsdoc.suppressWarnings,
|
|
130
|
+
...runBOnMessage !== void 0 ? { onMessage: runBOnMessage } : {},
|
|
131
|
+
...onSuppressed !== void 0 ? { onSuppressed: (entry) => {
|
|
132
|
+
runBSuppressed.add(diagnosticKey(entry));
|
|
133
|
+
onSuppressed(entry);
|
|
134
|
+
} } : {}
|
|
135
|
+
});
|
|
136
|
+
} catch (err) {
|
|
137
|
+
if (onMessage !== void 0) onMessage({
|
|
138
|
+
source: "api-extractor",
|
|
139
|
+
level: "warn",
|
|
140
|
+
code: "diagnostics-harvest-failed",
|
|
141
|
+
text: `Could not harvest per-module source locations for "${entryName}": ${String(err)}`
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
if (captureRollupOnlyFatal && onMessage !== void 0) for (const entry of rollupFatal) {
|
|
145
|
+
if (runBReported.has(diagnosticKey(entry))) continue;
|
|
146
|
+
onMessage(stripLocation(entry));
|
|
147
|
+
}
|
|
148
|
+
if (onSuppressed !== void 0) for (const entry of rollupSuppressed) {
|
|
149
|
+
if (runBSuppressed.has(diagnosticKey(entry))) continue;
|
|
150
|
+
onSuppressed(stripLocation(entry));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (isMain) mainEntryDidTsdocMetadata = true;
|
|
154
|
+
perEntryModels.set(entryName, JSON.parse(readFileSync(perEntryApiJson, "utf-8")));
|
|
155
|
+
}
|
|
156
|
+
const finalModel = perEntryModels.size === 1 ? perEntryModels.values().next().value : mergeApiModels({
|
|
157
|
+
perEntryModels,
|
|
158
|
+
packageName,
|
|
159
|
+
exportPaths
|
|
160
|
+
});
|
|
161
|
+
const apiJsonPath = join(outMetaDir, apiJsonFilename);
|
|
162
|
+
writeFileSync(apiJsonPath, `${JSON.stringify(finalModel, null, 2)}\n`, "utf-8");
|
|
163
|
+
for (const intermediate of intermediateApiJsons) rmSync(intermediate, { force: true });
|
|
164
|
+
const bundlePackageJson = join(outMetaDir, "package.json");
|
|
165
|
+
const builtPkg = JSON.parse(readFileSync(join(dtsDir, "package.json"), "utf-8"));
|
|
166
|
+
const finalPkg = manifestTransform ? manifestTransform(builtPkg) : builtPkg;
|
|
167
|
+
writeFileSync(bundlePackageJson, `${JSON.stringify(finalPkg, null, 2)}\n`, "utf-8");
|
|
168
|
+
const bundleTsconfig = join(outMetaDir, "tsconfig.json");
|
|
169
|
+
const portableTsconfig = resolvePortableTsconfig(cwd, tsconfigPath);
|
|
170
|
+
writeFileSync(bundleTsconfig, `${JSON.stringify(portableTsconfig, null, 2)}\n`, "utf-8");
|
|
171
|
+
rmSync(join(outMetaDir, BUNDLE_MANIFEST_FILENAME), { force: true });
|
|
172
|
+
rmSync(join(outMetaDir, RETIRED_MANIFEST_FILENAME), { force: true });
|
|
173
|
+
rmSync(join(outMetaDir, "og"), {
|
|
174
|
+
recursive: true,
|
|
175
|
+
force: true
|
|
176
|
+
});
|
|
177
|
+
let manifestPath;
|
|
178
|
+
let generatedImageRelative;
|
|
179
|
+
if (options.bundle !== void 0) {
|
|
180
|
+
const composeInput = {
|
|
181
|
+
config: options.bundle.config,
|
|
182
|
+
leaf: options.bundle.leaf,
|
|
183
|
+
project: options.bundle.project,
|
|
184
|
+
packageName,
|
|
185
|
+
isPrivate: finalPkg.private === true,
|
|
186
|
+
targets: options.bundle.targets,
|
|
187
|
+
generatedImage: void 0,
|
|
188
|
+
repository: manifestRepositoryOf(finalPkg.repository)
|
|
189
|
+
};
|
|
190
|
+
const generate = options.bundle.config?.openGraph?.generate;
|
|
191
|
+
if (generate !== void 0) {
|
|
192
|
+
const cacheSalt = resolveOgCacheSalt(generate, options.bundle.config?.openGraph?.cacheSalt);
|
|
193
|
+
const generated = await writeGeneratedOgImage({
|
|
194
|
+
generate,
|
|
195
|
+
info: ogImageInfoOf({
|
|
196
|
+
...composeInput,
|
|
197
|
+
version: String(finalPkg.version ?? "0.0.0")
|
|
198
|
+
}),
|
|
199
|
+
outMetaDir,
|
|
200
|
+
unscopedName: unscopedName(packageName),
|
|
201
|
+
...cacheSalt === void 0 ? {} : { cache: {
|
|
202
|
+
directory: join(cwd, "node_modules", ".cache", "effected", "og"),
|
|
203
|
+
salt: cacheSalt
|
|
204
|
+
} }
|
|
205
|
+
});
|
|
206
|
+
composeInput.generatedImage = generated;
|
|
207
|
+
generatedImageRelative = generated.path;
|
|
208
|
+
}
|
|
209
|
+
const manifest = composeBundleManifest(composeInput);
|
|
210
|
+
if (manifest !== void 0) {
|
|
211
|
+
const path = join(outMetaDir, BUNDLE_MANIFEST_FILENAME);
|
|
212
|
+
try {
|
|
213
|
+
const encoded = await Effect.runPromise(encodeBundleManifest(manifest));
|
|
214
|
+
writeFileSync(path, `${JSON.stringify(encoded, null, 2)}\n`, "utf-8");
|
|
215
|
+
} catch (cause) {
|
|
216
|
+
throw new BundleManifestEmitError({
|
|
217
|
+
packageName,
|
|
218
|
+
path,
|
|
219
|
+
cause
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
manifestPath = path;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
for (const localPath of localPaths) {
|
|
226
|
+
const dest = resolve(cwd, localPath);
|
|
227
|
+
mkdirSync(dest, { recursive: true });
|
|
228
|
+
copyFileSync(apiJsonPath, join(dest, apiJsonFilename));
|
|
229
|
+
copyFileSync(bundlePackageJson, join(dest, "package.json"));
|
|
230
|
+
copyFileSync(bundleTsconfig, join(dest, "tsconfig.json"));
|
|
231
|
+
if (manifestPath !== void 0) copyFileSync(manifestPath, join(dest, BUNDLE_MANIFEST_FILENAME));
|
|
232
|
+
else rmSync(join(dest, BUNDLE_MANIFEST_FILENAME), { force: true });
|
|
233
|
+
rmSync(join(dest, RETIRED_MANIFEST_FILENAME), { force: true });
|
|
234
|
+
rmSync(join(dest, "og"), {
|
|
235
|
+
recursive: true,
|
|
236
|
+
force: true
|
|
237
|
+
});
|
|
238
|
+
if (generatedImageRelative !== void 0) {
|
|
239
|
+
mkdirSync(join(dest, "og"), { recursive: true });
|
|
240
|
+
copyFileSync(join(outMetaDir, generatedImageRelative), join(dest, generatedImageRelative));
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
apiJsonPath,
|
|
245
|
+
apiJsonFilename
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
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 };
|