@nmakarov/cli-toolkit 0.57.0 → 0.59.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/dist/index.js CHANGED
@@ -3545,6 +3545,12 @@ var Db = class _Db {
3545
3545
  }
3546
3546
  if (!dbConnectionString) {
3547
3547
  if (!dbName) {
3548
+ const env = context?.args?.env;
3549
+ if (env && String(env).toLowerCase() !== "local") {
3550
+ throw new ParamError(
3551
+ `Db: dbName not set for env="${env}" (set --dbName or DB_NAME_${String(env).toUpperCase()})`
3552
+ );
3553
+ }
3548
3554
  dbName = "local";
3549
3555
  }
3550
3556
  const paramName = `dbConnectionString${capitalizeFirstLetter(dbName)}`;
@@ -5664,7 +5670,10 @@ async function reloadPm2(paths, options = {}) {
5664
5670
  logger.info(`pm2 ${appName}: reloading (old pid=${oldPid})`);
5665
5671
  }
5666
5672
  }
5667
- await runShell(`pm2 startOrReload "${paths.ecosystem}" --update-env`, { logger });
5673
+ await runShell(
5674
+ `ENV=production NODE_ENV=production pm2 startOrReload "${paths.ecosystem}" --update-env`,
5675
+ { logger }
5676
+ );
5668
5677
  logger.info("pm2 reloaded");
5669
5678
  if (appName) {
5670
5679
  const proc = await waitPm2(
@@ -5713,7 +5722,10 @@ async function startPm2(paths, options = {}) {
5713
5722
  logger.info(`[dryRun] would pm2 start ${paths.ecosystem} --update-env`);
5714
5723
  return;
5715
5724
  }
5716
- await runShell(`pm2 start "${paths.ecosystem}" --update-env`, { logger });
5725
+ await runShell(
5726
+ `ENV=production NODE_ENV=production pm2 start "${paths.ecosystem}" --update-env`,
5727
+ { logger }
5728
+ );
5717
5729
  logger.info("pm2 started");
5718
5730
  if (appName) {
5719
5731
  const proc = await waitPm2(
@@ -5968,11 +5980,12 @@ function resolvePm2Args(pm2) {
5968
5980
  function buildEnsureEnvScript() {
5969
5981
  return `/**
5970
5982
  * Written by cli-toolkit deploy (init-structure). Do not hand-edit.
5971
- * Preloaded via pm2 node_args --require so Args sees ENV=production even when
5972
- * a post-SIGKILL restart briefly omits ecosystem env (otherwise Db \u2192 local:6032).
5983
+ * Preloaded via pm2 node_args --require. Always set (do not only fill when unset):
5984
+ * \`pm2 startOrReload --update-env\` can inject a non-production ENV from the
5985
+ * deploy shell / prior dump, and a conditional assign would leave it in place.
5973
5986
  */
5974
- if (!process.env.ENV) process.env.ENV = "production";
5975
- if (!process.env.NODE_ENV) process.env.NODE_ENV = "production";
5987
+ process.env.ENV = "production";
5988
+ process.env.NODE_ENV = "production";
5976
5989
  `;
5977
5990
  }
5978
5991
  function buildEcosystemConfig(service, paths) {