@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/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ActionBuildResult, ActionBuilder, BuildFailed, ValidationFailed } from "./action/ActionBuilder.js";
|
|
2
|
+
import { ActionBundle, BuildResult, BundleResult, BundleStats } from "./action/ActionBundle.js";
|
|
3
|
+
import { ActionYmlPathError, BundleFailed, CleanError, PersistLocalError, WriteError } from "./action/ActionErrors.js";
|
|
4
|
+
import { ActionValidation, ValidationIssue, ValidationResult } from "./action/ActionValidation.js";
|
|
5
|
+
import { ActionYml, ActionYmlBranding, ActionYmlBrandingColor, ActionYmlBrandingIcon, ActionYmlInput, ActionYmlOutput, ActionYmlRuns } from "./action/ActionYml.js";
|
|
6
|
+
import { PersistLocal, PersistLocalResult } from "./action/PersistLocal.js";
|
|
7
|
+
import { Bundler, BundlerBuildResult } from "./Bundler.js";
|
|
8
|
+
import { BundlerError, BundlerPhase } from "./BundlerError.js";
|
|
9
|
+
import { resolveManifest } from "./catalog/resolve-catalogs.js";
|
|
10
|
+
import { resolveNextVersions } from "./changesets/next-versions.js";
|
|
11
|
+
import { ActionBuildOptions, ActionConfig, ActionEntries, ActionPersistLocalOptions, ActionValidationOptions } from "./config/ActionConfig.js";
|
|
12
|
+
import { BuildFormat, BuildPlatform, CopyEntry, EffectedConfig, EntryOverride, ExeConfig, ExeSeaConfig, ExeTargetConfig, JsxConfig, LooseFileSpec, ManifestConfig, MetaConfig, PackageBuildConfig, PackageConfig, TsdocConfig, TsdocTagDefinition, TsdoctorConfig, TsdoctorOpenGraphConfig, TsdoctorOpenGraphImage, TsdoctorRegistryRef, WarningSuppressionRule } from "./config/BuildConfig.js";
|
|
13
|
+
import { EffectedConfigError, EffectedConfigFile, ResolvedConfig, ResolvedEffectedConfig } from "./config/EffectedConfigFile.js";
|
|
14
|
+
import { merge } from "./config/merge.js";
|
|
15
|
+
import { PluginLoadError, loadPlugins } from "./config/plugins.js";
|
|
16
|
+
import { ConfigValidator } from "./config-validation/ConfigValidator.js";
|
|
17
|
+
import { analyzeReexportBarrel, collectExportNames, renderReexportStub } from "./dts/reexport-stub.js";
|
|
18
|
+
import { findRelativeSpecifiers } from "./dts/relative-imports.js";
|
|
19
|
+
import { buildResolvedTsconfig, writeDtsEmitTsconfig, writeResolvedTsconfig } from "./dts/resolved-tsconfig.js";
|
|
20
|
+
import { ambientOutName, assertNoEntryCollisions, classifyDtsExport, declarationExt, extractAmbientDts, mixedDtsExportError } from "./entries/ambient-dts.js";
|
|
21
|
+
import { deriveExportPaths } from "./entries/export-paths.js";
|
|
22
|
+
import { createEntryName, extractEntries } from "./entries/extract.js";
|
|
23
|
+
import { packageJsonEntries } from "./entries/package-json-entries.js";
|
|
24
|
+
import { ConfigValidationError, MetaGenerationError, TsdoctorEmitError } from "./errors.js";
|
|
25
|
+
import { runExeBuild } from "./exe/build.js";
|
|
26
|
+
import { DEFAULT_EXE_NODE_VERSION, normalizeExeOptions } from "./exe/config.js";
|
|
27
|
+
import { computeExeFileName } from "./exe/filename.js";
|
|
28
|
+
import { BuildJournal, IssueJournal } from "./journal/BuildJournal.js";
|
|
29
|
+
import { readTsconfigJsx, resolveJsxConfig } from "./jsx/config.js";
|
|
30
|
+
import { buildEmittedManifest, emitManifest, manifestNeedsCatalogResolution } from "./manifest/emit-manifest.js";
|
|
31
|
+
import { defaultManifestTransform, normalizeBinPaths, transformBin, transformExports, transformManifest } from "./manifest/transform.js";
|
|
32
|
+
import { BundleManifest, BundleManifestError, KNOWN_REGISTRY_TYPES, MANIFEST_SPEC, OpenGraphConfig, OpenGraphImage, ProjectIdentity, RegistryRef, SbomRef, TSDOCTOR_MANIFEST_FILENAME, decodeBundleManifest, encodeBundleManifest, isKnownRegistryType } from "./meta/BundleManifest.js";
|
|
33
|
+
import { normalizeMetaOptions } from "./meta/config.js";
|
|
34
|
+
import { ManifestSource, decodeManifestSource } from "./meta/ManifestSource.js";
|
|
35
|
+
import { OgGenerateError, resolveOgCacheSalt, resolveOgGenerator, writeGeneratedOgImage } from "./meta/og-image.js";
|
|
36
|
+
import { rewriteMetaVersions } from "./meta/optimistic.js";
|
|
37
|
+
import { resolvePortableTsconfig } from "./meta/tsconfig-resolver.js";
|
|
38
|
+
import { composeTsdoctorManifest, githubOwnerRepo, ogImageInfoOf, registriesFromTargets } from "./meta/tsdoctor-manifest.js";
|
|
39
|
+
import { TsdoctorSourceError, loadTsdoctorSources } from "./meta/tsdoctor-source.js";
|
|
40
|
+
import { buildTargetGroups } from "./passes/build-target-groups.js";
|
|
41
|
+
import { cjsDefaultInterop } from "./passes/cjs-default-interop.js";
|
|
42
|
+
import { normalizeLooseFiles } from "./passes/loose-files.js";
|
|
43
|
+
import { nodeBuiltinDefaultInterop } from "./passes/node-builtin-default-interop.js";
|
|
44
|
+
import { removeDeclarationMaps } from "./passes/strip-maps.js";
|
|
45
|
+
import { copyAmbientDts, copyPublicDir } from "./passes/sync-public.js";
|
|
46
|
+
import { declarationsDirFor, deriveDeclarationsPassOptions, deriveDtsPassOptions, deriveTargetGroupOptions, dtsPassDtsOptions, outDirFor } from "./passes/target-groups.js";
|
|
47
|
+
import { renderCiAnnotations } from "./report/ci-annotations.js";
|
|
48
|
+
import { BuildCollector, BuildCollectorTag } from "./report/collector.js";
|
|
49
|
+
import { BuildIssuesSchema, PlainDiagnosticSchema, flattenIssues, serializeIssues, writeIssuesArtifact } from "./report/issues-artifact.js";
|
|
50
|
+
import { buildMetricsPlugin } from "./report/metrics-plugin.js";
|
|
51
|
+
import { BuildReport, DiagnosticEntry, EmittedFile, PassReport, ReportTimings, TargetGroupReport } from "./report/schema.js";
|
|
52
|
+
import { createTimer, formatTime } from "./report/timer.js";
|
|
53
|
+
import { createTsdownLogger } from "./report/tsdown-logger.js";
|
|
54
|
+
import { writeTargetsBinding } from "./targets/binding.js";
|
|
55
|
+
import { RELEASE_CHANNELS, isTargetObject } from "./targets/config.js";
|
|
56
|
+
import { releaseWarnings, resolveTargets } from "./targets/resolve-targets.js";
|
|
57
|
+
|
|
58
|
+
export { ActionBuildOptions, ActionBuildResult, ActionBuilder, ActionBundle, ActionConfig, ActionEntries, ActionPersistLocalOptions, ActionValidation, ActionValidationOptions, ActionYml, ActionYmlBranding, ActionYmlBrandingColor, ActionYmlBrandingIcon, ActionYmlInput, ActionYmlOutput, ActionYmlPathError, ActionYmlRuns, BuildCollector, BuildCollectorTag, BuildFailed, BuildFormat, BuildIssuesSchema, BuildJournal, BuildPlatform, BuildReport, BuildResult, BundleFailed, BundleManifest, BundleManifestError, BundleResult, BundleStats, Bundler, BundlerBuildResult, BundlerError, BundlerPhase, CleanError, ConfigValidationError, ConfigValidator, CopyEntry, DEFAULT_EXE_NODE_VERSION, DiagnosticEntry, EffectedConfig, EffectedConfigError, EffectedConfigFile, EmittedFile, EntryOverride, ExeConfig, ExeSeaConfig, ExeTargetConfig, IssueJournal, JsxConfig, KNOWN_REGISTRY_TYPES, LooseFileSpec, MANIFEST_SPEC, ManifestConfig, ManifestSource, MetaConfig, MetaGenerationError, OgGenerateError, OpenGraphConfig, OpenGraphImage, PackageBuildConfig, PackageConfig, PassReport, PersistLocal, PersistLocalError, PersistLocalResult, PlainDiagnosticSchema, PluginLoadError, ProjectIdentity, RELEASE_CHANNELS, RegistryRef, ReportTimings, ResolvedConfig, ResolvedEffectedConfig, SbomRef, TSDOCTOR_MANIFEST_FILENAME, TargetGroupReport, TsdocConfig, TsdocTagDefinition, TsdoctorConfig, TsdoctorEmitError, TsdoctorOpenGraphConfig, TsdoctorOpenGraphImage, TsdoctorRegistryRef, TsdoctorSourceError, ValidationFailed, ValidationIssue, ValidationResult, WarningSuppressionRule, WriteError, ambientOutName, analyzeReexportBarrel, assertNoEntryCollisions, buildEmittedManifest, buildMetricsPlugin, buildResolvedTsconfig, buildTargetGroups, cjsDefaultInterop, classifyDtsExport, collectExportNames, composeTsdoctorManifest, computeExeFileName, copyAmbientDts, copyPublicDir, createEntryName, createTimer, createTsdownLogger, declarationExt, declarationsDirFor, decodeBundleManifest, decodeManifestSource, defaultManifestTransform, deriveDeclarationsPassOptions, deriveDtsPassOptions, deriveExportPaths, deriveTargetGroupOptions, dtsPassDtsOptions, emitManifest, encodeBundleManifest, extractAmbientDts, extractEntries, findRelativeSpecifiers, flattenIssues, formatTime, githubOwnerRepo, isKnownRegistryType, isTargetObject, loadPlugins, loadTsdoctorSources, manifestNeedsCatalogResolution, merge, mixedDtsExportError, nodeBuiltinDefaultInterop, normalizeBinPaths, normalizeExeOptions, normalizeLooseFiles, normalizeMetaOptions, ogImageInfoOf, outDirFor, packageJsonEntries, readTsconfigJsx, registriesFromTargets, releaseWarnings, removeDeclarationMaps, renderCiAnnotations, renderReexportStub, resolveJsxConfig, resolveManifest, resolveNextVersions, resolveOgCacheSalt, resolveOgGenerator, resolvePortableTsconfig, resolveTargets, rewriteMetaVersions, runExeBuild, serializeIssues, transformBin, transformExports, transformManifest, writeDtsEmitTsconfig, writeGeneratedOgImage, writeIssuesArtifact, writeResolvedTsconfig, writeTargetsBinding };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Predicate } from "effect";
|
|
2
|
+
|
|
3
|
+
// src/internal/causeMessage.ts
|
|
4
|
+
/** How many nodes of a cause chain the walk reads before stopping, so a cyclic chain cannot spin. */
|
|
5
|
+
const CAUSE_DEPTH = 8;
|
|
6
|
+
/**
|
|
7
|
+
* The message a single node carries: a thrown string, or a non-empty string `message` property. A getter or
|
|
8
|
+
* proxy trap that throws is a node with no message.
|
|
9
|
+
*/
|
|
10
|
+
const messageAt = (node) => {
|
|
11
|
+
try {
|
|
12
|
+
const text = Predicate.isString(node) ? node : Predicate.hasProperty(node, "message") && Predicate.isString(node.message) ? node.message : void 0;
|
|
13
|
+
return text === void 0 || text.trim() === "" ? void 0 : text;
|
|
14
|
+
} catch {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
/** The next link of the chain: a node's `cause`, or `undefined` when it has none or reading it throws. */
|
|
19
|
+
const causeAt = (node) => {
|
|
20
|
+
try {
|
|
21
|
+
return Predicate.hasProperty(node, "cause") ? node.cause : void 0;
|
|
22
|
+
} catch {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Every distinct non-empty message a preserved cause chain carries, nearest
|
|
28
|
+
* first and joined with `: `, or `undefined` when nothing along it has one.
|
|
29
|
+
*
|
|
30
|
+
* A `Schema.Defect()` field holds whatever was thrown, so the read is guarded
|
|
31
|
+
* rather than assumed: `Predicate.hasProperty` + `Predicate.isString` accepts
|
|
32
|
+
* an `Error`, a cross-realm `Error` that fails `instanceof`, a plain
|
|
33
|
+
* `{ message }` object and a thrown string alike. An empty or whitespace-only
|
|
34
|
+
* message counts as none. The walk follows `cause` links because a wrapper's
|
|
35
|
+
* text is often the generic summary and the driver's text underneath is the
|
|
36
|
+
* actionable detail, yet a wrapper that composes its own context must not
|
|
37
|
+
* lose it either; so nothing is dropped, and a deeper text the nearer one
|
|
38
|
+
* already contains is not repeated. The walk is bounded, so a cycle terminates.
|
|
39
|
+
*
|
|
40
|
+
* It never throws: every property read is guarded, so a `message` getter that throws leaves that link
|
|
41
|
+
* without text, and a `cause` getter that throws ends the walk with what was found so far.
|
|
42
|
+
*/
|
|
43
|
+
const causeMessage = (cause) => {
|
|
44
|
+
let message;
|
|
45
|
+
let node = cause;
|
|
46
|
+
for (let depth = 0; depth < CAUSE_DEPTH && node !== void 0 && node !== null; depth++) {
|
|
47
|
+
const text = messageAt(node);
|
|
48
|
+
if (text !== void 0) {
|
|
49
|
+
if (message === void 0 || text.includes(message)) message = text;
|
|
50
|
+
else if (!message.includes(text)) message = `${message}: ${text}`;
|
|
51
|
+
}
|
|
52
|
+
node = causeAt(node);
|
|
53
|
+
}
|
|
54
|
+
return message;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export { causeMessage };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { BuildIssuesSchema, PlainDiagnosticSchema } from "../report/issues-artifact.js";
|
|
2
|
+
import { Effect, FileSystem, Layer, Schema } from "effect";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { Journal, JsonlEvent } from "@effected/jsonl";
|
|
5
|
+
|
|
6
|
+
// src/journal/BuildJournal.ts
|
|
7
|
+
/** Each journal's place under the workspace root. */
|
|
8
|
+
const BUILD_JOURNAL_PATH = ".cache/effected/build.jsonl";
|
|
9
|
+
const ISSUE_JOURNAL_PATH = ".cache/effected/issues.jsonl";
|
|
10
|
+
/**
|
|
11
|
+
* A journal's directory, which appending never creates. The journal itself is created through its own `create`.
|
|
12
|
+
*/
|
|
13
|
+
const ensureDirectoryOf = (path) => Effect.gen(function* () {
|
|
14
|
+
yield* (yield* FileSystem.FileSystem).makeDirectory(dirname(path), { recursive: true });
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* The per-diagnostic journal: one line per error and warning of a build, in that order, scoped by package name.
|
|
18
|
+
* Suppressed diagnostics stay in `issues.json` and are counted on the build's line.
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
var IssueJournal = class IssueJournal extends Journal.Service()("effected/IssueJournal", {
|
|
23
|
+
events: [JsonlEvent.make("issue", { data: Schema.Struct({
|
|
24
|
+
package: Schema.String,
|
|
25
|
+
generatedAt: Schema.String,
|
|
26
|
+
...PlainDiagnosticSchema.fields
|
|
27
|
+
}) })],
|
|
28
|
+
config: { path: ISSUE_JOURNAL_PATH }
|
|
29
|
+
}) {
|
|
30
|
+
/**
|
|
31
|
+
* The journal at `<root>/.cache/effected/issues.jsonl`, with its directory and file created.
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* Every call is a fresh layer, and every build of one an independent journal: bind it to one const.
|
|
35
|
+
*
|
|
36
|
+
* @param root - The workspace root.
|
|
37
|
+
*/
|
|
38
|
+
static layerAt = (root) => {
|
|
39
|
+
const path = join(root, ISSUE_JOURNAL_PATH);
|
|
40
|
+
return Layer.effect(IssueJournal, ensureDirectoryOf(path).pipe(Effect.andThen(IssueJournal.make({ path })), Effect.tap((journal) => journal.create)));
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* The per-build journal: one line per finished build, scoped by package name.
|
|
45
|
+
*
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
var BuildJournal = class BuildJournal extends Journal.Service()("effected/BuildJournal", {
|
|
49
|
+
events: [JsonlEvent.make("build", { data: Schema.Struct({
|
|
50
|
+
package: Schema.String,
|
|
51
|
+
cwd: Schema.String,
|
|
52
|
+
generatedAt: Schema.String,
|
|
53
|
+
buildOk: Schema.Boolean,
|
|
54
|
+
failure: BuildIssuesSchema.fields.failure,
|
|
55
|
+
errors: Schema.Number,
|
|
56
|
+
warnings: Schema.Number,
|
|
57
|
+
suppressed: Schema.Number,
|
|
58
|
+
issuesPath: Schema.String
|
|
59
|
+
}) })],
|
|
60
|
+
config: { path: BUILD_JOURNAL_PATH }
|
|
61
|
+
}) {
|
|
62
|
+
/**
|
|
63
|
+
* The journal at `<root>/.cache/effected/build.jsonl`, with its directory and file created.
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* Every call is a fresh layer, and every build of one an independent journal: bind it to one const.
|
|
67
|
+
*
|
|
68
|
+
* @param root - The workspace root.
|
|
69
|
+
*/
|
|
70
|
+
static layerAt = (root) => {
|
|
71
|
+
const path = join(root, BUILD_JOURNAL_PATH);
|
|
72
|
+
return Layer.effect(BuildJournal, ensureDirectoryOf(path).pipe(Effect.andThen(BuildJournal.make({ path })), Effect.tap((journal) => journal.create)));
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Appends one finished build: a line per error and warning, then the build's own line.
|
|
76
|
+
*
|
|
77
|
+
* @remarks
|
|
78
|
+
* The build's line goes last, so a watcher that sees it finds that build's issues already written. Each line's
|
|
79
|
+
* `scope` is the package name, which is what a read filters on. Parallel builds may record at once: each line is
|
|
80
|
+
* one `O_APPEND` write.
|
|
81
|
+
*
|
|
82
|
+
* @param issues - The build's `issues.json`.
|
|
83
|
+
* @param cwd - The package directory the artifact sits under.
|
|
84
|
+
*/
|
|
85
|
+
static record = Effect.fn("BuildJournal.record")(function* (issues, cwd) {
|
|
86
|
+
const builds = yield* BuildJournal;
|
|
87
|
+
const journal = yield* IssueJournal;
|
|
88
|
+
const scope = { scope: issues.package };
|
|
89
|
+
for (const diagnostic of [...issues.errors, ...issues.warnings]) yield* journal.append("issue", {
|
|
90
|
+
package: issues.package,
|
|
91
|
+
generatedAt: issues.generatedAt,
|
|
92
|
+
...diagnostic
|
|
93
|
+
}, scope);
|
|
94
|
+
yield* builds.append("build", {
|
|
95
|
+
package: issues.package,
|
|
96
|
+
cwd,
|
|
97
|
+
generatedAt: issues.generatedAt,
|
|
98
|
+
buildOk: issues.buildOk,
|
|
99
|
+
...issues.failure !== void 0 ? { failure: issues.failure } : {},
|
|
100
|
+
errors: issues.errors.length,
|
|
101
|
+
warnings: issues.warnings.length,
|
|
102
|
+
suppressed: issues.suppressed.length,
|
|
103
|
+
issuesPath: join(cwd, "dist", issues.target, "issues.json")
|
|
104
|
+
}, scope);
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export { BuildJournal, IssueJournal };
|
package/jsx/config.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { tsconfigSyncOptions } from "../tsconfig/sync-options.js";
|
|
2
|
+
import { Option } from "effect";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import * as nodePath from "node:path";
|
|
5
|
+
import { JsxConfig, TsconfigLoaderSync } from "@effected/tsconfig-json";
|
|
6
|
+
|
|
7
|
+
// src/jsx/config.ts
|
|
8
|
+
/**
|
|
9
|
+
* Resolve the effective JSX config: an explicit override wins; otherwise infer from the tsconfig
|
|
10
|
+
* values via `@effected/tsconfig-json`'s `JsxConfig.fromCompilerOptions`. Returns undefined when
|
|
11
|
+
* no JSX transform is needed (preserve/none).
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
function resolveJsxConfig(tsconfig, override) {
|
|
15
|
+
if (override !== void 0) return override.runtime === "automatic" ? {
|
|
16
|
+
runtime: "automatic",
|
|
17
|
+
importSource: override.importSource ?? "react"
|
|
18
|
+
} : override;
|
|
19
|
+
const inferred = JsxConfig.fromCompilerOptions({
|
|
20
|
+
...tsconfig.jsx !== void 0 ? { jsx: tsconfig.jsx } : {},
|
|
21
|
+
...tsconfig.jsxImportSource !== void 0 ? { jsxImportSource: tsconfig.jsxImportSource } : {}
|
|
22
|
+
});
|
|
23
|
+
return Option.match(inferred, {
|
|
24
|
+
onNone: () => void 0,
|
|
25
|
+
onSome: (cfg) => ({
|
|
26
|
+
runtime: cfg.runtime,
|
|
27
|
+
...cfg.importSource !== void 0 ? { importSource: cfg.importSource } : {}
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Read the jsx-relevant compilerOptions from a package's own tsconfig.json (best-effort;
|
|
33
|
+
* returns empty on absence or parse error). Resolved through `@effected/tsconfig-json`'s
|
|
34
|
+
* sync loader, so JSONC syntax and `extends` chains are honored.
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
function readTsconfigJsx(cwd) {
|
|
38
|
+
const path = nodePath.join(cwd, "tsconfig.json");
|
|
39
|
+
if (!existsSync(path)) return {};
|
|
40
|
+
try {
|
|
41
|
+
const co = TsconfigLoaderSync.compilerOptions(path, tsconfigSyncOptions);
|
|
42
|
+
return {
|
|
43
|
+
...co.jsx !== void 0 ? { jsx: co.jsx } : {},
|
|
44
|
+
...co.jsxImportSource !== void 0 ? { jsxImportSource: co.jsxImportSource } : {}
|
|
45
|
+
};
|
|
46
|
+
} catch {
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { readTsconfigJsx, resolveJsxConfig };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { resolveManifest } from "../catalog/resolve-catalogs.js";
|
|
2
|
+
import { defaultManifestTransform, transformManifest } from "./transform.js";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
|
+
import { DependencySpecifier } from "@effected/npm";
|
|
6
|
+
|
|
7
|
+
// src/manifest/emit-manifest.ts
|
|
8
|
+
const DEPENDENCY_FIELDS = [
|
|
9
|
+
"dependencies",
|
|
10
|
+
"devDependencies",
|
|
11
|
+
"peerDependencies",
|
|
12
|
+
"optionalDependencies"
|
|
13
|
+
];
|
|
14
|
+
const isCatalogOrWorkspaceSpec = (spec) => typeof spec === "string" && (DependencySpecifier.isCatalog(spec) || DependencySpecifier.isWorkspace(spec));
|
|
15
|
+
/**
|
|
16
|
+
* Whether any of `pkg`'s four dependency fields carries at least one `catalog:`/`workspace:`
|
|
17
|
+
* specifier. `resolveManifest` returns a manifest with none of these unchanged, so callers can
|
|
18
|
+
* skip the CatalogResolver + pnpm-workspace + lockfile assembly entirely when this is false.
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
function manifestNeedsCatalogResolution(pkg) {
|
|
23
|
+
return DEPENDENCY_FIELDS.some((field) => {
|
|
24
|
+
const deps = pkg[field];
|
|
25
|
+
return typeof deps === "object" && deps !== null && Object.values(deps).some(isCatalogOrWorkspaceSpec);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Compute the final manifest bytes for a TargetGroup (catalog resolution + standard transforms).
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
async function buildEmittedManifest(options) {
|
|
34
|
+
const { pkg, cwd, targetGroup, devManifest, drop } = options;
|
|
35
|
+
const shouldResolve = (targetGroup.isProd || devManifest === "resolve") && manifestNeedsCatalogResolution(pkg);
|
|
36
|
+
let base = pkg;
|
|
37
|
+
if (shouldResolve) base = await resolveManifest(pkg, cwd);
|
|
38
|
+
base = {
|
|
39
|
+
...base,
|
|
40
|
+
name: targetGroup.name
|
|
41
|
+
};
|
|
42
|
+
return transformManifest(base, {
|
|
43
|
+
transform: drop ? (p) => defaultManifestTransform({ pkg: p }, { drop }) : void 0,
|
|
44
|
+
dual: options.dual ?? false,
|
|
45
|
+
subdirExports: options.subdirExports,
|
|
46
|
+
exeRewrite: options.exeRewrite,
|
|
47
|
+
emitDts: options.emitDts ?? true
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Rolldown plugin: emit the transformed package.json + LICENSE/README into the output pkg/ root.
|
|
52
|
+
*
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
function emitManifest(options) {
|
|
56
|
+
const sourceDir = options.sourceDir;
|
|
57
|
+
return {
|
|
58
|
+
name: "savvy:emit-manifest",
|
|
59
|
+
async generateBundle() {
|
|
60
|
+
const manifest = await buildEmittedManifest({
|
|
61
|
+
pkg: JSON.parse(await readFile(join(sourceDir, "package.json"), "utf-8")),
|
|
62
|
+
cwd: sourceDir,
|
|
63
|
+
targetGroup: options.targetGroup,
|
|
64
|
+
devManifest: options.devManifest ?? "preserve",
|
|
65
|
+
drop: options.drop,
|
|
66
|
+
dual: options.dual,
|
|
67
|
+
subdirExports: options.subdirExports,
|
|
68
|
+
exeRewrite: options.exeRewrite,
|
|
69
|
+
emitDts: options.emitDts
|
|
70
|
+
});
|
|
71
|
+
this.emitFile({
|
|
72
|
+
type: "asset",
|
|
73
|
+
fileName: "package.json",
|
|
74
|
+
source: `${JSON.stringify(manifest, null, " ")}\n`
|
|
75
|
+
});
|
|
76
|
+
for (const name of ["LICENSE", "README.md"]) try {
|
|
77
|
+
const content = await readFile(join(sourceDir, name), "utf-8");
|
|
78
|
+
this.emitFile({
|
|
79
|
+
type: "asset",
|
|
80
|
+
fileName: name,
|
|
81
|
+
source: content
|
|
82
|
+
});
|
|
83
|
+
} catch {}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { buildEmittedManifest, emitManifest, manifestNeedsCatalogResolution };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { isAbsolute, join, sep } from "node:path";
|
|
3
|
+
|
|
4
|
+
// src/manifest/export-patterns.ts
|
|
5
|
+
const stripDotSlash = (path) => path.startsWith("./") ? path.slice(2) : path;
|
|
6
|
+
/** Every string target under an export's value, conditions included; a `null` exclusion has none. */
|
|
7
|
+
const targetsOf = (value) => {
|
|
8
|
+
if (typeof value === "string") return [value];
|
|
9
|
+
if (Array.isArray(value)) return value.flatMap(targetsOf);
|
|
10
|
+
if (typeof value === "object" && value !== null) return Object.values(value).flatMap(targetsOf);
|
|
11
|
+
return [];
|
|
12
|
+
};
|
|
13
|
+
/** Node's pattern rule: the one `*` stands for a non-empty run of characters, `/` included. */
|
|
14
|
+
const matchesAny = (target, files) => {
|
|
15
|
+
const star = target.indexOf("*");
|
|
16
|
+
const prefix = target.slice(0, star).replace(/^\.\//, "");
|
|
17
|
+
const suffix = target.slice(star + 1);
|
|
18
|
+
return files.some((file) => file.length > prefix.length + suffix.length && file.startsWith(prefix) && file.endsWith(suffix));
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The `exports` and `bin` entries of the manifest in `pkgDir` whose targets match no file there: a `*` pattern that
|
|
22
|
+
* matches nothing, or a relative literal target (`./foo.js`, `bin/cli.js`) that is not a file. A package with no
|
|
23
|
+
* readable manifest has none.
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
function unmatchedExportPatterns(pkgDir, options = {}) {
|
|
28
|
+
let manifest;
|
|
29
|
+
try {
|
|
30
|
+
manifest = JSON.parse(readFileSync(join(pkgDir, "package.json"), "utf-8"));
|
|
31
|
+
} catch {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
const ignore = new Set((options.ignore ?? []).map(stripDotSlash));
|
|
35
|
+
const exportsMap = manifest.exports;
|
|
36
|
+
const exportTargets = (typeof exportsMap === "string" ? [[".", exportsMap]] : typeof exportsMap === "object" && exportsMap !== null ? Object.entries(exportsMap) : []).flatMap(([key, value]) => targetsOf(value).filter((target) => target.startsWith("./") && !target.endsWith("/")).map((target) => ({
|
|
37
|
+
field: "exports",
|
|
38
|
+
key,
|
|
39
|
+
target
|
|
40
|
+
})));
|
|
41
|
+
const bin = manifest.bin;
|
|
42
|
+
const binTargets = (typeof bin === "string" ? [["bin", bin]] : typeof bin === "object" && bin !== null ? Object.entries(bin).filter((entry) => typeof entry[1] === "string") : []).filter(([, target]) => !isAbsolute(target) && !target.startsWith("../")).map(([key, target]) => ({
|
|
43
|
+
field: "bin",
|
|
44
|
+
key,
|
|
45
|
+
target
|
|
46
|
+
}));
|
|
47
|
+
const targets = [...exportTargets, ...binTargets].filter(({ target }) => !ignore.has(stripDotSlash(target)));
|
|
48
|
+
const missingLiterals = targets.filter(({ target }) => !target.includes("*")).filter(({ target }) => statSync(join(pkgDir, target), { throwIfNoEntry: false })?.isFile() !== true);
|
|
49
|
+
const patterns = targets.filter(({ target }) => target.includes("*"));
|
|
50
|
+
if (patterns.length === 0) return missingLiterals;
|
|
51
|
+
const files = readdirSync(pkgDir, {
|
|
52
|
+
recursive: true,
|
|
53
|
+
encoding: "utf-8"
|
|
54
|
+
}).filter((path) => statSync(join(pkgDir, path), { throwIfNoEntry: false })?.isFile() === true).map((path) => path.split(sep).join("/"));
|
|
55
|
+
return [...missingLiterals, ...patterns.filter(({ target }) => !matchesAny(target, files))];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { unmatchedExportPatterns };
|