mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-28 06:05:24 +00:00
fix: finish 2.9.0 plugin moves and get every check green
This commit is contained in:
1 parent
8c1e02af89
commit
6489b62ece
335 files changed
+29878
-17749
No files matched your search
@@ -3,6 +3,7 @@ import path from "node:path";
|
||||
import * as esbuild from "esbuild";
|
||||
import { BACKEND_EXTERNALS, FRONTEND_EXTERNALS } from "../lib/externals.mjs";
|
||||
import { legacyCoreImports } from "../lib/legacy-core-imports.mjs";
|
||||
import { staticUrlImports } from "../lib/static-url-imports.mjs";
|
||||
import { readManifest, resolveEntry, copyDir } from "../lib/plugin-dir.mjs";
|
||||
|
||||
const BACKEND_ENTRIES = [
|
||||
@@ -75,6 +76,7 @@ export async function build({ cwd }) {
|
||||
logLevel: "warning",
|
||||
external: FRONTEND_EXTERNALS,
|
||||
plugins: [
|
||||
staticUrlImports({ outDir }),
|
||||
legacyCoreImports({
|
||||
pluginId,
|
||||
platform: "browser",
|
||||
|
||||
@@ -20,11 +20,6 @@ const CORE_BACKEND = /^(?:\.\.\/)+src\/backend\//;
|
||||
// value (AUTOMATION_DEFINITION_VERSION), so this has to resolve at runtime.
|
||||
const CORE_TYPES = /^(?:\.\.\/)+src\/types\//;
|
||||
const CORE_UI = /^(?:\.\.\/)+src\/ui\//;
|
||||
// "../../../<other-plugin>/backend/" -- only plugins/ai/.../executor.ts today.
|
||||
// esbuild filters are Go RE2, which has no lookahead, so "src" is excluded in
|
||||
// the callback rather than the pattern.
|
||||
const CROSS_PLUGIN = /^(?:\.\.\/)+([a-z0-9-]+)\/(?:src\/)?backend\//;
|
||||
|
||||
/** dist/plugins/<id>/dist/backend.js -> dist/backend/... */
|
||||
const COMPILED_CORE = "../../../backend/backend/";
|
||||
const COMPILED_TYPES = "../../../backend/types/";
|
||||
@@ -68,12 +63,6 @@ export function legacyCoreImports({ pluginId, platform, insideTermix = true }) {
|
||||
path: args.path.replace(CORE_TYPES, COMPILED_TYPES),
|
||||
external: true,
|
||||
}));
|
||||
|
||||
build.onResolve({ filter: CROSS_PLUGIN }, (args) => {
|
||||
const [, other] = CROSS_PLUGIN.exec(args.path);
|
||||
if (other === "src" || other === pluginId) return null;
|
||||
return { path: `../../${other}/dist/backend.js`, external: true };
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import crypto from "node:crypto";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
/**
|
||||
* `import url from "some/file.js?url"` in a plugin frontend, as core's Vite
|
||||
* build allows: the file is copied next to the bundle under assets/ and the
|
||||
* import becomes its URL, resolved against the bundle's own URL so it works
|
||||
* under /plugin-assets/<id>/. Only scripts, since that is all the asset
|
||||
* route serves (a pdfjs or Monaco worker, say).
|
||||
*/
|
||||
export function staticUrlImports({ outDir }) {
|
||||
return {
|
||||
name: "static-url-imports",
|
||||
setup(build) {
|
||||
build.onResolve({ filter: /\?url$/ }, async (args) => {
|
||||
const target = args.path.slice(0, -"?url".length);
|
||||
const resolved = await build.resolve(target, {
|
||||
kind: args.kind,
|
||||
resolveDir: args.resolveDir,
|
||||
importer: args.importer,
|
||||
});
|
||||
if (resolved.errors.length > 0) return { errors: resolved.errors };
|
||||
return { path: resolved.path, namespace: "static-url" };
|
||||
});
|
||||
|
||||
build.onLoad({ filter: /.*/, namespace: "static-url" }, (args) => {
|
||||
if (!/\.(m?js|cjs)$/.test(args.path)) {
|
||||
return {
|
||||
errors: [
|
||||
{
|
||||
text: `${args.path}: only script files can be imported with ?url`,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
const bytes = fs.readFileSync(args.path);
|
||||
const hash = crypto
|
||||
.createHash("sha256")
|
||||
.update(bytes)
|
||||
.digest("hex")
|
||||
.slice(0, 8);
|
||||
const base = path.basename(args.path).replace(/\.(m?js|cjs)$/, "");
|
||||
const name = `${base}-${hash}.js`;
|
||||
fs.mkdirSync(path.join(outDir, "assets"), { recursive: true });
|
||||
fs.writeFileSync(path.join(outDir, "assets", name), bytes);
|
||||
return {
|
||||
contents: `export default new URL("./assets/${name}", import.meta.url).href;`,
|
||||
loader: "js",
|
||||
};
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user