commit 0d360971d99bb75f603244b0e5681668fb212747 Author: Adrian Schröter Date: Mon Aug 7 12:49:11 2023 +0200 Sync from SUSE:ALP:Source:Standard:1.0 nodejs-common revision 0e585c1641d614246f0484de5f289618 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fecc750 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,23 @@ +## Default LFS +*.7z filter=lfs diff=lfs merge=lfs -text +*.bsp filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.gem filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.jar filter=lfs diff=lfs merge=lfs -text +*.lz filter=lfs diff=lfs merge=lfs -text +*.lzma filter=lfs diff=lfs merge=lfs -text +*.obscpio filter=lfs diff=lfs merge=lfs -text +*.oxt filter=lfs diff=lfs merge=lfs -text +*.pdf filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text +*.rpm filter=lfs diff=lfs merge=lfs -text +*.tbz filter=lfs diff=lfs merge=lfs -text +*.tbz2 filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.ttf filter=lfs diff=lfs merge=lfs -text +*.txz filter=lfs diff=lfs merge=lfs -text +*.whl filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b580453 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/node.c b/node.c new file mode 100644 index 0000000..e2c56fc --- /dev/null +++ b/node.c @@ -0,0 +1,101 @@ +#define _GNU_SOURCE + +#include +#include +#include +#include + +#ifdef HAVE_LIBALTERNATIVES_H +#include +#endif + +const unsigned min_version = 4; +const unsigned max_version = 42; +const char *default_version = "-default"; + +const char * const supported_execs[] = { + "node", + "npm", + "npx", + NULL +}; + + +static void __attribute__((noreturn)) printInvalidVersion(const char *version) { + fprintf(stderr, "Invalid node version: %s\n", version); + exit(-2); +} + + +int main(int argc, char *argv[]) +{ + if (argc < 1) { + fprintf(stderr, "Invalid parameters ... no basename?\n"); + return 128; + } + + /* Verify we are called with supported name */ + const char *program_name = basename(argv[0]); + const char * const * bn = supported_execs; + + for (; *bn!=NULL; bn++) { + if (strcmp(*bn, program_name) == 0) + break; + } + + if (*bn == NULL) { + fprintf(stderr, "Invalid program called: '%s'\n", program_name); + return 129; + } + + /* Verify we have one of probably supported versions */ + const char *version = getenv("NODE_VERSION"); + char *endptr = 0; + if (version == NULL || strcmp(version, default_version) == 0) + version = default_version; + + unsigned long node_ver = strtoul(version, &endptr, 10); + + if (*endptr == '\0' && + ( node_ver < min_version || node_ver > max_version)) + { + printInvalidVersion(version); + } + else if (*endptr != '\0' && version != default_version) + { + printInvalidVersion(version); + } + +#ifdef HAVE_LIBALTERNATIVES_H + // if we want default version and not using update-alternatives + if (version == default_version) + { + // should not return, and if it does, it probably means + // we should fall back to using node-default fallback. + libalts_exec_default(argv); + // some programs parse stderr, so let's be quiet here. + //fputs("Falling back to using -default symlink.\n", stderr); + } +#endif + + /* Generate our program path and check that we can execute it */ + char *program_path, *program; + if (asprintf(&program, "%s%s", *bn, version) == -1 || + asprintf(&program_path, "/usr/bin/%s", program) == -1) { + + fputs("Memory allocation error... terminating\n", stderr); + return 130; + } + + if (access(program_path, X_OK) != 0) { + perror(program_path); + return -1; + } + + argv[0] = program; + + execv(program_path, argv); + perror("execv failed"); + return -1; +} + diff --git a/nodejs-common.changes b/nodejs-common.changes new file mode 100644 index 0000000..f508001 --- /dev/null +++ b/nodejs-common.changes @@ -0,0 +1,135 @@ +------------------------------------------------------------------- +Thu Jun 15 12:37:25 UTC 2023 - Adam Majer + +- Rework default versions and include specifics for ALP +- Default version for SLE-12 is set to be 16 - no further updates + expected since W&S module is not supported in LTSS + +------------------------------------------------------------------- +Tue Apr 25 02:11:10 UTC 2023 - jsrain@suse.com + +- Use NodeJS 18 as default for ALP + +------------------------------------------------------------------- +Wed Apr 19 13:38:14 UTC 2023 - Adam Majer + +- Use NodeJS 20 as default for TW + +------------------------------------------------------------------- +Fri Oct 21 10:09:34 UTC 2022 - Adam Majer + +- Use NodeJS 19 as default for TW + +------------------------------------------------------------------- +Sun Jul 31 15:51:38 UTC 2022 - Adam Majer + +- Use NodeJS 18 as default for TW and for SLE15 SP5 + +------------------------------------------------------------------- +Wed Jan 12 09:17:01 UTC 2022 - Adam Majer + +- Use NodeJS 17 as default for TW + +------------------------------------------------------------------- +Mon Jun 21 05:01:32 UTC 2021 - Andreas Schneider + +- Allow building for Fedora in the OBS + +------------------------------------------------------------------- +Fri Jun 18 19:29:10 UTC 2021 - Adam Majer + +- Some applications do not like warnings or notices on stderr + as they use it for other things. So make nodejs-common quiet + unless we have a fatal error. + +------------------------------------------------------------------- +Thu Jun 10 10:27:58 UTC 2021 - Adam Majer + +- Use libalternatives on TW by default + +------------------------------------------------------------------- +Mon May 31 16:32:18 UTC 2021 - Adam Majer + +- Add libalternatives support + +------------------------------------------------------------------- +Thu May 6 12:50:02 UTC 2021 - Adam Majer + +- Enable 32-bit arches again on latest node for TW +- Set TW to nodejs16 +- Set nodejs14 for SP3 as default and nodejs16 for SP4 + +------------------------------------------------------------------- +Thu Apr 29 09:33:20 UTC 2021 - Dominique Leuenberger + +- Provide nodejs(engine) by nodejs-common: nodejs-packaging happens + to read the engines parameter from the json files and it's a + nice-to-have if OBS can find out what the default nodejs engine + to use. + +------------------------------------------------------------------- +Thu Apr 15 12:35:21 UTC 2021 - Guillaume GARDET + +- Use older nodejs (10) for %{arm} + +------------------------------------------------------------------- +Tue Mar 9 17:29:00 UTC 2021 - Adam Majer + +- Provide nodejs and npm and nodejs-devel by the appropriate + defaults package + +------------------------------------------------------------------- +Tue Jan 19 11:33:38 UTC 2021 - Adam Majer + +- set nodejs14 as default for sle15-sp3+ +- set nodejs15 as default for TW + +------------------------------------------------------------------- +Tue Jun 9 10:35:06 UTC 2020 - Adam Majer + +- Add nodejs-default, npm-default and nodejs-devel-default subpackages + to provide latest, best supported nodejs for current architecture + and codestream. + + nodejs-default - nodejs runtime only + npm-default - if you need npm + nodejs + nodejs-devel-default - if you need npm + nodejs + compile modules + +------------------------------------------------------------------- +Mon Dec 30 13:49:36 UTC 2019 - Adam Majer + +- Bump max supported version to 42 to account for automatically + built master branch called nodejs42 + +------------------------------------------------------------------- +Mon Oct 28 11:13:23 UTC 2019 - Adam Majer + +- Remove extra -g from compiler command-line + +------------------------------------------------------------------- +Fri Feb 1 15:03:12 UTC 2019 - adam.majer@suse.de + +- Change the shell script to regular executable + +------------------------------------------------------------------- +Fri Jun 22 12:31:05 UTC 2018 - dcassany@suse.de + +- Add LICENSE text to the package + +------------------------------------------------------------------- +Wed Aug 2 14:29:04 UTC 2017 - adam.majer@suse.de + +- NodeJS 8.2.0 adds support for `npx` binary. Add conditional + support to our wrapper +- Print a helpful message if wrapper cannot find target executable +- Wrapper only executes from /usr/bin and not PATH + +------------------------------------------------------------------- +Tue Jul 18 10:20:06 UTC 2017 - adam.majer@suse.de + +- Use MIT license so we don't have to ship the license text. + +------------------------------------------------------------------- +Fri Jul 7 13:09:29 UTC 2017 - adam.majer@suse.de + +- Initial release. diff --git a/nodejs-common.spec b/nodejs-common.spec new file mode 100644 index 0000000..a01b71f --- /dev/null +++ b/nodejs-common.spec @@ -0,0 +1,166 @@ +# +# spec file for package nodejs-common +# +# Copyright (c) 2023 SUSE LLC +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via https://bugs.opensuse.org/ +# + + +########################################################### +# +# WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! +# +# This spec file is generated from a template hosted at +# https://github.com/AdamMajer/nodejs-packaging +# +########################################################### + +%define NODEJS_LTS 18 +%define NODEJS_CURRENT 20 + +%if 0%{?suse_version} > 1500 || 0%{?fedora_version} +%bcond_without libalternatives +%else +%bcond_with libalternatives +%endif + +# SLE-12 variants +%if 0%{?suse_version} < 1500 +%define default_node_ver 16 +%endif + +%if 0%{?suse_version} == 1500 + +# SLE-15 variants, variation based on SP +%if 0%{?sle_version} >= 150000 && 0%{?sle_version} < 150200 +%define default_node_ver 10 +%endif + +%if 0%{?sle_version} >= 150200 && 0%{?sle_version} < 150300 +%define default_node_ver 12 +%endif + +%if 0%{?sle_version} >= 150300 && 0%{?sle_version} < 150400 +%define default_node_ver 14 +%endif + +%if 0%{?sle_version} >= 150400 && 0%{?sle_version} < 150500 +%define default_node_ver 16 +%endif + +%if 0%{?sle_version} >= 150500 && 0%{?sle_version} < 150600 +%define default_node_ver 18 +%endif + +%if 0%{?sle_version} >= 150600 && 0%{?sle_version} < 150700 +%define default_node_ver 20 +%endif + +# SLE-15 variants +%endif + +%if 0%{?suse_version} == 1600 +# ALP variants +%define default_node_ver 20 +%endif + +# TW +%if 0%{?suse_version} >= 1699 +%define default_node_ver %NODEJS_CURRENT +%endif + +Name: nodejs-common +Version: 6.0 +Release: 0 +Summary: Common files for the NodeJS ecosystem +License: MIT +Group: Development/Languages/NodeJS +URL: https://github.com/AdamMajer/nodejs-packaging +Source1: node.c +Source2: LICENSE +Requires: nodejs +Conflicts: nodejs4 < 4.8.4 +Conflicts: nodejs6 < 6.11.1 +Conflicts: nodejs7 < 7.10.1 +Conflicts: nodejs8 < 8.1.4 +BuildRequires: gcc +%if %{with libalternatives} +BuildRequires: libalternatives-devel +%define libalternatives_cflags -DHAVE_LIBALTERNATIVES_H +%define libalternatives_lflags -lalternatives +%endif + +%description +Common NodeJS files that allow recursive invocation of Node executable +while retaining the same codestream version. + +%package -n nodejs-default +Summary: Default version of nodejs +Group: Development/Languages/NodeJS +Requires: nodejs%{default_node_ver} +Requires: nodejs-common +Provides: nodejs = %default_node_ver +Provides: nodejs(engine) = %default_node_ver + +%description -n nodejs-default +Depends on the most current and recommended version of nodejs for +the current architecture and codestream. + +%package -n npm-default +Summary: Default version of npm +Group: Development/Languages/NodeJS +Requires: nodejs-default +Requires: npm%{default_node_ver} +Provides: npm = %default_node_ver + +%description -n npm-default +Depends on the npm version associated with the current default +version of nodejs for the current architecture and codestream. + +%package -n nodejs-devel-default +Summary: Headers for default version of nodejs +Group: Development/Languages/NodeJS +Requires: nodejs%{default_node_ver}-devel +Requires: npm-default +Provides: nodejs-devel = %default_node_ver + +%description -n nodejs-devel-default +Depends on the most current and up-to-date version of nodejs for +the current architecture and codestream. + +%prep + +%build +cp %{S:2} . +gcc ${RPM_OPT_FLAGS} %?libalternatives_cflags -o node %{S:1} %?libalternatives_lflags + +echo "Default Node version: " %{default_node_ver} + +%install +install -D -m 0755 node %{buildroot}%{_bindir}/node +ln node %{buildroot}%{_bindir}/npm +ln node %{buildroot}%{_bindir}/npx + +%files +%license LICENSE +%{_bindir}/node +%{_bindir}/npm +%{_bindir}/npx + +%files -n nodejs-default + +%files -n npm-default + +%files -n nodejs-devel-default + +%changelog