@biffo/cli 0.324.6 → 0.324.8
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.
|
@@ -202,6 +202,46 @@ def _external_base_name(raw: str) -> str | None:
|
|
|
202
202
|
return name if name in EXTERNAL_BASE_IDENTIFIERS else None
|
|
203
203
|
|
|
204
204
|
|
|
205
|
+
#: The dashboard's plugin registry — the one file `biffo plugin install` writes
|
|
206
|
+
#: a `user_frontend` plugin's `frontendUrl` into (`plugin-frontend-registry.ts`
|
|
207
|
+
#: in biffo-template, ADR-0021 section 2).
|
|
208
|
+
PLUGIN_REGISTRY_FILE = "apps/frontend/src/lib/plugins.ts"
|
|
209
|
+
|
|
210
|
+
#: The shared plugin host's `user_frontend` mount: `/api/v1/plugins/<slug>/ui`,
|
|
211
|
+
#: served same-origin by the plugin host behind the `/api/v1/plugins/*` route
|
|
212
|
+
#: family and NEVER by this BFF (biffo-template#2114). Every install of a
|
|
213
|
+
#: `user_frontend` plugin writes exactly one such literal into
|
|
214
|
+
#: `PLUGIN_REGISTRY_FILE`, so without this exemption the required check went
|
|
215
|
+
#: red on the first install, in every split dashboard.
|
|
216
|
+
#:
|
|
217
|
+
#: Like `EXTERNAL_BASE_IDENTIFIERS` this is an explicit ALLOWLIST, and it is
|
|
218
|
+
#: scoped on two axes at once -- the FILE (only `PLUGIN_REGISTRY_FILE`) and the
|
|
219
|
+
#: SHAPE (exactly `/api/v1/plugins/<one segment>/ui`, nothing before, after or
|
|
220
|
+
#: between). Any other `/api/v1/plugins/...` path, the same path from any other
|
|
221
|
+
#: file, or any other `/api/v1/...` path in the registry still has to match a
|
|
222
|
+
#: route this BFF registers.
|
|
223
|
+
#:
|
|
224
|
+
#: The shape is STRUCTURAL and deliberately defines no slug grammar of its own.
|
|
225
|
+
#: An earlier draft spelled the slug as kebab-case (`[a-z0-9]+(-[a-z0-9]+)*`),
|
|
226
|
+
#: which was narrower than what the installer accepts (its manifest grammar is
|
|
227
|
+
#: `^[a-z][a-z0-9-]*$`, admitting `widgets-` and `a--b`), so those installs went
|
|
228
|
+
#: red again. Two hand-kept grammars will always drift; one segment of anything
|
|
229
|
+
#: that cannot be a path separator, a template hole (`{`), a query/fragment
|
|
230
|
+
#: delimiter or a dot-segment cannot. The slug is whatever the installer wrote.
|
|
231
|
+
#: biffo-template pins the writer (`frontendUrlForSlug`) against this constant by
|
|
232
|
+
#: running THIS test over a `plugins.ts` the writer produced, for boundary slugs.
|
|
233
|
+
PLUGIN_HOST_UI_PATH = re.compile(r"^/api/v1/plugins/[^/{}?#.\s]+/ui$")
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def is_plugin_host_ui_path(file: Path, normalized: str | None) -> bool:
|
|
237
|
+
"""True for a `user_frontend` mount literal in the plugin registry file."""
|
|
238
|
+
return (
|
|
239
|
+
normalized is not None
|
|
240
|
+
and _relative(file) == PLUGIN_REGISTRY_FILE
|
|
241
|
+
and PLUGIN_HOST_UI_PATH.match(normalized) is not None
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
|
|
205
245
|
def _template_literals(text: str):
|
|
206
246
|
"""Every template literal in `text`, as `(content, start_index)` — scanned
|
|
207
247
|
with brace and backtick depth rather than matched with a regex.
|
|
@@ -728,7 +768,12 @@ def test_every_frontend_api_v1_path_is_registered_on_the_bff() -> None:
|
|
|
728
768
|
extracted.extend(extract_api_paths(file.read_text(encoding="utf-8"), file))
|
|
729
769
|
|
|
730
770
|
external = [p for p in extracted if p.external_base is not None]
|
|
731
|
-
|
|
771
|
+
plugin_host = [
|
|
772
|
+
p
|
|
773
|
+
for p in extracted
|
|
774
|
+
if p.external_base is None and is_plugin_host_ui_path(p.file, p.normalized)
|
|
775
|
+
]
|
|
776
|
+
in_scope = [p for p in extracted if p.external_base is None and p not in plugin_host]
|
|
732
777
|
resolved = [p for p in in_scope if p.normalized is not None]
|
|
733
778
|
unresolved = [p for p in in_scope if p.normalized is None]
|
|
734
779
|
|
|
@@ -750,7 +795,8 @@ def test_every_frontend_api_v1_path_is_registered_on_the_bff() -> None:
|
|
|
750
795
|
f"{matched_count} matched a route this BFF registers, "
|
|
751
796
|
f"{len(unmatched)} did not, {len(unresolved)} could not be resolved "
|
|
752
797
|
f"at all, {len(external)} target a declared external base and are out "
|
|
753
|
-
"of this BFF's scope
|
|
798
|
+
f"of this BFF's scope, {len(plugin_host)} are plugin-host `user_frontend` "
|
|
799
|
+
"mounts in the plugin registry (also out of this BFF's scope)."
|
|
754
800
|
)
|
|
755
801
|
|
|
756
802
|
lines = [summary]
|
|
@@ -775,6 +821,11 @@ def test_every_frontend_api_v1_path_is_registered_on_the_bff() -> None:
|
|
|
775
821
|
f" EXTERNAL {_relative(p.file)}:{p.line} {p.raw!r} "
|
|
776
822
|
f"-> prefixed with ${{{p.external_base}}}, declared external"
|
|
777
823
|
)
|
|
824
|
+
for p in plugin_host:
|
|
825
|
+
lines.append(
|
|
826
|
+
f" PLUGIN-HOST {_relative(p.file)}:{p.line} {p.raw!r} "
|
|
827
|
+
"-> plugin-host user_frontend mount, declared plugin-host route family"
|
|
828
|
+
)
|
|
778
829
|
if unmatched or unresolved:
|
|
779
830
|
# Display only -- `path_is_registered` above is what actually decided
|
|
780
831
|
# pass/fail; see its docstring for why this flattened set cannot be
|
|
@@ -1058,3 +1109,44 @@ class TestPathIsRegistered:
|
|
|
1058
1109
|
assert path_is_registered(catchall_app, "/api/v1/analytics/pipeline/funnel") is True
|
|
1059
1110
|
assert path_is_registered(catchall_app, "/api/v1/analytics/pipeline/funnel/{param}") is True
|
|
1060
1111
|
assert path_is_registered(catchall_app, "/api/v1/other/path") is False
|
|
1112
|
+
|
|
1113
|
+
|
|
1114
|
+
class TestPluginHostRouteFamily:
|
|
1115
|
+
"""The plugin-host exemption (biffo-template#2114) is an allowlist scoped by
|
|
1116
|
+
file AND shape — every row below is a way it must NOT widen."""
|
|
1117
|
+
|
|
1118
|
+
REGISTRY = REPO_ROOT / PLUGIN_REGISTRY_FILE
|
|
1119
|
+
|
|
1120
|
+
def test_user_frontend_mount_in_the_registry_is_exempt(self) -> None:
|
|
1121
|
+
assert is_plugin_host_ui_path(self.REGISTRY, "/api/v1/plugins/a5-throwaway/ui")
|
|
1122
|
+
assert is_plugin_host_ui_path(self.REGISTRY, "/api/v1/plugins/widgets/ui")
|
|
1123
|
+
|
|
1124
|
+
def test_every_slug_the_installer_accepts_is_exempt(self) -> None:
|
|
1125
|
+
# Manifest grammar is ^[a-z][a-z0-9-]*$ -- trailing and doubled hyphens
|
|
1126
|
+
# are legal, and so are the hand-authored shapes the registry reader
|
|
1127
|
+
# tolerates (underscore, uppercase). The guard defines no slug grammar.
|
|
1128
|
+
for slug in ("widgets-", "a--b", "a", "x9", "idea-scout", "a_b", "Widgets"):
|
|
1129
|
+
assert is_plugin_host_ui_path(self.REGISTRY, f"/api/v1/plugins/{slug}/ui"), slug
|
|
1130
|
+
|
|
1131
|
+
def test_same_path_in_any_other_file_is_not_exempt(self) -> None:
|
|
1132
|
+
other = FRONTEND_SRC / "lib" / "other.ts"
|
|
1133
|
+
assert not is_plugin_host_ui_path(other, "/api/v1/plugins/widgets/ui")
|
|
1134
|
+
|
|
1135
|
+
def test_other_shapes_in_the_registry_are_not_exempt(self) -> None:
|
|
1136
|
+
for path in (
|
|
1137
|
+
"/api/v1/plugins/widgets",
|
|
1138
|
+
"/api/v1/plugins/widgets/ui/extra",
|
|
1139
|
+
"/api/v1/plugins/widgets/api",
|
|
1140
|
+
"/api/v1/plugins/{param}/ui",
|
|
1141
|
+
"/api/v1/plugins/a/b/ui",
|
|
1142
|
+
"/api/v1/plugins//ui",
|
|
1143
|
+
"/api/v1/plugins/../ui",
|
|
1144
|
+
"/api/v1/plugins/./ui",
|
|
1145
|
+
"/api/v1/plugins/a?x=1/ui",
|
|
1146
|
+
"/api/v1/plugins/a#x/ui",
|
|
1147
|
+
"/api/v1/courses",
|
|
1148
|
+
"/api/v1/whoami",
|
|
1149
|
+
"/x/api/v1/plugins/widgets/ui",
|
|
1150
|
+
None,
|
|
1151
|
+
):
|
|
1152
|
+
assert not is_plugin_host_ui_path(self.REGISTRY, path), path
|
package/dist/index.js
CHANGED
|
@@ -9791,30 +9791,6 @@ function findInstalledPlugins(cwd) {
|
|
|
9791
9791
|
import { existsSync as existsSync31, readdirSync as readdirSync11, readFileSync as readFileSync21, writeFileSync as writeFileSync9 } from "fs";
|
|
9792
9792
|
import { join as join32 } from "path";
|
|
9793
9793
|
import { parse as parseToml } from "smol-toml";
|
|
9794
|
-
function readTomlStringArray(text, key) {
|
|
9795
|
-
const open = new RegExp(`^${key}\\s*=\\s*\\[`, "m").exec(text);
|
|
9796
|
-
if (!open) return [];
|
|
9797
|
-
const strings = [];
|
|
9798
|
-
let depth = 1;
|
|
9799
|
-
let i = open.index + open[0].length;
|
|
9800
|
-
while (i < text.length && depth > 0) {
|
|
9801
|
-
const c = text[i];
|
|
9802
|
-
if (c === "#") {
|
|
9803
|
-
const nl = text.indexOf("\n", i);
|
|
9804
|
-
i = nl === -1 ? text.length : nl;
|
|
9805
|
-
} else if (c === '"' || c === "'") {
|
|
9806
|
-
const close = text.indexOf(c, i + 1);
|
|
9807
|
-
if (close === -1) break;
|
|
9808
|
-
if (depth === 1) strings.push(text.slice(i + 1, close));
|
|
9809
|
-
i = close + 1;
|
|
9810
|
-
} else {
|
|
9811
|
-
if (c === "[") depth++;
|
|
9812
|
-
else if (c === "]") depth--;
|
|
9813
|
-
i++;
|
|
9814
|
-
}
|
|
9815
|
-
}
|
|
9816
|
-
return depth === 0 ? strings : [];
|
|
9817
|
-
}
|
|
9818
9794
|
function normaliseName(name) {
|
|
9819
9795
|
return name.replace(/[-_.]+/g, "-").toLowerCase();
|
|
9820
9796
|
}
|
|
@@ -9842,15 +9818,17 @@ function requirementsIn(groups) {
|
|
|
9842
9818
|
return Object.values(groups).filter(Array.isArray).flat().filter((entry) => typeof entry === "string");
|
|
9843
9819
|
}
|
|
9844
9820
|
function readDeclaredDependencyNames(doc) {
|
|
9821
|
+
return readDeclaredRequirements(doc).map(requirementName).filter((name) => name !== null);
|
|
9822
|
+
}
|
|
9823
|
+
function readDeclaredRequirements(doc) {
|
|
9845
9824
|
const project = isTable(doc.project) ? doc.project : {};
|
|
9846
|
-
|
|
9825
|
+
return [
|
|
9847
9826
|
...(Array.isArray(project.dependencies) ? project.dependencies : []).filter(
|
|
9848
9827
|
(dep) => typeof dep === "string"
|
|
9849
9828
|
),
|
|
9850
9829
|
...requirementsIn(project["optional-dependencies"]),
|
|
9851
9830
|
...requirementsIn(doc["dependency-groups"])
|
|
9852
9831
|
];
|
|
9853
|
-
return requirements.map(requirementName).filter((name) => name !== null);
|
|
9854
9832
|
}
|
|
9855
9833
|
function existingSourceNames(doc) {
|
|
9856
9834
|
const tool = isTable(doc.tool) ? doc.tool : {};
|
|
@@ -12037,6 +12015,7 @@ import { join as join44, relative as relative7, resolve as resolve19 } from "pat
|
|
|
12037
12015
|
import chalk19 from "chalk";
|
|
12038
12016
|
import { Command as Command21 } from "commander";
|
|
12039
12017
|
import inquirer7 from "inquirer";
|
|
12018
|
+
import { parse as parseToml2 } from "smol-toml";
|
|
12040
12019
|
var pluginUpgradeCommand = new Command21("upgrade").description(
|
|
12041
12020
|
"Upgrade an installed plugin to a new minor version (biffo plugin upgrade <name>@<new-minor>) or refresh it in place from a local, unpublished checkout (biffo plugin upgrade --local <path>)"
|
|
12042
12021
|
).argument(
|
|
@@ -12409,28 +12388,17 @@ function readPyprojectIfPresent(targetDir) {
|
|
|
12409
12388
|
}
|
|
12410
12389
|
function dependenciesChanged(before, after) {
|
|
12411
12390
|
if (before === after) return false;
|
|
12412
|
-
const beforeItems = before ? dependencySurface(before)
|
|
12413
|
-
const afterItems = after ? dependencySurface(after)
|
|
12391
|
+
const beforeItems = before === null ? [] : dependencySurface(before);
|
|
12392
|
+
const afterItems = after === null ? [] : dependencySurface(after);
|
|
12393
|
+
if (beforeItems === null || afterItems === null) return true;
|
|
12414
12394
|
return JSON.stringify(beforeItems) !== JSON.stringify(afterItems);
|
|
12415
12395
|
}
|
|
12416
12396
|
function dependencySurface(text) {
|
|
12417
|
-
|
|
12418
|
-
|
|
12419
|
-
|
|
12420
|
-
|
|
12421
|
-
|
|
12422
|
-
items.push(...readTomlStringArray(body, m[1]));
|
|
12423
|
-
}
|
|
12424
|
-
}
|
|
12425
|
-
return items.sort();
|
|
12426
|
-
}
|
|
12427
|
-
function tomlTableBody(text, header) {
|
|
12428
|
-
const escaped = header.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
12429
|
-
const headerMatch = new RegExp(`^\\[${escaped}\\]\\s*$`, "m").exec(text);
|
|
12430
|
-
if (!headerMatch) return null;
|
|
12431
|
-
const rest = text.slice(headerMatch.index + headerMatch[0].length);
|
|
12432
|
-
const nextHeader = /^\[/m.exec(rest);
|
|
12433
|
-
return nextHeader ? rest.slice(0, nextHeader.index) : rest;
|
|
12397
|
+
try {
|
|
12398
|
+
return readDeclaredRequirements(parseToml2(text)).sort();
|
|
12399
|
+
} catch {
|
|
12400
|
+
return null;
|
|
12401
|
+
}
|
|
12434
12402
|
}
|
|
12435
12403
|
function readInstalledVersion(targetDir) {
|
|
12436
12404
|
const manifestPath = join44(targetDir, "biffo.plugin.json");
|