Skip to content

Commit

Permalink
remove fs-extra from dependencies (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored Aug 9, 2024
1 parent 2ebda03 commit c0a5e5d
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 84 deletions.
6 changes: 6 additions & 0 deletions .changeset/spotty-owls-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@manypkg/find-root": patch
"@manypkg/tools": patch
---

Remove fs-extra from dependencies
3 changes: 1 addition & 2 deletions packages/find-root/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"main": "dist/manypkg-find-root.cjs.js",
"module": "dist/manypkg-find-root.esm.js",
"dependencies": {
"@manypkg/tools": "^1.1.1",
"fs-extra": "^8.1.0"
"@manypkg/tools": "^1.1.1"
},
"devDependencies": {
"@types/node": "^16.11.7",
Expand Down
5 changes: 3 additions & 2 deletions packages/find-root/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from "path";
import fs from "fs-extra";
import fs from "fs";
import fsp from "fs/promises";

import {
Tool,
Expand Down Expand Up @@ -114,7 +115,7 @@ export async function findRoot(
let rootDir = await findUp(
async (directory) => {
try {
await fs.access(path.join(directory, "package.json"));
await fsp.access(path.join(directory, "package.json"));
return directory;
} catch (err) {
if (!isNoEntryError(err)) {
Expand Down
1 change: 0 additions & 1 deletion packages/tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"license": "MIT",
"main": "dist/manypkg-tools.cjs.js",
"dependencies": {
"fs-extra": "^8.1.0",
"globby": "^11.0.0",
"jju": "^1.4.0",
"read-yaml-file": "^1.1.0"
Expand Down
18 changes: 5 additions & 13 deletions packages/tools/src/BoltTool.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import path from "path";
import fs from "fs-extra";

import { Tool, PackageJSON, Packages, InvalidMonorepoError } from "./Tool";
import {
expandPackageGlobs,
expandPackageGlobsSync,
} from "./expandPackageGlobs";
import { readJson, readJsonSync } from "./utils";

export interface BoltPackageJSON extends PackageJSON {
bolt?: {
Expand All @@ -18,9 +18,7 @@ export const BoltTool: Tool = {

async isMonorepoRoot(directory: string): Promise<boolean> {
try {
const pkgJson = (await fs.readJson(
path.join(directory, "package.json")
)) as BoltPackageJSON;
const pkgJson = await readJson(directory, "package.json") as BoltPackageJSON;
if (pkgJson.bolt && pkgJson.bolt.workspaces) {
return true;
}
Expand All @@ -35,9 +33,7 @@ export const BoltTool: Tool = {

isMonorepoRootSync(directory: string): boolean {
try {
const pkgJson = fs.readJsonSync(
path.join(directory, "package.json")
) as BoltPackageJSON;
const pkgJson = readJsonSync(directory, "package.json") as BoltPackageJSON;
if (pkgJson.bolt && pkgJson.bolt.workspaces) {
return true;
}
Expand All @@ -54,9 +50,7 @@ export const BoltTool: Tool = {
const rootDir = path.resolve(directory);

try {
const pkgJson = (await fs.readJson(
path.join(rootDir, "package.json")
)) as BoltPackageJSON;
const pkgJson = await readJson(rootDir, "package.json") as BoltPackageJSON;
if (!pkgJson.bolt || !pkgJson.bolt.workspaces) {
throw new InvalidMonorepoError(
`Directory ${rootDir} is not a valid ${BoltTool.type} monorepo root: missing bolt.workspaces entry`
Expand Down Expand Up @@ -88,9 +82,7 @@ export const BoltTool: Tool = {
const rootDir = path.resolve(directory);

try {
const pkgJson = fs.readJsonSync(
path.join(rootDir, "package.json")
) as BoltPackageJSON;
const pkgJson = readJsonSync(rootDir, "package.json") as BoltPackageJSON;
if (!pkgJson.bolt || !pkgJson.bolt.workspaces) {
throw new InvalidMonorepoError(
`Directory ${directory} is not a valid ${BoltTool.type} monorepo root: missing bolt.workspaces entry`
Expand Down
25 changes: 7 additions & 18 deletions packages/tools/src/LernaTool.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import path from "path";
import fs from "fs-extra";

import {
Tool,
Package,
PackageJSON,
Packages,
InvalidMonorepoError,
Expand All @@ -12,6 +10,7 @@ import {
expandPackageGlobs,
expandPackageGlobsSync,
} from "./expandPackageGlobs";
import { readJson, readJsonSync } from "./utils";

export interface LernaJson {
useWorkspaces?: boolean;
Expand All @@ -23,9 +22,7 @@ export const LernaTool: Tool = {

async isMonorepoRoot(directory: string): Promise<boolean> {
try {
const lernaJson = (await fs.readJson(
path.join(directory, "lerna.json")
)) as LernaJson;
const lernaJson = await readJson(directory, "lerna.json") as LernaJson;
if (lernaJson.useWorkspaces !== true) {
return true;
}
Expand All @@ -40,9 +37,7 @@ export const LernaTool: Tool = {

isMonorepoRootSync(directory: string): boolean {
try {
const lernaJson = fs.readJsonSync(
path.join(directory, "lerna.json")
) as LernaJson;
const lernaJson = readJsonSync(directory, "lerna.json") as LernaJson;
if (lernaJson.useWorkspaces !== true) {
return true;
}
Expand All @@ -59,10 +54,8 @@ export const LernaTool: Tool = {
const rootDir = path.resolve(directory);

try {
const lernaJson = await fs.readJson(path.join(rootDir, "lerna.json"));
const pkgJson = (await fs.readJson(
path.join(rootDir, "package.json")
)) as PackageJSON;
const lernaJson = await readJson(rootDir, "lerna.json") as LernaJson;
const pkgJson = await readJson(rootDir, "package.json") as PackageJSON;
const packageGlobs: string[] = lernaJson.packages || ["packages/*"];

return {
Expand All @@ -89,12 +82,8 @@ export const LernaTool: Tool = {
const rootDir = path.resolve(directory);

try {
const lernaJson = fs.readJsonSync(
path.join(rootDir, "lerna.json")
) as LernaJson;
const pkgJson = fs.readJsonSync(
path.join(rootDir, "package.json")
) as PackageJSON;
const lernaJson = readJsonSync(rootDir, "lerna.json") as LernaJson;
const pkgJson = readJsonSync(rootDir, "package.json") as PackageJSON;
const packageGlobs: string[] = lernaJson.packages || ["packages/*"];

return {
Expand Down
11 changes: 3 additions & 8 deletions packages/tools/src/PnpmTool.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import path from "path";
import readYamlFile, { sync as readYamlFileSync } from "read-yaml-file";
import fs from "fs-extra";

import {
Tool,
Package,
PackageJSON,
Packages,
InvalidMonorepoError,
Expand All @@ -13,6 +11,7 @@ import {
expandPackageGlobs,
expandPackageGlobsSync,
} from "./expandPackageGlobs";
import { readJson, readJsonSync } from "./utils";

export interface PnpmWorkspaceYaml {
packages?: string[];
Expand Down Expand Up @@ -64,9 +63,7 @@ export const PnpmTool: Tool = {
const manifest = await readYamlFile<{ packages?: string[] }>(
path.join(rootDir, "pnpm-workspace.yaml")
);
const pkgJson = (await fs.readJson(
path.join(rootDir, "package.json")
)) as PackageJSON;
const pkgJson = await readJson(rootDir, "package.json") as PackageJSON;
const packageGlobs: string[] = manifest.packages!;

return {
Expand Down Expand Up @@ -96,9 +93,7 @@ export const PnpmTool: Tool = {
const manifest = readYamlFileSync<{ packages?: string[] }>(
path.join(rootDir, "pnpm-workspace.yaml")
);
const pkgJson = fs.readJsonSync(
path.join(rootDir, "package.json")
) as PackageJSON;
const pkgJson = readJsonSync(rootDir, "package.json") as PackageJSON;
const packageGlobs: string[] = manifest.packages!;

return {
Expand Down
11 changes: 3 additions & 8 deletions packages/tools/src/RootTool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from "path";
import fs from "fs-extra";

import {
Tool,
Expand All @@ -8,7 +7,7 @@ import {
Packages,
InvalidMonorepoError,
} from "./Tool";
import { expandPackageGlobs } from "./expandPackageGlobs";
import { readJson, readJsonSync } from "./utils";

export const RootTool: Tool = {
type: "root",
Expand All @@ -27,9 +26,7 @@ export const RootTool: Tool = {
const rootDir = path.resolve(directory);

try {
const pkgJson: PackageJSON = await fs.readJson(
path.join(rootDir, "package.json")
);
const pkgJson = await readJson(rootDir, "package.json") as PackageJSON;
const pkg: Package = {
dir: rootDir,
relativeDir: ".",
Expand All @@ -56,9 +53,7 @@ export const RootTool: Tool = {
const rootDir = path.resolve(directory);

try {
const pkgJson: PackageJSON = fs.readJsonSync(
path.join(rootDir, "package.json")
);
const pkgJson = readJsonSync(rootDir, "package.json") as PackageJSON;
const pkg: Package = {
dir: rootDir,
relativeDir: ".",
Expand Down
16 changes: 7 additions & 9 deletions packages/tools/src/RushTool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from "path";
import fs from "fs-extra";
import fs from "fs";
import fsp from "fs/promises";
import jju from "jju";

import {
Expand All @@ -9,6 +10,7 @@ import {
Packages,
InvalidMonorepoError,
} from "./Tool";
import { readJson, readJsonSync } from "./utils";

interface RushJson {
projects: RushProject[];
Expand All @@ -24,15 +26,14 @@ export const RushTool: Tool = {

async isMonorepoRoot(directory: string): Promise<boolean> {
try {
await fs.readFile(path.join(directory, "rush.json"), "utf8");
await fsp.readFile(path.join(directory, "rush.json"), "utf8");
return true;
} catch (err) {
if (err && (err as { code: string }).code === "ENOENT") {
return false;
}
throw err;
}
return false;
},

isMonorepoRootSync(directory: string): boolean {
Expand All @@ -45,14 +46,13 @@ export const RushTool: Tool = {
}
throw err;
}
return false;
},

async getPackages(directory: string): Promise<Packages> {
const rootDir = path.resolve(directory);

try {
const rushText: string = await fs.readFile(
const rushText: string = await fsp.readFile(
path.join(rootDir, "rush.json"),
"utf8"
);
Expand All @@ -69,7 +69,7 @@ export const RushTool: Tool = {
return {
dir,
relativeDir: path.relative(directory, dir),
packageJson: await fs.readJson(path.join(dir, "package.json")),
packageJson: await readJson(dir, "package.json"),
};
})
);
Expand Down Expand Up @@ -107,9 +107,7 @@ export const RushTool: Tool = {
path.resolve(rootDir, project.projectFolder)
);
const packages: Package[] = directories.map((dir: string) => {
const packageJson: PackageJSON = fs.readJsonSync(
path.join(dir, "package.json")
);
const packageJson: PackageJSON = readJsonSync(dir, "package.json");
return {
dir,
relativeDir: path.relative(directory, dir),
Expand Down
19 changes: 5 additions & 14 deletions packages/tools/src/YarnTool.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import path from "path";
import fs from "fs-extra";

import {
Tool,
Package,
PackageJSON,
Packages,
InvalidMonorepoError,
Expand All @@ -12,6 +10,7 @@ import {
expandPackageGlobs,
expandPackageGlobsSync,
} from "./expandPackageGlobs";
import { readJson, readJsonSync } from "./utils";

export interface YarnPackageJSON extends PackageJSON {
workspaces?: string[] | { packages: string[] };
Expand All @@ -22,9 +21,7 @@ export const YarnTool: Tool = {

async isMonorepoRoot(directory: string): Promise<boolean> {
try {
const pkgJson = (await fs.readJson(
path.join(directory, "package.json")
)) as YarnPackageJSON;
const pkgJson = await readJson(directory, "package.json") as YarnPackageJSON;
if (pkgJson.workspaces) {
if (
Array.isArray(pkgJson.workspaces) ||
Expand All @@ -44,9 +41,7 @@ export const YarnTool: Tool = {

isMonorepoRootSync(directory: string): boolean {
try {
const pkgJson = fs.readJsonSync(
path.join(directory, "package.json")
) as YarnPackageJSON;
const pkgJson = readJsonSync(directory, "package.json") as YarnPackageJSON;
if (pkgJson.workspaces) {
if (
Array.isArray(pkgJson.workspaces) ||
Expand All @@ -68,9 +63,7 @@ export const YarnTool: Tool = {
const rootDir = path.resolve(directory);

try {
const pkgJson = (await fs.readJson(
path.join(rootDir, "package.json")
)) as YarnPackageJSON;
const pkgJson = await readJson(rootDir, "package.json") as YarnPackageJSON;
const packageGlobs: string[] = Array.isArray(pkgJson.workspaces)
? pkgJson.workspaces
: pkgJson.workspaces!.packages;
Expand Down Expand Up @@ -99,9 +92,7 @@ export const YarnTool: Tool = {
const rootDir = path.resolve(directory);

try {
const pkgJson = fs.readJsonSync(
path.join(rootDir, "package.json")
) as YarnPackageJSON;
const pkgJson = readJsonSync(rootDir, "package.json") as YarnPackageJSON;
const packageGlobs: string[] = Array.isArray(pkgJson.workspaces)
? pkgJson.workspaces
: pkgJson.workspaces!.packages;
Expand Down
Loading

0 comments on commit c0a5e5d

Please sign in to comment.