@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/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { BundlerError, BundlerPhase } from "./BundlerError.js";
|
|
|
9
9
|
import { resolveManifest } from "./catalog/resolve-catalogs.js";
|
|
10
10
|
import { resolveNextVersions } from "./changesets/next-versions.js";
|
|
11
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,
|
|
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
13
|
import { EffectedConfigError, EffectedConfigFile, ResolvedConfig, ResolvedEffectedConfig } from "./config/EffectedConfigFile.js";
|
|
14
14
|
import { merge } from "./config/merge.js";
|
|
15
15
|
import { PluginLoadError, loadPlugins } from "./config/plugins.js";
|
|
@@ -21,7 +21,7 @@ import { ambientOutName, assertNoEntryCollisions, classifyDtsExport, declaration
|
|
|
21
21
|
import { deriveExportPaths } from "./entries/export-paths.js";
|
|
22
22
|
import { createEntryName, extractEntries } from "./entries/extract.js";
|
|
23
23
|
import { packageJsonEntries } from "./entries/package-json-entries.js";
|
|
24
|
-
import { ConfigValidationError, MetaGenerationError
|
|
24
|
+
import { BundleManifestEmitError, ConfigValidationError, MetaGenerationError } from "./errors.js";
|
|
25
25
|
import { runExeBuild } from "./exe/build.js";
|
|
26
26
|
import { DEFAULT_EXE_NODE_VERSION, normalizeExeOptions } from "./exe/config.js";
|
|
27
27
|
import { computeExeFileName } from "./exe/filename.js";
|
|
@@ -29,14 +29,12 @@ import { BuildJournal, IssueJournal } from "./journal/BuildJournal.js";
|
|
|
29
29
|
import { readTsconfigJsx, resolveJsxConfig } from "./jsx/config.js";
|
|
30
30
|
import { buildEmittedManifest, emitManifest, manifestNeedsCatalogResolution } from "./manifest/emit-manifest.js";
|
|
31
31
|
import { defaultManifestTransform, normalizeBinPaths, transformBin, transformExports, transformManifest } from "./manifest/transform.js";
|
|
32
|
-
import {
|
|
32
|
+
import { composeBundleManifest, githubOwnerRepo, ogImageInfoOf, registriesFromTargets } from "./meta/bundle-manifest.js";
|
|
33
|
+
import { BundleManifestSourceError, loadBundleManifestSources } from "./meta/bundle-source.js";
|
|
33
34
|
import { normalizeMetaOptions } from "./meta/config.js";
|
|
34
|
-
import { ManifestSource, decodeManifestSource } from "./meta/ManifestSource.js";
|
|
35
35
|
import { OgGenerateError, resolveOgCacheSalt, resolveOgGenerator, writeGeneratedOgImage } from "./meta/og-image.js";
|
|
36
36
|
import { rewriteMetaVersions } from "./meta/optimistic.js";
|
|
37
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
38
|
import { buildTargetGroups } from "./passes/build-target-groups.js";
|
|
41
39
|
import { cjsDefaultInterop } from "./passes/cjs-default-interop.js";
|
|
42
40
|
import { normalizeLooseFiles } from "./passes/loose-files.js";
|
|
@@ -54,5 +52,6 @@ import { createTsdownLogger } from "./report/tsdown-logger.js";
|
|
|
54
52
|
import { writeTargetsBinding } from "./targets/binding.js";
|
|
55
53
|
import { RELEASE_CHANNELS, isTargetObject } from "./targets/config.js";
|
|
56
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";
|
|
57
56
|
|
|
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,
|
|
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 };
|
package/journal/BuildJournal.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BuildIssuesSchema, PlainDiagnosticSchema } from "../report/issues-artifact.js";
|
|
2
|
-
import { Effect, FileSystem, Layer, Schema } from "effect";
|
|
3
|
-
import { dirname, join } from "node:path";
|
|
2
|
+
import { Effect, FileSystem, Layer, Path, Schema } from "effect";
|
|
4
3
|
import { Journal, JsonlEvent } from "@effected/jsonl";
|
|
5
4
|
|
|
6
5
|
// src/journal/BuildJournal.ts
|
|
@@ -8,10 +7,15 @@ import { Journal, JsonlEvent } from "@effected/jsonl";
|
|
|
8
7
|
const BUILD_JOURNAL_PATH = ".cache/effected/build.jsonl";
|
|
9
8
|
const ISSUE_JOURNAL_PATH = ".cache/effected/issues.jsonl";
|
|
10
9
|
/**
|
|
11
|
-
*
|
|
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
12
|
*/
|
|
13
|
-
const
|
|
14
|
-
|
|
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;
|
|
15
19
|
});
|
|
16
20
|
/**
|
|
17
21
|
* The per-diagnostic journal: one line per error and warning of a build, in that order, scoped by package name.
|
|
@@ -35,10 +39,7 @@ var IssueJournal = class IssueJournal extends Journal.Service()("effected/IssueJ
|
|
|
35
39
|
*
|
|
36
40
|
* @param root - The workspace root.
|
|
37
41
|
*/
|
|
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
|
+
static layerAt = (root) => Layer.effect(IssueJournal, journalPathAt(root, ISSUE_JOURNAL_PATH).pipe(Effect.flatMap((path) => IssueJournal.make({ path })), Effect.tap((journal) => journal.create)));
|
|
42
43
|
};
|
|
43
44
|
/**
|
|
44
45
|
* The per-build journal: one line per finished build, scoped by package name.
|
|
@@ -67,10 +68,7 @@ var BuildJournal = class BuildJournal extends Journal.Service()("effected/BuildJ
|
|
|
67
68
|
*
|
|
68
69
|
* @param root - The workspace root.
|
|
69
70
|
*/
|
|
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
|
-
};
|
|
71
|
+
static layerAt = (root) => Layer.effect(BuildJournal, journalPathAt(root, BUILD_JOURNAL_PATH).pipe(Effect.flatMap((path) => BuildJournal.make({ path })), Effect.tap((journal) => journal.create)));
|
|
74
72
|
/**
|
|
75
73
|
* Appends one finished build: a line per error and warning, then the build's own line.
|
|
76
74
|
*
|
|
@@ -83,6 +81,7 @@ var BuildJournal = class BuildJournal extends Journal.Service()("effected/BuildJ
|
|
|
83
81
|
* @param cwd - The package directory the artifact sits under.
|
|
84
82
|
*/
|
|
85
83
|
static record = Effect.fn("BuildJournal.record")(function* (issues, cwd) {
|
|
84
|
+
const path = yield* Path.Path;
|
|
86
85
|
const builds = yield* BuildJournal;
|
|
87
86
|
const journal = yield* IssueJournal;
|
|
88
87
|
const scope = { scope: issues.package };
|
|
@@ -100,7 +99,7 @@ var BuildJournal = class BuildJournal extends Journal.Service()("effected/BuildJ
|
|
|
100
99
|
errors: issues.errors.length,
|
|
101
100
|
warnings: issues.warnings.length,
|
|
102
101
|
suppressed: issues.suppressed.length,
|
|
103
|
-
issuesPath: join(cwd, "dist", issues.target, "issues.json")
|
|
102
|
+
issuesPath: path.join(cwd, "dist", issues.target, "issues.json")
|
|
104
103
|
}, scope);
|
|
105
104
|
});
|
|
106
105
|
};
|
package/jsx/config.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { existsSync } from "node:fs";
|
|
4
|
-
import * as nodePath from "node:path";
|
|
5
|
-
import { JsxConfig, TsconfigLoaderSync } from "@effected/tsconfig-json";
|
|
1
|
+
import { Effect, FileSystem, Option, Path } from "effect";
|
|
2
|
+
import { JsxConfig, TsconfigLoader } from "@effected/tsconfig-json";
|
|
6
3
|
|
|
7
4
|
// src/jsx/config.ts
|
|
8
5
|
/**
|
|
@@ -30,22 +27,18 @@ function resolveJsxConfig(tsconfig, override) {
|
|
|
30
27
|
}
|
|
31
28
|
/**
|
|
32
29
|
* Read the jsx-relevant compilerOptions from a package's own tsconfig.json (best-effort;
|
|
33
|
-
*
|
|
34
|
-
*
|
|
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.
|
|
35
32
|
* @public
|
|
36
33
|
*/
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
} catch {
|
|
47
|
-
return {};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
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
|
+
});
|
|
50
43
|
|
|
51
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 };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { resolveManifest } from "../catalog/resolve-catalogs.js";
|
|
2
|
+
import { stripBuiltCondition } from "./built-condition.js";
|
|
3
|
+
import { applyManifestSet, validateManifestSet } from "./manifest-set.js";
|
|
2
4
|
import { defaultManifestTransform, transformManifest } from "./transform.js";
|
|
3
5
|
import { join } from "node:path";
|
|
4
6
|
import { readFile } from "node:fs/promises";
|
|
@@ -31,7 +33,9 @@ function manifestNeedsCatalogResolution(pkg) {
|
|
|
31
33
|
* @public
|
|
32
34
|
*/
|
|
33
35
|
async function buildEmittedManifest(options) {
|
|
34
|
-
const {
|
|
36
|
+
const { cwd, targetGroup, devManifest, drop, set } = options;
|
|
37
|
+
if (set !== void 0) validateManifestSet(set, drop ?? []);
|
|
38
|
+
const pkg = stripBuiltCondition(options.pkg);
|
|
35
39
|
const shouldResolve = (targetGroup.isProd || devManifest === "resolve") && manifestNeedsCatalogResolution(pkg);
|
|
36
40
|
let base = pkg;
|
|
37
41
|
if (shouldResolve) base = await resolveManifest(pkg, cwd);
|
|
@@ -40,7 +44,7 @@ async function buildEmittedManifest(options) {
|
|
|
40
44
|
name: targetGroup.name
|
|
41
45
|
};
|
|
42
46
|
return transformManifest(base, {
|
|
43
|
-
transform: drop ? (p) => defaultManifestTransform({ pkg: p }, { drop }) : void 0,
|
|
47
|
+
transform: drop !== void 0 || set !== void 0 ? (p) => applyManifestSet(drop !== void 0 ? defaultManifestTransform({ pkg: p }, { drop }) : p, set) : void 0,
|
|
44
48
|
dual: options.dual ?? false,
|
|
45
49
|
subdirExports: options.subdirExports,
|
|
46
50
|
exeRewrite: options.exeRewrite,
|
|
@@ -63,6 +67,7 @@ function emitManifest(options) {
|
|
|
63
67
|
targetGroup: options.targetGroup,
|
|
64
68
|
devManifest: options.devManifest ?? "preserve",
|
|
65
69
|
drop: options.drop,
|
|
70
|
+
set: options.set,
|
|
66
71
|
dual: options.dual,
|
|
67
72
|
subdirExports: options.subdirExports,
|
|
68
73
|
exeRewrite: options.exeRewrite,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isAbsolute, join, sep } from "node:path";
|
|
1
|
+
import { Effect, FileSystem, Path } from "effect";
|
|
3
2
|
|
|
4
3
|
// src/manifest/export-patterns.ts
|
|
5
4
|
const stripDotSlash = (path) => path.startsWith("./") ? path.slice(2) : path;
|
|
@@ -24,13 +23,13 @@ const matchesAny = (target, files) => {
|
|
|
24
23
|
*
|
|
25
24
|
* @public
|
|
26
25
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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;
|
|
34
33
|
const ignore = new Set((options.ignore ?? []).map(stripDotSlash));
|
|
35
34
|
const exportsMap = manifest.exports;
|
|
36
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) => ({
|
|
@@ -39,20 +38,19 @@ function unmatchedExportPatterns(pkgDir, options = {}) {
|
|
|
39
38
|
target
|
|
40
39
|
})));
|
|
41
40
|
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]) => ({
|
|
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]) => ({
|
|
43
42
|
field: "bin",
|
|
44
43
|
key,
|
|
45
44
|
target
|
|
46
45
|
}));
|
|
47
46
|
const targets = [...exportTargets, ...binTargets].filter(({ target }) => !ignore.has(stripDotSlash(target)));
|
|
48
|
-
const
|
|
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
49
|
const patterns = targets.filter(({ target }) => target.includes("*"));
|
|
50
50
|
if (patterns.length === 0) return missingLiterals;
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
encoding: "utf-8"
|
|
54
|
-
}).filter((path) => statSync(join(pkgDir, path), { throwIfNoEntry: false })?.isFile() === true).map((path) => path.split(sep).join("/"));
|
|
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("/"));
|
|
55
53
|
return [...missingLiterals, ...patterns.filter(({ target }) => !matchesAny(target, files))];
|
|
56
|
-
}
|
|
54
|
+
});
|
|
57
55
|
|
|
58
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 };
|
package/manifest/transform.js
CHANGED
package/meta/api-extractor.js
CHANGED
|
@@ -2,8 +2,8 @@ import { MetaGenerationError } from "../errors.js";
|
|
|
2
2
|
import { tsconfigSyncOptions } from "../tsconfig/sync-options.js";
|
|
3
3
|
import { createMessageSuppressor } from "./message-suppressor.js";
|
|
4
4
|
import { existsSync, realpathSync, writeFileSync } from "node:fs";
|
|
5
|
-
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
6
5
|
import { tmpdir } from "node:os";
|
|
6
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
8
8
|
import { TsconfigLoaderSync } from "@effected/tsconfig-json";
|
|
9
9
|
import { Extractor, ExtractorConfig, ExtractorLogLevel } from "@microsoft/api-extractor";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// src/meta/
|
|
1
|
+
// src/meta/bundle-config.ts
|
|
2
2
|
/**
|
|
3
|
-
* The options the meta pass takes, from the decoded `[package.
|
|
3
|
+
* The options the meta pass takes, from the decoded `[package.bundle]` table. The table names a renderer, and the
|
|
4
4
|
* caller passes the generator it resolved to; a table that asks for none needs none.
|
|
5
5
|
*/
|
|
6
|
-
function
|
|
6
|
+
function bundleMetaOptionsOf(config, generate) {
|
|
7
7
|
const { name, tagline, description, registries, openGraph } = config;
|
|
8
8
|
return {
|
|
9
9
|
...name !== void 0 ? { name } : {},
|
|
@@ -19,4 +19,4 @@ function tsdoctorMetaOptionsOf(config, generate) {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export {
|
|
22
|
+
export { bundleMetaOptionsOf };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { MANIFEST_SPEC } from "
|
|
1
|
+
import { MANIFEST_SPEC } from "@effected/manifest";
|
|
2
2
|
|
|
3
|
-
// src/meta/
|
|
3
|
+
// src/meta/bundle-manifest.ts
|
|
4
4
|
const first = (...values) => values.find((v) => v !== void 0);
|
|
5
5
|
/**
|
|
6
6
|
* `owner/repo` from any of the GitHub URL spellings a `repository.url` carries (https, `git+https`,
|
|
@@ -82,7 +82,7 @@ function registriesFromTargets(input) {
|
|
|
82
82
|
*
|
|
83
83
|
* @public
|
|
84
84
|
*/
|
|
85
|
-
function
|
|
85
|
+
function composeBundleManifest(input) {
|
|
86
86
|
const { config, leaf, project } = input;
|
|
87
87
|
const images = [
|
|
88
88
|
...input.generatedImage !== void 0 ? [input.generatedImage] : [],
|
|
@@ -101,7 +101,7 @@ function composeTsdoctorManifest(input) {
|
|
|
101
101
|
const description = first(config?.description, leaf?.description);
|
|
102
102
|
const projectIdentity = projectIdentityOf(project);
|
|
103
103
|
const manifest = {
|
|
104
|
-
spec:
|
|
104
|
+
spec: MANIFEST_SPEC,
|
|
105
105
|
...name !== void 0 ? { name } : {},
|
|
106
106
|
...tagline !== void 0 ? { tagline } : {},
|
|
107
107
|
...description !== void 0 ? { description } : {},
|
|
@@ -131,4 +131,4 @@ function ogImageInfoOf(input) {
|
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
export {
|
|
134
|
+
export { composeBundleManifest, githubOwnerRepo, ogImageInfoOf, registriesFromTargets };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { decodeManifestSource } from "./ManifestSource.js";
|
|
1
|
+
import { BUNDLE_MANIFEST_FILENAME, decodeManifestSource } from "@effected/manifest";
|
|
3
2
|
import { Data, Effect, Layer } from "effect";
|
|
4
3
|
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
5
4
|
import { join, resolve } from "node:path";
|
|
@@ -7,18 +6,25 @@ import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
|
|
|
7
6
|
import * as NodePath from "@effect/platform-node/NodePath";
|
|
8
7
|
import { WorkspaceDiscovery, WorkspaceRootNotFoundError, Workspaces } from "@effected/workspaces";
|
|
9
8
|
|
|
10
|
-
// src/meta/
|
|
9
|
+
// src/meta/bundle-source.ts
|
|
11
10
|
/**
|
|
12
|
-
* A present `
|
|
11
|
+
* A present `bundle.json` source file that could not be parsed or decoded. Absence is never
|
|
13
12
|
* this error — a missing source tier is the normal case.
|
|
14
13
|
*
|
|
15
14
|
* @public
|
|
16
15
|
*/
|
|
17
|
-
var
|
|
16
|
+
var BundleManifestSourceError = class extends Data.TaggedError("BundleManifestSourceError") {
|
|
18
17
|
get message() {
|
|
19
|
-
return `Invalid ${
|
|
18
|
+
return `Invalid ${BUNDLE_MANIFEST_FILENAME} at ${this.path}`;
|
|
20
19
|
}
|
|
21
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* The sidecar's and its source files' name before it became `bundle.json`. Nothing reads or writes it: a build
|
|
23
|
+
* deletes an emitted copy and reports an authored one.
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
const RETIRED_MANIFEST_FILENAME = "tsdoctor.json";
|
|
22
28
|
/** Bound once: the platform layer is stateless and layers memoize by reference. */
|
|
23
29
|
const platform = Layer.mergeAll(NodeFileSystem.layer, NodePath.layer);
|
|
24
30
|
/** The canonical absolute form of a directory, so a relative or symlinked `cwd` compares equal to the discovered root. */
|
|
@@ -60,35 +66,41 @@ async function readSource(path) {
|
|
|
60
66
|
try {
|
|
61
67
|
parsed = JSON.parse(readFileSync(path, "utf-8"));
|
|
62
68
|
} catch (cause) {
|
|
63
|
-
throw new
|
|
69
|
+
throw new BundleManifestSourceError({
|
|
64
70
|
path,
|
|
65
71
|
cause
|
|
66
72
|
});
|
|
67
73
|
}
|
|
68
74
|
const result = await Effect.runPromise(Effect.result(decodeManifestSource(parsed, path)));
|
|
69
|
-
if (result._tag === "Failure") throw new
|
|
75
|
+
if (result._tag === "Failure") throw new BundleManifestSourceError({
|
|
70
76
|
path,
|
|
71
77
|
cause: result.failure
|
|
72
78
|
});
|
|
73
79
|
return result.success;
|
|
74
80
|
}
|
|
75
81
|
/**
|
|
76
|
-
* Read the leaf (`<cwd>/
|
|
82
|
+
* Read the leaf (`<cwd>/bundle.json`) and project (`<workspaceRoot>/bundle.json`)
|
|
77
83
|
* source tiers. Absence is normal; a present file that does not decode throws
|
|
78
|
-
* {@link
|
|
84
|
+
* {@link BundleManifestSourceError}. A package that IS the workspace root reads its file once, as the
|
|
79
85
|
* leaf, and has no project tier.
|
|
80
86
|
*
|
|
81
87
|
* @public
|
|
82
88
|
*/
|
|
83
|
-
async function
|
|
89
|
+
async function loadBundleManifestSources(cwd) {
|
|
84
90
|
const leafDir = canonical(cwd);
|
|
85
|
-
const
|
|
91
|
+
const tierDirs = [leafDir];
|
|
92
|
+
const leaf = await readSource(join(leafDir, BUNDLE_MANIFEST_FILENAME));
|
|
86
93
|
const { root, failure } = await findWorkspaceRoot(leafDir);
|
|
94
|
+
const projectDir = root !== void 0 && canonical(root) !== leafDir ? root : void 0;
|
|
95
|
+
if (projectDir !== void 0) tierDirs.push(projectDir);
|
|
96
|
+
const project = projectDir !== void 0 ? await readSource(join(projectDir, BUNDLE_MANIFEST_FILENAME)) : void 0;
|
|
97
|
+
const retiredSources = tierDirs.filter((dir) => !existsSync(join(dir, BUNDLE_MANIFEST_FILENAME))).map((dir) => join(dir, RETIRED_MANIFEST_FILENAME)).filter((path) => existsSync(path));
|
|
87
98
|
return {
|
|
88
99
|
leaf,
|
|
89
|
-
project
|
|
90
|
-
...failure !== void 0 ? { discoveryFailure: failure } : {}
|
|
100
|
+
project,
|
|
101
|
+
...failure !== void 0 ? { discoveryFailure: failure } : {},
|
|
102
|
+
...retiredSources.length > 0 ? { retiredSources } : {}
|
|
91
103
|
};
|
|
92
104
|
}
|
|
93
105
|
|
|
94
|
-
export {
|
|
106
|
+
export { BundleManifestSourceError, RETIRED_MANIFEST_FILENAME, loadBundleManifestSources };
|