@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
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { ConfigValidationError } from "../errors.js";
|
|
2
|
+
import { createEntryName } from "./extract.js";
|
|
3
|
+
|
|
4
|
+
// src/entries/ambient-dts.ts
|
|
5
|
+
const DECLARATION_EXTS = [
|
|
6
|
+
".d.ts",
|
|
7
|
+
".d.cts",
|
|
8
|
+
".d.mts"
|
|
9
|
+
];
|
|
10
|
+
/** The declaration-file extension of a path, or undefined when it is not a declaration file. @public */
|
|
11
|
+
function declarationExt(p) {
|
|
12
|
+
return DECLARATION_EXTS.find((e) => p.endsWith(e));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Classify an export value:
|
|
16
|
+
* - `ambient` — a types-only declaration source (bare `.d.ts` string, or `{ types: "*.d.ts" }` with no runtime source).
|
|
17
|
+
* - `mixed` — a declaration `types` AND a compilable runtime source (`import`/`require`/`default` → `.ts`/`.tsx`).
|
|
18
|
+
* - `none` — anything else (normal runtime export, json, etc.).
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
function classifyDtsExport(value) {
|
|
22
|
+
if (typeof value === "string") return declarationExt(value) !== void 0 ? {
|
|
23
|
+
kind: "ambient",
|
|
24
|
+
source: value
|
|
25
|
+
} : { kind: "none" };
|
|
26
|
+
if (value && typeof value === "object") {
|
|
27
|
+
const o = value;
|
|
28
|
+
const typesVal = typeof o.types === "string" ? o.types : void 0;
|
|
29
|
+
const typesIsDecl = typesVal !== void 0 && declarationExt(typesVal) !== void 0;
|
|
30
|
+
const hasRuntime = Object.entries(o).some(([k, v]) => k !== "types" && typeof v === "string" && declarationExt(v) === void 0);
|
|
31
|
+
if (typesIsDecl) return hasRuntime ? { kind: "mixed" } : {
|
|
32
|
+
kind: "ambient",
|
|
33
|
+
source: typesVal
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return { kind: "none" };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Output basename (including the preserved declaration extension) for an ambient export, derived
|
|
40
|
+
* from the export KEY — consistent with how JS entries are named. @public
|
|
41
|
+
*/
|
|
42
|
+
function ambientOutName(exportKey, source, exportsAsIndexes = false) {
|
|
43
|
+
const ext = declarationExt(source) ?? ".d.ts";
|
|
44
|
+
return `${createEntryName(exportKey, exportsAsIndexes)}${ext}`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The shared mixed-export error (Decision 2), used by both the extractor and the manifest transform. The reason ends
|
|
48
|
+
* with the bare-string form to write instead, naming the export's runtime target when `value` holds one: a
|
|
49
|
+
* hand-written `{ "types": "./dist/foo.d.ts", "import": "./dist/foo.js" }` becomes `"./foo": "./dist/foo.js"`, which
|
|
50
|
+
* the bundler builds from `./src/foo.ts` and gives generated types. @public
|
|
51
|
+
*/
|
|
52
|
+
function mixedDtsExportError(exportKey, value) {
|
|
53
|
+
const conditions = value !== null && typeof value === "object" ? value : {};
|
|
54
|
+
const example = ["import", "default"].map((condition) => conditions[condition]).find((target) => typeof target === "string") ?? "./src/<name>.ts";
|
|
55
|
+
return new ConfigValidationError({
|
|
56
|
+
path: `exports."${exportKey}"`,
|
|
57
|
+
reason: `an export with a runtime source (import/require/default) cannot also hand-author its \`types\` as a .d.ts; the bundler generates types from the source. Drop the \`types\` condition and write "${exportKey}": "${example}"`
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Extract the types-only `.d.ts` exports from a package's `exports` map. Pure.
|
|
62
|
+
* Throws {@link ConfigValidationError} on a mixed export (Decision 2) or an ambient-vs-ambient
|
|
63
|
+
* output-name collision. @public
|
|
64
|
+
*/
|
|
65
|
+
function extractAmbientDts(pkg, options = {}) {
|
|
66
|
+
const exports = pkg.exports;
|
|
67
|
+
if (!exports || typeof exports !== "object") return [];
|
|
68
|
+
const exportsAsIndexes = options.exportsAsIndexes ?? false;
|
|
69
|
+
const out = [];
|
|
70
|
+
const byName = /* @__PURE__ */ new Map();
|
|
71
|
+
for (const [key, value] of Object.entries(exports)) {
|
|
72
|
+
if (key === "./package.json" || key.endsWith(".json")) continue;
|
|
73
|
+
if (declarationExt(key) !== void 0) continue;
|
|
74
|
+
const cls = classifyDtsExport(value);
|
|
75
|
+
if (cls.kind === "none") continue;
|
|
76
|
+
if (cls.kind === "mixed") throw mixedDtsExportError(key, value);
|
|
77
|
+
const outName = ambientOutName(key, cls.source, exportsAsIndexes);
|
|
78
|
+
const prev = byName.get(outName);
|
|
79
|
+
if (prev !== void 0) throw new ConfigValidationError({
|
|
80
|
+
path: `exports."${key}"`,
|
|
81
|
+
reason: `ambient .d.ts export flattens to "${outName}", colliding with export key "${prev}". Rename one so each produces a distinct file.`
|
|
82
|
+
});
|
|
83
|
+
byName.set(outName, key);
|
|
84
|
+
out.push({
|
|
85
|
+
exportKey: key,
|
|
86
|
+
source: cls.source,
|
|
87
|
+
outName
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Throw {@link ConfigValidationError} if any ambient output name collides with a JS build-entry name.
|
|
94
|
+
* The JS entry names carry no extension, so each ambient `outName` is compared with its declaration
|
|
95
|
+
* extension stripped. @public
|
|
96
|
+
*/
|
|
97
|
+
function assertNoEntryCollisions(jsEntryNames, ambient) {
|
|
98
|
+
const js = new Set(jsEntryNames);
|
|
99
|
+
for (const a of ambient) {
|
|
100
|
+
const base = a.outName.replace(/\.d\.(ts|cts|mts)$/, "");
|
|
101
|
+
if (js.has(base)) throw new ConfigValidationError({
|
|
102
|
+
path: `exports."${a.exportKey}"`,
|
|
103
|
+
reason: `ambient .d.ts export "${a.outName}" collides with the JS build entry "${base}". Rename the export so each produces a distinct output.`
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { ambientOutName, assertNoEntryCollisions, classifyDtsExport, declarationExt, extractAmbientDts, mixedDtsExportError };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/entries/export-paths.ts
|
|
2
|
+
/**
|
|
3
|
+
* Maps each build entry to its `package.json` export key: the key whose target is the entry's source, else `.`
|
|
4
|
+
* for `index` and `./<name>` for the rest.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
function deriveExportPaths(entries, exportsMap) {
|
|
9
|
+
const out = {};
|
|
10
|
+
const sourceToKey = /* @__PURE__ */ new Map();
|
|
11
|
+
if (exportsMap) for (const [key, src] of Object.entries(exportsMap)) sourceToKey.set(src, key);
|
|
12
|
+
for (const [entryName, src] of Object.entries(entries)) out[entryName] = sourceToKey.get(src) ?? (entryName === "index" ? "." : `./${entryName}`);
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { deriveExportPaths };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// src/entries/extract.ts
|
|
2
|
+
const isDeclarationFile = (p) => p.endsWith(".d.ts") || p.endsWith(".d.cts") || p.endsWith(".d.mts");
|
|
3
|
+
const isTypeScriptFile = (p) => !isDeclarationFile(p) && (p.endsWith(".ts") || p.endsWith(".tsx"));
|
|
4
|
+
/**
|
|
5
|
+
* `/dist/*.js` to `/src/*.ts`; otherwise unchanged. The entry pass builds a `./dist/foo.js` export from
|
|
6
|
+
* `./src/foo.ts`, and the manifest transform reads the same mapping to point that export at the emitted file.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
const resolveToTypeScript = (p) => p.endsWith(".js") && p.includes("/dist/") ? p.replace("/dist/", "/src/").replace(/\.js$/, ".ts") : p;
|
|
11
|
+
/** Resolve an export value to a source path: import || default || types (NOT require). */
|
|
12
|
+
const resolveSourcePath = (value) => {
|
|
13
|
+
if (typeof value === "string") return value;
|
|
14
|
+
if (value && typeof value === "object") {
|
|
15
|
+
const o = value;
|
|
16
|
+
return o.import || o.default || o.types || void 0;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Map an export key to the tsdown entry name (the emitted output basename).
|
|
21
|
+
*
|
|
22
|
+
* `.` becomes `index`; otherwise the leading `./` is stripped and, unless
|
|
23
|
+
* `exportsAsIndexes` is set, nested slashes are flattened to dashes
|
|
24
|
+
* (e.g. `./changesets/markdownlint` to `changesets-markdownlint`). The manifest
|
|
25
|
+
* transform reuses this so the declared output path always matches the emitted file.
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
const createEntryName = (exportKey, exportsAsIndexes) => {
|
|
30
|
+
if (exportKey === ".") return "index";
|
|
31
|
+
const withoutPrefix = exportKey.replace(/^\.\//, "");
|
|
32
|
+
return exportsAsIndexes ? `${withoutPrefix}/index` : withoutPrefix.replace(/\//g, "-");
|
|
33
|
+
};
|
|
34
|
+
/** @public */
|
|
35
|
+
function extractEntries(pkg, options = {}) {
|
|
36
|
+
const entries = {};
|
|
37
|
+
const exportPaths = {};
|
|
38
|
+
const exportsAsIndexes = options.exportsAsIndexes ?? false;
|
|
39
|
+
const stripDot = (p) => p.replace(/^\.\//, "");
|
|
40
|
+
const excluded = new Set((options.excludeSources ?? []).map(stripDot));
|
|
41
|
+
const isExcluded = (src) => excluded.has(stripDot(src));
|
|
42
|
+
const exports = pkg.exports;
|
|
43
|
+
if (typeof exports === "string") {
|
|
44
|
+
if (isTypeScriptFile(exports) && !isExcluded(exports)) {
|
|
45
|
+
entries.index = exports;
|
|
46
|
+
exportPaths.index = ".";
|
|
47
|
+
}
|
|
48
|
+
} else if (exports && typeof exports === "object") for (const [key, value] of Object.entries(exports)) {
|
|
49
|
+
if (key === "./package.json" || key.endsWith(".json")) continue;
|
|
50
|
+
const sourcePath = resolveSourcePath(value);
|
|
51
|
+
if (!sourcePath) continue;
|
|
52
|
+
const resolved = resolveToTypeScript(sourcePath);
|
|
53
|
+
if (!isTypeScriptFile(resolved)) continue;
|
|
54
|
+
if (isExcluded(sourcePath) || isExcluded(resolved)) continue;
|
|
55
|
+
const name = createEntryName(key, exportsAsIndexes);
|
|
56
|
+
if (name in entries) {
|
|
57
|
+
const previousKey = exportPaths[name];
|
|
58
|
+
throw new Error(`Export key "${key}" flattens to entry name "${name}", which collides with export key "${previousKey}". Rename one of the conflicting exports so each produces a distinct entry name.`);
|
|
59
|
+
}
|
|
60
|
+
entries[name] = resolved;
|
|
61
|
+
exportPaths[name] = key;
|
|
62
|
+
}
|
|
63
|
+
const bin = pkg.bin;
|
|
64
|
+
if (typeof bin === "string") {
|
|
65
|
+
const resolved = resolveToTypeScript(bin);
|
|
66
|
+
if (isTypeScriptFile(resolved) && !isExcluded(bin) && !isExcluded(resolved)) entries["bin/cli"] = resolved;
|
|
67
|
+
} else if (bin && typeof bin === "object") for (const [command, p] of Object.entries(bin)) {
|
|
68
|
+
if (typeof p !== "string") continue;
|
|
69
|
+
const resolved = resolveToTypeScript(p);
|
|
70
|
+
if (isExcluded(p) || isExcluded(resolved)) continue;
|
|
71
|
+
if (isTypeScriptFile(resolved)) entries[`bin/${command}`] = resolved;
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
entries,
|
|
75
|
+
exportPaths
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { createEntryName, extractEntries, resolveToTypeScript };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { extractEntries } from "./extract.js";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
|
|
5
|
+
// src/entries/package-json-entries.ts
|
|
6
|
+
/**
|
|
7
|
+
* Derive a tsdown `entry` record (name to source path) from a package.json.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
function packageJsonEntries(options = {}) {
|
|
12
|
+
const pkg = options.pkg ?? JSON.parse(readFileSync(resolve(options.cwd ?? process.cwd(), "package.json"), "utf-8"));
|
|
13
|
+
return extractEntries(pkg, {
|
|
14
|
+
exportsAsIndexes: options.exportsAsIndexes,
|
|
15
|
+
excludeSources: options.excludeSources
|
|
16
|
+
}).entries;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { packageJsonEntries };
|
package/errors.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Data } from "effect";
|
|
2
|
+
|
|
3
|
+
// src/errors.ts
|
|
4
|
+
/**
|
|
5
|
+
* A build config is structurally invalid; raised before any build work.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
var ConfigValidationError = class extends Data.TaggedError("ConfigValidationError") {
|
|
10
|
+
get message() {
|
|
11
|
+
return `Config validation failed at "${this.path}": ${this.reason}`;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* API Extractor meta generation failed for an entry.
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
var MetaGenerationError = class extends Data.TaggedError("MetaGenerationError") {
|
|
20
|
+
get message() {
|
|
21
|
+
return `Meta generation failed for entry "${this.entry}": ${this.reason}`;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Writing the `bundle.json` sidecar failed: the composed manifest did not encode, or the file could not be
|
|
26
|
+
* written (a read-only or full disk). Recorded in `issues.json` as a `meta` error.
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
var BundleManifestEmitError = class extends Data.TaggedError("BundleManifestEmitError") {
|
|
31
|
+
get message() {
|
|
32
|
+
const reason = this.cause instanceof Error ? this.cause.message : String(this.cause);
|
|
33
|
+
return `Could not emit ${this.path} for ${this.packageName}: ${reason}`;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { BundleManifestEmitError, ConfigValidationError, MetaGenerationError };
|
package/exe/build.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { buildMetricsPlugin } from "../report/metrics-plugin.js";
|
|
2
|
+
import { createTimer } from "../report/timer.js";
|
|
3
|
+
import { createTsdownLogger } from "../report/tsdown-logger.js";
|
|
4
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
|
|
8
|
+
// src/exe/build.ts
|
|
9
|
+
/**
|
|
10
|
+
* Compile each SEA binary via tsdown's exe mode. One tsdown build per spec.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
async function runExeBuild(options) {
|
|
15
|
+
const build = options.build ?? (await import("tsdown")).build;
|
|
16
|
+
for (const spec of options.specs) {
|
|
17
|
+
const scratch = mkdtempSync(join(tmpdir(), "effected-exe-"));
|
|
18
|
+
const collector = options.collector;
|
|
19
|
+
const groupId = options.groupId;
|
|
20
|
+
const instrument = collector !== void 0 && groupId !== void 0 ? {
|
|
21
|
+
logLevel: "silent",
|
|
22
|
+
customLogger: createTsdownLogger(collector, groupId)
|
|
23
|
+
} : {};
|
|
24
|
+
const plugins = collector !== void 0 && groupId !== void 0 ? [buildMetricsPlugin(collector, groupId, "exe", options.verbose ?? false)] : [];
|
|
25
|
+
const timer = createTimer();
|
|
26
|
+
try {
|
|
27
|
+
await build({
|
|
28
|
+
cwd: options.cwd,
|
|
29
|
+
config: false,
|
|
30
|
+
entry: [spec.entry],
|
|
31
|
+
format: "esm",
|
|
32
|
+
platform: "node",
|
|
33
|
+
clean: false,
|
|
34
|
+
outDir: scratch,
|
|
35
|
+
deps: { alwaysBundle: (id) => !id.startsWith("node:") },
|
|
36
|
+
exe: {
|
|
37
|
+
fileName: spec.fileName,
|
|
38
|
+
outDir: options.outDir,
|
|
39
|
+
seaConfig: spec.seaConfig,
|
|
40
|
+
targets: spec.targets
|
|
41
|
+
},
|
|
42
|
+
...instrument,
|
|
43
|
+
...plugins.length > 0 ? { plugins } : {}
|
|
44
|
+
});
|
|
45
|
+
} finally {
|
|
46
|
+
if (collector !== void 0 && groupId !== void 0) collector.recordPassTiming(groupId, "exe", timer.elapsed());
|
|
47
|
+
rmSync(scratch, {
|
|
48
|
+
recursive: true,
|
|
49
|
+
force: true
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { runExeBuild };
|
package/exe/config.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// src/exe/config.ts
|
|
2
|
+
/**
|
|
3
|
+
* Default Node runtime embedded in the SEA (parity with the vitest-agent reference).
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
const DEFAULT_EXE_NODE_VERSION = "25.9.0";
|
|
8
|
+
/** Map a package.json os value to the tsdown exe platform token. */
|
|
9
|
+
function platformToken(os) {
|
|
10
|
+
if (os === "darwin") return "darwin";
|
|
11
|
+
if (os === "linux") return "linux";
|
|
12
|
+
if (os === "win32") return "win";
|
|
13
|
+
}
|
|
14
|
+
/** Infer the default targets from the package's os/cpu (the zero-config, one-platform-per-package case). */
|
|
15
|
+
function inferTargets(pkg) {
|
|
16
|
+
const os = pkg.os[0];
|
|
17
|
+
const cpu = pkg.cpu[0];
|
|
18
|
+
if (os === void 0 || cpu === void 0) return [];
|
|
19
|
+
const platform = platformToken(os);
|
|
20
|
+
if (platform === void 0 || cpu !== "arm64" && cpu !== "x64") return [];
|
|
21
|
+
return [{
|
|
22
|
+
platform,
|
|
23
|
+
arch: cpu
|
|
24
|
+
}];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Normalize `exe` (object or array) into one fully-resolved spec per binary.
|
|
28
|
+
*
|
|
29
|
+
* Pure function; structural validation (missing fileName, empty targets) lives in the
|
|
30
|
+
* config-validation layer.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
function normalizeExeOptions(exe, pkg) {
|
|
34
|
+
return (Array.isArray(exe) ? exe : [exe]).map((c) => {
|
|
35
|
+
const nodeVersion = c.nodeVersion ?? "25.9.0";
|
|
36
|
+
const targetInputs = c.targets ?? inferTargets(pkg);
|
|
37
|
+
return {
|
|
38
|
+
fileName: c.fileName,
|
|
39
|
+
entry: c.entry ?? "./src/bin.ts",
|
|
40
|
+
targets: targetInputs.map((t) => ({
|
|
41
|
+
platform: t.platform,
|
|
42
|
+
arch: t.arch,
|
|
43
|
+
nodeVersion
|
|
44
|
+
})),
|
|
45
|
+
seaConfig: {
|
|
46
|
+
disableExperimentalSEAWarning: c.seaConfig?.disableExperimentalSEAWarning ?? true,
|
|
47
|
+
useCodeCache: c.seaConfig?.useCodeCache ?? false,
|
|
48
|
+
useSnapshot: c.seaConfig?.useSnapshot ?? false
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { DEFAULT_EXE_NODE_VERSION, normalizeExeOptions };
|
package/exe/filename.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/exe/filename.ts
|
|
2
|
+
/**
|
|
3
|
+
* The exact filename `@tsdown/exe` emits for a SEA target, mirroring tsdown's
|
|
4
|
+
* `resolveOutputFileName`: base fileName + `-<platform>-<arch>` + `.exe` on win.
|
|
5
|
+
* Single source of truth so the manifest value never drifts from the on-disk file.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
function computeExeFileName(fileName, target) {
|
|
10
|
+
return `${fileName}${`-${target.platform}-${target.arch}`}${target.platform === "win" ? ".exe" : ""}`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { computeExeFileName };
|