@flow.os/client 0.0.1-dev.1771778757 → 0.0.1-dev.1771779113
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/config.ts +28 -3
- package/package.json +1 -1
- package/start-dev.ts +23 -1
package/config.ts
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import os from 'node:os';
|
|
4
|
+
import net from 'node:net';
|
|
4
5
|
import type { Plugin } from 'vite';
|
|
5
6
|
import { createLogger } from 'vite';
|
|
6
7
|
|
|
8
|
+
function isPortFree(port: number): Promise<boolean> {
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
|
+
const s = net.createServer();
|
|
11
|
+
s.once('error', () => resolve(false));
|
|
12
|
+
s.once('listening', () => {
|
|
13
|
+
s.close(() => resolve(true));
|
|
14
|
+
});
|
|
15
|
+
s.listen(port, '127.0.0.1');
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function findFreePort(from: number, to: number): Promise<number> {
|
|
20
|
+
for (let p = from; p <= to; p++) {
|
|
21
|
+
if (await isPortFree(p)) return p;
|
|
22
|
+
}
|
|
23
|
+
throw new Error(`Nessuna porta libera tra ${from} e ${to}`);
|
|
24
|
+
}
|
|
25
|
+
|
|
7
26
|
const cyan = (s: string) => `\x1b[36m${s}\x1b[0m`;
|
|
8
27
|
const bold = (s: string) => `\x1b[1m${s}\x1b[0m`;
|
|
9
28
|
const dim = (s: string) => `\x1b[2m${s}\x1b[0m`;
|
|
@@ -109,8 +128,14 @@ function flowServerUrlPlugin(hostEnabled: boolean): Plugin {
|
|
|
109
128
|
export default function config(
|
|
110
129
|
options: FlowConfigOptions = {}
|
|
111
130
|
): () => Promise<ReturnType<typeof import('vite').defineConfig>> {
|
|
112
|
-
const { port = DEFAULTS.port, host = DEFAULTS.host, server = DEFAULTS.server, plugins = DEFAULTS.plugins } = options;
|
|
131
|
+
const { port: optPort = DEFAULTS.port, host = DEFAULTS.host, server = DEFAULTS.server, plugins = DEFAULTS.plugins } = options;
|
|
113
132
|
return async () => {
|
|
133
|
+
let port: number;
|
|
134
|
+
if (process.env.FLOW_DEV_PORT) {
|
|
135
|
+
port = parseInt(process.env.FLOW_DEV_PORT, 10);
|
|
136
|
+
} else {
|
|
137
|
+
port = await findFreePort(3000, 3020);
|
|
138
|
+
}
|
|
114
139
|
const { flow } = await import('./vite.js');
|
|
115
140
|
const allPlugins = [
|
|
116
141
|
flowServerUrlPlugin(host === true),
|
|
@@ -122,13 +147,13 @@ export default function config(
|
|
|
122
147
|
...baseLogger,
|
|
123
148
|
info: (msg: string, opts?: { clear?: boolean }) => {
|
|
124
149
|
const t = msg.replace(/\s+/g, ' ');
|
|
125
|
-
if (/VITE\s+v?\d|ready\s+in|Local:\s*http|Network:\s*http|press\s+h\s+enter/i.test(t)) return;
|
|
150
|
+
if (/VITE\s+v?\d|ready\s+in|Local:\s*http|Network:\s*http|press\s+h\s+enter|Port\s+\d+\s+is\s+in\s+use/i.test(t)) return;
|
|
126
151
|
baseLogger.info(msg, opts);
|
|
127
152
|
},
|
|
128
153
|
};
|
|
129
154
|
return {
|
|
130
155
|
resolve: Object.keys(alias).length ? { alias } : {},
|
|
131
|
-
server: { port, host, strictPort:
|
|
156
|
+
server: { port, host, strictPort: true },
|
|
132
157
|
customLogger,
|
|
133
158
|
build: {
|
|
134
159
|
rollupOptions: {
|
package/package.json
CHANGED
package/start-dev.ts
CHANGED
|
@@ -1,17 +1,39 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
/**
|
|
3
3
|
* Flow OS dev server runner. Loads flow.config.ts and starts the dev server.
|
|
4
|
-
*
|
|
4
|
+
* Trova una porta libera (3000, 3001, …) prima di avviare, così Vite non si blocca su "trying another one".
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { pathToFileURL } from 'node:url';
|
|
8
8
|
import { join } from 'node:path';
|
|
9
9
|
import { createServer } from 'vite';
|
|
10
|
+
import net from 'node:net';
|
|
10
11
|
|
|
11
12
|
const cwd = process.cwd();
|
|
12
13
|
const configPath = join(cwd, 'flow.config.ts');
|
|
13
14
|
const configUrl = pathToFileURL(configPath).href;
|
|
14
15
|
|
|
16
|
+
function isPortFree(port: number): Promise<boolean> {
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
const s = net.createServer();
|
|
19
|
+
s.once('error', () => resolve(false));
|
|
20
|
+
s.once('listening', () => {
|
|
21
|
+
s.close(() => resolve(true));
|
|
22
|
+
});
|
|
23
|
+
s.listen(port, '127.0.0.1');
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function findFreePort(from: number, to: number): Promise<number> {
|
|
28
|
+
for (let p = from; p <= to; p++) {
|
|
29
|
+
if (await isPortFree(p)) return p;
|
|
30
|
+
}
|
|
31
|
+
throw new Error(`Nessuna porta libera tra ${from} e ${to}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const port = await findFreePort(3000, 3020);
|
|
35
|
+
process.env.FLOW_DEV_PORT = String(port);
|
|
36
|
+
|
|
15
37
|
const mod = await import(configUrl).catch((e: Error) => {
|
|
16
38
|
console.error('Flow: could not load flow.config.ts:', e.message);
|
|
17
39
|
process.exit(1);
|