












@@ -127,6 +127,7 @@ describe("Dockerfile", () => {
127127const dockerfile = await readFile(dockerfilePath, "utf8");
128128const installIndex = dockerfile.indexOf("pnpm install --frozen-lockfile");
129129const postinstallIndex = dockerfile.indexOf("COPY scripts/postinstall-bundled-plugins.mjs");
130+const prepareIndex = dockerfile.indexOf("scripts/prepare-git-hooks.mjs");
130131const distImportHelperIndex = dockerfile.indexOf(
131132"COPY scripts/lib/package-dist-imports.mjs ./scripts/lib/package-dist-imports.mjs",
132133);
@@ -138,6 +139,7 @@ describe("Dockerfile", () => {
138139);
139140140141expect(postinstallIndex).toBeGreaterThan(-1);
142+expect(prepareIndex).toBeGreaterThan(-1);
141143expect(distImportHelperIndex).toBeGreaterThan(-1);
142144expect(packageManifestIndex).toBeGreaterThan(-1);
143145expect(extensionManifestIndex).toBeGreaterThan(-1);
@@ -146,11 +148,42 @@ describe("Dockerfile", () => {
146148`if [ -f "/tmp/\${OPENCLAW_BUNDLED_PLUGIN_DIR}/$ext/package.json" ]; then`,
147149);
148150expect(postinstallIndex).toBeLessThan(installIndex);
151+expect(prepareIndex).toBeLessThan(installIndex);
149152expect(distImportHelperIndex).toBeLessThan(installIndex);
150153expect(packageManifestIndex).toBeLessThan(installIndex);
151154expect(extensionManifestIndex).toBeLessThan(installIndex);
152155});
153156157+it("copies root package lifecycle scripts before pnpm install", async () => {
158+const [dockerfile, packageJsonText] = await Promise.all([
159+readFile(dockerfilePath, "utf8"),
160+readFile(join(repoRoot, "package.json"), "utf8"),
161+]);
162+const installIndex = dockerfile.indexOf("pnpm install --frozen-lockfile");
163+const packageJson = JSON.parse(packageJsonText) as {
164+scripts?: Record<string, string>;
165+};
166+const installLifecycleScripts = ["preinstall", "install", "postinstall", "prepare"] as const;
167+168+for (const lifecycleScript of installLifecycleScripts) {
169+const command = packageJson.scripts?.[lifecycleScript];
170+const scriptPath = command?.match(/\bnode\s+(scripts\/[^\s]+)/)?.[1];
171+if (!scriptPath) {
172+continue;
173+}
174+175+const copyIndex = dockerfile.indexOf(scriptPath);
176+expect(
177+copyIndex,
178+`${lifecycleScript} must copy ${scriptPath} before pnpm install`,
179+).toBeGreaterThan(-1);
180+expect(
181+copyIndex,
182+`${lifecycleScript} must copy ${scriptPath} before pnpm install`,
183+).toBeLessThan(installIndex);
184+}
185+});
186+154187it("does not let pnpm resync the full source workspace during Docker build scripts", async () => {
155188const dockerfile = await readFile(dockerfilePath, "utf8");
156189此內容由慣性聚合(RSS閱讀器)自動聚合整理,僅供閱讀參考。 原文來自 — 版權歸原作者所有。