From 25c4aa299587825e7df92af6ed0e733976e426c8 Mon Sep 17 00:00:00 2001 From: Peter Hedenskog Date: Tue, 7 Jan 2025 17:19:33 +0100 Subject: [PATCH] Replace find-up (#4385) --- bin/browsertimeWebPageReplay.js | 2 +- lib/cli/cli.js | 2 +- lib/support/fileUtil.js | 17 +++++++ npm-shrinkwrap.json | 79 +-------------------------------- package.json | 1 - 5 files changed, 20 insertions(+), 81 deletions(-) diff --git a/bin/browsertimeWebPageReplay.js b/bin/browsertimeWebPageReplay.js index ecaeccd5e..939ddf6e1 100755 --- a/bin/browsertimeWebPageReplay.js +++ b/bin/browsertimeWebPageReplay.js @@ -8,10 +8,10 @@ import get from 'lodash.get'; import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; -import { findUpSync } from 'find-up'; import { BrowsertimeEngine, configureLogging } from 'browsertime'; import { getURLs } from '../lib/cli/util.js'; +import { findUpSync } from '../lib/support/fileUtil.js'; import {config as browsertimeConfig} from '../lib/plugins/browsertime/index.js'; diff --git a/lib/cli/cli.js b/lib/cli/cli.js index 62dae6036..f0b9bdc5a 100644 --- a/lib/cli/cli.js +++ b/lib/cli/cli.js @@ -9,7 +9,6 @@ import merge from 'lodash.merge'; import reduce from 'lodash.reduce'; import set from 'lodash.set'; import get from 'lodash.get'; -import { findUpSync } from 'find-up'; import { getURLs, getAliases } from './util.js'; import { toArray } from '../support/util.js'; @@ -19,6 +18,7 @@ import { config as metricsConfig } from '../plugins/metrics/index.js'; import { config as slackConfig } from '../plugins/slack/index.js'; import { config as htmlConfig } from '../plugins/html/index.js'; import { messageTypes as matrixMessageTypes } from '../plugins/matrix/index.js'; +import { findUpSync } from '../support/fileUtil.js'; const metricList = Object.keys(friendlynames); const require = createRequire(import.meta.url); diff --git a/lib/support/fileUtil.js b/lib/support/fileUtil.js index 5f1154e94..f63eb5b93 100644 --- a/lib/support/fileUtil.js +++ b/lib/support/fileUtil.js @@ -1,4 +1,5 @@ import { readdir } from 'node:fs/promises'; +import { existsSync } from 'node:fs'; import path from 'node:path'; export async function recursiveReaddir(dir, ignoreDirectories = false) { @@ -21,3 +22,19 @@ export async function recursiveReaddir(dir, ignoreDirectories = false) { return results; } + +export function findUpSync(filenames, startDir = process.cwd()) { + let currentDir = startDir; + + while (currentDir !== path.dirname(currentDir)) { + for (const filename of filenames) { + const filePath = path.resolve(currentDir, filename); + if (existsSync(filePath)) { + return filePath; + } + } + currentDir = path.dirname(currentDir); + } + + return; +} diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 7ee1288aa..214ac740f 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -24,7 +24,6 @@ "dayjs": "1.11.11", "fast-crc32c": "2.0.0", "fast-stats": "0.0.7", - "find-up": "7.0.0", "import-global": "1.1.1", "influx": "5.9.3", "jstransformer-markdown-it": "3.0.0", @@ -5352,22 +5351,6 @@ "integrity": "sha1-2wAjj/hoVRoYLnShA0FtKVqYyMo=", "dev": true }, - "node_modules/find-up": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-7.0.0.tgz", - "integrity": "sha512-YyZM99iHrqLKjmt4LJDj58KI+fYyufRLBSYcqycxf//KpBk9FoewoGX0450m9nB44qrZnovzC2oeP5hUibxc/g==", - "dependencies": { - "locate-path": "^7.2.0", - "path-exists": "^5.0.0", - "unicorn-magic": "^0.1.0" - }, - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/find-up-simple": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/find-up-simple/-/find-up-simple-1.0.0.tgz", @@ -7102,20 +7085,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/locate-path": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-7.2.0.tgz", - "integrity": "sha512-gvVijfZvn7R+2qyPX8mAuKcFGDf6Nc61GdvGafQsHL0sBIxfKzA+usWn4GFC/bk+QdwPUD4kWFJLhElipq+0VA==", - "dependencies": { - "p-locate": "^6.0.0" - }, - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", @@ -7934,45 +7903,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/p-locate": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-6.0.0.tgz", - "integrity": "sha512-wPrq66Llhl7/4AGC6I+cqxT07LhXvWL08LNXz1fENOw0Ap4sRZZ/gZpTTJ5jpurzzzfS2W/Ge9BY3LgLjCShcw==", - "dependencies": { - "p-limit": "^4.0.0" - }, - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/p-locate/node_modules/p-limit": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-4.0.0.tgz", - "integrity": "sha512-5b0R4txpzjPWVw/cXXUResoD4hb6U/x9BH08L7nw+GN1sezDzPdxeRvpc9c433fZhBan/wusjbCsqwqm4EIBIQ==", - "dependencies": { - "yocto-queue": "^1.0.0" - }, - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/p-locate/node_modules/yocto-queue": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.0.0.tgz", - "integrity": "sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==", - "engines": { - "node": ">=12.20" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/p-map": { "version": "7.0.2", "resolved": "https://registry.npmjs.org/p-map/-/p-map-7.0.2.tgz", @@ -8087,14 +8017,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/path-exists": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-5.0.0.tgz", - "integrity": "sha512-RjhtfwJOxzcFmNOi6ltcbcu4Iu+FL3zEj83dk4kAS+fVpTxXLO1b38RvJgT/0QwvV/L3aY9TAnyv0EOqW4GoMQ==", - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - } - }, "node_modules/path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", @@ -10191,6 +10113,7 @@ "version": "0.1.0", "resolved": "https://registry.npmjs.org/unicorn-magic/-/unicorn-magic-0.1.0.tgz", "integrity": "sha512-lRfVq8fE8gz6QMBuDM6a+LO3IAzTi05H6gCVaUpir2E1Rwpo4ZUog45KpNXKC/Mn3Yb9UDuHumeFTo9iV/D9FQ==", + "dev": true, "engines": { "node": ">=18" }, diff --git a/package.json b/package.json index ccb4c46e5..9732a80e3 100644 --- a/package.json +++ b/package.json @@ -95,7 +95,6 @@ "dayjs": "1.11.11", "fast-crc32c": "2.0.0", "fast-stats": "0.0.7", - "find-up": "7.0.0", "import-global": "1.1.1", "influx": "5.9.3", "jstransformer-markdown-it": "3.0.0",