Skip to content

Commit da0d78b

Browse files
committed
Add build patch to avoid removing node_modules
note: Only affected if using the relative_url feature `gitlab/script/frontent/preinstall.mjs` is introduced since v16.4.0. This script is executed on container startup, if using the relative url. This script removes `NODE_MODULES` (/home/git/gitlab/node_modules) when "the folder seems to end up being a corrupted somehow" See more detail: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/130938 On sameersbn/gitlab, the folder node_modules is declared as volume. The volume is always busy so that cannot be removed in the container. You can see following error reported on container startup (sameersbn/gitlab:16.4.0 or later). ```` yarn install v1.22.19 $ node ./scripts/frontend/preinstall.mjs [WARNING] package.json changed significantly. Removing node_modules to be sure there are no problems. node:internal/process/esm_loader:97 internalBinding('errors').triggerUncaughtException( ^ [Error: EBUSY: resource busy or locked, rmdir '/home/git/gitlab/node_modules'] { errno: -16, code: 'EBUSY', syscall: 'rmdir', path: '/home/git/gitlab/node_modules' } Node.js v18.17.1 error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. ----- ```` This PR add a build time patch to change the behavior of script/frontend/preinstall.mjs to not to remove node_modules directly, but empty it instead.
1 parent 52e1461 commit da0d78b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
diff --git a/scripts/frontend/preinstall.mjs b/scripts/frontend/preinstall.mjs
2+
index 09d980344eac..b1514e803b75 100644
3+
--- a/scripts/frontend/preinstall.mjs
4+
+++ b/scripts/frontend/preinstall.mjs
5+
@@ -1,6 +1,6 @@
6+
import { dirname, join } from 'node:path';
7+
import { fileURLToPath } from 'node:url';
8+
-import { readFile, rm } from 'node:fs/promises';
9+
+import { readdir, readFile, rm, stat } from 'node:fs/promises';
10+
11+
const ROOT_PATH = join(dirname(fileURLToPath(import.meta.url)), '..', '..');
12+
const NODE_MODULES = join(ROOT_PATH, 'node_modules');
13+
@@ -55,5 +55,14 @@ if (!arraysHaveSameItems(prevTopLevelPatterns, currentTopLevelPatterns)) {
14+
console.error(
15+
'[WARNING] package.json changed significantly. Removing node_modules to be sure there are no problems.',
16+
);
17+
- await rm(NODE_MODULES, { recursive: true, force: true });
18+
+ // sameersbn/gitlab : avoid removing NODE_MODULES directly, iterate its content instead
19+
+ // The path NODE_MODULES is declared as docker volume - always busy so that cannot be removed
20+
+ // before iterating, check if the directory exists
21+
+ const isDirectory = await stat(NODE_MODULES).then((stat) => stat.isDirectory()).catch(() => false);
22+
+ if(isDirectory) {
23+
+ for (const dir_ent of await readdir(NODE_MODULES, { withFileTypes: true})) {
24+
+ const to_remove = join(NODE_MODULES, dir_ent.name);
25+
+ await rm(to_remove, { recursive: true, force: true });
26+
+ }
27+
+ }
28+
}

0 commit comments

Comments
 (0)