@tauri-cordis/cli 0.1.0 → 0.2.0
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 +5 -5
- package/src/bundle.mjs +4 -2
- package/src/check.mjs +97 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tauri-cordis/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "CLI toolkit (build, pack, check, dev, review, keygen, sign) for tauri-cordis plugins",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"node": ">=22.15"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
+
"@tauri-cordis/manifest": "0.2.0",
|
|
41
|
+
"@tauri-cordis/market": "0.2.0",
|
|
42
|
+
"@tauri-cordis/review": "0.2.0",
|
|
40
43
|
"esbuild": "0.28.1",
|
|
41
|
-
"
|
|
42
|
-
"@tauri-cordis/review": "0.1.0",
|
|
43
|
-
"@tauri-cordis/market": "0.1.0",
|
|
44
|
-
"tauri-cordis": "0.1.0"
|
|
44
|
+
"tauri-cordis": "0.2.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"test": "node --test \"test/**/*.test.mjs\""
|
package/src/bundle.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as esbuild from "esbuild";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
2
3
|
import { isBuiltin } from "node:module";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
4
6
|
import { BuildError } from "./errors.mjs";
|
|
5
7
|
import { isPackageOrSubpath, sharedPath } from "./shared.mjs";
|
|
6
8
|
|
|
@@ -67,7 +69,7 @@ function hostSharedPlugin(names) {
|
|
|
67
69
|
name: "fuyu-host-shared",
|
|
68
70
|
setup(build) {
|
|
69
71
|
if (filter) build.onResolve({ filter }, (args) => ({ path: args.path, external: true }));
|
|
70
|
-
|
|
72
|
+
},
|
|
71
73
|
};
|
|
72
74
|
}
|
|
73
75
|
|
package/src/check.mjs
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
import { resolve } from "node:path";
|
|
2
|
+
import { SERVICE_NAME, SLOTS } from "tauri-cordis/protocol";
|
|
2
3
|
import { review } from "@tauri-cordis/review";
|
|
3
|
-
import { build } from "./build.mjs";
|
|
4
|
+
import { build, readManifest } from "./build.mjs";
|
|
4
5
|
import { BuildError } from "./errors.mjs";
|
|
5
6
|
import { createScratch, snapshotDirectory } from "./sources.mjs";
|
|
6
7
|
|
|
8
|
+
const KNOWN_SLOTS = Object.freeze(Object.keys(SLOTS));
|
|
9
|
+
const KNOWN_INJECT = Object.freeze([
|
|
10
|
+
"clients",
|
|
11
|
+
"commands",
|
|
12
|
+
"config",
|
|
13
|
+
"http",
|
|
14
|
+
"windows",
|
|
15
|
+
"translator.engines",
|
|
16
|
+
"lyrics.sources",
|
|
17
|
+
"calendar.sources",
|
|
18
|
+
"agents.sources",
|
|
19
|
+
"clipboard.actions",
|
|
20
|
+
"screenshot.actions",
|
|
21
|
+
"messages.sources",
|
|
22
|
+
]);
|
|
23
|
+
const KNOWN_INJECT_SET = new Set(KNOWN_INJECT);
|
|
24
|
+
|
|
7
25
|
function isExperimental(finding) {
|
|
8
26
|
return finding.check === "manifest" && finding.file === "package.json" && finding.message.includes("fuyu.experimental");
|
|
9
27
|
}
|
|
@@ -17,8 +35,85 @@ function fromFinding(finding) {
|
|
|
17
35
|
};
|
|
18
36
|
}
|
|
19
37
|
|
|
38
|
+
function safeReadManifest(dir) {
|
|
39
|
+
try {
|
|
40
|
+
return readManifest(dir);
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function checkInterfaces(pkg, appKey, allowExperimental) {
|
|
47
|
+
const app = pkg?.[appKey];
|
|
48
|
+
if (!app || typeof app !== "object" || Array.isArray(app)) return [];
|
|
49
|
+
const experimental = new Set(Array.isArray(app.experimental) ? app.experimental.filter((item) => typeof item === "string") : []);
|
|
50
|
+
const issues = [];
|
|
51
|
+
if (Array.isArray(app.slots)) {
|
|
52
|
+
app.slots.forEach((slot, index) => {
|
|
53
|
+
if (typeof slot !== "string" || slot.trim() === "") return;
|
|
54
|
+
if (Object.hasOwn(SLOTS, slot)) {
|
|
55
|
+
if (SLOTS[slot].experimental === true) {
|
|
56
|
+
if (allowExperimental && (experimental.has(slot) || experimental.has("windows/v1"))) return;
|
|
57
|
+
issues.push({
|
|
58
|
+
path: `${appKey}.slots[${index}]`,
|
|
59
|
+
code: "experimental",
|
|
60
|
+
message: `"${slot}" is an experimental slot and requires ${appKey}.experimental to include "${slot}" or "windows/v1"`,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (allowExperimental && experimental.has(slot)) return;
|
|
66
|
+
issues.push({
|
|
67
|
+
path: `${appKey}.slots[${index}]`,
|
|
68
|
+
code: "unknown-slot",
|
|
69
|
+
message: `"${slot}" is not a known slot (known slots: ${KNOWN_SLOTS.join(", ")})`,
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
for (const field of ["provides", "replaces"]) {
|
|
74
|
+
const list = app[field];
|
|
75
|
+
if (!Array.isArray(list)) continue;
|
|
76
|
+
list.forEach((name, index) => {
|
|
77
|
+
if (typeof name !== "string" || name.trim() === "") return;
|
|
78
|
+
if (SERVICE_NAME.test(name)) return;
|
|
79
|
+
issues.push({
|
|
80
|
+
path: `${appKey}.${field}[${index}]`,
|
|
81
|
+
code: "service-name",
|
|
82
|
+
message: `"${name}" is not a valid service name (expected <name>/v<version>, e.g. "timers/v1")`,
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (app.inject && typeof app.inject === "object" && !Array.isArray(app.inject)) {
|
|
87
|
+
for (const kind of ["required", "optional"]) {
|
|
88
|
+
const list = app.inject[kind];
|
|
89
|
+
if (!Array.isArray(list)) continue;
|
|
90
|
+
list.forEach((name, index) => {
|
|
91
|
+
if (typeof name !== "string" || name.trim() === "") return;
|
|
92
|
+
if (name === "windows") {
|
|
93
|
+
if (allowExperimental && (experimental.has("windows") || experimental.has("windows/v1"))) return;
|
|
94
|
+
issues.push({
|
|
95
|
+
path: `${appKey}.inject.${kind}[${index}]`,
|
|
96
|
+
code: "experimental",
|
|
97
|
+
message: `"windows" is experimental and requires ${appKey}.experimental to include "windows/v1"`,
|
|
98
|
+
});
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (SERVICE_NAME.test(name) || KNOWN_INJECT_SET.has(name)) return;
|
|
102
|
+
if (allowExperimental && experimental.has(name)) return;
|
|
103
|
+
issues.push({
|
|
104
|
+
path: `${appKey}.inject.${kind}[${index}]`,
|
|
105
|
+
code: "service-name",
|
|
106
|
+
message: `"${name}" is not a valid service name (expected <name>/v<version> such as "timers/v1", or one of ${KNOWN_INJECT.join(", ")})`,
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return issues;
|
|
112
|
+
}
|
|
113
|
+
|
|
20
114
|
export async function check(dir, options = {}) {
|
|
21
115
|
const root = resolve(dir);
|
|
116
|
+
const appKey = options.appKey ?? "fuyu";
|
|
22
117
|
const allowExperimental = options.allowExperimental ?? true;
|
|
23
118
|
const errors = [];
|
|
24
119
|
const warnings = [];
|
|
@@ -35,6 +130,7 @@ export async function check(dir, options = {}) {
|
|
|
35
130
|
if (!(error instanceof BuildError)) throw error;
|
|
36
131
|
errors.push({ code: "build", message: error.message }, ...error.issues);
|
|
37
132
|
}
|
|
133
|
+
errors.push(...checkInterfaces(manifest ?? safeReadManifest(root), appKey, allowExperimental));
|
|
38
134
|
const report = review({ newDir: snapshotDirectory(root, scratch.dir("source")), newBuilt: built });
|
|
39
135
|
const listed = new Set(report.summary.dependencies.added.map((item) => `${item.name}@${item.versions.join(", ")}`));
|
|
40
136
|
const domains = new Set(warnings.filter((issue) => issue.code === "undeclared-domain").map((issue) => issue.domain));
|