@@ -10,7 +10,7 @@ import { pick } from "remeda";
1010import { useConfig } from "~/lib/config" ;
1111import { useLogger } from "~/lib/logger" ;
1212import type { PackageManifest , PackagesRegistry } from "~/lib/types" ;
13- import { getErrorMessage } from "~/lib/utils" ;
13+ import { getErrorMessage , isRushWorkspace } from "~/lib/utils" ;
1414import { pnpmMapImporter } from "./pnpm-map-importer" ;
1515
1616export async function generatePnpmLockfile ( {
@@ -34,9 +34,16 @@ export async function generatePnpmLockfile({
3434 log . info ( "Generating PNPM lockfile..." ) ;
3535
3636 try {
37- const lockfile = await readWantedLockfile ( workspaceRootDir , {
38- ignoreIncompatible : false ,
39- } ) ;
37+ const isRush = isRushWorkspace ( workspaceRootDir ) ;
38+
39+ const lockfile = await readWantedLockfile (
40+ isRush
41+ ? path . join ( workspaceRootDir , "common/config/rush" )
42+ : workspaceRootDir ,
43+ {
44+ ignoreIncompatible : false ,
45+ }
46+ ) ;
4047
4148 assert ( lockfile , `No input lockfile found at ${ workspaceRootDir } ` ) ;
4249
@@ -49,6 +56,8 @@ export async function generatePnpmLockfile({
4956 internalDepPackageNames . map ( ( name ) => {
5057 const pkg = packagesRegistry [ name ] ;
5158 assert ( pkg , `Package ${ name } not found in packages registry` ) ;
59+
60+ console . log ( "pkg.rootRelativeDir" , pkg . rootRelativeDir ) ;
5261 return [ name , pkg . rootRelativeDir ] ;
5362 } )
5463 ) ;
@@ -64,34 +73,48 @@ export async function generatePnpmLockfile({
6473
6574 log . debug ( "Relevant importer ids:" , relevantImporterIds ) ;
6675
76+ /**
77+ * In a Rush workspace the original lockfile is not in the root, so the
78+ * importerIds have to be prefixed with `../../`, but that's not how they
79+ * should be stored in the isolated lockfile, so we use the prefixed ids
80+ * only for parsing.
81+ */
82+ const relevantImporterIdsWithPrefix = relevantImporterIds . map ( ( x ) =>
83+ isRush ? `../../${ x } ` : x
84+ ) ;
85+
6786 lockfile . importers = Object . fromEntries (
68- Object . entries ( pick ( lockfile . importers , relevantImporterIds ) ) . map (
69- ( [ importerId , importer ] ) => {
70- if ( importerId === targetImporterId ) {
71- log . debug ( "Setting target package importer on root" ) ;
72-
73- return [
74- "." ,
75- pnpmMapImporter ( importer , {
76- includeDevDependencies,
77- includePatchedDependencies,
78- directoryByPackageName,
79- } ) ,
80- ] ;
81- }
82-
83- log . debug ( "Setting internal package importer:" , importerId ) ;
87+ Object . entries (
88+ pick ( lockfile . importers , relevantImporterIdsWithPrefix )
89+ ) . map ( ( [ prefixedImporterId , importer ] ) => {
90+ const importerId = isRush
91+ ? prefixedImporterId . replace ( "../../" , "" )
92+ : prefixedImporterId ;
93+
94+ if ( importerId === targetImporterId ) {
95+ log . debug ( "Setting target package importer on root" ) ;
8496
8597 return [
86- importerId ,
98+ "." ,
8799 pnpmMapImporter ( importer , {
88100 includeDevDependencies,
89101 includePatchedDependencies,
90102 directoryByPackageName,
91103 } ) ,
92104 ] ;
93105 }
94- )
106+
107+ log . debug ( "Setting internal package importer:" , importerId ) ;
108+
109+ return [
110+ importerId ,
111+ pnpmMapImporter ( importer , {
112+ includeDevDependencies,
113+ includePatchedDependencies,
114+ directoryByPackageName,
115+ } ) ,
116+ ] ;
117+ } )
95118 ) ;
96119
97120 log . debug ( "Pruning the lockfile" ) ;
0 commit comments