docker-gitlab/assets/build/patches/gitlabhq/0003-fix_preinstall.mjs-to-avoid-removing-node_modules_dir.patch
Kazunori Kimura e636b969a9 Revise build patch structure
to allow patching each middleware or library

Just move patches to assets/build/patches/gitlabhq
Folder name are matched to assets/runtime/config
2024-02-13 04:27:50 +09:00

29 lines
1.4 KiB
Diff

diff --git a/scripts/frontend/preinstall.mjs b/scripts/frontend/preinstall.mjs
index 09d980344eac..b1514e803b75 100644
--- a/scripts/frontend/preinstall.mjs
+++ b/scripts/frontend/preinstall.mjs
@@ -1,6 +1,6 @@
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
-import { readFile, rm } from 'node:fs/promises';
+import { readdir, readFile, rm, stat } from 'node:fs/promises';
const ROOT_PATH = join(dirname(fileURLToPath(import.meta.url)), '..', '..');
const NODE_MODULES = join(ROOT_PATH, 'node_modules');
@@ -55,5 +55,14 @@ if (!arraysHaveSameItems(prevTopLevelPatterns, currentTopLevelPatterns)) {
console.error(
'[WARNING] package.json changed significantly. Removing node_modules to be sure there are no problems.',
);
- await rm(NODE_MODULES, { recursive: true, force: true });
+ // sameersbn/gitlab : avoid removing NODE_MODULES directly, iterate its content instead
+ // The path NODE_MODULES is declared as docker volume - always busy so that cannot be removed
+ // before iterating, check if the directory exists
+ const isDirectory = await stat(NODE_MODULES).then((stat) => stat.isDirectory()).catch(() => false);
+ if(isDirectory) {
+ for (const dir_ent of await readdir(NODE_MODULES, { withFileTypes: true})) {
+ const to_remove = join(NODE_MODULES, dir_ent.name);
+ await rm(to_remove, { recursive: true, force: true });
+ }
+ }
}