@protobase/cli 0.45.2 → 0.45.4
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/mobile/local-pins.js +64 -0
- package/dist/mobile/local-spec.js +44 -0
- package/dist/mobile/mobile-config.js +2 -1
- package/dist/mobile/package-name.js +6 -0
- package/dist/mobile/pinned-packages.js +14 -2
- package/dist/mobile/run.js +2 -1
- package/dist/mobile/workspace.js +27 -3
- package/package.json +8 -6
- package/skills/protobase/references/reference/cli.md +1 -1
package/dist/cli/package.js
CHANGED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { packageNameProblem } from "./package-name.js";
|
|
2
|
+
import { isLocalSpec, localFolder } from "./local-spec.js";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import semver from "semver";
|
|
6
|
+
//#region src/mobile/local-pins.ts
|
|
7
|
+
const readJson = (file) => {
|
|
8
|
+
if (!existsSync(file)) return void 0;
|
|
9
|
+
try {
|
|
10
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
11
|
+
} catch (error) {
|
|
12
|
+
if (error instanceof SyntaxError) return void 0;
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const rootVersion = (dir, name) => {
|
|
17
|
+
const manifest = readJson(path.join(dir, "node_modules", name, "package.json"));
|
|
18
|
+
return typeof manifest?.version === "string" ? manifest.version : void 0;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The dependencies of each local folder among the workspace `dir`'s `dependencies`, which npm hoists to the workspace's
|
|
22
|
+
* root: optional and peer ones too, as npm installs them. A folder without a readable package.json, or a dependency
|
|
23
|
+
* that is no package name, is refused before anything is removed.
|
|
24
|
+
*/
|
|
25
|
+
const localPins = (dir, dependencies) => Object.entries(dependencies).filter(([, spec]) => isLocalSpec(spec)).flatMap(([key, spec]) => {
|
|
26
|
+
const file = path.join(localFolder(dir, spec), "package.json");
|
|
27
|
+
const manifest = readJson(file);
|
|
28
|
+
if (typeof manifest !== "object" || manifest === null) throw new Error(`${key} is installed from a local folder whose package.json is missing or not JSON: ${file}`);
|
|
29
|
+
const optionalPeer = (name) => manifest.peerDependenciesMeta?.[name]?.optional === true;
|
|
30
|
+
return [
|
|
31
|
+
[manifest.dependencies, () => false],
|
|
32
|
+
[manifest.optionalDependencies, () => true],
|
|
33
|
+
[manifest.peerDependencies, optionalPeer]
|
|
34
|
+
].flatMap(([group, optional]) => Object.entries(group ?? {}).map(([name, pin]) => {
|
|
35
|
+
const problem = packageNameProblem(name, file);
|
|
36
|
+
if (problem) throw new Error(problem);
|
|
37
|
+
return {
|
|
38
|
+
key,
|
|
39
|
+
name,
|
|
40
|
+
spec: String(pin),
|
|
41
|
+
optional: optional(name),
|
|
42
|
+
installed: rootVersion(dir, name)
|
|
43
|
+
};
|
|
44
|
+
}));
|
|
45
|
+
});
|
|
46
|
+
/** Whether npm installs a version for the pin that the workspace can be checked against: a version or a range. */
|
|
47
|
+
const isCheckable = ({ spec }) => semver.validRange(spec) !== null;
|
|
48
|
+
/**
|
|
49
|
+
* Whether the workspace's root does not hold what the pin asks: a pin that is no version or range, such as a tag, git,
|
|
50
|
+
* a URL, an alias or another folder, never counts as held. An optional one that is absent is held.
|
|
51
|
+
*/
|
|
52
|
+
const isUnmet = (pin) => {
|
|
53
|
+
if (pin.installed === void 0) return !pin.optional;
|
|
54
|
+
return !isCheckable(pin) || !semver.satisfies(pin.installed, pin.spec);
|
|
55
|
+
};
|
|
56
|
+
/** Refuses a version or range pin the workspace's root still does not hold after npm installed it, naming every pin of it. */
|
|
57
|
+
const checkLocalPins = (pins) => {
|
|
58
|
+
const unmet = pins.find((pin) => isCheckable(pin) && isUnmet(pin));
|
|
59
|
+
if (!unmet) return;
|
|
60
|
+
const same = pins.filter(({ name }) => name === unmet.name).map(({ key, spec }) => `${spec} by ${key}`);
|
|
61
|
+
throw new Error(`${unmet.name} is pinned at ${same.join(" and ")}, but .protobase/mobile holds ${unmet.installed ?? "none"} at its root, where Capacitor reads it: make the pins agree`);
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
export { checkLocalPins, isCheckable, isUnmet, localPins };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
//#region src/mobile/local-spec.ts
|
|
5
|
+
const localSpec = /^(?:file:|[.]|~[/\\]|[/\\]|[a-z]:)/i;
|
|
6
|
+
/** Whether npm installs the dependency spec `spec` from this machine, copying it, rather than fetching it. */
|
|
7
|
+
const isLocalSpec = (spec) => localSpec.test(spec);
|
|
8
|
+
const isWindows = process.platform === "win32";
|
|
9
|
+
const filePath = isWindows ? path.win32 : path.posix;
|
|
10
|
+
const encoded = /* @__PURE__ */ new Map([
|
|
11
|
+
["\0", "%00"],
|
|
12
|
+
[" ", "%09"],
|
|
13
|
+
["\n", "%0A"],
|
|
14
|
+
["\r", "%0D"],
|
|
15
|
+
[" ", "%20"],
|
|
16
|
+
["\"", "%22"],
|
|
17
|
+
["#", "%23"],
|
|
18
|
+
["%", "%25"],
|
|
19
|
+
["?", "%3F"],
|
|
20
|
+
["[", "%5B"],
|
|
21
|
+
["\\", isWindows ? "/" : "%5C"],
|
|
22
|
+
["]", "%5D"],
|
|
23
|
+
["^", "%5E"],
|
|
24
|
+
["|", "%7C"],
|
|
25
|
+
["~", "%7E"]
|
|
26
|
+
]);
|
|
27
|
+
/**
|
|
28
|
+
* The folder npm installs the local spec `spec` from, listed in the package.json in `where`: npm-package-arg's
|
|
29
|
+
* fromFile, so a relative path is read against `where` and `~/` against the home folder, as npm reads them.
|
|
30
|
+
*/
|
|
31
|
+
const localFolder = (where, spec, home = homedir()) => {
|
|
32
|
+
let raw = [...spec].map((char) => encoded.get(char) ?? char).join("");
|
|
33
|
+
if (!raw.startsWith("file:")) raw = `file:${raw}`;
|
|
34
|
+
if (/^file:\/\/[^/]/.test(raw)) raw = `file:/${raw.slice(5)}`;
|
|
35
|
+
if (/^\/{1,3}\.\.?(\/|$)/.test(raw.slice(5))) raw = raw.replace(/^file:\/{1,3}/, "file:");
|
|
36
|
+
const resolved = new URL(raw, `${pathToFileURL(filePath.resolve(where))}/`);
|
|
37
|
+
const strip = (pathname) => isWindows ? pathname.replace(/^\/+([a-z]:\/)/i, "$1") : pathname;
|
|
38
|
+
const specPath = strip(decodeURIComponent(new URL(raw).pathname));
|
|
39
|
+
const resolvedPath = strip(decodeURIComponent(resolved.pathname));
|
|
40
|
+
if (/^\/~(\/|$)/.test(specPath)) return filePath.resolve(home, specPath.slice(3));
|
|
41
|
+
return filePath.resolve(where, resolvedPath);
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
export { isLocalSpec, localFolder };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { pinnedProblem } from "./pinned-packages.js";
|
|
2
|
+
import { packageNameProblem } from "./package-name.js";
|
|
2
3
|
//#region src/mobile/mobile-config.ts
|
|
3
4
|
const noMobileSection = "This project has no mobile section: add `mobile: { appId: 'com.example.app' }` to the default export of protobase.config.ts";
|
|
4
5
|
const appIdPattern = /^[a-zA-Z][\w]*(?:\.[a-zA-Z][\w]*)+$/;
|
|
@@ -13,7 +14,7 @@ const checkMobileConfig = (value) => {
|
|
|
13
14
|
if (plugins === void 0) return { appId };
|
|
14
15
|
if (!isRecord(plugins) || Object.values(plugins).some((spec) => typeof spec !== "string")) throw new Error("mobile.plugins must map each plugin's npm name to a version range, such as { '@capacitor/camera': '^8.0.0' }");
|
|
15
16
|
for (const [name, spec] of Object.entries(plugins)) {
|
|
16
|
-
const problem = pinnedProblem(name);
|
|
17
|
+
const problem = packageNameProblem(name) ?? pinnedProblem(name);
|
|
17
18
|
if (problem) throw new Error(problem);
|
|
18
19
|
if (unauthenticated.test(spec)) throw new Error(`mobile.plugins installs ${name} from ${spec}, over a connection that is not secure: use a version range, https or git+https`);
|
|
19
20
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region src/mobile/package-name.ts
|
|
2
|
+
const packageName = /^(?:@[a-z0-9~-][\w.~-]*\/)?[a-z0-9~-][\w.~-]*$/i;
|
|
3
|
+
/** Why `name`, listed as a dependency in `where`, is no npm package name; `undefined` when it is one. */
|
|
4
|
+
const packageNameProblem = (name, where = "mobile.plugins") => packageName.test(name) ? void 0 : `${where} lists ${JSON.stringify(name)}, which is not an npm package name such as my-plugin or @scope/my-plugin`;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { packageNameProblem };
|
|
@@ -7,6 +7,8 @@ import { installedPackage } from "./installed-package.js";
|
|
|
7
7
|
* @protobase/mobile of its own version, the one it installs.
|
|
8
8
|
*/
|
|
9
9
|
const pinnedPackages = /* @__PURE__ */ new Set([name, ...Object.keys(dependencies)]);
|
|
10
|
+
/** The native packages @protobase/mobile pins, name → version. */
|
|
11
|
+
const nativeDependencies = Object.fromEntries(Object.entries(dependencies).filter(([name]) => !name.startsWith("@protobase/")));
|
|
10
12
|
/**
|
|
11
13
|
* The native code an app's binary carries from @protobase/mobile, name → version, which a native fingerprint names:
|
|
12
14
|
* the native packages it pins, at their versions, and its own native code by its `nativeContract`, `native-<n>`. Never
|
|
@@ -14,7 +16,7 @@ const pinnedPackages = /* @__PURE__ */ new Set([name, ...Object.keys(dependencie
|
|
|
14
16
|
* `nativeContract` whenever its Android (later iOS) sources change; its test fails until it is.
|
|
15
17
|
*/
|
|
16
18
|
const pinnedNative = {
|
|
17
|
-
...
|
|
19
|
+
...nativeDependencies,
|
|
18
20
|
[name]: `native-${nativeContract}`
|
|
19
21
|
};
|
|
20
22
|
const liveUpdate = "@capawesome/capacitor-live-update";
|
|
@@ -33,5 +35,15 @@ const checkInstalledPlugins = (dir, keys) => {
|
|
|
33
35
|
if (problem) throw new Error(problem);
|
|
34
36
|
}
|
|
35
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* Checks that the native packages installed in the workspace `dir` are the versions @protobase/mobile pins, which the
|
|
40
|
+
* native fingerprint names, whatever npm left in the workspace, so a binary never names native code it does not hold.
|
|
41
|
+
*/
|
|
42
|
+
const checkPinnedNative = (dir, pinned = nativeDependencies) => {
|
|
43
|
+
for (const [name, version] of Object.entries(pinned)) {
|
|
44
|
+
const installed = installedPackage(dir, name).version;
|
|
45
|
+
if (installed !== version) throw new Error(`${name} is ${installed}, not ${version}: delete .protobase/mobile and run the command again`);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
36
48
|
//#endregion
|
|
37
|
-
export { checkInstalledPlugins, pinnedNative, pinnedPackages, pinnedProblem };
|
|
49
|
+
export { checkInstalledPlugins, checkPinnedNative, nativeDependencies, pinnedNative, pinnedPackages, pinnedProblem };
|
package/dist/mobile/run.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { checkInstalledPlugins, pinnedNative } from "./pinned-packages.js";
|
|
1
|
+
import { checkInstalledPlugins, checkPinnedNative, pinnedNative } from "./pinned-packages.js";
|
|
2
2
|
import { nativeFingerprint } from "./fingerprint.js";
|
|
3
3
|
import { withoutAndroidSigning } from "./android-signing.js";
|
|
4
4
|
import { runChild } from "./child-process.js";
|
|
@@ -35,6 +35,7 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
|
|
|
35
35
|
env
|
|
36
36
|
}));
|
|
37
37
|
checkInstalledPlugins(ws, plugins);
|
|
38
|
+
checkPinnedNative(ws);
|
|
38
39
|
if (live === void 0) await buildWebPart({
|
|
39
40
|
projectDir,
|
|
40
41
|
ws,
|
package/dist/mobile/workspace.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { protobaseVersion } from "../version/version.js";
|
|
2
2
|
import { protobaseFolder } from "../project/protobase-folder.js";
|
|
3
|
+
import { packageNameProblem } from "./package-name.js";
|
|
4
|
+
import { isLocalSpec } from "./local-spec.js";
|
|
5
|
+
import { checkLocalPins, isUnmet, localPins } from "./local-pins.js";
|
|
3
6
|
import { existsSync } from "node:fs";
|
|
4
7
|
import path from "node:path";
|
|
5
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
8
|
+
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
6
9
|
import { fileURLToPath } from "node:url";
|
|
7
10
|
//#region src/mobile/workspace.ts
|
|
8
11
|
/** Where the mobile build lives in a project: npm's install of @protobase/mobile, the app's files and native projects. */
|
|
@@ -18,17 +21,37 @@ const workspacePackageJson = ({ mobileSpec, plugins = {} }) => ({
|
|
|
18
21
|
...plugins
|
|
19
22
|
}
|
|
20
23
|
});
|
|
24
|
+
const insideModules = (dir, name) => {
|
|
25
|
+
const problem = packageNameProblem(name);
|
|
26
|
+
if (problem) throw new Error(problem);
|
|
27
|
+
return path.join(dir, "node_modules", name);
|
|
28
|
+
};
|
|
21
29
|
/**
|
|
22
30
|
* Writes the workspace in `dir`, ignored by git, and installs its packages with npm when its package.json changed or
|
|
23
|
-
* one of them is missing, as after an install that failed. `--install-links` copies a `file:`
|
|
24
|
-
* dependencies at the workspace's root, where Capacitor looks for them.
|
|
31
|
+
* one of them is missing, as after an install that failed. `--install-links` copies a local folder, `file:` or a bare
|
|
32
|
+
* path, and puts its dependencies at the workspace's root, where Capacitor looks for them. npm keeps that copy while
|
|
33
|
+
* its spec is unchanged, however the folder changed, so the copy is removed on each run and npm copies it again. npm
|
|
34
|
+
* also keeps the root's versions its lock names, so when a folder's pins are not what the root holds, node_modules
|
|
35
|
+
* and the lock are removed and npm resolves the whole tree again.
|
|
25
36
|
*/
|
|
26
37
|
const prepareWorkspace = async (dir, packageJson, run) => {
|
|
38
|
+
const copies = Object.entries(packageJson.dependencies).filter(([, spec]) => isLocalSpec(spec)).map(([name]) => insideModules(dir, name));
|
|
27
39
|
await mkdir(dir, { recursive: true });
|
|
28
40
|
await writeFile(path.join(dir, ".gitignore"), "*\n");
|
|
29
41
|
const file = path.join(dir, "package.json");
|
|
30
42
|
const content = `${JSON.stringify(packageJson, null, 2)}\n`;
|
|
31
43
|
const changed = !existsSync(file) || await readFile(file, "utf8") !== content;
|
|
44
|
+
if (localPins(dir, packageJson.dependencies).some(isUnmet)) {
|
|
45
|
+
await rm(path.join(dir, "node_modules"), {
|
|
46
|
+
recursive: true,
|
|
47
|
+
force: true
|
|
48
|
+
});
|
|
49
|
+
await rm(path.join(dir, "package-lock.json"), { force: true });
|
|
50
|
+
}
|
|
51
|
+
for (const copy of copies) await rm(copy, {
|
|
52
|
+
recursive: true,
|
|
53
|
+
force: true
|
|
54
|
+
});
|
|
32
55
|
const missing = Object.keys(packageJson.dependencies).some((name) => !existsSync(path.join(dir, "node_modules", name, "package.json")));
|
|
33
56
|
if (changed) await writeFile(file, content);
|
|
34
57
|
if (changed || missing) await run("npm", [
|
|
@@ -37,6 +60,7 @@ const prepareWorkspace = async (dir, packageJson, run) => {
|
|
|
37
60
|
"--no-audit",
|
|
38
61
|
"--no-fund"
|
|
39
62
|
]);
|
|
63
|
+
checkLocalPins(localPins(dir, packageJson.dependencies));
|
|
40
64
|
};
|
|
41
65
|
//#endregion
|
|
42
66
|
export { mobileSpec, prepareWorkspace, workspaceDir, workspacePackageJson };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.45.
|
|
3
|
+
"version": "0.45.4",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"@better-auth/core": "^1.7.12",
|
|
37
37
|
"@hono/node-server": "^2.1.3",
|
|
38
38
|
"@hono/vite-dev-server": "^0.26.1",
|
|
39
|
-
"@protobase/layout": "0.45.
|
|
40
|
-
"@protobase/query": "0.45.
|
|
41
|
-
"@protobase/schema": "0.45.
|
|
42
|
-
"@protobase/server": "0.45.
|
|
43
|
-
"@protobase/ui": "0.45.
|
|
39
|
+
"@protobase/layout": "0.45.4",
|
|
40
|
+
"@protobase/query": "0.45.4",
|
|
41
|
+
"@protobase/schema": "0.45.4",
|
|
42
|
+
"@protobase/server": "0.45.4",
|
|
43
|
+
"@protobase/ui": "0.45.4",
|
|
44
44
|
"@react-email/render": "^2.1.0",
|
|
45
45
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
46
46
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"postcss": "^8.5.29",
|
|
58
58
|
"postgres": "^3.4.9",
|
|
59
59
|
"react": "^19.3.0",
|
|
60
|
+
"semver": "^7.8.5",
|
|
60
61
|
"ts-morph": "^28.0.0",
|
|
61
62
|
"vite": "^8.3.3",
|
|
62
63
|
"ws": "^8.22.0",
|
|
@@ -65,6 +66,7 @@
|
|
|
65
66
|
"devDependencies": {
|
|
66
67
|
"@supabase/server": "^1.9.2",
|
|
67
68
|
"@supabase/supabase-js": "^2.118.0",
|
|
69
|
+
"@types/semver": "^7.8.0",
|
|
68
70
|
"@types/ws": "^8.18.2",
|
|
69
71
|
"stripe": "^22.6.2",
|
|
70
72
|
"tsx": "^4.23.15"
|
|
@@ -545,7 +545,7 @@ protobase mobile build <ios|android> --app-version <x.y.z> --build-number <n> [-
|
|
|
545
545
|
|
|
546
546
|
Builds the project in the current directory as an iOS or Android app with Capacitor, from the `mobile` section of its `protobase.config.ts`; without one it stops and says what to add. See [A mobile app](../guides/mobile-app.md).
|
|
547
547
|
|
|
548
|
-
- It installs `@protobase/mobile`, of the CLI's version, which pins Capacitor and its plugins, with the section's `plugins` into `.protobase/mobile/` with npm, when that changed. It builds the app's files as [`build`](#build) does and keeps only `public/`, its `index.html` naming the API origin; writes `capacitor.config.json`, compiling in only the section's plugins; and generates the platform's native project again, replacing the last one.
|
|
548
|
+
- It installs `@protobase/mobile`, of the CLI's version, which pins Capacitor and its plugins, with the section's `plugins` into `.protobase/mobile/` with npm, when that changed, and on every run for a package from a local folder, given as `file:` or a path such as `../my-plugin`, which npm copies. When such a folder's dependencies are not the versions installed, it removes the workspace's `node_modules` and `package-lock.json` so npm resolves them again, and stops when a pin is still not met, as when two packages pin one dependency at different versions. It builds the app's files as [`build`](#build) does and keeps only `public/`, its `index.html` naming the API origin; writes `capacitor.config.json`, compiling in only the section's plugins; and generates the platform's native project again, replacing the last one.
|
|
549
549
|
- `--api` is the server the app calls, the project's auth `baseURL` by default: an http or https origin, plain http only to `localhost`, `127.0.0.1` and, on iOS, `[::1]`, or on Android `10.0.2.2`. An Android app calling `localhost` gets the port forwarded.
|
|
550
550
|
- `run` runs the app on `--target`, or asks for one. On iOS, `--team` writes the Apple team id into the generated project and builds it once with xcodebuild allowed to create the development profile and register the device, `--target` or the one connected device, before Capacitor runs it there. With `--live` it opens `protobase dev` on `localhost:--port` instead of its own files. `open` opens the native project in Xcode or Android Studio.
|
|
551
551
|
- `build` makes a signed release, an `.aab` (Android) or `.ipa` (iOS), and copies it to `--out`, which ignores itself in git when the command creates it, as `<appId>-<version>-<build number>`. Android signs through Gradle with the keystore, alias and passwords in `PROTOBASE_ANDROID_KEYSTORE`, `PROTOBASE_ANDROID_KEY_ALIAS`, `PROTOBASE_ANDROID_KEYSTORE_PASSWORD` and `PROTOBASE_ANDROID_KEY_PASSWORD`; iOS runs Capacitor's build with `--team`, and `--certificate` with `--profile` for manual signing.
|