Skip to content

Commit 0a84e7d

Browse files
committed
feat: Added support for monorepo by considering the relative path to the package.json itself instead of the workspace itself
1 parent f951f3a commit 0a84e7d

File tree

5 files changed

+7
-16
lines changed

5 files changed

+7
-16
lines changed

src/Diagnostic.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { sep } from "node:path"
1+
import { dirname, sep } from "node:path"
22
import {
33
intersects,
44
maxSatisfying,
@@ -44,7 +44,6 @@ import {
4444
} from "./Settings"
4545
import { Icons } from "./Theme"
4646
import { promiseLimit } from "./Utils"
47-
import { getWorkspacePath } from "./Workspace"
4847

4948
const isPackageJsonDocument = (document: TextDocument): boolean =>
5049
document.fileName.endsWith(`${sep}package.json`)
@@ -85,7 +84,7 @@ export const diagnosticSubscribe = (
8584
// Trigger when any file in the workspace is modified.
8685
// Our interest here is to know about the package.json itself, package-lock.json or pnpm-lock.yaml.
8786
const lockerUpdated = (uri: Uri): void => {
88-
const workspacePath = getWorkspacePath(uri)
87+
const workspacePath = dirname(uri.fsPath)
8988

9089
packageManagerCaches.get(workspacePath)?.invalidate()
9190
packagesInstalledCaches.get(workspacePath)?.invalidate()

src/PackageManager.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { exec } from "node:child_process"
22
import { existsSync } from "node:fs"
3+
import { dirname } from "node:path"
34
import { prerelease } from "semver"
45
import { TextDocument } from "vscode"
56
import { Cache } from "./Cache"
67
import { PackageInfo } from "./PackageInfo"
78
import { getCacheLifetime } from "./Settings"
89
import { cacheEnabled, fetchLite } from "./Utils"
9-
import { getWorkspacePath } from "./Workspace"
1010

1111
const PACKAGE_VERSION_REGEXP = /^\d+\.\d+\.\d+$/
1212

@@ -99,7 +99,7 @@ const supportsPackageManager = async (
9999
return
100100
}
101101

102-
const cwd = getWorkspacePath(document.uri)
102+
const cwd = dirname(document.uri.fsPath)
103103

104104
exec(`${cmd} --version`, { cwd }, (error, stdout) => {
105105
const isInstalled =
@@ -121,7 +121,7 @@ export const packageManagerCaches = new Map<
121121
export const getPackageManager = async (
122122
document: TextDocument,
123123
): Promise<PackageManager> => {
124-
const cwd = getWorkspacePath(document.uri)
124+
const cwd = dirname(document.uri.fsPath)
125125

126126
if (cacheEnabled()) {
127127
const packageManagerCache = packageManagerCaches.get(cwd)
@@ -194,7 +194,7 @@ export const packagesInstalledCaches = new Map<
194194
export const getPackagesInstalled = async (
195195
document: TextDocument,
196196
): Promise<PackagesInstalled | undefined> => {
197-
const cwd = getWorkspacePath(document.uri)
197+
const cwd = dirname(document.uri.fsPath)
198198

199199
if (cacheEnabled()) {
200200
const cache = packagesInstalledCaches.get(cwd)

src/TestUtils.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,6 @@ export const vscodeSimulator = async (options: SimulatorOptions = {}) => {
366366
),
367367
})
368368

369-
vscodeMock.workspace.getWorkspaceFolder = (): unknown => ({
370-
uri: { fsPath: "<root>/" },
371-
})
372-
373369
vscodeMock.languages.createDiagnosticCollection = jest.fn(() => ({
374370
clear: jest.fn(),
375371
delete: jest.fn(),

src/Workspace.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/extension.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ describe("code coverage", () => {
710710

711711
subscriptions.find(
712712
(subscription) => subscription[0] === "onDidChange",
713-
)?.[1]()
713+
)?.[1]({ fsPath: "/repo/package.json" })
714714

715715
expect(diagnostics).toHaveLength(0)
716716
expect(decorations).toStrictEqual([])

0 commit comments

Comments
 (0)