@uibro/cli 0.1.1 → 0.1.2
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/package.json +2 -2
- package/src/host-controller.js +1 -6
- package/src/project-install.js +14 -9
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uibro/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"uibro": "bin/uibro.js"
|
|
7
7
|
},
|
|
8
8
|
"files": ["bin", "src"],
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@uibro/bridge": "0.1.
|
|
10
|
+
"@uibro/bridge": "0.1.1"
|
|
11
11
|
},
|
|
12
12
|
"engines": {
|
|
13
13
|
"node": ">=22"
|
package/src/host-controller.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { projectIdentity } from "./identity.js";
|
|
2
2
|
|
|
3
3
|
async function loadBridgeRuntime() {
|
|
4
|
-
|
|
5
|
-
return (await import("@uibro/bridge/src/bridge-runtime.js")).createBridgeRuntime;
|
|
6
|
-
} catch (error) {
|
|
7
|
-
if (error?.code !== "ERR_MODULE_NOT_FOUND") throw error;
|
|
8
|
-
return (await import("../../../apps/bridge/src/bridge-runtime.js")).createBridgeRuntime;
|
|
9
|
-
}
|
|
4
|
+
return (await import("@uibro/bridge/runtime")).createBridgeRuntime;
|
|
10
5
|
}
|
|
11
6
|
|
|
12
7
|
export class HostController {
|
package/src/project-install.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
-
import {
|
|
2
|
+
import { readFile, realpath } from "node:fs/promises";
|
|
3
3
|
import { dirname, join, relative } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
|
|
@@ -33,23 +33,28 @@ function isInside(workspace, path) {
|
|
|
33
33
|
return child === "" || (!child.startsWith("..") && !child.startsWith("/"));
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
async function installedHostPath(workspace, expectedVersion) {
|
|
37
|
+
const root = join(workspace, "node_modules", "@uibro", "cli");
|
|
38
|
+
const pkg = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
|
|
39
|
+
if (pkg.version !== expectedVersion) throw new Error("Installed CLI version is stale.");
|
|
40
|
+
const path = await realpath(join(root, "bin", "uibro-project-host.js"));
|
|
41
|
+
if (!isInside(workspace, path)) throw new Error("Installed project host escaped the workspace.");
|
|
42
|
+
return path;
|
|
43
|
+
}
|
|
44
|
+
|
|
36
45
|
export async function ensureProjectHostBinary(workspace, { install = runNpmInstall } = {}) {
|
|
37
46
|
const target = await realpath(workspace);
|
|
38
|
-
const
|
|
47
|
+
const version = await packageVersion();
|
|
39
48
|
try {
|
|
40
|
-
await
|
|
41
|
-
const path = await realpath(installed);
|
|
42
|
-
if (isInside(target, path)) return path;
|
|
49
|
+
return await installedHostPath(target, version);
|
|
43
50
|
} catch {}
|
|
44
51
|
if (isInside(target, sourcePackageRoot)) {
|
|
45
52
|
return realpath(join(sourcePackageRoot, "bin", "uibro-project-host.js"));
|
|
46
53
|
}
|
|
47
|
-
const spec = `@uibro/cli@${
|
|
54
|
+
const spec = `@uibro/cli@${version}`;
|
|
48
55
|
await install(target, spec);
|
|
49
56
|
try {
|
|
50
|
-
|
|
51
|
-
if (!isInside(target, path)) throw new Error("Installed project host escaped the workspace.");
|
|
52
|
-
return path;
|
|
57
|
+
return await installedHostPath(target, version);
|
|
53
58
|
} catch (error) {
|
|
54
59
|
throw new Error("@uibro/cli was not installed inside the target project.", { cause: error });
|
|
55
60
|
}
|