@protobase/cli 0.133.10 → 0.133.11
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/package.js +1 -1
- package/dist/dev/dev-port.js +31 -7
- package/package.json +8 -8
package/dist/cli/package.js
CHANGED
package/dist/dev/dev-port.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { protobaseFolder } from "../project/protobase-folder.js";
|
|
2
2
|
import { heldOn } from "./loopback.js";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { link, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
5
6
|
//#region src/dev/dev-port.ts
|
|
6
7
|
/** Where `protobase dev` keeps the project's port: `.protobase/` is this machine's and ignores itself in git. */
|
|
7
8
|
const devPortFile = path.join(protobaseFolder, "dev-port");
|
|
@@ -24,10 +25,35 @@ const readSavedPort = async (projectDir) => {
|
|
|
24
25
|
const port = Number(trimmed);
|
|
25
26
|
return port >= 1 && port <= 65535 ? port : void 0;
|
|
26
27
|
};
|
|
28
|
+
const writeTemporary = async (projectDir, port) => {
|
|
29
|
+
await mkdir(path.join(projectDir, protobaseFolder), { recursive: true });
|
|
30
|
+
const temporary = path.join(projectDir, `${devPortFile}.${randomUUID()}.tmp`);
|
|
31
|
+
await writeFile(temporary, `${port}\n`);
|
|
32
|
+
return temporary;
|
|
33
|
+
};
|
|
27
34
|
const savePort = async (projectDir, port) => {
|
|
28
35
|
if (await readSavedPort(projectDir) === port) return;
|
|
29
|
-
await
|
|
30
|
-
await
|
|
36
|
+
const temporary = await writeTemporary(projectDir, port);
|
|
37
|
+
await rename(temporary, path.join(projectDir, devPortFile));
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Saves `port` only when no port file exists yet, and returns the project's port: `port`, or the one another run
|
|
41
|
+
* published first. Linking fails when the file exists, so of two first runs started together only one publishes.
|
|
42
|
+
*/
|
|
43
|
+
const publishPort = async (projectDir, port) => {
|
|
44
|
+
const temporary = await writeTemporary(projectDir, port);
|
|
45
|
+
try {
|
|
46
|
+
await link(temporary, path.join(projectDir, devPortFile));
|
|
47
|
+
return port;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (error.code !== "EEXIST") throw error;
|
|
50
|
+
} finally {
|
|
51
|
+
await unlink(temporary);
|
|
52
|
+
}
|
|
53
|
+
const saved = await readSavedPort(projectDir);
|
|
54
|
+
if (saved !== void 0) return saved;
|
|
55
|
+
await savePort(projectDir, port);
|
|
56
|
+
return port;
|
|
31
57
|
};
|
|
32
58
|
/** A random port in `randomPorts` that no process holds on either loopback address, trying a fixed number of them. */
|
|
33
59
|
const pickFreePort = async (held = heldOn, random = Math.random) => {
|
|
@@ -50,9 +76,7 @@ const devPort = async (projectDir, chosen, pick = pickFreePort) => {
|
|
|
50
76
|
}
|
|
51
77
|
const saved = await readSavedPort(projectDir);
|
|
52
78
|
if (saved !== void 0) return saved;
|
|
53
|
-
|
|
54
|
-
await savePort(projectDir, picked);
|
|
55
|
-
return picked;
|
|
79
|
+
return publishPort(projectDir, await pick());
|
|
56
80
|
};
|
|
57
81
|
//#endregion
|
|
58
|
-
export { devAddress, devPort, devPortFile, pickFreePort, randomPorts, readSavedPort, savePort };
|
|
82
|
+
export { devAddress, devPort, devPortFile, pickFreePort, publishPort, randomPorts, readSavedPort, savePort };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.133.
|
|
3
|
+
"version": "0.133.11",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@better-auth/core": "^1.7.12",
|
|
45
45
|
"@hono/node-server": "^2.1.3",
|
|
46
|
-
"@protobase/config": "0.133.
|
|
47
|
-
"@protobase/layout": "0.133.
|
|
48
|
-
"@protobase/query": "0.133.
|
|
49
|
-
"@protobase/schema": "0.133.
|
|
50
|
-
"@protobase/server": "0.133.
|
|
51
|
-
"@protobase/ui": "0.133.
|
|
52
|
-
"@protobase/workflows": "0.133.
|
|
46
|
+
"@protobase/config": "0.133.11",
|
|
47
|
+
"@protobase/layout": "0.133.11",
|
|
48
|
+
"@protobase/query": "0.133.11",
|
|
49
|
+
"@protobase/schema": "0.133.11",
|
|
50
|
+
"@protobase/server": "0.133.11",
|
|
51
|
+
"@protobase/ui": "0.133.11",
|
|
52
|
+
"@protobase/workflows": "0.133.11",
|
|
53
53
|
"@react-email/render": "^2.1.0",
|
|
54
54
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
55
55
|
"@sentry/vite-plugin": "^11.10.0",
|