From f76b78dd623c192a81ba9b0337caeaaeb5127ff1 Mon Sep 17 00:00:00 2001
From: Tomas Cohen Arazi <tomascohen@theke.io>
Date: Wed, 7 Dec 2022 16:16:58 -0300
Subject: [PATCH] Bug 32422: Hardcoded paths in _common.scss precent using
 external node_modules

This patch makes:

- gulpfile.js add the parent dir's node_modules to the sass include path
- removes hardcoded paths from _common.scss

To test:
1. Have the latest KTD image (this is not KTD specific, but easier to
   test)
2. Make sure you don't have any node_modules/ dir in your koha clone
3. Run:
   $ kshell
  k$ yarn build --view opac
=> FAIL: You get:
kohadev-koha@kohadevbox:/kohadevbox/koha$ yarn build --view opac
yarn run v1.22.19
$ gulp build --view opac
[18:27:38] Using gulpfile /kohadevbox/koha/gulpfile.js
[18:27:38] Starting 'build'...
Error in plugin 'sass'
Message:
    koha-tmpl/opac-tmpl/bootstrap/css/src/_common.scss
Error: File to import not found or unreadable: ../../../../../node_modules/bootstrap/scss/functions.
        on line 37 of koha-tmpl/opac-tmpl/bootstrap/css/src/_common.scss
        from line 1 of koha-tmpl/opac-tmpl/bootstrap/css/src/opac.scss
>> @import "../../../../../node_modules/bootstrap/scss/functions";

   ^

4. Apply this patch
5. Repeat 3
=> SUCCESS: It builds!
6. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
---
 gulpfile.js                                   |  6 +-
 .../opac-tmpl/bootstrap/css/src/_common.scss  | 92 +++++++++----------
 2 files changed, 51 insertions(+), 47 deletions(-)

diff --git a/gulpfile.js b/gulpfile.js
index f41f53afb89..a17b66effe6 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -37,7 +37,11 @@ if (args.view == "opac") {
 
 var sassOptions = {
     errLogToConsole: true,
-    precision: 3
+    precision: 3,
+    includePaths: [
+        __dirname + '/node_modules',
+        __dirname + '/../node_modules'
+    ]
 }
 
 // CSS processing for development
diff --git a/koha-tmpl/opac-tmpl/bootstrap/css/src/_common.scss b/koha-tmpl/opac-tmpl/bootstrap/css/src/_common.scss
index ec6da81fe1f..36d45f39b6a 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/css/src/_common.scss
+++ b/koha-tmpl/opac-tmpl/bootstrap/css/src/_common.scss
@@ -34,52 +34,52 @@ $high-contrast-grey: #666666;
 }
 
 /* Bootstrap imports */
-@import "../../../../../node_modules/bootstrap/scss/functions";
-@import "../../../../../node_modules/bootstrap/scss/variables";
-@import "../../../../../node_modules/bootstrap/scss/mixins";
-@import "../../../../../node_modules/bootstrap/scss/alert";
-
-// @import "../../../../../node_modules/bootstrap/scss/badge";
-@import "../../../../../node_modules/bootstrap/scss/breadcrumb";
-@import "../../../../../node_modules/bootstrap/scss/button-group";
-@import "../../../../../node_modules/bootstrap/scss/buttons";
-@import "../../../../../node_modules/bootstrap/scss/card";
-
-// @import "../../../../../node_modules/bootstrap/scss/carousel";
-@import "../../../../../node_modules/bootstrap/scss/close";
-
-// @import "../../../../../node_modules/bootstrap/scss/code";
-@import "../../../../../node_modules/bootstrap/scss/custom-forms";
-@import "../../../../../node_modules/bootstrap/scss/dropdown";
-@import "../../../../../node_modules/bootstrap/scss/forms";
-@import "../../../../../node_modules/bootstrap/scss/grid";
-
-// @import "../../../../../node_modules/bootstrap/scss/images";
-@import "../../../../../node_modules/bootstrap/scss/input-group";
-
-// @import "../../../../../node_modules/bootstrap/scss/jumbotron";
-// @import "../../../../../node_modules/bootstrap/scss/list-group";
-// @import "../../../../../node_modules/bootstrap/scss/media";
-@import "../../../../../node_modules/bootstrap/scss/modal";
-@import "../../../../../node_modules/bootstrap/scss/navbar";
-@import "../../../../../node_modules/bootstrap/scss/nav";
-@import "../../../../../node_modules/bootstrap/scss/pagination";
-
-// @import "../../../../../node_modules/bootstrap/scss/popover";
-@import "../../../../../node_modules/bootstrap/scss/print";
-
-// @import "../../../../../node_modules/bootstrap/scss/progress";
-@import "../../../../../node_modules/bootstrap/scss/reboot";
-@import "../../../../../node_modules/bootstrap/scss/root";
-
-// @import "../../../../../node_modules/bootstrap/scss/spinners";
-@import "../../../../../node_modules/bootstrap/scss/tables";
-
-// @import "../../../../../node_modules/bootstrap/scss/toasts";
-@import "../../../../../node_modules/bootstrap/scss/tooltip";
-@import "../../../../../node_modules/bootstrap/scss/transitions";
-@import "../../../../../node_modules/bootstrap/scss/type";
-@import "../../../../../node_modules/bootstrap/scss/utilities";
+@import "bootstrap/scss/functions";
+@import "bootstrap/scss/variables";
+@import "bootstrap/scss/mixins";
+@import "bootstrap/scss/alert";
+
+// @import "bootstrap/scss/badge";
+@import "bootstrap/scss/breadcrumb";
+@import "bootstrap/scss/button-group";
+@import "bootstrap/scss/buttons";
+@import "bootstrap/scss/card";
+
+// @import "bootstrap/scss/carousel";
+@import "bootstrap/scss/close";
+
+// @import "bootstrap/scss/code";
+@import "bootstrap/scss/custom-forms";
+@import "bootstrap/scss/dropdown";
+@import "bootstrap/scss/forms";
+@import "bootstrap/scss/grid";
+
+// @import "bootstrap/scss/images";
+@import "bootstrap/scss/input-group";
+
+// @import "bootstrap/scss/jumbotron";
+// @import "bootstrap/scss/list-group";
+// @import "bootstrap/scss/media";
+@import "bootstrap/scss/modal";
+@import "bootstrap/scss/navbar";
+@import "bootstrap/scss/nav";
+@import "bootstrap/scss/pagination";
+
+// @import "bootstrap/scss/popover";
+@import "bootstrap/scss/print";
+
+// @import "bootstrap/scss/progress";
+@import "bootstrap/scss/reboot";
+@import "bootstrap/scss/root";
+
+// @import "bootstrap/scss/spinners";
+@import "bootstrap/scss/tables";
+
+// @import "bootstrap/scss/toasts";
+@import "bootstrap/scss/tooltip";
+@import "bootstrap/scss/transitions";
+@import "bootstrap/scss/type";
+@import "bootstrap/scss/utilities";
 @import "flatpickr";
 
 /* Koha imports */
-- 
2.34.1