Skip to content

Commit 9c45e72

Browse files
zkochanclaude
andcommitted
fix(pnpm): restore workspace-sibling deps on injected component instances
The engine hands the readPackage hook a workspace project's importer manifest when it resolves that project as an injected "file:" dependency. That manifest was already stripped of workspace-sibling deps by the up-front with-dir transform (Bit wires siblings itself inside importers), so the injected instance lost its component deps — and with them the component graph edges recorded at tag time (the deps-graph e2e "should replace pending version in direct dependency" cluster). The next @pnpm/napi release passes the lockfile-root-relative directory of a directory resolution as the hook's second argument; use it to substitute the project's raw manifest for its dependency instances, mirroring how pnpm's TS engine applies the hook chain contextually to raw project manifests. With the current binding the argument is simply absent and behavior is unchanged. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 0a5e620 commit 9c45e72

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

‎scopes/dependencies/pnpm/lynx.ts‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { join } from 'path';
12
import semver from 'semver';
23
import parsePackageName from 'parse-package-name';
34
import { initDefaultReporter } from '@pnpm/cli.default-reporter';
@@ -318,8 +319,21 @@ export async function install(
318319
dir
319320
) as unknown as nodeApi.PackageManifest,
320321
}));
321-
const readPackageHookForDeps = (manifest: nodeApi.PackageManifest): nodeApi.PackageManifest =>
322-
applyReadPackageHooks(hooks, manifest as unknown as PackageManifest) as unknown as nodeApi.PackageManifest;
322+
// When the engine resolves a workspace project as a dependency (an injected
323+
// "file:" instance), it hands the hook that project's importer manifest —
324+
// which the up-front transform above already stripped of workspace-sibling
325+
// deps. The instance must keep those deps (they become the component's graph
326+
// edges), so substitute the project's raw manifest, identified by the
327+
// lockfile-root-relative directory the engine passes for directory
328+
// resolutions. pnpm's TS engine reaches the same split by keeping raw
329+
// project manifests and applying the hook chain contextually.
330+
const readPackageHookForDeps = (manifest: nodeApi.PackageManifest, resolvedDir?: string): nodeApi.PackageManifest => {
331+
const rawManifest = resolvedDir ? manifestsByPaths[join(rootDir, resolvedDir)] : undefined;
332+
return applyReadPackageHooks(
333+
hooks,
334+
(rawManifest ?? manifest) as unknown as PackageManifest
335+
) as unknown as nodeApi.PackageManifest;
336+
};
323337

324338
const scriptPolicies = resolveScriptPolicies({
325339
allowScripts: options.allowScripts,
@@ -410,7 +424,14 @@ export async function install(
410424
// survived). Capture it up front and re-assert it after the
411425
// install alongside `depsRequiringBuild`.
412426
const preInstallBitAttrs = await readBitLockfileAttrs(rootDir);
413-
installsRunning[rootDir] = nodeApi.install(installOptions, onLog, readPackageHookForDeps);
427+
// The extra `resolvedDir` param lands in `@pnpm/napi`'s ReadPackageHook
428+
// type in the release that ships the directory-resolution context; the
429+
// cast bridges the older published typing.
430+
installsRunning[rootDir] = nodeApi.install(
431+
installOptions,
432+
onLog,
433+
readPackageHookForDeps as unknown as nodeApi.ReadPackageHook
434+
);
414435
const installResult: nodeApi.InstallResult = await installsRunning[rootDir];
415436
resolvedStoreDir = installResult.storeDir;
416437
const sortedDepsRequiringBuild = installResult.depsRequiringBuild?.sort();

0 commit comments

Comments
 (0)