openmagic 0.31.6 → 0.31.7
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/cli.js +30 -1
- package/dist/cli.js.map +1 -1
- package/dist/toolbar/index.global.js +1 -1
- package/dist/toolbar/index.global.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1968,6 +1968,16 @@ async function detectDevServer(cwd = process.cwd()) {
|
|
|
1968
1968
|
async function isPortOpen(port) {
|
|
1969
1969
|
return checkPort(port);
|
|
1970
1970
|
}
|
|
1971
|
+
async function findAvailablePort(startPort) {
|
|
1972
|
+
let port = startPort;
|
|
1973
|
+
while (await isPortOpen(port)) {
|
|
1974
|
+
port++;
|
|
1975
|
+
if (port > startPort + 100) {
|
|
1976
|
+
throw new Error(`Could not find an available port near ${startPort}`);
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
return port;
|
|
1980
|
+
}
|
|
1971
1981
|
var FRAMEWORK_PATTERNS = [
|
|
1972
1982
|
{ match: /\bnext\b/, framework: "Next.js", defaultPort: 3e3 },
|
|
1973
1983
|
{ match: /\bvite\b/, framework: "Vite", defaultPort: 5173 },
|
|
@@ -2442,7 +2452,24 @@ async function offerToStartDevServer(expectedPort) {
|
|
|
2442
2452
|
chosen = scripts[idx];
|
|
2443
2453
|
}
|
|
2444
2454
|
}
|
|
2445
|
-
|
|
2455
|
+
let port = expectedPort || chosen.defaultPort;
|
|
2456
|
+
if (await isPortOpen(port)) {
|
|
2457
|
+
const owned = verifyPortOwnership(port, process.cwd());
|
|
2458
|
+
if (owned === true) {
|
|
2459
|
+
console.log(chalk.green(` \u2713 Dev server already running on port ${port}`));
|
|
2460
|
+
lastDetectedPort = port;
|
|
2461
|
+
return true;
|
|
2462
|
+
}
|
|
2463
|
+
const altPort = await findAvailablePort(port + 1);
|
|
2464
|
+
console.log("");
|
|
2465
|
+
console.log(
|
|
2466
|
+
chalk.yellow(` \u26A0 Port ${port} is already in use by another process.`)
|
|
2467
|
+
);
|
|
2468
|
+
console.log(
|
|
2469
|
+
chalk.dim(` Starting on port ${altPort} instead.`)
|
|
2470
|
+
);
|
|
2471
|
+
port = altPort;
|
|
2472
|
+
}
|
|
2446
2473
|
console.log("");
|
|
2447
2474
|
console.log(
|
|
2448
2475
|
chalk.dim(` Starting `) + chalk.cyan(`npm run ${chosen.name}`) + chalk.dim("...")
|
|
@@ -2580,6 +2607,8 @@ async function offerToStartDevServer(expectedPort) {
|
|
|
2580
2607
|
for (const scanPort of [3e3, 3001, 5173, 5174, 4200, 8080, 8e3, 4e3, 1234, 4321, 3333, 8081]) {
|
|
2581
2608
|
if (scanPort === port) continue;
|
|
2582
2609
|
if (await isPortOpen(scanPort)) {
|
|
2610
|
+
const owned = verifyPortOwnership(scanPort, process.cwd());
|
|
2611
|
+
if (owned === false) continue;
|
|
2583
2612
|
console.log(
|
|
2584
2613
|
chalk.green(` \u2713 Dev server found on port ${scanPort}.`)
|
|
2585
2614
|
);
|