Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: follow cwd symlink on windows #410

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/getAppRootPath.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { join, resolve } from "./path"
import process from "process"
import { existsSync } from "fs-extra"
import { realpathCwd } from "./realpathCwd"

export const getAppRootPath = (): string => {
let cwd = process.cwd()
let cwd = realpathCwd().replace("\\", "/")
while (!existsSync(join(cwd, "package.json"))) {
const up = resolve(cwd, "../")
const up = resolve(cwd, "../").replace("\\", "/")
if (up === cwd) {
throw new Error("no package.json found for this project")
}
Expand Down
3 changes: 2 additions & 1 deletion src/getPackageResolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { readFileSync, existsSync } from "fs-extra"
import { parse as parseYarnLockFile } from "@yarnpkg/lockfile"
import findWorkspaceRoot from "find-yarn-workspace-root"
import { getPackageVersion } from "./getPackageVersion"
import { realpathCwd } from "./realpathCwd"

export function getPackageResolution({
packageDetails,
Expand Down Expand Up @@ -104,7 +105,7 @@ if (require.main === module) {
}
console.log(
getPackageResolution({
appPath: process.cwd(),
appPath: realpathCwd(),
packageDetails,
packageManager: detectPackageManager(process.cwd(), null),
}),
Expand Down
3 changes: 3 additions & 0 deletions src/patch/read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const removeAnsiCodes = (s: string) =>
"",
)

jest.mock("fs", () => ({
realpathSync: jest.fn((path)=>path),
}))
jest.mock("fs-extra", () => ({
readFileSync: jest.fn(),
}))
Expand Down
5 changes: 3 additions & 2 deletions src/patch/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { relative, resolve } from "../path"
import { normalize } from "path"
import { PackageDetails } from "../PackageDetails"
import { parsePatchFile, PatchFilePart } from "./parse"
import { realpathCwd } from "../realpathCwd"

export function readPatch({
patchFilePath,
Expand All @@ -19,7 +20,7 @@ export function readPatch({
} catch (e) {
const fixupSteps: string[] = []
const relativePatchFilePath = normalize(
relative(process.cwd(), patchFilePath),
relative(realpathCwd(), patchFilePath),
)
const patchBaseDir = relativePatchFilePath.slice(
0,
Expand All @@ -36,7 +37,7 @@ export function readPatch({
fixupSteps.push(`npx patch-package ${packageDetails.pathSpecifier}`)
if (patchBaseDir) {
fixupSteps.push(
`cd ${relative(resolve(process.cwd(), patchBaseDir), process.cwd())}`,
`cd ${relative(resolve(realpathCwd(), patchBaseDir), realpathCwd())}`,
)
}

Expand Down
6 changes: 6 additions & 0 deletions src/realpathCwd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import fs from "fs"
import process from "process"

export const realpathCwd = (): string => {
return fs.realpathSync(process.cwd())
}