fix: narrow bundled runtime mirror materialization · openclaw/openclaw@87345c0
steipete
·
2026-04-28
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -71,6 +71,9 @@ const BUNDLED_RUNTIME_MIRROR_MATERIALIZED_EXTENSIONS = new Set([".cjs", ".js", "
|
71 | 71 | const BUNDLED_EXTENSION_DIST_DIR = "extensions"; |
72 | 72 | const MIRRORED_CORE_RUNTIME_DEP_NAMES = ["tslog"] as const; |
73 | 73 | const MIRRORED_PACKAGE_RUNTIME_DEP_PLUGIN_ID = "openclaw-core"; |
| 74 | +const BUNDLED_RUNTIME_MIRROR_PLUGIN_REGION_RE = /(?:^|\n)\/\/#region extensions\/[^/\s]+(?:\/|$)/u; |
| 75 | +const BUNDLED_RUNTIME_MIRROR_IMPORT_SPECIFIER_RE = |
| 76 | +/(?:^|[;\n])\s*(?:import|export)\s+(?:[^'"()]+?\s+from\s+)?["']([^"']+)["']|\bimport\(\s*["']([^"']+)["']\s*\)|\brequire\(\s*["']([^"']+)["']\s*\)/g; |
74 | 77 | |
75 | 78 | const registeredBundledRuntimeDepNodePaths = new Set<string>(); |
76 | 79 | |
@@ -81,7 +84,31 @@ export type BundledRuntimeDepsNpmRunner = {
|
81 | 84 | }; |
82 | 85 | |
83 | 86 | export function shouldMaterializeBundledRuntimeMirrorDistFile(sourcePath: string): boolean { |
84 | | -return BUNDLED_RUNTIME_MIRROR_MATERIALIZED_EXTENSIONS.has(path.extname(sourcePath)); |
| 87 | +if (!BUNDLED_RUNTIME_MIRROR_MATERIALIZED_EXTENSIONS.has(path.extname(sourcePath))) { |
| 88 | +return false; |
| 89 | +} |
| 90 | +let source: string; |
| 91 | +try { |
| 92 | +source = fs.readFileSync(sourcePath, "utf8"); |
| 93 | +} catch { |
| 94 | +return false; |
| 95 | +} |
| 96 | +if (BUNDLED_RUNTIME_MIRROR_PLUGIN_REGION_RE.test(source)) { |
| 97 | +return true; |
| 98 | +} |
| 99 | +for (const match of source.matchAll(BUNDLED_RUNTIME_MIRROR_IMPORT_SPECIFIER_RE)) { |
| 100 | +const specifier = match[1] ?? match[2] ?? match[3] ?? ""; |
| 101 | +if ( |
| 102 | +specifier !== "" && |
| 103 | +!specifier.startsWith(".") && |
| 104 | +!specifier.startsWith("/") && |
| 105 | +!specifier.startsWith("node:") && |
| 106 | +!specifier.includes(":") |
| 107 | +) { |
| 108 | +return false; |
| 109 | +} |
| 110 | +} |
| 111 | +return true; |
85 | 112 | } |
86 | 113 | |
87 | 114 | export function materializeBundledRuntimeMirrorDistFile( |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -51,6 +51,11 @@ describe("prepareBundledPluginRuntimeRoot", () => {
|
51 | 51 | "export const shared = 'mirrored-without-region';\n", |
52 | 52 | "utf8", |
53 | 53 | ); |
| 54 | +fs.writeFileSync( |
| 55 | +path.join(packageRoot, "dist", "config-runtime.js"), |
| 56 | +"import JSON5 from 'json5'; export const parse = JSON5.parse;\n", |
| 57 | +"utf8", |
| 58 | +); |
54 | 59 | fs.writeFileSync( |
55 | 60 | path.join(pluginRoot, "index.js"), |
56 | 61 | `import { marker } from "../../pw-ai.js"; export default { id: "browser", marker };\n`, |
@@ -118,6 +123,9 @@ describe("prepareBundledPluginRuntimeRoot", () => {
|
118 | 123 | expect(fs.lstatSync(path.join(installRoot, "dist", "shared-runtime.js")).isSymbolicLink()).toBe( |
119 | 124 | false, |
120 | 125 | ); |
| 126 | +expect(fs.lstatSync(path.join(installRoot, "dist", "config-runtime.js")).isSymbolicLink()).toBe( |
| 127 | +true, |
| 128 | +); |
121 | 129 | }); |
122 | 130 | |
123 | 131 | it("does not copy staged runtime mirror dist files onto themselves", () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1745,6 +1745,11 @@ module.exports = {
|
1745 | 1745 | "export const shared = 'mirrored-without-region';\n", |
1746 | 1746 | "utf-8", |
1747 | 1747 | ); |
| 1748 | +fs.writeFileSync( |
| 1749 | +path.join(packageRoot, "dist", "config-runtime.js"), |
| 1750 | +"import JSON5 from 'json5'; export const parse = JSON5.parse;\n", |
| 1751 | +"utf-8", |
| 1752 | +); |
1748 | 1753 | fs.writeFileSync( |
1749 | 1754 | path.join(pluginRoot, "index.js"), |
1750 | 1755 | [ |
@@ -1841,6 +1846,9 @@ module.exports = {
|
1841 | 1846 | expect( |
1842 | 1847 | fs.lstatSync(path.join(actualInstallRoot, "dist", "shared-runtime.js")).isSymbolicLink(), |
1843 | 1848 | ).toBe(false); |
| 1849 | +expect( |
| 1850 | +fs.lstatSync(path.join(actualInstallRoot, "dist", "config-runtime.js")).isSymbolicLink(), |
| 1851 | +).toBe(true); |
1844 | 1852 | }); |
1845 | 1853 | |
1846 | 1854 | it("loads bundled plugins with plugin-sdk imports from an external stage dir", () => { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。