Skip to content

fix: preserve an existing non-PortOS ecosystem.config.cjs during PM2 standardization#2087

Merged
atomantic merged 2 commits into
mainfrom
fix/standardizer-preserve-existing-ecosystem
Jul 4, 2026
Merged

fix: preserve an existing non-PortOS ecosystem.config.cjs during PM2 standardization#2087
atomantic merged 2 commits into
mainfrom
fix/standardizer-preserve-existing-ecosystem

Conversation

@atomantic

Copy link
Copy Markdown
Owner

Problem

Running PM2 standardization on an app unconditionally overwrote ecosystem.config.cjs. If the app already had a hand-authored PM2 config, standardizing silently replaced it — losing its custom ports and settings. (Hit in practice: a work app's carefully-tuned local-dev config, with non-default ports wired into its scripts, README, and OIDC callback, got clobbered by the standardizer's generic template.)

Fix

Make the standardizer respect an existing config it didn't create:

  • Preserve by default. If ecosystem.config.cjs exists and does not carry PortOS's generated-header marker (i.e. it's user-authored or another tool's), it is left untouched. Only a file PortOS previously generated (marker present) is regenerated — the normal re-standardize flow still works.
  • Don't strip its ports either. When the config is preserved, the coupled .env / vite.config stray-port removal is skipped — pulling ports out of those only makes sense once PortOS's generated ecosystem owns them.
  • Explicit opt-in to overwrite. A new overwriteEcosystem flag forces regeneration of a user-authored config. Exposed on the /api/standardize/apply request body and both standardize:start / app:standardize socket events (validated, optional, default false).
  • Fails safe. Provenance is re-read from disk at apply time (not trusted from the stale analyze plan); if the file exists but can't be read, it's preserved rather than clobbered.
  • Detection reuses a single PORTOS_ECOSYSTEM_MARKER constant that also stamps generated output, so the stamp and the check can't drift. Results now report filesPreserved alongside filesModified, surfaced through the flow + socket events.

Tests

  • New real-FS applyStandardization cases (temp dirs): preserves a user-authored config by default; regenerates a PortOS-generated one; overwrites when overwriteEcosystem: true; writes fresh when none exists; leaves .env stray ports alone when preserving but still strips them when regenerating.
  • Updated / added runStandardizeFlow cases for the opt-in forwarding and the filesPreserved passthrough.
  • Full server suite green (789 files, 15,769 tests).

Changelog

Added a ## Fixed entry to .changelog/NEXT.md.

atomantic added 2 commits July 3, 2026 13:45
…dization

Standardizing an app unconditionally overwrote ecosystem.config.cjs, silently
destroying a hand-authored config (its custom ports/settings). Now a config
PortOS didn't generate — detected via the header marker — is preserved by
default, and its ports are left untouched in .env/vite; only PortOS's own
previously-generated config is regenerated. Add an explicit overwriteEcosystem
opt-in (apply-route body + both standardize socket events) to force a rewrite.
…erve-existing-ecosystem

# Conflicts:
#	.changelog/NEXT.md
@atomantic atomantic merged commit 9a7f6e8 into main Jul 4, 2026
2 checks passed
@atomantic atomantic deleted the fix/standardizer-preserve-existing-ecosystem branch July 4, 2026 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant