@effected/bundler 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Bundler.js +498 -0
- package/BundlerError.js +39 -0
- package/LICENSE +21 -0
- package/README.md +84 -2
- package/action/ActionBuilder.js +108 -0
- package/action/ActionBundle.js +272 -0
- package/action/ActionErrors.js +83 -0
- package/action/ActionValidation.js +195 -0
- package/action/ActionYml.js +366 -0
- package/action/PersistLocal.js +186 -0
- package/action/entries.js +23 -0
- package/action/ignore-stub-plugin.js +25 -0
- package/action/import-check.js +134 -0
- package/assets/Inter-SemiBold.ttf +0 -0
- package/assets/LICENSE-Inter.txt +92 -0
- package/catalog/resolve-catalogs.js +32 -0
- package/changesets/next-versions.js +50 -0
- package/config/ActionConfig.js +102 -0
- package/config/BuildConfig.js +438 -0
- package/config/EffectedConfigFile.js +171 -0
- package/config/merge.js +20 -0
- package/config/plugins.js +84 -0
- package/config-validation/ConfigValidator.js +73 -0
- package/dts/bundled-siblings.js +108 -0
- package/dts/parse.js +28 -0
- package/dts/reexport-stub.js +94 -0
- package/dts/relative-imports.js +33 -0
- package/dts/resolved-tsconfig.js +238 -0
- package/entries/ambient-dts.js +108 -0
- package/entries/export-paths.js +16 -0
- package/entries/extract.js +79 -0
- package/entries/package-json-entries.js +19 -0
- package/errors.js +37 -0
- package/exe/build.js +55 -0
- package/exe/config.js +54 -0
- package/exe/filename.js +13 -0
- package/index.d.ts +3619 -0
- package/index.js +57 -0
- package/internal/causeMessage.js +57 -0
- package/journal/BuildJournal.js +107 -0
- package/jsx/config.js +44 -0
- package/manifest/built-condition.js +120 -0
- package/manifest/emit-manifest.js +93 -0
- package/manifest/export-patterns.js +56 -0
- package/manifest/manifest-set.js +101 -0
- package/manifest/transform.js +324 -0
- package/meta/api-extractor.js +241 -0
- package/meta/bundle-config.js +22 -0
- package/meta/bundle-manifest.js +134 -0
- package/meta/bundle-source.js +106 -0
- package/meta/config.js +24 -0
- package/meta/generate.js +249 -0
- package/meta/merge-models.js +43 -0
- package/meta/message-suppressor.js +43 -0
- package/meta/og-image.js +137 -0
- package/meta/og-satori.js +140 -0
- package/meta/optimistic.js +32 -0
- package/meta/run-pass.js +124 -0
- package/meta/scrub-declaration-maps.js +63 -0
- package/meta/tsconfig-resolver.js +55 -0
- package/meta/tsdoc-config.js +47 -0
- package/package.json +86 -5
- package/passes/build-target-groups.js +347 -0
- package/passes/cjs-default-interop.js +98 -0
- package/passes/loose-files.js +57 -0
- package/passes/node-builtin-default-interop.js +79 -0
- package/passes/strip-maps.js +40 -0
- package/passes/sync-public.js +100 -0
- package/passes/target-groups.js +112 -0
- package/report/ci-annotations.js +36 -0
- package/report/collector.js +140 -0
- package/report/issues-artifact.js +149 -0
- package/report/metrics-plugin.js +76 -0
- package/report/schema.js +77 -0
- package/report/timer.js +19 -0
- package/report/tsdown-logger.js +58 -0
- package/targets/binding.js +19 -0
- package/targets/config.js +21 -0
- package/targets/resolve-targets.js +165 -0
- package/tsconfig/sync-options.js +20 -0
- package/tsdoc-metadata.json +11 -0
package/index.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
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, BundleConfig, BundleOpenGraphConfig, BundleOpenGraphImage, BundleRegistryRef, CopyEntry, EffectedConfig, EntryOverride, ExeConfig, ExeSeaConfig, ExeTargetConfig, JsxConfig, LooseFileSpec, ManifestConfig, MetaConfig, PackageBuildConfig, PackageConfig, TsdocConfig, TsdocTagDefinition, 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 { BundleManifestEmitError, ConfigValidationError, MetaGenerationError } 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 { composeBundleManifest, githubOwnerRepo, ogImageInfoOf, registriesFromTargets } from "./meta/bundle-manifest.js";
|
|
33
|
+
import { BundleManifestSourceError, loadBundleManifestSources } from "./meta/bundle-source.js";
|
|
34
|
+
import { normalizeMetaOptions } from "./meta/config.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 { buildTargetGroups } from "./passes/build-target-groups.js";
|
|
39
|
+
import { cjsDefaultInterop } from "./passes/cjs-default-interop.js";
|
|
40
|
+
import { normalizeLooseFiles } from "./passes/loose-files.js";
|
|
41
|
+
import { nodeBuiltinDefaultInterop } from "./passes/node-builtin-default-interop.js";
|
|
42
|
+
import { removeDeclarationMaps } from "./passes/strip-maps.js";
|
|
43
|
+
import { copyAmbientDts, copyPublicDir } from "./passes/sync-public.js";
|
|
44
|
+
import { declarationsDirFor, deriveDeclarationsPassOptions, deriveDtsPassOptions, deriveTargetGroupOptions, dtsPassDtsOptions, outDirFor } from "./passes/target-groups.js";
|
|
45
|
+
import { renderCiAnnotations } from "./report/ci-annotations.js";
|
|
46
|
+
import { BuildCollector, BuildCollectorTag } from "./report/collector.js";
|
|
47
|
+
import { BuildIssuesSchema, PlainDiagnosticSchema, flattenIssues, serializeIssues, writeIssuesArtifact } from "./report/issues-artifact.js";
|
|
48
|
+
import { buildMetricsPlugin } from "./report/metrics-plugin.js";
|
|
49
|
+
import { BuildReport, DiagnosticEntry, EmittedFile, PassReport, ReportTimings, TargetGroupReport } from "./report/schema.js";
|
|
50
|
+
import { createTimer, formatTime } from "./report/timer.js";
|
|
51
|
+
import { createTsdownLogger } from "./report/tsdown-logger.js";
|
|
52
|
+
import { writeTargetsBinding } from "./targets/binding.js";
|
|
53
|
+
import { RELEASE_CHANNELS, isTargetObject } from "./targets/config.js";
|
|
54
|
+
import { releaseWarnings, resolveTargets } from "./targets/resolve-targets.js";
|
|
55
|
+
import { BUNDLE_MANIFEST_FILENAME, BundleManifest, BundleManifestError, KNOWN_REGISTRY_TYPES, MANIFEST_SPEC, ManifestSource, OpenGraphConfig, OpenGraphImage, ProjectIdentity, RegistryRef, SbomRef, decodeBundleManifest, decodeManifestSource, encodeBundleManifest, isKnownRegistryType } from "@effected/manifest";
|
|
56
|
+
|
|
57
|
+
export { ActionBuildOptions, ActionBuildResult, ActionBuilder, ActionBundle, ActionConfig, ActionEntries, ActionPersistLocalOptions, ActionValidation, ActionValidationOptions, ActionYml, ActionYmlBranding, ActionYmlBrandingColor, ActionYmlBrandingIcon, ActionYmlInput, ActionYmlOutput, ActionYmlPathError, ActionYmlRuns, BUNDLE_MANIFEST_FILENAME, BuildCollector, BuildCollectorTag, BuildFailed, BuildFormat, BuildIssuesSchema, BuildJournal, BuildPlatform, BuildReport, BuildResult, BundleConfig, BundleFailed, BundleManifest, BundleManifestEmitError, BundleManifestError, BundleManifestSourceError, BundleOpenGraphConfig, BundleOpenGraphImage, BundleRegistryRef, 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, TargetGroupReport, TsdocConfig, TsdocTagDefinition, ValidationFailed, ValidationIssue, ValidationResult, WarningSuppressionRule, WriteError, ambientOutName, analyzeReexportBarrel, assertNoEntryCollisions, buildEmittedManifest, buildMetricsPlugin, buildResolvedTsconfig, buildTargetGroups, cjsDefaultInterop, classifyDtsExport, collectExportNames, composeBundleManifest, 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, loadBundleManifestSources, loadPlugins, 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,107 @@
|
|
|
1
|
+
import { BuildIssuesSchema, PlainDiagnosticSchema } from "../report/issues-artifact.js";
|
|
2
|
+
import { Effect, FileSystem, Layer, Path, Schema } from "effect";
|
|
3
|
+
import { Journal, JsonlEvent } from "@effected/jsonl";
|
|
4
|
+
|
|
5
|
+
// src/journal/BuildJournal.ts
|
|
6
|
+
/** Each journal's place under the workspace root. */
|
|
7
|
+
const BUILD_JOURNAL_PATH = ".cache/effected/build.jsonl";
|
|
8
|
+
const ISSUE_JOURNAL_PATH = ".cache/effected/issues.jsonl";
|
|
9
|
+
/**
|
|
10
|
+
* The journal at `relative` under `root`, with its directory made first: appending never creates the directory, and
|
|
11
|
+
* the journal itself is created through its own `create`.
|
|
12
|
+
*/
|
|
13
|
+
const journalPathAt = (root, relative) => Effect.gen(function* () {
|
|
14
|
+
const fs = yield* FileSystem.FileSystem;
|
|
15
|
+
const path = yield* Path.Path;
|
|
16
|
+
const file = path.join(root, relative);
|
|
17
|
+
yield* fs.makeDirectory(path.dirname(file), { recursive: true });
|
|
18
|
+
return file;
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* The per-diagnostic journal: one line per error and warning of a build, in that order, scoped by package name.
|
|
22
|
+
* Suppressed diagnostics stay in `issues.json` and are counted on the build's line.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
var IssueJournal = class IssueJournal extends Journal.Service()("effected/IssueJournal", {
|
|
27
|
+
events: [JsonlEvent.make("issue", { data: Schema.Struct({
|
|
28
|
+
package: Schema.String,
|
|
29
|
+
generatedAt: Schema.String,
|
|
30
|
+
...PlainDiagnosticSchema.fields
|
|
31
|
+
}) })],
|
|
32
|
+
config: { path: ISSUE_JOURNAL_PATH }
|
|
33
|
+
}) {
|
|
34
|
+
/**
|
|
35
|
+
* The journal at `<root>/.cache/effected/issues.jsonl`, with its directory and file created.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* Every call is a fresh layer, and every build of one an independent journal: bind it to one const.
|
|
39
|
+
*
|
|
40
|
+
* @param root - The workspace root.
|
|
41
|
+
*/
|
|
42
|
+
static layerAt = (root) => Layer.effect(IssueJournal, journalPathAt(root, ISSUE_JOURNAL_PATH).pipe(Effect.flatMap((path) => IssueJournal.make({ path })), Effect.tap((journal) => journal.create)));
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* The per-build journal: one line per finished build, scoped by package name.
|
|
46
|
+
*
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
var BuildJournal = class BuildJournal extends Journal.Service()("effected/BuildJournal", {
|
|
50
|
+
events: [JsonlEvent.make("build", { data: Schema.Struct({
|
|
51
|
+
package: Schema.String,
|
|
52
|
+
cwd: Schema.String,
|
|
53
|
+
generatedAt: Schema.String,
|
|
54
|
+
buildOk: Schema.Boolean,
|
|
55
|
+
failure: BuildIssuesSchema.fields.failure,
|
|
56
|
+
errors: Schema.Number,
|
|
57
|
+
warnings: Schema.Number,
|
|
58
|
+
suppressed: Schema.Number,
|
|
59
|
+
issuesPath: Schema.String
|
|
60
|
+
}) })],
|
|
61
|
+
config: { path: BUILD_JOURNAL_PATH }
|
|
62
|
+
}) {
|
|
63
|
+
/**
|
|
64
|
+
* The journal at `<root>/.cache/effected/build.jsonl`, with its directory and file created.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* Every call is a fresh layer, and every build of one an independent journal: bind it to one const.
|
|
68
|
+
*
|
|
69
|
+
* @param root - The workspace root.
|
|
70
|
+
*/
|
|
71
|
+
static layerAt = (root) => Layer.effect(BuildJournal, journalPathAt(root, BUILD_JOURNAL_PATH).pipe(Effect.flatMap((path) => BuildJournal.make({ path })), Effect.tap((journal) => journal.create)));
|
|
72
|
+
/**
|
|
73
|
+
* Appends one finished build: a line per error and warning, then the build's own line.
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* The build's line goes last, so a watcher that sees it finds that build's issues already written. Each line's
|
|
77
|
+
* `scope` is the package name, which is what a read filters on. Parallel builds may record at once: each line is
|
|
78
|
+
* one `O_APPEND` write.
|
|
79
|
+
*
|
|
80
|
+
* @param issues - The build's `issues.json`.
|
|
81
|
+
* @param cwd - The package directory the artifact sits under.
|
|
82
|
+
*/
|
|
83
|
+
static record = Effect.fn("BuildJournal.record")(function* (issues, cwd) {
|
|
84
|
+
const path = yield* Path.Path;
|
|
85
|
+
const builds = yield* BuildJournal;
|
|
86
|
+
const journal = yield* IssueJournal;
|
|
87
|
+
const scope = { scope: issues.package };
|
|
88
|
+
for (const diagnostic of [...issues.errors, ...issues.warnings]) yield* journal.append("issue", {
|
|
89
|
+
package: issues.package,
|
|
90
|
+
generatedAt: issues.generatedAt,
|
|
91
|
+
...diagnostic
|
|
92
|
+
}, scope);
|
|
93
|
+
yield* builds.append("build", {
|
|
94
|
+
package: issues.package,
|
|
95
|
+
cwd,
|
|
96
|
+
generatedAt: issues.generatedAt,
|
|
97
|
+
buildOk: issues.buildOk,
|
|
98
|
+
...issues.failure !== void 0 ? { failure: issues.failure } : {},
|
|
99
|
+
errors: issues.errors.length,
|
|
100
|
+
warnings: issues.warnings.length,
|
|
101
|
+
suppressed: issues.suppressed.length,
|
|
102
|
+
issuesPath: path.join(cwd, "dist", issues.target, "issues.json")
|
|
103
|
+
}, scope);
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export { BuildJournal, IssueJournal };
|
package/jsx/config.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Effect, FileSystem, Option, Path } from "effect";
|
|
2
|
+
import { JsxConfig, TsconfigLoader } from "@effected/tsconfig-json";
|
|
3
|
+
|
|
4
|
+
// src/jsx/config.ts
|
|
5
|
+
/**
|
|
6
|
+
* Resolve the effective JSX config: an explicit override wins; otherwise infer from the tsconfig
|
|
7
|
+
* values via `@effected/tsconfig-json`'s `JsxConfig.fromCompilerOptions`. Returns undefined when
|
|
8
|
+
* no JSX transform is needed (preserve/none).
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
function resolveJsxConfig(tsconfig, override) {
|
|
12
|
+
if (override !== void 0) return override.runtime === "automatic" ? {
|
|
13
|
+
runtime: "automatic",
|
|
14
|
+
importSource: override.importSource ?? "react"
|
|
15
|
+
} : override;
|
|
16
|
+
const inferred = JsxConfig.fromCompilerOptions({
|
|
17
|
+
...tsconfig.jsx !== void 0 ? { jsx: tsconfig.jsx } : {},
|
|
18
|
+
...tsconfig.jsxImportSource !== void 0 ? { jsxImportSource: tsconfig.jsxImportSource } : {}
|
|
19
|
+
});
|
|
20
|
+
return Option.match(inferred, {
|
|
21
|
+
onNone: () => void 0,
|
|
22
|
+
onSome: (cfg) => ({
|
|
23
|
+
runtime: cfg.runtime,
|
|
24
|
+
...cfg.importSource !== void 0 ? { importSource: cfg.importSource } : {}
|
|
25
|
+
})
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Read the jsx-relevant compilerOptions from a package's own tsconfig.json (best-effort;
|
|
30
|
+
* answers empty on absence or on a read or parse failure; a loader defect is not swallowed). Resolved through `@effected/tsconfig-json`'s
|
|
31
|
+
* loader, so JSONC syntax and `extends` chains are honored.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
const readTsconfigJsx = Effect.fnUntraced(function* (cwd) {
|
|
35
|
+
const fs = yield* FileSystem.FileSystem;
|
|
36
|
+
const file = (yield* Path.Path).join(cwd, "tsconfig.json");
|
|
37
|
+
if (!(yield* fs.exists(file).pipe(Effect.orElseSucceed(() => false)))) return {};
|
|
38
|
+
return yield* TsconfigLoader.compilerOptions(file).pipe(Effect.map((co) => ({
|
|
39
|
+
...co.jsx !== void 0 ? { jsx: co.jsx } : {},
|
|
40
|
+
...co.jsxImportSource !== void 0 ? { jsxImportSource: co.jsxImportSource } : {}
|
|
41
|
+
})), Effect.orElseSucceed(() => ({})));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export { readTsconfigJsx, resolveJsxConfig };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { ConfigValidationError } from "../errors.js";
|
|
2
|
+
|
|
3
|
+
// src/manifest/built-condition.ts
|
|
4
|
+
/**
|
|
5
|
+
* The export condition that routes a workspace consumer to a sibling's built output instead of its source.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Workspace links resolve to `src/`, which tsx and vitest load and plain Node does not. A consumer that loads a
|
|
9
|
+
* sibling in plain Node, such as a framework CLI importing a workspace plugin, runs with
|
|
10
|
+
* `--conditions=effected-built` and reaches the `./dist/prod/<group>/pkg/...` file this condition names. Every other
|
|
11
|
+
* resolver ignores an unknown condition and falls through to the source. The build strips the condition, so it never
|
|
12
|
+
* publishes.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
const BUILT_CONDITION = "effected-built";
|
|
17
|
+
/** The prefix every built-condition target must carry: the build's one output tree. */
|
|
18
|
+
const BUILT_PREFIX = "./dist/prod/";
|
|
19
|
+
const conditionError = (exportKey, reason) => new ConfigValidationError({
|
|
20
|
+
path: `exports."${exportKey}".${BUILT_CONDITION}`,
|
|
21
|
+
reason
|
|
22
|
+
});
|
|
23
|
+
const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
24
|
+
/** Whether a condition object holds the built condition at any depth. */
|
|
25
|
+
const holdsCondition = (value) => isRecord(value) && Object.entries(value).some(([key, inner]) => key === "effected-built" || holdsCondition(inner));
|
|
26
|
+
/**
|
|
27
|
+
* Refuse a built condition that could not take effect or could not be checked, and answer every one that can.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* It must be the first key of a subpath's condition object, since Node takes the first condition it matches and
|
|
31
|
+
* `import` and `default` match in plain Node too. Its value must be a literal path under `./dist/prod/`, an `import` or
|
|
32
|
+
* `default` condition naming the source must follow it, and it may not
|
|
33
|
+
* nest inside another condition or sit in a root-level condition object, which has no subpath key to check it against.
|
|
34
|
+
*
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
function builtConditionTargets(exports) {
|
|
38
|
+
if (!isRecord(exports)) return [];
|
|
39
|
+
const entries = Object.entries(exports);
|
|
40
|
+
if (!entries.some(([key]) => key.startsWith("."))) {
|
|
41
|
+
if (holdsCondition(exports)) throw conditionError(".", "a root-level condition object cannot carry it; write the export under a \".\" subpath key");
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
const targets = [];
|
|
45
|
+
for (const [exportKey, value] of entries) {
|
|
46
|
+
if (!isRecord(value)) continue;
|
|
47
|
+
const conditions = Object.entries(value);
|
|
48
|
+
for (const [index, [condition, target]] of conditions.entries()) {
|
|
49
|
+
if (condition !== "effected-built") {
|
|
50
|
+
if (holdsCondition(target)) throw conditionError(exportKey, `it cannot nest inside the "${condition}" condition; make it the first key`);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (index !== 0) throw conditionError(exportKey, "it must be the first condition, or Node resolves an earlier one (import and default match in plain Node too)");
|
|
54
|
+
if (typeof target !== "string" || !target.startsWith(BUILT_PREFIX) || target.includes("*")) throw conditionError(exportKey, `its value must be a literal path into the build's output, "${BUILT_PREFIX}<group>/pkg/<file>"`);
|
|
55
|
+
if (!conditions.slice(1).some(([after, source]) => (after === "import" || after === "default") && typeof source === "string")) throw conditionError(exportKey, "it needs an \"import\" or \"default\" condition after it, naming the source every other resolver takes");
|
|
56
|
+
targets.push({
|
|
57
|
+
exportKey,
|
|
58
|
+
target
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return targets;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A copy of `pkg` with the built condition removed from every subpath's condition object, and from a root-level
|
|
66
|
+
* condition object. A manifest without it is returned unchanged.
|
|
67
|
+
*
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
function stripBuiltCondition(pkg) {
|
|
71
|
+
const { exports } = pkg;
|
|
72
|
+
if (!isRecord(exports)) return pkg;
|
|
73
|
+
if ("effected-built" in exports) {
|
|
74
|
+
const { [BUILT_CONDITION]: _built, ...rest } = exports;
|
|
75
|
+
return {
|
|
76
|
+
...pkg,
|
|
77
|
+
exports: rest
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
if (!Object.values(exports).some((value) => isRecord(value) && "effected-built" in value)) return pkg;
|
|
81
|
+
const next = {};
|
|
82
|
+
for (const [exportKey, value] of Object.entries(exports)) if (isRecord(value) && "effected-built" in value) {
|
|
83
|
+
const { [BUILT_CONDITION]: _built, ...rest } = value;
|
|
84
|
+
next[exportKey] = rest;
|
|
85
|
+
} else next[exportKey] = value;
|
|
86
|
+
return {
|
|
87
|
+
...pkg,
|
|
88
|
+
exports: next
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Each built-condition target that names no file a group emitted for its export, with the path it should name.
|
|
93
|
+
*
|
|
94
|
+
* @remarks
|
|
95
|
+
* `emitted` maps a group id to that group's emitted `exports`. A target matches when it is
|
|
96
|
+
* `./dist/prod/<group>/pkg/` joined to the file the group's manifest exports for the same key under `import` or
|
|
97
|
+
* `default`. The expected path is the first group's.
|
|
98
|
+
*
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
function mismatchedBuiltTargets(targets, emitted) {
|
|
102
|
+
const builtPathFor = (groupId, exports, exportKey) => {
|
|
103
|
+
if (!isRecord(exports)) return void 0;
|
|
104
|
+
const value = exports[exportKey];
|
|
105
|
+
const file = typeof value === "string" ? value : isRecord(value) ? value.import ?? value.default : void 0;
|
|
106
|
+
return typeof file === "string" && file.startsWith("./") ? `${BUILT_PREFIX}${groupId}/pkg/${file.slice(2)}` : void 0;
|
|
107
|
+
};
|
|
108
|
+
const out = [];
|
|
109
|
+
for (const target of targets) {
|
|
110
|
+
const candidates = emitted.map((group) => builtPathFor(group.groupId, group.exports, target.exportKey));
|
|
111
|
+
if (candidates.includes(target.target)) continue;
|
|
112
|
+
out.push({
|
|
113
|
+
...target,
|
|
114
|
+
expected: candidates.find((candidate) => candidate !== void 0)
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export { BUILT_CONDITION, builtConditionTargets, mismatchedBuiltTargets, stripBuiltCondition };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { resolveManifest } from "../catalog/resolve-catalogs.js";
|
|
2
|
+
import { stripBuiltCondition } from "./built-condition.js";
|
|
3
|
+
import { applyManifestSet, validateManifestSet } from "./manifest-set.js";
|
|
4
|
+
import { defaultManifestTransform, transformManifest } from "./transform.js";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { readFile } from "node:fs/promises";
|
|
7
|
+
import { DependencySpecifier } from "@effected/npm";
|
|
8
|
+
|
|
9
|
+
// src/manifest/emit-manifest.ts
|
|
10
|
+
const DEPENDENCY_FIELDS = [
|
|
11
|
+
"dependencies",
|
|
12
|
+
"devDependencies",
|
|
13
|
+
"peerDependencies",
|
|
14
|
+
"optionalDependencies"
|
|
15
|
+
];
|
|
16
|
+
const isCatalogOrWorkspaceSpec = (spec) => typeof spec === "string" && (DependencySpecifier.isCatalog(spec) || DependencySpecifier.isWorkspace(spec));
|
|
17
|
+
/**
|
|
18
|
+
* Whether any of `pkg`'s four dependency fields carries at least one `catalog:`/`workspace:`
|
|
19
|
+
* specifier. `resolveManifest` returns a manifest with none of these unchanged, so callers can
|
|
20
|
+
* skip the CatalogResolver + pnpm-workspace + lockfile assembly entirely when this is false.
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
function manifestNeedsCatalogResolution(pkg) {
|
|
25
|
+
return DEPENDENCY_FIELDS.some((field) => {
|
|
26
|
+
const deps = pkg[field];
|
|
27
|
+
return typeof deps === "object" && deps !== null && Object.values(deps).some(isCatalogOrWorkspaceSpec);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Compute the final manifest bytes for a TargetGroup (catalog resolution + standard transforms).
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
async function buildEmittedManifest(options) {
|
|
36
|
+
const { cwd, targetGroup, devManifest, drop, set } = options;
|
|
37
|
+
if (set !== void 0) validateManifestSet(set, drop ?? []);
|
|
38
|
+
const pkg = stripBuiltCondition(options.pkg);
|
|
39
|
+
const shouldResolve = (targetGroup.isProd || devManifest === "resolve") && manifestNeedsCatalogResolution(pkg);
|
|
40
|
+
let base = pkg;
|
|
41
|
+
if (shouldResolve) base = await resolveManifest(pkg, cwd);
|
|
42
|
+
base = {
|
|
43
|
+
...base,
|
|
44
|
+
name: targetGroup.name
|
|
45
|
+
};
|
|
46
|
+
return transformManifest(base, {
|
|
47
|
+
transform: drop !== void 0 || set !== void 0 ? (p) => applyManifestSet(drop !== void 0 ? defaultManifestTransform({ pkg: p }, { drop }) : p, set) : void 0,
|
|
48
|
+
dual: options.dual ?? false,
|
|
49
|
+
subdirExports: options.subdirExports,
|
|
50
|
+
exeRewrite: options.exeRewrite,
|
|
51
|
+
emitDts: options.emitDts ?? true
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Rolldown plugin: emit the transformed package.json + LICENSE/README into the output pkg/ root.
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
function emitManifest(options) {
|
|
60
|
+
const sourceDir = options.sourceDir;
|
|
61
|
+
return {
|
|
62
|
+
name: "savvy:emit-manifest",
|
|
63
|
+
async generateBundle() {
|
|
64
|
+
const manifest = await buildEmittedManifest({
|
|
65
|
+
pkg: JSON.parse(await readFile(join(sourceDir, "package.json"), "utf-8")),
|
|
66
|
+
cwd: sourceDir,
|
|
67
|
+
targetGroup: options.targetGroup,
|
|
68
|
+
devManifest: options.devManifest ?? "preserve",
|
|
69
|
+
drop: options.drop,
|
|
70
|
+
set: options.set,
|
|
71
|
+
dual: options.dual,
|
|
72
|
+
subdirExports: options.subdirExports,
|
|
73
|
+
exeRewrite: options.exeRewrite,
|
|
74
|
+
emitDts: options.emitDts
|
|
75
|
+
});
|
|
76
|
+
this.emitFile({
|
|
77
|
+
type: "asset",
|
|
78
|
+
fileName: "package.json",
|
|
79
|
+
source: `${JSON.stringify(manifest, null, " ")}\n`
|
|
80
|
+
});
|
|
81
|
+
for (const name of ["LICENSE", "README.md"]) try {
|
|
82
|
+
const content = await readFile(join(sourceDir, name), "utf-8");
|
|
83
|
+
this.emitFile({
|
|
84
|
+
type: "asset",
|
|
85
|
+
fileName: name,
|
|
86
|
+
source: content
|
|
87
|
+
});
|
|
88
|
+
} catch {}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { buildEmittedManifest, emitManifest, manifestNeedsCatalogResolution };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Effect, FileSystem, Path } from "effect";
|
|
2
|
+
|
|
3
|
+
// src/manifest/export-patterns.ts
|
|
4
|
+
const stripDotSlash = (path) => path.startsWith("./") ? path.slice(2) : path;
|
|
5
|
+
/** Every string target under an export's value, conditions included; a `null` exclusion has none. */
|
|
6
|
+
const targetsOf = (value) => {
|
|
7
|
+
if (typeof value === "string") return [value];
|
|
8
|
+
if (Array.isArray(value)) return value.flatMap(targetsOf);
|
|
9
|
+
if (typeof value === "object" && value !== null) return Object.values(value).flatMap(targetsOf);
|
|
10
|
+
return [];
|
|
11
|
+
};
|
|
12
|
+
/** Node's pattern rule: the one `*` stands for a non-empty run of characters, `/` included. */
|
|
13
|
+
const matchesAny = (target, files) => {
|
|
14
|
+
const star = target.indexOf("*");
|
|
15
|
+
const prefix = target.slice(0, star).replace(/^\.\//, "");
|
|
16
|
+
const suffix = target.slice(star + 1);
|
|
17
|
+
return files.some((file) => file.length > prefix.length + suffix.length && file.startsWith(prefix) && file.endsWith(suffix));
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The `exports` and `bin` entries of the manifest in `pkgDir` whose targets match no file there: a `*` pattern that
|
|
21
|
+
* matches nothing, or a relative literal target (`./foo.js`, `bin/cli.js`) that is not a file. A package with no
|
|
22
|
+
* readable manifest has none.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
const unmatchedExportPatterns = Effect.fnUntraced(function* (pkgDir, options = {}) {
|
|
27
|
+
const fs = yield* FileSystem.FileSystem;
|
|
28
|
+
const path = yield* Path.Path;
|
|
29
|
+
const isFile = (file) => fs.stat(file).pipe(Effect.map((info) => info.type === "File"), Effect.orElseSucceed(() => false));
|
|
30
|
+
const read = yield* fs.readFileString(path.join(pkgDir, "package.json")).pipe(Effect.flatMap((text) => Effect.try(() => JSON.parse(text))), Effect.option);
|
|
31
|
+
if (read._tag === "None") return [];
|
|
32
|
+
const manifest = read.value;
|
|
33
|
+
const ignore = new Set((options.ignore ?? []).map(stripDotSlash));
|
|
34
|
+
const exportsMap = manifest.exports;
|
|
35
|
+
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) => ({
|
|
36
|
+
field: "exports",
|
|
37
|
+
key,
|
|
38
|
+
target
|
|
39
|
+
})));
|
|
40
|
+
const bin = manifest.bin;
|
|
41
|
+
const binTargets = (typeof bin === "string" ? [["bin", bin]] : typeof bin === "object" && bin !== null ? Object.entries(bin).filter((entry) => typeof entry[1] === "string") : []).filter(([, target]) => !path.isAbsolute(target) && !target.startsWith("../")).map(([key, target]) => ({
|
|
42
|
+
field: "bin",
|
|
43
|
+
key,
|
|
44
|
+
target
|
|
45
|
+
}));
|
|
46
|
+
const targets = [...exportTargets, ...binTargets].filter(({ target }) => !ignore.has(stripDotSlash(target)));
|
|
47
|
+
const literals = targets.filter(({ target }) => !target.includes("*"));
|
|
48
|
+
const missingLiterals = yield* Effect.filter(literals, ({ target }) => Effect.map(isFile(path.join(pkgDir, target)), (file) => !file));
|
|
49
|
+
const patterns = targets.filter(({ target }) => target.includes("*"));
|
|
50
|
+
if (patterns.length === 0) return missingLiterals;
|
|
51
|
+
const entries = yield* fs.readDirectory(pkgDir, { recursive: true });
|
|
52
|
+
const files = (yield* Effect.filter(entries, (entry) => isFile(path.join(pkgDir, entry)))).map((entry) => entry.split(path.sep).join("/"));
|
|
53
|
+
return [...missingLiterals, ...patterns.filter(({ target }) => !matchesAny(target, files))];
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export { unmatchedExportPatterns };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { ConfigValidationError } from "../errors.js";
|
|
2
|
+
import { PackageName } from "@effected/package-json";
|
|
3
|
+
|
|
4
|
+
// src/manifest/manifest-set.ts
|
|
5
|
+
/**
|
|
6
|
+
* Top-level keys the build or the release owns, each with the reason a config author reads when `set` names one.
|
|
7
|
+
*
|
|
8
|
+
* Every one is owned by something other than the config: the release tooling, the publish decision, the build's own
|
|
9
|
+
* rewrite of the source manifest, or the always-stripped build-only fields. A string written over one would publish a
|
|
10
|
+
* manifest that disagrees with what was built or released.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
const PROTECTED_KEYS = {
|
|
15
|
+
version: "the version is owned by the release: changesets bump it, the release tags it and the API model's optimistic version reads it",
|
|
16
|
+
private: "publishability is derived from publishConfig.access, which \"set\" must not contradict",
|
|
17
|
+
type: "the build emits ES modules as .js, which the module type has to keep loadable",
|
|
18
|
+
exports: "the build rewrites the exports map to the files it emits",
|
|
19
|
+
bin: "the build rewrites bin to the files it emits",
|
|
20
|
+
files: "the build adds what it emits to files",
|
|
21
|
+
main: "write an exports entry instead; the build emits from exports and bin",
|
|
22
|
+
module: "write an exports entry instead; the build emits from exports and bin",
|
|
23
|
+
types: "the build generates the declarations and points exports at them",
|
|
24
|
+
typings: "the build generates the declarations and points exports at them",
|
|
25
|
+
dependencies: "dependency maps are objects, and the build resolves their catalog: and workspace: specifiers",
|
|
26
|
+
peerDependencies: "dependency maps are objects, and the build resolves their catalog: and workspace: specifiers",
|
|
27
|
+
optionalDependencies: "dependency maps are objects, and the build resolves their catalog: and workspace: specifiers",
|
|
28
|
+
devDependencies: "always stripped from the emitted manifest",
|
|
29
|
+
bundleDependencies: "always stripped from the emitted manifest",
|
|
30
|
+
bundledDependencies: "always stripped from the emitted manifest",
|
|
31
|
+
scripts: "always stripped from the emitted manifest",
|
|
32
|
+
publishConfig: "always stripped from the emitted manifest; publish targets are read from the source manifest",
|
|
33
|
+
packageManager: "always stripped from the emitted manifest",
|
|
34
|
+
devEngines: "always stripped from the emitted manifest"
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The top-level keys `set` may write: those npm's package.json reference documents as taking a string, alone or as
|
|
38
|
+
* one accepted form, and that nothing in the build or the release owns.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* `name`, `description`, `homepage` and `license` are strings. `author`, `bugs`, `funding` and `repository` each also
|
|
42
|
+
* take a string shorthand (`"Name <email> (url)"`, an issues URL, a funding URL, `"github:owner/repo"`). `browser`
|
|
43
|
+
* takes a string replacement for `main`, and `man` a single page's path. Every other documented key is a boolean, an
|
|
44
|
+
* array or an object (`sideEffects`, `keywords`, `os`, `cpu`, `engines`, `imports`, `workspaces`, ...), so a string
|
|
45
|
+
* written over it would publish a value of the wrong type, and an undocumented key has no type to check.
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
const STRING_KEYS = [
|
|
50
|
+
"name",
|
|
51
|
+
"description",
|
|
52
|
+
"homepage",
|
|
53
|
+
"license",
|
|
54
|
+
"author",
|
|
55
|
+
"bugs",
|
|
56
|
+
"funding",
|
|
57
|
+
"repository",
|
|
58
|
+
"browser",
|
|
59
|
+
"man"
|
|
60
|
+
];
|
|
61
|
+
const setError = (key, reason) => new ConfigValidationError({
|
|
62
|
+
path: `manifest.set.${key}`,
|
|
63
|
+
reason
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Refuse a `[package.build.manifest] set` table the build could not honour: a protected key, a key package.json does
|
|
67
|
+
* not type as a string, a key also listed in `drop`, an empty key, or a `name` npm would not accept.
|
|
68
|
+
*
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
function validateManifestSet(set, drop) {
|
|
72
|
+
for (const [key, value] of Object.entries(set)) {
|
|
73
|
+
if (key.length === 0) throw setError("\"\"", "a manifest key cannot be empty");
|
|
74
|
+
const reason = PROTECTED_KEYS[key];
|
|
75
|
+
if (reason !== void 0) throw setError(key, `"${key}" cannot be set: ${reason}`);
|
|
76
|
+
if (!STRING_KEYS.includes(key)) throw setError(key, `"${key}" cannot be set: set writes only keys package.json types as a string (${STRING_KEYS.join(", ")})`);
|
|
77
|
+
if (drop.includes(key)) throw setError(key, `"${key}" is both set and listed in manifest.drop; keep one`);
|
|
78
|
+
if (key === "name" && !PackageName.isValid(value)) throw setError(key, `"${value}" is not a valid npm package name`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The package name every emitted manifest, `targets.json` group and API model carries: `set.name` when written,
|
|
83
|
+
* otherwise the source manifest's.
|
|
84
|
+
*
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
const emittedPackageName = (set, sourceName) => set.name ?? sourceName;
|
|
88
|
+
/**
|
|
89
|
+
* Write the `set` keys other than `name` over an emitted manifest. `name` reaches the manifest through the publish
|
|
90
|
+
* group, so a target's own name override still wins for its group. Pure: returns a copy.
|
|
91
|
+
*
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
94
|
+
function applyManifestSet(pkg, set) {
|
|
95
|
+
if (set === void 0) return pkg;
|
|
96
|
+
const out = { ...pkg };
|
|
97
|
+
for (const [key, value] of Object.entries(set)) if (key !== "name") out[key] = value;
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export { PROTECTED_KEYS, STRING_KEYS, applyManifestSet, emittedPackageName, validateManifestSet };
|