Skip to content

Commit 8f26944

Browse files
committed
fix: revert back some fs-extra changes
1 parent 679ce95 commit 8f26944

7 files changed

+35
-26
lines changed

Diff for: src/applyPatches.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { existsSync, writeFileSync } from "fs"
1+
import { existsSync, writeFileSync } from "fs-extra"
22
import { posix } from "path"
33
import { blue, bold, cyan, green, red, yellow } from "picocolors"
44
import semver from "semver"

Diff for: src/detectPackageManager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import findWorkspaceRoot from "find-yarn-workspace-root"
2-
import fs from "fs"
2+
import fs from "fs-extra"
33
import { bold, red } from "picocolors"
44
import process from "process"
55
import { join } from "./path"

Diff for: src/getAppRootPath.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { join, resolve } from "./path"
1+
import { existsSync } from "fs-extra"
22
import process from "process"
3-
import { existsSync } from "fs"
3+
import { join, resolve } from "./path"
44

55
export const getAppRootPath = (): string => {
66
let cwd = process.cwd()

Diff for: src/getPackageResolution.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { join, resolve } from "./path"
2-
import { PackageDetails, getPatchDetailsFromCliString } from "./PackageDetails"
3-
import { PackageManager, detectPackageManager } from "./detectPackageManager"
4-
import { readFileSync, existsSync } from "fs"
51
import { parse as parseYarnLockFile } from "@yarnpkg/lockfile"
6-
import yaml from "yaml"
72
import findWorkspaceRoot from "find-yarn-workspace-root"
8-
import { getPackageVersion } from "./getPackageVersion"
3+
import { existsSync, readFileSync } from "fs-extra"
4+
import yaml from "yaml"
5+
import { PackageDetails, getPatchDetailsFromCliString } from "./PackageDetails"
96
import { coerceSemVer } from "./coerceSemVer"
7+
import { PackageManager, detectPackageManager } from "./detectPackageManager"
8+
import { getPackageVersion } from "./getPackageVersion"
9+
import { join, resolve } from "./path"
1010

1111
export function getPackageResolution({
1212
packageDetails,

Diff for: src/makePatch.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import console from "console"
12
import {
23
copySync,
34
existsSync,

Diff for: src/patch/apply.ts

+23-15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
import fs from "fs"
2-
import fse from "fs-extra"
1+
import {
2+
chmodSync,
3+
ensureDirSync,
4+
existsSync,
5+
moveSync,
6+
readFileSync,
7+
statSync,
8+
unlinkSync,
9+
writeFileSync,
10+
} from "fs-extra"
311
import { dirname, join, relative, resolve } from "path"
4-
import { ParsedPatchFile, FilePatch, Hunk } from "./parse"
512
import { assertNever } from "../assertNever"
13+
import { FilePatch, Hunk, ParsedPatchFile } from "./parse"
614

715
export const executeEffects = (
816
effects: ParsedPatchFile,
@@ -19,7 +27,7 @@ export const executeEffects = (
1927
switch (eff.type) {
2028
case "file deletion":
2129
if (dryRun) {
22-
if (!fs.existsSync(inCwd(eff.path))) {
30+
if (!existsSync(inCwd(eff.path))) {
2331
throw new Error(
2432
"Trying to delete file that doesn't exist: " +
2533
humanReadable(eff.path),
@@ -28,7 +36,7 @@ export const executeEffects = (
2836
} else {
2937
// TODO: integrity checks
3038
try {
31-
fs.unlinkSync(inCwd(eff.path))
39+
unlinkSync(inCwd(eff.path))
3240
} catch (e) {
3341
if (bestEffort) {
3442
errors?.push(`Failed to delete file ${eff.path}`)
@@ -41,15 +49,15 @@ export const executeEffects = (
4149
case "rename":
4250
if (dryRun) {
4351
// TODO: see what patch files look like if moving to exising path
44-
if (!fs.existsSync(inCwd(eff.fromPath))) {
52+
if (!existsSync(inCwd(eff.fromPath))) {
4553
throw new Error(
4654
"Trying to move file that doesn't exist: " +
4755
humanReadable(eff.fromPath),
4856
)
4957
}
5058
} else {
5159
try {
52-
fse.moveSync(inCwd(eff.fromPath), inCwd(eff.toPath))
60+
moveSync(inCwd(eff.fromPath), inCwd(eff.toPath))
5361
} catch (e) {
5462
if (bestEffort) {
5563
errors?.push(
@@ -63,7 +71,7 @@ export const executeEffects = (
6371
break
6472
case "file creation":
6573
if (dryRun) {
66-
if (fs.existsSync(inCwd(eff.path))) {
74+
if (existsSync(inCwd(eff.path))) {
6775
throw new Error(
6876
"Trying to create file that already exists: " +
6977
humanReadable(eff.path),
@@ -77,8 +85,8 @@ export const executeEffects = (
7785
: ""
7886
const path = inCwd(eff.path)
7987
try {
80-
fse.ensureDirSync(dirname(path))
81-
fs.writeFileSync(path, fileContents, { mode: eff.mode })
88+
ensureDirSync(dirname(path))
89+
writeFileSync(path, fileContents, { mode: eff.mode })
8290
} catch (e) {
8391
if (bestEffort) {
8492
errors?.push(`Failed to create new file ${eff.path}`)
@@ -92,7 +100,7 @@ export const executeEffects = (
92100
applyPatch(eff, { dryRun, cwd, bestEffort, errors })
93101
break
94102
case "mode change":
95-
const currentMode = fs.statSync(inCwd(eff.path)).mode
103+
const currentMode = statSync(inCwd(eff.path)).mode
96104
if (
97105
((isExecutable(eff.newMode) && isExecutable(currentMode)) ||
98106
(!isExecutable(eff.newMode) && !isExecutable(currentMode))) &&
@@ -102,7 +110,7 @@ export const executeEffects = (
102110
`Mode change is not required for file ${humanReadable(eff.path)}`,
103111
)
104112
}
105-
fs.chmodSync(inCwd(eff.path), eff.newMode)
113+
chmodSync(inCwd(eff.path), eff.newMode)
106114
break
107115
default:
108116
assertNever(eff)
@@ -153,8 +161,8 @@ function applyPatch(
153161
): void {
154162
path = cwd ? resolve(cwd, path) : path
155163
// modifying the file in place
156-
const fileContents = fs.readFileSync(path).toString()
157-
const mode = fs.statSync(path).mode
164+
const fileContents = readFileSync(path).toString()
165+
const mode = statSync(path).mode
158166

159167
const fileLines: string[] = fileContents.split(/\n/)
160168

@@ -220,7 +228,7 @@ function applyPatch(
220228
}
221229

222230
try {
223-
fs.writeFileSync(path, fileLines.join("\n"), { mode })
231+
writeFileSync(path, fileLines.join("\n"), { mode })
224232
} catch (e) {
225233
if (bestEffort) {
226234
errors?.push(`Failed to write file ${path}`)

Diff for: src/patch/read.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readFileSync } from "fs"
1+
import { readFileSync } from "fs-extra"
22
import { normalize } from "path"
33
import { bold, red } from "picocolors"
44
import { PackageDetails } from "../PackageDetails"

0 commit comments

Comments
 (0)