From d50c2000dd52a0878170f45611474472fd4b6ede Mon Sep 17 00:00:00 2001
From: orozot <ztren@gitlab.cn>
Date: Wed, 24 Nov 2021 16:20:46 +0000
Subject: [PATCH] Add jh_else_ee and any_else_ce support for webpack alias

- https://gitlab.com/gitlab-org/gitlab/-/issues/345477
- https://gitlab.com/gitlab-org/gitlab/-/merge_requests/74305
---
 config/webpack.config.js | 8 ++++++++
 jest.config.base.js      | 8 +++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/config/webpack.config.js b/config/webpack.config.js
index f334e17bbafab..7eaa11d93466c 100644
--- a/config/webpack.config.js
+++ b/config/webpack.config.js
@@ -163,6 +163,9 @@ const alias = {
   // the following resolves files which are different between CE and JH
   jh_else_ce: path.join(ROOT_PATH, 'app/assets/javascripts'),
 
+  // the following resolves files which are different between CE/EE/JH
+  any_else_ce: path.join(ROOT_PATH, 'app/assets/javascripts'),
+
   // override loader path for icons.svg so we do not duplicate this asset
   '@gitlab/svgs/dist/icons.svg': path.join(
     ROOT_PATH,
@@ -179,6 +182,8 @@ if (IS_EE) {
     ee_images: path.join(ROOT_PATH, 'ee/app/assets/images'),
     ee_jest: path.join(ROOT_PATH, 'ee/spec/frontend'),
     ee_else_ce: path.join(ROOT_PATH, 'ee/app/assets/javascripts'),
+    jh_else_ee: path.join(ROOT_PATH, 'ee/app/assets/javascripts'),
+    any_else_ce: path.join(ROOT_PATH, 'ee/app/assets/javascripts'),
   });
 }
 
@@ -190,7 +195,10 @@ if (IS_JH) {
     jh_icons: path.join(ROOT_PATH, 'jh/app/views/shared/icons'),
     jh_images: path.join(ROOT_PATH, 'jh/app/assets/images'),
     jh_jest: path.join(ROOT_PATH, 'jh/spec/frontend'),
+    // jh path alias https://gitlab.com/gitlab-org/gitlab/-/merge_requests/74305#note_732793956
     jh_else_ce: path.join(ROOT_PATH, 'jh/app/assets/javascripts'),
+    jh_else_ee: path.join(ROOT_PATH, 'jh/app/assets/javascripts'),
+    any_else_ce: path.join(ROOT_PATH, 'jh/app/assets/javascripts'),
   });
 }
 
diff --git a/jest.config.base.js b/jest.config.base.js
index d1478987fb8ec..f2a7422303d92 100644
--- a/jest.config.base.js
+++ b/jest.config.base.js
@@ -51,6 +51,7 @@ module.exports = (path, options = {}) => {
     '^shared_queries(/.*)$': '<rootDir>/app/graphql/queries$1',
     '^ee_else_ce(/.*)$': '<rootDir>/app/assets/javascripts$1',
     '^jh_else_ce(/.*)$': '<rootDir>/app/assets/javascripts$1',
+    '^any_else_ce(/.*)$': '<rootDir>/app/assets/javascripts$1',
     '^helpers(/.*)$': '<rootDir>/spec/frontend/__helpers__$1',
     '^vendor(/.*)$': '<rootDir>/vendor/assets/javascripts$1',
     [TEST_FIXTURES_PATTERN]: '<rootDir>/tmp/tests/frontend/fixtures$1',
@@ -72,6 +73,8 @@ module.exports = (path, options = {}) => {
       '^ee_component(/.*)$': rootDirEE,
       '^ee_else_ce(/.*)$': rootDirEE,
       '^ee_jest/(.*)$': '<rootDir>/ee/spec/frontend/$1',
+      '^any_else_ce(/.*)$': rootDirEE,
+      '^jh_else_ee(/.*)$': rootDirEE,
       [TEST_FIXTURES_PATTERN]: '<rootDir>/tmp/tests/frontend/fixtures-ee$1',
       ...extModuleNameMapperEE,
     });
@@ -84,8 +87,11 @@ module.exports = (path, options = {}) => {
     Object.assign(moduleNameMapper, {
       '^jh(/.*)$': rootDirJH,
       '^jh_component(/.*)$': rootDirJH,
-      '^jh_else_ce(/.*)$': rootDirJH,
       '^jh_jest/(.*)$': '<rootDir>/jh/spec/frontend/$1',
+      // jh path alias https://gitlab.com/gitlab-org/gitlab/-/merge_requests/74305#note_732793956
+      '^jh_else_ce(/.*)$': rootDirJH,
+      '^jh_else_ee(/.*)$': rootDirJH,
+      '^any_else_ce(/.*)$': rootDirJH,
       ...extModuleNameMapperJH,
     });
 
-- 
GitLab