Skip to content

Commit ebdbe52

Browse files
authored
perf: remove find-up (#12601)
1 parent 6f6cd94 commit ebdbe52

File tree

12 files changed

+38
-57
lines changed

12 files changed

+38
-57
lines changed

.changeset/purple-queens-vanish.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@cloudflare/workers-utils": patch
3+
"wrangler": patch
4+
---
5+
6+
Switch to `empathic` for file-system upwards traversal to reduce dependency bloat.

packages/workers-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
"@vitest/ui": "catalog:default",
4646
"cloudflare": "^5.2.0",
4747
"concurrently": "^8.2.2",
48+
"empathic": "^2.0.0",
4849
"eslint": "catalog:default",
49-
"find-up": "^6.3.0",
5050
"jsonc-parser": "catalog:default",
5151
"smol-toml": "catalog:default",
5252
"ts-dedent": "^2.2.0",

packages/workers-utils/src/config/config-helpers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { existsSync } from "node:fs";
22
import path from "node:path";
3-
import { findUpSync } from "find-up";
3+
import * as find from "empathic/find";
44
import dedent from "ts-dedent";
55
import { PATH_TO_DEPLOY_CONFIG } from "../constants";
66
import { UserError } from "../errors";
@@ -61,9 +61,9 @@ export function findWranglerConfig(
6161
{ useRedirectIfAvailable = false } = {}
6262
): ConfigPaths {
6363
const userConfigPath =
64-
findUpSync(`wrangler.json`, { cwd: referencePath }) ??
65-
findUpSync(`wrangler.jsonc`, { cwd: referencePath }) ??
66-
findUpSync(`wrangler.toml`, { cwd: referencePath });
64+
find.file(`wrangler.json`, { cwd: referencePath }) ??
65+
find.file(`wrangler.jsonc`, { cwd: referencePath }) ??
66+
find.file(`wrangler.toml`, { cwd: referencePath });
6767

6868
if (!useRedirectIfAvailable) {
6969
return {
@@ -99,7 +99,7 @@ function findRedirectedWranglerConfig(
9999
deployConfigPath: string | undefined;
100100
redirected: boolean;
101101
} {
102-
const deployConfigPath = findUpSync(PATH_TO_DEPLOY_CONFIG, { cwd });
102+
const deployConfigPath = find.file(PATH_TO_DEPLOY_CONFIG, { cwd });
103103
if (deployConfigPath === undefined) {
104104
return { configPath: userConfigPath, deployConfigPath, redirected: false };
105105
}

packages/wrangler/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@
127127
"devtools-protocol": "^0.0.1182435",
128128
"dotenv": "^16.3.1",
129129
"dotenv-expand": "^12.0.2",
130+
"empathic": "^2.0.0",
130131
"eslint": "catalog:default",
131132
"esprima": "4.0.1",
132133
"execa": "^6.1.0",
133-
"find-up": "^6.3.0",
134134
"get-port": "^7.0.0",
135135
"glob-to-regexp": "^0.4.1",
136136
"https-proxy-agent": "7.0.2",

packages/wrangler/src/autoconfig/frameworks/utils/packages.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { parsePackageJSON, readFileSync } from "@cloudflare/workers-utils";
2-
import { findUpSync } from "find-up";
2+
import * as find from "empathic/find";
33

44
/**
55
* Checks wether a package is installed in a target project or not
@@ -35,9 +35,9 @@ export function getInstalledPackageVersion(
3535
if (!packagePath) {
3636
return undefined;
3737
}
38-
const packageJsonPath = findUpSync("package.json", {
38+
const packageJsonPath = find.file("package.json", {
3939
cwd: packagePath,
40-
stopAt: opts.stopAtProjectPath === true ? projectPath : undefined,
40+
last: opts.stopAtProjectPath === true ? projectPath : undefined,
4141
});
4242
if (!packageJsonPath) {
4343
return undefined;

packages/wrangler/src/config-cache.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "node:fs";
88
import * as path from "node:path";
99
import { getWranglerCacheDirFromEnv } from "@cloudflare/workers-utils";
10-
import { findUpSync } from "find-up";
10+
import * as find from "empathic/find";
1111
import { isNonInteractiveOrCI } from "./is-interactive";
1212
import { logger } from "./logger";
1313

@@ -29,9 +29,7 @@ export function getCacheFolder(): string {
2929
}
3030

3131
// Find node_modules using existing find-up logic
32-
const closestNodeModulesDirectory = findUpSync("node_modules", {
33-
type: "directory",
34-
});
32+
const closestNodeModulesDirectory = find.dir("node_modules");
3533

3634
const nodeModulesCache = closestNodeModulesDirectory
3735
? path.join(closestNodeModulesDirectory, ".cache", "wrangler")

packages/wrangler/src/pages/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from "node:path";
2-
import { findUpSync } from "find-up";
2+
import * as find from "empathic/find";
33
import { getWranglerTmpDir } from "../paths";
44
import type { BundleResult } from "../deployment-bundle/bundle";
55

@@ -47,7 +47,7 @@ export function getPagesProjectRoot(): string {
4747
if (projectRootCache !== undefined && projectRootCacheCwd === cwd) {
4848
return projectRootCache;
4949
}
50-
const packagePath = findUpSync("package.json");
50+
const packagePath = find.file("package.json");
5151
projectRootCache = packagePath ? path.dirname(packagePath) : process.cwd();
5252
projectRootCacheCwd = cwd;
5353
return projectRootCache;

packages/wrangler/src/type-generation/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
UserError,
1111
} from "@cloudflare/workers-utils";
1212
import chalk from "chalk";
13-
import { findUpSync } from "find-up";
13+
import * as find from "empathic/find";
1414
import { getNodeCompat } from "miniflare";
1515
import { readConfig } from "../config";
1616
import { createCommand } from "../core/create-command";
@@ -1257,7 +1257,7 @@ function generatePerEnvTypeStrings(
12571257
* @throws {UserError} If a non-Wrangler .d.ts file already exists at the given path.
12581258
*/
12591259
const validateTypesFile = (path: string): void => {
1260-
const wranglerOverrideDTSPath = findUpSync(path);
1260+
const wranglerOverrideDTSPath = find.file(path);
12611261
if (wranglerOverrideDTSPath === undefined) {
12621262
return;
12631263
}

packages/wrangler/src/type-generation/runtime/log-runtime-types-message.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { existsSync } from "node:fs";
2-
import { join } from "node:path";
32
import chalk from "chalk";
4-
import { findUpMultipleSync } from "find-up";
3+
import * as find from "empathic/find";
54
import { logger } from "../../logger";
65

76
/**
@@ -42,14 +41,9 @@ export function logRuntimeTypesMessage(
4241
);
4342

4443
if (!isNodeTypesInstalled && isNodeCompat) {
45-
const nodeModules = findUpMultipleSync("node_modules", {
46-
type: "directory",
47-
});
48-
for (const folder of nodeModules) {
49-
if (nodeModules && existsSync(join(folder, "@types/node"))) {
50-
isNodeTypesInstalled = true;
51-
break;
52-
}
44+
const nodeModules = find.dir("node_modules/@types/node");
45+
if (nodeModules) {
46+
isNodeTypesInstalled = true;
5347
}
5448
}
5549
if (isNodeCompat && !isNodeTypesInstalled) {

pnpm-lock.yaml

Lines changed: 9 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)