From 791defcccf1e163005443fb5138ae2bf1c19a202 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Sun, 5 Nov 2023 21:45:59 +0100 Subject: [PATCH 1/2] chore: remove nanoid --- lib/utils.js | 13 ++++++++++--- package-lock.json | 17 ----------------- package.json | 1 - test/unit/utils.spec.js | 3 +++ 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 7e1d566819..c573903370 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -8,8 +8,6 @@ /** * Module dependencies. */ - -const {nanoid} = require('nanoid/non-secure'); var path = require('path'); var util = require('util'); var he = require('he'); @@ -615,11 +613,20 @@ exports.constants = exports.defineConstants({ MOCHA_ID_PROP_NAME }); +const uniqueIDBase = + 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_'; + /** * Creates a new unique identifier * @returns {string} Unique identifier */ -exports.uniqueID = () => nanoid(); +exports.uniqueID = () => { + let id = ''; + for (let i = 0; i < 21; i++) { + id += uniqueIDBase[(Math.random() * 64) | 0]; + } + return id; +}; exports.assignNewMochaID = obj => { const id = exports.uniqueID(); diff --git a/package-lock.json b/package-lock.json index 8f1ed39671..542c4097aa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,6 @@ "log-symbols": "4.1.0", "minimatch": "5.0.1", "ms": "2.1.3", - "nanoid": "3.3.3", "serialize-javascript": "6.0.0", "strip-json-comments": "3.1.1", "supports-color": "8.1.1", @@ -14069,17 +14068,6 @@ "integrity": "sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==", "dev": true }, - "node_modules/nanoid": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.3.tgz", - "integrity": "sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w==", - "bin": { - "nanoid": "bin/nanoid.cjs" - }, - "engines": { - "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" - } - }, "node_modules/natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", @@ -33952,11 +33940,6 @@ "integrity": "sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==", "dev": true }, - "nanoid": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.3.tgz", - "integrity": "sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w==" - }, "natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", diff --git a/package.json b/package.json index 14c013a9db..8925811032 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,6 @@ "log-symbols": "4.1.0", "minimatch": "5.0.1", "ms": "2.1.3", - "nanoid": "3.3.3", "serialize-javascript": "6.0.0", "strip-json-comments": "3.1.1", "supports-color": "8.1.1", diff --git a/test/unit/utils.spec.js b/test/unit/utils.spec.js index adb36c4cd6..46f27b57ad 100644 --- a/test/unit/utils.spec.js +++ b/test/unit/utils.spec.js @@ -760,5 +760,8 @@ describe('lib/utils', function () { it('should return a non-empty string', function () { expect(utils.uniqueID(), 'to be a string').and('not to be empty'); }); + it('should have length of 21', function () { + expect(utils.uniqueID().length, 'to equal', 21); + }); }); }); From 3e9e56f7eaa8ba2e92ae8ab68e5ad2f005826e81 Mon Sep 17 00:00:00 2001 From: Aras Abbasi Date: Mon, 6 Nov 2023 09:22:11 +0100 Subject: [PATCH 2/2] add comment --- lib/utils.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/utils.js b/lib/utils.js index c573903370..fc7271d019 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -618,6 +618,8 @@ const uniqueIDBase = /** * Creates a new unique identifier + * Does not create cryptographically safe ids. + * Trivial copy of nanoid/non-secure * @returns {string} Unique identifier */ exports.uniqueID = () => {