Skip to content

Commit fbddf2b

Browse files
authored
Merge pull request #21 from mukaschultze/master
2 parents 8efd6c1 + 1e851c5 commit fbddf2b

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

src/getAppRootPath.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { join, resolve } from "./path"
2-
import process from "process"
32
import { existsSync } from "fs-extra"
3+
import { realpathCwd } from "./realpathCwd"
44

55
export const getAppRootPath = (): string => {
6-
let cwd = process.cwd()
6+
let cwd = realpathCwd().replace(/\\/g, "/")
77
while (!existsSync(join(cwd, "package.json"))) {
8-
const up = resolve(cwd, "../")
8+
const up = resolve(cwd, "../").replace(/\\/g, "/")
99
if (up === cwd) {
1010
throw new Error("no package.json found for this project")
1111
}

src/getPackageResolution.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { readFileSync, existsSync } from "fs-extra"
55
import { parse as parseYarnLockFile } from "@yarnpkg/lockfile"
66
import findYarnWorkspaceRoot from "find-yarn-workspace-root"
77
import { getPackageVersion } from "./getPackageVersion"
8+
import { realpathCwd } from "./realpathCwd"
89
//import { execSync } from "child_process"
910

1011
//const isVerbose = global.patchPackageIsVerbose
@@ -261,9 +262,9 @@ if (require.main === module) {
261262
}
262263
console.log(
263264
getPackageResolution({
264-
appPath: process.cwd(),
265+
appPath: realpathCwd(),
265266
packageDetails,
266-
packageManager: detectPackageManager(process.cwd(), null),
267+
packageManager: detectPackageManager(realpathCwd(), null),
267268
appPackageJson: {}, // TODO?
268269
}),
269270
)

src/patch/read.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const removeAnsiCodes = (s: string) =>
77
"",
88
)
99

10+
jest.mock("fs", () => ({
11+
realpathSync: jest.fn((path)=>path),
12+
}))
1013
jest.mock("fs-extra", () => ({
1114
readFileSync: jest.fn(),
1215
}))

src/patch/read.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { relative, resolve } from "../path"
44
import { normalize } from "path"
55
import { PackageDetails } from "../PackageDetails"
66
import { parsePatchFile, PatchFilePart } from "./parse"
7+
import { realpathCwd } from "../realpathCwd"
78

89
export function readPatch({
910
patchFilePath,
@@ -19,7 +20,7 @@ export function readPatch({
1920
} catch (e) {
2021
const fixupSteps: string[] = []
2122
const relativePatchFilePath = normalize(
22-
relative(process.cwd(), patchFilePath),
23+
relative(realpathCwd(), patchFilePath),
2324
)
2425
const patchBaseDir = relativePatchFilePath.slice(
2526
0,
@@ -36,7 +37,7 @@ export function readPatch({
3637
fixupSteps.push(`npx patch-package ${packageDetails.pathSpecifier}`)
3738
if (patchBaseDir) {
3839
fixupSteps.push(
39-
`cd ${relative(resolve(process.cwd(), patchBaseDir), process.cwd())}`,
40+
`cd ${relative(resolve(realpathCwd(), patchBaseDir), realpathCwd())}`,
4041
)
4142
}
4243

src/realpathCwd.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import fs from "fs"
2+
import process from "process"
3+
4+
export const realpathCwd = (): string => {
5+
return fs.realpathSync(process.cwd())
6+
}

0 commit comments

Comments
 (0)