mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-29 19:01:44 +00:00
fix: prevent matrix-js-sdk plugin load crash (#56273) (thanks @aquaright1)
* Fix matrix-js-sdk multiple entrypoint crash on plugin load * test(matrix): cover runtime bundle import regression * fix: prevent matrix-js-sdk plugin load crash (#56273) (thanks @aquaright1) * fix: widen matrix-js-sdk bundle import guard (#56273) (thanks @aquaright1) --------- Co-authored-by: Kenny Xie <kennyxie@Mac-mini-von-Kenny.local> Co-authored-by: Ayaan Zaidi <hi@obviy.us>
This commit is contained in:
@@ -8,7 +8,28 @@ import { buildPluginSdkEntrySources, pluginSdkEntrypoints } from "./entrypoints.
|
||||
const require = createRequire(import.meta.url);
|
||||
const tsdownModuleUrl = pathToFileURL(require.resolve("tsdown")).href;
|
||||
const bundledRepresentativeEntrypoints = ["matrix-runtime-heavy"] as const;
|
||||
const bundledCoverageEntrySources = buildPluginSdkEntrySources(bundledRepresentativeEntrypoints);
|
||||
const matrixRuntimeCoverageEntries = {
|
||||
"matrix-runtime-sdk": "extensions/matrix/src/matrix/sdk.ts",
|
||||
} as const;
|
||||
const bundledCoverageEntrySources = {
|
||||
...buildPluginSdkEntrySources(bundledRepresentativeEntrypoints),
|
||||
...matrixRuntimeCoverageEntries,
|
||||
};
|
||||
const bareMatrixSdkImportPattern = /(?:from|require|import)\s*\(?\s*["']matrix-js-sdk["']/;
|
||||
|
||||
async function listBuiltJsFiles(rootDir: string): Promise<string[]> {
|
||||
const entries = await fs.readdir(rootDir, { withFileTypes: true });
|
||||
const nested = await Promise.all(
|
||||
entries.map(async (entry) => {
|
||||
const entryPath = path.join(rootDir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
return await listBuiltJsFiles(entryPath);
|
||||
}
|
||||
return entry.isFile() && entry.name.endsWith(".js") ? [entryPath] : [];
|
||||
}),
|
||||
);
|
||||
return nested.flat();
|
||||
}
|
||||
|
||||
describe("plugin-sdk bundled exports", () => {
|
||||
it("emits importable bundled subpath entries", { timeout: 120_000 }, async () => {
|
||||
@@ -34,7 +55,9 @@ describe("plugin-sdk bundled exports", () => {
|
||||
},
|
||||
// Full plugin-sdk coverage belongs to `pnpm build`, package contract
|
||||
// guardrails, and `subpaths.test.ts`. This file only keeps the expensive
|
||||
// bundler path honest across representative entrypoint families.
|
||||
// bundler path honest across representative entrypoint families plus the
|
||||
// Matrix SDK runtime import surface that historically crashed plugin
|
||||
// loading when bare and deep SDK entrypoints mixed.
|
||||
entry: bundledCoverageEntrySources,
|
||||
env: { NODE_ENV: "production" },
|
||||
fixedExtension: false,
|
||||
@@ -49,6 +72,21 @@ describe("plugin-sdk bundled exports", () => {
|
||||
await expect(fs.stat(path.join(outDir, `${entry}.js`))).resolves.toBeTruthy();
|
||||
}),
|
||||
);
|
||||
await Promise.all(
|
||||
Object.keys(matrixRuntimeCoverageEntries).map(async (entry) => {
|
||||
await expect(fs.stat(path.join(outDir, `${entry}.js`))).resolves.toBeTruthy();
|
||||
}),
|
||||
);
|
||||
const builtJsFiles = await listBuiltJsFiles(outDir);
|
||||
const filesWithBareMatrixSdkImports = (
|
||||
await Promise.all(
|
||||
builtJsFiles.map(async (filePath) => {
|
||||
const contents = await fs.readFile(filePath, "utf8");
|
||||
return bareMatrixSdkImportPattern.test(contents) ? filePath : null;
|
||||
}),
|
||||
)
|
||||
).filter((filePath): filePath is string => filePath !== null);
|
||||
expect(filesWithBareMatrixSdkImports).toEqual([]);
|
||||
|
||||
// Export list and package-specifier coverage already live in
|
||||
// package-contract-guardrails.test.ts and subpaths.test.ts. Keep this file
|
||||
|
||||
Reference in New Issue
Block a user