@flow.os/client 0.0.1-dev.1771777625 → 0.0.1-dev.1771778985

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 CHANGED
@@ -109,8 +109,11 @@ function flowServerUrlPlugin(hostEnabled: boolean): Plugin {
109
109
  export default function config(
110
110
  options: FlowConfigOptions = {}
111
111
  ): () => Promise<ReturnType<typeof import('vite').defineConfig>> {
112
- const { port = DEFAULTS.port, host = DEFAULTS.host, server = DEFAULTS.server, plugins = DEFAULTS.plugins } = options;
112
+ const { port: optPort = DEFAULTS.port, host = DEFAULTS.host, server = DEFAULTS.server, plugins = DEFAULTS.plugins } = options;
113
113
  return async () => {
114
+ const envPort = process.env.FLOW_DEV_PORT;
115
+ const port = envPort ? parseInt(envPort, 10) : optPort;
116
+ const strictPort = !!envPort;
114
117
  const { flow } = await import('./vite.js');
115
118
  const allPlugins = [
116
119
  flowServerUrlPlugin(host === true),
@@ -122,13 +125,13 @@ export default function config(
122
125
  ...baseLogger,
123
126
  info: (msg: string, opts?: { clear?: boolean }) => {
124
127
  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;
128
+ 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
129
  baseLogger.info(msg, opts);
127
130
  },
128
131
  };
129
132
  return {
130
133
  resolve: Object.keys(alias).length ? { alias } : {},
131
- server: { port, host, strictPort: false },
134
+ server: { port, host, strictPort },
132
135
  customLogger,
133
136
  build: {
134
137
  rollupOptions: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flow.os/client",
3
- "version": "0.0.1-dev.1771777625",
3
+ "version": "0.0.1-dev.1771778985",
4
4
  "license": "PolyForm-Shield-1.0.0",
5
5
  "type": "module",
6
6
  "main": "./index.ts",
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
- * Usage: bun node_modules/@flow.os/client/start-dev.ts (or bun packages/client/start-dev.ts in monorepo)
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);