From 49a6133d90bab4aeb59ffb291a4b32b618b80643 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Mon, 4 Apr 2022 17:03:35 +0200
Subject: [PATCH] Issue #3272872 by nod_: deprecate underscore and mark it
 internal

---
 core/core.libraries.yml                       | 20 ++++++++++++++++++-
 core/modules/editor/editor.libraries.yml      |  2 +-
 core/modules/filter/filter.libraries.yml      |  2 +-
 core/modules/image/image.libraries.yml        |  2 +-
 .../modules/quickedit/quickedit.libraries.yml |  2 +-
 core/scripts/js/vendor-update.js              |  5 +++++
 6 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/core/core.libraries.yml b/core/core.libraries.yml
index 6a16429a4525..21e7989125ed 100644
--- a/core/core.libraries.yml
+++ b/core/core.libraries.yml
@@ -10,7 +10,7 @@ backbone:
   js:
     assets/vendor/backbone/backbone-min.js: { weight: -19, minified: true }
   dependencies:
-    - core/underscore
+    - core/internal.underscore
 
 ckeditor:
   remote: https://github.com/ckeditor/ckeditor4
@@ -1082,6 +1082,24 @@ underscore:
     gpl-compatible: true
   js:
     assets/vendor/underscore/underscore-min.js: { weight: -20, minified: true }
+  deprecated: The %library_id% asset library is deprecated in Drupal 9.4.0 and will be removed in Drupal 10.0.0.
+
+internal.underscore:
+  # Internal library, do not depend on it.
+  # The library will be removed as soon as the following issues are fixed:
+  #  - https://www.drupal.org/project/drupal/issues/3270395
+  #  - https://www.drupal.org/project/drupal/issues/3203920
+  #  - https://www.drupal.org/project/drupal/issues/3204011
+  #  - https://www.drupal.org/project/drupal/issues/3204015
+  remote: https://github.com/jashkenas/underscore
+  version: "1.13.2"
+  license:
+    name: MIT
+    url: https://raw.githubusercontent.com/jashkenas/underscore/1.13.2/LICENSE
+    gpl-compatible: true
+  js:
+    assets/vendor/underscore/underscore-min.js: { weight: -20, minified: true }
+
 
 drupal.dialog.off_canvas:
   version: VERSION
diff --git a/core/modules/editor/editor.libraries.yml b/core/modules/editor/editor.libraries.yml
index 20678413309f..bf8566180865 100644
--- a/core/modules/editor/editor.libraries.yml
+++ b/core/modules/editor/editor.libraries.yml
@@ -6,7 +6,7 @@ drupal.editor.admin:
     - core/jquery
     - core/once
     - core/drupal
-    - core/underscore
+    - core/internal.underscore
 
 drupal.editor:
   version: VERSION
diff --git a/core/modules/filter/filter.libraries.yml b/core/modules/filter/filter.libraries.yml
index f3ad11443411..00767d525563 100644
--- a/core/modules/filter/filter.libraries.yml
+++ b/core/modules/filter/filter.libraries.yml
@@ -15,7 +15,7 @@ drupal.filter.filter_html.admin:
   dependencies:
     - core/jquery
     - core/once
-    - core/underscore
+    - core/internal.underscore
 
 drupal.filter:
   version: VERSION
diff --git a/core/modules/image/image.libraries.yml b/core/modules/image/image.libraries.yml
index a47a2b518f14..14ea11623dfc 100644
--- a/core/modules/image/image.libraries.yml
+++ b/core/modules/image/image.libraries.yml
@@ -17,5 +17,5 @@ quickedit.inPlaceEditor.image:
   dependencies:
     - core/jquery
     - core/drupal
-    - core/underscore
+    - core/internal.underscore
     - quickedit/quickedit
diff --git a/core/modules/quickedit/quickedit.libraries.yml b/core/modules/quickedit/quickedit.libraries.yml
index 1169abbd300d..60cb2f6d4bbc 100644
--- a/core/modules/quickedit/quickedit.libraries.yml
+++ b/core/modules/quickedit/quickedit.libraries.yml
@@ -29,7 +29,7 @@ quickedit:
   dependencies:
     - core/jquery
     - core/once
-    - core/underscore
+    - core/internal.underscore
     - core/backbone
     - core/jquery.form
     - core/drupal
diff --git a/core/scripts/js/vendor-update.js b/core/scripts/js/vendor-update.js
index e74473f166a1..ef2b2c83463f 100644
--- a/core/scripts/js/vendor-update.js
+++ b/core/scripts/js/vendor-update.js
@@ -171,8 +171,13 @@ const assetsFolder = `${coreFolder}/assets/vendor`;
     },
     {
       pack: 'underscore',
+      library: 'internal.underscore',
       files: ['underscore-min.js', 'underscore-min.js.map'],
     },
+    // Only used to update the version number of the deprecated library.
+    {
+      pack: 'underscore',
+    },
     {
       pack: 'loadjs',
       files: [{ from: 'dist/loadjs.min.js', to: 'loadjs.min.js' }],
-- 
GitLab