|
4 | 4 | cleanupProject,
|
5 | 5 | createFile,
|
6 | 6 | newProject,
|
| 7 | + readFile, |
7 | 8 | readJson,
|
| 9 | + rmDist, |
8 | 10 | runCLI,
|
9 | 11 | runCLIAsync,
|
10 | 12 | uniq,
|
@@ -160,4 +162,72 @@ export function ${lib}Wildcard() {
|
160 | 162 | runCLI(`build ${nonBuildable}`);
|
161 | 163 | checkFilesExist(`dist/libs/${nonBuildable}/src/index.js`);
|
162 | 164 | });
|
| 165 | + |
| 166 | + it('should build buildable libraries using the task graph and handle more scenarios than current implementation', () => { |
| 167 | + const lib1 = uniq('lib1'); |
| 168 | + const lib2 = uniq('lib2'); |
| 169 | + runCLI(`generate @nx/js:lib ${lib1} --bundler=tsc --no-interactive`); |
| 170 | + runCLI(`generate @nx/js:lib ${lib2} --bundler=tsc --no-interactive`); |
| 171 | + |
| 172 | + // add dep between lib1 and lib2 |
| 173 | + updateFile( |
| 174 | + `libs/${lib1}/src/index.ts`, |
| 175 | + `export { ${lib2} } from '@${scope}/${lib2}';` |
| 176 | + ); |
| 177 | + |
| 178 | + // check current implementation |
| 179 | + expect(runCLI(`build ${lib1} --skip-nx-cache`)).toContain( |
| 180 | + 'Done compiling TypeScript files' |
| 181 | + ); |
| 182 | + checkFilesExist(`dist/libs/${lib1}/src/index.js`); |
| 183 | + checkFilesExist(`dist/libs/${lib2}/src/index.js`); |
| 184 | + |
| 185 | + // cleanup dist |
| 186 | + rmDist(); |
| 187 | + |
| 188 | + // check task graph implementation |
| 189 | + expect( |
| 190 | + runCLI(`build ${lib1} --skip-nx-cache`, { |
| 191 | + env: { NX_BUILDABLE_LIBRARIES_TASK_GRAPH: 'true' }, |
| 192 | + }) |
| 193 | + ).toContain('Done compiling TypeScript files'); |
| 194 | + checkFilesExist(`dist/libs/${lib1}/src/index.js`); |
| 195 | + checkFilesExist(`dist/libs/${lib2}/src/index.js`); |
| 196 | + |
| 197 | + // change build target name of lib2 and update target dependencies |
| 198 | + updateJson(`libs/${lib2}/project.json`, (json) => { |
| 199 | + json.targets['my-custom-build'] = json.targets.build; |
| 200 | + delete json.targets.build; |
| 201 | + return json; |
| 202 | + }); |
| 203 | + const originalNxJson = readFile('nx.json'); |
| 204 | + updateJson('nx.json', (json) => { |
| 205 | + json.targetDefaults.build = { |
| 206 | + ...json.targetDefaults.build, |
| 207 | + dependsOn: [...json.targetDefaults.build.dependsOn, '^my-custom-build'], |
| 208 | + }; |
| 209 | + return json; |
| 210 | + }); |
| 211 | + |
| 212 | + // cleanup dist |
| 213 | + rmDist(); |
| 214 | + |
| 215 | + // check current implementation, it doesn't support a different build target name |
| 216 | + expect(() => runCLI(`build ${lib1} --skip-nx-cache`)).toThrow(); |
| 217 | + |
| 218 | + // cleanup dist |
| 219 | + rmDist(); |
| 220 | + |
| 221 | + // check task graph implementation |
| 222 | + expect( |
| 223 | + runCLI(`build ${lib1} --skip-nx-cache`, { |
| 224 | + env: { NX_BUILDABLE_LIBRARIES_TASK_GRAPH: 'true' }, |
| 225 | + }) |
| 226 | + ).toContain('Done compiling TypeScript files'); |
| 227 | + checkFilesExist(`dist/libs/${lib1}/src/index.js`); |
| 228 | + checkFilesExist(`dist/libs/${lib2}/src/index.js`); |
| 229 | + |
| 230 | + // restore nx.json |
| 231 | + updateFile('nx.json', () => originalNxJson); |
| 232 | + }); |
163 | 233 | });
|
0 commit comments