git: 01c33f63b62f - main - textproc/opensearch-dashboards: Fix startup after node14 update

From: Romain Tartière <romain_at_FreeBSD.org>
Date: Tue, 09 Aug 2022 04:40:43 UTC
The branch main has been updated by romain:

URL: https://cgit.FreeBSD.org/ports/commit/?id=01c33f63b62fe112782908ab9f926a36ec144f09

commit 01c33f63b62fe112782908ab9f926a36ec144f09
Author:     Romain Tartière <romain@FreeBSD.org>
AuthorDate: 2022-08-09 04:27:50 +0000
Commit:     Romain Tartière <romain@FreeBSD.org>
CommitDate: 2022-08-09 04:40:28 +0000

    textproc/opensearch-dashboards: Fix startup after node14 update
    
    PR:             265717
    With hat:       opensearch
---
 textproc/opensearch-dashboards/Makefile             |  1 +
 ...src_setup__node__env_node__version__validator.js | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/textproc/opensearch-dashboards/Makefile b/textproc/opensearch-dashboards/Makefile
index 8e0365f4e303..2ff215926a43 100644
--- a/textproc/opensearch-dashboards/Makefile
+++ b/textproc/opensearch-dashboards/Makefile
@@ -1,6 +1,7 @@
 PORTNAME=	opensearch-dashboards
 DISTVERSION=	2.1.0
 DISTVERSIONSUFFIX=	-linux-x64
+PORTREVISION=	1
 CATEGORIES=	textproc www
 MASTER_SITES=	https://artifacts.opensearch.org/releases/bundle/${PORTNAME}/${DISTVERSION}/
 
diff --git a/textproc/opensearch-dashboards/files/patch-src_setup__node__env_node__version__validator.js b/textproc/opensearch-dashboards/files/patch-src_setup__node__env_node__version__validator.js
new file mode 100644
index 000000000000..b78a0bf27cc9
--- /dev/null
+++ b/textproc/opensearch-dashboards/files/patch-src_setup__node__env_node__version__validator.js
@@ -0,0 +1,21 @@
+--- src/setup_node_env/node_version_validator.js.orig	2022-06-30 21:38:00 UTC
++++ src/setup_node_env/node_version_validator.js
+@@ -36,13 +36,13 @@ var pkg = require('../../package.json'); // Note: This
+ var currentVersion = process && process.version || null;
+ var rawRequiredVersion = pkg && pkg.engines && pkg.engines.node || null;
+ var requiredVersion = rawRequiredVersion ? 'v' + rawRequiredVersion : rawRequiredVersion;
+-var currentVersionMajorMinorPatch = currentVersion.match(/^v(\d+)\.(\d+)\.(\d+)/);
+-var requiredVersionMajorMinorPatch = requiredVersion.match(/^v(\d+)\.(\d+)\.(\d+)/);
+-var isVersionValid = currentVersionMajorMinorPatch[1] === requiredVersionMajorMinorPatch[1] && currentVersionMajorMinorPatch[2] === requiredVersionMajorMinorPatch[2] && parseInt(currentVersionMajorMinorPatch[3], 10) >= parseInt(requiredVersionMajorMinorPatch[3], 10); // Validates current the NodeJS version compatibility when OpenSearch Dashboards starts.
++var currentVersionMajorMinorPatch = currentVersion.match(/^v(\d+)\.(\d+)\.(\d+)/).map(x => parseInt(x, 10));
++var requiredVersionMajorMinorPatch = requiredVersion.match(/^v(\d+)\.(\d+)\.(\d+)/).map(x => parseInt(x, 10));
++var isVersionValid = currentVersionMajorMinorPatch[1] === requiredVersionMajorMinorPatch[1] && currentVersionMajorMinorPatch[2] > requiredVersionMajorMinorPatch[2] || currentVersionMajorMinorPatch[1] === requiredVersionMajorMinorPatch[1] && currentVersionMajorMinorPatch[2] === requiredVersionMajorMinorPatch[2] && currentVersionMajorMinorPatch[3] >= requiredVersionMajorMinorPatch[3]; // Validates current the NodeJS version compatibility when OpenSearch Dashboards starts.
+ 
+ if (!isVersionValid) {
+   var errorMessage = `OpenSearch Dashboards was built with ${requiredVersion} and does not support the current Node.js version ${currentVersion}. ` + `Please use Node.js ${requiredVersion} or a higher patch version.`; // Actions to apply when validation fails: error report + exit.
+ 
+   console.error(errorMessage);
+   process.exit(1);
+-}
+\ No newline at end of file
++}