Skip to content

Commit a926cc4

Browse files
committed
Ignore replacePortInApp for some web framework
1 parent c5046a9 commit a926cc4

1 file changed

Lines changed: 7 additions & 20 deletions

File tree

packages/init/src/test/port.ts

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ const ENTRY_FILES: Partial<Record<WebFramework, string>> = {
100100
elysia: "src/index.ts",
101101
};
102102

103+
const WF_READ_PORT_FROM_ENV: Set<WebFramework> = new Set([
104+
"nuxt",
105+
"nitro",
106+
"solidstart",
107+
]);
108+
103109
/**
104110
* Replace the hardcoded default port with `newPort` in the generated test
105111
* app's source files. Strategy varies by framework.
@@ -110,6 +116,7 @@ export async function replacePortInApp(
110116
defaultPort: number,
111117
newPort: number,
112118
): Promise<void> {
119+
if (WF_READ_PORT_FROM_ENV.has(wf)) return;
113120
if (defaultPort === newPort) return;
114121

115122
const entryFile = ENTRY_FILES[wf];
@@ -125,12 +132,6 @@ export async function replacePortInApp(
125132
return;
126133
}
127134

128-
if (wf === "nitro") {
129-
// Nitro reads PORT from .env
130-
await appendFile(join(dir, ".env"), `\nPORT=${newPort}\n`);
131-
return;
132-
}
133-
134135
if (wf === "astro") {
135136
// Insert server.port into the Astro config
136137
const configPath = join(dir, "astro.config.ts");
@@ -145,20 +146,6 @@ export async function replacePortInApp(
145146
return;
146147
}
147148

148-
if (wf === "nuxt") {
149-
// Insert server.port into the Nuxt config (via nitro config in nuxt.config.ts)
150-
const configPath = join(dir, "nuxt.config.ts");
151-
const content = await readFile(configPath, "utf8");
152-
await writeFile(
153-
configPath,
154-
content.replace(
155-
"defineNuxtConfig({",
156-
`defineNuxtConfig({\n nitro: { port: ${newPort} },`,
157-
),
158-
);
159-
return;
160-
}
161-
162149
printErrorMessage`Unknown framework ${wf} — cannot replace port.`;
163150
}
164151

0 commit comments

Comments
 (0)