├── .eslintignore ├── test ├── .eslintrc.yml ├── methods.js └── browserify.js ├── .eslintrc.yml ├── .gitignore ├── .github ├── dependabot.yml └── workflows │ ├── codeql.yml │ ├── scorecard.yml │ └── ci.yml ├── HISTORY.md ├── LICENSE ├── package.json ├── index.js └── README.md /.eslintignore: -------------------------------------------------------------------------------- 1 | coverage 2 | node_modules 3 | -------------------------------------------------------------------------------- /test/.eslintrc.yml: -------------------------------------------------------------------------------- 1 | env: 2 | mocha: true 3 | -------------------------------------------------------------------------------- /.eslintrc.yml: -------------------------------------------------------------------------------- 1 | root: true 2 | extends: standard 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store* 3 | *.log 4 | *.gz 5 | 6 | node_modules 7 | coverage 8 | cache 9 | 10 | package-lock.json 11 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: github-actions 4 | directory: / 5 | schedule: 6 | interval: monthly 7 | 8 | - package-ecosystem: npm 9 | directory: / 10 | schedule: 11 | interval: monthly 12 | time: "23:00" 13 | timezone: Europe/London 14 | open-pull-requests-limit: 10 15 | ignore: 16 | - dependency-name: "*" 17 | update-types: ["version-update:semver-major"] 18 | -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | 1.1.2 / 2016-01-17 2 | ================== 3 | 4 | * perf: enable strict mode 5 | 6 | 1.1.1 / 2014-12-30 7 | ================== 8 | 9 | * Improve `browserify` support 10 | 11 | 1.1.0 / 2014-07-05 12 | ================== 13 | 14 | * Add `CONNECT` method 15 | 16 | 1.0.1 / 2014-06-02 17 | ================== 18 | 19 | * Fix module to work with harmony transform 20 | 21 | 1.0.0 / 2014-05-08 22 | ================== 23 | 24 | * Add `PURGE` method 25 | 26 | 0.1.0 / 2013-10-28 27 | ================== 28 | 29 | * Add `http.METHODS` support 30 | -------------------------------------------------------------------------------- /test/methods.js: -------------------------------------------------------------------------------- 1 | var http = require('http') 2 | var assert = require('assert') 3 | var methods = require('..') 4 | 5 | describe('methods', function () { 6 | if (http.METHODS) { 7 | it('is a lowercased http.METHODS', function () { 8 | var lowercased = http.METHODS.map(function (method) { 9 | return method.toLowerCase() 10 | }) 11 | assert.deepEqual(lowercased, methods) 12 | }) 13 | } else { 14 | it('contains GET, POST, PUT, and DELETE', function () { 15 | assert.notEqual(methods.indexOf('get'), -1) 16 | assert.notEqual(methods.indexOf('post'), -1) 17 | assert.notEqual(methods.indexOf('put'), -1) 18 | assert.notEqual(methods.indexOf('delete'), -1) 19 | }) 20 | 21 | it('is all lowercase', function () { 22 | for (var i = 0; i < methods.length; i++) { 23 | assert(methods[i], methods[i].toLowerCase(), methods[i] + " isn't all lowercase") 24 | } 25 | }) 26 | } 27 | }) 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) 2013-2014 TJ Holowaychuk 4 | Copyright (c) 2015-2016 Douglas Christopher Wilson 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining 7 | a copy of this software and associated documentation files (the 8 | 'Software'), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "methods", 3 | "description": "HTTP methods that node supports", 4 | "version": "1.1.2", 5 | "contributors": [ 6 | "Douglas Christopher Wilson ", 7 | "Jonathan Ong (http://jongleberry.com)", 8 | "TJ Holowaychuk (http://tjholowaychuk.com)" 9 | ], 10 | "license": "MIT", 11 | "repository": "jshttp/methods", 12 | "devDependencies": { 13 | "eslint": "4.19.1", 14 | "eslint-config-standard": "11.0.0", 15 | "eslint-plugin-import": "2.13.0", 16 | "eslint-plugin-node": "6.0.1", 17 | "eslint-plugin-promise": "3.8.0", 18 | "eslint-plugin-standard": "3.1.0", 19 | "mocha": "10.2.0", 20 | "nyc": "15.1.0" 21 | }, 22 | "files": [ 23 | "index.js", 24 | "HISTORY.md", 25 | "LICENSE" 26 | ], 27 | "engines": { 28 | "node": ">= 0.6" 29 | }, 30 | "scripts": { 31 | "lint": "eslint .", 32 | "test": "mocha --reporter spec --bail --check-leaks test/", 33 | "test-ci": "nyc --reporter=lcov --reporter=text npm test", 34 | "test-cov": "nyc --reporter=html --reporter=text npm test" 35 | }, 36 | "browser": { 37 | "http": false 38 | }, 39 | "keywords": [ 40 | "http", 41 | "methods" 42 | ] 43 | } 44 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * methods 3 | * Copyright(c) 2013-2014 TJ Holowaychuk 4 | * Copyright(c) 2015-2016 Douglas Christopher Wilson 5 | * MIT Licensed 6 | */ 7 | 8 | 'use strict' 9 | 10 | /** 11 | * Module dependencies. 12 | * @private 13 | */ 14 | 15 | var http = require('http') 16 | 17 | /** 18 | * Module exports. 19 | * @public 20 | */ 21 | 22 | module.exports = getCurrentNodeMethods() || getBasicNodeMethods() 23 | 24 | /** 25 | * Get the current Node.js methods. 26 | * @private 27 | */ 28 | 29 | function getCurrentNodeMethods () { 30 | return http.METHODS && http.METHODS.map(function lowerCaseMethod (method) { 31 | return method.toLowerCase() 32 | }) 33 | } 34 | 35 | /** 36 | * Get the "basic" Node.js methods, a snapshot from Node.js 0.10. 37 | * @private 38 | */ 39 | 40 | function getBasicNodeMethods () { 41 | return [ 42 | 'get', 43 | 'post', 44 | 'put', 45 | 'head', 46 | 'delete', 47 | 'options', 48 | 'trace', 49 | 'copy', 50 | 'lock', 51 | 'mkcol', 52 | 'move', 53 | 'purge', 54 | 'propfind', 55 | 'proppatch', 56 | 'unlock', 57 | 'report', 58 | 'mkactivity', 59 | 'checkout', 60 | 'merge', 61 | 'm-search', 62 | 'notify', 63 | 'subscribe', 64 | 'unsubscribe', 65 | 'patch', 66 | 'search', 67 | 'connect' 68 | ] 69 | } 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Methods 2 | 3 | [![NPM Version][npm-version-image]][npm-url] 4 | [![NPM Downloads][npm-downloads-image]][npm-url] 5 | [![Node.js Version][node-image]][node-url] 6 | [![Build Status][ci-image]][ci-url] 7 | [![Coverage Status][coveralls-image]][coveralls-url] 8 | 9 | HTTP verbs that Node.js core's HTTP parser supports. 10 | 11 | This module provides an export that is just like `http.METHODS` from Node.js core, 12 | with the following differences: 13 | 14 | * All method names are lower-cased. 15 | * Contains a fallback list of methods for Node.js versions that do not have a 16 | `http.METHODS` export (0.10 and lower). 17 | * Provides the fallback list when using tools like `browserify` without pulling 18 | in the `http` shim module. 19 | 20 | ## Install 21 | 22 | This is a [Node.js](https://nodejs.org/en/) module available through the 23 | [npm registry](https://www.npmjs.com/). Installation is done using the 24 | [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally): 25 | 26 | ```sh 27 | $ npm install methods 28 | ``` 29 | 30 | ## API 31 | 32 | ```js 33 | var methods = require('methods') 34 | ``` 35 | 36 | ### methods 37 | 38 | This is an array of lower-cased method names that Node.js supports. If Node.js 39 | provides the `http.METHODS` export, then this is the same array lower-cased, 40 | otherwise it is a snapshot of the verbs from Node.js 0.10. 41 | 42 | ## License 43 | 44 | [MIT](LICENSE) 45 | 46 | [ci-image]: https://badgen.net/github/checks/jshttp/methods/master?label=ci 47 | [ci-url]: https://github.com/jshttp/methods/actions/workflows/ci.yml 48 | [coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/methods/master 49 | [coveralls-url]: https://coveralls.io/r/jshttp/methods?branch=master 50 | [node-image]: https://badgen.net/npm/node/methods 51 | [node-url]: https://nodejs.org/en/download 52 | [npm-downloads-image]: https://badgen.net/npm/dm/methods 53 | [npm-url]: https://npmjs.org/package/methods 54 | [npm-version-image]: https://badgen.net/npm/v/methods 55 | -------------------------------------------------------------------------------- /test/browserify.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert') 2 | var browserify = tryRequire('browserify') 3 | var istanbul = tryRequire('istanbul') 4 | var methods = null 5 | var path = require('path') 6 | var run = browserify ? describe : describe.skip 7 | var stream = require('stream') 8 | var vm = require('vm') 9 | 10 | run('when browserified', function () { 11 | before(function (done) { 12 | var b = browserify() 13 | var c = {} 14 | 15 | // instrument 16 | if (istanbul && getCoverageGlobal()) { 17 | b.transform(istanbulify(c)) 18 | } 19 | 20 | // require methods 21 | b.require(path.join(__dirname, '..'), { 22 | expose: 'methods' 23 | }) 24 | 25 | // bundle and eval 26 | b.bundle(function (err, buf) { 27 | if (err) return done(err) 28 | var require = vm.runInNewContext(buf.toString(), c) 29 | methods = require('methods') 30 | done() 31 | }) 32 | }) 33 | 34 | describe('methods', function () { 35 | ['get', 'post', 'put', 'patch', 'delete'].forEach(function (method) { 36 | it('should contain "' + method + '"', function () { 37 | assert.notEqual(methods.indexOf(method), -1) 38 | }) 39 | }) 40 | 41 | it('should only have lower-case entries', function () { 42 | for (var i = 0; i < methods.length; i++) { 43 | assert(methods[i], methods[i].toLowerCase(), methods[i] + ' is lower-case') 44 | } 45 | }) 46 | }) 47 | }) 48 | 49 | function getCoverageGlobal () { 50 | for (var key in global) { 51 | if (key.substr(0, 6) === '$$cov_') { 52 | return global[key] 53 | } 54 | } 55 | } 56 | 57 | function istanbulify (context) { 58 | // link coverage 59 | context.__coverage__ = getCoverageGlobal() 60 | 61 | // browserify transform 62 | return function (file) { 63 | var chunks = [] 64 | var instrumenter = new istanbul.Instrumenter() 65 | var transformer = new stream.Transform() 66 | 67 | // buffer chunks 68 | transformer._transform = function _transform (data, encoding, callback) { 69 | chunks.push(data) 70 | callback() 71 | } 72 | 73 | // transform on flush 74 | transformer._flush = function _flush (callback) { 75 | var contents = Buffer.concat(chunks).toString() 76 | instrumenter.instrument(contents, file, function (err, output) { 77 | if (err) return transformer.emit('error', err) 78 | transformer.push(output) 79 | transformer.push(null) 80 | callback() 81 | }) 82 | } 83 | 84 | return transformer 85 | } 86 | } 87 | 88 | function tryRequire (name) { 89 | try { 90 | return require(name) 91 | } catch (e) { 92 | return undefined 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: ["master"] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: ["master"] 20 | schedule: 21 | - cron: "0 0 * * 1" 22 | 23 | permissions: 24 | contents: read 25 | 26 | jobs: 27 | analyze: 28 | name: Analyze 29 | runs-on: ubuntu-latest 30 | permissions: 31 | actions: read 32 | contents: read 33 | security-events: write 34 | 35 | strategy: 36 | fail-fast: false 37 | matrix: 38 | language: ["javascript"] 39 | # CodeQL supports [ $supported-codeql-languages ] 40 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 41 | 42 | steps: 43 | - name: Checkout repository 44 | uses: actions/checkout@v4 45 | 46 | # Initializes the CodeQL tools for scanning. 47 | - name: Initialize CodeQL 48 | uses: github/codeql-action/init@v3 49 | with: 50 | languages: ${{ matrix.language }} 51 | # If you wish to specify custom queries, you can do so here or in a config file. 52 | # By default, queries listed here will override any specified in a config file. 53 | # Prefix the list here with "+" to use these queries and those in the config file. 54 | 55 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 56 | # If this step fails, then you should remove it and run the build manually (see below) 57 | - name: Autobuild 58 | uses: github/codeql-action/autobuild@v3 59 | 60 | # ℹ️ Command-line programs to run using the OS shell. 61 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun 62 | 63 | # If the Autobuild fails above, remove it and uncomment the following three lines. 64 | # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. 65 | 66 | # - run: | 67 | # echo "Run, Build Application using script" 68 | # ./location_of_script_within_repo/buildscript.sh 69 | 70 | - name: Perform CodeQL Analysis 71 | uses: github/codeql-action/analyze@v3 72 | with: 73 | category: "/language:${{matrix.language}}" 74 | -------------------------------------------------------------------------------- /.github/workflows/scorecard.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. They are provided 2 | # by a third-party and are governed by separate terms of service, privacy 3 | # policy, and support documentation. 4 | 5 | name: Scorecard supply-chain security 6 | on: 7 | # For Branch-Protection check. Only the default branch is supported. See 8 | # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection 9 | branch_protection_rule: 10 | # To guarantee Maintained check is occasionally updated. See 11 | # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained 12 | schedule: 13 | - cron: '16 21 * * 1' 14 | push: 15 | branches: [ "master" ] 16 | 17 | # Declare default permissions as read only. 18 | permissions: read-all 19 | 20 | jobs: 21 | analysis: 22 | name: Scorecard analysis 23 | runs-on: ubuntu-latest 24 | permissions: 25 | # Needed to upload the results to code-scanning dashboard. 26 | security-events: write 27 | # Needed to publish results and get a badge (see publish_results below). 28 | id-token: write 29 | # Uncomment the permissions below if installing in a private repository. 30 | # contents: read 31 | # actions: read 32 | 33 | steps: 34 | - name: "Checkout code" 35 | uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 36 | with: 37 | persist-credentials: false 38 | 39 | - name: "Run analysis" 40 | uses: ossf/scorecard-action@99c53751e09b9529366343771cc321ec74e9bd3d # v2.0.6 41 | with: 42 | results_file: results.sarif 43 | results_format: sarif 44 | # (Optional) "write" PAT token. Uncomment the `repo_token` line below if: 45 | # - you want to enable the Branch-Protection check on a *public* repository, or 46 | # - you are installing Scorecard on a *private* repository 47 | # To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat. 48 | # repo_token: ${{ secrets.SCORECARD_TOKEN }} 49 | 50 | # Public repositories: 51 | # - Publish results to OpenSSF REST API for easy access by consumers 52 | # - Allows the repository to include the Scorecard badge. 53 | # - See https://github.com/ossf/scorecard-action#publishing-results. 54 | # For private repositories: 55 | # - `publish_results` will always be set to `false`, regardless 56 | # of the value entered here. 57 | publish_results: true 58 | 59 | # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF 60 | # format to the repository Actions tab. 61 | - name: "Upload artifact" 62 | uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 63 | with: 64 | name: SARIF file 65 | path: results.sarif 66 | retention-days: 5 67 | 68 | # Upload the results to GitHub's code scanning dashboard. 69 | - name: "Upload to code-scanning" 70 | uses: github/codeql-action/upload-sarif@2f93e4319b2f04a2efc38fa7f78bd681bc3f7b2f # v2.23.2 71 | with: 72 | sarif_file: results.sarif -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: 4 | - pull_request 5 | - push 6 | 7 | permissions: 8 | contents: read 9 | 10 | jobs: 11 | test: 12 | permissions: 13 | checks: write # for coverallsapp/github-action to create new checks 14 | contents: read # for actions/checkout to fetch code 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | name: 19 | - Node.js 0.6 20 | - Node.js 0.8 21 | - Node.js 0.10 22 | - Node.js 0.12 23 | - io.js 1.x 24 | - io.js 2.x 25 | - io.js 3.x 26 | - Node.js 4.x 27 | - Node.js 5.x 28 | - Node.js 6.x 29 | - Node.js 7.x 30 | - Node.js 8.x 31 | - Node.js 9.x 32 | - Node.js 10.x 33 | - Node.js 11.x 34 | - Node.js 12.x 35 | - Node.js 13.x 36 | - Node.js 14.x 37 | - Node.js 15.x 38 | - Node.js 16.x 39 | - Node.js 17.x 40 | - Node.js 18.x 41 | - Node.js 19.x 42 | - Node.js 20.x 43 | - Node.js 21.x 44 | 45 | include: 46 | - name: Node.js 0.6 47 | node-version: "0.6" 48 | npm-i: mocha@1.21.5 49 | npm-rm: nyc 50 | 51 | - name: Node.js 0.8 52 | node-version: "0.8" 53 | npm-i: mocha@2.5.3 54 | npm-rm: nyc 55 | 56 | - name: Node.js 0.10 57 | node-version: "0.10" 58 | npm-i: mocha@3.5.3 nyc@10.3.2 59 | 60 | - name: Node.js 0.12 61 | node-version: "0.12" 62 | npm-i: mocha@3.5.3 nyc@10.3.2 63 | 64 | - name: io.js 1.x 65 | node-version: "1.8" 66 | npm-i: mocha@3.5.3 nyc@10.3.2 67 | 68 | - name: io.js 2.x 69 | node-version: "2.5" 70 | npm-i: mocha@3.5.3 nyc@10.3.2 71 | 72 | - name: io.js 3.x 73 | node-version: "3.3" 74 | npm-i: mocha@3.5.3 nyc@10.3.2 75 | 76 | - name: Node.js 4.x 77 | node-version: "4.9" 78 | npm-i: mocha@5.2.0 nyc@11.9.0 79 | 80 | - name: Node.js 5.x 81 | node-version: "5.12" 82 | npm-i: mocha@5.2.0 nyc@11.9.0 83 | 84 | - name: Node.js 6.x 85 | node-version: "6.17" 86 | npm-i: mocha@6.2.2 nyc@14.1.1 87 | 88 | - name: Node.js 7.x 89 | node-version: "7.10" 90 | npm-i: mocha@6.2.2 nyc@14.1.1 91 | 92 | - name: Node.js 8.x 93 | node-version: "8.17" 94 | npm-i: mocha@7.1.2 nyc@14.1.1 95 | 96 | - name: Node.js 9.x 97 | node-version: "9.11" 98 | npm-i: mocha@7.1.2 nyc@14.1.1 99 | 100 | - name: Node.js 10.x 101 | node-version: "10.24" 102 | npm-i: mocha@8.4.0 103 | 104 | - name: Node.js 11.x 105 | node-version: "11.15" 106 | npm-i: mocha@8.4.0 107 | 108 | - name: Node.js 12.x 109 | node-version: "12.22" 110 | npm-i: mocha@9.2.2 111 | 112 | - name: Node.js 13.x 113 | node-version: "13.14" 114 | npm-i: mocha@9.2.2 115 | 116 | - name: Node.js 14.x 117 | node-version: "14.21" 118 | 119 | - name: Node.js 15.x 120 | node-version: "15.14" 121 | 122 | - name: Node.js 16.x 123 | node-version: "16.20" 124 | 125 | - name: Node.js 17.x 126 | node-version: "17.9" 127 | 128 | - name: Node.js 18.x 129 | node-version: "18.18" 130 | 131 | - name: Node.js 19.x 132 | node-version: "19.9" 133 | 134 | - name: Node.js 20.x 135 | node-version: "20.9" 136 | 137 | - name: Node.js 21.x 138 | node-version: "21.1" 139 | 140 | steps: 141 | - uses: actions/checkout@v3 142 | 143 | - name: Install Node.js ${{ matrix.node-version }} 144 | shell: bash -eo pipefail -l {0} 145 | run: | 146 | if [[ "${{ matrix.node-version }}" == 0.6* ]]; then 147 | sudo sh -c 'echo "deb http://us.archive.ubuntu.com/ubuntu/ bionic universe" >> /etc/apt/sources.list' 148 | sudo sh -c 'echo "deb http://security.ubuntu.com/ubuntu bionic-security main" >> /etc/apt/sources.list' 149 | sudo apt-get update 150 | sudo apt-get install g++-4.8 gcc-4.8 libssl1.0-dev python2 python-is-python2 151 | export CC=/usr/bin/gcc-4.8 152 | export CXX=/usr/bin/g++-4.8 153 | fi 154 | nvm install --default ${{ matrix.node-version }} 155 | if [[ "${{ matrix.node-version }}" == 0.* && "$(cut -d. -f2 <<< "${{ matrix.node-version }}")" -lt 10 ]]; then 156 | nvm install --alias=npm 0.10 157 | nvm use ${{ matrix.node-version }} 158 | if [[ "$(npm -v)" == 1.1.* ]]; then 159 | nvm exec npm npm install -g npm@1.1 160 | ln -fs "$(which npm)" "$(dirname "$(nvm which npm)")/npm" 161 | else 162 | sed -i '1s;^.*$;'"$(printf '#!%q' "$(nvm which npm)")"';' "$(readlink -f "$(which npm)")" 163 | fi 164 | npm config set strict-ssl false 165 | fi 166 | dirname "$(nvm which ${{ matrix.node-version }})" >> "$GITHUB_PATH" 167 | 168 | - name: Configure npm 169 | run: | 170 | if [[ "$(npm config get package-lock)" == "true" ]]; then 171 | npm config set package-lock false 172 | else 173 | npm config set shrinkwrap false 174 | fi 175 | 176 | - name: Remove npm module(s) ${{ matrix.npm-rm }} 177 | run: npm rm --silent --save-dev ${{ matrix.npm-rm }} 178 | if: matrix.npm-rm != '' 179 | 180 | - name: Install npm module(s) ${{ matrix.npm-i }} 181 | run: npm install --save-dev ${{ matrix.npm-i }} 182 | if: matrix.npm-i != '' 183 | 184 | - name: Setup Node.js version-specific dependencies 185 | shell: bash 186 | run: | 187 | # eslint for linting 188 | # - remove on Node.js < 12 189 | if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -lt 12 ]]; then 190 | node -pe 'Object.keys(require("./package").devDependencies).join("\n")' | \ 191 | grep -E '^eslint(-|$)' | \ 192 | sort -r | \ 193 | xargs -n1 npm rm --silent --save-dev 194 | fi 195 | 196 | - name: Install Node.js dependencies 197 | run: npm install 198 | 199 | - name: Install browserify 200 | run: | 201 | if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -ge 1 ]]; then 202 | npm install --save-dev browserify@16 203 | fi 204 | 205 | - name: List environment 206 | id: list_env 207 | shell: bash 208 | run: | 209 | echo "node@$(node -v)" 210 | echo "npm@$(npm -v)" 211 | npm -s ls ||: 212 | (npm -s ls --depth=0 ||:) | awk -F'[ @]' 'NR>1 && $2 { print $2 "=" $3 }' >> "$GITHUB_OUTPUT" 213 | 214 | - name: Run tests 215 | shell: bash 216 | run: | 217 | if npm -ps ls nyc | grep -q nyc; then 218 | npm run test-ci 219 | else 220 | npm test 221 | fi 222 | 223 | - name: Lint code 224 | if: steps.list_env.outputs.eslint != '' 225 | run: npm run lint 226 | 227 | - name: Collect code coverage 228 | uses: coverallsapp/github-action@master 229 | if: steps.list_env.outputs.nyc != '' 230 | with: 231 | github-token: ${{ secrets.GITHUB_TOKEN }} 232 | flag-name: run-${{ matrix.test_number }} 233 | parallel: true 234 | 235 | coverage: 236 | permissions: 237 | checks: write # for coverallsapp/github-action to create new checks 238 | needs: test 239 | runs-on: ubuntu-latest 240 | steps: 241 | - name: Upload code coverage 242 | uses: coverallsapp/github-action@master 243 | with: 244 | github-token: ${{ secrets.github_token }} 245 | parallel-finished: true 246 | --------------------------------------------------------------------------------