@@ -86,6 +86,115 @@ describe('PackageManager', () => {
8686 } ) ;
8787 } ) ;
8888
89+ describe ( 'acquireTempPackage' , ( ) => {
90+ it ( 'should copy and sanitize pnpm-workspace.yaml when package manager is pnpm and workspace file exists' , async ( ) => {
91+ const pnpmDescriptor = SUPPORTED_PACKAGE_MANAGERS [ 'pnpm' ] ;
92+ const testHost = new MockHost ( { '/tmp/project/node_modules' : true } ) ;
93+ const pm = new PackageManager ( testHost , '/tmp/project' , pnpmDescriptor ) ;
94+
95+ const createTempDirectorySpy = spyOn ( testHost , 'createTempDirectory' ) . and . resolveTo (
96+ '/tmp/project/node_modules/angular-cli-tmp-packages-abc' ,
97+ ) ;
98+ const mockWorkspaceContent = [
99+ 'packages:' ,
100+ ' - .' ,
101+ ' - packages/*' ,
102+ 'minimumReleaseAge: 1440' ,
103+ 'minimumReleaseAgeExclude:' ,
104+ " - '@angular/*'" ,
105+ 'overrides:' ,
106+ " '@angular/build': workspace:*" ,
107+ 'packageExtensions:' ,
108+ ' vitest:' ,
109+ ' peerDependencies:' ,
110+ " '@vitest/coverage-v8': '*'" ,
111+ ] . join ( '\n' ) ;
112+ const readFileSpy = spyOn ( testHost , 'readFile' ) . and . resolveTo ( mockWorkspaceContent ) ;
113+ const writeFileSpy = spyOn ( testHost , 'writeFile' ) . and . resolveTo ( ) ;
114+ spyOn ( testHost , 'runCommand' ) . and . resolveTo ( { stdout : '' , stderr : '' } ) ;
115+
116+ const { workingDirectory } = await pm . acquireTempPackage ( 'foo@1.0.0' ) ;
117+
118+ expect ( workingDirectory ) . toBe ( '/tmp/project/node_modules/angular-cli-tmp-packages-abc' ) ;
119+ expect ( createTempDirectorySpy ) . toHaveBeenCalledWith ( '/tmp/project/node_modules' ) ;
120+ expect ( readFileSpy ) . toHaveBeenCalledWith ( '/tmp/project/pnpm-workspace.yaml' ) ;
121+
122+ const expectedSanitizedContent = [
123+ 'packages:' ,
124+ " - '.'" ,
125+ 'minimumReleaseAge: 1440' ,
126+ 'minimumReleaseAgeExclude:' ,
127+ " - '@angular/*'" ,
128+ 'packageExtensions:' ,
129+ ' vitest:' ,
130+ ' peerDependencies:' ,
131+ " '@vitest/coverage-v8': '*'" ,
132+ ] . join ( '\n' ) ;
133+ expect ( writeFileSpy ) . toHaveBeenCalledWith (
134+ '/tmp/project/node_modules/angular-cli-tmp-packages-abc/pnpm-workspace.yaml' ,
135+ expectedSanitizedContent ,
136+ ) ;
137+ expect ( writeFileSpy ) . toHaveBeenCalledWith (
138+ '/tmp/project/node_modules/angular-cli-tmp-packages-abc/package.json' ,
139+ '{}' ,
140+ ) ;
141+ } ) ;
142+
143+ it ( 'should write empty pnpm-workspace.yaml as fallback when package manager is pnpm and workspace file does not exist' , async ( ) => {
144+ const pnpmDescriptor = SUPPORTED_PACKAGE_MANAGERS [ 'pnpm' ] ;
145+ const testHost = new MockHost ( { '/tmp/project/node_modules' : true } ) ;
146+ const pm = new PackageManager ( testHost , '/tmp/project' , pnpmDescriptor ) ;
147+
148+ const createTempDirectorySpy = spyOn ( testHost , 'createTempDirectory' ) . and . resolveTo (
149+ '/tmp/project/node_modules/angular-cli-tmp-packages-abc' ,
150+ ) ;
151+ const readFileSpy = spyOn ( testHost , 'readFile' ) . and . throwError (
152+ new Error ( 'ENOENT: no such file or directory' ) ,
153+ ) ;
154+ const writeFileSpy = spyOn ( testHost , 'writeFile' ) . and . resolveTo ( ) ;
155+ spyOn ( testHost , 'runCommand' ) . and . resolveTo ( { stdout : '' , stderr : '' } ) ;
156+
157+ const { workingDirectory } = await pm . acquireTempPackage ( 'foo@1.0.0' ) ;
158+
159+ expect ( workingDirectory ) . toBe ( '/tmp/project/node_modules/angular-cli-tmp-packages-abc' ) ;
160+ expect ( createTempDirectorySpy ) . toHaveBeenCalledWith ( '/tmp/project/node_modules' ) ;
161+ expect ( readFileSpy ) . toHaveBeenCalledWith ( '/tmp/project/pnpm-workspace.yaml' ) ;
162+ expect ( writeFileSpy ) . toHaveBeenCalledWith (
163+ '/tmp/project/node_modules/angular-cli-tmp-packages-abc/package.json' ,
164+ '{}' ,
165+ ) ;
166+ expect ( writeFileSpy ) . toHaveBeenCalledWith (
167+ '/tmp/project/node_modules/angular-cli-tmp-packages-abc/pnpm-workspace.yaml' ,
168+ "packages:\n - '.'\n" ,
169+ ) ;
170+ } ) ;
171+
172+ it ( 'should NOT write pnpm-workspace.yaml when package manager is npm' , async ( ) => {
173+ const npmDescriptor = SUPPORTED_PACKAGE_MANAGERS [ 'npm' ] ;
174+ const testHost = new MockHost ( { '/tmp/project/node_modules' : true } ) ;
175+ const pm = new PackageManager ( testHost , '/tmp/project' , npmDescriptor ) ;
176+
177+ const createTempDirectorySpy = spyOn ( testHost , 'createTempDirectory' ) . and . resolveTo (
178+ '/tmp/project/node_modules/angular-cli-tmp-packages-abc' ,
179+ ) ;
180+ const writeFileSpy = spyOn ( testHost , 'writeFile' ) . and . resolveTo ( ) ;
181+ spyOn ( testHost , 'runCommand' ) . and . resolveTo ( { stdout : '' , stderr : '' } ) ;
182+
183+ const { workingDirectory } = await pm . acquireTempPackage ( 'foo@1.0.0' ) ;
184+
185+ expect ( workingDirectory ) . toBe ( '/tmp/project/node_modules/angular-cli-tmp-packages-abc' ) ;
186+ expect ( createTempDirectorySpy ) . toHaveBeenCalledWith ( '/tmp/project/node_modules' ) ;
187+ expect ( writeFileSpy ) . toHaveBeenCalledWith (
188+ '/tmp/project/node_modules/angular-cli-tmp-packages-abc/package.json' ,
189+ '{}' ,
190+ ) ;
191+ expect ( writeFileSpy ) . not . toHaveBeenCalledWith (
192+ '/tmp/project/node_modules/angular-cli-tmp-packages-abc/pnpm-workspace.yaml' ,
193+ '' ,
194+ ) ;
195+ } ) ;
196+ } ) ;
197+
89198 describe ( 'initializationError' , ( ) => {
90199 it ( 'should throw initializationError when running commands' , async ( ) => {
91200 const error = new Error ( 'Not installed' ) ;
0 commit comments