Skip to content

Commit c0a46a6

Browse files
committed
fix: use pkg manager start command in PM2 instead of detecting entry point
PM2 ecosystem now runs `pnpm start` (or npm/yarn/bun) instead of trying to resolve a script file path. The user's start script defines how the app launches — PM2 just delegates to it.
1 parent b384148 commit c0a46a6

1 file changed

Lines changed: 5 additions & 32 deletions

File tree

src/domain/deploy/backend-strategy.ts

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { execa } from 'execa';
2-
import { readFile } from 'node:fs/promises';
32
import { pathExists } from 'fs-extra';
43
import { resolve } from 'path';
54
import type { ShipnodeConfig } from '../../shared/types.js';
@@ -76,8 +75,8 @@ export class BackendStrategy implements DeploymentStrategy {
7675
async startApp(ctx: StrategyContext): Promise<void> {
7776
if (!this.config.pm2) return;
7877

79-
const script = await this.resolveEntryPoint();
80-
const ecosystemContent = this.generateEcosystemFile(script);
78+
const pkgManager = await this.resolvePkgManager();
79+
const ecosystemContent = this.generateEcosystemFile(pkgManager);
8180
const ecosystemPath = this.config.zeroDowntime
8281
? `${this.config.remotePath}/shared/ecosystem.config.cjs`
8382
: `${ctx.workDir}/ecosystem.config.cjs`;
@@ -94,34 +93,7 @@ export class BackendStrategy implements DeploymentStrategy {
9493
);
9594
}
9695

97-
private async resolveEntryPoint(): Promise<string> {
98-
try {
99-
const raw = await readFile(resolve(this.cwd, 'package.json'), 'utf-8');
100-
const pkg = JSON.parse(raw);
101-
102-
// 1. Explicit main field
103-
if (pkg.main) return pkg.main as string;
104-
105-
// 2. Parse from start script: "node dist/index.js" → "dist/index.js"
106-
const startScript = pkg.scripts?.start as string | undefined;
107-
if (startScript) {
108-
const match = startScript.match(/node\s+([\S]+)/);
109-
if (match) return match[1];
110-
}
111-
} catch {
112-
// ignore
113-
}
114-
115-
// 3. Probe common entry points that actually exist locally
116-
const candidates = ['server.js', 'app.js', 'index.js', 'dist/index.js', 'dist/server.js', 'src/index.js'];
117-
for (const candidate of candidates) {
118-
if (await pathExists(resolve(this.cwd, candidate))) return candidate;
119-
}
120-
121-
return 'index.js';
122-
}
123-
124-
private generateEcosystemFile(script: string): string {
96+
private generateEcosystemFile(pkgManager: string): string {
12597
if (!this.config.pm2) return '';
12698

12799
const port = this.config.backend?.port ?? 3000;
@@ -132,7 +104,8 @@ export class BackendStrategy implements DeploymentStrategy {
132104
return `module.exports = {
133105
apps: [{
134106
name: '${name}',
135-
script: '${script}',
107+
script: '${pkgManager}',
108+
args: 'start',
136109
instances: ${instances},
137110
exec_mode: 'cluster',
138111
max_memory_restart: '${maxMemory}',

0 commit comments

Comments
 (0)