@flow.os/client 0.0.1-dev.1771778985 → 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 +26 -4
- package/package.json +1 -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`;
|
|
@@ -111,9 +130,12 @@ export default function config(
|
|
|
111
130
|
): () => Promise<ReturnType<typeof import('vite').defineConfig>> {
|
|
112
131
|
const { port: optPort = DEFAULTS.port, host = DEFAULTS.host, server = DEFAULTS.server, plugins = DEFAULTS.plugins } = options;
|
|
113
132
|
return async () => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
+
}
|
|
117
139
|
const { flow } = await import('./vite.js');
|
|
118
140
|
const allPlugins = [
|
|
119
141
|
flowServerUrlPlugin(host === true),
|
|
@@ -131,7 +153,7 @@ export default function config(
|
|
|
131
153
|
};
|
|
132
154
|
return {
|
|
133
155
|
resolve: Object.keys(alias).length ? { alias } : {},
|
|
134
|
-
server: { port, host, strictPort },
|
|
156
|
+
server: { port, host, strictPort: true },
|
|
135
157
|
customLogger,
|
|
136
158
|
build: {
|
|
137
159
|
rollupOptions: {
|