@@ -10,7 +10,7 @@ import { pick } from "remeda";
10
10
import { useConfig } from "~/lib/config" ;
11
11
import { useLogger } from "~/lib/logger" ;
12
12
import type { PackageManifest , PackagesRegistry } from "~/lib/types" ;
13
- import { getErrorMessage } from "~/lib/utils" ;
13
+ import { getErrorMessage , isRushWorkspace } from "~/lib/utils" ;
14
14
import { pnpmMapImporter } from "./pnpm-map-importer" ;
15
15
16
16
export async function generatePnpmLockfile ( {
@@ -34,9 +34,16 @@ export async function generatePnpmLockfile({
34
34
log . info ( "Generating PNPM lockfile..." ) ;
35
35
36
36
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
+ ) ;
40
47
41
48
assert ( lockfile , `No input lockfile found at ${ workspaceRootDir } ` ) ;
42
49
@@ -49,6 +56,8 @@ export async function generatePnpmLockfile({
49
56
internalDepPackageNames . map ( ( name ) => {
50
57
const pkg = packagesRegistry [ name ] ;
51
58
assert ( pkg , `Package ${ name } not found in packages registry` ) ;
59
+
60
+ console . log ( "pkg.rootRelativeDir" , pkg . rootRelativeDir ) ;
52
61
return [ name , pkg . rootRelativeDir ] ;
53
62
} )
54
63
) ;
@@ -64,34 +73,48 @@ export async function generatePnpmLockfile({
64
73
65
74
log . debug ( "Relevant importer ids:" , relevantImporterIds ) ;
66
75
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
+
67
86
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" ) ;
84
96
85
97
return [
86
- importerId ,
98
+ "." ,
87
99
pnpmMapImporter ( importer , {
88
100
includeDevDependencies,
89
101
includePatchedDependencies,
90
102
directoryByPackageName,
91
103
} ) ,
92
104
] ;
93
105
}
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
+ } )
95
118
) ;
96
119
97
120
log . debug ( "Pruning the lockfile" ) ;
0 commit comments