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