From 04e8068a3238732a8fe5e7e6089ab1cf838fd33d Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 30 Oct 2024 07:33:04 +0100 Subject: [PATCH 1/8] Modernize CI Signed-off-by: Matteo Collina --- .coveralls.yml | 1 - .github/dependabot.yml | 11 ++++++ .github/workflows/ci.yml | 75 ++++++++++++++++++++++++++++++++++++++++ .travis.yml | 28 --------------- LICENSE | 2 +- package.json | 9 ++--- 6 files changed, 89 insertions(+), 37 deletions(-) delete mode 100644 .coveralls.yml create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index 359f683..0000000 --- a/.coveralls.yml +++ /dev/null @@ -1 +0,0 @@ -repo_token: yIxhFqtaaz5iGVYfie9mODehFYogm8S8L diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..7e7cbe1 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +version: 2 +updates: +- package-ecosystem: npm + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 + ignore: + - dependency-name: standard + versions: + - 16.0.3 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a0f0eff --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,75 @@ +name: ci + +on: [push, pull_request] + +jobs: + legacy: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: ['0.10', '0.12', 4.x, 6.x, 8.x] + + steps: + - uses: actions/checkout@v3 + with: + persist-credentials: false + + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Install + run: | + npm install --production && npm install tape + + - name: Run tests + run: | + npm run test + + test: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [10.x, 12.x, 13.x, 14.x, 15.x, 16.x, 18.x, 20.x, 22.x] + + steps: + - uses: actions/checkout@v3 + with: + persist-credentials: false + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Install + run: | + npm install + + - name: Run tests + run: | + npm run test + + types: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + persist-credentials: false + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: 16 + + - name: Install + run: | + npm install + + - name: Run types tests + run: | + npm run typescript diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1970476..0000000 --- a/.travis.yml +++ /dev/null @@ -1,28 +0,0 @@ -language: node_js -sudo: false - -node_js: - - 9 - - 8 - - 7 - - 6 - - 5 - - 4 - - 4.0 - - iojs-v3 - - iojs-v2 - - iojs-v1 - - 0.12 - - 0.10 - -cache: - directories: - - node_modules - -after_script: -- npm run coverage - -notifications: - email: - on_success: never - on_failure: always diff --git a/LICENSE b/LICENSE index fbf3a01..56d1590 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Matteo Collina +Copyright (c) 2015-2024 Matteo Collina Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/package.json b/package.json index ac9342b..d4e8037 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,7 @@ "types": "reusify.d.ts", "scripts": { "lint": "standard", - "test": "tape test.js | faucet", - "istanbul": "istanbul cover tape test.js", - "coverage": "npm run istanbul; cat coverage/lcov.info | coveralls", + "test": "tape test.js", "test:typescript": "tsc" }, "pre-commit": [ @@ -39,12 +37,9 @@ }, "devDependencies": { "@types/node": "^20.1.0", - "coveralls": "^2.13.3", - "faucet": "0.0.1", - "istanbul": "^0.4.5", "pre-commit": "^1.2.2", "standard": "^10.0.3", - "tape": "^4.8.0", + "tape": "^5.0.0", "typescript": "^5.2.2" } } From 68fecdec15579c89fc5424dd91c49f476b6cd240 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 30 Oct 2024 07:34:51 +0100 Subject: [PATCH 2/8] lint Signed-off-by: Matteo Collina --- .github/workflows/ci.yml | 23 ++++++++++++++++++++++- benchmarks/createNoCodeFunction.js | 12 ++++++------ benchmarks/fib.js | 4 ++-- benchmarks/reuseNoCodeFunction.js | 18 +++++++++--------- eslint.config.js | 3 +++ package.json | 5 +++-- reusify.js | 10 +++++----- test.js | 22 +++++++++++----------- 8 files changed, 61 insertions(+), 36 deletions(-) create mode 100644 eslint.config.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a0f0eff..5c74230 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,7 @@ jobs: - name: Use Node.js uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 22 - name: Install run: | @@ -73,3 +73,24 @@ jobs: - name: Run types tests run: | npm run typescript + + lint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + persist-credentials: false + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: 22 + + - name: Install + run: | + npm install + + - name: Lint + run: | + npm run lint diff --git a/benchmarks/createNoCodeFunction.js b/benchmarks/createNoCodeFunction.js index ce1aac7..9fac0a0 100644 --- a/benchmarks/createNoCodeFunction.js +++ b/benchmarks/createNoCodeFunction.js @@ -1,15 +1,15 @@ 'use strict' -var fib = require('./fib') -var max = 100000000 -var start = Date.now() +const fib = require('./fib') +const max = 100000000 +const start = Date.now() // create a funcion with the typical error // pattern, that delegates the heavy load // to something else function createNoCodeFunction () { /* eslint no-constant-condition: "off" */ - var num = 100 + const num = 100 ;(function () { if (null) { @@ -20,11 +20,11 @@ function createNoCodeFunction () { })() } -for (var i = 0; i < max; i++) { +for (let i = 0; i < max; i++) { createNoCodeFunction() } -var time = Date.now() - start +const time = Date.now() - start console.log('Total time', time) console.log('Total iterations', max) console.log('Iteration/s', max / time * 1000) diff --git a/benchmarks/fib.js b/benchmarks/fib.js index e22cc48..6f0ee10 100644 --- a/benchmarks/fib.js +++ b/benchmarks/fib.js @@ -1,11 +1,11 @@ 'use strict' function fib (num) { - var fib = [] + const fib = [] fib[0] = 0 fib[1] = 1 - for (var i = 2; i <= num; i++) { + for (let i = 2; i <= num; i++) { fib[i] = fib[i - 2] + fib[i - 1] } } diff --git a/benchmarks/reuseNoCodeFunction.js b/benchmarks/reuseNoCodeFunction.js index 3358d6e..e872781 100644 --- a/benchmarks/reuseNoCodeFunction.js +++ b/benchmarks/reuseNoCodeFunction.js @@ -1,13 +1,13 @@ 'use strict' -var reusify = require('../') -var fib = require('./fib') -var instance = reusify(MyObject) -var max = 100000000 -var start = Date.now() +const reusify = require('../') +const fib = require('./fib') +const instance = reusify(MyObject) +const max = 100000000 +const start = Date.now() function reuseNoCodeFunction () { - var obj = instance.get() + const obj = instance.get() obj.num = 100 obj.func() obj.num = 0 @@ -16,7 +16,7 @@ function reuseNoCodeFunction () { function MyObject () { this.next = null - var that = this + const that = this this.num = 0 this.func = function () { /* eslint no-constant-condition: "off" */ @@ -28,11 +28,11 @@ function MyObject () { } } -for (var i = 0; i < max; i++) { +for (let i = 0; i < max; i++) { reuseNoCodeFunction() } -var time = Date.now() - start +const time = Date.now() - start console.log('Total time', time) console.log('Total iterations', max) console.log('Iteration/s', max / time * 1000) diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..5212dc9 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,3 @@ +'use strict' + +module.exports = require('neostandard')({}) diff --git a/package.json b/package.json index d4e8037..7938658 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "reusify.js", "types": "reusify.d.ts", "scripts": { - "lint": "standard", + "lint": "eslint", "test": "tape test.js", "test:typescript": "tsc" }, @@ -37,8 +37,9 @@ }, "devDependencies": { "@types/node": "^20.1.0", + "eslint": "^9.13.0", + "neostandard": "^0.11.7", "pre-commit": "^1.2.2", - "standard": "^10.0.3", "tape": "^5.0.0", "typescript": "^5.2.2" } diff --git a/reusify.js b/reusify.js index e6f36f3..dee6e58 100644 --- a/reusify.js +++ b/reusify.js @@ -1,11 +1,11 @@ 'use strict' function reusify (Constructor) { - var head = new Constructor() - var tail = head + let head = new Constructor() + let tail = head function get () { - var current = head + const current = head if (current.next) { head = current.next @@ -25,8 +25,8 @@ function reusify (Constructor) { } return { - get: get, - release: release + get, + release } } diff --git a/test.js b/test.js index 929cfd7..e32fea7 100644 --- a/test.js +++ b/test.js @@ -1,7 +1,7 @@ 'use strict' -var test = require('tape') -var reusify = require('./') +const test = require('tape') +const reusify = require('./') test('reuse objects', function (t) { t.plan(6) @@ -11,8 +11,8 @@ test('reuse objects', function (t) { this.next = null } - var instance = reusify(MyObject) - var obj = instance.get() + const instance = reusify(MyObject) + const obj = instance.get() t.notEqual(obj, instance.get(), 'two instance created') t.notOk(obj.next, 'next must be null') @@ -35,10 +35,10 @@ test('reuse more than 2 objects', function (t) { this.next = null } - var instance = reusify(MyObject) - var obj = instance.get() - var obj2 = instance.get() - var obj3 = instance.get() + const instance = reusify(MyObject) + const obj = instance.get() + const obj2 = instance.get() + const obj3 = instance.get() t.notOk(obj.next, 'next must be null') t.notOk(obj2.next, 'next must be null') @@ -55,9 +55,9 @@ test('reuse more than 2 objects', function (t) { // skip one instance.get() - var obj4 = instance.get() - var obj5 = instance.get() - var obj6 = instance.get() + const obj4 = instance.get() + const obj5 = instance.get() + const obj6 = instance.get() t.equal(obj4, obj) t.equal(obj5, obj2) From ac154c2dc61bd20c1d0030cf9e3ba10eccb6e4da Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 30 Oct 2024 07:35:26 +0100 Subject: [PATCH 3/8] fixup Signed-off-by: Matteo Collina --- .github/dependabot.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 7e7cbe1..4872c5a 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,7 +5,3 @@ updates: schedule: interval: daily open-pull-requests-limit: 10 - ignore: - - dependency-name: standard - versions: - - 16.0.3 From e5189c6fee62fa9b498124adcbd8134d89796c62 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 30 Oct 2024 07:36:02 +0100 Subject: [PATCH 4/8] adjust badges Signed-off-by: Matteo Collina --- README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/README.md b/README.md index 9897b25..1aaee5d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # reusify [![npm version][npm-badge]][npm-url] -[![Build Status][travis-badge]][travis-url] -[![Coverage Status][coveralls-badge]][coveralls-url] Reuse your objects and functions for maximum speed. This technique will make any function run ~10% faster. You call your functions a @@ -139,7 +137,3 @@ MIT [npm-badge]: https://badge.fury.io/js/reusify.svg [npm-url]: https://badge.fury.io/js/reusify -[travis-badge]: https://api.travis-ci.org/mcollina/reusify.svg -[travis-url]: https://travis-ci.org/mcollina/reusify -[coveralls-badge]: https://coveralls.io/repos/mcollina/reusify/badge.svg?branch=master&service=github -[coveralls-url]: https://coveralls.io/github/mcollina/reusify?branch=master From c6d68729434d7765844c5e5ace94f1e1d0ce3b7c Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 30 Oct 2024 07:44:32 +0100 Subject: [PATCH 5/8] fix linting Signed-off-by: Matteo Collina --- benchmarks/createNoCodeFunction.js | 12 ++++++------ benchmarks/fib.js | 4 ++-- benchmarks/reuseNoCodeFunction.js | 18 +++++++++--------- eslint.config.js | 13 ++++++++++++- reusify.js | 10 +++++----- test.js | 22 +++++++++++----------- 6 files changed, 45 insertions(+), 34 deletions(-) diff --git a/benchmarks/createNoCodeFunction.js b/benchmarks/createNoCodeFunction.js index 9fac0a0..ce1aac7 100644 --- a/benchmarks/createNoCodeFunction.js +++ b/benchmarks/createNoCodeFunction.js @@ -1,15 +1,15 @@ 'use strict' -const fib = require('./fib') -const max = 100000000 -const start = Date.now() +var fib = require('./fib') +var max = 100000000 +var start = Date.now() // create a funcion with the typical error // pattern, that delegates the heavy load // to something else function createNoCodeFunction () { /* eslint no-constant-condition: "off" */ - const num = 100 + var num = 100 ;(function () { if (null) { @@ -20,11 +20,11 @@ function createNoCodeFunction () { })() } -for (let i = 0; i < max; i++) { +for (var i = 0; i < max; i++) { createNoCodeFunction() } -const time = Date.now() - start +var time = Date.now() - start console.log('Total time', time) console.log('Total iterations', max) console.log('Iteration/s', max / time * 1000) diff --git a/benchmarks/fib.js b/benchmarks/fib.js index 6f0ee10..e22cc48 100644 --- a/benchmarks/fib.js +++ b/benchmarks/fib.js @@ -1,11 +1,11 @@ 'use strict' function fib (num) { - const fib = [] + var fib = [] fib[0] = 0 fib[1] = 1 - for (let i = 2; i <= num; i++) { + for (var i = 2; i <= num; i++) { fib[i] = fib[i - 2] + fib[i - 1] } } diff --git a/benchmarks/reuseNoCodeFunction.js b/benchmarks/reuseNoCodeFunction.js index e872781..3358d6e 100644 --- a/benchmarks/reuseNoCodeFunction.js +++ b/benchmarks/reuseNoCodeFunction.js @@ -1,13 +1,13 @@ 'use strict' -const reusify = require('../') -const fib = require('./fib') -const instance = reusify(MyObject) -const max = 100000000 -const start = Date.now() +var reusify = require('../') +var fib = require('./fib') +var instance = reusify(MyObject) +var max = 100000000 +var start = Date.now() function reuseNoCodeFunction () { - const obj = instance.get() + var obj = instance.get() obj.num = 100 obj.func() obj.num = 0 @@ -16,7 +16,7 @@ function reuseNoCodeFunction () { function MyObject () { this.next = null - const that = this + var that = this this.num = 0 this.func = function () { /* eslint no-constant-condition: "off" */ @@ -28,11 +28,11 @@ function MyObject () { } } -for (let i = 0; i < max; i++) { +for (var i = 0; i < max; i++) { reuseNoCodeFunction() } -const time = Date.now() - start +var time = Date.now() - start console.log('Total time', time) console.log('Total iterations', max) console.log('Iteration/s', max / time * 1000) diff --git a/eslint.config.js b/eslint.config.js index 5212dc9..d0a9af6 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,3 +1,14 @@ 'use strict' -module.exports = require('neostandard')({}) +const base = require('neostandard')({}) + +module.exports = [ + ...base, + { + name: 'old-standard', + rules: { + 'no-var': 'off', + 'object-shorthand': 'off', + } + } +] diff --git a/reusify.js b/reusify.js index dee6e58..e6f36f3 100644 --- a/reusify.js +++ b/reusify.js @@ -1,11 +1,11 @@ 'use strict' function reusify (Constructor) { - let head = new Constructor() - let tail = head + var head = new Constructor() + var tail = head function get () { - const current = head + var current = head if (current.next) { head = current.next @@ -25,8 +25,8 @@ function reusify (Constructor) { } return { - get, - release + get: get, + release: release } } diff --git a/test.js b/test.js index e32fea7..929cfd7 100644 --- a/test.js +++ b/test.js @@ -1,7 +1,7 @@ 'use strict' -const test = require('tape') -const reusify = require('./') +var test = require('tape') +var reusify = require('./') test('reuse objects', function (t) { t.plan(6) @@ -11,8 +11,8 @@ test('reuse objects', function (t) { this.next = null } - const instance = reusify(MyObject) - const obj = instance.get() + var instance = reusify(MyObject) + var obj = instance.get() t.notEqual(obj, instance.get(), 'two instance created') t.notOk(obj.next, 'next must be null') @@ -35,10 +35,10 @@ test('reuse more than 2 objects', function (t) { this.next = null } - const instance = reusify(MyObject) - const obj = instance.get() - const obj2 = instance.get() - const obj3 = instance.get() + var instance = reusify(MyObject) + var obj = instance.get() + var obj2 = instance.get() + var obj3 = instance.get() t.notOk(obj.next, 'next must be null') t.notOk(obj2.next, 'next must be null') @@ -55,9 +55,9 @@ test('reuse more than 2 objects', function (t) { // skip one instance.get() - const obj4 = instance.get() - const obj5 = instance.get() - const obj6 = instance.get() + var obj4 = instance.get() + var obj5 = instance.get() + var obj6 = instance.get() t.equal(obj4, obj) t.equal(obj5, obj2) From c1d878beaf6f4e54c52d766ff1ba62912c87dab7 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 30 Oct 2024 07:52:05 +0100 Subject: [PATCH 6/8] fixup Signed-off-by: Matteo Collina --- .github/workflows/ci.yml | 20 ++++++++++---------- package.json | 4 ++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5c74230..35108e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,10 +8,10 @@ jobs: strategy: matrix: - node-version: ['0.10', '0.12', 4.x, 6.x, 8.x] + node-version: ['0.10', '0.12', 4.x, 6.x, 8.x, 10.x, 12.x, 13.x, 14.x, 15.x, 16.x] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: persist-credentials: false @@ -33,15 +33,15 @@ jobs: strategy: matrix: - node-version: [10.x, 12.x, 13.x, 14.x, 15.x, 16.x, 18.x, 20.x, 22.x] + node-version: [18.x, 20.x, 22.x] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: persist-credentials: false - name: Use Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} @@ -51,18 +51,18 @@ jobs: - name: Run tests run: | - npm run test + npm run test:coverage types: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: persist-credentials: false - name: Use Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 22 @@ -78,12 +78,12 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: persist-credentials: false - name: Use Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 22 diff --git a/package.json b/package.json index 7938658..ed63d7b 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "scripts": { "lint": "eslint", "test": "tape test.js", + "test:coverage": "c8 --100 tape test.js", "test:typescript": "tsc" }, "pre-commit": [ @@ -42,5 +43,8 @@ "pre-commit": "^1.2.2", "tape": "^5.0.0", "typescript": "^5.2.2" + }, + "dependencies": { + "c8": "^10.1.2" } } From 4d3abd6f9256b6530314a47a542def07f192e464 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 30 Oct 2024 07:56:48 +0100 Subject: [PATCH 7/8] fixup Signed-off-by: Matteo Collina --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 35108e4..70d2a8b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: persist-credentials: false - name: Use Node.js - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} From 641960c8b8565291b51e10cadf346a928c01160f Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 30 Oct 2024 07:57:47 +0100 Subject: [PATCH 8/8] fixup Signed-off-by: Matteo Collina --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ed63d7b..ac2cb09 100644 --- a/package.json +++ b/package.json @@ -42,9 +42,9 @@ "neostandard": "^0.11.7", "pre-commit": "^1.2.2", "tape": "^5.0.0", + "c8": "^10.1.2", "typescript": "^5.2.2" }, "dependencies": { - "c8": "^10.1.2" } }