Skip to content

Commit

Permalink
fix(nxls): track timestamp when getting pnp api
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKless committed Apr 11, 2024
1 parent a8e1804 commit 54ce3d0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion libs/shared/npm/src/lib/pnp-dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { PnpApi } from '@yarnpkg/pnp';
import { join } from 'path';
import { fileExists } from '@nx-console/shared/file-system';
import { statSync } from 'fs';

let PNP_API: PnpApi;
let lastPnpFileTimestamp: number;

async function getPnpFile(workspacePath: string) {
const extensions = ['.cjs', '.js'];
Expand All @@ -24,12 +26,14 @@ async function pnpApi(workspacePath: string) {
if (!pnpFile) {
return;
}
const currentPnpFileTimestamp = statSync(pnpFile)?.mtimeMs;

if (!PNP_API) {
if (!PNP_API || currentPnpFileTimestamp !== lastPnpFileTimestamp) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pnp = require(pnpFile);
pnp.setup();
PNP_API = pnp;
lastPnpFileTimestamp = statSync(pnpFile)?.mtimeMs;
}

return PNP_API;
Expand Down

0 comments on commit 54ce3d0

Please sign in to comment.