@geekmidas/cli 1.10.4 → 1.10.5

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.mjs CHANGED
@@ -35,7 +35,7 @@ import prompts from "prompts";
35
35
 
36
36
  //#region package.json
37
37
  var name = "@geekmidas/cli";
38
- var version = "1.10.3";
38
+ var version = "1.10.4";
39
39
  var description = "CLI tools for building Lambda handlers, server applications, and generating OpenAPI specs";
40
40
  var private$1 = false;
41
41
  var type = "module";
@@ -815,13 +815,19 @@ function rewriteUrlsWithPorts(secrets, resolvedPorts) {
815
815
  const { ports, mappings } = resolvedPorts;
816
816
  const result = { ...secrets };
817
817
  const portReplacements = [];
818
+ const serviceNames = /* @__PURE__ */ new Set();
818
819
  for (const mapping of mappings) {
820
+ serviceNames.add(mapping.service);
819
821
  const resolved = ports[mapping.envVar];
820
822
  if (resolved !== void 0) portReplacements.push({
821
823
  defaultPort: mapping.defaultPort,
822
824
  resolvedPort: resolved
823
825
  });
824
826
  }
827
+ for (const [key, value] of Object.entries(result)) {
828
+ if (!key.endsWith("_HOST")) continue;
829
+ if (serviceNames.has(value)) result[key] = "localhost";
830
+ }
825
831
  for (const [key, value] of Object.entries(result)) {
826
832
  if (!key.endsWith("_PORT")) continue;
827
833
  for (const { defaultPort, resolvedPort } of portReplacements) if (value === String(defaultPort)) result[key] = String(resolvedPort);
@@ -829,6 +835,7 @@ function rewriteUrlsWithPorts(secrets, resolvedPorts) {
829
835
  for (const [key, value] of Object.entries(result)) {
830
836
  if (!key.endsWith("_URL") && key !== "DATABASE_URL") continue;
831
837
  let rewritten = value;
838
+ for (const name$1 of serviceNames) rewritten = rewritten.replace(new RegExp(`@${name$1}:`, "g"), "@localhost:");
832
839
  for (const { defaultPort, resolvedPort } of portReplacements) rewritten = replacePortInUrl(rewritten, defaultPort, resolvedPort);
833
840
  result[key] = rewritten;
834
841
  }
@@ -2882,7 +2889,7 @@ services:
2882
2889
  environment:
2883
2890
  - NODE_ENV=production
2884
2891
  `;
2885
- if (serviceMap.has("postgres")) yaml += ` - DATABASE_URL=\${DATABASE_URL:-postgresql://postgres:postgres@postgres:5432/app}
2892
+ if (serviceMap.has("postgres")) yaml += ` - DATABASE_URL=\${DATABASE_URL:-postgresql://\${POSTGRES_USER:-postgres}:\${POSTGRES_PASSWORD:-postgres}@postgres:5432/\${POSTGRES_DB:-app}}
2886
2893
  `;
2887
2894
  if (serviceMap.has("redis")) yaml += ` - REDIS_URL=\${REDIS_URL:-redis://redis:6379}
2888
2895
  `;
@@ -2917,7 +2924,7 @@ services:
2917
2924
  volumes:
2918
2925
  - postgres_data:/var/lib/postgresql/data
2919
2926
  healthcheck:
2920
- test: ["CMD-SHELL", "pg_isready -U postgres"]
2927
+ test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER"]
2921
2928
  interval: 5s
2922
2929
  timeout: 5s
2923
2930
  retries: 5
@@ -3046,7 +3053,7 @@ services:
3046
3053
  volumes:
3047
3054
  - postgres_data:/var/lib/postgresql/data
3048
3055
  healthcheck:
3049
- test: ["CMD-SHELL", "pg_isready -U postgres"]
3056
+ test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER"]
3050
3057
  interval: 5s
3051
3058
  timeout: 5s
3052
3059
  retries: 5
@@ -3139,7 +3146,7 @@ function generateAppService(appName, app, allApps, options) {
3139
3146
  `;
3140
3147
  }
3141
3148
  if (app.type === "backend") {
3142
- if (hasPostgres) yaml += ` - DATABASE_URL=\${DATABASE_URL:-postgresql://postgres:postgres@postgres:5432/app}
3149
+ if (hasPostgres) yaml += ` - DATABASE_URL=\${DATABASE_URL:-postgresql://\${POSTGRES_USER:-postgres}:\${POSTGRES_PASSWORD:-postgres}@postgres:5432/\${POSTGRES_DB:-app}}
3143
3150
  `;
3144
3151
  if (hasRedis) yaml += ` - REDIS_URL=\${REDIS_URL:-redis://redis:6379}
3145
3152
  `;
@@ -6951,15 +6958,15 @@ function generateDockerFiles(options, template, dbApps) {
6951
6958
  container_name: ${options.name}-postgres
6952
6959
  restart: unless-stopped${envFile}
6953
6960
  environment:
6954
- POSTGRES_USER: postgres
6955
- POSTGRES_PASSWORD: postgres
6956
- POSTGRES_DB: ${options.name.replace(/-/g, "_")}_dev
6961
+ POSTGRES_USER: \${POSTGRES_USER:-postgres}
6962
+ POSTGRES_PASSWORD: \${POSTGRES_PASSWORD:-postgres}
6963
+ POSTGRES_DB: \${POSTGRES_DB:-${options.name.replace(/-/g, "_")}_dev}
6957
6964
  ports:
6958
6965
  - '\${POSTGRES_HOST_PORT:-5432}:5432'
6959
6966
  volumes:
6960
6967
  - postgres_data:/var/lib/postgresql/data${initVolume}
6961
6968
  healthcheck:
6962
- test: ['CMD-SHELL', 'pg_isready -U postgres']
6969
+ test: ['CMD-SHELL', 'pg_isready -U $$POSTGRES_USER']
6963
6970
  interval: 5s
6964
6971
  timeout: 5s
6965
6972
  retries: 5`);
@@ -11368,7 +11375,6 @@ async function testCommand(options = {}) {
11368
11375
  }
11369
11376
  }
11370
11377
  secretsEnv = rewriteDatabaseUrlForTests(secretsEnv);
11371
- await ensureTestDatabase(secretsEnv);
11372
11378
  let dependencyEnv = {};
11373
11379
  try {
11374
11380
  const appInfo = await loadWorkspaceAppInfo(cwd);
@@ -11456,34 +11462,6 @@ function rewriteDatabaseUrlForTests(env) {
11456
11462
  }
11457
11463
  return result;
11458
11464
  }
11459
- /**
11460
- * Ensure the test database exists by connecting to the default database
11461
- * and running CREATE DATABASE IF NOT EXISTS.
11462
- * @internal Exported for testing
11463
- */
11464
- async function ensureTestDatabase(env) {
11465
- const databaseUrl = env.DATABASE_URL;
11466
- if (!databaseUrl) return;
11467
- try {
11468
- const url = new URL(databaseUrl);
11469
- const testDbName = url.pathname.slice(1);
11470
- if (!testDbName) return;
11471
- url.pathname = "/postgres";
11472
- const { default: pg } = await import("pg");
11473
- const client = new pg.Client({ connectionString: url.toString() });
11474
- await client.connect();
11475
- try {
11476
- await client.query(`CREATE DATABASE "${testDbName}"`);
11477
- console.log(` 📦 Created test database "${testDbName}"`);
11478
- } catch (err) {
11479
- if (err.code !== "42P04") throw err;
11480
- } finally {
11481
- await client.end();
11482
- }
11483
- } catch (err) {
11484
- console.log(` ⚠️ Could not ensure test database: ${err.message}`);
11485
- }
11486
- }
11487
11465
 
11488
11466
  //#endregion
11489
11467
  //#region src/upgrade/index.ts