@geekmidas/cli 10.0.0-alpha.115 → 10.0.0-alpha.116
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/{bundler-hvCgi0EG.cjs → bundler-B2_2-Dum.cjs} +54 -2
- package/dist/bundler-B2_2-Dum.cjs.map +1 -0
- package/dist/{bundler-B2ysiCTa.mjs → bundler-CgcwaVI0.mjs} +55 -3
- package/dist/bundler-CgcwaVI0.mjs.map +1 -0
- package/dist/index.cjs +24 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +24 -24
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
- package/dist/bundler-B2ysiCTa.mjs.map +0 -1
- package/dist/bundler-hvCgi0EG.cjs.map +0 -1
|
@@ -55,6 +55,58 @@ async function collectRequiredEnvVars(constructs) {
|
|
|
55
55
|
for (const construct of constructs) for (const name of await construct.getEnvironment({ markOptional: true })) if (!name.endsWith("?")) required.add(name);
|
|
56
56
|
return Array.from(required).sort();
|
|
57
57
|
}
|
|
58
|
+
/** `<dir>/node_modules/<name>`, from `from` up to the root; the first found. */
|
|
59
|
+
function installed(name, from) {
|
|
60
|
+
for (let dir = from;; dir = (0, node_path.dirname)(dir)) {
|
|
61
|
+
const candidate = (0, node_path.join)(dir, "node_modules", name, "package.json");
|
|
62
|
+
if ((0, node_fs.existsSync)(candidate)) return (0, node_fs.realpathSync)((0, node_path.dirname)(candidate));
|
|
63
|
+
if ((0, node_path.dirname)(dir) === dir) return void 0;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The optional peers of the @geekmidas packages an app reaches that are not
|
|
68
|
+
* installed where those packages would resolve them.
|
|
69
|
+
*
|
|
70
|
+
* Each is imported only on the path that needs it — `@aws-sdk/client-kms`
|
|
71
|
+
* for a `kms:` key, say — so an app that never takes that path never
|
|
72
|
+
* installs it. esbuild resolves a dynamic import all the same, and fails
|
|
73
|
+
* the bundle on one it cannot find; left external instead, it is only
|
|
74
|
+
* looked for if that path runs, where its absence says what to install.
|
|
75
|
+
*/
|
|
76
|
+
function missingOptionalPeers(from) {
|
|
77
|
+
const missing = /* @__PURE__ */ new Set();
|
|
78
|
+
const seen = /* @__PURE__ */ new Set();
|
|
79
|
+
const visit = (dir) => {
|
|
80
|
+
if (seen.has(dir)) return;
|
|
81
|
+
seen.add(dir);
|
|
82
|
+
const pkg = JSON.parse((0, node_fs.readFileSync)((0, node_path.join)(dir, "package.json"), "utf-8"));
|
|
83
|
+
for (const [peer, meta] of Object.entries(pkg.peerDependenciesMeta ?? {})) if (meta?.optional && !installed(peer, dir)) missing.add(peer);
|
|
84
|
+
for (const name of Object.keys({
|
|
85
|
+
...pkg.dependencies,
|
|
86
|
+
...pkg.peerDependencies
|
|
87
|
+
})) {
|
|
88
|
+
if (!name.startsWith("@geekmidas/")) continue;
|
|
89
|
+
const found = installed(name, dir);
|
|
90
|
+
if (found) visit(found);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
for (let dir = from;; dir = (0, node_path.dirname)(dir)) {
|
|
94
|
+
if ((0, node_fs.existsSync)((0, node_path.join)(dir, "package.json"))) {
|
|
95
|
+
const pkg = JSON.parse((0, node_fs.readFileSync)((0, node_path.join)(dir, "package.json"), "utf-8"));
|
|
96
|
+
for (const name of Object.keys({
|
|
97
|
+
...pkg.dependencies,
|
|
98
|
+
...pkg.devDependencies
|
|
99
|
+
})) {
|
|
100
|
+
if (!name.startsWith("@geekmidas/")) continue;
|
|
101
|
+
const found = installed(name, dir);
|
|
102
|
+
if (found) visit(found);
|
|
103
|
+
}
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
if ((0, node_path.dirname)(dir) === dir) break;
|
|
107
|
+
}
|
|
108
|
+
return [...missing].sort();
|
|
109
|
+
}
|
|
58
110
|
/**
|
|
59
111
|
* Bundle the server application using esbuild.
|
|
60
112
|
* Creates a fully standalone bundle with all dependencies included.
|
|
@@ -79,7 +131,7 @@ async function bundleServer(options) {
|
|
|
79
131
|
];
|
|
80
132
|
if (minify) args.push("--minify", "--keep-names");
|
|
81
133
|
if (sourcemap) args.push("--sourcemap");
|
|
82
|
-
for (const ext of external) args.push(`--external:${ext}`);
|
|
134
|
+
for (const ext of [...external, ...missingOptionalPeers((0, node_path.dirname)(entryPoint))]) args.push(`--external:${ext}`);
|
|
83
135
|
let masterKey;
|
|
84
136
|
if (stage) {
|
|
85
137
|
const { toEmbeddableSecrets, validateEnvironmentVariables, initStageSecrets } = await Promise.resolve().then(() => require("./seeds-DbKNcs3o.cjs")).then((n) => n.storage_exports);
|
|
@@ -166,4 +218,4 @@ async function bundleServer(options) {
|
|
|
166
218
|
//#endregion
|
|
167
219
|
exports.bundleServer = bundleServer;
|
|
168
220
|
|
|
169
|
-
//# sourceMappingURL=bundler-
|
|
221
|
+
//# sourceMappingURL=bundler-B2_2-Dum.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundler-B2_2-Dum.cjs","names":["require","createRequire","join","dirname","existsSync","realpathSync","readFileSync","mkdir","spawnSync","writeFile"],"sources":["../src/build/bundler.ts"],"sourcesContent":["import { spawnSync } from 'node:child_process';\nimport { existsSync, readFileSync, realpathSync } from 'node:fs';\nimport { mkdir, writeFile } from 'node:fs/promises';\nimport { createRequire } from 'node:module';\nimport { dirname, join } from 'node:path';\nimport type { Construct } from '@geekmidas/constructs';\n\n/**\n * Banner to inject into ESM bundle for CJS compatibility.\n * Creates a `require` function using Node's createRequire for packages\n * that internally use CommonJS require() for Node builtins.\n */\nconst ESM_CJS_COMPAT_BANNER =\n\t'import { createRequire } from \"module\"; const require = createRequire(import.meta.url);';\n\nexport interface BundleOptions {\n\t/** Entry point file (e.g., .gkm/server/server.ts) */\n\tentryPoint: string;\n\t/** Output directory for bundled files */\n\toutputDir: string;\n\t/** The bundle's file name in `outputDir`. Defaults to `server.mjs`. */\n\toutfile?: string;\n\t/** Minify the output (default: true) */\n\tminify: boolean;\n\t/** Generate sourcemaps (default: false) */\n\tsourcemap: boolean;\n\t/** Packages to exclude from bundling */\n\texternal: string[];\n\t/** Stage for secrets injection (optional) */\n\tstage?: string;\n\t/** Constructs to validate environment variables for */\n\tconstructs?: Construct[];\n}\n\nexport interface BundleResult {\n\t/** Path to the bundled output */\n\toutputPath: string;\n\t/** Ephemeral master key for deployment (only if stage was provided) */\n\tmasterKey?: string;\n}\n\n/**\n * The esbuild binary, resolved from this package rather than from PATH.\n *\n * It used to be `npx esbuild`, which is two assumptions: that esbuild is\n * installed somewhere npx can find, and that the *app's* directory is where to\n * look. Neither holds — the CLI did not depend on esbuild at all, so a deploy\n * run from an app that had not installed it failed at the bundle step with\n * `sh: esbuild: command not found`, after provisioning had already happened.\n *\n * The same fix `bin/gkm.mjs` makes for tsx: resolve from this package's own\n * `node_modules`, so the tool the CLI shells out to is the one it depends on.\n */\nfunction esbuildBinary(): string {\n\tconst require = createRequire(import.meta.url);\n\n\ttry {\n\t\t// The package root, then its bin — `require.resolve('esbuild')` gives the\n\t\t// JS entry point, which is a library rather than the CLI.\n\t\tconst pkg = require.resolve('esbuild/package.json');\n\t\treturn join(dirname(pkg), 'bin', 'esbuild');\n\t} catch {\n\t\t// Better a PATH lookup than a hard failure: a project that installed\n\t\t// esbuild itself still works.\n\t\treturn 'esbuild';\n\t}\n}\n\n/**\n * Collect the environment variables a build cannot proceed without.\n *\n * Uses the SnifferEnvironmentParser to detect which env vars each service\n * reads, and keeps only the ones it cannot do without. `markOptional` is what\n * separates them: the sniffer already knows which reads went through\n * `.optional()` or `.default()`, and asking for that distinction is the\n * difference between a build that stops and one that proceeds correctly.\n *\n * Without it, a key that is *absent by design* failed the build. A surface\n * publishes `AUTH_COOKIE_DOMAIN` only when there is a domain to widen a cookie\n * to — one host has nothing to share it with, so the derivation correctly\n * yields nothing, and Better Auth reads it as optional for exactly that\n * reason. Treating every sniffed read as required made the honest answer\n * indistinguishable from a missing secret.\n *\n * @param constructs - Array of constructs to analyze\n * @returns Deduplicated, sorted names of the required variables\n */\nasync function collectRequiredEnvVars(\n\tconstructs: Construct[],\n): Promise<string[]> {\n\t// A key read optionally by one construct and required by another stays\n\t// required: the strictest read is the one that fails at runtime, and taking\n\t// the union of the required reads is what says so.\n\tconst required = new Set<string>();\n\n\tfor (const construct of constructs) {\n\t\tfor (const name of await construct.getEnvironment({ markOptional: true })) {\n\t\t\tif (!name.endsWith('?')) required.add(name);\n\t\t}\n\t}\n\n\treturn Array.from(required).sort();\n}\n\n/** `<dir>/node_modules/<name>`, from `from` up to the root; the first found. */\nfunction installed(name: string, from: string): string | undefined {\n\tfor (let dir = from; ; dir = dirname(dir)) {\n\t\tconst candidate = join(dir, 'node_modules', name, 'package.json');\n\t\tif (existsSync(candidate)) return realpathSync(dirname(candidate));\n\t\tif (dirname(dir) === dir) return undefined;\n\t}\n}\n\n/**\n * The optional peers of the @geekmidas packages an app reaches that are not\n * installed where those packages would resolve them.\n *\n * Each is imported only on the path that needs it — `@aws-sdk/client-kms`\n * for a `kms:` key, say — so an app that never takes that path never\n * installs it. esbuild resolves a dynamic import all the same, and fails\n * the bundle on one it cannot find; left external instead, it is only\n * looked for if that path runs, where its absence says what to install.\n */\nexport function missingOptionalPeers(from: string): string[] {\n\tconst missing = new Set<string>();\n\tconst seen = new Set<string>();\n\tconst visit = (dir: string) => {\n\t\tif (seen.has(dir)) return;\n\t\tseen.add(dir);\n\t\tconst pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf-8'));\n\t\tfor (const [peer, meta] of Object.entries(\n\t\t\t(pkg.peerDependenciesMeta ?? {}) as Record<\n\t\t\t\tstring,\n\t\t\t\t{ optional?: boolean }\n\t\t\t>,\n\t\t)) {\n\t\t\tif (meta?.optional && !installed(peer, dir)) missing.add(peer);\n\t\t}\n\t\tfor (const name of Object.keys({\n\t\t\t...pkg.dependencies,\n\t\t\t...pkg.peerDependencies,\n\t\t})) {\n\t\t\tif (!name.startsWith('@geekmidas/')) continue;\n\t\t\tconst found = installed(name, dir);\n\t\t\tif (found) visit(found);\n\t\t}\n\t};\n\n\t// The app's own package.json: the nearest above the entry.\n\tfor (let dir = from; ; dir = dirname(dir)) {\n\t\tif (existsSync(join(dir, 'package.json'))) {\n\t\t\tconst pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf-8'));\n\t\t\tfor (const name of Object.keys({\n\t\t\t\t...pkg.dependencies,\n\t\t\t\t...pkg.devDependencies,\n\t\t\t})) {\n\t\t\t\tif (!name.startsWith('@geekmidas/')) continue;\n\t\t\t\tconst found = installed(name, dir);\n\t\t\t\tif (found) visit(found);\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tif (dirname(dir) === dir) break;\n\t}\n\treturn [...missing].sort();\n}\n\n/**\n * Bundle the server application using esbuild.\n * Creates a fully standalone bundle with all dependencies included.\n *\n * @param options - Bundle configuration options\n * @returns Bundle result with output path and optional master key\n */\n\nexport async function bundleServer(\n\toptions: BundleOptions,\n): Promise<BundleResult> {\n\tconst {\n\t\tentryPoint,\n\t\toutputDir,\n\t\tminify,\n\t\tsourcemap,\n\t\texternal,\n\t\tstage,\n\t\tconstructs,\n\t} = options;\n\n\t// Ensure output directory exists\n\tawait mkdir(outputDir, { recursive: true });\n\n\tconst mjsOutput = join(outputDir, options.outfile ?? 'server.mjs');\n\n\t// Build command-line arguments for esbuild\n\tconst args = [\n\t\tesbuildBinary(),\n\t\tentryPoint,\n\t\t'--bundle',\n\t\t'--platform=node',\n\t\t'--target=node22',\n\t\t'--format=esm',\n\t\t`--outfile=${mjsOutput}`,\n\t\t'--packages=bundle', // Bundle all dependencies for standalone output\n\t\t`--banner:js=${ESM_CJS_COMPAT_BANNER}`, // CJS compatibility for packages like pino\n\t];\n\n\tif (minify) {\n\t\t// Names kept: an error's class name is what a log line's `err.type` and\n\t\t// a response's `name` say, and minified they read `_6`.\n\t\targs.push('--minify', '--keep-names');\n\t}\n\n\tif (sourcemap) {\n\t\targs.push('--sourcemap');\n\t}\n\n\t// Add external packages (user-specified), and the optional peers a\n\t// @geekmidas package only loads on a path this app may never take\n\tfor (const ext of [\n\t\t...external,\n\t\t...missingOptionalPeers(dirname(entryPoint)),\n\t]) {\n\t\targs.push(`--external:${ext}`);\n\t}\n\n\t// Handle secrets injection if stage is provided\n\tlet masterKey: string | undefined;\n\n\tif (stage) {\n\t\tconst {\n\t\t\ttoEmbeddableSecrets,\n\t\t\tvalidateEnvironmentVariables,\n\t\t\tinitStageSecrets,\n\t\t} = await import('../secrets/storage');\n\t\tconst { FileSecretsStore, secretsStoreFor } = await import(\n\t\t\t'../secrets/store'\n\t\t);\n\t\tconst { ConfigNotFound, loadWorkspaceSettings } = await import('../config');\n\t\tconst { encryptSecrets, generateDefineOptions } = await import(\n\t\t\t'../secrets/encryption'\n\t\t);\n\n\t\t// The stage's own store — SSM or Secrets Manager for a deployed stage\n\t\t// kept there. Outside\n\t\t// any workspace nothing names one, so it is the file.\n\t\tconst store = await loadWorkspaceSettings().then(\n\t\t\t(workspace) => secretsStoreFor(workspace, stage),\n\t\t\t(error) => {\n\t\t\t\tif (error instanceof ConfigNotFound) {\n\t\t\t\t\treturn new FileSecretsStore(process.cwd());\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t);\n\t\tlet secrets = await store.read(stage);\n\n\t\tif (!secrets) {\n\t\t\t// Auto-initialize secrets for the stage\n\t\t\tconsole.log(` Initializing secrets for stage \"${stage}\"...`);\n\t\t\tsecrets = initStageSecrets(stage);\n\t\t\tawait store.write(stage, secrets);\n\t\t\tconsole.log(` ✓ Created the \"${stage}\" secrets (${store.name})`);\n\t\t}\n\n\t\t// Validate environment variables if constructs are provided\n\t\tif (constructs && constructs.length > 0) {\n\t\t\tconsole.log(' Analyzing environment variable requirements...');\n\t\t\tconst requiredVars = await collectRequiredEnvVars(constructs);\n\n\t\t\tif (requiredVars.length > 0) {\n\t\t\t\tconst validation = validateEnvironmentVariables(requiredVars, secrets);\n\n\t\t\t\tif (!validation.valid) {\n\t\t\t\t\tconst errorMessage = [\n\t\t\t\t\t\t`Missing environment variables for stage \"${stage}\":`,\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t...validation.missing.map((v) => ` ❌ ${v}`),\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t'To fix this, either:',\n\t\t\t\t\t\t` 1. Add the missing variables to the \"${stage}\" secrets using:`,\n\t\t\t\t\t\t` gkm secrets:set <KEY> <VALUE> --stage ${stage}`,\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t` 2. Or import from a JSON file:`,\n\t\t\t\t\t\t` gkm secrets:import secrets.json --stage ${stage}`,\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t'Required variables:',\n\t\t\t\t\t\t...validation.required.map((v) =>\n\t\t\t\t\t\t\tvalidation.missing.includes(v) ? ` ❌ ${v}` : ` ✓ ${v}`,\n\t\t\t\t\t\t),\n\t\t\t\t\t].join('\\n');\n\n\t\t\t\t\tthrow new Error(errorMessage);\n\t\t\t\t}\n\n\t\t\t\tconsole.log(\n\t\t\t\t\t` ✓ All ${requiredVars.length} required environment variables found`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Convert to embeddable format and encrypt\n\t\tconst embeddable = toEmbeddableSecrets(secrets);\n\t\tconst encrypted = encryptSecrets(embeddable);\n\t\tmasterKey = encrypted.masterKey;\n\n\t\t// Add define options for build-time injection using esbuild's --define:KEY=VALUE format\n\t\tconst defines = generateDefineOptions(encrypted);\n\t\tfor (const [key, value] of Object.entries(defines)) {\n\t\t\t// `value` is already a JS string literal; quoting it again would\n\t\t\t// embed the quotes, and the IV would not parse as hex.\n\t\t\targs.push(`--define:${key}=${value}`);\n\t\t}\n\n\t\tconsole.log(` Secrets encrypted for stage \"${stage}\"`);\n\t} else {\n\t\t// Credentials encrypted elsewhere — an image build hands them in as a\n\t\t// BuildKit secret and writes them beside the app's `.gkm/server` — are\n\t\t// embedded as they are; whoever encrypted them holds the key.\n\t\tconst gkmDir = join(outputDir, '..', '..');\n\t\tconst encryptedPath = join(gkmDir, 'credentials.enc');\n\t\tconst ivPath = join(gkmDir, 'credentials.iv');\n\t\tif (existsSync(encryptedPath) && existsSync(ivPath)) {\n\t\t\tconst { generateDefineOptions } = await import('../secrets/encryption');\n\t\t\tconst defines = generateDefineOptions({\n\t\t\t\tencrypted: readFileSync(encryptedPath, 'utf-8').trim(),\n\t\t\t\tiv: readFileSync(ivPath, 'utf-8').trim(),\n\t\t\t\tmasterKey: '',\n\t\t\t});\n\t\t\tfor (const [key, value] of Object.entries(defines)) {\n\t\t\t\targs.push(`--define:${key}=${value}`);\n\t\t\t}\n\t\t\tconsole.log(' Embedded the encrypted credentials the build was given');\n\t\t}\n\t}\n\n\ttry {\n\t\t// Run esbuild with command-line arguments\n\t\tconst [cmd, ...cmdArgs] = args as [string, ...string[]];\n\t\tconst result = spawnSync(cmd, cmdArgs, {\n\t\t\tcwd: process.cwd(),\n\t\t\tstdio: 'inherit',\n\t\t\tshell: process.platform === 'win32', // Only use shell on Windows for npx resolution\n\t\t});\n\n\t\tif (result.error) {\n\t\t\tthrow result.error;\n\t\t}\n\t\tif (result.status !== 0) {\n\t\t\tthrow new Error(`esbuild exited with code ${result.status}`);\n\t\t}\n\n\t\t// Add shebang to the bundled file\n\t\tconst { readFile } = await import('node:fs/promises');\n\t\tconst content = await readFile(mjsOutput, 'utf-8');\n\t\tif (!content.startsWith('#!')) {\n\t\t\tawait writeFile(mjsOutput, `#!/usr/bin/env node\\n${content}`);\n\t\t}\n\t} catch (error) {\n\t\tthrow new Error(\n\t\t\t`Failed to bundle server: ${error instanceof Error ? error.message : 'Unknown error'}`,\n\t\t);\n\t}\n\n\treturn {\n\t\toutputPath: mjsOutput,\n\t\tmasterKey,\n\t};\n}\n"],"mappings":";;;;;;;;;;;AAYA,MAAM,wBACL;;;;;;;;;;;;;AAwCD,SAAS,gBAAwB;CAChC,MAAMA,aAAAA,GAAUC,YAAAA,cAAAA,CAAAA,QAAAA,KAAAA,CAAAA,CAAAA,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AA,aAAAA,CAAa,eAAe,OAAO,CAAC,CAAC,KAAK;IACrD,KAAA,GAAIA,QAAAA,aAAAA,CAAa,QAAQ,OAAO,CAAC,CAAC,KAAK;IACvC,WAAW;GACZ,CAAC;GACD,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,GAChD,KAAK,KAAK,YAAY,IAAI,GAAG,OAAO;GAErC,QAAQ,IAAI,0DAA0D;EACvE;CACD;CAEA,IAAI;EAEH,MAAM,CAAC,KAAK,GAAG,WAAW;EAC1B,MAAM,UAAA,GAASE,mBAAAA,UAAAA,CAAU,KAAK,SAAS;GACtC,KAAK,QAAQ,IAAI;GACjB,OAAO;GACP,OAAO,QAAQ,aAAa;EAC7B,CAAC;EAED,IAAI,OAAO,OACV,MAAM,OAAO;EAEd,IAAI,OAAO,WAAW,GACrB,MAAM,IAAI,MAAM,4BAA4B,OAAO,QAAQ;EAI5D,MAAM,EAAE,aAAa,MAAM,OAAO;EAClC,MAAM,UAAU,MAAM,SAAS,WAAW,OAAO;EACjD,IAAI,CAAC,QAAQ,WAAW,IAAI,GAC3B,OAAA,GAAMC,iBAAAA,UAAAA,CAAU,WAAW,wBAAwB,SAAS;CAE9D,SAAS,OAAO;EACf,MAAM,IAAI,MACT,4BAA4B,iBAAiB,QAAQ,MAAM,UAAU,iBACtE;CACD;CAEA,OAAO;EACN,YAAY;EACZ;CACD;AACD"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
4
4
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
5
5
|
import { spawnSync } from "node:child_process";
|
|
6
6
|
//#region src/build/bundler.ts
|
|
@@ -55,6 +55,58 @@ async function collectRequiredEnvVars(constructs) {
|
|
|
55
55
|
for (const construct of constructs) for (const name of await construct.getEnvironment({ markOptional: true })) if (!name.endsWith("?")) required.add(name);
|
|
56
56
|
return Array.from(required).sort();
|
|
57
57
|
}
|
|
58
|
+
/** `<dir>/node_modules/<name>`, from `from` up to the root; the first found. */
|
|
59
|
+
function installed(name, from) {
|
|
60
|
+
for (let dir = from;; dir = dirname(dir)) {
|
|
61
|
+
const candidate = join(dir, "node_modules", name, "package.json");
|
|
62
|
+
if (existsSync(candidate)) return realpathSync(dirname(candidate));
|
|
63
|
+
if (dirname(dir) === dir) return void 0;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The optional peers of the @geekmidas packages an app reaches that are not
|
|
68
|
+
* installed where those packages would resolve them.
|
|
69
|
+
*
|
|
70
|
+
* Each is imported only on the path that needs it — `@aws-sdk/client-kms`
|
|
71
|
+
* for a `kms:` key, say — so an app that never takes that path never
|
|
72
|
+
* installs it. esbuild resolves a dynamic import all the same, and fails
|
|
73
|
+
* the bundle on one it cannot find; left external instead, it is only
|
|
74
|
+
* looked for if that path runs, where its absence says what to install.
|
|
75
|
+
*/
|
|
76
|
+
function missingOptionalPeers(from) {
|
|
77
|
+
const missing = /* @__PURE__ */ new Set();
|
|
78
|
+
const seen = /* @__PURE__ */ new Set();
|
|
79
|
+
const visit = (dir) => {
|
|
80
|
+
if (seen.has(dir)) return;
|
|
81
|
+
seen.add(dir);
|
|
82
|
+
const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf-8"));
|
|
83
|
+
for (const [peer, meta] of Object.entries(pkg.peerDependenciesMeta ?? {})) if (meta?.optional && !installed(peer, dir)) missing.add(peer);
|
|
84
|
+
for (const name of Object.keys({
|
|
85
|
+
...pkg.dependencies,
|
|
86
|
+
...pkg.peerDependencies
|
|
87
|
+
})) {
|
|
88
|
+
if (!name.startsWith("@geekmidas/")) continue;
|
|
89
|
+
const found = installed(name, dir);
|
|
90
|
+
if (found) visit(found);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
for (let dir = from;; dir = dirname(dir)) {
|
|
94
|
+
if (existsSync(join(dir, "package.json"))) {
|
|
95
|
+
const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf-8"));
|
|
96
|
+
for (const name of Object.keys({
|
|
97
|
+
...pkg.dependencies,
|
|
98
|
+
...pkg.devDependencies
|
|
99
|
+
})) {
|
|
100
|
+
if (!name.startsWith("@geekmidas/")) continue;
|
|
101
|
+
const found = installed(name, dir);
|
|
102
|
+
if (found) visit(found);
|
|
103
|
+
}
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
if (dirname(dir) === dir) break;
|
|
107
|
+
}
|
|
108
|
+
return [...missing].sort();
|
|
109
|
+
}
|
|
58
110
|
/**
|
|
59
111
|
* Bundle the server application using esbuild.
|
|
60
112
|
* Creates a fully standalone bundle with all dependencies included.
|
|
@@ -79,7 +131,7 @@ async function bundleServer(options) {
|
|
|
79
131
|
];
|
|
80
132
|
if (minify) args.push("--minify", "--keep-names");
|
|
81
133
|
if (sourcemap) args.push("--sourcemap");
|
|
82
|
-
for (const ext of external) args.push(`--external:${ext}`);
|
|
134
|
+
for (const ext of [...external, ...missingOptionalPeers(dirname(entryPoint))]) args.push(`--external:${ext}`);
|
|
83
135
|
let masterKey;
|
|
84
136
|
if (stage) {
|
|
85
137
|
const { toEmbeddableSecrets, validateEnvironmentVariables, initStageSecrets } = await import("./seeds-CRkKeyW0.mjs").then((n) => n.Vt);
|
|
@@ -166,4 +218,4 @@ async function bundleServer(options) {
|
|
|
166
218
|
//#endregion
|
|
167
219
|
export { bundleServer };
|
|
168
220
|
|
|
169
|
-
//# sourceMappingURL=bundler-
|
|
221
|
+
//# sourceMappingURL=bundler-CgcwaVI0.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundler-CgcwaVI0.mjs","names":[],"sources":["../src/build/bundler.ts"],"sourcesContent":["import { spawnSync } from 'node:child_process';\nimport { existsSync, readFileSync, realpathSync } from 'node:fs';\nimport { mkdir, writeFile } from 'node:fs/promises';\nimport { createRequire } from 'node:module';\nimport { dirname, join } from 'node:path';\nimport type { Construct } from '@geekmidas/constructs';\n\n/**\n * Banner to inject into ESM bundle for CJS compatibility.\n * Creates a `require` function using Node's createRequire for packages\n * that internally use CommonJS require() for Node builtins.\n */\nconst ESM_CJS_COMPAT_BANNER =\n\t'import { createRequire } from \"module\"; const require = createRequire(import.meta.url);';\n\nexport interface BundleOptions {\n\t/** Entry point file (e.g., .gkm/server/server.ts) */\n\tentryPoint: string;\n\t/** Output directory for bundled files */\n\toutputDir: string;\n\t/** The bundle's file name in `outputDir`. Defaults to `server.mjs`. */\n\toutfile?: string;\n\t/** Minify the output (default: true) */\n\tminify: boolean;\n\t/** Generate sourcemaps (default: false) */\n\tsourcemap: boolean;\n\t/** Packages to exclude from bundling */\n\texternal: string[];\n\t/** Stage for secrets injection (optional) */\n\tstage?: string;\n\t/** Constructs to validate environment variables for */\n\tconstructs?: Construct[];\n}\n\nexport interface BundleResult {\n\t/** Path to the bundled output */\n\toutputPath: string;\n\t/** Ephemeral master key for deployment (only if stage was provided) */\n\tmasterKey?: string;\n}\n\n/**\n * The esbuild binary, resolved from this package rather than from PATH.\n *\n * It used to be `npx esbuild`, which is two assumptions: that esbuild is\n * installed somewhere npx can find, and that the *app's* directory is where to\n * look. Neither holds — the CLI did not depend on esbuild at all, so a deploy\n * run from an app that had not installed it failed at the bundle step with\n * `sh: esbuild: command not found`, after provisioning had already happened.\n *\n * The same fix `bin/gkm.mjs` makes for tsx: resolve from this package's own\n * `node_modules`, so the tool the CLI shells out to is the one it depends on.\n */\nfunction esbuildBinary(): string {\n\tconst require = createRequire(import.meta.url);\n\n\ttry {\n\t\t// The package root, then its bin — `require.resolve('esbuild')` gives the\n\t\t// JS entry point, which is a library rather than the CLI.\n\t\tconst pkg = require.resolve('esbuild/package.json');\n\t\treturn join(dirname(pkg), 'bin', 'esbuild');\n\t} catch {\n\t\t// Better a PATH lookup than a hard failure: a project that installed\n\t\t// esbuild itself still works.\n\t\treturn 'esbuild';\n\t}\n}\n\n/**\n * Collect the environment variables a build cannot proceed without.\n *\n * Uses the SnifferEnvironmentParser to detect which env vars each service\n * reads, and keeps only the ones it cannot do without. `markOptional` is what\n * separates them: the sniffer already knows which reads went through\n * `.optional()` or `.default()`, and asking for that distinction is the\n * difference between a build that stops and one that proceeds correctly.\n *\n * Without it, a key that is *absent by design* failed the build. A surface\n * publishes `AUTH_COOKIE_DOMAIN` only when there is a domain to widen a cookie\n * to — one host has nothing to share it with, so the derivation correctly\n * yields nothing, and Better Auth reads it as optional for exactly that\n * reason. Treating every sniffed read as required made the honest answer\n * indistinguishable from a missing secret.\n *\n * @param constructs - Array of constructs to analyze\n * @returns Deduplicated, sorted names of the required variables\n */\nasync function collectRequiredEnvVars(\n\tconstructs: Construct[],\n): Promise<string[]> {\n\t// A key read optionally by one construct and required by another stays\n\t// required: the strictest read is the one that fails at runtime, and taking\n\t// the union of the required reads is what says so.\n\tconst required = new Set<string>();\n\n\tfor (const construct of constructs) {\n\t\tfor (const name of await construct.getEnvironment({ markOptional: true })) {\n\t\t\tif (!name.endsWith('?')) required.add(name);\n\t\t}\n\t}\n\n\treturn Array.from(required).sort();\n}\n\n/** `<dir>/node_modules/<name>`, from `from` up to the root; the first found. */\nfunction installed(name: string, from: string): string | undefined {\n\tfor (let dir = from; ; dir = dirname(dir)) {\n\t\tconst candidate = join(dir, 'node_modules', name, 'package.json');\n\t\tif (existsSync(candidate)) return realpathSync(dirname(candidate));\n\t\tif (dirname(dir) === dir) return undefined;\n\t}\n}\n\n/**\n * The optional peers of the @geekmidas packages an app reaches that are not\n * installed where those packages would resolve them.\n *\n * Each is imported only on the path that needs it — `@aws-sdk/client-kms`\n * for a `kms:` key, say — so an app that never takes that path never\n * installs it. esbuild resolves a dynamic import all the same, and fails\n * the bundle on one it cannot find; left external instead, it is only\n * looked for if that path runs, where its absence says what to install.\n */\nexport function missingOptionalPeers(from: string): string[] {\n\tconst missing = new Set<string>();\n\tconst seen = new Set<string>();\n\tconst visit = (dir: string) => {\n\t\tif (seen.has(dir)) return;\n\t\tseen.add(dir);\n\t\tconst pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf-8'));\n\t\tfor (const [peer, meta] of Object.entries(\n\t\t\t(pkg.peerDependenciesMeta ?? {}) as Record<\n\t\t\t\tstring,\n\t\t\t\t{ optional?: boolean }\n\t\t\t>,\n\t\t)) {\n\t\t\tif (meta?.optional && !installed(peer, dir)) missing.add(peer);\n\t\t}\n\t\tfor (const name of Object.keys({\n\t\t\t...pkg.dependencies,\n\t\t\t...pkg.peerDependencies,\n\t\t})) {\n\t\t\tif (!name.startsWith('@geekmidas/')) continue;\n\t\t\tconst found = installed(name, dir);\n\t\t\tif (found) visit(found);\n\t\t}\n\t};\n\n\t// The app's own package.json: the nearest above the entry.\n\tfor (let dir = from; ; dir = dirname(dir)) {\n\t\tif (existsSync(join(dir, 'package.json'))) {\n\t\t\tconst pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf-8'));\n\t\t\tfor (const name of Object.keys({\n\t\t\t\t...pkg.dependencies,\n\t\t\t\t...pkg.devDependencies,\n\t\t\t})) {\n\t\t\t\tif (!name.startsWith('@geekmidas/')) continue;\n\t\t\t\tconst found = installed(name, dir);\n\t\t\t\tif (found) visit(found);\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tif (dirname(dir) === dir) break;\n\t}\n\treturn [...missing].sort();\n}\n\n/**\n * Bundle the server application using esbuild.\n * Creates a fully standalone bundle with all dependencies included.\n *\n * @param options - Bundle configuration options\n * @returns Bundle result with output path and optional master key\n */\n\nexport async function bundleServer(\n\toptions: BundleOptions,\n): Promise<BundleResult> {\n\tconst {\n\t\tentryPoint,\n\t\toutputDir,\n\t\tminify,\n\t\tsourcemap,\n\t\texternal,\n\t\tstage,\n\t\tconstructs,\n\t} = options;\n\n\t// Ensure output directory exists\n\tawait mkdir(outputDir, { recursive: true });\n\n\tconst mjsOutput = join(outputDir, options.outfile ?? 'server.mjs');\n\n\t// Build command-line arguments for esbuild\n\tconst args = [\n\t\tesbuildBinary(),\n\t\tentryPoint,\n\t\t'--bundle',\n\t\t'--platform=node',\n\t\t'--target=node22',\n\t\t'--format=esm',\n\t\t`--outfile=${mjsOutput}`,\n\t\t'--packages=bundle', // Bundle all dependencies for standalone output\n\t\t`--banner:js=${ESM_CJS_COMPAT_BANNER}`, // CJS compatibility for packages like pino\n\t];\n\n\tif (minify) {\n\t\t// Names kept: an error's class name is what a log line's `err.type` and\n\t\t// a response's `name` say, and minified they read `_6`.\n\t\targs.push('--minify', '--keep-names');\n\t}\n\n\tif (sourcemap) {\n\t\targs.push('--sourcemap');\n\t}\n\n\t// Add external packages (user-specified), and the optional peers a\n\t// @geekmidas package only loads on a path this app may never take\n\tfor (const ext of [\n\t\t...external,\n\t\t...missingOptionalPeers(dirname(entryPoint)),\n\t]) {\n\t\targs.push(`--external:${ext}`);\n\t}\n\n\t// Handle secrets injection if stage is provided\n\tlet masterKey: string | undefined;\n\n\tif (stage) {\n\t\tconst {\n\t\t\ttoEmbeddableSecrets,\n\t\t\tvalidateEnvironmentVariables,\n\t\t\tinitStageSecrets,\n\t\t} = await import('../secrets/storage');\n\t\tconst { FileSecretsStore, secretsStoreFor } = await import(\n\t\t\t'../secrets/store'\n\t\t);\n\t\tconst { ConfigNotFound, loadWorkspaceSettings } = await import('../config');\n\t\tconst { encryptSecrets, generateDefineOptions } = await import(\n\t\t\t'../secrets/encryption'\n\t\t);\n\n\t\t// The stage's own store — SSM or Secrets Manager for a deployed stage\n\t\t// kept there. Outside\n\t\t// any workspace nothing names one, so it is the file.\n\t\tconst store = await loadWorkspaceSettings().then(\n\t\t\t(workspace) => secretsStoreFor(workspace, stage),\n\t\t\t(error) => {\n\t\t\t\tif (error instanceof ConfigNotFound) {\n\t\t\t\t\treturn new FileSecretsStore(process.cwd());\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t);\n\t\tlet secrets = await store.read(stage);\n\n\t\tif (!secrets) {\n\t\t\t// Auto-initialize secrets for the stage\n\t\t\tconsole.log(` Initializing secrets for stage \"${stage}\"...`);\n\t\t\tsecrets = initStageSecrets(stage);\n\t\t\tawait store.write(stage, secrets);\n\t\t\tconsole.log(` ✓ Created the \"${stage}\" secrets (${store.name})`);\n\t\t}\n\n\t\t// Validate environment variables if constructs are provided\n\t\tif (constructs && constructs.length > 0) {\n\t\t\tconsole.log(' Analyzing environment variable requirements...');\n\t\t\tconst requiredVars = await collectRequiredEnvVars(constructs);\n\n\t\t\tif (requiredVars.length > 0) {\n\t\t\t\tconst validation = validateEnvironmentVariables(requiredVars, secrets);\n\n\t\t\t\tif (!validation.valid) {\n\t\t\t\t\tconst errorMessage = [\n\t\t\t\t\t\t`Missing environment variables for stage \"${stage}\":`,\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t...validation.missing.map((v) => ` ❌ ${v}`),\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t'To fix this, either:',\n\t\t\t\t\t\t` 1. Add the missing variables to the \"${stage}\" secrets using:`,\n\t\t\t\t\t\t` gkm secrets:set <KEY> <VALUE> --stage ${stage}`,\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t` 2. Or import from a JSON file:`,\n\t\t\t\t\t\t` gkm secrets:import secrets.json --stage ${stage}`,\n\t\t\t\t\t\t'',\n\t\t\t\t\t\t'Required variables:',\n\t\t\t\t\t\t...validation.required.map((v) =>\n\t\t\t\t\t\t\tvalidation.missing.includes(v) ? ` ❌ ${v}` : ` ✓ ${v}`,\n\t\t\t\t\t\t),\n\t\t\t\t\t].join('\\n');\n\n\t\t\t\t\tthrow new Error(errorMessage);\n\t\t\t\t}\n\n\t\t\t\tconsole.log(\n\t\t\t\t\t` ✓ All ${requiredVars.length} required environment variables found`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Convert to embeddable format and encrypt\n\t\tconst embeddable = toEmbeddableSecrets(secrets);\n\t\tconst encrypted = encryptSecrets(embeddable);\n\t\tmasterKey = encrypted.masterKey;\n\n\t\t// Add define options for build-time injection using esbuild's --define:KEY=VALUE format\n\t\tconst defines = generateDefineOptions(encrypted);\n\t\tfor (const [key, value] of Object.entries(defines)) {\n\t\t\t// `value` is already a JS string literal; quoting it again would\n\t\t\t// embed the quotes, and the IV would not parse as hex.\n\t\t\targs.push(`--define:${key}=${value}`);\n\t\t}\n\n\t\tconsole.log(` Secrets encrypted for stage \"${stage}\"`);\n\t} else {\n\t\t// Credentials encrypted elsewhere — an image build hands them in as a\n\t\t// BuildKit secret and writes them beside the app's `.gkm/server` — are\n\t\t// embedded as they are; whoever encrypted them holds the key.\n\t\tconst gkmDir = join(outputDir, '..', '..');\n\t\tconst encryptedPath = join(gkmDir, 'credentials.enc');\n\t\tconst ivPath = join(gkmDir, 'credentials.iv');\n\t\tif (existsSync(encryptedPath) && existsSync(ivPath)) {\n\t\t\tconst { generateDefineOptions } = await import('../secrets/encryption');\n\t\t\tconst defines = generateDefineOptions({\n\t\t\t\tencrypted: readFileSync(encryptedPath, 'utf-8').trim(),\n\t\t\t\tiv: readFileSync(ivPath, 'utf-8').trim(),\n\t\t\t\tmasterKey: '',\n\t\t\t});\n\t\t\tfor (const [key, value] of Object.entries(defines)) {\n\t\t\t\targs.push(`--define:${key}=${value}`);\n\t\t\t}\n\t\t\tconsole.log(' Embedded the encrypted credentials the build was given');\n\t\t}\n\t}\n\n\ttry {\n\t\t// Run esbuild with command-line arguments\n\t\tconst [cmd, ...cmdArgs] = args as [string, ...string[]];\n\t\tconst result = spawnSync(cmd, cmdArgs, {\n\t\t\tcwd: process.cwd(),\n\t\t\tstdio: 'inherit',\n\t\t\tshell: process.platform === 'win32', // Only use shell on Windows for npx resolution\n\t\t});\n\n\t\tif (result.error) {\n\t\t\tthrow result.error;\n\t\t}\n\t\tif (result.status !== 0) {\n\t\t\tthrow new Error(`esbuild exited with code ${result.status}`);\n\t\t}\n\n\t\t// Add shebang to the bundled file\n\t\tconst { readFile } = await import('node:fs/promises');\n\t\tconst content = await readFile(mjsOutput, 'utf-8');\n\t\tif (!content.startsWith('#!')) {\n\t\t\tawait writeFile(mjsOutput, `#!/usr/bin/env node\\n${content}`);\n\t\t}\n\t} catch (error) {\n\t\tthrow new Error(\n\t\t\t`Failed to bundle server: ${error instanceof Error ? error.message : 'Unknown error'}`,\n\t\t);\n\t}\n\n\treturn {\n\t\toutputPath: mjsOutput,\n\t\tmasterKey,\n\t};\n}\n"],"mappings":";;;;;;;;;;;AAYA,MAAM,wBACL;;;;;;;;;;;;;AAwCD,SAAS,gBAAwB;CAChC,MAAM,UAAU,cAAc,YAAY,GAAG;CAE7C,IAAI;EAGH,MAAM,MAAM,QAAQ,QAAQ,sBAAsB;EAClD,OAAO,KAAK,QAAQ,GAAG,GAAG,OAAO,SAAS;CAC3C,QAAQ;EAGP,OAAO;CACR;AACD;;;;;;;;;;;;;;;;;;;;AAqBA,eAAe,uBACd,YACoB;CAIpB,MAAM,2BAAW,IAAI,IAAY;CAEjC,KAAK,MAAM,aAAa,YACvB,KAAK,MAAM,QAAQ,MAAM,UAAU,eAAe,EAAE,cAAc,KAAK,CAAC,GACvE,IAAI,CAAC,KAAK,SAAS,GAAG,GAAG,SAAS,IAAI,IAAI;CAI5C,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,KAAK;AAClC;;AAGA,SAAS,UAAU,MAAc,MAAkC;CAClE,KAAK,IAAI,MAAM,OAAQ,MAAM,QAAQ,GAAG,GAAG;EAC1C,MAAM,YAAY,KAAK,KAAK,gBAAgB,MAAM,cAAc;EAChE,IAAI,WAAW,SAAS,GAAG,OAAO,aAAa,QAAQ,SAAS,CAAC;EACjE,IAAI,QAAQ,GAAG,MAAM,KAAK,OAAO,KAAA;CAClC;AACD;;;;;;;;;;;AAYA,SAAgB,qBAAqB,MAAwB;CAC5D,MAAM,0BAAU,IAAI,IAAY;CAChC,MAAM,uBAAO,IAAI,IAAY;CAC7B,MAAM,SAAS,QAAgB;EAC9B,IAAI,KAAK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CAAC;EAED,IAAI,OAAO,OACV,MAAM,OAAO;EAEd,IAAI,OAAO,WAAW,GACrB,MAAM,IAAI,MAAM,4BAA4B,OAAO,QAAQ;EAI5D,MAAM,EAAE,aAAa,MAAM,OAAO;EAClC,MAAM,UAAU,MAAM,SAAS,WAAW,OAAO;EACjD,IAAI,CAAC,QAAQ,WAAW,IAAI,GAC3B,MAAM,UAAU,WAAW,wBAAwB,SAAS;CAE9D,SAAS,OAAO;EACf,MAAM,IAAI,MACT,4BAA4B,iBAAiB,QAAQ,MAAM,UAAU,iBACtE;CACD;CAEA,OAAO;EACN,YAAY;EACZ;CACD;AACD"}
|
package/dist/index.cjs
CHANGED
|
@@ -57,7 +57,7 @@ crypto = require_rolldown_runtime.__toESM(crypto, 1);
|
|
|
57
57
|
let _geekmidas_constructs_functions = require("@geekmidas/constructs/functions");
|
|
58
58
|
let _geekmidas_constructs_topic = require("@geekmidas/constructs/topic");
|
|
59
59
|
//#region package.json
|
|
60
|
-
var version = "10.0.0-alpha.
|
|
60
|
+
var version = "10.0.0-alpha.116";
|
|
61
61
|
//#endregion
|
|
62
62
|
//#region src/prompt.ts
|
|
63
63
|
/**
|
|
@@ -3831,7 +3831,7 @@ async function buildApp(input) {
|
|
|
3831
3831
|
...production,
|
|
3832
3832
|
...telemetry ? { telemetry } : {}
|
|
3833
3833
|
});
|
|
3834
|
-
const { bundleServer } = await Promise.resolve().then(() => require("./bundler-
|
|
3834
|
+
const { bundleServer } = await Promise.resolve().then(() => require("./bundler-B2_2-Dum.cjs"));
|
|
3835
3835
|
await bundleServer({
|
|
3836
3836
|
entryPoint,
|
|
3837
3837
|
outputDir: (0, node_path.join)(outputDir, "dist"),
|
|
@@ -4030,7 +4030,7 @@ async function buildWorkers(input) {
|
|
|
4030
4030
|
});
|
|
4031
4031
|
logger$4.log(`Generated worker ${worker.id}: ${crons.length} crons, ${queues.length} queues, ${subscribers.length} subscribers`);
|
|
4032
4032
|
if (!input.bundle) continue;
|
|
4033
|
-
const { bundleServer } = await Promise.resolve().then(() => require("./bundler-
|
|
4033
|
+
const { bundleServer } = await Promise.resolve().then(() => require("./bundler-B2_2-Dum.cjs"));
|
|
4034
4034
|
const outfile = require_seeds.workerBundleName(worker.id);
|
|
4035
4035
|
await bundleServer({
|
|
4036
4036
|
entryPoint,
|
|
@@ -4116,7 +4116,7 @@ async function buildForTarget(target, context, appRoot, workspaceRoot, endpointG
|
|
|
4116
4116
|
let masterKey;
|
|
4117
4117
|
if (context.production?.bundle && !skipBundle) {
|
|
4118
4118
|
logger$4.log(`\n📦 Bundling production server...`);
|
|
4119
|
-
const { bundleServer } = await Promise.resolve().then(() => require("./bundler-
|
|
4119
|
+
const { bundleServer } = await Promise.resolve().then(() => require("./bundler-B2_2-Dum.cjs"));
|
|
4120
4120
|
const allConstructs = [
|
|
4121
4121
|
...endpoints.map((e) => e.construct),
|
|
4122
4122
|
...functions.map((f) => f.construct),
|
|
@@ -5950,25 +5950,25 @@ function loadPackageJson() {
|
|
|
5950
5950
|
* Run: pnpm --filter @geekmidas/cli sync-versions
|
|
5951
5951
|
*/
|
|
5952
5952
|
const GEEKMIDAS_VERSIONS = {
|
|
5953
|
-
"@geekmidas/audit": "~10.0.0-alpha.
|
|
5954
|
-
"@geekmidas/auth": "~10.0.0-alpha.
|
|
5955
|
-
"@geekmidas/cache": "~10.0.0-alpha.
|
|
5956
|
-
"@geekmidas/client": "~10.0.0-alpha.
|
|
5957
|
-
"@geekmidas/cloud": "~10.0.0-alpha.
|
|
5958
|
-
"@geekmidas/constructs": "~10.0.0-alpha.
|
|
5959
|
-
"@geekmidas/db": "~10.0.0-alpha.
|
|
5960
|
-
"@geekmidas/emailkit": "~10.0.0-alpha.
|
|
5961
|
-
"@geekmidas/envkit": "~10.0.0-alpha.
|
|
5962
|
-
"@geekmidas/errors": "~10.0.0-alpha.
|
|
5963
|
-
"@geekmidas/events": "~10.0.0-alpha.
|
|
5964
|
-
"@geekmidas/logger": "~10.0.0-alpha.
|
|
5965
|
-
"@geekmidas/manifest": "~10.0.0-alpha.
|
|
5966
|
-
"@geekmidas/rate-limit": "~10.0.0-alpha.
|
|
5967
|
-
"@geekmidas/schema": "~10.0.0-alpha.
|
|
5968
|
-
"@geekmidas/services": "~10.0.0-alpha.
|
|
5969
|
-
"@geekmidas/storage": "~10.0.0-alpha.
|
|
5970
|
-
"@geekmidas/telescope": "~10.0.0-alpha.
|
|
5971
|
-
"@geekmidas/testkit": "~10.0.0-alpha.
|
|
5953
|
+
"@geekmidas/audit": "~10.0.0-alpha.116",
|
|
5954
|
+
"@geekmidas/auth": "~10.0.0-alpha.116",
|
|
5955
|
+
"@geekmidas/cache": "~10.0.0-alpha.116",
|
|
5956
|
+
"@geekmidas/client": "~10.0.0-alpha.116",
|
|
5957
|
+
"@geekmidas/cloud": "~10.0.0-alpha.116",
|
|
5958
|
+
"@geekmidas/constructs": "~10.0.0-alpha.116",
|
|
5959
|
+
"@geekmidas/db": "~10.0.0-alpha.116",
|
|
5960
|
+
"@geekmidas/emailkit": "~10.0.0-alpha.116",
|
|
5961
|
+
"@geekmidas/envkit": "~10.0.0-alpha.116",
|
|
5962
|
+
"@geekmidas/errors": "~10.0.0-alpha.116",
|
|
5963
|
+
"@geekmidas/events": "~10.0.0-alpha.116",
|
|
5964
|
+
"@geekmidas/logger": "~10.0.0-alpha.116",
|
|
5965
|
+
"@geekmidas/manifest": "~10.0.0-alpha.116",
|
|
5966
|
+
"@geekmidas/rate-limit": "~10.0.0-alpha.116",
|
|
5967
|
+
"@geekmidas/schema": "~10.0.0-alpha.116",
|
|
5968
|
+
"@geekmidas/services": "~10.0.0-alpha.116",
|
|
5969
|
+
"@geekmidas/storage": "~10.0.0-alpha.116",
|
|
5970
|
+
"@geekmidas/telescope": "~10.0.0-alpha.116",
|
|
5971
|
+
"@geekmidas/testkit": "~10.0.0-alpha.116",
|
|
5972
5972
|
"@geekmidas/cli": `~${loadPackageJson().version}`
|
|
5973
5973
|
};
|
|
5974
5974
|
//#endregion
|
|
@@ -7161,7 +7161,7 @@ const COMMIT = /^[0-9a-f]{40}$/;
|
|
|
7161
7161
|
* The `uses:` value for the stages action, with a comment saying which CLI
|
|
7162
7162
|
* release the pinned commit is.
|
|
7163
7163
|
*/
|
|
7164
|
-
function stagesActionUses(commit = "
|
|
7164
|
+
function stagesActionUses(commit = "8441f7be92366877d6802babf8ee655bcdde2489", version = cliVersion()) {
|
|
7165
7165
|
return commit && COMMIT.test(commit) ? `${STAGES_ACTION}@${commit} # @geekmidas/cli ${version}` : `${STAGES_ACTION}@main # pin to a commit SHA: see the action's README`;
|
|
7166
7166
|
}
|
|
7167
7167
|
//#endregion
|