mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-28 06:05:24 +00:00
fix: unify connection failure screens and rebuild stale local plugins
This commit is contained in:
1 parent
a72aa5b57b
commit
49fc241e06
9 files changed
+262
-29
No files matched your search
@@ -11,6 +11,8 @@ import {
|
||||
extractArtifact,
|
||||
pinsFromIndex,
|
||||
findLocalPluginBuilds,
|
||||
isLocalBuildStale,
|
||||
rebuildLocalPlugins,
|
||||
copyLocalBuild,
|
||||
} from "./lib/bundled-plugins.cjs";
|
||||
|
||||
@@ -230,3 +232,52 @@ describe("local plugin builds", () => {
|
||||
expect(fs.existsSync(path.join(out, "src"))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("rebuilding local plugins", () => {
|
||||
function repo(dir: string, name: string, id: string): string {
|
||||
const root = path.join(dir, name);
|
||||
fs.mkdirSync(path.join(root, "src"), { recursive: true });
|
||||
fs.mkdirSync(path.join(root, "node_modules"));
|
||||
fs.writeFileSync(path.join(root, "manifest.json"), JSON.stringify({ id }));
|
||||
fs.writeFileSync(path.join(root, "src", "index.ts"), "x");
|
||||
return root;
|
||||
}
|
||||
|
||||
function touch(file: string, secondsAgo: number) {
|
||||
const time = new Date(Date.now() - secondsAgo * 1000);
|
||||
fs.utimesSync(file, time, time);
|
||||
}
|
||||
|
||||
it("is stale with no dist or with a source newer than the build", () => {
|
||||
const root = repo(tempDir(), "Plugin-A", "a");
|
||||
expect(isLocalBuildStale(root)).toBe(true);
|
||||
|
||||
fs.mkdirSync(path.join(root, "dist"));
|
||||
fs.writeFileSync(path.join(root, "dist", "frontend.js"), "x");
|
||||
touch(path.join(root, "manifest.json"), 60);
|
||||
touch(path.join(root, "src", "index.ts"), 60);
|
||||
expect(isLocalBuildStale(root)).toBe(false);
|
||||
|
||||
touch(path.join(root, "src", "index.ts"), 0);
|
||||
touch(path.join(root, "dist", "frontend.js"), 30);
|
||||
expect(isLocalBuildStale(root)).toBe(true);
|
||||
});
|
||||
|
||||
it("builds only stale repos for bundled ids that have node_modules", () => {
|
||||
const dir = tempDir();
|
||||
repo(dir, "Plugin-A", "a");
|
||||
repo(dir, "Plugin-B", "b");
|
||||
const noDeps = repo(dir, "Plugin-C", "c");
|
||||
fs.rmSync(path.join(noDeps, "node_modules"), { recursive: true });
|
||||
|
||||
const run: string[] = [];
|
||||
const rebuilt = rebuildLocalPlugins(
|
||||
dir,
|
||||
new Set(["a", "c"]),
|
||||
(_repo: string, id: string) => run.push(id),
|
||||
);
|
||||
expect(rebuilt).toEqual(["a"]);
|
||||
expect(run).toEqual(["a"]);
|
||||
expect(rebuildLocalPlugins(null, new Set(["a"]), () => {})).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user