Skip to content

Commit

Permalink
Replace findup (#2240)
Browse files Browse the repository at this point in the history
  • Loading branch information
soulgalore authored Jan 1, 2025
1 parent ec2be52 commit ff37ae1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 131 deletions.
3 changes: 1 addition & 2 deletions lib/support/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { format } from 'node:util';
import { readFileSync, statSync } from 'node:fs';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { findUpSync } from 'find-up';
import get from 'lodash.get';
import set from 'lodash.set';
import {
Expand All @@ -14,7 +13,7 @@ import {
} from '../video/defaults.js';
import { screenshotDefaults } from '../screenshot/defaults.js';
import { geckoProfilerDefaults } from '../firefox/settings/geckoProfilerDefaults.js';

import { findUpSync } from './fileUtil.js';
import { execaSync } from 'execa';

const configPath = findUpSync(['.browsertime.json']);
Expand Down
19 changes: 18 additions & 1 deletion lib/support/fileUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
rename as _rename,
readFile as _readFile,
copyFileSync as _copyFileSync,
unlinkSync as _unlinkSync
unlinkSync as _unlinkSync,
existsSync
} from 'node:fs';
import intel from 'intel';
import { onlyFiles, onlyWithExtension } from './filters.js';
Expand Down Expand Up @@ -83,3 +84,19 @@ export async function findFiles(dir, filter) {
});
return filePaths;
}

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;
}
130 changes: 3 additions & 127 deletions package-lock.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 @@ -18,7 +18,6 @@
"execa": "9.5.2",
"fast-stats": "0.0.7",
"ff-test-bidi-har-export": "0.0.17",
"find-up": "7.0.0",
"get-port": "7.1.0",
"intel": "1.2.0",
"lodash.get": "4.4.2",
Expand Down

0 comments on commit ff37ae1

Please sign in to comment.