|
10 | 10 |
|
11 | 11 | import { $, echo, fs, chalk } from 'zx'; |
12 | 12 | import path from 'path'; |
| 13 | +import os from 'os'; |
13 | 14 |
|
14 | 15 | // Check if running in a CI environment |
15 | 16 | const isCI = process.env.CI === 'true'; |
@@ -123,14 +124,13 @@ const packageJsonFiles = await $`cd ${config.rootDir} && find . -name "package.j |
123 | 124 | -not -path "./compiled/*" \ |
124 | 125 | -type f`.lines(); |
125 | 126 |
|
126 | | -// Backup all package.json files |
127 | | -// This is only needed locally, not in CI |
128 | | -if (process.env.CI !== 'true') { |
129 | | - for (const file of packageJsonFiles) { |
130 | | - if (file) { |
131 | | - const fullPath = path.join(config.rootDir, file); |
132 | | - await fs.copy(fullPath, `${fullPath}.bak`); |
133 | | - } |
| 127 | +// Backup all package.json files. The FE trim below mutates them, and pnpm verifies |
| 128 | +// the lockfile before running any later script, which fails until they are restored. |
| 129 | +// Backups live outside the workspace: siblings would be packed into the deployment. |
| 130 | +const packageJsonBackupDir = await fs.mkdtemp(path.join(os.tmpdir(), 'n8n-build-pkgjson-')); |
| 131 | +for (const file of packageJsonFiles) { |
| 132 | + if (file) { |
| 133 | + await fs.copy(path.join(config.rootDir, file), path.join(packageJsonBackupDir, file)); |
134 | 134 | } |
135 | 135 | } |
136 | 136 | // Run FE trim script |
@@ -303,18 +303,15 @@ if (generateLicenses) { |
303 | 303 | } |
304 | 304 |
|
305 | 305 | // Restore package.json files |
306 | | -// This is only needed locally, not in CI |
307 | | -if (process.env.CI !== 'true') { |
308 | | - for (const file of packageJsonFiles) { |
309 | | - if (file) { |
310 | | - const fullPath = path.join(config.rootDir, file); |
311 | | - const backupPath = `${fullPath}.bak`; |
312 | | - if (await fs.pathExists(backupPath)) { |
313 | | - await fs.move(backupPath, fullPath, { overwrite: true }); |
314 | | - } |
| 306 | +for (const file of packageJsonFiles) { |
| 307 | + if (file) { |
| 308 | + const backupPath = path.join(packageJsonBackupDir, file); |
| 309 | + if (await fs.pathExists(backupPath)) { |
| 310 | + await fs.move(backupPath, path.join(config.rootDir, file), { overwrite: true }); |
315 | 311 | } |
316 | 312 | } |
317 | 313 | } |
| 314 | +await fs.remove(packageJsonBackupDir); |
318 | 315 |
|
319 | 316 | // Calculate output size |
320 | 317 | const compiledAppOutputSize = (await $`du -sh ${config.compiledAppDir} | cut -f1`).stdout.trim(); |
|
0 commit comments