├── documentation └── .gitkeep ├── .mdlrc ├── .gitattributes ├── .rubocop.yml ├── .github ├── CODEOWNERS ├── workflows │ ├── conventional-commits.yml │ ├── prevent-file-change.yml │ ├── release.yml │ ├── copilot-setup-steps.yml │ ├── stale.yml │ └── ci.yml └── copilot-instructions.md ├── .release-please-manifest.json ├── .envrc ├── test ├── cookbooks │ └── test │ │ ├── metadata.rb │ │ ├── recipes │ │ ├── default.rb │ │ ├── package.rb │ │ ├── chocolatey.rb │ │ ├── source.rb │ │ ├── source_iojs.rb │ │ ├── resource_win.rb │ │ └── resource.rb │ │ └── templates │ │ └── package.json └── integration │ ├── options │ └── default_spec.rb │ ├── npm_embedded │ └── default_spec.rb │ ├── chocolatey │ └── default.rb │ ├── npm_source │ └── default_spec.rb │ ├── source │ └── default.rb │ ├── default │ └── default_spec.rb │ └── package │ └── default.rb ├── attributes ├── npm.rb ├── repo.rb ├── packages.rb └── default.rb ├── recipes ├── iojs.rb ├── npm_packages.rb ├── install.rb ├── nodejs.rb ├── nodejs_from_chocolatey.rb ├── default.rb ├── npm.rb ├── npm_from_source.rb ├── nodejs_from_package.rb ├── nodejs_from_source.rb ├── repo.rb └── nodejs_from_binary.rb ├── CODE_OF_CONDUCT.md ├── kitchen.exec.yml ├── Berksfile ├── TESTING.md ├── .vscode └── extensions.json ├── CONTRIBUTING.md ├── .markdownlint-cli2.yaml ├── spec ├── rspec_helper.rb ├── spec_helper.rb └── unit │ ├── recipes │ └── default_spec.rb │ └── library │ └── helper_spec.rb ├── .yamllint ├── release-please-config.json ├── .editorconfig ├── renovate.json ├── .overcommit.yml ├── .gitignore ├── metadata.rb ├── kitchen.global.yml ├── kitchen.yml ├── Dangerfile ├── chefignore ├── libraries └── nodejs_helper.rb ├── kitchen.dokken.yml ├── resources └── npm_package.rb ├── README.md ├── LICENSE └── CHANGELOG.md /documentation/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.mdlrc: -------------------------------------------------------------------------------- 1 | rules "~MD013" 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | require: 2 | - cookstyle 3 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @sous-chefs/maintainers 2 | -------------------------------------------------------------------------------- /.release-please-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | ".": "10.2.3" 3 | } 4 | -------------------------------------------------------------------------------- /.envrc: -------------------------------------------------------------------------------- 1 | use chefworkstation 2 | export KITCHEN_GLOBAL_YAML=kitchen.global.yml 3 | -------------------------------------------------------------------------------- /test/cookbooks/test/metadata.rb: -------------------------------------------------------------------------------- 1 | name 'test' 2 | version '0.1.0' 3 | 4 | depends 'git' 5 | depends 'nodejs' 6 | -------------------------------------------------------------------------------- /attributes/npm.rb: -------------------------------------------------------------------------------- 1 | default['nodejs']['npm']['install_method'] = 'embedded' 2 | default['nodejs']['npm']['version'] = 'latest' 3 | -------------------------------------------------------------------------------- /test/cookbooks/test/recipes/default.rb: -------------------------------------------------------------------------------- 1 | apt_update 'update' 2 | 3 | include_recipe 'nodejs::default' 4 | include_recipe 'test::resource' 5 | -------------------------------------------------------------------------------- /recipes/iojs.rb: -------------------------------------------------------------------------------- 1 | Chef::Log.fatal('The nodejs::iojs recipe has been deprecated. If you need iojs installation pin to cookbook version 3.0.1.') 2 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Community Guidelines 2 | 3 | This project follows the Chef Community Guidelines 4 | -------------------------------------------------------------------------------- /kitchen.exec.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: { name: exec } 3 | transport: { name: exec } 4 | 5 | platforms: 6 | - name: macos-latest 7 | - name: windows-latest 8 | -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | source 'https://supermarket.chef.io' 2 | 3 | metadata 4 | 5 | group :integration do 6 | cookbook 'test', path: './test/cookbooks/test' 7 | end 8 | -------------------------------------------------------------------------------- /test/cookbooks/test/recipes/package.rb: -------------------------------------------------------------------------------- 1 | apt_update 'update' 2 | 3 | node.default['nodejs']['install_method'] = 'package' 4 | 5 | include_recipe 'nodejs::default' 6 | -------------------------------------------------------------------------------- /test/cookbooks/test/recipes/chocolatey.rb: -------------------------------------------------------------------------------- 1 | node.default['nodejs']['install_method'] = 'chocolatey' 2 | include_recipe 'nodejs::default' 3 | include_recipe 'test::resource_win' 4 | -------------------------------------------------------------------------------- /TESTING.md: -------------------------------------------------------------------------------- 1 | # Testing 2 | 3 | Please refer to [the community cookbook documentation on testing](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/main/TESTING.MD). 4 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "chef-software.chef", 4 | "Shopify.ruby-lsp", 5 | "editorconfig.editorconfig", 6 | "DavidAnson.vscode-markdownlint" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Please refer to 4 | [https://github.com/chef-cookbooks/community_cookbook_documentation/blob/main/CONTRIBUTING.MD](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/main/CONTRIBUTING.MD) 5 | -------------------------------------------------------------------------------- /.markdownlint-cli2.yaml: -------------------------------------------------------------------------------- 1 | config: 2 | ul-indent: false # MD007 3 | line-length: false # MD013 4 | no-duplicate-heading: false # MD024 5 | reference-links-images: false # MD052 6 | no-multiple-blanks: 7 | maximum: 2 8 | ignores: 9 | - .github/copilot-instructions.md 10 | -------------------------------------------------------------------------------- /spec/rspec_helper.rb: -------------------------------------------------------------------------------- 1 | Dir.glob('libraries/*.rb').each do |lib| 2 | require_relative "../#{lib}" 3 | end 4 | 5 | RSpec.configure do |config| 6 | config.expose_dsl_globally = true 7 | config.mock_with :rspec do |mocks| 8 | mocks.allow_message_expectations_on_nil = true 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /test/cookbooks/test/recipes/source.rb: -------------------------------------------------------------------------------- 1 | apt_update 'update' 2 | 3 | # Source install puts the npm symlink in /usr/local/bin 4 | ENV['PATH'] = '/usr/local/bin:' + ENV['PATH'] 5 | 6 | node.default['nodejs']['install_method'] = 'source' 7 | include_recipe 'nodejs::default' 8 | include_recipe 'test::resource' 9 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'chefspec' 2 | require 'chefspec/berkshelf' 3 | 4 | RSpec.configure do |config| 5 | config.color = true # Use color in STDOUT 6 | config.formatter = :documentation # Use the specified formatter 7 | config.log_level = :error # Avoid deprecation notice SPAM 8 | end 9 | -------------------------------------------------------------------------------- /.github/workflows/conventional-commits.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: conventional-commits 3 | 4 | "on": 5 | pull_request: 6 | types: 7 | - opened 8 | - reopened 9 | - edited 10 | - synchronize 11 | 12 | jobs: 13 | conventional-commits: 14 | uses: sous-chefs/.github/.github/workflows/conventional-commits.yml@5.0.3 15 | -------------------------------------------------------------------------------- /test/integration/options/default_spec.rb: -------------------------------------------------------------------------------- 1 | control 'packages should install' do 2 | describe package('nodejs') do 3 | it { should be_installed } 4 | end 5 | 6 | describe package('acpid') do 7 | it { should be_installed } 8 | end 9 | 10 | describe package('adcli') do 11 | it { should_not be_installed } 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /.yamllint: -------------------------------------------------------------------------------- 1 | --- 2 | extends: default 3 | rules: 4 | line-length: 5 | max: 256 6 | level: warning 7 | document-start: disable 8 | braces: 9 | forbid: false 10 | min-spaces-inside: 0 11 | max-spaces-inside: 1 12 | min-spaces-inside-empty: -1 13 | max-spaces-inside-empty: -1 14 | comments: 15 | min-spaces-from-content: 1 16 | -------------------------------------------------------------------------------- /test/cookbooks/test/recipes/source_iojs.rb: -------------------------------------------------------------------------------- 1 | apt_update 'update' 2 | 3 | node.default['nodejs']['engine'] = 'iojs' 4 | node.default['nodejs']['install_method'] = 'source' 5 | node.default['nodejs']['source']['checksum'] = '55e79cc4f4cde41f03c1e204d2af5ee4b6e4edcf14defc82e518436e939195fa' 6 | node.default['nodejs']['version'] = '2.2.1' 7 | 8 | include_recipe 'nodejs::default' 9 | -------------------------------------------------------------------------------- /test/integration/npm_embedded/default_spec.rb: -------------------------------------------------------------------------------- 1 | 2 | control 'commands should exist' do 3 | describe command('node -v') do 4 | its('exit_status') { should eq 0 } 5 | end 6 | 7 | describe command('npm -v') do 8 | its('exit_status') { should eq 0 } 9 | end 10 | 11 | describe command('npx -v') do 12 | its('exit_status') { should eq 0 } 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /release-please-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": { 3 | ".": { 4 | "package-name": "nodejs", 5 | "changelog-path": "CHANGELOG.md", 6 | "release-type": "ruby", 7 | "include-component-in-tag": false, 8 | "version-file": "metadata.rb" 9 | } 10 | }, 11 | "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json" 12 | } 13 | -------------------------------------------------------------------------------- /.github/workflows/prevent-file-change.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: prevent-file-change 3 | 4 | "on": 5 | pull_request: 6 | types: 7 | - opened 8 | - reopened 9 | - edited 10 | - synchronize 11 | 12 | jobs: 13 | prevent-file-change: 14 | uses: sous-chefs/.github/.github/workflows/prevent-file-change.yml@5.0.3 15 | secrets: 16 | token: ${{ secrets.GITHUB_TOKEN }} 17 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root=true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | 11 | # 2 space indentation 12 | indent_style = space 13 | indent_size = 2 14 | 15 | # Avoid issues parsing cookbook files later 16 | charset = utf-8 17 | 18 | # Avoid cookstyle warnings 19 | trim_trailing_whitespace = true 20 | -------------------------------------------------------------------------------- /recipes/npm_packages.rb: -------------------------------------------------------------------------------- 1 | if node['nodejs'].key?('npm_packages') 2 | node['nodejs']['npm_packages'].each do |pkg| 3 | pkg_action = pkg.key?('action') ? pkg['action'] : :install 4 | f = npm_package "nodejs_npm-#{pkg['name']}-#{pkg_action}" do 5 | action :nothing 6 | package pkg['name'] 7 | end 8 | pkg.each do |key, value| 9 | f.send(key, value) unless key == 'name' || key == 'action' 10 | end 11 | f.action(pkg_action) 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /test/cookbooks/test/templates/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "random-test", 3 | "version": "0.1.0", 4 | "description": "Just some random test", 5 | "license": "MIT", 6 | "author": { 7 | "name": "Random" 8 | }, 9 | "engines": { 10 | "node": ">=0.10.0" 11 | }, 12 | "dependencies": { 13 | "config": "^3.3.7", 14 | "koa": "^2.13.4" 15 | }, 16 | "devDependencies": { 17 | "gulp": "^4.0.2" 18 | }, 19 | "scripts": { 20 | "postinstall": "touch $NODE_ENV" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/integration/chocolatey/default.rb: -------------------------------------------------------------------------------- 1 | control 'commands should exist' do 2 | describe command('node -v') do 3 | its('exit_status') { should eq 0 } 4 | end 5 | 6 | describe command('npm -v') do 7 | its('exit_status') { should eq 0 } 8 | end 9 | 10 | describe command('npm list -json -global') do 11 | its('stdout') { should match(/express/) } 12 | its('stdout') { should match(/async@0.6.2/) } 13 | its('stdout') { should match(/request/) } 14 | its('stdout') { should match(/mocha/) } 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /test/integration/npm_source/default_spec.rb: -------------------------------------------------------------------------------- 1 | 2 | control 'commands should exist' do 3 | describe command('node -v') do 4 | its('exit_status') { should eq 0 } 5 | end 6 | 7 | describe command('npm -v') do 8 | its('exit_status') { should eq 0 } 9 | end 10 | 11 | describe command('npx -v') do 12 | its('exit_status') { should eq 0 } 13 | end 14 | 15 | describe file('/usr/local/bin/npm') do 16 | it { should exist } 17 | end 18 | 19 | describe file('/usr/local/bin/npx') do 20 | it { should exist } 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": ["config:base"], 4 | "packageRules": [ 5 | { 6 | "groupName": "Actions", 7 | "matchUpdateTypes": ["minor", "patch", "pin"], 8 | "automerge": true, 9 | "addLabels": ["Release: Patch", "Skip: Announcements"] 10 | }, 11 | { 12 | "groupName": "Actions", 13 | "matchUpdateTypes": ["major"], 14 | "automerge": false, 15 | "addLabels": ["Release: Patch", "Skip: Announcements"] 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: release 3 | 4 | "on": 5 | push: 6 | branches: 7 | - main 8 | 9 | permissions: 10 | contents: write 11 | issues: write 12 | pull-requests: write 13 | packages: write 14 | attestations: write 15 | id-token: write 16 | 17 | jobs: 18 | release: 19 | uses: sous-chefs/.github/.github/workflows/release-cookbook.yml@5.0.3 20 | secrets: 21 | token: ${{ secrets.PORTER_GITHUB_TOKEN }} 22 | supermarket_user: ${{ secrets.CHEF_SUPERMARKET_USER }} 23 | supermarket_key: ${{ secrets.CHEF_SUPERMARKET_KEY }} 24 | -------------------------------------------------------------------------------- /test/cookbooks/test/recipes/resource_win.rb: -------------------------------------------------------------------------------- 1 | include_recipe 'nodejs::npm' 2 | include_recipe 'git' 3 | 4 | user 'random' do 5 | manage_home true 6 | home '/home/random' 7 | end 8 | 9 | user 'random1' do 10 | manage_home true 11 | home '/home/random1' 12 | end 13 | 14 | user 'random2' do 15 | manage_home true 16 | home '/home/random2' 17 | end 18 | 19 | # global "express" using the old resource name 20 | nodejs_npm 'express' 21 | 22 | npm_package 'async' do 23 | version '0.6.2' 24 | end 25 | 26 | npm_package 'mocha' do 27 | options ['--force', '--production'] 28 | end 29 | -------------------------------------------------------------------------------- /.overcommit.yml: -------------------------------------------------------------------------------- 1 | --- 2 | PreCommit: 3 | TrailingWhitespace: 4 | enabled: true 5 | YamlLint: 6 | enabled: true 7 | required_executable: "yamllint" 8 | ChefSpec: 9 | enabled: true 10 | required_executable: "chef" 11 | command: ["chef", "exec", "rspec"] 12 | Cookstyle: 13 | enabled: true 14 | required_executable: "cookstyle" 15 | command: ["cookstyle"] 16 | MarkdownLint: 17 | enabled: false 18 | required_executable: "npx" 19 | command: ["npx", "markdownlint-cli2", "'**/*.md'"] 20 | include: ["**/*.md"] 21 | 22 | CommitMsg: 23 | HardTabs: 24 | enabled: true 25 | -------------------------------------------------------------------------------- /test/integration/source/default.rb: -------------------------------------------------------------------------------- 1 | control 'commands should exist' do 2 | describe command('node -v') do 3 | its('exit_status') { should eq 0 } 4 | end 5 | 6 | describe command('npm -v') do 7 | its('exit_status') { should eq 0 } 8 | end 9 | 10 | describe file '/home/random/staging' do 11 | it { should exist } 12 | end 13 | 14 | describe command('npx -v') do 15 | its('exit_status') { should eq 0 } 16 | end 17 | 18 | describe file('/usr/local/bin/npm') do 19 | it { should exist } 20 | end 21 | 22 | describe file('/usr/local/bin/npx') do 23 | it { should exist } 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /.github/workflows/copilot-setup-steps.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: 'Copilot Setup Steps' 3 | 4 | "on": 5 | workflow_dispatch: 6 | push: 7 | paths: 8 | - .github/workflows/copilot-setup-steps.yml 9 | pull_request: 10 | paths: 11 | - .github/workflows/copilot-setup-steps.yml 12 | 13 | jobs: 14 | copilot-setup-steps: 15 | runs-on: ubuntu-latest 16 | permissions: 17 | contents: read 18 | steps: 19 | - name: Check out code 20 | uses: actions/checkout@v5 21 | - name: Install Chef 22 | uses: actionshub/chef-install@main 23 | - name: Install cookbooks 24 | run: berks install 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.rbc 2 | .config 3 | InstalledFiles 4 | pkg 5 | test/tmp 6 | test/version_tmp 7 | tmp 8 | _Store 9 | *~ 10 | *# 11 | .#* 12 | \#*# 13 | *.un~ 14 | *.tmp 15 | *.bk 16 | *.bkup 17 | 18 | # editor files 19 | .idea 20 | .*.sw[a-z] 21 | 22 | # ruby/bundler/rspec files 23 | .ruby-version 24 | .ruby-gemset 25 | .rvmrc 26 | Gemfile.lock 27 | .bundle 28 | *.gem 29 | coverage 30 | spec/reports 31 | 32 | # YARD / rdoc artifacts 33 | .yardoc 34 | _yardoc 35 | doc/ 36 | rdoc 37 | 38 | # chef infra stuff 39 | Berksfile.lock 40 | .kitchen 41 | kitchen.local.yml 42 | vendor/ 43 | .coverage/ 44 | .zero-knife.rb 45 | Policyfile.lock.json 46 | 47 | # vagrant stuff 48 | .vagrant/ 49 | .vagrant.d/ 50 | -------------------------------------------------------------------------------- /attributes/repo.rb: -------------------------------------------------------------------------------- 1 | case node['platform_family'] 2 | when 'debian' 3 | default['nodejs']['install_repo'] = true 4 | default['nodejs']['repo'] = 'https://deb.nodesource.com/node_20.x' 5 | default['nodejs']['distribution'] = 'nodistro' 6 | default['nodejs']['key'] = 'https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key' 7 | when 'rhel', 'amazon', 'fedora' 8 | default['nodejs']['install_repo'] = true 9 | node_version = platform?('amazon') ? '17.x' : '20.x' 10 | default['nodejs']['repo'] = "https://rpm.nodesource.com/pub_#{node_version}/nodistro/nodejs/$basearch" 11 | default['nodejs']['key'] = 'https://rpm.nodesource.com/gpgkey/ns-operations-public.key' 12 | end 13 | -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | name 'nodejs' 2 | maintainer 'Sous Chefs' 3 | maintainer_email 'help@sous-chefs.org' 4 | license 'Apache-2.0' 5 | description 'Installs/Configures node.js' 6 | version '10.2.3' 7 | source_url 'https://github.com/sous-chefs/nodejs' 8 | issues_url 'https://github.com/sous-chefs/nodejs/issues' 9 | chef_version '>= 15.3' 10 | 11 | supports 'amazon' 12 | supports 'centos' 13 | supports 'debian' 14 | supports 'mac_os_x' 15 | supports 'opensuseleap' 16 | supports 'oracle' 17 | supports 'redhat' 18 | supports 'scientific' 19 | supports 'smartos' 20 | supports 'suse' 21 | supports 'ubuntu' 22 | supports 'windows' 23 | 24 | depends 'ark', '>= 2.0.2' 25 | depends 'chocolatey', '>= 3.0' 26 | depends 'yum', '>= 7.2' 27 | -------------------------------------------------------------------------------- /attributes/packages.rb: -------------------------------------------------------------------------------- 1 | include_attribute 'nodejs::default' 2 | include_attribute 'nodejs::repo' 3 | 4 | default['nodejs']['packages'] = value_for_platform_family( 5 | 'debian' => node['nodejs']['install_repo'] ? ['nodejs'] : %w(nodejs npm nodejs-dev), 6 | %w(rhel fedora amazon) => node['nodejs']['install_repo'] ? %w(nodejs nodejs-devel) : %w(nodejs npm nodejs-dev), 7 | 'suse' => %w(nodejs npm nodejs-devel), 8 | 'mac_os_x' => ['node'], 9 | 'freebsd' => %w(node npm), 10 | 'default' => ['nodejs'] 11 | ) 12 | 13 | # Add options and actions by package name 14 | default['nodejs']['package_action'] = { default: :install } 15 | default['nodejs']['package_options'] = { default: '' } 16 | # Disable upstream DNF module on EL8 based systems 17 | default['nodejs']['dnf_module'] = false 18 | -------------------------------------------------------------------------------- /recipes/install.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Marius Ducea (marius@promethost.com) 3 | # Cookbook:: nodejs 4 | # Recipe:: install 5 | # 6 | # Copyright:: 2010-2017, Promet Solutions 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | include_recipe "nodejs::nodejs_from_#{node['nodejs']['install_method']}" 22 | -------------------------------------------------------------------------------- /recipes/nodejs.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Marius Ducea (marius@promethost.com) 3 | # Cookbook:: nodejs 4 | # Recipe:: nodejs 5 | # 6 | # Copyright:: 2010-2017, Promet Solutions 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | Chef::Log.fatal('The nodejs::nodejs recipe is no longer used. Use nodejs::install to install nodejs instead.') 22 | -------------------------------------------------------------------------------- /kitchen.global.yml: -------------------------------------------------------------------------------- 1 | --- 2 | provisioner: 3 | name: chef_infra 4 | product_name: chef 5 | product_version: <%= ENV['CHEF_VERSION'] || 'latest' %> 6 | channel: stable 7 | install_strategy: once 8 | chef_license: accept 9 | enforce_idempotency: <%= ENV['ENFORCE_IDEMPOTENCY'] || true %> 10 | multiple_converge: <%= ENV['MULTIPLE_CONVERGE'] || 2 %> 11 | deprecations_as_errors: true 12 | log_level: <%= ENV['CHEF_LOG_LEVEL'] || 'auto' %> 13 | 14 | verifier: 15 | name: inspec 16 | 17 | platforms: 18 | - name: almalinux-8 19 | - name: almalinux-9 20 | - name: amazonlinux-2023 21 | - name: centos-stream-9 22 | - name: debian-11 23 | - name: debian-12 24 | - name: fedora-latest 25 | - name: opensuse-leap-15 26 | - name: oraclelinux-8 27 | - name: oraclelinux-9 28 | - name: rockylinux-8 29 | - name: rockylinux-9 30 | - name: ubuntu-20.04 31 | - name: ubuntu-22.04 32 | - name: ubuntu-24.04 33 | -------------------------------------------------------------------------------- /recipes/nodejs_from_chocolatey.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Hossein Margani (hossein@margani.dev) 3 | # Cookbook:: nodejs 4 | # Recipe:: install_from_chocolatey 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | include_recipe 'chocolatey' 20 | 21 | chocolatey_package 'nodejs-lts' do 22 | version node['nodejs']['version'] if node['nodejs']['version'] 23 | action :upgrade 24 | end 25 | -------------------------------------------------------------------------------- /recipes/default.rb: -------------------------------------------------------------------------------- 1 | 2 | # Author:: Marius Ducea (marius@promethost.com) 3 | # Cookbook:: nodejs 4 | # Recipe:: default 5 | # 6 | # Copyright:: 2010-2017, Promet Solutions 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | include_recipe 'nodejs::install' if node['nodejs']['manage_node'] 22 | include_recipe 'nodejs::npm' if node['nodejs']['manage_node'] 23 | include_recipe 'nodejs::npm_packages' if node['nodejs']['manage_node'] 24 | -------------------------------------------------------------------------------- /recipes/npm.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Marius Ducea (marius@promethost.com) 3 | # Cookbook:: nodejs 4 | # Recipe:: npm 5 | # 6 | # Copyright:: 2010-2017, Promet Solutions 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | case node['nodejs']['npm']['install_method'] 22 | when 'embedded' 23 | include_recipe 'nodejs::install' 24 | when 'source' 25 | include_recipe 'nodejs::npm_from_source' 26 | else 27 | Chef::Log.error('No install method found for npm') 28 | end 29 | -------------------------------------------------------------------------------- /recipes/npm_from_source.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Marius Ducea (marius@promethost.com) 3 | # Cookbook:: nodejs 4 | # Recipe:: npm 5 | # 6 | # Copyright:: 2010-2017, Promet Solutions 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | Chef::DSL::Recipe.include NodeJs::Helper 22 | 23 | include_recipe 'nodejs::nodejs_from_source' 24 | 25 | dist = npm_dist 26 | 27 | ark 'npm' do 28 | url dist['url'] 29 | checksum dist['checksum'] 30 | version dist['version'] 31 | action :install_with_make 32 | end 33 | -------------------------------------------------------------------------------- /test/integration/default/default_spec.rb: -------------------------------------------------------------------------------- 1 | os_family = os.family 2 | 3 | control 'commands should exist' do 4 | describe command('node -v') do 5 | its('exit_status') { should eq 0 } 6 | # No upstream repository so it installs the OS version 7 | unless os_family == 'suse' 8 | its('stdout') { should match /^v17\.*/ } 9 | end 10 | end 11 | 12 | describe command('npm -v') do 13 | its('exit_status') { should eq 0 } 14 | # No upstream repository so it installs the OS version 15 | unless os_family == 'suse' 16 | its('stdout') { should match /^8\.*/ } 17 | end 18 | end 19 | 20 | describe command('npx -v') do 21 | its('exit_status') { should eq 0 } 22 | # No upstream repository so it installs the OS version 23 | unless os_family == 'suse' 24 | its('stdout') { should match /^8\.*/ } 25 | end 26 | end 27 | 28 | describe command('npm list -json -global') do 29 | its('stdout') { should_not match(/"express"/) } 30 | its('stdout') { should match(/"socket.io"/) } 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Mark stale issues and pull requests 3 | 4 | "on": 5 | schedule: [cron: "0 0 * * *"] 6 | 7 | jobs: 8 | stale: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/stale@v10 12 | with: 13 | repo-token: ${{ secrets.GITHUB_TOKEN }} 14 | close-issue-message: > 15 | Closing due to inactivity. 16 | If this is still an issue please reopen or open another issue. 17 | Alternatively drop by the #sous-chefs channel on the [Chef Community Slack](http://community-slack.chef.io/) and we'll be happy to help! 18 | Thanks, Sous-Chefs. 19 | days-before-close: 7 20 | days-before-stale: 365 21 | stale-issue-message: > 22 | Marking stale due to inactivity. 23 | Remove stale label or comment or this will be closed in 7 days. 24 | Alternatively drop by the #sous-chefs channel on the [Chef Community Slack](http://community-slack.chef.io/) and we'll be happy to help! 25 | Thanks, Sous-Chefs. 26 | -------------------------------------------------------------------------------- /kitchen.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: 3 | name: vagrant 4 | 5 | suites: 6 | - name: default 7 | run_list: 8 | - recipe[nodejs::default] 9 | attributes: 10 | nodejs: 11 | manage_node: true 12 | npm: 13 | install_method: embedded 14 | npm_packages: 15 | - name: express 16 | - name: socket.io 17 | version: 1.0.4 18 | - name: express 19 | action: :uninstall 20 | - name: npm_embedded 21 | run_list: 22 | - recipe[nodejs::npm] 23 | attributes: 24 | nodejs: 25 | npm: 26 | install_method: embedded 27 | - name: npm_source 28 | run_list: 29 | - recipe[nodejs::npm] 30 | attributes: 31 | nodejs: 32 | npm: 33 | install_method: source 34 | - name: package 35 | run_list: 36 | - recipe[test::default] 37 | - name: source 38 | run_list: 39 | - recipe[test::source] 40 | - name: options 41 | run_list: 42 | - recipe[nodejs] 43 | attributes: 44 | nodejs: 45 | packages: 46 | - nodejs 47 | - acpid 48 | - adcli 49 | package_options: 50 | acpid: "--force-yes" 51 | package_action: 52 | adcli: :nothing 53 | -------------------------------------------------------------------------------- /test/integration/package/default.rb: -------------------------------------------------------------------------------- 1 | control 'commands should exist' do 2 | describe command('node -v') do 3 | its('exit_status') { should eq 0 } 4 | end 5 | 6 | describe command('npm -v') do 7 | its('exit_status') { should eq 0 } 8 | end 9 | 10 | describe file '/home/random/staging' do 11 | it { should exist } 12 | end 13 | 14 | describe command('npm list -json -global') do 15 | its('stdout') { should match(/express/) } 16 | its('stdout') { should match(/"async": {\n\s*"version": "0.6.2"/) } 17 | its('stdout') { should match(/request/) } 18 | its('stdout') { should match(/mocha/) } 19 | end 20 | 21 | describe command('npm list xss -json -global') do 22 | its('stdout') { should match(/"version":\s*"1.0.7"/) } 23 | end 24 | 25 | describe command('npm list minify -json -global') do 26 | its('stdout') { should_not match(/"version":\s*"5.2.0"/) } 27 | end 28 | 29 | describe command('export NPM_TOKEN="123-abcde" && cd /home/random && npm list -json') do 30 | its('stdout') { should match(/koa/) } 31 | its('stdout') { should match(/gulp/) } 32 | end 33 | 34 | describe command('export NPM_TOKEN="123-abcde" && cd /home/random1 && npm list -json') do 35 | its('stdout') { should match(/koa/) } 36 | its('stdout') { should match(/gulp/) } 37 | end 38 | 39 | describe command('export NPM_TOKEN="123-abcde" && cd /home/random2 && npm list -json') do 40 | its('stdout') { should match(/grunt/) } 41 | its('stdout') { should match(/vary/) } 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /recipes/nodejs_from_package.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Nathan L Smith (nlloyds@gmail.com) 3 | # Author:: Marius Ducea (marius@promethost.com) 4 | # Cookbook:: nodejs 5 | # Recipe:: package 6 | # 7 | # Copyright:: 2012-2017, Cramer Development, Inc. 8 | # Copyright:: 2013-2017, Opscale 9 | # 10 | # Licensed under the Apache License, Version 2.0 (the "License"); 11 | # you may not use this file except in compliance with the License. 12 | # You may obtain a copy of the License at 13 | # 14 | # http://www.apache.org/licenses/LICENSE-2.0 15 | # 16 | # Unless required by applicable law or agreed to in writing, software 17 | # distributed under the License is distributed on an "AS IS" BASIS, 18 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | # See the License for the specific language governing permissions and 20 | # limitations under the License. 21 | # 22 | 23 | include_recipe 'nodejs::repo' if node['nodejs']['install_repo'] 24 | 25 | unless node['nodejs']['packages'] 26 | Chef::Log.error 'No package for nodejs' 27 | Chef::Log.warn 'Please use the source or binary method to install node' 28 | return 29 | end 30 | 31 | if platform_family?('rhel', 'fedora') && node['platform_version'].to_i >= 8 && !node['nodejs']['dnf_module'] 32 | dnf_module 'nodejs' do 33 | action :disable 34 | only_if 'dnf module list nodejs' 35 | end 36 | end 37 | 38 | node['nodejs']['packages'].each do |node_pkg| 39 | package node_pkg do 40 | action node['nodejs']['package_action'][node_pkg] if node['nodejs']['package_action'][node_pkg] 41 | options node['nodejs']['package_options'][node_pkg] if node['nodejs']['package_options'][node_pkg] 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /recipes/nodejs_from_source.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Marius Ducea (marius@promethost.com) 3 | # Cookbook:: nodejs 4 | # Recipe:: source 5 | # 6 | # Copyright:: 2010-2017, Promet Solutions 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | Chef::DSL::Recipe.include NodeJs::Helper 22 | 23 | build_essential 'install build tools' 24 | 25 | case node['platform_family'] 26 | when 'rhel', 'fedora', 'amazon' 27 | package %w(openssl-devel python3 tar) 28 | when 'debian' 29 | package %w(libssl-dev python3) 30 | else 31 | package %w(python3) 32 | end 33 | 34 | version = "v#{node['nodejs']['version']}/" 35 | prefix = node['nodejs']['prefix_url']['node'] 36 | filename = "node-v#{node['nodejs']['version']}.tar.gz" 37 | archive_name = 'nodejs-source' 38 | 39 | nodejs_src_url = node['nodejs']['source']['url'] || ::URI.join(prefix, version, filename).to_s 40 | 41 | ark archive_name do 42 | url nodejs_src_url 43 | version node['nodejs']['version'] 44 | checksum node['nodejs']['source']['checksum'] 45 | make_opts ["-j #{node['nodejs']['make_threads']}"] 46 | action :install_with_make 47 | environment(PYTHON: 'python3') 48 | end 49 | -------------------------------------------------------------------------------- /Dangerfile: -------------------------------------------------------------------------------- 1 | # Reference: http://danger.systems/reference.html 2 | 3 | # A pull request summary is required. Add a description of the pull request purpose. 4 | # Changelog must be updated for each pull request that changes code. 5 | # Warnings will be issued for: 6 | # Pull request with more than 400 lines of code changed 7 | # Pull reqest that change more than 5 lines without test changes 8 | # Failures will be issued for: 9 | # Pull request without summary 10 | # Pull requests with code changes without changelog entry 11 | 12 | def code_changes? 13 | code = %w(libraries attributes recipes resources files templates) 14 | code.each do |location| 15 | return true unless git.modified_files.grep(/#{location}/).empty? 16 | end 17 | false 18 | end 19 | 20 | def test_changes? 21 | tests = %w(spec test kitchen.yml kitchen.dokken.yml) 22 | tests.each do |location| 23 | return true unless git.modified_files.grep(/#{location}/).empty? 24 | end 25 | false 26 | end 27 | 28 | failure 'Please provide a summary of your Pull Request.' if github.pr_body.length < 10 29 | 30 | warn 'This is a big Pull Request.' if git.lines_of_code > 400 31 | 32 | warn 'This is a Table Flip.' if git.lines_of_code > 2000 33 | 34 | # Require a CHANGELOG entry for non-test changes. 35 | if !git.modified_files.include?('CHANGELOG.md') && code_changes? 36 | failure 'Please include a CHANGELOG entry.' 37 | end 38 | 39 | # Require Major Minor Patch version labels 40 | unless github.pr_labels.grep /minor|major|patch/i 41 | warn 'Please add a release label to this pull request' 42 | end 43 | 44 | # A sanity check for tests. 45 | if git.lines_of_code > 5 && code_changes? && !test_changes? 46 | warn 'This Pull Request is probably missing tests.' 47 | end 48 | -------------------------------------------------------------------------------- /recipes/repo.rb: -------------------------------------------------------------------------------- 1 | case node['platform_family'] 2 | when 'debian' 3 | # Install necessary packages for downloading and verifying new repository information 4 | package %w(ca-certificates curl gnupg apt-transport-https) 5 | 6 | # Create a directory for the new repository's keyring, if it doesn't exist 7 | directory '/etc/apt/keyrings' 8 | 9 | # Download the new repository's GPG key and save it in the keyring directory 10 | execute 'add nodejs gpg key' do 11 | command "curl -fsSL #{node['nodejs']['key']} | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg" 12 | not_if { ::File.exist? '/etc/apt/keyrings/nodesource.gpg' } 13 | end 14 | 15 | # Prefer nodesource over Ubuntu universe packages by giving a higher priority (default 500) 16 | apt_preference 'nodesource' do 17 | glob '*' 18 | pin 'origin deb.nodesource.com' 19 | pin_priority '600' 20 | end 21 | 22 | if Gem::Version.new('18.3.0') <= Chef::VERSION 23 | apt_repository 'nodesource' do 24 | uri node['nodejs']['repo'] 25 | components ['main'] 26 | options ['signed-by=/etc/apt/keyrings/nodesource.gpg'] 27 | distribution node['nodejs']['distribution'] 28 | end 29 | else 30 | # Chef Infra < 18.3 doesn't support options attribute, fallback to (deprecated) apt-key method 31 | apt_repository 'nodesource' do 32 | uri node['nodejs']['repo'] 33 | components ['main'] 34 | key '2F59B5F99B1BE0B4' 35 | keyserver 'keyserver.ubuntu.com' 36 | distribution node['nodejs']['distribution'] 37 | end 38 | end 39 | 40 | when 'rhel', 'fedora', 'amazon' 41 | yum_repository 'nodesource-nodejs' do 42 | description 'nodesource.com nodejs repository' 43 | baseurl node['nodejs']['repo'] 44 | gpgkey node['nodejs']['key'] 45 | priority '9' 46 | options(module_hotfixes: 1) 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: ci 3 | 4 | "on": 5 | pull_request: 6 | push: 7 | branches: [main] 8 | 9 | jobs: 10 | lint-unit: 11 | uses: sous-chefs/.github/.github/workflows/lint-unit.yml@5.0.3 12 | permissions: 13 | actions: write 14 | checks: write 15 | pull-requests: write 16 | statuses: write 17 | issues: write 18 | 19 | integration: 20 | needs: lint-unit 21 | runs-on: ubuntu-latest 22 | strategy: 23 | matrix: 24 | os: 25 | - "almalinux-9" 26 | - "rockylinux-9" 27 | - "amazonlinux-2023" 28 | - "centos-stream-9" 29 | - "centos-stream-10" 30 | - "debian-11" 31 | - "debian-12" 32 | - "ubuntu-2204" 33 | - "ubuntu-2404" 34 | suite: 35 | - "default" 36 | - "npm-embedded" 37 | - "package" 38 | - "source" 39 | exclude: 40 | - os: "amazonlinux-2023" 41 | suite: "source" 42 | - os: "fedora-latest" 43 | suite: "source" 44 | fail-fast: false 45 | 46 | steps: 47 | - name: Check out code 48 | uses: actions/checkout@v5 49 | - name: Install Chef 50 | uses: actionshub/chef-install@3.0.1 51 | - name: Dokken 52 | uses: actionshub/test-kitchen@3.0.0 53 | env: 54 | CHEF_LICENSE: accept-no-persist 55 | KITCHEN_LOCAL_YAML: kitchen.dokken.yml 56 | with: 57 | suite: ${{ matrix.suite }} 58 | os: ${{ matrix.os }} 59 | 60 | success: 61 | if: ${{ always() }} 62 | needs: ["integration"] 63 | name: Integration Successful 64 | runs-on: ubuntu-latest 65 | steps: 66 | - if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} 67 | name: Check matrix status 68 | run: exit 1 69 | -------------------------------------------------------------------------------- /chefignore: -------------------------------------------------------------------------------- 1 | # Put files/directories that should be ignored in this file when uploading 2 | # to a Chef Infra Server or Supermarket. 3 | # Lines that start with '# ' are comments. 4 | 5 | # OS generated files # 6 | ###################### 7 | .DS_Store 8 | ehthumbs.db 9 | Icon? 10 | nohup.out 11 | Thumbs.db 12 | .envrc 13 | 14 | # EDITORS # 15 | ########### 16 | .#* 17 | .project 18 | .settings 19 | *_flymake 20 | *_flymake.* 21 | *.bak 22 | *.sw[a-z] 23 | *.tmproj 24 | *~ 25 | \#* 26 | REVISION 27 | TAGS* 28 | tmtags 29 | .vscode 30 | .editorconfig 31 | 32 | ## COMPILED ## 33 | ############## 34 | *.class 35 | *.com 36 | *.dll 37 | *.exe 38 | *.o 39 | *.pyc 40 | *.so 41 | */rdoc/ 42 | a.out 43 | mkmf.log 44 | 45 | # Testing # 46 | ########### 47 | .circleci/* 48 | .codeclimate.yml 49 | .delivery/* 50 | .foodcritic 51 | .kitchen* 52 | .mdlrc 53 | .overcommit.yml 54 | .rspec 55 | .rubocop.yml 56 | .travis.yml 57 | .watchr 58 | .yamllint 59 | azure-pipelines.yml 60 | Dangerfile 61 | examples/* 62 | features/* 63 | Guardfile 64 | kitchen*.yml 65 | mlc_config.json 66 | Procfile 67 | Rakefile 68 | spec/* 69 | test/* 70 | 71 | # SCM # 72 | ####### 73 | .git 74 | .gitattributes 75 | .gitconfig 76 | .github/* 77 | .gitignore 78 | .gitkeep 79 | .gitmodules 80 | .svn 81 | */.bzr/* 82 | */.git 83 | */.hg/* 84 | */.svn/* 85 | 86 | # Berkshelf # 87 | ############# 88 | Berksfile 89 | Berksfile.lock 90 | cookbooks/* 91 | tmp 92 | 93 | # Bundler # 94 | ########### 95 | vendor/* 96 | Gemfile 97 | Gemfile.lock 98 | 99 | # Policyfile # 100 | ############## 101 | Policyfile.rb 102 | Policyfile.lock.json 103 | 104 | # Documentation # 105 | ############# 106 | CODE_OF_CONDUCT* 107 | CONTRIBUTING* 108 | documentation/* 109 | TESTING* 110 | UPGRADING* 111 | 112 | # Vagrant # 113 | ########### 114 | .vagrant 115 | Vagrantfile 116 | -------------------------------------------------------------------------------- /attributes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: nodejs 3 | # Attributes:: nodejs 4 | # 5 | # Copyright:: 2010-2017, Promet Solutions 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | default['nodejs']['install_method'] = case node['platform_family'] 21 | when 'smartos', 'rhel', 'debian', 'fedora', 'mac_os_x', 'suse', 'amazon' 22 | 'package' 23 | when 'windows' 24 | 'chocolatey' 25 | else 26 | 'source' 27 | end 28 | 29 | default['nodejs']['version'] = '22.11.0' 30 | 31 | default['nodejs']['prefix_url']['node'] = 'https://nodejs.org/dist/' 32 | 33 | default['nodejs']['tmpdir'] = '/tmp' 34 | default['nodejs']['source']['url'] = nil # Auto generated 35 | default['nodejs']['source']['checksum'] = '24e5130fa7bc1eaab218a0c9cb05e03168fa381bb9e3babddc6a11f655799222' 36 | 37 | default['nodejs']['binary']['url'] = nil # Auto generated 38 | default['nodejs']['binary']['checksum']['linux_x64'] = '8c9f4c95c254336fcb2c768e746f4316b8176adc0fb599cbbb460d0933991d12' 39 | default['nodejs']['binary']['checksum']['linux_arm64'] = 'd4acf5c0380c96c867428d0232666d3327dc5fa83a694d7b63f728a76ece84b2' 40 | default['nodejs']['binary']['append_env_path'] = true 41 | 42 | default['nodejs']['make_threads'] = node['cpu'] ? node['cpu']['total'].to_i : 2 43 | 44 | default['nodejs']['manage_node'] = true 45 | -------------------------------------------------------------------------------- /libraries/nodejs_helper.rb: -------------------------------------------------------------------------------- 1 | module NodeJs 2 | module Helper 3 | def npm_dist 4 | if node['nodejs']['npm']['url'] 5 | { 'url' => node['nodejs']['npm']['url'] } 6 | else 7 | 8 | require 'open-uri' 9 | require 'json' 10 | result = JSON.parse(URI.parse("https://registry.npmjs.org/npm/#{node['nodejs']['npm']['version']}").read, max_nesting: false) 11 | ret = { 'url' => result['dist']['tarball'], 'version' => result['_npmVersion'], 'shasum' => result['dist']['shasum'] } 12 | Chef::Log.debug("Npm dist #{ret}") 13 | ret 14 | end 15 | end 16 | 17 | def npm_list(package, path = nil, environment = {}) 18 | require 'json' 19 | cmd = if path 20 | Mixlib::ShellOut.new("npm list #{package} -json", cwd: path, environment: environment) 21 | else 22 | Mixlib::ShellOut.new("npm list #{package} -global -json", environment: environment) 23 | end 24 | 25 | begin 26 | JSON.parse(cmd.run_command.stdout, max_nesting: false) 27 | rescue JSON::ParserError => e 28 | Chef::Log.error("nodejs::library::nodejs_helper::npm_list exception #{e}") 29 | {} 30 | end 31 | end 32 | 33 | def url_valid?(list, package) 34 | require 'open-uri' 35 | 36 | begin 37 | URI.parse(list.fetch(package, {}).fetch('resolved')) 38 | rescue KeyError 39 | # the package may have been installed without using a url 40 | true 41 | rescue URI::InvalidURIError 42 | false 43 | end 44 | end 45 | 46 | def version_valid?(list, package, version) 47 | (version ? list[package]['version'] == version : true) 48 | end 49 | 50 | def npm_package_installed?(package, version = nil, path = nil, environment = {}) 51 | list = npm_list(package, path, environment)['dependencies'] 52 | # Return true if package installed and installed to good version 53 | # see if we really want to add the url check 54 | !list.nil? && list.key?(package) && version_valid?(list, package, version) && url_valid?(list, package) 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /kitchen.dokken.yml: -------------------------------------------------------------------------------- 1 | driver: 2 | name: dokken 3 | privileged: true 4 | chef_version: <%= ENV['CHEF_VERSION'] || 'current' %> 5 | 6 | transport: { name: dokken } 7 | provisioner: { name: dokken } 8 | 9 | platforms: 10 | - name: almalinux-8 11 | driver: 12 | image: dokken/almalinux-8 13 | pid_one_command: /usr/lib/systemd/systemd 14 | 15 | - name: almalinux-9 16 | driver: 17 | image: dokken/almalinux-9 18 | pid_one_command: /usr/lib/systemd/systemd 19 | 20 | - name: almalinux-10 21 | driver: 22 | image: dokken/almalinux-10 23 | pid_one_command: /usr/lib/systemd/systemd 24 | 25 | - name: amazonlinux-2023 26 | driver: 27 | image: dokken/amazonlinux-2023 28 | pid_one_command: /usr/lib/systemd/systemd 29 | 30 | - name: centos-stream-9 31 | driver: 32 | image: dokken/centos-stream-9 33 | pid_one_command: /usr/lib/systemd/systemd 34 | 35 | - name: centos-stream-10 36 | driver: 37 | image: dokken/centos-stream-10 38 | pid_one_command: /usr/lib/systemd/systemd 39 | 40 | - name: debian-12 41 | driver: 42 | image: dokken/debian-12 43 | pid_one_command: /bin/systemd 44 | 45 | - name: debian-13 46 | driver: 47 | image: dokken/debian-13 48 | pid_one_command: /usr/lib/systemd/systemd 49 | 50 | - name: fedora-latest 51 | driver: 52 | image: dokken/fedora-latest 53 | pid_one_command: /usr/lib/systemd/systemd 54 | 55 | - name: opensuse-leap-15 56 | driver: 57 | image: dokken/opensuse-leap-15 58 | pid_one_command: /usr/lib/systemd/systemd 59 | 60 | - name: oraclelinux-8 61 | driver: 62 | image: dokken/oraclelinux-8 63 | pid_one_command: /usr/lib/systemd/systemd 64 | 65 | - name: oraclelinux-9 66 | driver: 67 | image: dokken/oraclelinux-9 68 | pid_one_command: /usr/lib/systemd/systemd 69 | 70 | - name: rockylinux-8 71 | driver: 72 | image: dokken/rockylinux-8 73 | pid_one_command: /usr/lib/systemd/systemd 74 | 75 | - name: rockylinux-9 76 | driver: 77 | image: dokken/rockylinux-9 78 | pid_one_command: /usr/lib/systemd/systemd 79 | 80 | - name: rockylinux-10 81 | driver: 82 | image: dokken/rockylinux-10 83 | pid_one_command: /usr/lib/systemd/systemd 84 | 85 | - name: ubuntu-20.04 86 | driver: 87 | image: dokken/ubuntu-20.04 88 | pid_one_command: /bin/systemd 89 | 90 | - name: ubuntu-22.04 91 | driver: 92 | image: dokken/ubuntu-22.04 93 | pid_one_command: /bin/systemd 94 | 95 | - name: ubuntu-24.04 96 | driver: 97 | image: dokken/ubuntu-24.04 98 | pid_one_command: /bin/systemd 99 | -------------------------------------------------------------------------------- /spec/unit/recipes/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'default recipe on ubuntu 22.04' do 4 | let(:runner) { ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '22.04') } 5 | let(:chef_run) { runner.converge('nodejs::default') } 6 | 7 | it 'includes the package install recipes' do 8 | expect(chef_run).to include_recipe('nodejs::nodejs_from_package') 9 | expect(chef_run).to include_recipe('nodejs::npm_packages') 10 | end 11 | 12 | it 'converges successfully' do 13 | expect { :chef_run }.to_not raise_error 14 | end 15 | end 16 | 17 | describe 'default recipe on centos 8' do 18 | let(:runner) { ChefSpec::ServerRunner.new(platform: 'centos', version: '8') } 19 | let(:chef_run) { runner.converge('nodejs::default') } 20 | 21 | it 'includes the package install recipes' do 22 | stub_command('dnf module list nodejs').and_return(0) 23 | expect(chef_run).to include_recipe('nodejs::nodejs_from_package') 24 | expect(chef_run).to include_recipe('nodejs::npm_packages') 25 | end 26 | 27 | it 'converges successfully' do 28 | expect { :chef_run }.to_not raise_error 29 | end 30 | end 31 | 32 | describe 'default recipe on debian 12' do 33 | let(:runner) { ChefSpec::ServerRunner.new(platform: 'debian', version: '12') } 34 | let(:chef_run) { runner.converge('nodejs::default') } 35 | 36 | it 'includes the package install recipes' do 37 | expect(chef_run).to include_recipe('nodejs::nodejs_from_package') 38 | expect(chef_run).to include_recipe('nodejs::npm_packages') 39 | end 40 | 41 | it 'converges successfully' do 42 | expect { :chef_run }.to_not raise_error 43 | end 44 | end 45 | 46 | describe 'default recipe on mac_os_x' do 47 | let(:runner) { ChefSpec::ServerRunner.new(platform: 'mac_os_x') } 48 | let(:chef_run) { runner.converge('nodejs::default') } 49 | 50 | it 'includes the package install recipes' do 51 | expect(chef_run).to include_recipe('nodejs::nodejs_from_package') 52 | expect(chef_run).to include_recipe('nodejs::npm_packages') 53 | end 54 | 55 | it 'converges successfully' do 56 | expect { :chef_run }.to_not raise_error 57 | end 58 | end 59 | 60 | describe 'default recipe on fedora' do 61 | let(:runner) { ChefSpec::ServerRunner.new(platform: 'fedora') } 62 | let(:chef_run) do 63 | stub_command('dnf module list nodejs').and_return(0) 64 | runner.converge('nodejs::default') 65 | end 66 | 67 | it 'includes the package install recipes' do 68 | expect(chef_run).to include_recipe('nodejs::nodejs_from_package') 69 | expect(chef_run).to include_recipe('nodejs::npm_packages') 70 | end 71 | 72 | it 'converges successfully' do 73 | expect { :chef_run }.to_not raise_error 74 | end 75 | end 76 | -------------------------------------------------------------------------------- /recipes/nodejs_from_binary.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Julian Wilde (jules@jules.com.au) 3 | # Cookbook:: nodejs 4 | # Recipe:: install_from_binary 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | Chef::DSL::Recipe.include NodeJs::Helper 20 | 21 | # Shamelessly borrowed from http://docs.chef.io/dsl_recipe_method_platform.html 22 | # Surely there's a more canonical way to get arch? 23 | arch = if node['kernel']['machine'] =~ /armv6l/ 24 | # FIXME: This should really check the version of node we're looking for 25 | # as it seems that they haven't build an `arm-pi` version in a while... 26 | # if it's old, return this, otherwise just return `node['kernel']['machine']` 27 | 'arm-pi' # assume a raspberry pi 28 | elsif node['kernel']['machine'] =~ /aarch64/ 29 | 'arm64' 30 | elsif node['kernel']['machine'] =~ /x86_64/ 31 | 'x64' 32 | elsif node['kernel']['machine'] =~ /\d86/ 33 | 'x86' 34 | else 35 | node['kernel']['machine'] 36 | end 37 | 38 | # needed to uncompress the binary 39 | package 'tar' if platform_family?('rhel', 'fedora', 'amazon', 'suse') 40 | 41 | # package_stub is for example: "node-v6.9.1-linux-x64.tar.gz" 42 | version = "v#{node['nodejs']['version']}/" 43 | prefix = node['nodejs']['prefix_url']['node'] 44 | 45 | filename = "node-v#{node['nodejs']['version']}-linux-#{arch}.tar.gz" 46 | archive_name = 'nodejs-binary' 47 | binaries = ['bin/node'] 48 | 49 | binaries.push('bin/npm') if node['nodejs']['npm']['install_method'] == 'embedded' 50 | binaries.push('bin/npx') if node['nodejs']['npm']['install_method'] == 'embedded' 51 | 52 | if node['nodejs']['binary']['url'] 53 | nodejs_bin_url = node['nodejs']['binary']['url'] 54 | checksum = node['nodejs']['binary']['checksum'] 55 | else 56 | nodejs_bin_url = ::URI.join(prefix, version, filename).to_s 57 | checksum = node['nodejs']['binary']['checksum']["linux_#{arch}"] 58 | end 59 | 60 | ark archive_name do 61 | url nodejs_bin_url 62 | version node['nodejs']['version'] 63 | checksum checksum 64 | has_binaries binaries 65 | append_env_path node['nodejs']['binary']['append_env_path'] 66 | action :install 67 | end 68 | -------------------------------------------------------------------------------- /test/cookbooks/test/recipes/resource.rb: -------------------------------------------------------------------------------- 1 | apt_update 'update' 2 | 3 | include_recipe 'nodejs::npm' 4 | include_recipe 'git' 5 | 6 | user 'random' do 7 | manage_home true 8 | home '/home/random' 9 | end 10 | 11 | user 'random1' do 12 | manage_home true 13 | home '/home/random1' 14 | end 15 | 16 | user 'random2' do 17 | manage_home true 18 | home '/home/random2' 19 | end 20 | 21 | # global "express" using the old resource name 22 | nodejs_npm 'express' 23 | 24 | npm_package 'async' do 25 | version '0.6.2' 26 | end 27 | 28 | npm_package 'xss' do 29 | version '1.0.7' 30 | end 31 | 32 | npm_package 'xss noupgrade' do 33 | package 'xss' 34 | auto_update false 35 | end 36 | 37 | npm_package 'minify' do 38 | version '5.2.0' 39 | end 40 | 41 | npm_package 'minify upgrade' do 42 | package 'minify' 43 | live_stream true 44 | end 45 | 46 | npm_package 'request' do 47 | url 'github mikeal/request' 48 | live_stream true 49 | end 50 | 51 | npm_package 'mocha' do 52 | options ['--force', '--production'] 53 | end 54 | 55 | git '/home/random2/grunt' do 56 | repository 'https://github.com/gruntjs/grunt' 57 | user 'random2' 58 | end 59 | 60 | directory '/home/random2/.npm' do 61 | owner 'random2' 62 | end 63 | 64 | npm_package 'Install the grunt package' do 65 | path '/home/random2' 66 | package 'grunt' 67 | json '/home/random2/grunt' 68 | user 'random2' 69 | end 70 | 71 | npm_package 'Install the vary package from a tgz url' do 72 | path '/home/random2' 73 | package 'vary' 74 | json 'https://registry.npmjs.org/vary/-/vary-1.1.2.tgz' 75 | user 'random2' 76 | end 77 | 78 | directory '/home/random/.npm' do 79 | owner 'random' 80 | end 81 | 82 | # Create a package.json file for the test user 83 | template '/home/random/package.json' do 84 | source 'package.json' 85 | owner 'random' 86 | user 'random' 87 | end 88 | 89 | # Create an .npmrc file for the test user 90 | file '/home/random/.npmrc' do 91 | content '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' 92 | owner 'random' 93 | user 'random' 94 | end 95 | 96 | # Test npm_token usage (for NPM private repositories) 97 | npm_package 'from_package_json' do 98 | path '/home/random' 99 | json true 100 | user 'random' 101 | npm_token '123-abcde' 102 | node_env 'staging' # Test node_env usage 103 | end 104 | 105 | directory '/home/random1/.npm' do 106 | owner 'random1' 107 | end 108 | 109 | # Create an .npmrc file for the test user 110 | file '/home/random1/.npmrc' do 111 | content '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' 112 | owner 'random1' 113 | user 'random1' 114 | end 115 | 116 | # Create a package.json file for the test user 117 | template '/home/random1/package.json' do 118 | source 'package.json' 119 | owner 'random1' 120 | user 'random1' 121 | end 122 | 123 | # Test npm_token usage (for NPM private repositories) 124 | npm_package 'from_package_json_private' do 125 | path '/home/random1' 126 | json true 127 | npm_token '123-abcde' 128 | options ['--development'] 129 | node_env 'development' 130 | end 131 | -------------------------------------------------------------------------------- /resources/npm_package.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: nodejs 3 | # Resource:: npm 4 | # 5 | # Author:: Sergey Balbeko 6 | # 7 | # Copyright:: 2012-2017, Sergey Balbeko 8 | # 9 | # Licensed under the Apache License, Version 2.0 (the "License"); 10 | # you may not use this file except in compliance with the License. 11 | # You may obtain a copy of the License at 12 | # 13 | # http://www.apache.org/licenses/LICENSE-2.0 14 | # 15 | # Unless required by applicable law or agreed to in writing, software 16 | # distributed under the License is distributed on an "AS IS" BASIS, 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | # See the License for the specific language governing permissions and 19 | # limitations under the License. 20 | # 21 | 22 | resource_name :npm_package 23 | provides :npm_package 24 | unified_mode true 25 | 26 | # backwards compatibility for the old resource name 27 | provides :nodejs_npm 28 | 29 | property :package, String, name_property: true 30 | property :version, String 31 | property :path, String 32 | property :url, String 33 | property :json, [String, true, false] 34 | property :npm_token, String 35 | property :options, Array, default: [] 36 | property :user, String 37 | property :group, String 38 | property :live_stream, [false, true], default: false 39 | property :node_env, String 40 | property :auto_update, [true, false], default: true 41 | 42 | def initialize(*args) 43 | super 44 | @run_context.include_recipe 'nodejs::npm' if node['nodejs']['manage_node'] 45 | end 46 | 47 | action :install do 48 | execute "install NPM package #{new_resource.package}" do 49 | cwd new_resource.path 50 | command "npm install #{npm_options}" 51 | user new_resource.user 52 | group new_resource.group 53 | environment npm_env_vars 54 | live_stream new_resource.live_stream 55 | not_if { package_installed? && no_auto_update? } 56 | end 57 | end 58 | 59 | action :uninstall do 60 | execute "uninstall NPM package #{new_resource.package}" do 61 | cwd new_resource.path 62 | command "npm uninstall #{npm_options}" 63 | user new_resource.user 64 | group new_resource.group 65 | environment npm_env_vars 66 | live_stream new_resource.live_stream 67 | only_if { package_installed? } 68 | end 69 | end 70 | 71 | action_class do 72 | include NodeJs::Helper 73 | 74 | def npm_env_vars 75 | env_vars = {} 76 | env_vars['HOME'] = ::Dir.home(new_resource.user) if new_resource.user 77 | env_vars['USER'] = new_resource.user if new_resource.user 78 | env_vars['NPM_TOKEN'] = new_resource.npm_token if new_resource.npm_token 79 | env_vars['NODE_ENV'] = new_resource.node_env if new_resource.node_env 80 | 81 | env_vars 82 | end 83 | 84 | def package_installed? 85 | new_resource.package && npm_package_installed?(new_resource.package, new_resource.version, new_resource.path, npm_env_vars) 86 | end 87 | 88 | def no_auto_update? 89 | new_resource.package && !new_resource.auto_update 90 | end 91 | 92 | def npm_options 93 | options = '' 94 | options << ' -global' unless new_resource.path 95 | new_resource.options.each do |option| 96 | options << " #{option}" 97 | end 98 | options << " #{npm_package}" 99 | end 100 | 101 | def npm_package 102 | if new_resource.json 103 | new_resource.json.is_a?(String) ? new_resource.json : nil 104 | elsif new_resource.url 105 | new_resource.url 106 | elsif new_resource.package 107 | new_resource.version ? "#{new_resource.package}@#{new_resource.version}" : new_resource.package 108 | else 109 | Chef::Log.error("No good options found to install #{new_resource.package}") 110 | end 111 | end 112 | end 113 | -------------------------------------------------------------------------------- /.github/copilot-instructions.md: -------------------------------------------------------------------------------- 1 | # Copilot Instructions for Sous Chefs Cookbooks 2 | 3 | ## Repository Overview 4 | 5 | **Chef cookbook** for managing software installation and configuration. Part of the Sous Chefs cookbook ecosystem. 6 | 7 | **Key Facts:** Ruby-based, Chef >= 16 required, supports various OS platforms (check metadata.rb, kitchen.yml and .github/workflows/ci.yml for which platforms to specifically test) 8 | 9 | ## Project Structure 10 | 11 | **Critical Paths:** 12 | - `recipes/` - Chef recipes for cookbook functionality (if this is a recipe-driven cookbook) 13 | - `resources/` - Custom Chef resources with properties and actions (if this is a resource-driven cookbook) 14 | - `spec/` - ChefSpec unit tests 15 | - `test/integration/` - InSpec integration tests (tests all platforms supported) 16 | - `test/cookbooks/` or `test/fixtures/` - Example cookbooks used during testing that show good examples of custom resource usage 17 | - `attributes/` - Configuration for recipe driven cookbooks (not applicable to resource cookbooks) 18 | - `libraries/` - Library helpers to assist with the cookbook. May contain multiple files depending on complexity of the cookbook. 19 | - `templates/` - ERB templates that may be used in the cookbook 20 | - `files/` - files that may be used in the cookbook 21 | - `metadata.rb`, `Berksfile` - Cookbook metadata and dependencies 22 | 23 | ## Build and Test System 24 | 25 | ### Environment Setup 26 | **MANDATORY:** Install Chef Workstation first - provides chef, berks, cookstyle, kitchen tools. 27 | 28 | ### Essential Commands (strict order) 29 | ```bash 30 | berks install # Install dependencies (always first) 31 | cookstyle # Ruby/Chef linting 32 | yamllint . # YAML linting 33 | markdownlint-cli2 '**/*.md' # Markdown linting 34 | chef exec rspec # Unit tests (ChefSpec) 35 | # Integration tests will be done via the ci.yml action. Do not run these. Only check the action logs for issues after CI is done running. 36 | ``` 37 | 38 | ### Critical Testing Details 39 | - **Kitchen Matrix:** Multiple OS platforms × software versions (check kitchen.yml for specific combinations) 40 | - **Docker Required:** Integration tests use Dokken driver 41 | - **CI Environment:** Set `CHEF_LICENSE=accept-no-persist` 42 | - **Full CI Runtime:** 30+ minutes for complete matrix 43 | 44 | ### Common Issues and Solutions 45 | - **Always run `berks install` first** - most failures are dependency-related 46 | - **Docker must be running** for kitchen tests 47 | - **Chef Workstation required** - no workarounds, no alternatives 48 | - **Test data bags needed** (optional for some cookbooks) in `test/integration/data_bags/` for convergence 49 | 50 | ## Development Workflow 51 | 52 | ### Making Changes 53 | 1. Edit recipes/resources/attributes/templates/libraries 54 | 2. Update corresponding ChefSpec tests in `spec/` 55 | 3. Also update any InSpec tests under test/integration 56 | 4. Ensure cookstyle and rspec passes at least. You may run `cookstyle -a` to automatically fix issues if needed. 57 | 5. Also always update all documentation found in README.md and any files under documentation/* 58 | 6. **Always update CHANGELOG.md** (required by Dangerfile) - Make sure this conforms with the Sous Chefs changelog standards. 59 | 60 | ### Pull Request Requirements 61 | - **PR description >10 chars** (Danger enforced) 62 | - **CHANGELOG.md entry** for all code changes 63 | - **Version labels** (major/minor/patch) required 64 | - **All linters must pass** (cookstyle, yamllint, markdownlint) 65 | - **Test updates** needed for code changes >5 lines and parameter changes that affect the code logic 66 | 67 | ## Chef Cookbook Patterns 68 | 69 | ### Resource Development 70 | - Custom resources in `resources/` with properties and actions 71 | - Include comprehensive ChefSpec tests for all actions 72 | - Follow Chef resource DSL patterns 73 | 74 | ### Recipe Conventions 75 | - Use `include_recipe` for modularity 76 | - Handle platforms with `platform_family?` conditionals 77 | - Use encrypted data bags for secrets (passwords, SSL certs) 78 | - Leverage attributes for configuration with defaults 79 | 80 | ### Testing Approach 81 | - **ChefSpec (Unit):** Mock dependencies, test recipe logic in `spec/` 82 | - **InSpec (Integration):** Verify actual system state in `test/integration/inspec/` - InSpec files should contain proper inspec.yml and controls directories so that it could be used by other suites more easily. 83 | - One test file per recipe, use standard Chef testing patterns 84 | 85 | ## Trust These Instructions 86 | 87 | These instructions are validated for Sous Chefs cookbooks. **Do not search for build instructions** unless information here fails. 88 | 89 | **Error Resolution Checklist:** 90 | 1. Verify Chef Workstation installation 91 | 2. Confirm `berks install` completed successfully 92 | 3. Ensure Docker is running for integration tests 93 | 4. Check for missing test data dependencies 94 | 95 | The CI system uses these exact commands - following them matches CI behavior precisely. 96 | -------------------------------------------------------------------------------- /spec/unit/library/helper_spec.rb: -------------------------------------------------------------------------------- 1 | 2 | require 'rspec_helper' 3 | require 'mixlib/shellout' 4 | require 'ostruct' 5 | 6 | describe 'helper methods' do 7 | before(:each) do 8 | @mt = MT.new 9 | end 10 | 11 | describe 'npm_dist' do 12 | it 'should return a url if specified in the node attributes' do 13 | n = { 'nodejs': { 'npm': { 'url': 'get it' } } } 14 | n = Mash.new(n) 15 | allow(@mt).to receive(:node).and_return(n) 16 | expect(@mt.npm_dist['url']).to eq('get it') 17 | end 18 | it 'should return a url based on the version' do 19 | n = { 'nodejs': { 'npm': { 'url': nil, 'version': '6.14.8' } } } 20 | n = Mash.new(n) 21 | allow(@mt).to receive(:node).and_return(n) 22 | expect(@mt.npm_dist['url']).to eq('https://registry.npmjs.org/npm/-/npm-6.14.8.tgz') 23 | end 24 | end 25 | 26 | describe 'npm_list' do 27 | it 'should list information for a package' do 28 | allow_any_instance_of(Mixlib::ShellOut).to receive(:run_command).and_return(npmxss) 29 | expect(@mt.npm_list('xss')).to eq({ 'dependencies' => { 'xss' => { 'from' => 'xss', 'resolved' => 'https://registry.npmjs.org/xss/-/xss-1.0.8.tgz', 'version' => '1.0.8' } } }) 30 | end 31 | it 'should handle bad output fomr the npm list command' do 32 | allow_any_instance_of(Mixlib::ShellOut).to receive(:run_command).and_return(npminvalid) 33 | expect(@mt.npm_list('other')).to eq({}) 34 | end 35 | end 36 | 37 | describe 'url_valid?' do 38 | it 'should return true the url of an installed package for a valid value' do 39 | allow_any_instance_of(Mixlib::ShellOut).to receive(:run_command).and_return(npmxss) 40 | list = @mt.npm_list('xss')['dependencies'] 41 | expect(@mt.url_valid?(list, 'xss')).to be_truthy 42 | end 43 | it 'should return true an installed package that does not have a url' do 44 | allow_any_instance_of(Mixlib::ShellOut).to receive(:run_command).and_return(npmcssfilter) 45 | list = @mt.npm_list('cssfilter')['dependencies'] 46 | expect(@mt.url_valid?(list, 'cssfilter')).to eq(true) 47 | end 48 | it 'should return false for an installed package that has an invalid url' do 49 | allow_any_instance_of(Mixlib::ShellOut).to receive(:run_command).and_return(npmglobal) 50 | list = @mt.npm_list('security')['dependencies'] 51 | expect(@mt.url_valid?(list, 'security')).to eq(false) 52 | end 53 | end 54 | 55 | describe 'version_valid?' do 56 | it 'should check that the installed version of a package matches the expected' do 57 | allow_any_instance_of(Mixlib::ShellOut).to receive(:run_command).and_return(npmxss) 58 | list = @mt.npm_list('xss')['dependencies'] 59 | expect(@mt.version_valid?(list, 'xss', '1.0.8')).to be_truthy 60 | end 61 | it 'should return false if the version a package does not match the expected' do 62 | allow_any_instance_of(Mixlib::ShellOut).to receive(:run_command).and_return(npmxss) 63 | list = @mt.npm_list('xss')['dependencies'] 64 | expect(@mt.version_valid?(list, 'xss', '1.1.1')).to be_falsy 65 | end 66 | end 67 | 68 | describe 'npm_package_installed?' do 69 | it 'should return false if any of the checks fail - wrong version' do 70 | allow_any_instance_of(Mixlib::ShellOut).to receive(:run_command).and_return(npmxss) 71 | expect(@mt.npm_package_installed?('xss', '1.1.1')).to be_falsy 72 | end 73 | it 'should return false if any of the checks fail - nothing found' do 74 | allow_any_instance_of(Mixlib::ShellOut).to receive(:run_command).and_return(npmempty) 75 | expect(@mt.npm_package_installed?('xss')).to be_falsy 76 | end 77 | it 'should return true checking package and version' do 78 | allow_any_instance_of(Mixlib::ShellOut).to receive(:run_command).and_return(npmxss) 79 | expect(@mt.npm_package_installed?('xss', '1.0.8')).to be_truthy 80 | end 81 | it 'should return true checking package installed' do 82 | allow_any_instance_of(Mixlib::ShellOut).to receive(:run_command).and_return(npmxss) 83 | expect(@mt.npm_package_installed?('xss')).to be_truthy 84 | end 85 | end 86 | end 87 | 88 | class MT 89 | include NodeJs::Helper 90 | end 91 | 92 | def npmempty 93 | os = OpenStruct.new 94 | os.stdout = 95 | '{}' 96 | os 97 | end 98 | 99 | def npmglobal 100 | os = OpenStruct.new 101 | os.stdout = 102 | '{ 103 | "dependencies": { 104 | "dtrace": { 105 | "version": "0.0.0", 106 | "from": "dtrace", 107 | "resolved": "https://registry.npmjs.org/dtrace/-/dtrace-0.0.0.tgz" 108 | }, 109 | "dtrace-provider": { 110 | "version": "0.8.8", 111 | "from": "dtrace-provider", 112 | "resolved": "https://registry.npmjs.org/dtrace-provider/-/dtrace-provider-0.8.8.tgz", 113 | "dependencies": { 114 | "nan": { 115 | "version": "2.14.1", 116 | "from": "nan@^2.14.0", 117 | "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.1.tgz" 118 | } 119 | } 120 | }, 121 | "sax": { 122 | "version": "1.2.4", 123 | "from": "sax", 124 | "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz" 125 | }, 126 | "security": { 127 | "version": "1.0.0", 128 | "from": "security", 129 | "resolved": "http://invalid##registry.npmjs.org/security/-/security-1.0.0.tgz" 130 | }, 131 | "xss": { 132 | "version": "1.0.8", 133 | "from": "xss", 134 | "resolved": "https://registry.npmjs.org/xss/-/xss-1.0.8.tgz", 135 | "dependencies": { 136 | "commander": { 137 | "version": "2.20.3", 138 | "from": "commander@^2.20.3", 139 | "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz" 140 | }, 141 | "cssfilter": { 142 | "version": "0.0.10", 143 | "from": "cssfilter@0.0.10" 144 | } 145 | } 146 | } 147 | } 148 | }' 149 | os 150 | end 151 | 152 | def npminvalid 153 | os = OpenStruct.new 154 | os.stdout = 155 | 'Invalid return' 156 | os 157 | end 158 | 159 | def npmxss 160 | os = OpenStruct.new 161 | os.stdout = 162 | '{ 163 | "dependencies": { 164 | "xss": { 165 | "version": "1.0.8", 166 | "from": "xss", 167 | "resolved": "https://registry.npmjs.org/xss/-/xss-1.0.8.tgz" 168 | } 169 | } 170 | }' 171 | os 172 | end 173 | 174 | def npmcssfilter 175 | os = OpenStruct.new 176 | os.stdout = 177 | '{ 178 | "dependencies": { 179 | "xss": { 180 | "version": "1.0.8", 181 | "from": "xss", 182 | "resolved": "https://registry.npmjs.org/xss/-/xss-1.0.8.tgz", 183 | "dependencies": { 184 | "cssfilter": { 185 | "version": "0.0.10", 186 | "from": "cssfilter@0.0.10", 187 | "resolved": "https://registry.npmjs.org/cssfilter/-/cssfilter-0.0.10.tgz" 188 | } 189 | } 190 | } 191 | } 192 | }' 193 | os 194 | end 195 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [nodejs-cookbook](https://github.com/redguide/nodejs) 2 | 3 | [![Cookbook Version](https://img.shields.io/cookbook/v/nodejs.svg)](https://supermarket.chef.io/cookbooks/nodejs) 4 | [![CI State](https://github.com/sous-chefs/nodejs/workflows/ci/badge.svg)](https://github.com/sous-chefs/nodejs/actions?query=workflow%3Aci) 5 | [![OpenCollective](https://opencollective.com/sous-chefs/backers/badge.svg)](#backers) 6 | [![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors) 7 | [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) 8 | 9 | Installs node.js/npm and includes a resource for managing npm packages 10 | 11 | ## Maintainers 12 | 13 | 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). 14 | 15 | ## Requirements 16 | 17 | ### Platforms 18 | 19 | - Debian/Ubuntu 20 | - RHEL/CentOS/Scientific/Amazon/Oracle 21 | - openSUSE 22 | - Windows 23 | 24 | Note: Source installs require GCC 4.8+, which is not included on older distro releases 25 | 26 | ### Chef 27 | 28 | - Chef Infra Client 15.3+ 29 | 30 | ### Cookbooks 31 | 32 | - ark 33 | 34 | ## Usage 35 | 36 | Include the nodejs recipe to install node on your system based on the default installation method: 37 | 38 | ```ruby 39 | include_recipe "nodejs" 40 | ``` 41 | 42 | ### Install methods 43 | 44 | #### Package 45 | 46 | Install node from packages: 47 | 48 | ```ruby 49 | node['nodejs']['install_method'] = 'package' # Not necessary because it's the default 50 | include_recipe "nodejs" 51 | # Or 52 | include_recipe "nodejs::nodejs_from_package" 53 | ``` 54 | 55 | 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`. 56 | 57 | #### Binary 58 | 59 | Install node from official prebuilt binaries: 60 | 61 | ```ruby 62 | node['nodejs']['install_method'] = 'binary' 63 | include_recipe "nodejs" 64 | 65 | # Or 66 | include_recipe "nodejs::nodejs_from_binary" 67 | 68 | # Or set a specific version of nodejs to be installed 69 | node.default['nodejs']['install_method'] = 'binary' 70 | node.default['nodejs']['version'] = '5.9.0' 71 | node.default['nodejs']['binary']['checksum'] = '99c4136cf61761fac5ac57f80544140a3793b63e00a65d4a0e528c9db328bf40' 72 | 73 | # Or fetch the binary from your own location 74 | node.default['nodejs']['install_method'] = 'binary' 75 | node.default['nodejs']['binary']['url'] = 'https://s3.amazonaws.com/my-bucket/node-v7.8.0-linux-x64.tar.gz' 76 | node.default['nodejs']['binary']['checksum'] = '0bd86f2a39221b532172c7d1acb57f0b0cba88c7b82ea74ba9d1208b9f6f9697' 77 | ``` 78 | 79 | #### Source 80 | 81 | Install node from sources: 82 | 83 | ```ruby 84 | node['nodejs']['install_method'] = 'source' 85 | include_recipe "nodejs" 86 | # Or 87 | include_recipe "nodejs::nodejs_from_source" 88 | ``` 89 | 90 | #### Chocolatey 91 | 92 | Install node from chocolatey: 93 | 94 | ```chef 95 | node['nodejs']['install_method'] = 'chocolatey' 96 | include_recipe "nodejs" 97 | # Or 98 | include_recipe "nodejs::nodejs_from_chocolatey" 99 | ``` 100 | 101 | ## NPM 102 | 103 | 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']` 104 | 105 | ```ruby 106 | include_recipe "nodejs::npm" 107 | ``` 108 | 109 | _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']`. 110 | 111 | ## Resources 112 | 113 | ### npm_package 114 | 115 | 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. 116 | 117 | `npm_package` lets you install npm packages from various sources: 118 | 119 | - npm registry: 120 | 121 | - name: `property :package` 122 | - version: `property :version` (optional) 123 | 124 | - url: `property :url` 125 | 126 | - for git use `git://{your_repo}` 127 | 128 | - from a json (package.json by default): `property :json` 129 | 130 | - use `true` for default 131 | - use a `String` to specify json file 132 | 133 | Packages can be installed globally (by default) or in a directory (by using `attribute :path`) 134 | 135 | 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` 136 | 137 | 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`. 138 | 139 | You can append more specific options to npm command with `attribute :options` array : 140 | 141 | 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. 142 | 143 | - use an array of options (w/ dash), they will be added to npm call. 144 | - ex: `['--production','--force']` or `['--force-latest']` 145 | 146 | 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. 147 | 148 | This LWRP attempts to use vanilla npm as much as possible (no custom wrapper). 149 | 150 | ### Packages 151 | 152 | ```ruby 153 | npm_package 'express' 154 | 155 | npm_package 'async' do 156 | version '0.6.2' 157 | end 158 | 159 | npm_package 'request' do 160 | url 'github mikeal/request' 161 | end 162 | 163 | npm_package 'grunt' do 164 | path '/home/random/grunt' 165 | json true 166 | user 'random' 167 | node_env 'staging' 168 | end 169 | 170 | npm_package 'my_private_module' do 171 | path '/home/random/myproject' # The root path to your project, containing a package.json file 172 | json true 173 | npm_token '12345-abcde-e5d4c3b2a1' 174 | user 'random' 175 | options ['--production'] # Only install dependencies. Skip devDependencies 176 | end 177 | ``` 178 | 179 | [Working Examples](test/cookbooks/nodejs_test/recipes/npm.rb) 180 | 181 | Or add packages via attributes (which accept the same attributes as the LWRP above): 182 | 183 | ```json 184 | "nodejs": { 185 | "npm_packages": [ 186 | { 187 | "name": "express" 188 | }, 189 | { 190 | "name": "async", 191 | "version": "0.6.2" 192 | }, 193 | { 194 | "name": "request", 195 | "url": "github mikeal/request" 196 | } 197 | { 198 | "name": "grunt", 199 | "path": "/home/random/grunt", 200 | "json": true, 201 | "user": "random" 202 | } 203 | ] 204 | } 205 | ``` 206 | 207 | ## Contributors 208 | 209 | This project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890&button=false) 210 | 211 | ### Backers 212 | 213 | Thank you to all our backers! 214 | 215 | ![https://opencollective.com/sous-chefs#backers](https://opencollective.com/sous-chefs/backers.svg?width=600&avatarHeight=40) 216 | 217 | ### Sponsors 218 | 219 | Support this project by becoming a sponsor. Your logo will show up here with a link to your website. 220 | 221 | ![https://opencollective.com/sous-chefs/sponsor/0/website](https://opencollective.com/sous-chefs/sponsor/0/avatar.svg?avatarHeight=100) 222 | ![https://opencollective.com/sous-chefs/sponsor/1/website](https://opencollective.com/sous-chefs/sponsor/1/avatar.svg?avatarHeight=100) 223 | ![https://opencollective.com/sous-chefs/sponsor/2/website](https://opencollective.com/sous-chefs/sponsor/2/avatar.svg?avatarHeight=100) 224 | ![https://opencollective.com/sous-chefs/sponsor/3/website](https://opencollective.com/sous-chefs/sponsor/3/avatar.svg?avatarHeight=100) 225 | ![https://opencollective.com/sous-chefs/sponsor/4/website](https://opencollective.com/sous-chefs/sponsor/4/avatar.svg?avatarHeight=100) 226 | ![https://opencollective.com/sous-chefs/sponsor/5/website](https://opencollective.com/sous-chefs/sponsor/5/avatar.svg?avatarHeight=100) 227 | ![https://opencollective.com/sous-chefs/sponsor/6/website](https://opencollective.com/sous-chefs/sponsor/6/avatar.svg?avatarHeight=100) 228 | ![https://opencollective.com/sous-chefs/sponsor/7/website](https://opencollective.com/sous-chefs/sponsor/7/avatar.svg?avatarHeight=100) 229 | ![https://opencollective.com/sous-chefs/sponsor/8/website](https://opencollective.com/sous-chefs/sponsor/8/avatar.svg?avatarHeight=100) 230 | ![https://opencollective.com/sous-chefs/sponsor/9/website](https://opencollective.com/sous-chefs/sponsor/9/avatar.svg?avatarHeight=100) 231 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # NodeJS Cookbook Changelog 2 | 3 | Standardise files with files in sous-chefs/repo-management 4 | Standardise files with files in sous-chefs/repo-management 5 | Standardise files with files in sous-chefs/repo-management 6 | 7 | ## [10.2.3](https://github.com/sous-chefs/nodejs/compare/10.2.2...v10.2.3) (2025-10-15) 8 | 9 | 10 | ### Bug Fixes 11 | 12 | * **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)) 13 | 14 | ## 10.2.1 - *2025-06-08* 15 | 16 | Standardise files with files in sous-chefs/repo-management 17 | 18 | ## 10.2.0 - *2024-11-20* 19 | 20 | * Add support for new NodeSource repository (Thanks to @stissot) 21 | * Rework source install packages 22 | * Update SUSE packages 23 | 24 | ## 10.1.22 - *2024-11-19* 25 | 26 | * Update default version to current LTS 27 | 28 | ## 10.1.21 - *2024-11-19* 29 | 30 | * Update CI platforms 31 | 32 | ## 10.1.20 - *2024-11-18* 33 | 34 | * Update test matrix check success of the integration stage 35 | 36 | ## 10.1.19 - *2024-11-18* 37 | 38 | Standardise files with files in sous-chefs/repo-management 39 | 40 | Standardise files with files in sous-chefs/repo-management 41 | 42 | Standardise files with files in sous-chefs/repo-management 43 | 44 | Standardise files with files in sous-chefs/repo-management 45 | 46 | Standardise files with files in sous-chefs/repo-management 47 | 48 | ## 10.1.16 - *2024-05-03* 49 | 50 | Standardise files with files in sous-chefs/repo-management 51 | 52 | ## 10.1.10 - *2023-04-07* 53 | 54 | Standardise files with files in sous-chefs/repo-management 55 | 56 | ## 10.1.7 - *2023-04-01* 57 | 58 | Standardise files with files in sous-chefs/repo-management 59 | 60 | ## 10.1.6 - *2023-03-20* 61 | 62 | Standardise files with files in sous-chefs/repo-management 63 | 64 | ## 10.1.5 - *2023-03-15* 65 | 66 | Standardise files with files in sous-chefs/repo-management 67 | 68 | ## 10.1.4 - *2023-02-20* 69 | 70 | Standardise files with files in sous-chefs/repo-management 71 | 72 | ## 10.1.2 - *2023-02-14* 73 | 74 | Standardise files with files in sous-chefs/repo-management 75 | 76 | ## 10.1.1 - *2022-12-08* 77 | 78 | Standardise files with files in sous-chefs/repo-management 79 | 80 | ## 10.1.0 - *2022-08-08* 81 | 82 | * To ensure consistent environment between `npm install` and `npm list`, pass same environment variables. 83 | 84 | ## 10.0.1 - *2022-08-07* 85 | 86 | * Standardise files with files in sous-chefs/repo-management 87 | * Default to using EL 9 repo for Fedora 88 | * CI: Remove Fedora from source suite 89 | 90 | ## 10.0.0 - *2022-04-21* 91 | 92 | * Update to NodeJS 17.x 93 | * Remove delivery and move to calling RSpec directly via a reusable workflow 94 | * Update tested platforms 95 | * Disable upstream DNF module on EL8 based systems 96 | 97 | ## 9.0.2 - *2022-02-17* 98 | 99 | * Standardise files with files in sous-chefs/repo-management 100 | 101 | ## 9.0.1 - *2022-02-08* 102 | 103 | * Remove delivery folder 104 | 105 | ## 9.0.0 - *2021-09-13* 106 | 107 | * Update the default version to 14 LTS 108 | * Remove testing for EOL platforms 109 | * Add Debian 11 testing 110 | * Fix release version to use for Amazon Linux 111 | 112 | ## 8.0.0 - *2021-09-02* 113 | 114 | * Update metadata and README to Sous Chef 115 | * Enable unified_mode by default and require at least Chef Infra Client 15.3 116 | * Cookstyle fixes 117 | 118 | ## 7.3.3 - *2021-08-30* 119 | 120 | * Standardise files with files in sous-chefs/repo-management 121 | 122 | ## 7.3.2 - *2021-06-01* 123 | 124 | * Standardise files with files in sous-chefs/repo-management 125 | 126 | ## 7.3.1 - *2020-12-31* 127 | 128 | * resolved cookstyle error: attributes/packages.rb:15:55 convention: `Layout/TrailingEmptyLines` 129 | * resolved cookstyle error: test/cookbooks/test/recipes/resource.rb:118:1 convention: `Layout/TrailingEmptyLines` 130 | * Enable builds for opensuse-leap-15 131 | * Add a library method test 132 | 133 | ## 7.3.0 (2020-10-21) 134 | 135 | * Add rspec tests for the library methods 136 | * Update the url_invalid? method to return false if it detects an invalid uri 137 | * Add the auto_update option to the npm_package resource. Allows turning off auto_update of npm packages. 138 | * Allow actions and options for OS package installation to be specified as attributes 139 | * Add the live_stream parameter to the npm_package execution to get better installation diagnostics 140 | * Add the auto_update option to the npm_package resource. Allows turning off auto_update of npm packages. 141 | * Update testing 142 | 143 | ## 7.2.0 (2020-10-07) 144 | 145 | * Verify the URI of installed packages to help determine if a good URI has been installed 146 | * Add tests that verify npm-package installed packages 147 | * Get the example test cookbook working 148 | * Add support for installing node on windows 149 | 150 | ## 7.1.0 (2020-10-01) 151 | 152 | * resolved cookstyle error: recipes/nodejs_from_binary.rb:19:1 refactor: `ChefCorrectness/IncorrectLibraryInjection` 153 | * resolved cookstyle error: recipes/nodejs_from_source.rb:21:1 refactor: `ChefCorrectness/IncorrectLibraryInjection` 154 | * resolved cookstyle error: recipes/npm_from_source.rb:21:1 refactor: `ChefCorrectness/IncorrectLibraryInjection` 155 | * Have ark setup node and npm binaries into PATH 156 | * Add `node_env` to `npm_package` in order to set `NODE_ENV` (useful for some packages) 157 | * 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) 158 | 159 | ## 7.0.1 (2020-06-04) 160 | 161 | * Minor readme fix 162 | 163 | ## 7.0.0 (2020-06-04) 164 | 165 | * Require Chef Infra Client 14+ and remove the build-essential dependency 166 | * Updated the default to Node.js v10.16.3 167 | * Added compatibility with Chef Infra Client 16.2+ 168 | * Removed Foodcritic testing 169 | * Updated ChefSpec and Kitchen platforms 170 | * Resolved multiple minor cookstyle issues in the cookbook 171 | * Added a vscode editor config 172 | 173 | ## 6.0.0 (2018-10-11) 174 | 175 | * 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+ 176 | * Set default version to Node.js v8.12.0 177 | 178 | ## 5.0.0 (2017-11-15) 179 | 180 | * 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. 181 | * compat_resource cookbook dependency has been removed and this cookbook instead requires Chef 12.14 or later 182 | * Chef 13 compatibility has been resolved 183 | * The npm_package resource now properly installs packages when the 'package' property is setA 184 | * Speed up npm operations by only returning a list of the desired package instead of every npm package 185 | * Speed up source installation by using multipackage install for the dependencies 186 | * Remove the broken url_valid? helper which didn't work 187 | 188 | ## 4.0.0 (2017-07-11) 189 | 190 | * Updated the cookbook to require Chef 12.1+ and the compat_resource cookbook 191 | * Removed support for io.js which has merged back into the node.js project 192 | * Removed the dependency on homebrew, yum-epel, and apt cookbooks 193 | * Added node['nodejs']['manage_node'] attribute to use only cookbook's LWRP (required to manage node by nvm) 194 | * Updated the default repository URLs to be the 6.X repos 195 | * Added initial support for Suse and Amazon Linux 196 | * Improved architecture detection to support aarch64 197 | * Improved readme with examples for fetching your own binaries 198 | * Added installation of openssl and xz utilities that are needed for the binary install recipe 199 | * Updated the cookbook license string to be an SPDX compliant string 200 | * Set the minimum version of the ark cookbook to 2.0.2 in order to support Suse 201 | * Updated the default version from 6.9.1 to 6.10.2 202 | * Switched to Delivery local mode for testing 203 | * Added Integration testing in Travis CI with kitchen-dokken and ChefDK 204 | 205 | ## 3.0.0 (2016-11-02) 206 | 207 | * 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. 208 | * Switched the download URLs to the .xz packages since the .tar.gz packages are no longer being created 209 | * Improvements to the readme examples and requirements sections 210 | * Removed installation of apt-transport-https and instead rely on an apt cookbook that will do the same 211 | * Fixed the ChefSpec matchers 212 | * Added Scientific, Oracle, and Amazon as supported distros in the metadata 213 | * Added chef_version metadata 214 | * Removed conflicts and suggests metadata which aren't implemented or recommended for use 215 | * Removed Chef 10 compatibility code 216 | * Switched Integration testing to Inspec from bats 217 | * Added the Apache 2.0 license file to the repo 218 | * Expanded Test Kitchen testing 219 | * Switched from Rubocop to Cookstyle and resolved all warnings 220 | * Switched Travis to testing using ChefDK 221 | 222 | ## 2.4.4 223 | 224 | * Use HTTPS prefix URLs for node download #98 225 | * Update NPM symlink when installing from source #105 226 | * Add support for NPM private modules #107 227 | 228 | ## v2.4.2 229 | 230 | * Fix check version 231 | * Support iojs package install 232 | 233 | ## v2.4.0 234 | 235 | * Move `npm_packages` to his own recipe 236 | * Fix different race conditions when using direct recipe call 237 | * Fix npm recipe 238 | 239 | ## v2.3.2 240 | 241 | * Fix package recipe 242 | 243 | ## v2.3.0 244 | 245 | * Support io.js. Use node['nodejs']['engine']. 246 | * Add MacOS support via homebrew 247 | 248 | ## v2.2.0 249 | 250 | * Add node['nodejs']['keyserver'] 251 | * Update arm checksum 252 | * Fix `npm_packages` JSON 253 | 254 | ## v2.1.0 255 | 256 | * Use official nodesource repository 257 | * Add node['nodejs']['npm_packages'] to install npm package with `default` recipe 258 | 259 | ## v2.0.0 260 | 261 | * Travis integration 262 | * Gems updated 263 | * Rewrite cookbook dependencies 264 | * Added complete test-kitchen integration : Rake, rubocop, foodcritic, vagrant, bats testing ... 265 | * Added NodeJS `install_method` option (sources, bins or packages) 266 | * Added NPM `install_method` option (sources or packages) 267 | * NPM version can now be chosen independently from nodejs' embedded version 268 | * Added a `nodejs_npm` LWRP to manage, install and resolve NPM packages 269 | 270 | ## v1.3.0 271 | 272 | * update default versions to the latest: node - v0.10.15 and npm - v1.3.5 273 | * default to package installation of nodejs on smartos ([@wanelo-pair]) 274 | * Add Raspberry pi support ([@robertkowalski]) 275 | 276 | ## v1.2.0 277 | 278 | * implement installation from package on RedHat - ([@vaskas]) 279 | 280 | ## v1.1.3 281 | 282 | * update default version of node to 0.10.13 - and npm - v1.3.4 ([@jodosha][]) 283 | 284 | ## v1.1.2 285 | 286 | * update default version of node to 0.10.2 - ([@bakins]) 287 | * fully migrated to test-kitchen 1.alpha and vagrant 1.1.x/berkshelf 1.3.1 288 | 289 | ## v1.1.1 290 | 291 | * update default versions to the latest: node - v0.10.0 and npm - v1.2.14 292 | * `make_thread` is now a real attribute - ([@ChrisLundquist]) 293 | 294 | ## v1.1.0 295 | 296 | * rewrite the package install; remove rpm support since there are no longer any packages available anywhere 297 | * add support to install `legacy_packages` from ubuntu repo as well as the latest 0.10.x branch (this is default). 298 | 299 | ## v1.0.4 300 | 301 | * add support for binary installation method ([@JulesAU]) 302 | 303 | ## v1.0.3 304 | 305 | * 7.3.1 - *2020-12-31* 306 | 307 | ## v1.0.2 308 | 309 | * add smartos support for package install ([@sax]) 310 | * support to compile with all processors available (default 2 if unknown) - ([@ChrisLundquist]) 311 | * moved to `platform_family` syntax 312 | * ensure npm recipe honours the 'source' or 'package' setting - ([@markbirbeck]) 313 | * updated the default versions to the latest stable node/npm 314 | 315 | ## v1.0.1 316 | 317 | * fixed bug that prevented overwritting the node/npm versions (moved the `src_url`s as local variables instead of attributes) - ([@johannesbecker]) 318 | * updated the default versions to the latest node/npm 319 | 320 | ## v1.0.0 321 | 322 | * added packages installation support ([@smith]) 323 | 324 | [@bakins]: https://github.com/bakins 325 | [@chrislundquist]: https://github.com/ChrisLundquist 326 | [@johannesbecker]: https://github.com/johannesbecker 327 | [@julesau]: https://github.com/JulesAU 328 | [@markbirbeck]: https://github.com/markbirbeck 329 | [@robertkowalski]: https://github.com/robertkowalski 330 | [@sax]: https://github.com/sax 331 | [@smith]: https://github.com/smith 332 | [@vaskas]: https://github.com/vaskas 333 | [@wanelo-pair]: https://github.com/wanelo-pair 334 | --------------------------------------------------------------------------------