Skip to content

Commit

Permalink
Replace find-up (#4385)
Browse files Browse the repository at this point in the history
  • Loading branch information
soulgalore authored Jan 7, 2025
1 parent eb0ba42 commit 25c4aa2
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 81 deletions.
2 changes: 1 addition & 1 deletion bin/browsertimeWebPageReplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion lib/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions lib/support/fileUtil.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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;
}
79 changes: 1 addition & 78 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 25c4aa2

Please sign in to comment.