Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-09-07 03:09:45 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-09-07 03:09:45 +0300
commitd8f61f6383a930a4b25455fd8ccf624fa313bb07 (patch)
treed1a4eca43aa9a251ae37e9747f4461bebe9445fa /scripts/frontend
parent179a30a49dbbbf4de03f28ac0fe9a8925d5f4883 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'scripts/frontend')
-rw-r--r--scripts/frontend/preinstall.mjs59
-rwxr-xr-xscripts/frontend/webpack_dev_server.js14
2 files changed, 65 insertions, 8 deletions
diff --git a/scripts/frontend/preinstall.mjs b/scripts/frontend/preinstall.mjs
new file mode 100644
index 00000000000..09d980344ea
--- /dev/null
+++ b/scripts/frontend/preinstall.mjs
@@ -0,0 +1,59 @@
+import { dirname, join } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { readFile, rm } from 'node:fs/promises';
+
+const ROOT_PATH = join(dirname(fileURLToPath(import.meta.url)), '..', '..');
+const NODE_MODULES = join(ROOT_PATH, 'node_modules');
+const INTEGRITY_FILE = join(NODE_MODULES, '.yarn-integrity');
+const PACKAGE_JSON = join(ROOT_PATH, 'package.json');
+
+function isAliasedDependency(x) {
+ return x.includes('@npm:');
+}
+function serializeAliasedDependencyPatterns(obj) {
+ return Object.entries(obj).map(([key, version]) => `${key}@${version}`);
+}
+
+async function readJSON(file) {
+ return JSON.parse(await readFile(file, { encoding: 'utf-8' }));
+}
+
+async function getPrevTopLevelPatterns() {
+ try {
+ return (await readJSON(INTEGRITY_FILE))?.topLevelPatterns?.filter(isAliasedDependency);
+ } catch {
+ return [];
+ }
+}
+async function getCurrentTopLevelPatterns() {
+ try {
+ const { dependencies, devDependencies } = await readJSON(PACKAGE_JSON);
+
+ return serializeAliasedDependencyPatterns(dependencies)
+ .concat(serializeAliasedDependencyPatterns(devDependencies))
+ .filter(isAliasedDependency);
+ } catch {
+ return [];
+ }
+}
+
+function arraysHaveSameItems(a1, a2) {
+ return JSON.stringify(a1.sort()) === JSON.stringify(a2.sort());
+}
+
+const [prevTopLevelPatterns, currentTopLevelPatterns] = await Promise.all([
+ getPrevTopLevelPatterns(),
+ getCurrentTopLevelPatterns(),
+]);
+
+/**
+ * Yarn seems to have problems at times, if one uses an <alias>@npm:<name>
+ * and those packages are being updated. In case one switches branches the
+ * node_modules folder seems to end up being a corrupted somehow
+ */
+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 });
+}
diff --git a/scripts/frontend/webpack_dev_server.js b/scripts/frontend/webpack_dev_server.js
index a76e6dc024a..ae73c14b501 100755
--- a/scripts/frontend/webpack_dev_server.js
+++ b/scripts/frontend/webpack_dev_server.js
@@ -30,17 +30,15 @@ if (STATIC_MODE) {
// run webpack through webpack-dev-server, optionally compiling a DLL to reduce memory
else {
- const watch = ['config/webpack.config.js'];
+ const watch = [
+ 'config/webpack.config.js',
+ // ensure we refresh when running yarn install
+ 'node_modules/.yarn-integrity',
+ ];
// if utilizing the vendor DLL, we need to restart the process when dependency changes occur
if (DLL_MODE) {
- watch.push(
- 'config/webpack.vendor.config.js',
- // ensure we refresh when running yarn install
- 'node_modules/.yarn-integrity',
- 'package.json',
- 'yarn.lock',
- );
+ watch.push('config/webpack.vendor.config.js', 'package.json', 'yarn.lock');
}
nodemon({
exec: 'webpack-dev-server --config config/webpack.config.js',