@effected/bundler 0.1.0 → 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 +126 -78
- package/README.md +3 -3
- package/action/ActionBundle.js +89 -78
- package/action/import-check.js +2 -2
- package/config/BuildConfig.js +26 -15
- package/config/EffectedConfigFile.js +12 -1
- package/config-validation/ConfigValidator.js +20 -14
- package/dts/resolved-tsconfig.js +1 -1
- package/errors.js +3 -3
- package/exe/build.js +1 -1
- package/index.d.ts +180 -480
- package/index.js +6 -7
- package/journal/BuildJournal.js +13 -14
- package/jsx/config.js +13 -20
- package/manifest/built-condition.js +120 -0
- package/manifest/emit-manifest.js +7 -2
- package/manifest/export-patterns.js +14 -16
- package/manifest/manifest-set.js +101 -0
- package/manifest/transform.js +1 -0
- package/meta/api-extractor.js +1 -1
- package/meta/{tsdoctor-config.js → bundle-config.js} +4 -4
- package/meta/{tsdoctor-manifest.js → bundle-manifest.js} +5 -5
- package/meta/{tsdoctor-source.js → bundle-source.js} +27 -15
- package/meta/config.js +1 -1
- package/meta/generate.js +19 -16
- package/meta/og-image.js +1 -1
- package/meta/og-satori.js +2 -2
- package/meta/run-pass.js +18 -11
- package/meta/tsdoc-config.js +1 -1
- package/package.json +6 -5
- package/passes/build-target-groups.js +1 -0
- package/passes/strip-maps.js +16 -15
- package/report/issues-artifact.js +10 -16
- package/report/schema.js +1 -1
- package/targets/binding.js +10 -9
- package/meta/BundleManifest.js +0 -208
- package/meta/ManifestSource.js +0 -37
package/Bundler.js
CHANGED
|
@@ -11,11 +11,13 @@ import { normalizeExeOptions } from "./exe/config.js";
|
|
|
11
11
|
import { computeExeFileName } from "./exe/filename.js";
|
|
12
12
|
import { causeMessage } from "./internal/causeMessage.js";
|
|
13
13
|
import { readTsconfigJsx, resolveJsxConfig } from "./jsx/config.js";
|
|
14
|
+
import { builtConditionTargets, mismatchedBuiltTargets, stripBuiltCondition } from "./manifest/built-condition.js";
|
|
14
15
|
import { buildEmittedManifest } from "./manifest/emit-manifest.js";
|
|
15
16
|
import { unmatchedExportPatterns } from "./manifest/export-patterns.js";
|
|
17
|
+
import { emittedPackageName, validateManifestSet } from "./manifest/manifest-set.js";
|
|
16
18
|
import { assertBuildableConditionExports } from "./manifest/transform.js";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
+
import { bundleMetaOptionsOf } from "./meta/bundle-config.js";
|
|
20
|
+
import { resolveOgGenerator } from "./meta/og-image.js";
|
|
19
21
|
import { buildTargetGroups } from "./passes/build-target-groups.js";
|
|
20
22
|
import { normalizeLooseFiles } from "./passes/loose-files.js";
|
|
21
23
|
import { removeDeclarationMaps } from "./passes/strip-maps.js";
|
|
@@ -24,9 +26,9 @@ import { writeIssuesArtifact } from "./report/issues-artifact.js";
|
|
|
24
26
|
import { BuildReport } from "./report/schema.js";
|
|
25
27
|
import { writeTargetsBinding } from "./targets/binding.js";
|
|
26
28
|
import { releaseWarnings, resolveTargets } from "./targets/resolve-targets.js";
|
|
27
|
-
import { Effect, Schema } from "effect";
|
|
28
|
-
import
|
|
29
|
-
import
|
|
29
|
+
import { Cause, Effect, Exit, Schema } from "effect";
|
|
30
|
+
import * as Fs from "effect/FileSystem";
|
|
31
|
+
import * as PathService from "effect/Path";
|
|
30
32
|
|
|
31
33
|
// src/Bundler.ts
|
|
32
34
|
/**
|
|
@@ -61,14 +63,10 @@ function describeFailure(err) {
|
|
|
61
63
|
}
|
|
62
64
|
return { message: String(err) };
|
|
63
65
|
}
|
|
64
|
-
/** Read and parse
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
} catch {
|
|
69
|
-
return {};
|
|
70
|
-
}
|
|
71
|
-
}
|
|
66
|
+
/** Read and parse a JSON file, answering `undefined` on any error. */
|
|
67
|
+
const readJsonOrUndefined = (file) => Effect.flatMap(Fs.FileSystem, (fs) => fs.readFileString(file).pipe(Effect.flatMap((text) => Effect.try(() => JSON.parse(text))), Effect.orElseSucceed(() => void 0)));
|
|
68
|
+
/** Read and parse package.json at cwd, answering an empty object on any error. */
|
|
69
|
+
const readPackageJson = (cwd, path) => Effect.map(readJsonOrUndefined(path.join(cwd, "package.json")), (pkg) => pkg ?? {});
|
|
72
70
|
/** Write the resolved tsconfig with the resolved JSX settings in `compilerOptions`. */
|
|
73
71
|
function writeTsconfig(cwd, jsx) {
|
|
74
72
|
return writeResolvedTsconfig({
|
|
@@ -158,7 +156,8 @@ function partitionOverrides(config, entries, exportsMap, packageName) {
|
|
|
158
156
|
};
|
|
159
157
|
}
|
|
160
158
|
/** Refuses a `copy` the build could not honour: no JS pass to run it, or a destination outside `pkg/`. */
|
|
161
|
-
function validateCopy(config, hasJsEntries) {
|
|
159
|
+
function validateCopy(config, hasJsEntries, path) {
|
|
160
|
+
const { isAbsolute, relative, resolve, sep } = path;
|
|
162
161
|
if (config.copy.length === 0) return;
|
|
163
162
|
if (!hasJsEntries && config.exe !== void 0) throw new ConfigValidationError({
|
|
164
163
|
path: "copy",
|
|
@@ -173,55 +172,81 @@ function validateCopy(config, hasJsEntries) {
|
|
|
173
172
|
});
|
|
174
173
|
}
|
|
175
174
|
}
|
|
175
|
+
/** The `exports` of a group's emitted manifest, or `undefined` when there is none to read. */
|
|
176
|
+
const readEmittedExports = (cwd, groupId, path) => Effect.map(readJsonOrUndefined(path.join(cwd, "dist", "prod", groupId, "pkg", "package.json")), (manifest) => typeof manifest === "object" && manifest !== null ? manifest.exports : void 0);
|
|
177
|
+
/**
|
|
178
|
+
* The optimistic next-version read for a package `set.name` renames: changesets key the release by the workspace
|
|
179
|
+
* package's own name, so the emitted name takes that entry's version.
|
|
180
|
+
*/
|
|
181
|
+
function aliasNextVersions(seam, sourceName, emittedName) {
|
|
182
|
+
const read = seam ?? ((cwd) => import("./changesets/next-versions.js").then((module) => module.resolveNextVersions(cwd)));
|
|
183
|
+
return async (cwd) => {
|
|
184
|
+
const { versions } = await read(cwd);
|
|
185
|
+
const own = versions.get(sourceName);
|
|
186
|
+
if (own === void 0) return { versions };
|
|
187
|
+
const aliased = new Map(versions);
|
|
188
|
+
aliased.set(emittedName, own);
|
|
189
|
+
return { versions: aliased };
|
|
190
|
+
};
|
|
191
|
+
}
|
|
176
192
|
/** A decoded empty `[package.build.meta]` table, which a config that never wrote one also decodes to. */
|
|
177
193
|
const defaultMetaFingerprint = JSON.stringify(Schema.decodeUnknownSync(MetaConfig)({}));
|
|
178
194
|
/**
|
|
179
|
-
* The generator the
|
|
195
|
+
* The generator the bundle table names, if any. A failure is named in `issues.json` the way the meta pass names a
|
|
180
196
|
* renderer failure, since it never reaches that pass.
|
|
181
197
|
*/
|
|
182
|
-
|
|
183
|
-
const name = options.
|
|
184
|
-
if (name === void 0) return void 0;
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
} catch (err) {
|
|
191
|
-
if (err instanceof OgGenerateError) for (const g of groups) collector.recordError(g.id, {
|
|
198
|
+
function resolveConfiguredGenerator(options, packageName, groups, collector, seams) {
|
|
199
|
+
const name = options.bundle?.openGraph?.generate;
|
|
200
|
+
if (name === void 0) return Effect.succeed(void 0);
|
|
201
|
+
return resolveOgGenerator(name, {
|
|
202
|
+
packageName,
|
|
203
|
+
...seams.importOgPeer !== void 0 ? { importModule: seams.importOgPeer } : {}
|
|
204
|
+
}).pipe(Effect.tapError((err) => Effect.sync(() => {
|
|
205
|
+
for (const g of groups) collector.recordError(g.id, {
|
|
192
206
|
source: "meta",
|
|
193
207
|
level: "error",
|
|
194
208
|
code: "og-generate-failed",
|
|
195
209
|
text: err.message
|
|
196
210
|
});
|
|
197
|
-
|
|
198
|
-
}
|
|
211
|
+
})));
|
|
199
212
|
}
|
|
200
213
|
/**
|
|
201
|
-
* The orchestration
|
|
202
|
-
*
|
|
214
|
+
* The orchestration. Its own reads and writes go through `FileSystem` and `Path`; the passes it hands to tsdown,
|
|
215
|
+
* API Extractor and the SEA compiler stay promise-returning and are awaited through `Effect.promise`, so a rejection
|
|
216
|
+
* reaches {@link Bundler.build} as the thrown value itself. A ported module's synchronous throw is a defect for the
|
|
217
|
+
* same reason. The issues artifact is written on the way out of either terminal path.
|
|
203
218
|
*/
|
|
204
|
-
|
|
219
|
+
const runBuild = Effect.fnUntraced(function* (options, collector, progress) {
|
|
205
220
|
const { cwd, config, noExe, verbose, seams = {} } = options;
|
|
221
|
+
const fs = yield* Fs.FileSystem;
|
|
222
|
+
const path = yield* PathService.Path;
|
|
223
|
+
const { join, resolve } = path;
|
|
206
224
|
let issuesPath = join(cwd, "dist", "prod", "issues.json");
|
|
207
225
|
const writeIssuesBestEffort = (err) => {
|
|
208
|
-
|
|
209
|
-
const
|
|
226
|
+
return Effect.suspend(() => {
|
|
227
|
+
const input = {
|
|
210
228
|
cwd,
|
|
211
229
|
target: "prod",
|
|
212
230
|
reports: collector.snapshot(progress.packageName),
|
|
213
231
|
buildOk: err === void 0,
|
|
214
232
|
...err !== void 0 ? { failure: describeFailure(err) } : {}
|
|
215
|
-
}
|
|
233
|
+
};
|
|
234
|
+
return seams.writeIssues !== void 0 ? Effect.sync(() => seams.writeIssues?.(input)) : writeIssuesArtifact(input);
|
|
235
|
+
}).pipe(Effect.tap((written) => Effect.sync(() => {
|
|
216
236
|
if (written !== void 0) issuesPath = written;
|
|
217
|
-
}
|
|
237
|
+
})), Effect.catchCause(() => Effect.void));
|
|
218
238
|
};
|
|
219
|
-
|
|
220
|
-
const
|
|
221
|
-
const version =
|
|
222
|
-
const
|
|
223
|
-
progress.packageName =
|
|
224
|
-
|
|
239
|
+
const exit = yield* Effect.exit(Effect.gen(function* () {
|
|
240
|
+
const sourcePkg = seams.readPackageJson !== void 0 ? seams.readPackageJson(cwd) : yield* readPackageJson(cwd, path);
|
|
241
|
+
const version = sourcePkg.version ?? "0.0.0";
|
|
242
|
+
const sourceName = sourcePkg.name ?? "unknown";
|
|
243
|
+
progress.packageName = sourceName;
|
|
244
|
+
validateManifestSet(config.manifest.set, config.manifest.drop);
|
|
245
|
+
const packageName = emittedPackageName(config.manifest.set, sourceName);
|
|
246
|
+
const builtTargets = builtConditionTargets(sourcePkg.exports);
|
|
247
|
+
const pkg = stripBuiltCondition(sourcePkg);
|
|
248
|
+
const tsconfigJsx = seams.readTsconfigJsx !== void 0 ? seams.readTsconfigJsx(cwd) : yield* readTsconfigJsx(cwd);
|
|
249
|
+
const jsx = resolveJsxConfig(tsconfigJsx, config.jsx);
|
|
225
250
|
const tsconfigPath = (seams.writeTsconfig ?? writeTsconfig)(cwd, jsx);
|
|
226
251
|
const exportsMap = pkg.exports;
|
|
227
252
|
const publishTargets = readPublishTargets(pkg);
|
|
@@ -236,7 +261,7 @@ async function runBuild(options, collector, progress) {
|
|
|
236
261
|
};
|
|
237
262
|
const hasLooseFiles = Object.keys(config.looseFiles).length > 0;
|
|
238
263
|
const metaIsExplicit = config.meta !== false && JSON.stringify(config.meta) !== defaultMetaFingerprint;
|
|
239
|
-
|
|
264
|
+
yield* Effect.flatMap(ConfigValidator, (v) => v.validate({
|
|
240
265
|
baseName: packageName,
|
|
241
266
|
hasExports: exportsMap !== void 0 && Object.keys(exportsMap).length > 0,
|
|
242
267
|
...publishTargets !== void 0 ? { targets: publishTargets } : {},
|
|
@@ -247,7 +272,7 @@ async function runBuild(options, collector, progress) {
|
|
|
247
272
|
localPaths: meta.localPaths?.map((path) => resolve(cwd, path))
|
|
248
273
|
} } : {},
|
|
249
274
|
...hasLooseFiles ? { looseFiles: config.looseFiles } : {}
|
|
250
|
-
})).pipe(Effect.provide(ConfigValidator.layer))
|
|
275
|
+
})).pipe(Effect.provide(ConfigValidator.layer));
|
|
251
276
|
const exeSpecs = config.exe !== void 0 ? normalizeExeOptions(config.exe, osCpu) : [];
|
|
252
277
|
if (config.exe !== void 0 && (exeSpecs.length !== 1 || (exeSpecs[0]?.targets.length ?? 0) !== 1)) throw new ConfigValidationError({
|
|
253
278
|
path: "exe",
|
|
@@ -280,8 +305,8 @@ async function runBuild(options, collector, progress) {
|
|
|
280
305
|
path: "exports",
|
|
281
306
|
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
307
|
});
|
|
283
|
-
validateCopy(config, hasJsEntries);
|
|
284
|
-
const { partitions, baseEntries, dualExports, subdirExports } = partitionOverrides(config, entries, exportsMap,
|
|
308
|
+
validateCopy(config, hasJsEntries, path);
|
|
309
|
+
const { partitions, baseEntries, dualExports, subdirExports } = partitionOverrides(config, entries, exportsMap, sourceName);
|
|
285
310
|
const looseFiles = hasLooseFiles ? normalizeLooseFiles(config.looseFiles) : void 0;
|
|
286
311
|
const { groups, resolution } = deriveProdGroups(publishTargets, packageName);
|
|
287
312
|
const anchor = resolution.groups[0]?.id ?? "npm";
|
|
@@ -293,7 +318,8 @@ async function runBuild(options, collector, progress) {
|
|
|
293
318
|
});
|
|
294
319
|
if (hasJsEntries || config.exe === void 0) {
|
|
295
320
|
progress.phase = "js";
|
|
296
|
-
|
|
321
|
+
const buildGroups = seams.buildTargetGroups ?? buildTargetGroups;
|
|
322
|
+
yield* Effect.promise(() => buildGroups({
|
|
297
323
|
cwd,
|
|
298
324
|
version,
|
|
299
325
|
entry: baseEntries,
|
|
@@ -302,6 +328,7 @@ async function runBuild(options, collector, progress) {
|
|
|
302
328
|
devManifest: "preserve",
|
|
303
329
|
externals: config.externals,
|
|
304
330
|
drop: config.manifest.drop,
|
|
331
|
+
...Object.keys(config.manifest.set).length > 0 ? { set: config.manifest.set } : {},
|
|
305
332
|
format: config.format,
|
|
306
333
|
emitDts: config.emitDts,
|
|
307
334
|
emitDeclarations: true,
|
|
@@ -323,15 +350,16 @@ async function runBuild(options, collector, progress) {
|
|
|
323
350
|
...config.copy.length > 0 ? { copy: config.copy } : {},
|
|
324
351
|
...options.plugins.length > 0 ? { extraPlugins: options.plugins } : {},
|
|
325
352
|
...exeRewrite !== void 0 ? { exeRewrite } : {}
|
|
326
|
-
});
|
|
353
|
+
}));
|
|
327
354
|
}
|
|
328
355
|
progress.phase = "manifest";
|
|
329
|
-
const targetsPath =
|
|
356
|
+
const targetsPath = seams.writeTargetsBinding !== void 0 ? seams.writeTargetsBinding(cwd, resolution) : yield* writeTargetsBinding(cwd, resolution);
|
|
330
357
|
if (meta !== void 0 && config.emitDts && (config.exe === void 0 || hasJsEntries)) {
|
|
331
358
|
progress.phase = "meta";
|
|
332
|
-
const generate =
|
|
333
|
-
const
|
|
334
|
-
|
|
359
|
+
const generate = yield* resolveConfiguredGenerator(options, packageName, groups, collector, seams);
|
|
360
|
+
const bundleMeta = options.bundle !== void 0 ? bundleMetaOptionsOf(options.bundle, generate) : void 0;
|
|
361
|
+
const runMetaPass = seams.runMetaPass ?? defaultRunMetaPass;
|
|
362
|
+
yield* Effect.promise(() => runMetaPass({
|
|
335
363
|
cwd,
|
|
336
364
|
packageName,
|
|
337
365
|
tsconfigPath,
|
|
@@ -341,22 +369,22 @@ async function runBuild(options, collector, progress) {
|
|
|
341
369
|
overrides: config.overrides,
|
|
342
370
|
meta: {
|
|
343
371
|
...meta,
|
|
344
|
-
...
|
|
372
|
+
...bundleMeta !== void 0 ? { bundle: bundleMeta } : {}
|
|
345
373
|
},
|
|
346
374
|
collector,
|
|
347
375
|
ci: options.ci,
|
|
348
376
|
targets: resolution.targets,
|
|
349
377
|
...seams.generateMeta !== void 0 ? { generateMeta: seams.generateMeta } : {},
|
|
350
|
-
...seams.resolveNextVersions !== void 0 ? { resolveNextVersions: seams.resolveNextVersions } : {}
|
|
351
|
-
});
|
|
378
|
+
...packageName !== sourceName ? { resolveNextVersions: aliasNextVersions(seams.resolveNextVersions, sourceName, packageName) } : seams.resolveNextVersions !== void 0 ? { resolveNextVersions: seams.resolveNextVersions } : {}
|
|
379
|
+
}));
|
|
352
380
|
}
|
|
353
381
|
progress.phase = "dts";
|
|
354
|
-
for (const g of groups) removeDeclarationMaps(join(cwd, "dist", "prod", g.id, "pkg"));
|
|
382
|
+
for (const g of groups) yield* removeDeclarationMaps(join(cwd, "dist", "prod", g.id, "pkg"));
|
|
355
383
|
if (exeSpec !== void 0 && exeRewrite !== void 0 && exeFileName !== void 0) for (const g of groups) {
|
|
356
384
|
const outDir = join(cwd, "dist", "prod", g.id, "pkg");
|
|
357
385
|
if (!hasJsEntries) {
|
|
358
386
|
progress.phase = "manifest";
|
|
359
|
-
const manifest =
|
|
387
|
+
const manifest = yield* Effect.promise(() => buildEmittedManifest({
|
|
360
388
|
pkg,
|
|
361
389
|
cwd,
|
|
362
390
|
targetGroup: {
|
|
@@ -366,45 +394,59 @@ async function runBuild(options, collector, progress) {
|
|
|
366
394
|
},
|
|
367
395
|
devManifest: "preserve",
|
|
368
396
|
drop: config.manifest.drop,
|
|
397
|
+
set: config.manifest.set,
|
|
369
398
|
exeRewrite
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
for (const file of ["LICENSE", "README.md"])
|
|
374
|
-
copyFileSync(join(cwd, file), join(outDir, file));
|
|
375
|
-
} catch {}
|
|
399
|
+
}));
|
|
400
|
+
yield* fs.makeDirectory(outDir, { recursive: true });
|
|
401
|
+
yield* fs.writeFileString(join(outDir, "package.json"), `${JSON.stringify(manifest, null, " ")}\n`);
|
|
402
|
+
for (const file of ["LICENSE", "README.md"]) yield* fs.copyFile(join(cwd, file), join(outDir, file)).pipe(Effect.ignore);
|
|
376
403
|
}
|
|
377
404
|
if (!noExe) {
|
|
378
405
|
progress.phase = "exe";
|
|
379
406
|
const binDir = join(outDir, "bin");
|
|
380
|
-
|
|
407
|
+
const runExeBuild = seams.runExeBuild ?? defaultRunExeBuild;
|
|
408
|
+
yield* Effect.promise(() => runExeBuild({
|
|
381
409
|
cwd,
|
|
382
410
|
outDir: binDir,
|
|
383
411
|
specs: exeSpecs,
|
|
384
412
|
collector,
|
|
385
413
|
groupId: g.id,
|
|
386
414
|
verbose
|
|
387
|
-
});
|
|
388
|
-
if (seams.runExeBuild === void 0 && !
|
|
415
|
+
}));
|
|
416
|
+
if (seams.runExeBuild === void 0 && !(yield* fs.exists(join(binDir, exeFileName)).pipe(Effect.orElseSucceed(() => false)))) 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
417
|
}
|
|
390
418
|
}
|
|
391
419
|
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, {
|
|
420
|
+
for (const g of groups) for (const { field, key, target } of yield* unmatchedExportPatterns(join(cwd, "dist", "prod", g.id, "pkg"), { ...exeExportPath !== void 0 ? { ignore: [exeExportPath] } : {} })) collector.recordWarning(g.id, {
|
|
393
421
|
source: "config",
|
|
394
422
|
level: "warn",
|
|
395
423
|
code: "exports-pattern-unmatched",
|
|
396
424
|
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
425
|
});
|
|
398
|
-
|
|
426
|
+
if (builtTargets.length > 0) {
|
|
427
|
+
const emitted = yield* Effect.forEach(groups, (g) => Effect.map(readEmittedExports(cwd, g.id, path), (exports) => ({
|
|
428
|
+
groupId: g.id,
|
|
429
|
+
exports
|
|
430
|
+
})));
|
|
431
|
+
for (const { exportKey, target, expected } of mismatchedBuiltTargets(builtTargets, emitted)) collector.recordWarning(anchor, {
|
|
432
|
+
source: "config",
|
|
433
|
+
level: "warn",
|
|
434
|
+
code: "exports-built-condition-unmatched",
|
|
435
|
+
text: expected !== void 0 ? `The export "${exportKey}" names "${target}" under the effected-built condition, which is not the file the build emits for it. Write "${expected}".` : `The export "${exportKey}" names "${target}" under the effected-built condition, but the build emits no JS file for that export.`
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
return targetsPath;
|
|
439
|
+
}));
|
|
440
|
+
if (Exit.isSuccess(exit)) {
|
|
441
|
+
yield* writeIssuesBestEffort();
|
|
399
442
|
return {
|
|
400
443
|
issuesPath,
|
|
401
|
-
targetsPath
|
|
444
|
+
targetsPath: exit.value
|
|
402
445
|
};
|
|
403
|
-
} catch (err) {
|
|
404
|
-
writeIssuesBestEffort(err);
|
|
405
|
-
throw err;
|
|
406
446
|
}
|
|
407
|
-
|
|
447
|
+
yield* writeIssuesBestEffort(Cause.squash(exit.cause));
|
|
448
|
+
return yield* Effect.failCause(exit.cause);
|
|
449
|
+
});
|
|
408
450
|
/**
|
|
409
451
|
* Builds one package: the JS and declaration passes for every publish group, the emitted manifest,
|
|
410
452
|
* `dist/prod/targets.json`, the API model, an optional SEA binary, and `dist/prod/issues.json`.
|
|
@@ -419,6 +461,11 @@ var Bundler = class {
|
|
|
419
461
|
* It writes nothing to stdout; rendering the report belongs to the caller. A structurally invalid config fails
|
|
420
462
|
* {@link ConfigValidationError} before any build work, and anything thrown afterwards fails
|
|
421
463
|
* {@link BundlerError} naming the phase. Both paths write `issues.json` stamped `buildOk: false` first.
|
|
464
|
+
*
|
|
465
|
+
* The build's own reads and writes (`package.json`, the package's tsconfig, `targets.json`, `issues.json`, the
|
|
466
|
+
* emitted manifest's checks) go through the provided `FileSystem` and `Path`, while tsdown, API Extractor and the
|
|
467
|
+
* SEA compiler always work on the host disk. Provide the host's (`NodeServices.layer`) for a real build. A memory
|
|
468
|
+
* filesystem suits a build whose passes are all replaced through `seams`.
|
|
422
469
|
*/
|
|
423
470
|
static build = Effect.fn("Bundler.build")(function* (options) {
|
|
424
471
|
const collector = new BuildCollector();
|
|
@@ -430,15 +477,16 @@ var Bundler = class {
|
|
|
430
477
|
package: progress.packageName,
|
|
431
478
|
targetGroups: []
|
|
432
479
|
});
|
|
433
|
-
const { issuesPath, targetsPath } = yield* Effect.
|
|
434
|
-
|
|
435
|
-
|
|
480
|
+
const { issuesPath, targetsPath } = yield* runBuild(options, collector, progress).pipe(Effect.catchCause((cause) => {
|
|
481
|
+
if (Cause.hasInterruptsOnly(cause)) return Effect.failCause(cause);
|
|
482
|
+
const err = Cause.squash(cause);
|
|
483
|
+
return Effect.fail(err instanceof ConfigValidationError ? err : BundlerError.make({
|
|
436
484
|
phase: progress.phase,
|
|
437
|
-
message: causeMessage(
|
|
438
|
-
cause,
|
|
485
|
+
message: causeMessage(err) ?? String(err),
|
|
486
|
+
cause: err,
|
|
439
487
|
report: snapshot()
|
|
440
|
-
})
|
|
441
|
-
});
|
|
488
|
+
}));
|
|
489
|
+
}));
|
|
442
490
|
return BundlerBuildResult.make({
|
|
443
491
|
report: snapshot(),
|
|
444
492
|
issuesPath,
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
[](https://nodejs.org/)
|
|
6
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 `
|
|
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 `bundle.json` manifest, an optional single-executable binary, and a structured `issues.json`.
|
|
8
8
|
|
|
9
9
|
> **Pre-`1.0.0`.** This package is part of the `@effected/*` kit, built on stable
|
|
10
10
|
> Effect v4 and still in `0.x` development. Pin an exact version: even a package
|
|
@@ -40,7 +40,7 @@ const program = Effect.gen(function* () {
|
|
|
40
40
|
const result = yield* Bundler.build({
|
|
41
41
|
cwd,
|
|
42
42
|
config: config.package.build,
|
|
43
|
-
|
|
43
|
+
bundle: config.package.bundle,
|
|
44
44
|
noExe: false,
|
|
45
45
|
verbose: false,
|
|
46
46
|
plugins: [],
|
|
@@ -59,7 +59,7 @@ All under the package:
|
|
|
59
59
|
| Path | What it is |
|
|
60
60
|
| --- | --- |
|
|
61
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`, `
|
|
62
|
+
| `dist/prod/<group>/meta` | the `.api.json` model, `package.json`, a portable `tsconfig.json`, `bundle.json` and any Open Graph image |
|
|
63
63
|
| `dist/prod/targets.json` | which target publishes which group |
|
|
64
64
|
| `dist/prod/issues.json` | every diagnostic, and whether the build finished |
|
|
65
65
|
|
package/action/ActionBundle.js
CHANGED
|
@@ -3,9 +3,7 @@ import { BundleFailed, CleanError, WriteError } from "./ActionErrors.js";
|
|
|
3
3
|
import { DEFAULT_LIFECYCLE_ENTRIES, invalidWorkerName } from "./entries.js";
|
|
4
4
|
import { ignoreStubPlugin } from "./ignore-stub-plugin.js";
|
|
5
5
|
import { checkImport } from "./import-check.js";
|
|
6
|
-
import { Effect,
|
|
7
|
-
import { existsSync, mkdirSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
8
|
-
import { join, resolve } from "node:path";
|
|
6
|
+
import { Effect, FileSystem, Path, Schema } from "effect";
|
|
9
7
|
import { stripVTControlCharacters } from "node:util";
|
|
10
8
|
import { rolldown } from "rolldown";
|
|
11
9
|
|
|
@@ -59,13 +57,16 @@ var BuildResult = class extends Schema.Class("BuildResult")({
|
|
|
59
57
|
* The entries to build. A `pre` or `post` the config names must exist, and the conventional `src/pre.ts` and
|
|
60
58
|
* `src/post.ts` are built when they do.
|
|
61
59
|
*/
|
|
62
|
-
const entriesToBuild = (config, cwd)
|
|
60
|
+
const entriesToBuild = Effect.fnUntraced(function* (config, cwd) {
|
|
61
|
+
const fs = yield* FileSystem.FileSystem;
|
|
62
|
+
const path = yield* Path.Path;
|
|
63
|
+
const exists = (file) => fs.exists(file).pipe(Effect.orElseSucceed(() => false));
|
|
63
64
|
const { main, pre, post, workers } = config.entries;
|
|
64
|
-
const mainSource = resolve(cwd, main);
|
|
65
|
-
if (!
|
|
65
|
+
const mainSource = path.resolve(cwd, main);
|
|
66
|
+
if (!(yield* exists(mainSource))) return yield* new BundleFailed({
|
|
66
67
|
entry: main,
|
|
67
68
|
cause: /* @__PURE__ */ new Error("Main entry point not found")
|
|
68
|
-
})
|
|
69
|
+
});
|
|
69
70
|
const entries = [{
|
|
70
71
|
name: "main",
|
|
71
72
|
source: mainSource
|
|
@@ -79,36 +80,39 @@ const entriesToBuild = (config, cwd) => {
|
|
|
79
80
|
post,
|
|
80
81
|
DEFAULT_LIFECYCLE_ENTRIES.post
|
|
81
82
|
]]) {
|
|
82
|
-
const source = resolve(cwd, explicit ?? fallback);
|
|
83
|
-
if (
|
|
83
|
+
const source = path.resolve(cwd, explicit ?? fallback);
|
|
84
|
+
if (yield* exists(source)) entries.push({
|
|
84
85
|
name,
|
|
85
86
|
source
|
|
86
87
|
});
|
|
87
|
-
else if (explicit !== void 0) return
|
|
88
|
+
else if (explicit !== void 0) return yield* new BundleFailed({
|
|
88
89
|
entry: name,
|
|
89
90
|
cause: /* @__PURE__ */ new Error(`Entry point not found: ${explicit}`)
|
|
90
|
-
})
|
|
91
|
+
});
|
|
91
92
|
}
|
|
92
93
|
for (const [name, source] of Object.entries(workers)) {
|
|
93
94
|
const reason = invalidWorkerName(name);
|
|
94
|
-
if (reason !== void 0) return
|
|
95
|
+
if (reason !== void 0) return yield* new BundleFailed({
|
|
95
96
|
entry: name,
|
|
96
97
|
cause: new Error(reason)
|
|
97
|
-
})
|
|
98
|
-
const workerSource = resolve(cwd, source);
|
|
99
|
-
if (!
|
|
98
|
+
});
|
|
99
|
+
const workerSource = path.resolve(cwd, source);
|
|
100
|
+
if (!(yield* exists(workerSource))) return yield* new BundleFailed({
|
|
100
101
|
entry: name,
|
|
101
102
|
cause: /* @__PURE__ */ new Error(`Worker entry point not found: ${source}`)
|
|
102
|
-
})
|
|
103
|
+
});
|
|
103
104
|
entries.push({
|
|
104
105
|
name,
|
|
105
106
|
source: workerSource
|
|
106
107
|
});
|
|
107
108
|
}
|
|
108
|
-
return
|
|
109
|
-
};
|
|
110
|
-
/**
|
|
111
|
-
|
|
109
|
+
return entries;
|
|
110
|
+
});
|
|
111
|
+
/**
|
|
112
|
+
* Bundles one entry and, unless the config turns it off, proves the bundle loads. A failure comes back as a result.
|
|
113
|
+
* `out` is `cwd`'s `dist`, joined by the caller: rolldown and the load check work on the host disk.
|
|
114
|
+
*/
|
|
115
|
+
const bundleEntry = async (entry, config, cwd, out, signal) => {
|
|
112
116
|
const started = Date.now();
|
|
113
117
|
const { minify, sourceMap, externals, ignore, importCheck } = config.build;
|
|
114
118
|
const warnings = [];
|
|
@@ -133,7 +137,7 @@ const bundleEntry = async (entry, config, cwd, signal) => {
|
|
|
133
137
|
});
|
|
134
138
|
try {
|
|
135
139
|
await build.write({
|
|
136
|
-
dir:
|
|
140
|
+
dir: out.dir,
|
|
137
141
|
format: "esm",
|
|
138
142
|
entryFileNames: "[name].js",
|
|
139
143
|
minify,
|
|
@@ -148,37 +152,40 @@ const bundleEntry = async (entry, config, cwd, signal) => {
|
|
|
148
152
|
} finally {
|
|
149
153
|
await build.close();
|
|
150
154
|
}
|
|
151
|
-
const file =
|
|
155
|
+
const { file } = out;
|
|
152
156
|
if (importCheck) {
|
|
153
157
|
const verdict = await checkImport(file, {
|
|
154
158
|
externals,
|
|
155
159
|
signal
|
|
156
160
|
});
|
|
157
|
-
if (verdict.kind === "failed") return
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
161
|
+
if (verdict.kind === "failed") return {
|
|
162
|
+
_tag: "Failed",
|
|
163
|
+
result: BundleResult.make({
|
|
164
|
+
success: false,
|
|
165
|
+
error: `${entry.name} does not load: ${verdict.message}`,
|
|
166
|
+
...logged()
|
|
167
|
+
})
|
|
168
|
+
};
|
|
162
169
|
if (verdict.kind === "external-missing") warnings.push(`${verdict.packageName} is in build.externals and is not installed, so the load check stopped there`);
|
|
163
170
|
}
|
|
164
|
-
return
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
outputPath: `dist/${entry.name}.js`
|
|
171
|
-
}),
|
|
172
|
-
...logged()
|
|
173
|
-
});
|
|
171
|
+
return {
|
|
172
|
+
_tag: "Bundled",
|
|
173
|
+
file,
|
|
174
|
+
started,
|
|
175
|
+
warnings
|
|
176
|
+
};
|
|
174
177
|
} catch (cause) {
|
|
175
|
-
return
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
});
|
|
178
|
+
return {
|
|
179
|
+
_tag: "Failed",
|
|
180
|
+
result: failedToBundle(entry, cause, warnings)
|
|
181
|
+
};
|
|
180
182
|
}
|
|
181
183
|
};
|
|
184
|
+
const failedToBundle = (entry, cause, warnings) => BundleResult.make({
|
|
185
|
+
success: false,
|
|
186
|
+
error: `${entry.name} failed to bundle: ${causeMessage(cause) ?? String(cause)}`,
|
|
187
|
+
...warnings.length > 0 ? { warnings } : {}
|
|
188
|
+
});
|
|
182
189
|
/**
|
|
183
190
|
* Bundles a GitHub Action with rolldown.
|
|
184
191
|
*
|
|
@@ -204,48 +211,52 @@ var ActionBundle = class {
|
|
|
204
211
|
* in `dist`. A missing `main`, a `pre`, `post` or worker the config names with no file, and a bad worker name fail
|
|
205
212
|
* {@link BundleFailed} before `dist` is touched. Interrupting the build kills a running load check.
|
|
206
213
|
*
|
|
214
|
+
* Cleaning `dist`, writing `dist/package.json` and reading each bundle's size go through the provided `FileSystem`
|
|
215
|
+
* and `Path`, while rolldown and the load check work on the host disk, so provide the host's.
|
|
216
|
+
*
|
|
207
217
|
* @param options - `cwd` is the action's directory; `clean` removes `dist` first.
|
|
208
218
|
*/
|
|
209
219
|
static build = Effect.fn("ActionBundle.build")(function* (config, options) {
|
|
220
|
+
const fs = yield* FileSystem.FileSystem;
|
|
221
|
+
const path = yield* Path.Path;
|
|
210
222
|
const started = Date.now();
|
|
211
|
-
const requested = resolve(options.cwd);
|
|
212
|
-
const cwd =
|
|
213
|
-
const dist = join(cwd, "dist");
|
|
214
|
-
const entries = yield*
|
|
215
|
-
if (options.clean) yield*
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
try: () => {
|
|
228
|
-
mkdirSync(dist, { recursive: true });
|
|
229
|
-
writeFileSync(manifest, "{ \"type\": \"module\" }", "utf8");
|
|
230
|
-
},
|
|
231
|
-
catch: (cause) => new WriteError({
|
|
232
|
-
path: manifest,
|
|
233
|
-
cause
|
|
234
|
-
})
|
|
235
|
-
});
|
|
223
|
+
const requested = path.resolve(options.cwd);
|
|
224
|
+
const cwd = yield* fs.realPath(requested).pipe(Effect.orElseSucceed(() => requested));
|
|
225
|
+
const dist = path.join(cwd, "dist");
|
|
226
|
+
const entries = yield* entriesToBuild(config, cwd);
|
|
227
|
+
if (options.clean) yield* fs.remove(dist, {
|
|
228
|
+
recursive: true,
|
|
229
|
+
force: true
|
|
230
|
+
}).pipe(Effect.mapError((cause) => new CleanError({
|
|
231
|
+
directory: dist,
|
|
232
|
+
cause
|
|
233
|
+
})));
|
|
234
|
+
const manifest = path.join(dist, "package.json");
|
|
235
|
+
yield* fs.makeDirectory(dist, { recursive: true }).pipe(Effect.andThen(fs.writeFileString(manifest, "{ \"type\": \"module\" }")), Effect.mapError((cause) => new WriteError({
|
|
236
|
+
path: manifest,
|
|
237
|
+
cause
|
|
238
|
+
})));
|
|
236
239
|
const results = [];
|
|
237
240
|
for (const entry of entries) {
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
241
|
+
const out = {
|
|
242
|
+
dir: dist,
|
|
243
|
+
file: path.join(dist, `${entry.name}.js`)
|
|
244
|
+
};
|
|
245
|
+
const bundled = yield* Effect.promise((signal) => bundleEntry(entry, config, cwd, out, signal));
|
|
246
|
+
const result = bundled._tag === "Failed" ? bundled.result : yield* fs.stat(bundled.file).pipe(Effect.map((info) => BundleResult.make({
|
|
247
|
+
success: true,
|
|
248
|
+
stats: BundleStats.make({
|
|
249
|
+
entry: entry.name,
|
|
250
|
+
size: Number(info.size),
|
|
251
|
+
duration: Date.now() - bundled.started,
|
|
252
|
+
outputPath: `dist/${entry.name}.js`
|
|
253
|
+
}),
|
|
254
|
+
...bundled.warnings.length > 0 ? { warnings: bundled.warnings } : {}
|
|
255
|
+
})), Effect.catch((cause) => Effect.succeed(failedToBundle(entry, cause, bundled.warnings))));
|
|
256
|
+
if (!result.success) yield* fs.remove(path.join(dist, `${entry.name}.js`), { force: true }).pipe(Effect.andThen(fs.remove(path.join(dist, `${entry.name}.js.map`), { force: true })), Effect.mapError((cause) => new CleanError({
|
|
257
|
+
directory: dist,
|
|
258
|
+
cause
|
|
259
|
+
})));
|
|
249
260
|
results.push(result);
|
|
250
261
|
}
|
|
251
262
|
const failed = results.filter((result) => !result.success).length;
|
package/action/import-check.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { mkdtempSync, realpathSync, rmSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
1
|
import { execFile } from "node:child_process";
|
|
2
|
+
import { mkdtempSync, realpathSync, rmSync } from "node:fs";
|
|
4
3
|
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
6
6
|
|
|
7
7
|
// src/action/import-check.ts
|