diff --git a/Berksfile b/Berksfile index 5019974..dad2c52 100644 --- a/Berksfile +++ b/Berksfile @@ -31,7 +31,7 @@ cookbook 'java', '~> 4.3.0' cookbook 'logrotate', '= 2.2.0' cookbook 'mysql', '~> 8.7.3' cookbook 'nginx', '= 9.0.0' -cookbook 'nodejs', '~> 7.3.1' +cookbook 'nodejs', '~> 11.0.1' cookbook 'ntp', '= 3.4.0' cookbook 'ohai', '~> 5.2.5' cookbook 'openssl', '~> 8.5.5' diff --git a/Berksfile.lock b/Berksfile.lock index 1651b1b..0090668 100644 --- a/Berksfile.lock +++ b/Berksfile.lock @@ -24,7 +24,7 @@ DEPENDENCIES ref: nginx mysql (~> 8.7.3) nginx (= 9.0.0) - nodejs (~> 7.3.1) + nodejs (~> 11.0.1) ntp (= 3.4.0) ohai (~> 5.2.5) openssl (~> 8.5.5) @@ -86,9 +86,10 @@ GRAPH build-essential (>= 5.0) ohai (>= 4.1.0) yum-epel (>= 0.0.0) - nodejs (7.3.3) + nodejs (11.0.1) ark (>= 2.0.2) chocolatey (>= 3.0) + yum (>= 7.2) ntp (3.4.0) ohai (5.2.5) openssl (8.5.5) diff --git a/cookbooks/nodejs/.markdownlint-cli2.yaml b/cookbooks/nodejs/.markdownlint-cli2.yaml new file mode 100644 index 0000000..9b06cfe --- /dev/null +++ b/cookbooks/nodejs/.markdownlint-cli2.yaml @@ -0,0 +1,12 @@ +config: + ul-indent: false # MD007 + line-length: false # MD013 + no-duplicate-heading: false # MD024 + reference-links-images: false # MD052 + ul-style: + style: asterisk + no-multiple-blanks: + maximum: 2 +ignores: + - .github/copilot-instructions.md + - .windsurf/** diff --git a/cookbooks/nodejs/.release-please-manifest.json b/cookbooks/nodejs/.release-please-manifest.json new file mode 100644 index 0000000..c656ffb --- /dev/null +++ b/cookbooks/nodejs/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "11.0.1" +} diff --git a/cookbooks/nodejs/CHANGELOG.md b/cookbooks/nodejs/CHANGELOG.md index e12da9f..e73ae76 100644 --- a/cookbooks/nodejs/CHANGELOG.md +++ b/cookbooks/nodejs/CHANGELOG.md @@ -1,221 +1,356 @@ # NodeJS Cookbook Changelog +Standardise files with files in sous-chefs/repo-management +Standardise files with files in sous-chefs/repo-management +Standardise files with files in sous-chefs/repo-management + +## [11.0.1](https://github.com/sous-chefs/nodejs/compare/v11.0.0...v11.0.1) (2026-07-09) + + +### Bug Fixes + +* migrate to Policyfile ([#315](https://github.com/sous-chefs/nodejs/issues/315)) ([0a481e2](https://github.com/sous-chefs/nodejs/commit/0a481e22c2dcb811800219f96d24ba95bca583da)) + +## [11.0.0](https://github.com/sous-chefs/nodejs/compare/v10.2.3...v11.0.0) (2026-05-19) + + +### ⚠ BREAKING CHANGES + +* migrate nodejs to custom resources ([#306](https://github.com/sous-chefs/nodejs/issues/306)) + +### Features + +* migrate nodejs to custom resources ([#306](https://github.com/sous-chefs/nodejs/issues/306)) ([a941d0f](https://github.com/sous-chefs/nodejs/commit/a941d0f729fad8b386cd8886ad9c232ed41b57e5)) + + +### Bug Fixes + +* **ci:** Update workflows to use release pipeline ([#300](https://github.com/sous-chefs/nodejs/issues/300)) ([ef16e2c](https://github.com/sous-chefs/nodejs/commit/ef16e2ce7d32be9d50822926a8d09e30d4a54bad)) + +## [10.2.3](https://github.com/sous-chefs/nodejs/compare/10.2.2...v10.2.3) (2025-10-15) + + +### Bug Fixes + +* **ci:** Update workflows to use release pipeline ([#300](https://github.com/sous-chefs/nodejs/issues/300)) ([ef16e2c](https://github.com/sous-chefs/nodejs/commit/ef16e2ce7d32be9d50822926a8d09e30d4a54bad)) + +## 10.2.1 - *2025-06-08* + +Standardise files with files in sous-chefs/repo-management + +## 10.2.0 - *2024-11-20* + +* Add support for new NodeSource repository (Thanks to @stissot) +* Rework source install packages +* Update SUSE packages + +## 10.1.22 - *2024-11-19* + +* Update default version to current LTS + +## 10.1.21 - *2024-11-19* + +* Update CI platforms + +## 10.1.20 - *2024-11-18* + +* Update test matrix check success of the integration stage + +## 10.1.19 - *2024-11-18* + +Standardise files with files in sous-chefs/repo-management + +Standardise files with files in sous-chefs/repo-management + +Standardise files with files in sous-chefs/repo-management + +Standardise files with files in sous-chefs/repo-management + +Standardise files with files in sous-chefs/repo-management + +## 10.1.16 - *2024-05-03* + +Standardise files with files in sous-chefs/repo-management + +## 10.1.10 - *2023-04-07* + +Standardise files with files in sous-chefs/repo-management + +## 10.1.7 - *2023-04-01* + +Standardise files with files in sous-chefs/repo-management + +## 10.1.6 - *2023-03-20* + +Standardise files with files in sous-chefs/repo-management + +## 10.1.5 - *2023-03-15* + +Standardise files with files in sous-chefs/repo-management + +## 10.1.4 - *2023-02-20* + +Standardise files with files in sous-chefs/repo-management + +## 10.1.2 - *2023-02-14* + +Standardise files with files in sous-chefs/repo-management + +## 10.1.1 - *2022-12-08* + +Standardise files with files in sous-chefs/repo-management + +## 10.1.0 - *2022-08-08* + +* To ensure consistent environment between `npm install` and `npm list`, pass same environment variables. + +## 10.0.1 - *2022-08-07* + +* Standardise files with files in sous-chefs/repo-management +* Default to using EL 9 repo for Fedora +* CI: Remove Fedora from source suite + +## 10.0.0 - *2022-04-21* + +* Update to NodeJS 17.x +* Remove delivery and move to calling RSpec directly via a reusable workflow +* Update tested platforms +* Disable upstream DNF module on EL8 based systems + +## 9.0.2 - *2022-02-17* + +* Standardise files with files in sous-chefs/repo-management + +## 9.0.1 - *2022-02-08* + +* Remove delivery folder + +## 9.0.0 - *2021-09-13* + +* Update the default version to 14 LTS +* Remove testing for EOL platforms +* Add Debian 11 testing +* Fix release version to use for Amazon Linux + +## 8.0.0 - *2021-09-02* + +* Update metadata and README to Sous Chef +* Enable unified_mode by default and require at least Chef Infra Client 15.3 +* Cookstyle fixes + ## 7.3.3 - *2021-08-30* -- Standardise files with files in sous-chefs/repo-management +* Standardise files with files in sous-chefs/repo-management ## 7.3.2 - *2021-06-01* -- Standardise files with files in sous-chefs/repo-management +* Standardise files with files in sous-chefs/repo-management ## 7.3.1 - *2020-12-31* -- resolved cookstyle error: attributes/packages.rb:15:55 convention: `Layout/TrailingEmptyLines` -- resolved cookstyle error: test/cookbooks/test/recipes/resource.rb:118:1 convention: `Layout/TrailingEmptyLines` -- Enable builds for opensuse-leap-15 -- Add a library method test +* resolved cookstyle error: attributes/packages.rb:15:55 convention: `Layout/TrailingEmptyLines` +* resolved cookstyle error: test/cookbooks/test/recipes/resource.rb:118:1 convention: `Layout/TrailingEmptyLines` +* Enable builds for opensuse-leap-15 +* Add a library method test ## 7.3.0 (2020-10-21) -- Add rspec tests for the library methods -- Update the url_invalid? method to return false if it detects an invalid uri -- Add the auto_update option to the npm_package resource. Allows turning off auto_update of npm packages. -- Allow actions and options for OS package installation to be specified as attributes -- Add the live_stream parameter to the npm_package execution to get better installation diagnostics -- Add the auto_update option to the npm_package resource. Allows turning off auto_update of npm packages. -- Update testing +* Add rspec tests for the library methods +* Update the url_invalid? method to return false if it detects an invalid uri +* Add the auto_update option to the npm_package resource. Allows turning off auto_update of npm packages. +* Allow actions and options for OS package installation to be specified as attributes +* Add the live_stream parameter to the npm_package execution to get better installation diagnostics +* Add the auto_update option to the npm_package resource. Allows turning off auto_update of npm packages. +* Update testing ## 7.2.0 (2020-10-07) -- Verify the URI of installed packages to help determine if a good URI has been installed -- Add tests that verify npm-package installed packages -- Get the example test cookbook working -- Add support for installing node on windows +* Verify the URI of installed packages to help determine if a good URI has been installed +* Add tests that verify npm-package installed packages +* Get the example test cookbook working +* Add support for installing node on windows ## 7.1.0 (2020-10-01) -- resolved cookstyle error: recipes/nodejs_from_binary.rb:19:1 refactor: `ChefCorrectness/IncorrectLibraryInjection` -- resolved cookstyle error: recipes/nodejs_from_source.rb:21:1 refactor: `ChefCorrectness/IncorrectLibraryInjection` -- resolved cookstyle error: recipes/npm_from_source.rb:21:1 refactor: `ChefCorrectness/IncorrectLibraryInjection` -- Have ark setup node and npm binaries into PATH -- Add `node_env` to `npm_package` in order to set `NODE_ENV` (useful for some packages) -- Include `npx` as a binary in addition to `npm`, it has been [included since `npm` v5.2.0](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b) +* resolved cookstyle error: recipes/nodejs_from_binary.rb:19:1 refactor: `ChefCorrectness/IncorrectLibraryInjection` +* resolved cookstyle error: recipes/nodejs_from_source.rb:21:1 refactor: `ChefCorrectness/IncorrectLibraryInjection` +* resolved cookstyle error: recipes/npm_from_source.rb:21:1 refactor: `ChefCorrectness/IncorrectLibraryInjection` +* Have ark setup node and npm binaries into PATH +* Add `node_env` to `npm_package` in order to set `NODE_ENV` (useful for some packages) +* Include `npx` as a binary in addition to `npm`, it has been [included since `npm` v5.2.0](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b) ## 7.0.1 (2020-06-04) -- Minor readme fix +* Minor readme fix ## 7.0.0 (2020-06-04) -- Require Chef Infra Client 14+ and remove the build-essential dependency -- Updated the default to Node.js v10.16.3 -- Added compatibility with Chef Infra Client 16.2+ -- Removed Foodcritic testing -- Updated ChefSpec and Kitchen platforms -- Resolved multiple minor cookstyle issues in the cookbook -- Added a vscode editor config +* Require Chef Infra Client 14+ and remove the build-essential dependency +* Updated the default to Node.js v10.16.3 +* Added compatibility with Chef Infra Client 16.2+ +* Removed Foodcritic testing +* Updated ChefSpec and Kitchen platforms +* Resolved multiple minor cookstyle issues in the cookbook +* Added a vscode editor config ## 6.0.0 (2018-10-11) -- Use the build_essential resource in the source install recipe instead of the build-essential::default recipe. This way we can use the new built-in build_essential resource in Chef 14+ -- Set default version to Node.js v8.12.0 +* Use the build_essential resource in the source install recipe instead of the build-essential::default recipe. This way we can use the new built-in build_essential resource in Chef 14+ +* Set default version to Node.js v8.12.0 ## 5.0.0 (2017-11-15) -- nodejs_npm resource has been converted to a custom resource and renamed to npm_package. The existing resource name will continue to function, but over time code should be updated for the new name. This name change has been made so we can eventually merge this resource into the chef-client. -- compat_resource cookbook dependency has been removed and this cookbook instead requires Chef 12.14 or later -- Chef 13 compatibility has been resolved -- The npm_package resource now properly installs packages when the 'package' property is setA -- Speed up npm operations by only returning a list of the desired package instead of every npm package -- Speed up source installation by using multipackage install for the dependencies -- Remove the broken url_valid? helper which didn't work +* nodejs_npm resource has been converted to a custom resource and renamed to npm_package. The existing resource name will continue to function, but over time code should be updated for the new name. This name change has been made so we can eventually merge this resource into the chef-client. +* compat_resource cookbook dependency has been removed and this cookbook instead requires Chef 12.14 or later +* Chef 13 compatibility has been resolved +* The npm_package resource now properly installs packages when the 'package' property is setA +* Speed up npm operations by only returning a list of the desired package instead of every npm package +* Speed up source installation by using multipackage install for the dependencies +* Remove the broken url_valid? helper which didn't work ## 4.0.0 (2017-07-11) -- Updated the cookbook to require Chef 12.1+ and the compat_resource cookbook -- Removed support for io.js which has merged back into the node.js project -- Removed the dependency on homebrew, yum-epel, and apt cookbooks -- Added node['nodejs']['manage_node'] attribute to use only cookbook's LWRP (required to manage node by nvm) -- Updated the default repository URLs to be the 6.X repos -- Added initial support for Suse and Amazon Linux -- Improved architecture detection to support aarch64 -- Improved readme with examples for fetching your own binaries -- Added installation of openssl and xz utilities that are needed for the binary install recipe -- Updated the cookbook license string to be an SPDX compliant string -- Set the minimum version of the ark cookbook to 2.0.2 in order to support Suse -- Updated the default version from 6.9.1 to 6.10.2 -- Switched to Delivery local mode for testing -- Added Integration testing in Travis CI with kitchen-dokken and ChefDK +* Updated the cookbook to require Chef 12.1+ and the compat_resource cookbook +* Removed support for io.js which has merged back into the node.js project +* Removed the dependency on homebrew, yum-epel, and apt cookbooks +* Added node['nodejs']['manage_node'] attribute to use only cookbook's LWRP (required to manage node by nvm) +* Updated the default repository URLs to be the 6.X repos +* Added initial support for Suse and Amazon Linux +* Improved architecture detection to support aarch64 +* Improved readme with examples for fetching your own binaries +* Added installation of openssl and xz utilities that are needed for the binary install recipe +* Updated the cookbook license string to be an SPDX compliant string +* Set the minimum version of the ark cookbook to 2.0.2 in order to support Suse +* Updated the default version from 6.9.1 to 6.10.2 +* Switched to Delivery local mode for testing +* Added Integration testing in Travis CI with kitchen-dokken and ChefDK ## 3.0.0 (2016-11-02) -- Updated the default release to the nodejs 6.9.1\. This requires C++11 extensions to compile, which are only present in GCC 4.8+. Due to this RHEL 5/6 and Ubuntu 12.04 are not supported if using this version. -- Switched the download URLs to the .xz packages since the .tar.gz packages are no longer being created -- Improvements to the readme examples and requirements sections -- Removed installation of apt-transport-https and instead rely on an apt cookbook that will do the same -- Fixed the ChefSpec matchers -- Added Scientific, Oracle, and Amazon as supported distros in the metadata -- Added chef_version metadata -- Removed conflicts and suggests metadata which aren't implemented or recommended for use -- Removed Chef 10 compatibility code -- Switched Integration testing to Inspec from bats -- Added the Apache 2.0 license file to the repo -- Expanded Test Kitchen testing -- Switched from Rubocop to Cookstyle and resolved all warnings -- Switched Travis to testing using ChefDK +* Updated the default release to the nodejs 6.9.1\. This requires C++11 extensions to compile, which are only present in GCC 4.8+. Due to this RHEL 5/6 and Ubuntu 12.04 are not supported if using this version. +* Switched the download URLs to the .xz packages since the .tar.gz packages are no longer being created +* Improvements to the readme examples and requirements sections +* Removed installation of apt-transport-https and instead rely on an apt cookbook that will do the same +* Fixed the ChefSpec matchers +* Added Scientific, Oracle, and Amazon as supported distros in the metadata +* Added chef_version metadata +* Removed conflicts and suggests metadata which aren't implemented or recommended for use +* Removed Chef 10 compatibility code +* Switched Integration testing to Inspec from bats +* Added the Apache 2.0 license file to the repo +* Expanded Test Kitchen testing +* Switched from Rubocop to Cookstyle and resolved all warnings +* Switched Travis to testing using ChefDK ## 2.4.4 -- Use HTTPS prefix URLs for node download #98 -- Update NPM symlink when installing from source #105 -- Add support for NPM private modules #107 +* Use HTTPS prefix URLs for node download #98 +* Update NPM symlink when installing from source #105 +* Add support for NPM private modules #107 ## v2.4.2 -- Fix check version -- Support iojs package install +* Fix check version +* Support iojs package install ## v2.4.0 -- Move `npm_packages` to his own recipe -- Fix different race conditions when using direct recipe call -- Fix npm recipe +* Move `npm_packages` to his own recipe +* Fix different race conditions when using direct recipe call +* Fix npm recipe ## v2.3.2 -- Fix package recipe +* Fix package recipe ## v2.3.0 -- Support io.js. Use node['nodejs']['engine']. -- Add MacOS support via homebrew +* Support io.js. Use node['nodejs']['engine']. +* Add MacOS support via homebrew ## v2.2.0 -- Add node['nodejs']['keyserver'] -- Update arm checksum -- Fix `npm_packages` JSON +* Add node['nodejs']['keyserver'] +* Update arm checksum +* Fix `npm_packages` JSON ## v2.1.0 -- Use official nodesource repository -- Add node['nodejs']['npm_packages'] to install npm package with `default` recipe +* Use official nodesource repository +* Add node['nodejs']['npm_packages'] to install npm package with `default` recipe ## v2.0.0 -- Travis integration -- Gems updated -- Rewrite cookbook dependencies -- Added complete test-kitchen integration : Rake, rubocop, foodcritic, vagrant, bats testing ... -- Added NodeJS `install_method` option (sources, bins or packages) -- Added NPM `install_method` option (sources or packages) -- NPM version can now be chosen independently from nodejs' embedded version -- Added a `nodejs_npm` LWRP to manage, install and resolve NPM packages +* Travis integration +* Gems updated +* Rewrite cookbook dependencies +* Added complete test-kitchen integration : Rake, rubocop, foodcritic, vagrant, bats testing ... +* Added NodeJS `install_method` option (sources, bins or packages) +* Added NPM `install_method` option (sources or packages) +* NPM version can now be chosen independently from nodejs' embedded version +* Added a `nodejs_npm` LWRP to manage, install and resolve NPM packages ## v1.3.0 -- update default versions to the latest: node - v0.10.15 and npm - v1.3.5 -- default to package installation of nodejs on smartos ([@wanelo-pair]) -- Add Raspberry pi support ([@robertkowalski]) +* update default versions to the latest: node - v0.10.15 and npm - v1.3.5 +* default to package installation of nodejs on smartos ([@wanelo-pair]) +* Add Raspberry pi support ([@robertkowalski]) ## v1.2.0 -- implement installation from package on RedHat - ([@vaskas]) +* implement installation from package on RedHat - ([@vaskas]) ## v1.1.3 -- update default version of node to 0.10.13 - and npm - v1.3.4 ([@jodosha][]) +* update default version of node to 0.10.13 - and npm - v1.3.4 ([@jodosha][]) ## v1.1.2 -- update default version of node to 0.10.2 - ([@bakins]) -- fully migrated to test-kitchen 1.alpha and vagrant 1.1.x/berkshelf 1.3.1 +* update default version of node to 0.10.2 - ([@bakins]) +* fully migrated to test-kitchen 1.alpha and vagrant 1.1.x/berkshelf 1.3.1 ## v1.1.1 -- update default versions to the latest: node - v0.10.0 and npm - v1.2.14 -- `make_thread` is now a real attribute - ([@ChrisLundquist]) +* update default versions to the latest: node - v0.10.0 and npm - v1.2.14 +* `make_thread` is now a real attribute - ([@ChrisLundquist]) ## v1.1.0 -- rewrite the package install; remove rpm support since there are no longer any packages available anywhere -- add support to install `legacy_packages` from ubuntu repo as well as the latest 0.10.x branch (this is default). +* rewrite the package install; remove rpm support since there are no longer any packages available anywhere +* add support to install `legacy_packages` from ubuntu repo as well as the latest 0.10.x branch (this is default). ## v1.0.4 -- add support for binary installation method ([@JulesAU]) +* add support for binary installation method ([@JulesAU]) ## v1.0.3 -- 7.3.1 - *2020-12-31* +* 7.3.1 - *2020-12-31* ## v1.0.2 -- add smartos support for package install ([@sax]) -- support to compile with all processors available (default 2 if unknown) - ([@ChrisLundquist]) -- moved to `platform_family` syntax -- ensure npm recipe honours the 'source' or 'package' setting - ([@markbirbeck]) -- updated the default versions to the latest stable node/npm +* add smartos support for package install ([@sax]) +* support to compile with all processors available (default 2 if unknown) - ([@ChrisLundquist]) +* moved to `platform_family` syntax +* ensure npm recipe honours the 'source' or 'package' setting - ([@markbirbeck]) +* updated the default versions to the latest stable node/npm ## v1.0.1 -- fixed bug that prevented overwritting the node/npm versions (moved the `src_url`s as local variables instead of attributes) - ([@johannesbecker]) -- updated the default versions to the latest node/npm +* fixed bug that prevented overwritting the node/npm versions (moved the `src_url`s as local variables instead of attributes) - ([@johannesbecker]) +* updated the default versions to the latest node/npm ## v1.0.0 -- added packages installation support ([@smith]) +* added packages installation support ([@smith]) -[@bakins]: https://github.com/bakins -[@chrislundquist]: https://github.com/ChrisLundquist -[@gmccue]: https://github.com/gmccue -[@johannesbecker]: https://github.com/johannesbecker -[@julesau]: https://github.com/JulesAU -[@markbirbeck]: https://github.com/markbirbeck -[@predominant]: https://github.com/predominant -[@robertkowalski]: https://github.com/robertkowalski -[@sax]: https://github.com/sax -[@sjlu]: https://github.com/sjlu -[@smith]: https://github.com/smith -[@vaskas]: https://github.com/vaskas -[@wanelo-pair]: https://github.com/wanelo-pair +[@bakins]: +[@chrislundquist]: +[@johannesbecker]: +[@julesau]: +[@markbirbeck]: +[@robertkowalski]: +[@sax]: +[@smith]: +[@vaskas]: +[@wanelo-pair]: diff --git a/cookbooks/nodejs/LIMITATIONS.md b/cookbooks/nodejs/LIMITATIONS.md new file mode 100644 index 0000000..24b8e6f --- /dev/null +++ b/cookbooks/nodejs/LIMITATIONS.md @@ -0,0 +1,69 @@ +# Limitations + +This cookbook defaults to Node.js 24 LTS, using Node.js v24.15.0 checksums from the official `SHASUMS256.txt` published for `latest-v24.x` on 2026-04-16. + +Sources checked on 2026-04-29: + +* Node.js release schedule: +* Node.js latest v24 artifacts: +* Node.js v24 checksums: +* NodeSource distributions page: +* NodeSource distributions repository: + +## Package Availability + +### APT (Debian/Ubuntu) + +NodeSource documents Node 24 packages for: + +* Ubuntu 20.04, 22.04, 24.04: `amd64`, `armhf`, `arm64` +* Debian 10, 11, 12: `amd64`, `armhf`, `arm64` + +The cookbook only declares currently supported, non-EOL Debian/Ubuntu platforms in `metadata.rb`: Debian 12 or later and Ubuntu 22.04 or later. NodeSource packages use the `nodistro` repository distribution. + +### DNF/YUM (RHEL family) + +NodeSource documents RPM packages for RHEL 8/9, Fedora 29+, and Amazon Linux 2023 on `x86_64` and `arm64`. The repository URL pattern used by this cookbook is: + +```text +>.x/nodistro/nodejs/$basearch +``` + +The cookbook declares AlmaLinux, Amazon Linux 2023, CentOS Stream, Fedora, Oracle Linux, Red Hat, and Rocky Linux where current test images are available. + +### Zypper (SUSE) + +NodeSource does not publish SUSE repository rows in the current distributions documentation. This migration does not declare SUSE/openSUSE support in `metadata.rb`. + +### Windows and macOS + +Windows support is limited to `nodejs_install` with `install_method 'chocolatey'`. macOS support is limited to package installation through the platform package provider where available. Dokken coverage is Linux-only. + +## Architecture Limitations + +Official Node.js v24.15.0 source and binary checksums pinned by this cookbook: + +| Artifact | SHA256 | +| ---------------------------------- | ------------------------------------------------------------------ | +| `node-v24.15.0.tar.gz` | `729de494dd2872e5a3a6c32a1cd156a5413d4aca2772b2d873ee86bb5531bcd9` | +| `node-v24.15.0-linux-x64.tar.gz` | `44836872d9aec49f1e6b52a9a922872db9a2b02d235a616a5681b6a85fec8d89` | +| `node-v24.15.0-linux-arm64.tar.gz` | `73afc234d558c24919875f51c2d1ea002a2ada4ea6f83601a383869fefa64eed` | + +The `nodejs_install` binary action currently models Linux `x64` and `arm64` checksums. Other official Node.js artifacts can be installed by passing `binary_url` and the matching checksum. + +## Source/Compiled Installation + +### Build Dependencies + +| Platform Family | Packages | +| ------------------ | ---------------------------------------------------- | +| Debian | `build-essential`, `libssl-dev`, `python3` | +| RHEL/Fedora/Amazon | `build-essential`, `openssl-devel`, `python3`, `tar` | +| Other | `build-essential`, `python3` | + +Source builds are much slower than package or binary installs and are not used as the default Kitchen smoke path. + +## Known Issues + +* Node.js 20 reaches end-of-life on 2026-04-30, so this migration does not keep old Node 20 defaults. +* NodeSource repository docs currently show some LTS/current labels that lag the official Node.js release schedule. The cookbook version defaults follow the official Node.js release schedule and official Node.js checksum artifacts. diff --git a/cookbooks/nodejs/Policyfile.rb b/cookbooks/nodejs/Policyfile.rb new file mode 100644 index 0000000..75db510 --- /dev/null +++ b/cookbooks/nodejs/Policyfile.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +name 'nodejs' + +default_source :supermarket + +run_list 'recipe[test::default]' + +cookbook 'nodejs', path: '.' +cookbook 'test', path: './test/cookbooks/test' + +Dir.children('./test/cookbooks/test/recipes').grep(/\.rb\z/).sort.each do |recipe| + recipe_name = File.basename(recipe, '.rb') + + named_run_list recipe_name.to_sym, "recipe[test::#{recipe_name}]" +end diff --git a/cookbooks/nodejs/README.md b/cookbooks/nodejs/README.md index bb3f27a..cb114a7 100644 --- a/cookbooks/nodejs/README.md +++ b/cookbooks/nodejs/README.md @@ -1,220 +1,109 @@ # [nodejs-cookbook](https://github.com/redguide/nodejs) -[![CK Version](http://img.shields.io/cookbook/v/nodejs.svg?branch=master)](https://supermarket.chef.io/cookbooks/nodejs) [![Build Status](https://img.shields.io/travis/redguide/nodejs.svg)](https://travis-ci.org/redguide/nodejs) +[![Cookbook Version](https://img.shields.io/cookbook/v/nodejs.svg)](https://supermarket.chef.io/cookbooks/nodejs) +[![CI State](https://github.com/sous-chefs/nodejs/workflows/ci/badge.svg)](https://github.com/sous-chefs/nodejs/actions?query=workflow%3Aci) +[![OpenCollective](https://opencollective.com/sous-chefs/backers/badge.svg)](#backers) +[![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors) +[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) -Installs node.js/npm and includes a resource for managing npm packages +Provides custom resources for installing Node.js/npm and managing npm packages. + +## Maintainers + +This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit [sous-chefs.org](https://sous-chefs.org/) or come chat with us on the Chef Community Slack in [#sous-chefs](https://chefcommunity.slack.com/messages/C2V7B88SF). ## Requirements ### Platforms -- Debian/Ubuntu -- RHEL/CentOS/Scientific/Amazon/Oracle -- openSUSE -- Windows - -Note: Source installs require GCC 4.8+, which is not included on older distro releases +* Debian/Ubuntu +* RHEL family/Fedora/Amazon Linux +* macOS where platform packages are available +* Windows through Chocolatey ### Chef -- Chef Infra Client 14+ +* Chef Infra Client 15.3+ ### Cookbooks -- ark +* ark +* chocolatey ## Usage -Include the nodejs recipe to install node on your system based on the default installation method: +Install Node.js with the default platform method: ```ruby -include_recipe "nodejs" +nodejs_install 'nodejs' ``` -### Install methods - -#### Package - Install node from packages: ```ruby -node['nodejs']['install_method'] = 'package' # Not necessary because it's the default -include_recipe "nodejs" -# Or -include_recipe "nodejs::nodejs_from_package" +nodejs_install 'nodejs' do + install_method 'package' + version '24.15.0' ``` -By default this will setup deb/rpm repositories from nodesource.com, which include up to date NodeJS packages. If you prefer to use distro provided package you can disable this behavior by setting `node['nodejs']['install_repo']` to `false`. - -#### Binary - -Install node from official prebuilt binaries: +Install Node.js from official prebuilt binaries: ```ruby -node['nodejs']['install_method'] = 'binary' -include_recipe "nodejs" - -# Or -include_recipe "nodejs::nodejs_from_binary" - -# Or set a specific version of nodejs to be installed -node.default['nodejs']['install_method'] = 'binary' -node.default['nodejs']['version'] = '5.9.0' -node.default['nodejs']['binary']['checksum'] = '99c4136cf61761fac5ac57f80544140a3793b63e00a65d4a0e528c9db328bf40' - -# Or fetch the binary from your own location -node.default['nodejs']['install_method'] = 'binary' -node.default['nodejs']['binary']['url'] = 'https://s3.amazonaws.com/my-bucket/node-v7.8.0-linux-x64.tar.gz' -node.default['nodejs']['binary']['checksum'] = '0bd86f2a39221b532172c7d1acb57f0b0cba88c7b82ea74ba9d1208b9f6f9697' +nodejs_install 'nodejs' do + install_method 'binary' ``` -#### Source - -Install node from sources: +Install Node.js from source: ```ruby -node['nodejs']['install_method'] = 'source' -include_recipe "nodejs" -# Or -include_recipe "nodejs::nodejs_from_source" +nodejs_install 'nodejs' do + install_method 'source' +end ``` -#### Chocolatey - -Install node from chocolatey: - -```chef -node['nodejs']['install_method'] = 'chocolatey' -include_recipe "nodejs" -# Or -include_recipe "nodejs::nodejs_from_chocolatey" -``` - -## NPM - -Npm is included in nodejs installs by default. By default, we are using it and call it `embedded`. Adding recipe `nodejs::npm` assure you to have npm installed and let you choose install method with `node['nodejs']['npm']['install_method']` - -```ruby -include_recipe "nodejs::npm" -``` - -_Warning:_ This recipe will include the `nodejs` recipe, which by default includes `nodejs::nodejs_from_package` if you did not set `node['nodejs']['install_method']`. - -## Resources - -### npm_package - -note: This resource was previously named nodejs_npm. Calls to that resource name will still function, but cookbooks should be updated for the new npm_package resource name. - -`npm_package` lets you install npm packages from various sources: - -- npm registry: - - - name: `property :package` - - version: `property :version` (optional) - -- url: `property :url` - - - for git use `git://{your_repo}` - -- from a json (package.json by default): `property :json` - - - use `true` for default - - use a `String` to specify json file - -Packages can be installed globally (by default) or in a directory (by using `attribute :path`) - -You can specify an `NPM_TOKEN` environment variable for accessing [NPM private modules](https://docs.npmjs.com/private-modules/intro) by using `attribute :npm_token` - -You can specify a `NODE_ENV` environment variable, in the case that some element of your installation depends on this by using `attribute :node_env`. E.g., using [`node-config`](https://www.npmjs.com/package/config) as part of your postinstall script. Please note that adding the `--production` option will override this to `NODE_ENV=production`. - -You can append more specific options to npm command with `attribute :options` array : - -You can specify auto_update as false to stop the npm install command from running and updating an installed package. Running the command will update packages within restrictions imposed by a package.json file. The default behavior is to update automatically. - -- use an array of options (w/ dash), they will be added to npm call. -- ex: `['--production','--force']` or `['--force-latest']` - -You can specify live_stream true for the resource to have the package install information included in the chef-client log outout for better npm package diagnostics and trouble shooting. - -This LWRP attempts to use vanilla npm as much as possible (no custom wrapper). - -### Packages +Install npm packages: ```ruby npm_package 'express' -npm_package 'async' do - version '0.6.2' -end - -npm_package 'request' do - url 'github mikeal/request' -end - -npm_package 'grunt' do - path '/home/random/grunt' - json true - user 'random' - node_env 'staging' -end - -npm_package 'my_private_module' do - path '/home/random/myproject' # The root path to your project, containing a package.json file - json true - npm_token '12345-abcde-e5d4c3b2a1' - user 'random' - options ['--production'] # Only install dependencies. Skip devDependencies -end -``` - -[Working Examples](test/cookbooks/nodejs_test/recipes/npm.rb) - -Or add packages via attributes (which accept the same attributes as the LWRP above): - -```json -"nodejs": { - "npm_packages": [ - { - "name": "express" - }, - { - "name": "async", - "version": "0.6.2" - }, - { - "name": "request", - "url": "github mikeal/request" - } - { - "name": "grunt", - "path": "/home/random/grunt", - "json": true, - "user": "random" - } +nodejs_npm_packages 'application packages' do + packages [ + { name: 'socket.io', version: '4.8.1' }, ] -} +end ``` -## License & Authors +See [migration.md](migration.md) for the breaking recipe/attribute migration guide. -**Author:** Marius Ducea (marius@promethost.com) -**Author:** Nathan L Smith (nlloyds@gmail.com) -**Author:** Guilhem Lettron (guilhem@lettron.fr) -**Author:** Barthelemy Vessemont (bvessemont@gmail.com) +## Resources -**Copyright:** Chef Software, Inc. +* [nodejs_install](documentation/nodejs_install.md) +* [nodejs_repository](documentation/nodejs_repository.md) +* [nodejs_npm_install](documentation/nodejs_npm_install.md) +* [nodejs_npm_packages](documentation/nodejs_npm_packages.md) +* [npm_package](documentation/nodejs_npm_package.md) -``` -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at +## Contributors - http://www.apache.org/licenses/LICENSE-2.0 +This project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890&button=false) -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -``` +### Backers + +Thank you to all our backers! + +![) + +### Sponsors + +Support this project by becoming a sponsor. Your logo will show up here with a link to your website. + +![) +![) +![) +![) +![) +![) +![) +![) +![) +![) diff --git a/cookbooks/nodejs/attributes/default.rb b/cookbooks/nodejs/attributes/default.rb deleted file mode 100644 index 3e043c6..0000000 --- a/cookbooks/nodejs/attributes/default.rb +++ /dev/null @@ -1,44 +0,0 @@ -# -# Cookbook:: nodejs -# Attributes:: nodejs -# -# Copyright:: 2010-2017, Promet Solutions -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -case node['platform_family'] -when 'smartos', 'rhel', 'debian', 'fedora', 'mac_os_x', 'suse', 'amazon' - default['nodejs']['install_method'] = 'package' -when 'windows' - default['nodejs']['install_method'] = 'chocolatey' -else - default['nodejs']['install_method'] = 'source' -end - -default['nodejs']['version'] = '10.16.3' - -default['nodejs']['prefix_url']['node'] = 'https://nodejs.org/dist/' - -default['nodejs']['tmpdir'] = '/tmp' -default['nodejs']['source']['url'] = nil # Auto generated -default['nodejs']['source']['checksum'] = 'db5a5e03a815b84a1266a4b48bb6a6d887175705f84fd2472f0d28e5e305a1f8' - -default['nodejs']['binary']['url'] = nil # Auto generated -default['nodejs']['binary']['checksum']['linux_x64'] = '2f0397bb81c1d0c9901b9aff82a933257bf60f3992227b86107111a75b9030d9' -default['nodejs']['binary']['checksum']['linux_arm64'] = '3bab16e7107092e43426e082ee9fd88ef0a43a35816f662f14563bcc5152600d' -default['nodejs']['binary']['append_env_path'] = true - -default['nodejs']['make_threads'] = node['cpu'] ? node['cpu']['total'].to_i : 2 - -default['nodejs']['manage_node'] = true diff --git a/cookbooks/nodejs/attributes/npm.rb b/cookbooks/nodejs/attributes/npm.rb deleted file mode 100644 index 97ee5d3..0000000 --- a/cookbooks/nodejs/attributes/npm.rb +++ /dev/null @@ -1,2 +0,0 @@ -default['nodejs']['npm']['install_method'] = 'embedded' -default['nodejs']['npm']['version'] = 'latest' diff --git a/cookbooks/nodejs/attributes/packages.rb b/cookbooks/nodejs/attributes/packages.rb deleted file mode 100644 index 38754b1..0000000 --- a/cookbooks/nodejs/attributes/packages.rb +++ /dev/null @@ -1,15 +0,0 @@ -include_attribute 'nodejs::default' -include_attribute 'nodejs::repo' - -default['nodejs']['packages'] = value_for_platform_family( - 'debian' => node['nodejs']['install_repo'] ? ['nodejs'] : %w(nodejs npm nodejs-dev), - %w(rhel fedora amazon) => node['nodejs']['install_repo'] ? %w(nodejs nodejs-devel) : %w(nodejs npm nodejs-dev), - 'suse' => node['platform_version'].to_i < 42 ? %w(nodejs10 npm10 nodejs10-devel) : %w(nodejs4 npm4 nodejs4-devel), - 'mac_os_x' => ['node'], - 'freebsd' => %w(node npm), - 'default' => ['nodejs'] -) - -# Add options and actions by package name -default['nodejs']['package_action'] = { default: :install } -default['nodejs']['package_options'] = { default: '' } diff --git a/cookbooks/nodejs/attributes/repo.rb b/cookbooks/nodejs/attributes/repo.rb deleted file mode 100644 index 6e6a344..0000000 --- a/cookbooks/nodejs/attributes/repo.rb +++ /dev/null @@ -1,12 +0,0 @@ -case node['platform_family'] -when 'debian' - default['nodejs']['install_repo'] = true - default['nodejs']['repo'] = 'https://deb.nodesource.com/node_10.x' - default['nodejs']['keyserver'] = 'keyserver.ubuntu.com' - default['nodejs']['key'] = '1655a0ab68576280' -when 'rhel', 'fedora', 'amazon' - default['nodejs']['install_repo'] = true - release_ver = platform?('amazon') ? 6 : node['platform_version'].to_i - default['nodejs']['repo'] = "https://rpm.nodesource.com/pub_10.x/el/#{release_ver}/$basearch" - default['nodejs']['key'] = 'https://rpm.nodesource.com/pub/el/NODESOURCE-GPG-SIGNING-KEY-EL' -end diff --git a/cookbooks/nodejs/chefignore b/cookbooks/nodejs/chefignore index cc170ea..e824a7f 100644 --- a/cookbooks/nodejs/chefignore +++ b/cookbooks/nodejs/chefignore @@ -61,7 +61,7 @@ Dangerfile examples/* features/* Guardfile -kitchen.yml* +kitchen*.yml mlc_config.json Procfile Rakefile @@ -83,10 +83,8 @@ test/* */.hg/* */.svn/* -# Berkshelf # -############# -Berksfile -Berksfile.lock +# Dependency cache # +#################### cookbooks/* tmp @@ -98,7 +96,6 @@ Gemfile.lock # Policyfile # ############## -Policyfile.rb Policyfile.lock.json # Documentation # diff --git a/cookbooks/nodejs/kitchen.dokken.yml b/cookbooks/nodejs/kitchen.dokken.yml deleted file mode 100644 index 4047cea..0000000 --- a/cookbooks/nodejs/kitchen.dokken.yml +++ /dev/null @@ -1,88 +0,0 @@ ---- -driver: - name: dokken - privileged: true # because Docker and SystemD - chef_version: <%= ENV['CHEF_VERSION'] || 'current' %> - chef_license: accept-no-persist - -transport: - name: dokken - -provisioner: - name: dokken - deprecations_as_errors: true - -verifier: - name: inspec - -platforms: - - name: amazonlinux - driver: - image: dokken/amazonlinux - pid_one_command: /sbin/init - - - name: amazonlinux-2 - driver: - image: dokken/amazonlinux-2 - pid_one_command: /usr/lib/systemd/systemd - - - name: debian-8 - driver: - image: dokken/debian-8 - pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update - - - name: debian-9 - driver: - image: dokken/debian-9 - pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update - - - name: debian-10 - driver: - image: dokken/debian-10 - pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update - - - name: centos-7 - driver: - image: dokken/centos-7 - pid_one_command: /usr/lib/systemd/systemd - - - name: centos-8 - driver: - image: dokken/centos-8 - pid_one_command: /usr/lib/systemd/systemd - - - name: fedora-latest - driver: - image: dokken/fedora-latest - pid_one_command: /usr/lib/systemd/systemd - - - name: opensuse-leap-15 - driver: - image: dokken/opensuse-leap-15 - pid_one_command: /bin/systemd - - - name: ubuntu-18.04 - driver: - image: dokken/ubuntu-18.04 - pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update - - - name: ubuntu-20.04 - driver: - image: dokken/ubuntu-20.04 - pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update - - RUN /usr/bin/apt-get install python -y - - - name: opensuse-leap-15 - driver: - image: dokken/opensuse-leap-15 - pid_one_command: /bin/systemd diff --git a/cookbooks/nodejs/libraries/nodejs_helper.rb b/cookbooks/nodejs/libraries/nodejs_helper.rb index f6f46c7..4fecad5 100644 --- a/cookbooks/nodejs/libraries/nodejs_helper.rb +++ b/cookbooks/nodejs/libraries/nodejs_helper.rb @@ -1,19 +1,96 @@ +# frozen_string_literal: true + module NodeJs module Helper - def npm_dist - if node['nodejs']['npm']['url'] - { 'url' => node['nodejs']['npm']['url'] } + def default_install_method + case node['platform_family'] + when 'debian', 'rhel', 'fedora', 'amazon', 'mac_os_x', 'suse' + 'package' + when 'windows' + 'chocolatey' else - - require 'open-uri' - require 'json' - result = JSON.parse(URI.parse("https://registry.npmjs.org/npm/#{node['nodejs']['npm']['version']}").read, max_nesting: false) - ret = { 'url' => result['dist']['tarball'], 'version' => result['_npmVersion'], 'shasum' => result['dist']['shasum'] } - Chef::Log.debug("Npm dist #{ret}") - ret + 'source' end end + def default_packages(install_repository) + case node['platform_family'] + when 'debian' + install_repository ? ['nodejs'] : %w(nodejs npm nodejs-dev) + when 'rhel', 'fedora', 'amazon' + install_repository ? %w(nodejs nodejs-devel) : %w(nodejs npm nodejs-devel) + when 'suse' + %w(nodejs npm nodejs-devel) + when 'mac_os_x' + ['node'] + else + ['nodejs'] + end + end + + def default_build_packages + case node['platform_family'] + when 'rhel', 'fedora', 'amazon' + %w(openssl-devel python3 tar) + when 'debian' + %w(libssl-dev python3) + else + %w(python3) + end + end + + def dnf_python_package?(package_name) + package_name == 'python3' && platform_family?('rhel', 'fedora', 'amazon') + end + + def default_make_threads + node['cpu'] ? node['cpu']['total'].to_i : 2 + end + + def node_major_from_version(version) + version.to_s.split('.').first + end + + def nodejs_arch + machine = node['kernel']['machine'] + + case machine + when /armv6l/ + 'arm-pi' + when /aarch64/ + 'arm64' + when /x86_64/ + 'x64' + when /\d86/ + 'x86' + else + machine + end + end + + def nodejs_binary_checksum(checksums) + checksums["linux_#{nodejs_arch}"] + end + + def nodejs_source_url(version, prefix_url, source_url) + source_url || ::URI.join(prefix_url, "v#{version}/", "node-v#{version}.tar.gz").to_s + end + + def nodejs_binary_url(version, prefix_url, binary_url) + binary_url || ::URI.join(prefix_url, "v#{version}/", "node-v#{version}-linux-#{nodejs_arch}.tar.gz").to_s + end + + def npm_dist(version, url = nil) + return { 'url' => url } if url + + require 'open-uri' + require 'json' + result = JSON.parse(URI.parse("https://registry.npmjs.org/npm/#{version}").read, max_nesting: false) + ret = { 'url' => result['dist']['tarball'], 'version' => result['_npmVersion'], 'shasum' => result['dist']['shasum'] } + Chef::Log.debug("Npm dist #{ret}") + ret + end + def npm_list(package, path = nil, environment = {}) require 'json' cmd = if path @@ -47,9 +124,7 @@ module NodeJs (version ? list[package]['version'] == version : true) end - def npm_package_installed?(package, version = nil, path = nil, npm_token = nil) - environment = { 'NPM_TOKEN' => npm_token } if npm_token - + def npm_package_installed?(package, version = nil, path = nil, environment = {}) list = npm_list(package, path, environment)['dependencies'] # Return true if package installed and installed to good version # see if we really want to add the url check diff --git a/cookbooks/nodejs/metadata.json b/cookbooks/nodejs/metadata.json index e6c24a9..b3d016b 100644 --- a/cookbooks/nodejs/metadata.json +++ b/cookbooks/nodejs/metadata.json @@ -1,27 +1,27 @@ { "name": "nodejs", - "description": "Installs/Configures node.js", + "description": "Provides resources for installing Node.js and managing npm packages", "long_description": "", - "maintainer": "redguide", - "maintainer_email": "guilhem@lettron.fr", + "maintainer": "Sous Chefs", + "maintainer_email": "help@sous-chefs.org", "license": "Apache-2.0", "platforms": { - "debian": ">= 0.0.0", - "ubuntu": ">= 0.0.0", - "centos": ">= 0.0.0", - "redhat": ">= 0.0.0", - "scientific": ">= 0.0.0", - "oracle": ">= 0.0.0", - "amazon": ">= 0.0.0", - "smartos": ">= 0.0.0", + "almalinux": ">= 8.0", + "amazon": ">= 2023.0", + "centos_stream": ">= 9.0", + "debian": ">= 12.0", + "fedora": ">= 0.0.0", "mac_os_x": ">= 0.0.0", - "opensuseleap": ">= 0.0.0", - "suse": ">= 0.0.0", + "oracle": ">= 8.0", + "redhat": ">= 8.0", + "rocky": ">= 8.0", + "ubuntu": ">= 22.04", "windows": ">= 0.0.0" }, "dependencies": { "ark": ">= 2.0.2", - "chocolatey": ">= 3.0" + "chocolatey": ">= 3.0", + "yum": ">= 7.2" }, "providing": { @@ -29,13 +29,13 @@ "recipes": { }, - "version": "7.3.3", - "source_url": "https://github.com/redguide/nodejs", - "issues_url": "https://github.com/redguide/nodejs/issues", + "version": "11.0.1", + "source_url": "https://github.com/sous-chefs/nodejs", + "issues_url": "https://github.com/sous-chefs/nodejs/issues", "privacy": false, "chef_versions": [ [ - ">= 14" + ">= 15.3" ] ], "ohai_versions": [ diff --git a/cookbooks/nodejs/metadata.rb b/cookbooks/nodejs/metadata.rb index f22b592..43e38c5 100644 --- a/cookbooks/nodejs/metadata.rb +++ b/cookbooks/nodejs/metadata.rb @@ -1,16 +1,27 @@ -name 'nodejs' -maintainer 'redguide' -maintainer_email 'guilhem@lettron.fr' -license 'Apache-2.0' -description 'Installs/Configures node.js' -source_url 'https://github.com/redguide/nodejs' -issues_url 'https://github.com/redguide/nodejs/issues' -chef_version '>= 14' -version '7.3.3' +# frozen_string_literal: true + +name 'nodejs' +maintainer 'Sous Chefs' +maintainer_email 'help@sous-chefs.org' +license 'Apache-2.0' +description 'Provides resources for installing Node.js and managing npm packages' +version '11.0.1' +source_url 'https://github.com/sous-chefs/nodejs' +issues_url 'https://github.com/sous-chefs/nodejs/issues' +chef_version '>= 15.3' + +supports 'almalinux', '>= 8.0' +supports 'amazon', '>= 2023.0' +supports 'centos_stream', '>= 9.0' +supports 'debian', '>= 12.0' +supports 'fedora' +supports 'mac_os_x' +supports 'oracle', '>= 8.0' +supports 'redhat', '>= 8.0' +supports 'rocky', '>= 8.0' +supports 'ubuntu', '>= 22.04' +supports 'windows' depends 'ark', '>= 2.0.2' depends 'chocolatey', '>= 3.0' - -%w(debian ubuntu centos redhat scientific oracle amazon smartos mac_os_x opensuseleap suse windows).each do |os| - supports os -end +depends 'yum', '>= 7.2' diff --git a/cookbooks/nodejs/migration.md b/cookbooks/nodejs/migration.md new file mode 100644 index 0000000..c23f8be --- /dev/null +++ b/cookbooks/nodejs/migration.md @@ -0,0 +1,52 @@ +# Migration Guide + +This release is a breaking migration from recipes and node attributes to custom resources. + +## What Changed + +The cookbook no longer exposes `nodejs::default`, `nodejs::install`, `nodejs::repo`, `nodejs::npm`, `nodejs::npm_packages`, or the install-method recipes. The `attributes/` directory was removed. Configure Node.js through resource properties instead of `node['nodejs']` attributes. + +## Recipe to Resource Mapping + +| Before | After | +| ------------------------------------------------- | ------------------------------------------------------------- | +| `include_recipe 'nodejs::default'` | `nodejs_install 'nodejs'` plus optional `nodejs_npm_packages` | +| `include_recipe 'nodejs::repo'` | `nodejs_repository 'nodesource'` | +| `include_recipe 'nodejs::nodejs_from_package'` | `nodejs_install 'nodejs' do install_method 'package' end` | +| `include_recipe 'nodejs::nodejs_from_binary'` | `nodejs_install 'nodejs' do install_method 'binary' end` | +| `include_recipe 'nodejs::nodejs_from_source'` | `nodejs_install 'nodejs' do install_method 'source' end` | +| `include_recipe 'nodejs::nodejs_from_chocolatey'` | `nodejs_install 'nodejs' do install_method 'chocolatey' end` | +| `include_recipe 'nodejs::npm'` | `nodejs_npm_install 'npm'` | +| `node['nodejs']['npm_packages']` | `nodejs_npm_packages 'packages'` | + +## Examples + +Install Node.js from NodeSource packages: + +```ruby +nodejs_install 'nodejs' do + install_method 'package' + version '24.15.0' +end +``` + +Install packages that used to be configured with `node['nodejs']['npm_packages']`: + +```ruby +nodejs_npm_packages 'application packages' do + packages [ + { name: 'express' }, + { name: 'socket.io', version: '4.8.1' }, + ] +end +``` + +The `nodejs_npm` alias still works for the `npm_package` resource, but it no longer auto-includes any Node.js or npm recipes. Install Node.js first: + +```ruby +nodejs_install 'nodejs' + +nodejs_npm 'express' +``` + +See `test/cookbooks/test/recipes/` for runnable migration examples used by Kitchen. diff --git a/cookbooks/nodejs/recipes/default.rb b/cookbooks/nodejs/recipes/default.rb deleted file mode 100644 index aac903e..0000000 --- a/cookbooks/nodejs/recipes/default.rb +++ /dev/null @@ -1,23 +0,0 @@ - -# Author:: Marius Ducea (marius@promethost.com) -# Cookbook:: nodejs -# Recipe:: default -# -# Copyright:: 2010-2017, Promet Solutions -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -include_recipe 'nodejs::install' if node['nodejs']['manage_node'] -include_recipe 'nodejs::npm' if node['nodejs']['manage_node'] -include_recipe 'nodejs::npm_packages' if node['nodejs']['manage_node'] diff --git a/cookbooks/nodejs/recipes/install.rb b/cookbooks/nodejs/recipes/install.rb deleted file mode 100644 index bb4b529..0000000 --- a/cookbooks/nodejs/recipes/install.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Author:: Marius Ducea (marius@promethost.com) -# Cookbook:: nodejs -# Recipe:: install -# -# Copyright:: 2010-2017, Promet Solutions -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -include_recipe "nodejs::nodejs_from_#{node['nodejs']['install_method']}" diff --git a/cookbooks/nodejs/recipes/iojs.rb b/cookbooks/nodejs/recipes/iojs.rb deleted file mode 100644 index a1244b0..0000000 --- a/cookbooks/nodejs/recipes/iojs.rb +++ /dev/null @@ -1 +0,0 @@ -Chef::Log.fatal('The nodejs::iojs recipe has been deprecated. If you need iojs installation pin to cookbook version 3.0.1.') diff --git a/cookbooks/nodejs/recipes/nodejs.rb b/cookbooks/nodejs/recipes/nodejs.rb deleted file mode 100644 index 368b88d..0000000 --- a/cookbooks/nodejs/recipes/nodejs.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Author:: Marius Ducea (marius@promethost.com) -# Cookbook:: nodejs -# Recipe:: nodejs -# -# Copyright:: 2010-2017, Promet Solutions -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -Chef::Log.fatal('The nodejs::nodejs recipe is no longer used. Use nodejs::install to install nodejs instead.') diff --git a/cookbooks/nodejs/recipes/nodejs_from_binary.rb b/cookbooks/nodejs/recipes/nodejs_from_binary.rb deleted file mode 100644 index 0c05710..0000000 --- a/cookbooks/nodejs/recipes/nodejs_from_binary.rb +++ /dev/null @@ -1,67 +0,0 @@ -# -# Author:: Julian Wilde (jules@jules.com.au) -# Cookbook:: nodejs -# Recipe:: install_from_binary -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -Chef::DSL::Recipe.include NodeJs::Helper - -# Shamelessly borrowed from http://docs.chef.io/dsl_recipe_method_platform.html -# Surely there's a more canonical way to get arch? -arch = if node['kernel']['machine'] =~ /armv6l/ - # FIXME: This should really check the version of node we're looking for - # as it seems that they haven't build an `arm-pi` version in a while... - # if it's old, return this, otherwise just return `node['kernel']['machine']` - 'arm-pi' # assume a raspberry pi - elsif node['kernel']['machine'] =~ /aarch64/ - 'arm64' - elsif node['kernel']['machine'] =~ /x86_64/ - 'x64' - elsif node['kernel']['machine'] =~ /\d86/ - 'x86' - else - node['kernel']['machine'] - end - -# needed to uncompress the binary -package 'tar' if platform_family?('rhel', 'fedora', 'amazon', 'suse') - -# package_stub is for example: "node-v6.9.1-linux-x64.tar.gz" -version = "v#{node['nodejs']['version']}/" -prefix = node['nodejs']['prefix_url']['node'] - -filename = "node-v#{node['nodejs']['version']}-linux-#{arch}.tar.gz" -archive_name = 'nodejs-binary' -binaries = ['bin/node'] - -binaries.push('bin/npm') if node['nodejs']['npm']['install_method'] == 'embedded' -binaries.push('bin/npx') if node['nodejs']['npm']['install_method'] == 'embedded' - -if node['nodejs']['binary']['url'] - nodejs_bin_url = node['nodejs']['binary']['url'] - checksum = node['nodejs']['binary']['checksum'] -else - nodejs_bin_url = ::URI.join(prefix, version, filename).to_s - checksum = node['nodejs']['binary']['checksum']["linux_#{arch}"] -end - -ark archive_name do - url nodejs_bin_url - version node['nodejs']['version'] - checksum checksum - has_binaries binaries - append_env_path node['nodejs']['binary']['append_env_path'] - action :install -end diff --git a/cookbooks/nodejs/recipes/nodejs_from_chocolatey.rb b/cookbooks/nodejs/recipes/nodejs_from_chocolatey.rb deleted file mode 100644 index a0fa9d0..0000000 --- a/cookbooks/nodejs/recipes/nodejs_from_chocolatey.rb +++ /dev/null @@ -1,24 +0,0 @@ -# -# Author:: Hossein Margani (hossein@margani.dev) -# Cookbook:: nodejs -# Recipe:: install_from_chocolatey -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -include_recipe 'chocolatey' - -chocolatey_package 'nodejs-lts' do - version node['nodejs']['version'] if node['nodejs']['version'] - action :upgrade -end diff --git a/cookbooks/nodejs/recipes/nodejs_from_package.rb b/cookbooks/nodejs/recipes/nodejs_from_package.rb deleted file mode 100644 index fdd80e7..0000000 --- a/cookbooks/nodejs/recipes/nodejs_from_package.rb +++ /dev/null @@ -1,36 +0,0 @@ -# -# Author:: Nathan L Smith (nlloyds@gmail.com) -# Author:: Marius Ducea (marius@promethost.com) -# Cookbook:: nodejs -# Recipe:: package -# -# Copyright:: 2012-2017, Cramer Development, Inc. -# Copyright:: 2013-2017, Opscale -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -include_recipe 'nodejs::repo' if node['nodejs']['install_repo'] - -unless node['nodejs']['packages'] - Chef::Log.error 'No package for nodejs' - Chef::Log.warn 'Please use the source or binary method to install node' - return -end - -node['nodejs']['packages'].each do |node_pkg| - package node_pkg do - action node['nodejs']['package_action'][node_pkg] if node['nodejs']['package_action'][node_pkg] - options node['nodejs']['package_options'][node_pkg] if node['nodejs']['package_options'][node_pkg] - end -end diff --git a/cookbooks/nodejs/recipes/nodejs_from_source.rb b/cookbooks/nodejs/recipes/nodejs_from_source.rb deleted file mode 100644 index 865dbbf..0000000 --- a/cookbooks/nodejs/recipes/nodejs_from_source.rb +++ /dev/null @@ -1,49 +0,0 @@ -# -# Author:: Marius Ducea (marius@promethost.com) -# Cookbook:: nodejs -# Recipe:: source -# -# Copyright:: 2010-2017, Promet Solutions -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -Chef::DSL::Recipe.include NodeJs::Helper - -build_essential 'install build tools' - -case node['platform_family'] -when 'rhel', 'fedora', 'amazon' - # The ark resource uses and requires python2 for builds - package %w(openssl-devel python2 tar) -when 'debian' - package %w(libssl-dev python) -when 'suse' - package %w(python) -end - -version = "v#{node['nodejs']['version']}/" -prefix = node['nodejs']['prefix_url']['node'] -filename = "node-v#{node['nodejs']['version']}.tar.gz" -archive_name = 'nodejs-source' - -nodejs_src_url = node['nodejs']['source']['url'] || ::URI.join(prefix, version, filename).to_s - -ark archive_name do - url nodejs_src_url - version node['nodejs']['version'] - checksum node['nodejs']['source']['checksum'] - make_opts ["-j #{node['nodejs']['make_threads']}"] - action :install_with_make - environment(PYTHON: 'python2') -end diff --git a/cookbooks/nodejs/recipes/npm.rb b/cookbooks/nodejs/recipes/npm.rb deleted file mode 100644 index 9d049fc..0000000 --- a/cookbooks/nodejs/recipes/npm.rb +++ /dev/null @@ -1,28 +0,0 @@ -# -# Author:: Marius Ducea (marius@promethost.com) -# Cookbook:: nodejs -# Recipe:: npm -# -# Copyright:: 2010-2017, Promet Solutions -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -case node['nodejs']['npm']['install_method'] -when 'embedded' - include_recipe 'nodejs::install' -when 'source' - include_recipe 'nodejs::npm_from_source' -else - Chef::Log.error('No install method found for npm') -end diff --git a/cookbooks/nodejs/recipes/npm_from_source.rb b/cookbooks/nodejs/recipes/npm_from_source.rb deleted file mode 100644 index d2dc71d..0000000 --- a/cookbooks/nodejs/recipes/npm_from_source.rb +++ /dev/null @@ -1,32 +0,0 @@ -# -# Author:: Marius Ducea (marius@promethost.com) -# Cookbook:: nodejs -# Recipe:: npm -# -# Copyright:: 2010-2017, Promet Solutions -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -Chef::DSL::Recipe.include NodeJs::Helper - -include_recipe 'nodejs::nodejs_from_source' - -dist = npm_dist - -ark 'npm' do - url dist['url'] - checksum dist['checksum'] - version dist['version'] - action :install_with_make -end diff --git a/cookbooks/nodejs/recipes/npm_packages.rb b/cookbooks/nodejs/recipes/npm_packages.rb deleted file mode 100644 index ec0d3c5..0000000 --- a/cookbooks/nodejs/recipes/npm_packages.rb +++ /dev/null @@ -1,13 +0,0 @@ -if node['nodejs'].key?('npm_packages') - node['nodejs']['npm_packages'].each do |pkg| - pkg_action = pkg.key?('action') ? pkg['action'] : :install - f = npm_package "nodejs_npm-#{pkg['name']}-#{pkg_action}" do - action :nothing - package pkg['name'] - end - pkg.each do |key, value| - f.send(key, value) unless key == 'name' || key == 'action' - end - f.action(pkg_action) - end -end diff --git a/cookbooks/nodejs/recipes/repo.rb b/cookbooks/nodejs/recipes/repo.rb deleted file mode 100644 index 14b98e4..0000000 --- a/cookbooks/nodejs/recipes/repo.rb +++ /dev/null @@ -1,19 +0,0 @@ -case node['platform_family'] -when 'debian' - package 'nodejs-apt-transport-https' do - package_name 'apt-transport-https' - end - - apt_repository 'node.js' do - uri node['nodejs']['repo'] - components ['main'] - keyserver node['nodejs']['keyserver'] - key node['nodejs']['key'] - end -when 'rhel', 'fedora', 'amazon' - yum_repository 'node.js' do - description 'nodesource.com nodejs repository' - baseurl node['nodejs']['repo'] - gpgkey node['nodejs']['key'] - end -end diff --git a/cookbooks/nodejs/release-please-config.json b/cookbooks/nodejs/release-please-config.json new file mode 100644 index 0000000..512531e --- /dev/null +++ b/cookbooks/nodejs/release-please-config.json @@ -0,0 +1,12 @@ +{ + "packages": { + ".": { + "package-name": "nodejs", + "changelog-path": "CHANGELOG.md", + "release-type": "ruby", + "include-component-in-tag": false, + "version-file": "metadata.rb" + } + }, + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json" +} diff --git a/cookbooks/nodejs/renovate.json b/cookbooks/nodejs/renovate.json new file mode 100644 index 0000000..a0b29c8 --- /dev/null +++ b/cookbooks/nodejs/renovate.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": ["config:base"], + "packageRules": [ + { + "groupName": "Actions", + "matchUpdateTypes": ["minor", "patch", "pin"], + "automerge": true, + "addLabels": ["Release: Patch", "Skip: Announcements"] + }, + { + "groupName": "Actions", + "matchUpdateTypes": ["major"], + "automerge": false, + "addLabels": ["Release: Patch", "Skip: Announcements"] + } + ] +} diff --git a/cookbooks/nodejs/resources/_partial/_nodejs.rb b/cookbooks/nodejs/resources/_partial/_nodejs.rb new file mode 100644 index 0000000..47b2b5f --- /dev/null +++ b/cookbooks/nodejs/resources/_partial/_nodejs.rb @@ -0,0 +1,2 @@ +property :version, String, default: '24.15.0' +property :prefix_url, String, default: 'https://nodejs.org/dist/' diff --git a/cookbooks/nodejs/resources/nodejs_install.rb b/cookbooks/nodejs/resources/nodejs_install.rb new file mode 100644 index 0000000..f4468ac --- /dev/null +++ b/cookbooks/nodejs/resources/nodejs_install.rb @@ -0,0 +1,146 @@ +# frozen_string_literal: true + +provides :nodejs_install +unified_mode true + +use '_partial/_nodejs' + +property :install_method, String, equal_to: %w(package binary source chocolatey) +property :install_repository, [true, false], default: true +property :packages, [Array, nil], default: nil +property :package_action, [Symbol, String], default: :install +property :package_options, [String, nil] +property :disable_dnf_module, [true, false], default: true +property :source_url, [String, nil] +property :source_checksum, [String, nil], default: '729de494dd2872e5a3a6c32a1cd156a5413d4aca2772b2d873ee86bb5531bcd9' +property :binary_url, [String, nil] +property :binary_checksums, Hash, + default: { + 'linux_x64' => '44836872d9aec49f1e6b52a9a922872db9a2b02d235a616a5681b6a85fec8d89', + 'linux_arm64' => '73afc234d558c24919875f51c2d1ea002a2ada4ea6f83601a383869fefa64eed', + } +property :append_env_path, [true, false], default: true +property :make_threads, [Integer, String, nil], default: nil +property :build_packages, [Array, nil], default: nil +property :chocolatey_package_name, String, default: 'nodejs-lts' + +default_action :install + +action :install do + case requested_install_method + when 'package' + nodejs_repository 'nodesource' do + node_major node_major_from_version(new_resource.version) + action :create + only_if { new_resource.install_repository } + end + + dnf_module 'nodejs' do + action :disable + only_if { disable_dnf_module? } + end + + resolved_packages.each do |pkg| + package pkg do + action new_resource.package_action.to_sym + options new_resource.package_options if new_resource.package_options + end + end + when 'binary' + package 'tar' if platform_family?('rhel', 'fedora', 'amazon', 'suse') + + ark 'nodejs-binary' do + url nodejs_binary_url(new_resource.version, new_resource.prefix_url, new_resource.binary_url) + version new_resource.version + checksum nodejs_binary_checksum(new_resource.binary_checksums) unless new_resource.binary_url + has_binaries %w(bin/node bin/npm bin/npx) + append_env_path new_resource.append_env_path + action :install + end + when 'source' + build_essential 'install build tools' + + (new_resource.build_packages || default_build_packages).each do |pkg| + if dnf_python_package?(pkg) + execute 'install python3 build package' do + command 'dnf -y install python3' + not_if 'command -v python3' + only_if 'command -v dnf' + end + else + package pkg + end + end + + link '/usr/local/bin/python' do + to '/usr/bin/python3' + not_if { ::File.exist?('/usr/bin/python') || ::File.exist?('/usr/local/bin/python') } + only_if { ::File.exist?('/usr/bin/python3') } + end + + ark 'nodejs-source' do + url nodejs_source_url(new_resource.version, new_resource.prefix_url, new_resource.source_url) + version new_resource.version + checksum new_resource.source_checksum if new_resource.source_checksum + make_opts ["-j #{new_resource.make_threads || default_make_threads}"] + environment(PYTHON: 'python3') + action :install_with_make + end + when 'chocolatey' + chocolatey_package new_resource.chocolatey_package_name do + version new_resource.version if new_resource.version + action :upgrade + end + end +end + +action :remove do + case requested_install_method + when 'package' + resolved_packages.each do |pkg| + package pkg do + action :remove + end + end + + nodejs_repository 'nodesource' do + action :remove + only_if { new_resource.install_repository } + end + when 'binary' + ark 'nodejs-binary' do + action :remove + end + when 'source' + ark 'nodejs-source' do + action :remove + end + when 'chocolatey' + chocolatey_package new_resource.chocolatey_package_name do + action :remove + end + end +end + +action_class do + include NodeJs::Helper + + def requested_install_method + new_resource.install_method || default_install_method + end + + def resolved_packages + new_resource.packages || default_packages(new_resource.install_repository) + end + + def disable_dnf_module? + new_resource.disable_dnf_module && + platform_family?('rhel', 'fedora') && + node['platform_version'].to_i >= 8 && + dnf_module_available?('nodejs') + end + + def dnf_module_available?(module_name) + shell_out!("dnf -q module list #{module_name}", returns: [0, 1]).stdout.match?(/^#{Regexp.escape(module_name)}\s/m) + end +end diff --git a/cookbooks/nodejs/resources/nodejs_npm_install.rb b/cookbooks/nodejs/resources/nodejs_npm_install.rb new file mode 100644 index 0000000..b506d2d --- /dev/null +++ b/cookbooks/nodejs/resources/nodejs_npm_install.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +provides :nodejs_npm_install +unified_mode true + +use '_partial/_nodejs' + +property :install_method, String, equal_to: %w(embedded source), default: 'embedded' +property :install_node, [true, false], default: true +property :node_install_method, String, equal_to: %w(package binary source chocolatey), default: 'package' +property :npm_version, String, default: 'latest' +property :npm_url, [String, nil] +property :npm_checksum, [String, nil] +property :make_threads, [Integer, String, nil], default: nil + +default_action :install + +action :install do + nodejs_install 'nodejs for npm' do + install_method new_resource.node_install_method + version new_resource.version + prefix_url new_resource.prefix_url + action :install + only_if { new_resource.install_node } + end + + ark 'npm' do + url lazy { npm_dist(new_resource.npm_version, new_resource.npm_url)['url'] } + checksum new_resource.npm_checksum if new_resource.npm_checksum + version lazy { npm_dist(new_resource.npm_version, new_resource.npm_url)['version'] || new_resource.npm_version } + make_opts ["-j #{new_resource.make_threads || default_make_threads}"] + action :install_with_make + only_if { new_resource.install_method == 'source' } + end +end + +action :remove do + ark 'npm' do + action :remove + only_if { new_resource.install_method == 'source' } + end +end + +action_class do + include NodeJs::Helper +end diff --git a/cookbooks/nodejs/resources/nodejs_npm_packages.rb b/cookbooks/nodejs/resources/nodejs_npm_packages.rb new file mode 100644 index 0000000..cbe2c96 --- /dev/null +++ b/cookbooks/nodejs/resources/nodejs_npm_packages.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +provides :nodejs_npm_packages +unified_mode true + +property :packages, Array, default: [] + +default_action :install + +action :install do + new_resource.packages.each do |pkg| + package_properties = normalize_package(pkg) + pkg_action = package_properties.delete(:action) || :install + pkg_name = package_properties.delete(:package) + + npm_package "nodejs_npm-#{pkg_name}-#{pkg_action}" do + package pkg_name + package_properties.each do |property_name, property_value| + send(property_name, property_value) + end + action pkg_action.to_sym + end + end +end + +action :remove do + new_resource.packages.each do |pkg| + package_properties = normalize_package(pkg) + pkg_name = package_properties[:package] + + npm_package "nodejs_npm-#{pkg_name}-remove" do + package pkg_name + action :remove + end + end +end + +action_class do + def normalize_package(pkg) + pkg.each_with_object({}) do |(key, value), memo| + property_name = key.to_sym + property_name = :package if property_name == :name + memo[property_name] = value + end + end +end diff --git a/cookbooks/nodejs/resources/nodejs_repository.rb b/cookbooks/nodejs/resources/nodejs_repository.rb new file mode 100644 index 0000000..654b83a --- /dev/null +++ b/cookbooks/nodejs/resources/nodejs_repository.rb @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +provides :nodejs_repository +unified_mode true + +property :repo_name, String, name_property: true +property :node_major, [String, Integer], default: '24' +property :apt_uri, String +property :apt_distribution, String, default: 'nodistro' +property :apt_components, Array, default: ['main'] +property :apt_key, String, default: 'https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key' +property :apt_keyring, String, default: '/etc/apt/keyrings/nodesource.asc' +property :apt_pin_priority, String, default: '600' +property :yum_baseurl, String +property :yum_gpgkey, String, default: 'https://rpm.nodesource.com/gpgkey/ns-operations-public.key' +property :yum_priority, String, default: '9' +property :enabled, [true, false], default: true +property :gpgcheck, [true, false], default: true + +default_action :create + +action :create do + case node['platform_family'] + when 'debian' + package %w(ca-certificates curl gnupg apt-transport-https) + + directory ::File.dirname(new_resource.apt_keyring) do + recursive true + mode '0755' + end + + remote_file new_resource.apt_keyring do + source new_resource.apt_key + mode '0644' + end + + apt_preference new_resource.repo_name do + glob '*' + pin 'origin deb.nodesource.com' + pin_priority new_resource.apt_pin_priority + end + + apt_repository new_resource.repo_name do + uri lazy { new_resource.apt_uri || "https://deb.nodesource.com/node_#{new_resource.node_major}.x" } + components new_resource.apt_components + signed_by new_resource.apt_keyring + distribution new_resource.apt_distribution + end + when 'rhel', 'fedora', 'amazon' + yum_repository "#{new_resource.repo_name}-nodejs" do + description 'nodesource.com nodejs repository' + baseurl lazy { new_resource.yum_baseurl || "https://rpm.nodesource.com/pub_#{new_resource.node_major}.x/nodistro/nodejs/$basearch" } + gpgkey new_resource.yum_gpgkey + priority new_resource.yum_priority + enabled new_resource.enabled + gpgcheck new_resource.gpgcheck + options(module_hotfixes: 1) + action :create + end + end +end + +action :remove do + case node['platform_family'] + when 'debian' + apt_repository new_resource.repo_name do + action :remove + end + + file new_resource.apt_keyring do + action :delete + end + when 'rhel', 'fedora', 'amazon' + yum_repository "#{new_resource.repo_name}-nodejs" do + action :remove + end + end +end diff --git a/cookbooks/nodejs/resources/npm_package.rb b/cookbooks/nodejs/resources/npm_package.rb index 71ae487..f2f2434 100644 --- a/cookbooks/nodejs/resources/npm_package.rb +++ b/cookbooks/nodejs/resources/npm_package.rb @@ -1,28 +1,8 @@ -# -# Cookbook:: nodejs -# Resource:: npm -# -# Author:: Sergey Balbeko -# -# Copyright:: 2012-2017, Sergey Balbeko -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# +# frozen_string_literal: true -resource_name :npm_package provides :npm_package +unified_mode true -# backwards compatibility for the old resource name provides :nodejs_npm property :package, String, name_property: true @@ -30,7 +10,7 @@ property :version, String property :path, String property :url, String property :json, [String, true, false] -property :npm_token, String +property :npm_token, String, sensitive: true property :options, Array, default: [] property :user, String property :group, String @@ -38,10 +18,7 @@ property :live_stream, [false, true], default: false property :node_env, String property :auto_update, [true, false], default: true -def initialize(*args) - super - @run_context.include_recipe 'nodejs::npm' if node['nodejs']['manage_node'] -end +default_action :install action :install do execute "install NPM package #{new_resource.package}" do @@ -51,7 +28,8 @@ action :install do group new_resource.group environment npm_env_vars live_stream new_resource.live_stream - not_if { package_installed? && no_auto_update? } + sensitive true if new_resource.npm_token + not_if { no_auto_update? && package_installed? } end end @@ -63,6 +41,20 @@ action :uninstall do group new_resource.group environment npm_env_vars live_stream new_resource.live_stream + sensitive true if new_resource.npm_token + only_if { package_installed? } + end +end + +action :remove do + execute "uninstall NPM package #{new_resource.package}" do + cwd new_resource.path + command "npm uninstall #{npm_options}" + user new_resource.user + group new_resource.group + environment npm_env_vars + live_stream new_resource.live_stream + sensitive true if new_resource.npm_token only_if { package_installed? } end end @@ -75,13 +67,19 @@ action_class do env_vars['HOME'] = ::Dir.home(new_resource.user) if new_resource.user env_vars['USER'] = new_resource.user if new_resource.user env_vars['NPM_TOKEN'] = new_resource.npm_token if new_resource.npm_token - env_vars['NODE_ENV'] = new_resource.node_env if new_resource.node_env + env_vars['NODE_ENV'] = new_resource.node_env if new_resource.node_env env_vars end def package_installed? - new_resource.package && npm_package_installed?(new_resource.package, new_resource.version, new_resource.path, new_resource.npm_token) + return package_json_installed? if new_resource.json == true + + new_resource.package && npm_package_installed?(new_resource.package, new_resource.version, new_resource.path, npm_env_vars) + end + + def package_json_installed? + new_resource.path && ::File.exist?(::File.join(new_resource.path, 'node_modules')) end def no_auto_update? @@ -89,7 +87,7 @@ action_class do end def npm_options - options = '' + options = +'' options << ' -global' unless new_resource.path new_resource.options.each do |option| options << " #{option}" diff --git a/site-cookbooks/kosmos-bitcoin/recipes/rtl.rb b/site-cookbooks/kosmos-bitcoin/recipes/rtl.rb index 1321bb2..080eb8b 100644 --- a/site-cookbooks/kosmos-bitcoin/recipes/rtl.rb +++ b/site-cookbooks/kosmos-bitcoin/recipes/rtl.rb @@ -3,7 +3,7 @@ # Recipe:: rtl # -node.override["nodejs"]["repo"] = "https://deb.nodesource.com/node_18.x" +node.override["kosmos_nodejs"]["version"] = "18.20.8" include_recipe 'kosmos-nodejs' app_name = "rtl" diff --git a/site-cookbooks/kosmos-hubot/recipes/_nodejs.rb b/site-cookbooks/kosmos-hubot/recipes/_nodejs.rb index 3a0fb57..366e3ae 100644 --- a/site-cookbooks/kosmos-hubot/recipes/_nodejs.rb +++ b/site-cookbooks/kosmos-hubot/recipes/_nodejs.rb @@ -3,6 +3,5 @@ # Recipe:: _nodejs # -node.override["nodejs"]["repo"] = "https://deb.nodesource.com/node_16.x" - +node.override["kosmos_nodejs"]["version"] = "16.20.2" include_recipe "kosmos-nodejs" diff --git a/site-cookbooks/kosmos-ipfs/recipes/kredits_pinner.rb b/site-cookbooks/kosmos-ipfs/recipes/kredits_pinner.rb index d1b1f76..1c02cd8 100644 --- a/site-cookbooks/kosmos-ipfs/recipes/kredits_pinner.rb +++ b/site-cookbooks/kosmos-ipfs/recipes/kredits_pinner.rb @@ -3,8 +3,7 @@ # Recipe:: kredits_pinner # -node.override["nodejs"]["repo"] = "https://deb.nodesource.com/node_16.x" - +node.override["kosmos_nodejs"]["version"] = "16.20.2" include_recipe 'kosmos-nodejs' app_name = "ipfs-pinner" diff --git a/site-cookbooks/kosmos-mastodon/recipes/default.rb b/site-cookbooks/kosmos-mastodon/recipes/default.rb index ffb6b92..f6e7e0a 100644 --- a/site-cookbooks/kosmos-mastodon/recipes/default.rb +++ b/site-cookbooks/kosmos-mastodon/recipes/default.rb @@ -3,7 +3,7 @@ # Recipe:: default # -node.override["nodejs"]["repo"] = "https://deb.nodesource.com/node_18.x" +node.override["kosmos_nodejs"]["version"] = "18.20.8" include_recipe "kosmos-nodejs" include_recipe "java" diff --git a/site-cookbooks/kosmos-nodejs/attributes/default.rb b/site-cookbooks/kosmos-nodejs/attributes/default.rb index 039cebf..2bbcbdf 100644 --- a/site-cookbooks/kosmos-nodejs/attributes/default.rb +++ b/site-cookbooks/kosmos-nodejs/attributes/default.rb @@ -1,3 +1 @@ -node.override["nodejs"]["repo"] = "https://deb.nodesource.com/node_14.x" -# Allows upgrading -node.override["nodejs"]["package_action"]["nodejs"] = :upgrade +node.default["kosmos_nodejs"]["version"] = "14.21.3" diff --git a/site-cookbooks/kosmos-nodejs/recipes/default.rb b/site-cookbooks/kosmos-nodejs/recipes/default.rb index 849c6a9..2769bdc 100644 --- a/site-cookbooks/kosmos-nodejs/recipes/default.rb +++ b/site-cookbooks/kosmos-nodejs/recipes/default.rb @@ -3,4 +3,7 @@ # Recipe:: default # -include_recipe "nodejs::nodejs_from_package" +nodejs_install 'nodejs' do + install_method 'package' + version node["kosmos_nodejs"]["version"] +end diff --git a/site-cookbooks/kosmos_gitea/recipes/compile_from_source.rb b/site-cookbooks/kosmos_gitea/recipes/compile_from_source.rb index 488d8cc..9bfa8cf 100644 --- a/site-cookbooks/kosmos_gitea/recipes/compile_from_source.rb +++ b/site-cookbooks/kosmos_gitea/recipes/compile_from_source.rb @@ -7,7 +7,7 @@ include_recipe "git" -node.override["nodejs"]["repo"] = "https://deb.nodesource.com/node_20.x" +node.override["kosmos_nodejs"]["version"] = "20.20.2" include_recipe 'kosmos-nodejs' node.override["golang"]["version"] = "1.23.9" diff --git a/site-cookbooks/sockethub/recipes/default.rb b/site-cookbooks/sockethub/recipes/default.rb index e258718..353baee 100644 --- a/site-cookbooks/sockethub/recipes/default.rb +++ b/site-cookbooks/sockethub/recipes/default.rb @@ -5,6 +5,8 @@ include_recipe 'redisio::default' include_recipe 'redisio::enable' + +node.override["kosmos_nodejs"]["version"] = "24.18.0" include_recipe 'kosmos-nodejs' user = "sockethub"