Skip to content

Commit 9c1bcc8

Browse files
authored
fix(pnp): report missing files in watch mode (#5132)
1 parent 0aadf4f commit 9c1bcc8

File tree

11 files changed

+96
-41
lines changed

11 files changed

+96
-41
lines changed

.pnp.cjs

Lines changed: 16 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.pnp.loader.mjs

Lines changed: 12 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.yarn/versions/371a1b00.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/plugin-pnp": patch
4+
"@yarnpkg/pnp": patch
5+
6+
declined:
7+
- "@yarnpkg/plugin-compat"
8+
- "@yarnpkg/plugin-constraints"
9+
- "@yarnpkg/plugin-dlx"
10+
- "@yarnpkg/plugin-essentials"
11+
- "@yarnpkg/plugin-init"
12+
- "@yarnpkg/plugin-interactive-tools"
13+
- "@yarnpkg/plugin-nm"
14+
- "@yarnpkg/plugin-npm-cli"
15+
- "@yarnpkg/plugin-pack"
16+
- "@yarnpkg/plugin-patch"
17+
- "@yarnpkg/plugin-pnpm"
18+
- "@yarnpkg/plugin-stage"
19+
- "@yarnpkg/plugin-typescript"
20+
- "@yarnpkg/plugin-version"
21+
- "@yarnpkg/plugin-workspace-tools"
22+
- "@yarnpkg/builder"
23+
- "@yarnpkg/core"
24+
- "@yarnpkg/doctor"
25+
- "@yarnpkg/nm"
26+
- "@yarnpkg/pnpify"
27+
- "@yarnpkg/sdks"

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ The following changes only affect people writing Yarn plugins:
8080

8181
- Updates the PnP compatibility layer for TypeScript v4.9.4.
8282
- The patched filesystem now supports `FileHandle.readLines`.
83+
- PnP now reports missing files when in watch mode.
8384

8485
## 3.3.0
8586

packages/yarnpkg-pnp/sources/esm-loader/built-loader.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/yarnpkg-pnp/sources/esm-loader/hooks/load.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {VirtualFS, npath} from '@yarnpkg/fslib';
2-
import fs from 'fs';
3-
import {fileURLToPath, pathToFileURL} from 'url';
1+
import {VirtualFS, npath} from '@yarnpkg/fslib';
2+
import fs from 'fs';
3+
import {fileURLToPath, pathToFileURL} from 'url';
44

5-
import {HAS_JSON_IMPORT_ASSERTION_REQUIREMENT} from '../loaderFlags';
6-
import * as loaderUtils from '../loaderUtils';
5+
import {HAS_JSON_IMPORT_ASSERTION_REQUIREMENT, WATCH_MODE_MESSAGE_USES_ARRAYS} from '../loaderFlags';
6+
import * as loaderUtils from '../loaderUtils';
77

88
// The default `load` doesn't support reading from zip files
99
export async function load(
@@ -37,12 +37,13 @@ export async function load(
3737
// At the time of writing Node.js reports all loaded URLs itself so
3838
// we technically only need to do this for virtual files but in the
3939
// event that ever changes we report everything.
40+
const pathToSend = pathToFileURL(
41+
npath.fromPortablePath(
42+
VirtualFS.resolveVirtual(npath.toPortablePath(filePath)),
43+
),
44+
).href;
4045
process.send({
41-
'watch:import': pathToFileURL(
42-
npath.fromPortablePath(
43-
VirtualFS.resolveVirtual(npath.toPortablePath(filePath)),
44-
),
45-
).href,
46+
'watch:import': WATCH_MODE_MESSAGE_USES_ARRAYS ? [pathToSend] : pathToSend,
4647
});
4748
}
4849

packages/yarnpkg-pnp/sources/esm-loader/loaderFlags.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ export const HAS_UNFLAGGED_JSON_MODULES = major > 17 || (major === 17 && minor >
88

99
// JSON modules requires import assertions after https://github.com/nodejs/node/pull/40250
1010
export const HAS_JSON_IMPORT_ASSERTION_REQUIREMENT = major > 17 || (major === 17 && minor >= 1) || (major === 16 && minor > 14);
11+
12+
// The message switched to using an array in https://github.com/nodejs/node/pull/45348
13+
export const WATCH_MODE_MESSAGE_USES_ARRAYS = major > 19 || (major === 19 && minor >= 2);

packages/yarnpkg-pnp/sources/hook.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/yarnpkg-pnp/sources/loader/applyPatch.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ declare global {
2727
}
2828
}
2929

30-
// https://github.com/nodejs/node/pull/44366
31-
const shouldReportRequiredModules = process.env.WATCH_REPORT_DEPENDENCIES;
32-
function reportModuleToWatchMode(filename: NativePath) {
33-
if (shouldReportRequiredModules && process.send) {
34-
process.send({'watch:require': npath.fromPortablePath(VirtualFS.resolveVirtual(npath.toPortablePath(filename)))});
35-
}
36-
}
37-
3830
export function applyPatch(pnpapi: PnpApi, opts: ApplyPatchOptions) {
3931
/**
4032
* The cache that will be used for all accesses occurring outside of a PnP context.
@@ -175,7 +167,7 @@ export function applyPatch(pnpapi: PnpApi, opts: ApplyPatchOptions) {
175167
const module = new Module(modulePath, parent ?? undefined) as PatchedModule;
176168
module.pnpApiPath = moduleApiPath;
177169

178-
reportModuleToWatchMode(modulePath);
170+
nodeUtils.reportRequiredFilesToWatchMode([modulePath]);
179171

180172
entry.cache[modulePath] = module;
181173

packages/yarnpkg-pnp/sources/loader/makeApi.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,8 @@ export function makeApi(runtimeState: RuntimeState, opts: MakeApiOptions): PnpAp
830830
if (qualifiedPath) {
831831
return ppath.normalize(qualifiedPath);
832832
} else {
833+
nodeUtils.reportRequiredFilesToWatchMode(candidates.map(candidate => npath.fromPortablePath(candidate)));
834+
833835
const unqualifiedPathForDisplay = getPathForDisplay(unqualifiedPath);
834836

835837
const containingPackage = findPackageLocator(unqualifiedPath);

0 commit comments

Comments
 (0)