@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
package/Bundler.js
ADDED
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import { BundlerError } from "./BundlerError.js";
|
|
2
|
+
import { MetaConfig } from "./config/BuildConfig.js";
|
|
3
|
+
import { ConfigValidator } from "./config-validation/ConfigValidator.js";
|
|
4
|
+
import { writeResolvedTsconfig } from "./dts/resolved-tsconfig.js";
|
|
5
|
+
import { assertNoEntryCollisions, extractAmbientDts } from "./entries/ambient-dts.js";
|
|
6
|
+
import { deriveExportPaths } from "./entries/export-paths.js";
|
|
7
|
+
import { createEntryName } from "./entries/extract.js";
|
|
8
|
+
import { packageJsonEntries } from "./entries/package-json-entries.js";
|
|
9
|
+
import { ConfigValidationError } from "./errors.js";
|
|
10
|
+
import { normalizeExeOptions } from "./exe/config.js";
|
|
11
|
+
import { computeExeFileName } from "./exe/filename.js";
|
|
12
|
+
import { causeMessage } from "./internal/causeMessage.js";
|
|
13
|
+
import { readTsconfigJsx, resolveJsxConfig } from "./jsx/config.js";
|
|
14
|
+
import { buildEmittedManifest } from "./manifest/emit-manifest.js";
|
|
15
|
+
import { unmatchedExportPatterns } from "./manifest/export-patterns.js";
|
|
16
|
+
import { assertBuildableConditionExports } from "./manifest/transform.js";
|
|
17
|
+
import { OgGenerateError, resolveOgGenerator } from "./meta/og-image.js";
|
|
18
|
+
import { tsdoctorMetaOptionsOf } from "./meta/tsdoctor-config.js";
|
|
19
|
+
import { buildTargetGroups } from "./passes/build-target-groups.js";
|
|
20
|
+
import { normalizeLooseFiles } from "./passes/loose-files.js";
|
|
21
|
+
import { removeDeclarationMaps } from "./passes/strip-maps.js";
|
|
22
|
+
import { BuildCollector } from "./report/collector.js";
|
|
23
|
+
import { writeIssuesArtifact } from "./report/issues-artifact.js";
|
|
24
|
+
import { BuildReport } from "./report/schema.js";
|
|
25
|
+
import { writeTargetsBinding } from "./targets/binding.js";
|
|
26
|
+
import { releaseWarnings, resolveTargets } from "./targets/resolve-targets.js";
|
|
27
|
+
import { Effect, Schema } from "effect";
|
|
28
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
29
|
+
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
30
|
+
|
|
31
|
+
// src/Bundler.ts
|
|
32
|
+
/**
|
|
33
|
+
* A finished build.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
var BundlerBuildResult = class extends Schema.Class("BundlerBuildResult")({
|
|
38
|
+
/** Everything the build recorded. */
|
|
39
|
+
report: BuildReport,
|
|
40
|
+
/** Where `issues.json` was written. */
|
|
41
|
+
issuesPath: Schema.String,
|
|
42
|
+
/** Where `targets.json` was written. */
|
|
43
|
+
targetsPath: Schema.UndefinedOr(Schema.String)
|
|
44
|
+
}) {};
|
|
45
|
+
const defaultRunMetaPass = (options) => import("./meta/run-pass.js").then((module) => module.runMetaPass(options));
|
|
46
|
+
const defaultRunExeBuild = (options) => import("./exe/build.js").then((module) => module.runExeBuild(options));
|
|
47
|
+
/** Reduce a thrown value to the `{ name?, message }` shape the issues artifact stamps on a failed build. */
|
|
48
|
+
function describeFailure(err) {
|
|
49
|
+
if (err instanceof Error) return err.name !== "" ? {
|
|
50
|
+
name: err.name,
|
|
51
|
+
message: err.message
|
|
52
|
+
} : { message: err.message };
|
|
53
|
+
if (typeof err === "object" && err !== null) {
|
|
54
|
+
const rec = err;
|
|
55
|
+
const name = typeof rec._tag === "string" ? rec._tag : typeof rec.name === "string" ? rec.name : void 0;
|
|
56
|
+
const message = typeof rec.message === "string" ? rec.message : String(err);
|
|
57
|
+
return name !== void 0 ? {
|
|
58
|
+
name,
|
|
59
|
+
message
|
|
60
|
+
} : { message };
|
|
61
|
+
}
|
|
62
|
+
return { message: String(err) };
|
|
63
|
+
}
|
|
64
|
+
/** Read and parse package.json at cwd, returning an empty object on any error. */
|
|
65
|
+
function readPackageJson(cwd) {
|
|
66
|
+
try {
|
|
67
|
+
return JSON.parse(readFileSync(join(cwd, "package.json"), "utf-8"));
|
|
68
|
+
} catch {
|
|
69
|
+
return {};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** Write the resolved tsconfig with the resolved JSX settings in `compilerOptions`. */
|
|
73
|
+
function writeTsconfig(cwd, jsx) {
|
|
74
|
+
return writeResolvedTsconfig({
|
|
75
|
+
cwd,
|
|
76
|
+
...jsx?.runtime === "automatic" ? {
|
|
77
|
+
jsx: "react-jsx",
|
|
78
|
+
jsxImportSource: jsx.importSource
|
|
79
|
+
} : {},
|
|
80
|
+
...jsx?.runtime === "classic" ? { jsx: "react" } : {}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/** The publish targets declared in `publishConfig.targets`; only the map form drives multi-target. */
|
|
84
|
+
function readPublishTargets(pkg) {
|
|
85
|
+
const declared = pkg.publishConfig?.targets;
|
|
86
|
+
return declared !== void 0 && !Array.isArray(declared) && typeof declared === "object" ? declared : void 0;
|
|
87
|
+
}
|
|
88
|
+
/** Resolve the prod build groups and the target binding from publishConfig.targets (or the single-npm default). */
|
|
89
|
+
function deriveProdGroups(targets, baseName) {
|
|
90
|
+
const effective = targets !== void 0 && Object.keys(targets).length > 0 ? targets : { npm: true };
|
|
91
|
+
const resolution = resolveTargets({
|
|
92
|
+
targets: effective,
|
|
93
|
+
baseName
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
groups: resolution.groups.map((g) => ({
|
|
97
|
+
id: g.id,
|
|
98
|
+
name: g.name
|
|
99
|
+
})),
|
|
100
|
+
resolution
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const overridesError = (reason) => new ConfigValidationError({
|
|
104
|
+
path: "overrides",
|
|
105
|
+
reason
|
|
106
|
+
});
|
|
107
|
+
/** The partitions, base entries and export-key sets that per-entry overrides produce. */
|
|
108
|
+
function partitionOverrides(config, entries, exportsMap, packageName) {
|
|
109
|
+
const subdirExports = /* @__PURE__ */ new Set();
|
|
110
|
+
if (config.overrides.length === 0) return {
|
|
111
|
+
partitions: [],
|
|
112
|
+
baseEntries: entries,
|
|
113
|
+
dualExports: void 0,
|
|
114
|
+
subdirExports
|
|
115
|
+
};
|
|
116
|
+
const partitions = [];
|
|
117
|
+
const overriddenEntryNames = /* @__PURE__ */ new Set();
|
|
118
|
+
const dualExports = /* @__PURE__ */ new Set();
|
|
119
|
+
const exportPathByEntry = deriveExportPaths(entries, exportsMap);
|
|
120
|
+
for (const ov of config.overrides) {
|
|
121
|
+
if (ov.outSubdir !== void 0 && ov.entries.length !== 1) throw overridesError(`outSubdir "${ov.outSubdir}" must pin exactly one export path (got ${ov.entries.length})`);
|
|
122
|
+
const partEntry = {};
|
|
123
|
+
for (const exportPath of ov.entries) {
|
|
124
|
+
if (exportPath !== "." && !exportPath.startsWith("./")) throw overridesError(`entry "${exportPath}" must be a canonical export path — use "." for the root or a "./"-prefixed subpath (e.g. "./changesets/markdownlint")`);
|
|
125
|
+
const flatName = createEntryName(exportPath, false);
|
|
126
|
+
const src = entries[flatName];
|
|
127
|
+
if (src === void 0) throw overridesError(`export path "${exportPath}" (entry "${flatName}") is not a build entry of ${packageName}`);
|
|
128
|
+
partEntry[ov.outSubdir !== void 0 ? "index" : flatName] = src;
|
|
129
|
+
overriddenEntryNames.add(flatName);
|
|
130
|
+
if (ov.outSubdir !== void 0) subdirExports.add(exportPath);
|
|
131
|
+
if ((ov.format ?? config.format).includes("cjs")) dualExports.add(exportPath);
|
|
132
|
+
}
|
|
133
|
+
partitions.push({
|
|
134
|
+
entry: partEntry,
|
|
135
|
+
...ov.format !== void 0 ? { format: ov.format } : {},
|
|
136
|
+
...ov.externals !== void 0 ? { externals: ov.externals } : {},
|
|
137
|
+
...ov.bundle !== void 0 ? { bundle: ov.bundle } : {},
|
|
138
|
+
...ov.bundleNodeModules !== void 0 ? { bundleNodeModules: ov.bundleNodeModules } : {},
|
|
139
|
+
...ov.bundledPackages !== void 0 ? { bundledPackages: ov.bundledPackages } : {},
|
|
140
|
+
...ov.dtsExternals !== void 0 ? { dtsExternals: ov.dtsExternals } : {},
|
|
141
|
+
...ov.platform !== void 0 ? { platform: ov.platform } : {},
|
|
142
|
+
...ov.css !== void 0 ? { css: ov.css } : {},
|
|
143
|
+
...ov.outSubdir !== void 0 ? { outSubdir: ov.outSubdir } : {}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
const baseEntries = {};
|
|
147
|
+
const baseIsDual = config.format.includes("cjs");
|
|
148
|
+
for (const [name, src] of Object.entries(entries)) {
|
|
149
|
+
if (overriddenEntryNames.has(name)) continue;
|
|
150
|
+
baseEntries[name] = src;
|
|
151
|
+
if (baseIsDual) dualExports.add(exportPathByEntry[name] ?? (name === "index" ? "." : `./${name}`));
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
partitions,
|
|
155
|
+
baseEntries,
|
|
156
|
+
dualExports,
|
|
157
|
+
subdirExports
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/** Refuses a `copy` the build could not honour: no JS pass to run it, or a destination outside `pkg/`. */
|
|
161
|
+
function validateCopy(config, hasJsEntries) {
|
|
162
|
+
if (config.copy.length === 0) return;
|
|
163
|
+
if (!hasJsEntries && config.exe !== void 0) throw new ConfigValidationError({
|
|
164
|
+
path: "copy",
|
|
165
|
+
reason: "a package that only compiles a binary runs no JS pass, so nothing would copy these files"
|
|
166
|
+
});
|
|
167
|
+
for (const entry of config.copy) {
|
|
168
|
+
if (typeof entry === "string" || entry.to === void 0) continue;
|
|
169
|
+
const fromPkg = relative("/pkg", resolve("/pkg", entry.to));
|
|
170
|
+
if (isAbsolute(entry.to) || fromPkg === ".." || fromPkg.startsWith(`..${sep}`)) throw new ConfigValidationError({
|
|
171
|
+
path: "copy",
|
|
172
|
+
reason: `"to" must stay inside the group's pkg/ directory (got "${entry.to}")`
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/** A decoded empty `[package.build.meta]` table, which a config that never wrote one also decodes to. */
|
|
177
|
+
const defaultMetaFingerprint = JSON.stringify(Schema.decodeUnknownSync(MetaConfig)({}));
|
|
178
|
+
/**
|
|
179
|
+
* The generator the tsdoctor table names, if any. A failure is named in `issues.json` the way the meta pass names a
|
|
180
|
+
* renderer failure, since it never reaches that pass.
|
|
181
|
+
*/
|
|
182
|
+
async function resolveConfiguredGenerator(options, packageName, groups, collector, seams) {
|
|
183
|
+
const name = options.tsdoctor?.openGraph?.generate;
|
|
184
|
+
if (name === void 0) return void 0;
|
|
185
|
+
try {
|
|
186
|
+
return await Effect.runPromise(resolveOgGenerator(name, {
|
|
187
|
+
packageName,
|
|
188
|
+
...seams.importOgPeer !== void 0 ? { importModule: seams.importOgPeer } : {}
|
|
189
|
+
}));
|
|
190
|
+
} catch (err) {
|
|
191
|
+
if (err instanceof OgGenerateError) for (const g of groups) collector.recordError(g.id, {
|
|
192
|
+
source: "meta",
|
|
193
|
+
level: "error",
|
|
194
|
+
code: "og-generate-failed",
|
|
195
|
+
text: err.message
|
|
196
|
+
});
|
|
197
|
+
throw err;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* The orchestration, in plain async code over the ported modules. A thrown value reaches the Effect boundary in
|
|
202
|
+
* {@link Bundler.build}; the issues artifact is written on the way out of either terminal path.
|
|
203
|
+
*/
|
|
204
|
+
async function runBuild(options, collector, progress) {
|
|
205
|
+
const { cwd, config, noExe, verbose, seams = {} } = options;
|
|
206
|
+
let issuesPath = join(cwd, "dist", "prod", "issues.json");
|
|
207
|
+
const writeIssuesBestEffort = (err) => {
|
|
208
|
+
try {
|
|
209
|
+
const written = (seams.writeIssues ?? writeIssuesArtifact)({
|
|
210
|
+
cwd,
|
|
211
|
+
target: "prod",
|
|
212
|
+
reports: collector.snapshot(progress.packageName),
|
|
213
|
+
buildOk: err === void 0,
|
|
214
|
+
...err !== void 0 ? { failure: describeFailure(err) } : {}
|
|
215
|
+
});
|
|
216
|
+
if (written !== void 0) issuesPath = written;
|
|
217
|
+
} catch {}
|
|
218
|
+
};
|
|
219
|
+
try {
|
|
220
|
+
const pkg = (seams.readPackageJson ?? readPackageJson)(cwd);
|
|
221
|
+
const version = pkg.version ?? "0.0.0";
|
|
222
|
+
const packageName = pkg.name ?? "unknown";
|
|
223
|
+
progress.packageName = packageName;
|
|
224
|
+
const jsx = resolveJsxConfig((seams.readTsconfigJsx ?? readTsconfigJsx)(cwd), config.jsx);
|
|
225
|
+
const tsconfigPath = (seams.writeTsconfig ?? writeTsconfig)(cwd, jsx);
|
|
226
|
+
const exportsMap = pkg.exports;
|
|
227
|
+
const publishTargets = readPublishTargets(pkg);
|
|
228
|
+
const osCpu = {
|
|
229
|
+
os: pkg.os ?? [],
|
|
230
|
+
cpu: pkg.cpu ?? []
|
|
231
|
+
};
|
|
232
|
+
const meta = config.meta === false ? void 0 : {
|
|
233
|
+
localPaths: config.meta.localPaths,
|
|
234
|
+
optimistic: config.meta.optimistic === "auto" ? !options.ci : config.meta.optimistic,
|
|
235
|
+
tsdoc: config.meta.tsdoc
|
|
236
|
+
};
|
|
237
|
+
const hasLooseFiles = Object.keys(config.looseFiles).length > 0;
|
|
238
|
+
const metaIsExplicit = config.meta !== false && JSON.stringify(config.meta) !== defaultMetaFingerprint;
|
|
239
|
+
await Effect.runPromise(Effect.flatMap(ConfigValidator, (v) => v.validate({
|
|
240
|
+
baseName: packageName,
|
|
241
|
+
hasExports: exportsMap !== void 0 && Object.keys(exportsMap).length > 0,
|
|
242
|
+
...publishTargets !== void 0 ? { targets: publishTargets } : {},
|
|
243
|
+
...config.exe !== void 0 ? { exe: config.exe } : {},
|
|
244
|
+
osCpu,
|
|
245
|
+
...meta !== void 0 && metaIsExplicit ? { meta: {
|
|
246
|
+
...meta,
|
|
247
|
+
localPaths: meta.localPaths?.map((path) => resolve(cwd, path))
|
|
248
|
+
} } : {},
|
|
249
|
+
...hasLooseFiles ? { looseFiles: config.looseFiles } : {}
|
|
250
|
+
})).pipe(Effect.provide(ConfigValidator.layer)));
|
|
251
|
+
const exeSpecs = config.exe !== void 0 ? normalizeExeOptions(config.exe, osCpu) : [];
|
|
252
|
+
if (config.exe !== void 0 && (exeSpecs.length !== 1 || (exeSpecs[0]?.targets.length ?? 0) !== 1)) throw new ConfigValidationError({
|
|
253
|
+
path: "exe",
|
|
254
|
+
reason: `exe build requires exactly one binary with one target (got ${exeSpecs.length} spec(s), ${exeSpecs[0]?.targets.length ?? 0} target(s) on the first). A package's exports["."] resolves to a single SEA — cross-platform binaries must each ship as their own per-platform package.`
|
|
255
|
+
});
|
|
256
|
+
const exeSpec = exeSpecs[0];
|
|
257
|
+
const exeTarget = exeSpec?.targets[0];
|
|
258
|
+
const exeFileName = exeSpec && exeTarget ? computeExeFileName(exeSpec.fileName, exeTarget) : void 0;
|
|
259
|
+
const exeEntrySource = exeSpec?.entry ?? "./src/bin.ts";
|
|
260
|
+
const exeRewrite = config.exe !== void 0 && exeFileName !== void 0 ? {
|
|
261
|
+
source: exeEntrySource,
|
|
262
|
+
fileName: exeFileName,
|
|
263
|
+
dir: "bin"
|
|
264
|
+
} : void 0;
|
|
265
|
+
const entries = packageJsonEntries({
|
|
266
|
+
pkg: {
|
|
267
|
+
exports: pkg.exports,
|
|
268
|
+
bin: pkg.bin
|
|
269
|
+
},
|
|
270
|
+
...config.exe !== void 0 ? { excludeSources: [exeEntrySource] } : {}
|
|
271
|
+
});
|
|
272
|
+
const hasJsEntries = Object.keys(entries).length > 0;
|
|
273
|
+
const ambient = extractAmbientDts({
|
|
274
|
+
exports: pkg.exports,
|
|
275
|
+
bin: pkg.bin
|
|
276
|
+
}, {});
|
|
277
|
+
assertNoEntryCollisions(Object.keys(entries), ambient);
|
|
278
|
+
assertBuildableConditionExports(pkg.exports, config.exe !== void 0 ? { exeSource: exeEntrySource } : {});
|
|
279
|
+
if (ambient.length > 0 && !hasJsEntries && config.exe === void 0) throw new ConfigValidationError({
|
|
280
|
+
path: "exports",
|
|
281
|
+
reason: "a types-only package with only ambient .d.ts exports is not supported — add at least one JS entry (or an exe) alongside the ambient declarations"
|
|
282
|
+
});
|
|
283
|
+
validateCopy(config, hasJsEntries);
|
|
284
|
+
const { partitions, baseEntries, dualExports, subdirExports } = partitionOverrides(config, entries, exportsMap, packageName);
|
|
285
|
+
const looseFiles = hasLooseFiles ? normalizeLooseFiles(config.looseFiles) : void 0;
|
|
286
|
+
const { groups, resolution } = deriveProdGroups(publishTargets, packageName);
|
|
287
|
+
const anchor = resolution.groups[0]?.id ?? "npm";
|
|
288
|
+
for (const text of releaseWarnings(resolution)) collector.recordWarning(anchor, {
|
|
289
|
+
source: "config",
|
|
290
|
+
level: "warn",
|
|
291
|
+
code: "targets-no-final-release",
|
|
292
|
+
text
|
|
293
|
+
});
|
|
294
|
+
if (hasJsEntries || config.exe === void 0) {
|
|
295
|
+
progress.phase = "js";
|
|
296
|
+
await (seams.buildTargetGroups ?? buildTargetGroups)({
|
|
297
|
+
cwd,
|
|
298
|
+
version,
|
|
299
|
+
entry: baseEntries,
|
|
300
|
+
tsconfigPath,
|
|
301
|
+
groups,
|
|
302
|
+
devManifest: "preserve",
|
|
303
|
+
externals: config.externals,
|
|
304
|
+
drop: config.manifest.drop,
|
|
305
|
+
format: config.format,
|
|
306
|
+
emitDts: config.emitDts,
|
|
307
|
+
emitDeclarations: true,
|
|
308
|
+
collector,
|
|
309
|
+
verbose,
|
|
310
|
+
onPass: (pass) => {
|
|
311
|
+
progress.phase = pass === "dts" ? "dts" : "js";
|
|
312
|
+
},
|
|
313
|
+
...config.bundledPackages.length > 0 ? { bundledPackages: config.bundledPackages } : {},
|
|
314
|
+
...config.dtsExternals.length > 0 ? { dtsExternals: config.dtsExternals } : {},
|
|
315
|
+
...config.bundleNodeModules ? { bundleNodeModules: true } : {},
|
|
316
|
+
...config.bundle.length > 0 ? { bundle: config.bundle } : {},
|
|
317
|
+
...config.minify ? { minify: true } : {},
|
|
318
|
+
...Object.keys(config.define).length > 0 ? { define: config.define } : {},
|
|
319
|
+
...partitions.length > 0 ? { overrides: partitions } : {},
|
|
320
|
+
...dualExports !== void 0 ? { dualExports } : {},
|
|
321
|
+
...subdirExports.size > 0 ? { subdirExports } : {},
|
|
322
|
+
...looseFiles !== void 0 ? { looseFiles } : {},
|
|
323
|
+
...config.copy.length > 0 ? { copy: config.copy } : {},
|
|
324
|
+
...options.plugins.length > 0 ? { extraPlugins: options.plugins } : {},
|
|
325
|
+
...exeRewrite !== void 0 ? { exeRewrite } : {}
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
progress.phase = "manifest";
|
|
329
|
+
const targetsPath = (seams.writeTargetsBinding ?? writeTargetsBinding)(cwd, resolution);
|
|
330
|
+
if (meta !== void 0 && config.emitDts && (config.exe === void 0 || hasJsEntries)) {
|
|
331
|
+
progress.phase = "meta";
|
|
332
|
+
const generate = await resolveConfiguredGenerator(options, packageName, groups, collector, seams);
|
|
333
|
+
const tsdoctor = options.tsdoctor !== void 0 ? tsdoctorMetaOptionsOf(options.tsdoctor, generate) : void 0;
|
|
334
|
+
await (seams.runMetaPass ?? defaultRunMetaPass)({
|
|
335
|
+
cwd,
|
|
336
|
+
packageName,
|
|
337
|
+
tsconfigPath,
|
|
338
|
+
groups,
|
|
339
|
+
entries,
|
|
340
|
+
exportsMap,
|
|
341
|
+
overrides: config.overrides,
|
|
342
|
+
meta: {
|
|
343
|
+
...meta,
|
|
344
|
+
...tsdoctor !== void 0 ? { tsdoctor } : {}
|
|
345
|
+
},
|
|
346
|
+
collector,
|
|
347
|
+
ci: options.ci,
|
|
348
|
+
targets: resolution.targets,
|
|
349
|
+
...seams.generateMeta !== void 0 ? { generateMeta: seams.generateMeta } : {},
|
|
350
|
+
...seams.resolveNextVersions !== void 0 ? { resolveNextVersions: seams.resolveNextVersions } : {}
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
progress.phase = "dts";
|
|
354
|
+
for (const g of groups) removeDeclarationMaps(join(cwd, "dist", "prod", g.id, "pkg"));
|
|
355
|
+
if (exeSpec !== void 0 && exeRewrite !== void 0 && exeFileName !== void 0) for (const g of groups) {
|
|
356
|
+
const outDir = join(cwd, "dist", "prod", g.id, "pkg");
|
|
357
|
+
if (!hasJsEntries) {
|
|
358
|
+
progress.phase = "manifest";
|
|
359
|
+
const manifest = await buildEmittedManifest({
|
|
360
|
+
pkg,
|
|
361
|
+
cwd,
|
|
362
|
+
targetGroup: {
|
|
363
|
+
id: g.id,
|
|
364
|
+
name: g.name,
|
|
365
|
+
isProd: true
|
|
366
|
+
},
|
|
367
|
+
devManifest: "preserve",
|
|
368
|
+
drop: config.manifest.drop,
|
|
369
|
+
exeRewrite
|
|
370
|
+
});
|
|
371
|
+
mkdirSync(outDir, { recursive: true });
|
|
372
|
+
writeFileSync(join(outDir, "package.json"), `${JSON.stringify(manifest, null, " ")}\n`);
|
|
373
|
+
for (const file of ["LICENSE", "README.md"]) try {
|
|
374
|
+
copyFileSync(join(cwd, file), join(outDir, file));
|
|
375
|
+
} catch {}
|
|
376
|
+
}
|
|
377
|
+
if (!noExe) {
|
|
378
|
+
progress.phase = "exe";
|
|
379
|
+
const binDir = join(outDir, "bin");
|
|
380
|
+
await (seams.runExeBuild ?? defaultRunExeBuild)({
|
|
381
|
+
cwd,
|
|
382
|
+
outDir: binDir,
|
|
383
|
+
specs: exeSpecs,
|
|
384
|
+
collector,
|
|
385
|
+
groupId: g.id,
|
|
386
|
+
verbose
|
|
387
|
+
});
|
|
388
|
+
if (seams.runExeBuild === void 0 && !existsSync(join(binDir, exeFileName))) throw new Error(`exe: expected compiled binary at ${join(binDir, exeFileName)} but it is missing — tsdown's emitted name may have drifted from computeExeFileName`);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
const exeExportPath = exeRewrite !== void 0 ? `./${exeRewrite.dir}/${exeRewrite.fileName}` : void 0;
|
|
392
|
+
for (const g of groups) for (const { field, key, target } of unmatchedExportPatterns(join(cwd, "dist", "prod", g.id, "pkg"), { ...exeExportPath !== void 0 ? { ignore: [exeExportPath] } : {} })) collector.recordWarning(g.id, {
|
|
393
|
+
source: "config",
|
|
394
|
+
level: "warn",
|
|
395
|
+
code: "exports-pattern-unmatched",
|
|
396
|
+
text: field === "bin" ? `The bin "${key}" points at "${target}", which is not a file in the emitted package. Point it at a source the build emits, or ship the file from public/ or with [package.build] copy.` : target.includes("*") ? `The exports pattern "${key}" points at "${target}", which matches no file in the emitted package. Ship the files from public/ or with [package.build] copy.` : `The export "${key}" points at "${target}", which is not a file in the emitted package. Point it at a source the build emits, or ship the file from public/ or with [package.build] copy.`
|
|
397
|
+
});
|
|
398
|
+
writeIssuesBestEffort();
|
|
399
|
+
return {
|
|
400
|
+
issuesPath,
|
|
401
|
+
targetsPath
|
|
402
|
+
};
|
|
403
|
+
} catch (err) {
|
|
404
|
+
writeIssuesBestEffort(err);
|
|
405
|
+
throw err;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Builds one package: the JS and declaration passes for every publish group, the emitted manifest,
|
|
410
|
+
* `dist/prod/targets.json`, the API model, an optional SEA binary, and `dist/prod/issues.json`.
|
|
411
|
+
*
|
|
412
|
+
* @public
|
|
413
|
+
*/
|
|
414
|
+
var Bundler = class {
|
|
415
|
+
/**
|
|
416
|
+
* Runs a build of the package at `options.cwd`, writing into its `dist/prod`.
|
|
417
|
+
*
|
|
418
|
+
* @remarks
|
|
419
|
+
* It writes nothing to stdout; rendering the report belongs to the caller. A structurally invalid config fails
|
|
420
|
+
* {@link ConfigValidationError} before any build work, and anything thrown afterwards fails
|
|
421
|
+
* {@link BundlerError} naming the phase. Both paths write `issues.json` stamped `buildOk: false` first.
|
|
422
|
+
*/
|
|
423
|
+
static build = Effect.fn("Bundler.build")(function* (options) {
|
|
424
|
+
const collector = new BuildCollector();
|
|
425
|
+
const progress = {
|
|
426
|
+
phase: "validate",
|
|
427
|
+
packageName: "unknown"
|
|
428
|
+
};
|
|
429
|
+
const snapshot = () => collector.snapshot(progress.packageName)[0] ?? BuildReport.make({
|
|
430
|
+
package: progress.packageName,
|
|
431
|
+
targetGroups: []
|
|
432
|
+
});
|
|
433
|
+
const { issuesPath, targetsPath } = yield* Effect.tryPromise({
|
|
434
|
+
try: () => runBuild(options, collector, progress),
|
|
435
|
+
catch: (cause) => cause instanceof ConfigValidationError ? cause : BundlerError.make({
|
|
436
|
+
phase: progress.phase,
|
|
437
|
+
message: causeMessage(cause) ?? String(cause),
|
|
438
|
+
cause,
|
|
439
|
+
report: snapshot()
|
|
440
|
+
})
|
|
441
|
+
});
|
|
442
|
+
return BundlerBuildResult.make({
|
|
443
|
+
report: snapshot(),
|
|
444
|
+
issuesPath,
|
|
445
|
+
targetsPath
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
export { Bundler, BundlerBuildResult };
|
package/BundlerError.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { BuildReport } from "./report/schema.js";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
|
|
4
|
+
// src/BundlerError.ts
|
|
5
|
+
/**
|
|
6
|
+
* The part of a build a {@link BundlerError} failed in.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
const BundlerPhase = Schema.Literals([
|
|
11
|
+
"validate",
|
|
12
|
+
"js",
|
|
13
|
+
"dts",
|
|
14
|
+
"meta",
|
|
15
|
+
"exe",
|
|
16
|
+
"manifest"
|
|
17
|
+
]);
|
|
18
|
+
/**
|
|
19
|
+
* A build ended before it finished.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* `report` is the collector's snapshot at the moment of failure, so a caller can still render the diagnostics
|
|
23
|
+
* the build gathered. `dist/prod/issues.json` was written with `buildOk: false` before this failure was raised,
|
|
24
|
+
* unless writing it failed too.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
var BundlerError = class extends Schema.TaggedError()("BundlerError", {
|
|
29
|
+
/** The part of the build that failed. */
|
|
30
|
+
phase: BundlerPhase,
|
|
31
|
+
/** What went wrong, read from the thrown value and its cause chain. */
|
|
32
|
+
message: Schema.String,
|
|
33
|
+
/** The thrown value, carried structurally. */
|
|
34
|
+
cause: Schema.optionalKey(Schema.Defect()),
|
|
35
|
+
/** Everything the build recorded before it failed. */
|
|
36
|
+
report: BuildReport
|
|
37
|
+
}) {};
|
|
38
|
+
|
|
39
|
+
export { BundlerError, BundlerPhase };
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 C. Spencer Beggs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,85 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @effected/bundler
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@effected/bundler)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://nodejs.org/)
|
|
6
|
+
|
|
7
|
+
The build pipeline of the `@effected/*` kit as a library. Give it a package directory and a decoded `effected.toml`, and it writes what a release packs: per-module JS and rolled-up declarations through tsdown, the publishable `package.json`, an API Extractor model with its `tsdoctor.json` manifest, an optional single-executable binary, and a structured `issues.json`.
|
|
8
|
+
|
|
9
|
+
> **Pre-`1.0.0`.** This package is part of the `@effected/*` kit, built on stable
|
|
10
|
+
> Effect v4 and still in `0.x` development. Pin an exact version: even a package
|
|
11
|
+
> marked *stable* before `1.0.0` can introduce a breaking change by accident, and
|
|
12
|
+
> an exact pin turns that into a type-check error rather than a runtime surprise.
|
|
13
|
+
> Full policy: [release strategy](https://github.com/spencerbeggs/effected#release-strategy).
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @effected/bundler effect typescript
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Requires Node.js >=24.11.0. `effect` and `typescript` are peer dependencies. To generate an Open Graph image, also install the optional peers `satori` and `@resvg/resvg-js`. All `@effected/*` packages are ESM-only.
|
|
22
|
+
|
|
23
|
+
## Quick start
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { NodeFileSystem, NodePath } from "@effect/platform-node";
|
|
27
|
+
import { Bundler, EffectedConfigFile } from "@effected/bundler";
|
|
28
|
+
import { WorkspaceDiscovery, WorkspaceRoot } from "@effected/workspaces";
|
|
29
|
+
import { Effect, Layer } from "effect";
|
|
30
|
+
|
|
31
|
+
const platform = Layer.merge(NodeFileSystem.layer, NodePath.layer);
|
|
32
|
+
const discovery = WorkspaceDiscovery.layer().pipe(
|
|
33
|
+
Layer.provideMerge(WorkspaceRoot.layer),
|
|
34
|
+
Layer.provideMerge(platform),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const program = Effect.gen(function* () {
|
|
38
|
+
const cwd = process.cwd();
|
|
39
|
+
const { config } = yield* EffectedConfigFile.load({ cwd });
|
|
40
|
+
const result = yield* Bundler.build({
|
|
41
|
+
cwd,
|
|
42
|
+
config: config.package.build,
|
|
43
|
+
tsdoctor: config.package.tsdoctor,
|
|
44
|
+
noExe: false,
|
|
45
|
+
verbose: false,
|
|
46
|
+
plugins: [],
|
|
47
|
+
ci: Boolean(process.env.CI),
|
|
48
|
+
});
|
|
49
|
+
return result.issuesPath;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
Effect.runPromise(program.pipe(Effect.provide(discovery))).then(console.log);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## What it writes
|
|
56
|
+
|
|
57
|
+
All under the package:
|
|
58
|
+
|
|
59
|
+
| Path | What it is |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| `dist/prod/<group>/pkg` | the directory to publish, one per publish target group |
|
|
62
|
+
| `dist/prod/<group>/meta` | the `.api.json` model, `package.json`, a portable `tsconfig.json`, `tsdoctor.json` and any Open Graph image |
|
|
63
|
+
| `dist/prod/targets.json` | which target publishes which group |
|
|
64
|
+
| `dist/prod/issues.json` | every diagnostic, and whether the build finished |
|
|
65
|
+
|
|
66
|
+
Gate on `issues.json`'s `buildOk` first, never on an empty `errors` list: the file is written on failure too, and a crash can leave every bucket empty.
|
|
67
|
+
|
|
68
|
+
## Failures
|
|
69
|
+
|
|
70
|
+
`Bundler.build` fails with one of two typed errors, and writes `issues.json` stamped `buildOk: false` before either:
|
|
71
|
+
|
|
72
|
+
- `ConfigValidationError`: the config cannot describe a build. Nothing was built.
|
|
73
|
+
- `BundlerError`: something failed during the build. Its `phase` names where (`validate`, `js`, `dts`, `meta`, `exe` or `manifest`) and its `report` carries what the build had recorded, so you can still render it.
|
|
74
|
+
|
|
75
|
+
The module writes nothing to stdout. Rendering the report is the caller's.
|
|
76
|
+
|
|
77
|
+
## Limits
|
|
78
|
+
|
|
79
|
+
- `cwd` must be an absolute path.
|
|
80
|
+
- `bundledPackages` cannot name a workspace sibling that resolves to its TypeScript source: the build fails, because the declaration generator covers only the package's own project.
|
|
81
|
+
- API Extractor reporting `ae-wrong-input-file-type` about a file outside the package, as it does for a sibling resolved to source, is recorded as suppressed. About a file inside the package, it stays a warning.
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
[MIT](./LICENSE)
|