From 1a2193b9520eb3abe62953c32f3e65b078da4f35 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sun, 7 Jul 2024 15:44:20 -0700 Subject: [PATCH 1/3] remove find-up to remove six dependencies --- packages/find-root/package.json | 1 - packages/find-root/src/index.ts | 38 ++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/packages/find-root/package.json b/packages/find-root/package.json index 6753b08..78f320b 100644 --- a/packages/find-root/package.json +++ b/packages/find-root/package.json @@ -11,7 +11,6 @@ "module": "dist/manypkg-find-root.esm.js", "dependencies": { "@manypkg/tools": "^1.1.1", - "find-up": "^4.1.0", "fs-extra": "^8.1.0" }, "devDependencies": { diff --git a/packages/find-root/src/index.ts b/packages/find-root/src/index.ts index 072138d..f115764 100644 --- a/packages/find-root/src/index.ts +++ b/packages/find-root/src/index.ts @@ -1,6 +1,6 @@ -import findUp, { sync as findUpSync } from "find-up"; import path from "path"; import fs from "fs-extra"; +import fsp from "fs/promises"; import { Tool, @@ -98,7 +98,7 @@ export async function findRoot( } }); }, - { cwd, type: "directory" } + cwd ); if (monorepoRoot) { @@ -123,7 +123,7 @@ export async function findRoot( } } }, - { cwd, type: "directory" } + cwd ); if (!rootDir) { @@ -158,7 +158,7 @@ export function findRootSync( } } }, - { cwd, type: "directory" } + cwd ); if (monorepoRoot) { @@ -177,7 +177,7 @@ export function findRootSync( const exists = fs.existsSync(path.join(directory, "package.json")); return exists ? directory : undefined; }, - { cwd, type: "directory" } + cwd ); if (!rootDir) { @@ -189,3 +189,31 @@ export function findRootSync( rootDir, }; } + +export async function findUp(matcher: (directory: string) => Promise, cwd = process.cwd()) { + let directory = path.resolve(cwd); + const { root } = path.parse(directory); + + while (directory && directory !== root) { + const filePath = await matcher(directory); + if (filePath) { + return path.resolve(directory, filePath); + } + + directory = path.dirname(directory); + } +} + +export function findUpSync(matcher: (directory: string) => string | undefined, cwd = process.cwd()) { + let directory = path.resolve(cwd); + const { root } = path.parse(directory); + + while (directory && directory !== root) { + const filePath = matcher(directory); + if (filePath) { + return path.resolve(directory, filePath); + } + + directory = path.dirname(directory); + } +} From 9839cb6b09b057e158acf50544201bc68a9a1d32 Mon Sep 17 00:00:00 2001 From: Emma Hamilton Date: Fri, 9 Aug 2024 10:05:55 +1000 Subject: [PATCH 2/3] Create cool-goats-kiss.md --- .changeset/cool-goats-kiss.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/cool-goats-kiss.md diff --git a/.changeset/cool-goats-kiss.md b/.changeset/cool-goats-kiss.md new file mode 100644 index 0000000..67dfb39 --- /dev/null +++ b/.changeset/cool-goats-kiss.md @@ -0,0 +1,5 @@ +--- +"@manypkg/find-root": patch +--- + +Remove find-up dependency From eafdf227e31f89b111ccd2dc9685766978260a11 Mon Sep 17 00:00:00 2001 From: Emma Hamilton Date: Fri, 9 Aug 2024 10:14:17 +1000 Subject: [PATCH 3/3] Stop exporting new functions and make cwd required --- packages/find-root/src/index.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/find-root/src/index.ts b/packages/find-root/src/index.ts index f115764..6850fb8 100644 --- a/packages/find-root/src/index.ts +++ b/packages/find-root/src/index.ts @@ -1,6 +1,5 @@ import path from "path"; import fs from "fs-extra"; -import fsp from "fs/promises"; import { Tool, @@ -190,7 +189,7 @@ export function findRootSync( }; } -export async function findUp(matcher: (directory: string) => Promise, cwd = process.cwd()) { +async function findUp(matcher: (directory: string) => Promise, cwd: string) { let directory = path.resolve(cwd); const { root } = path.parse(directory); @@ -204,7 +203,7 @@ export async function findUp(matcher: (directory: string) => Promise string | undefined, cwd = process.cwd()) { +function findUpSync(matcher: (directory: string) => string | undefined, cwd: string) { let directory = path.resolve(cwd); const { root } = path.parse(directory);