@torba/dev 1.0.10

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/dist/index.cjs ADDED
@@ -0,0 +1,81 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let _torba_core = require("@torba/core");
3
+
4
+ //#region lib/plugin.ts
5
+ /** Identity helper for authoring a plugin with inferred types. */
6
+ function definePlugin(plugin) {
7
+ return plugin;
8
+ }
9
+
10
+ //#endregion
11
+ //#region lib/config.ts
12
+ /** Use as the default export of `torba.config.mjs`. */
13
+ function defineConfig(input) {
14
+ return input;
15
+ }
16
+ /** Resolve a config input to a concrete `TorbaConfig`. */
17
+ async function resolveConfig(input, ctx) {
18
+ return typeof input === "function" ? input(ctx) : input;
19
+ }
20
+
21
+ //#endregion
22
+ //#region lib/engine.ts
23
+ /** Flatten author-ordered launch groups into a single `Valset`. */
24
+ function flattenArgs(items) {
25
+ const out = [];
26
+ for (const item of items) if (typeof item === "string") out.push({
27
+ rules: [],
28
+ value: [item]
29
+ });
30
+ else if (Array.isArray(item)) out.push(...item);
31
+ else out.push(item);
32
+ return out;
33
+ }
34
+ /**
35
+ * Run every plugin's `build` hook in parallel, merge the contributions, and
36
+ * assemble the final `Manifest`.
37
+ */
38
+ async function buildManifest(config, ctx) {
39
+ ctx.log("torba", `resolving ${config.plugins.length} plugin(s)`);
40
+ const results = await Promise.all(config.plugins.map(async (p) => ({
41
+ name: p.name,
42
+ contribution: await p.build(ctx)
43
+ })));
44
+ const artifacts = [];
45
+ for (const r of results) if (r.contribution.artifacts) artifacts.push(...r.contribution.artifacts);
46
+ if (config.manifest.artifacts) artifacts.push(...config.manifest.artifacts);
47
+ const deduped = (0, _torba_core.deduplicateArtifacts)(artifacts);
48
+ const vars = {};
49
+ const owner = {};
50
+ for (const r of results) {
51
+ if (!r.contribution.vars) continue;
52
+ for (const [key, value] of Object.entries(r.contribution.vars)) {
53
+ const prev = owner[key];
54
+ if (prev !== void 0 && prev !== r.name) ctx.log("torba", `warning: var '${key}' set by both '${prev}' and '${r.name}' — using '${r.name}'`);
55
+ vars[key] = value;
56
+ owner[key] = r.name;
57
+ }
58
+ }
59
+ if (config.manifest.vars) for (const [key, value] of Object.entries(config.manifest.vars)) vars[key] = value;
60
+ const pluginMap = Object.fromEntries(results.map((r) => [r.name, r.contribution.launch ?? {}]));
61
+ const m = config.manifest;
62
+ const launch = {
63
+ command: m.command(pluginMap),
64
+ workdir: typeof m.workdir === "function" ? m.workdir(pluginMap) : m.workdir ?? ".",
65
+ args: flattenArgs(m.args(pluginMap)),
66
+ envs: typeof m.envs === "function" ? m.envs(pluginMap) : m.envs ?? {}
67
+ };
68
+ ctx.log("torba", `merged ${deduped.length} artifact(s) (${artifacts.length - deduped.length} deduped)`);
69
+ return {
70
+ vars,
71
+ launch,
72
+ artifacts: deduped,
73
+ ...m.restrict && m.restrict.length > 0 ? { restrict: m.restrict } : {}
74
+ };
75
+ }
76
+
77
+ //#endregion
78
+ exports.buildManifest = buildManifest;
79
+ exports.defineConfig = defineConfig;
80
+ exports.definePlugin = definePlugin;
81
+ exports.resolveConfig = resolveConfig;
@@ -0,0 +1,91 @@
1
+ import { Artifact, Manifest, Val, ValDefs, Valset } from "@torba/core";
2
+
3
+ //#region lib/plugin.d.ts
4
+ /** Build-time context handed to every plugin's `build` hook. */
5
+ interface BuildContext {
6
+ /** Sanctioned build-time logging channel; auto-prefixed by plugin name. */
7
+ log: (scope: string, message: string) => void;
8
+ /** Absolute directory of `torba.config.mjs` — anchor for relative paths. */
9
+ configDir: string;
10
+ /** Value of `torba build --mode <m>`; empty string when unset. */
11
+ mode: string;
12
+ }
13
+ /**
14
+ * Named launch fragments a plugin exposes for the config's `command`/`args`
15
+ * accessor functions — e.g. `{ jvmArgs, mainClass, gameArgs }` or `{ bin }`.
16
+ */
17
+ type LaunchGroups = Record<string, Valset | Val | string>;
18
+ /** What a plugin's `build` hook returns. */
19
+ interface Contribution {
20
+ /** Artifacts to download/copy/extract. */
21
+ artifacts?: Artifact[];
22
+ /** Manifest vars this plugin owns. */
23
+ vars?: ValDefs;
24
+ /** Named launch fragments, exposed to the config's accessor functions. */
25
+ launch?: LaunchGroups;
26
+ }
27
+ /**
28
+ * A torba plugin — a pure-to-construct, bundler-style hook object. The
29
+ * constructor (`forge('1.20.1-best')`, …) does zero I/O; all network/fs work
30
+ * happens inside `build`, which the engine drives.
31
+ */
32
+ interface TorbaPlugin {
33
+ name: string;
34
+ build(ctx: BuildContext): Promise<Contribution> | Contribution;
35
+ }
36
+ /** Identity helper for authoring a plugin with inferred types. */
37
+ declare function definePlugin(plugin: TorbaPlugin): TorbaPlugin;
38
+ //#endregion
39
+ //#region lib/config.d.ts
40
+ /** Map of plugin name → its launch groups, passed to launch accessors. */
41
+ type PluginMap = Record<string, LaunchGroups>;
42
+ /** One entry of a config's assembled `args` — flattened to a `Valset`. */
43
+ type ArgItem = Valset | Val | string;
44
+ interface TorbaManifestConfig {
45
+ /** Hand-written literal artifacts, merged with plugin output (last wins). */
46
+ artifacts?: Artifact[];
47
+ /** Override/extra vars layered on top of the merged plugin vars. */
48
+ vars?: ValDefs;
49
+ /** Launch command — typically `({ java }) => java.bin`. */
50
+ command: (plugins: PluginMap) => string;
51
+ /** Launch args — author-ordered named groups, flattened to a `Valset`. */
52
+ args: (plugins: PluginMap) => ArgItem[];
53
+ /** Working directory for the launched process. */
54
+ workdir?: string | ((plugins: PluginMap) => string);
55
+ /** Environment variables for the launched process. */
56
+ envs?: ValDefs | ((plugins: PluginMap) => ValDefs);
57
+ /** `restrict` globs swept clean after install. */
58
+ restrict?: string[];
59
+ }
60
+ interface TorbaConfig {
61
+ /** Default manifest output path, relative to the config file. */
62
+ output?: string;
63
+ /** The plugins whose `build` hooks produce the manifest. */
64
+ plugins: TorbaPlugin[];
65
+ /** Declarative manifest fields, separate from tooling config. */
66
+ manifest: TorbaManifestConfig;
67
+ /**
68
+ * Launch-time manifest patch. Re-run on every `torba launch`; the returned
69
+ * partial is shallow-merged (per field) over the loaded manifest.
70
+ */
71
+ runClient?: (manifest: Manifest) => Partial<Manifest>;
72
+ }
73
+ interface TorbaConfigContext {
74
+ /** Value of `torba build --mode <m>`; empty string when unset. */
75
+ mode: string;
76
+ }
77
+ type TorbaConfigInput = TorbaConfig | ((ctx: TorbaConfigContext) => TorbaConfig | Promise<TorbaConfig>);
78
+ /** Use as the default export of `torba.config.mjs`. */
79
+ declare function defineConfig(input: TorbaConfigInput): TorbaConfigInput;
80
+ /** Resolve a config input to a concrete `TorbaConfig`. */
81
+ declare function resolveConfig(input: TorbaConfigInput, ctx: TorbaConfigContext): Promise<TorbaConfig>;
82
+ //#endregion
83
+ //#region lib/engine.d.ts
84
+ /**
85
+ * Run every plugin's `build` hook in parallel, merge the contributions, and
86
+ * assemble the final `Manifest`.
87
+ */
88
+ declare function buildManifest(config: TorbaConfig, ctx: BuildContext): Promise<Manifest>;
89
+ //#endregion
90
+ export { ArgItem, BuildContext, Contribution, LaunchGroups, PluginMap, TorbaConfig, TorbaConfigContext, TorbaConfigInput, TorbaManifestConfig, TorbaPlugin, buildManifest, defineConfig, definePlugin, resolveConfig };
91
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../lib/plugin.ts","../lib/config.ts","../lib/engine.ts"],"mappings":";;;;UAGiB,YAAA;EAAA;EAEf,GAAA,GAAM,KAAA,UAAe,OAAA;;EAErB,SAAA;EAFA;EAIA,IAAA;AAAA;;;;;KAOU,YAAA,GAAe,MAAA,SAAe,MAAA,GAAS,GAAA;;UAGlC,YAAA;EAHyB;EAKxC,SAAA,GAAY,QAAA;EALa;EAOzB,IAAA,GAAO,OAAA;EAPwB;EAS/B,MAAA,GAAS,YAAA;AAAA;;;;AANX;;UAciB,WAAA;EACf,IAAA;EACA,KAAA,CAAM,GAAA,EAAK,YAAA,GAAe,OAAA,CAAQ,YAAA,IAAgB,YAAA;AAAA;;iBAIpC,YAAA,CAAa,MAAA,EAAQ,WAAA,GAAc,WAAA;;;;KCnCvC,SAAA,GAAY,MAAA,SAAe,YAAA;;KAG3B,OAAA,GAAU,MAAA,GAAS,GAAA;AAAA,UAEd,mBAAA;EDJf;ECMA,SAAA,GAAY,QAAA;EDNS;ECQrB,IAAA,GAAO,OAAA;EDJP;ECMA,OAAA,GAAU,OAAA,EAAS,SAAA;EDNf;ECQJ,IAAA,GAAO,OAAA,EAAS,SAAA,KAAc,OAAA;EDDR;ECGtB,OAAA,cAAqB,OAAA,EAAS,SAAA;EDHU;ECKxC,IAAA,GAAO,OAAA,KAAY,OAAA,EAAS,SAAA,KAAc,OAAA;EDLjB;ECOzB,QAAA;AAAA;AAAA,UAGe,WAAA;EDVyB;ECYxC,MAAA;EDZoD;ECcpD,OAAA,EAAS,WAAA;EDXM;ECaf,QAAA,EAAU,mBAAA;;;;;EAKV,SAAA,IAAa,QAAA,EAAU,QAAA,KAAa,OAAA,CAAQ,QAAA;AAAA;AAAA,UAG7B,kBAAA;EDnBH;ECqBZ,IAAA;AAAA;AAAA,KAGU,gBAAA,GACR,WAAA,KACE,GAAA,EAAK,kBAAA,KAAuB,WAAA,GAAc,OAAA,CAAQ,WAAA;;iBAGxC,YAAA,CAAa,KAAA,EAAO,gBAAA,GAAmB,gBAAA;;iBAKjC,aAAA,CACpB,KAAA,EAAO,gBAAA,EACP,GAAA,EAAK,kBAAA,GACJ,OAAA,CAAQ,WAAA;;;ADvDX;;;;AAAA,iBEwBsB,aAAA,CACpB,MAAA,EAAQ,WAAA,EACR,GAAA,EAAK,YAAA,GACJ,OAAA,CAAQ,QAAA"}
@@ -0,0 +1,91 @@
1
+ import { Artifact, Manifest, Val, ValDefs, Valset } from "@torba/core";
2
+
3
+ //#region lib/plugin.d.ts
4
+ /** Build-time context handed to every plugin's `build` hook. */
5
+ interface BuildContext {
6
+ /** Sanctioned build-time logging channel; auto-prefixed by plugin name. */
7
+ log: (scope: string, message: string) => void;
8
+ /** Absolute directory of `torba.config.mjs` — anchor for relative paths. */
9
+ configDir: string;
10
+ /** Value of `torba build --mode <m>`; empty string when unset. */
11
+ mode: string;
12
+ }
13
+ /**
14
+ * Named launch fragments a plugin exposes for the config's `command`/`args`
15
+ * accessor functions — e.g. `{ jvmArgs, mainClass, gameArgs }` or `{ bin }`.
16
+ */
17
+ type LaunchGroups = Record<string, Valset | Val | string>;
18
+ /** What a plugin's `build` hook returns. */
19
+ interface Contribution {
20
+ /** Artifacts to download/copy/extract. */
21
+ artifacts?: Artifact[];
22
+ /** Manifest vars this plugin owns. */
23
+ vars?: ValDefs;
24
+ /** Named launch fragments, exposed to the config's accessor functions. */
25
+ launch?: LaunchGroups;
26
+ }
27
+ /**
28
+ * A torba plugin — a pure-to-construct, bundler-style hook object. The
29
+ * constructor (`forge('1.20.1-best')`, …) does zero I/O; all network/fs work
30
+ * happens inside `build`, which the engine drives.
31
+ */
32
+ interface TorbaPlugin {
33
+ name: string;
34
+ build(ctx: BuildContext): Promise<Contribution> | Contribution;
35
+ }
36
+ /** Identity helper for authoring a plugin with inferred types. */
37
+ declare function definePlugin(plugin: TorbaPlugin): TorbaPlugin;
38
+ //#endregion
39
+ //#region lib/config.d.ts
40
+ /** Map of plugin name → its launch groups, passed to launch accessors. */
41
+ type PluginMap = Record<string, LaunchGroups>;
42
+ /** One entry of a config's assembled `args` — flattened to a `Valset`. */
43
+ type ArgItem = Valset | Val | string;
44
+ interface TorbaManifestConfig {
45
+ /** Hand-written literal artifacts, merged with plugin output (last wins). */
46
+ artifacts?: Artifact[];
47
+ /** Override/extra vars layered on top of the merged plugin vars. */
48
+ vars?: ValDefs;
49
+ /** Launch command — typically `({ java }) => java.bin`. */
50
+ command: (plugins: PluginMap) => string;
51
+ /** Launch args — author-ordered named groups, flattened to a `Valset`. */
52
+ args: (plugins: PluginMap) => ArgItem[];
53
+ /** Working directory for the launched process. */
54
+ workdir?: string | ((plugins: PluginMap) => string);
55
+ /** Environment variables for the launched process. */
56
+ envs?: ValDefs | ((plugins: PluginMap) => ValDefs);
57
+ /** `restrict` globs swept clean after install. */
58
+ restrict?: string[];
59
+ }
60
+ interface TorbaConfig {
61
+ /** Default manifest output path, relative to the config file. */
62
+ output?: string;
63
+ /** The plugins whose `build` hooks produce the manifest. */
64
+ plugins: TorbaPlugin[];
65
+ /** Declarative manifest fields, separate from tooling config. */
66
+ manifest: TorbaManifestConfig;
67
+ /**
68
+ * Launch-time manifest patch. Re-run on every `torba launch`; the returned
69
+ * partial is shallow-merged (per field) over the loaded manifest.
70
+ */
71
+ runClient?: (manifest: Manifest) => Partial<Manifest>;
72
+ }
73
+ interface TorbaConfigContext {
74
+ /** Value of `torba build --mode <m>`; empty string when unset. */
75
+ mode: string;
76
+ }
77
+ type TorbaConfigInput = TorbaConfig | ((ctx: TorbaConfigContext) => TorbaConfig | Promise<TorbaConfig>);
78
+ /** Use as the default export of `torba.config.mjs`. */
79
+ declare function defineConfig(input: TorbaConfigInput): TorbaConfigInput;
80
+ /** Resolve a config input to a concrete `TorbaConfig`. */
81
+ declare function resolveConfig(input: TorbaConfigInput, ctx: TorbaConfigContext): Promise<TorbaConfig>;
82
+ //#endregion
83
+ //#region lib/engine.d.ts
84
+ /**
85
+ * Run every plugin's `build` hook in parallel, merge the contributions, and
86
+ * assemble the final `Manifest`.
87
+ */
88
+ declare function buildManifest(config: TorbaConfig, ctx: BuildContext): Promise<Manifest>;
89
+ //#endregion
90
+ export { ArgItem, BuildContext, Contribution, LaunchGroups, PluginMap, TorbaConfig, TorbaConfigContext, TorbaConfigInput, TorbaManifestConfig, TorbaPlugin, buildManifest, defineConfig, definePlugin, resolveConfig };
91
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../lib/plugin.ts","../lib/config.ts","../lib/engine.ts"],"mappings":";;;;UAGiB,YAAA;EAAA;EAEf,GAAA,GAAM,KAAA,UAAe,OAAA;;EAErB,SAAA;EAFA;EAIA,IA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AA,CACpB,MAAA,EAAQ,WAAA,EACR,GAAA,EAAK,YAAA,GACJ,OAAA,CAAQ,QAAA"}
package/dist/index.mjs ADDED
@@ -0,0 +1,78 @@
1
+ import { deduplicateArtifacts } from "@torba/core";
2
+
3
+ //#region lib/plugin.ts
4
+ /** Identity helper for authoring a plugin with inferred types. */
5
+ function definePlugin(plugin) {
6
+ return plugin;
7
+ }
8
+
9
+ //#endregion
10
+ //#region lib/config.ts
11
+ /** Use as the default export of `torba.config.mjs`. */
12
+ function defineConfig(input) {
13
+ return input;
14
+ }
15
+ /** Resolve a config input to a concrete `TorbaConfig`. */
16
+ async function resolveConfig(input, ctx) {
17
+ return typeof input === "function" ? input(ctx) : input;
18
+ }
19
+
20
+ //#endregion
21
+ //#region lib/engine.ts
22
+ /** Flatten author-ordered launch groups into a single `Valset`. */
23
+ function flattenArgs(items) {
24
+ const out = [];
25
+ for (const item of items) if (typeof item === "string") out.push({
26
+ rules: [],
27
+ value: [item]
28
+ });
29
+ else if (Array.isArray(item)) out.push(...item);
30
+ else out.push(item);
31
+ return out;
32
+ }
33
+ /**
34
+ * Run every plugin's `build` hook in parallel, merge the contributions, and
35
+ * assemble the final `Manifest`.
36
+ */
37
+ async function buildManifest(config, ctx) {
38
+ ctx.log("torba", `resolving ${config.plugins.length} plugin(s)`);
39
+ const results = await Promise.all(config.plugins.map(async (p) => ({
40
+ name: p.name,
41
+ contribution: await p.build(ctx)
42
+ })));
43
+ const artifacts = [];
44
+ for (const r of results) if (r.contribution.artifacts) artifacts.push(...r.contribution.artifacts);
45
+ if (config.manifest.artifacts) artifacts.push(...config.manifest.artifacts);
46
+ const deduped = deduplicateArtifacts(artifacts);
47
+ const vars = {};
48
+ const owner = {};
49
+ for (const r of results) {
50
+ if (!r.contribution.vars) continue;
51
+ for (const [key, value] of Object.entries(r.contribution.vars)) {
52
+ const prev = owner[key];
53
+ if (prev !== void 0 && prev !== r.name) ctx.log("torba", `warning: var '${key}' set by both '${prev}' and '${r.name}' — using '${r.name}'`);
54
+ vars[key] = value;
55
+ owner[key] = r.name;
56
+ }
57
+ }
58
+ if (config.manifest.vars) for (const [key, value] of Object.entries(config.manifest.vars)) vars[key] = value;
59
+ const pluginMap = Object.fromEntries(results.map((r) => [r.name, r.contribution.launch ?? {}]));
60
+ const m = config.manifest;
61
+ const launch = {
62
+ command: m.command(pluginMap),
63
+ workdir: typeof m.workdir === "function" ? m.workdir(pluginMap) : m.workdir ?? ".",
64
+ args: flattenArgs(m.args(pluginMap)),
65
+ envs: typeof m.envs === "function" ? m.envs(pluginMap) : m.envs ?? {}
66
+ };
67
+ ctx.log("torba", `merged ${deduped.length} artifact(s) (${artifacts.length - deduped.length} deduped)`);
68
+ return {
69
+ vars,
70
+ launch,
71
+ artifacts: deduped,
72
+ ...m.restrict && m.restrict.length > 0 ? { restrict: m.restrict } : {}
73
+ };
74
+ }
75
+
76
+ //#endregion
77
+ export { buildManifest, defineConfig, definePlugin, resolveConfig };
78
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../lib/plugin.ts","../lib/config.ts","../lib/engine.ts"],"sourcesContent":["import type { Artifact, ValDefs, Val, Valset } from '@torba/core';\n\n/** Build-time context handed to every plugin's `build` hook. */\nexport interface BuildContext {\n /** Sanctioned build-time logging channel; auto-prefixed by plugin name. */\n log: (scope: string, message: string) => void;\n /** Absolute directory of `torba.config.mjs` — anchor for relative paths. */\n configDir: string;\n /** Value of `torba build --mode <m>`; empty string when unset. */\n mode: string;\n}\n\n/**\n * Named launch fragments a plugin exposes for the config's `command`/`args`\n * accessor functions — e.g. `{ jvmArgs, mainClass, gameArgs }` or `{ bin }`.\n */\nexport type LaunchGroups = Record<string, Valset | Val | string>;\n\n/** What a plugin's `build` hook returns. */\nexport interface Contribution {\n /** Artifacts to download/copy/extract. */\n artifacts?: Artifact[];\n /** Manifest vars this plugin owns. */\n vars?: ValDefs;\n /** Named launch fragments, exposed to the config's accessor functions. */\n launch?: LaunchGroups;\n}\n\n/**\n * A torba plugin — a pure-to-construct, bundler-style hook object. The\n * constructor (`forge('1.20.1-best')`, …) does zero I/O; all network/fs work\n * happens inside `build`, which the engine drives.\n */\nexport interface TorbaPlugin {\n name: string;\n build(ctx: BuildContext): Promise<Contribution> | Contribution;\n}\n\n/** Identity helper for authoring a plugin with inferred types. */\nexport function definePlugin(plugin: TorbaPlugin): TorbaPlugin {\n return plugin;\n}\n","import type { Artifact, ValDefs, Manifest, Val, Valset } from '@torba/core';\nimport type { TorbaPlugin, LaunchGroups } from './plugin';\n\n/** Map of plugin name → its launch groups, passed to launch accessors. */\nexport type PluginMap = Record<string, LaunchGroups>;\n\n/** One entry of a config's assembled `args` — flattened to a `Valset`. */\nexport type ArgItem = Valset | Val | string;\n\nexport interface TorbaManifestConfig {\n /** Hand-written literal artifacts, merged with plugin output (last wins). */\n artifacts?: Artifact[];\n /** Override/extra vars layered on top of the merged plugin vars. */\n vars?: ValDefs;\n /** Launch command — typically `({ java }) => java.bin`. */\n command: (plugins: PluginMap) => string;\n /** Launch args — author-ordered named groups, flattened to a `Valset`. */\n args: (plugins: PluginMap) => ArgItem[];\n /** Working directory for the launched process. */\n workdir?: string | ((plugins: PluginMap) => string);\n /** Environment variables for the launched process. */\n envs?: ValDefs | ((plugins: PluginMap) => ValDefs);\n /** `restrict` globs swept clean after install. */\n restrict?: string[];\n}\n\nexport interface TorbaConfig {\n /** Default manifest output path, relative to the config file. */\n output?: string;\n /** The plugins whose `build` hooks produce the manifest. */\n plugins: TorbaPlugin[];\n /** Declarative manifest fields, separate from tooling config. */\n manifest: TorbaManifestConfig;\n /**\n * Launch-time manifest patch. Re-run on every `torba launch`; the returned\n * partial is shallow-merged (per field) over the loaded manifest.\n */\n runClient?: (manifest: Manifest) => Partial<Manifest>;\n}\n\nexport interface TorbaConfigContext {\n /** Value of `torba build --mode <m>`; empty string when unset. */\n mode: string;\n}\n\nexport type TorbaConfigInput =\n | TorbaConfig\n | ((ctx: TorbaConfigContext) => TorbaConfig | Promise<TorbaConfig>);\n\n/** Use as the default export of `torba.config.mjs`. */\nexport function defineConfig(input: TorbaConfigInput): TorbaConfigInput {\n return input;\n}\n\n/** Resolve a config input to a concrete `TorbaConfig`. */\nexport async function resolveConfig(\n input: TorbaConfigInput,\n ctx: TorbaConfigContext,\n): Promise<TorbaConfig> {\n return typeof input === 'function' ? input(ctx) : input;\n}\n","import {\n type Manifest,\n type Artifact,\n type Launch,\n type ValDefs,\n type Val,\n type Valset,\n deduplicateArtifacts,\n} from '@torba/core';\nimport type { TorbaConfig, ArgItem, PluginMap } from './config';\nimport type { BuildContext } from './plugin';\n\n/** Flatten author-ordered launch groups into a single `Valset`. */\nfunction flattenArgs(items: ReadonlyArray<ArgItem>): Valset {\n const out: Val[] = [];\n for (const item of items) {\n if (typeof item === 'string') out.push({ rules: [], value: [item] });\n else if (Array.isArray(item)) out.push(...item);\n else out.push(item);\n }\n return out;\n}\n\n/**\n * Run every plugin's `build` hook in parallel, merge the contributions, and\n * assemble the final `Manifest`.\n */\nexport async function buildManifest(\n config: TorbaConfig,\n ctx: BuildContext,\n): Promise<Manifest> {\n ctx.log('torba', `resolving ${config.plugins.length} plugin(s)`);\n const results = await Promise.all(\n config.plugins.map(async (p) => ({\n name: p.name,\n contribution: await p.build(ctx),\n })),\n );\n\n // Artifacts: plugin output in list order, then literal manifest.artifacts.\n const artifacts: Artifact[] = [];\n for (const r of results) {\n if (r.contribution.artifacts) artifacts.push(...r.contribution.artifacts);\n }\n if (config.manifest.artifacts) artifacts.push(...config.manifest.artifacts);\n const deduped = deduplicateArtifacts(artifacts);\n\n // Vars: merge plugin vars (list order, last wins); warn on collisions.\n const vars: Record<string, ValDefs[string]> = {};\n const owner: Record<string, string> = {};\n for (const r of results) {\n if (!r.contribution.vars) continue;\n for (const [key, value] of Object.entries(r.contribution.vars)) {\n const prev = owner[key];\n if (prev !== undefined && prev !== r.name) {\n ctx.log(\n 'torba',\n `warning: var '${key}' set by both '${prev}' and '${r.name}' — using '${r.name}'`,\n );\n }\n vars[key] = value;\n owner[key] = r.name;\n }\n }\n // Config `vars` is the sanctioned override layer (silent).\n if (config.manifest.vars) {\n for (const [key, value] of Object.entries(config.manifest.vars)) {\n vars[key] = value;\n }\n }\n\n // Launch: author functions over the plugin → launch-groups map.\n const pluginMap: PluginMap = Object.fromEntries(\n results.map((r) => [r.name, r.contribution.launch ?? {}]),\n );\n const m = config.manifest;\n const launch: Launch = {\n command: m.command(pluginMap),\n workdir:\n typeof m.workdir === 'function'\n ? m.workdir(pluginMap)\n : (m.workdir ?? '.'),\n args: flattenArgs(m.args(pluginMap)),\n envs: typeof m.envs === 'function' ? m.envs(pluginMap) : (m.envs ?? {}),\n };\n\n ctx.log(\n 'torba',\n `merged ${deduped.length} artifact(s) (${artifacts.length - deduped.length} deduped)`,\n );\n\n return {\n vars,\n launch,\n artifacts: deduped,\n ...(m.restrict && m.restrict.length > 0 ? { restrict: m.restrict } : {}),\n };\n}\n"],"mappings":";;;;AAuCA,SAAgB,aAAa,QAAkC;AAC7D,QAAO;;;;;;ACUT,SAAgB,aAAa,OAA2C;AACtE,QAAO;;;AAIT,eAAsB,cACpB,OACA,KACsB;AACtB,QAAO,OAAO,UAAU,aAAa,MAAM,IAAI,GAAG;;;;;;AC9CpD,SAAS,YAAY,OAAuC;CAC1D,MAAM,MAAa,EAAE;AACrB,MAAK,MAAM,QAAQ,MACjB,KAAI,OAAO,SAAS,SAAU,KAAI,KAAK;EAAE,OAAO,EAAE;EAAE,OAAO,CAAC,KAAK;EAAE,CAAC;UAC3D,MAAM,QAAQ,KAAK,CAAE,KAAI,KAAK,GAAG,KAAK;KAC1C,KAAI,KAAK,KAAK;AAErB,QAAO;;;;;;AAOT,eAAsB,cACpB,QACA,KACmB;AACnB,KAAI,IAAI,SAAS,aAAa,OAAO,QAAQ,OAAO,YAAY;CAChE,MAAM,UAAU,MAAM,QAAQ,IAC5B,OAAO,QAAQ,IAAI,OAAO,OAAO;EAC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,QAAQ,OAAO,WAC5E;AAED,QAAO;EACL;EACA;EACA,WAAW;EACX,GAAI,EAAE,YAAY,EAAE,SAAS,SAAS,IAAI,EAAE,UAAU,EAAE,UAAU,GAAG,EAAE;EACxE"}
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@torba/dev",
3
+ "version": "1.0.10",
4
+ "main": "./dist/index.js",
5
+ "module": "./dist/index.js",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./dist/index.mjs",
9
+ "require": "./dist/index.cjs"
10
+ }
11
+ },
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsdown lib/index.ts --format esm,cjs --dts --clean",
17
+ "test": "vitest run tests/unit --passWithNoTests"
18
+ },
19
+ "type": "module",
20
+ "dependencies": {
21
+ "@torba/core": "^1.0.10"
22
+ },
23
+ "peerDependencies": {
24
+ "zod": "^4.0.0"
25
+ },
26
+ "devDependencies": {
27
+ "vitest": "*"
28
+ }
29
+ }