@edhspace/devkit 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/README.md +17 -0
- package/dist/cli.js +116 -4
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -6,6 +6,7 @@ Local CLI for reviewed EDHspace extensions. Requires Node 22.12+.
|
|
|
6
6
|
edhspace check extensions/my-extension
|
|
7
7
|
edhspace build extensions/my-extension
|
|
8
8
|
edhspace dev extensions/my-extension
|
|
9
|
+
edhspace sideload extensions/my-extension
|
|
9
10
|
edhspace check-all extensions
|
|
10
11
|
edhspace build-all extensions
|
|
11
12
|
edhspace inspect-dependency node_modules/<package>
|
|
@@ -26,6 +27,22 @@ storage. API requests use the host's consent dialog before any outgoing data is
|
|
|
26
27
|
sent. Unsupported capabilities reject. Stop with Ctrl+C; generated workbench
|
|
27
28
|
assets stay in `.local/dev`, separate from distributable `dist`.
|
|
28
29
|
|
|
30
|
+
Sideload builds `dist/sideload.edhspace-extension.json` for the site's development
|
|
31
|
+
upload. From the public repository root, use
|
|
32
|
+
`npm run build:sideload -- extensions/my-extension`.
|
|
33
|
+
Each declared panel includes its own React/API/UI runtime, styles, and inlined
|
|
34
|
+
assets; no private site packages or local server are needed. Source, manifest,
|
|
35
|
+
dependency, and import checks still apply. Native `build` outputs remain unchanged.
|
|
36
|
+
The bootstrap renders mana/rules symbols as text tokens so shared UI does not
|
|
37
|
+
request external images from the sandbox.
|
|
38
|
+
Choose or drop the file through Workspace > Extensions > Test an extension using an
|
|
39
|
+
ordinary EDHspace account and a disposable owned test deck. Rebuild and reopen
|
|
40
|
+
Manage test extension to upload your changes or remove the build.
|
|
41
|
+
|
|
42
|
+
Sideload bundles are unreviewed code. The host must render them only in an opaque
|
|
43
|
+
sandboxed iframe and keep grants, host actions, and network approvals outside it.
|
|
44
|
+
Do not import or execute an uploaded bundle in the application context.
|
|
45
|
+
|
|
29
46
|
The policy catches common violations, not malicious JavaScript in general.
|
|
30
47
|
Contributions require source/artifact review before native application inclusion.
|
|
31
48
|
See the [API reference](../../API.md) and [contribution guide](../../CONTRIBUTING.md).
|
package/dist/cli.js
CHANGED
|
@@ -521,24 +521,136 @@ createRoot(document.getElementById("root")).render(<Workbench/>);
|
|
|
521
521
|
|
|
522
522
|
// src/cli.ts
|
|
523
523
|
import { readdir as readdir2, realpath as realpath3 } from "fs/promises";
|
|
524
|
+
import path5 from "path";
|
|
525
|
+
|
|
526
|
+
// src/sideload.ts
|
|
527
|
+
import { build as build2 } from "esbuild";
|
|
528
|
+
import { mkdir as mkdir3, readFile as readFile4, writeFile as writeFile2, lstat as lstat3 } from "fs/promises";
|
|
524
529
|
import path4 from "path";
|
|
530
|
+
import { sideloadBundleSchema, sideloadProtocol, sideloadVersion } from "@edhspace/api/sideload";
|
|
531
|
+
async function buildSideloadExtension(directory2) {
|
|
532
|
+
const context2 = await validateExtension(directory2);
|
|
533
|
+
const panels = [];
|
|
534
|
+
const notices = [];
|
|
535
|
+
for (const dependency of context2.dependencies)
|
|
536
|
+
for (const file of dependency.review.licenseFiles)
|
|
537
|
+
notices.push(
|
|
538
|
+
`${dependency.review.name}@${dependency.review.version}
|
|
539
|
+
` + await readFile4(path4.join(dependency.root, file), "utf8")
|
|
540
|
+
);
|
|
541
|
+
for (const panel of context2.pkg.panels) {
|
|
542
|
+
const source = `
|
|
543
|
+
import React from "react";
|
|
544
|
+
import { createRoot } from "react-dom/client";
|
|
545
|
+
import { connectSideload, sideloadProtocol, sideloadVersion } from "@edhspace/api/sideload";
|
|
546
|
+
import { ExtensionProvider } from "@edhspace/api/react";
|
|
547
|
+
import { Notice, SymbolRenderingProvider } from "@edhspace/ui";
|
|
548
|
+
import "@edhspace/ui/styles.css";
|
|
549
|
+
import Panel from ${JSON.stringify(path4.join(context2.root, panel.entry))};
|
|
550
|
+
const root = createRoot(document.getElementById("root"));
|
|
551
|
+
function fail(error) {
|
|
552
|
+
const message = error instanceof Error ? error.message : "The extension failed to start.";
|
|
553
|
+
root.render(<div className="edhspace-ui"><Notice error>{message}</Notice></div>);
|
|
554
|
+
window.parent.postMessage({protocol:sideloadProtocol,version:sideloadVersion,type:"error",message:message.slice(0,300)}, "*");
|
|
555
|
+
}
|
|
556
|
+
class Boundary extends React.Component {
|
|
557
|
+
state = {error:undefined};
|
|
558
|
+
static getDerivedStateFromError(error) { return {error}; }
|
|
559
|
+
componentDidCatch(error) {
|
|
560
|
+
console.error("Sideloaded panel failed.", error);
|
|
561
|
+
window.parent.postMessage({protocol:sideloadProtocol,version:sideloadVersion,type:"error",message:"The extension panel failed to render."}, "*");
|
|
562
|
+
}
|
|
563
|
+
render() {
|
|
564
|
+
return this.state.error ? <Notice error>The extension panel failed to render.</Notice> : this.props.children;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
connectSideload(${JSON.stringify(panel.id)}).then(connection => {
|
|
568
|
+
function SideloadPanel() {
|
|
569
|
+
const state = React.useSyncExternalStore(connection.subscribe, connection.getSnapshot);
|
|
570
|
+
React.useEffect(() => { document.documentElement.dataset.theme = state.theme; }, [state.theme]);
|
|
571
|
+
return <div className="edhspace-ui">{state.error ? <Notice error>{state.error.message}</Notice> :
|
|
572
|
+
<Boundary><SymbolRenderingProvider mode="text"><ExtensionProvider api={connection.api} revision={state.revision}><Panel/></ExtensionProvider></SymbolRenderingProvider></Boundary>}</div>;
|
|
573
|
+
}
|
|
574
|
+
window.addEventListener("pagehide", () => connection.dispose(), {once:true});
|
|
575
|
+
root.render(<SideloadPanel/>);
|
|
576
|
+
}).catch(fail);
|
|
577
|
+
`;
|
|
578
|
+
const result = await build2({
|
|
579
|
+
stdin: { contents: source, loader: "tsx", resolveDir: context2.root },
|
|
580
|
+
outfile: "panel.js",
|
|
581
|
+
write: false,
|
|
582
|
+
bundle: true,
|
|
583
|
+
format: "iife",
|
|
584
|
+
platform: "browser",
|
|
585
|
+
target: "es2022",
|
|
586
|
+
minify: true,
|
|
587
|
+
legalComments: "inline",
|
|
588
|
+
define: { "process.env.NODE_ENV": '"production"' },
|
|
589
|
+
loader: { ".svg": "dataurl", ".png": "dataurl", ".jpg": "dataurl", ".woff2": "dataurl" },
|
|
590
|
+
plugins: [importBoundary(context2.root, context2.dependencies, context2.directDependencies)],
|
|
591
|
+
banner: notices.length ? { js: notices.join("\n\n").split("\n").map((line) => `// ${line}`).join("\n") } : void 0
|
|
592
|
+
});
|
|
593
|
+
const javascript = result.outputFiles.find((file) => file.path.endsWith(".js"));
|
|
594
|
+
if (!javascript) throw new Error(`No JavaScript was emitted for panel ${panel.id}.`);
|
|
595
|
+
const unsupported = result.outputFiles.filter(
|
|
596
|
+
(file) => !file.path.endsWith(".js") && !file.path.endsWith(".css")
|
|
597
|
+
);
|
|
598
|
+
if (unsupported.length)
|
|
599
|
+
throw new Error(`Sideload panels must inline all assets: ${unsupported[0].path}.`);
|
|
600
|
+
panels.push({
|
|
601
|
+
id: panel.id,
|
|
602
|
+
javascript: javascript.text,
|
|
603
|
+
css: result.outputFiles.find((file) => file.path.endsWith(".css"))?.text ?? ""
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
const bundle = sideloadBundleSchema.parse({
|
|
607
|
+
protocol: sideloadProtocol,
|
|
608
|
+
version: sideloadVersion,
|
|
609
|
+
manifest: context2.manifest,
|
|
610
|
+
panels
|
|
611
|
+
});
|
|
612
|
+
const outputDirectory = path4.join(context2.root, "dist");
|
|
613
|
+
try {
|
|
614
|
+
const output2 = await lstat3(outputDirectory);
|
|
615
|
+
if (!output2.isDirectory() || output2.isSymbolicLink())
|
|
616
|
+
throw new Error("Extension dist output must be a regular directory.");
|
|
617
|
+
} catch (error) {
|
|
618
|
+
if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) throw error;
|
|
619
|
+
}
|
|
620
|
+
await mkdir3(outputDirectory, { recursive: true });
|
|
621
|
+
const output = path4.join(outputDirectory, "sideload.edhspace-extension.json");
|
|
622
|
+
try {
|
|
623
|
+
const existing = await lstat3(output);
|
|
624
|
+
if (existing.isSymbolicLink() || !existing.isFile())
|
|
625
|
+
throw new Error("Sideload output must be a regular file.");
|
|
626
|
+
} catch (error) {
|
|
627
|
+
if (!(error instanceof Error && "code" in error && error.code === "ENOENT")) throw error;
|
|
628
|
+
}
|
|
629
|
+
await writeFile2(output, JSON.stringify(bundle));
|
|
630
|
+
return { ...context2, bundle, output };
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// src/cli.ts
|
|
525
634
|
var [command, directory] = process.argv.slice(2);
|
|
526
635
|
try {
|
|
527
|
-
if (!directory || !["build", "check", "dev", "build-all", "check-all", "inspect-dependency"].includes(command))
|
|
636
|
+
if (!directory || !["build", "check", "dev", "sideload", "build-all", "check-all", "inspect-dependency"].includes(command))
|
|
528
637
|
throw new Error(
|
|
529
|
-
"Usage: edhspace <check|build|dev> <extension-directory>, <check-all|build-all> <extensions-directory>, or inspect-dependency <installed-package-directory>"
|
|
638
|
+
"Usage: edhspace <check|build|dev|sideload> <extension-directory>, <check-all|build-all> <extensions-directory>, or inspect-dependency <installed-package-directory>"
|
|
530
639
|
);
|
|
531
640
|
if (command === "inspect-dependency")
|
|
532
641
|
console.log(JSON.stringify(await inspectDependency(directory), null, 2));
|
|
533
642
|
else if (command === "dev") await devExtension(directory);
|
|
534
|
-
else {
|
|
643
|
+
else if (command === "sideload") {
|
|
644
|
+
const result = await buildSideloadExtension(directory);
|
|
645
|
+
console.log(`Sideload bundle: ${result.output}`);
|
|
646
|
+
} else {
|
|
535
647
|
let directories = [directory];
|
|
536
648
|
if (command.endsWith("-all")) {
|
|
537
649
|
const root = await realpath3(directory);
|
|
538
650
|
const entries = await readdir2(root, { withFileTypes: true });
|
|
539
651
|
if (entries.some((entry) => entry.isSymbolicLink()))
|
|
540
652
|
throw new Error("Extension directories cannot be symlinks.");
|
|
541
|
-
directories = entries.filter((entry) => entry.isDirectory()).map((entry) =>
|
|
653
|
+
directories = entries.filter((entry) => entry.isDirectory()).map((entry) => path5.join(root, entry.name)).sort();
|
|
542
654
|
if (!directories.length) throw new Error("No extension directories found.");
|
|
543
655
|
}
|
|
544
656
|
for (const extension of directories) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edhspace/devkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": {
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"scripts": {
|
|
28
28
|
"build": "tsup",
|
|
29
29
|
"typecheck": "tsc --noEmit",
|
|
30
|
-
"test": "vitest run"
|
|
30
|
+
"test": "vitest run --maxWorkers=1"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@edhspace/api": "^0.
|
|
34
|
-
"@edhspace/ui": "^0.
|
|
33
|
+
"@edhspace/api": "^0.2.0",
|
|
34
|
+
"@edhspace/ui": "^0.2.0",
|
|
35
35
|
"esbuild": "0.27.1",
|
|
36
36
|
"typescript": "5.9.3",
|
|
37
37
|
"react": "^19.2.8",
|