|
| 1 | +import { |
| 2 | + cleanupProject, |
| 3 | + getPackageManagerCommand, |
| 4 | + getSelectedPackageManager, |
| 5 | + newProject, |
| 6 | + runCLI, |
| 7 | + runCommand, |
| 8 | + uniq, |
| 9 | + updateFile, |
| 10 | + updateJson, |
| 11 | +} from '@nx/e2e/utils'; |
| 12 | + |
| 13 | +describe('JS - TS solution setup', () => { |
| 14 | + beforeAll(() => { |
| 15 | + newProject({ |
| 16 | + packages: ['@nx/js'], |
| 17 | + preset: 'ts', |
| 18 | + }); |
| 19 | + }); |
| 20 | + |
| 21 | + afterAll(() => { |
| 22 | + cleanupProject(); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should generate libraries with different bundlers and link them successfully', () => { |
| 26 | + const esbuildParentLib = uniq('esbuild-parent-lib'); |
| 27 | + const esbuildChildLib = uniq('esbuild-child-lib'); |
| 28 | + const rollupParentLib = uniq('rollup-parent-lib'); |
| 29 | + const rollupChildLib = uniq('rollup-child-lib'); |
| 30 | + const swcParentLib = uniq('swc-parent-lib'); |
| 31 | + const swcChildLib = uniq('swc-child-lib'); |
| 32 | + const tscParentLib = uniq('tsc-parent-lib'); |
| 33 | + const tscChildLib = uniq('tsc-child-lib'); |
| 34 | + const viteParentLib = uniq('vite-parent-lib'); |
| 35 | + const viteChildLib = uniq('vite-child-lib'); |
| 36 | + |
| 37 | + runCLI( |
| 38 | + `generate @nx/js:lib packages/${esbuildParentLib} --bundler=esbuild --linter=eslint --unitTestRunner=jest` |
| 39 | + ); |
| 40 | + runCLI( |
| 41 | + `generate @nx/js:lib packages/${esbuildChildLib} --bundler=esbuild --linter=eslint --unitTestRunner=jest` |
| 42 | + ); |
| 43 | + runCLI( |
| 44 | + `generate @nx/js:lib packages/${rollupParentLib} --bundler=rollup --linter=eslint --unitTestRunner=jest` |
| 45 | + ); |
| 46 | + runCLI( |
| 47 | + `generate @nx/js:lib packages/${rollupChildLib} --bundler=rollup --linter=eslint --unitTestRunner=jest` |
| 48 | + ); |
| 49 | + runCLI( |
| 50 | + `generate @nx/js:lib packages/${swcParentLib} --bundler=swc --linter=eslint --unitTestRunner=jest` |
| 51 | + ); |
| 52 | + runCLI( |
| 53 | + `generate @nx/js:lib packages/${swcChildLib} --bundler=swc --linter=eslint --unitTestRunner=jest` |
| 54 | + ); |
| 55 | + runCLI( |
| 56 | + `generate @nx/js:lib packages/${tscParentLib} --bundler=tsc --linter=eslint --unitTestRunner=jest` |
| 57 | + ); |
| 58 | + runCLI( |
| 59 | + `generate @nx/js:lib packages/${tscChildLib} --bundler=tsc --linter=eslint --unitTestRunner=jest` |
| 60 | + ); |
| 61 | + runCLI( |
| 62 | + `generate @nx/js:lib packages/${viteParentLib} --bundler=vite --linter=eslint --unitTestRunner=jest` |
| 63 | + ); |
| 64 | + runCLI( |
| 65 | + `generate @nx/js:lib packages/${viteChildLib} --bundler=vite --linter=eslint --unitTestRunner=jest` |
| 66 | + ); |
| 67 | + |
| 68 | + // add deps, each parent lib imports all child libs |
| 69 | + const addImports = (parentLib: string) => { |
| 70 | + updateFile( |
| 71 | + `packages/${parentLib}/src/index.ts`, |
| 72 | + (content) => `export * from '@proj/${esbuildChildLib}'; |
| 73 | +export * from '@proj/${rollupChildLib}'; |
| 74 | +export * from '@proj/${swcChildLib}'; |
| 75 | +export * from '@proj/${tscChildLib}'; |
| 76 | +export * from '@proj/${viteChildLib}'; |
| 77 | +${content}` |
| 78 | + ); |
| 79 | + }; |
| 80 | + |
| 81 | + addImports(esbuildParentLib); |
| 82 | + addImports(rollupParentLib); |
| 83 | + addImports(swcParentLib); |
| 84 | + addImports(tscParentLib); |
| 85 | + addImports(viteParentLib); |
| 86 | + |
| 87 | + const pm = getSelectedPackageManager(); |
| 88 | + if (pm === 'pnpm') { |
| 89 | + // for pnpm we need to add the local packages as dependencies to each consumer package.json |
| 90 | + const addDeps = (parentLib: string) => { |
| 91 | + updateJson(`packages/${parentLib}/package.json`, (json) => { |
| 92 | + json.dependencies ??= {}; |
| 93 | + json.dependencies[`@proj/${esbuildChildLib}`] = 'workspace:*'; |
| 94 | + json.dependencies[`@proj/${rollupChildLib}`] = 'workspace:*'; |
| 95 | + json.dependencies[`@proj/${swcChildLib}`] = 'workspace:*'; |
| 96 | + json.dependencies[`@proj/${tscChildLib}`] = 'workspace:*'; |
| 97 | + json.dependencies[`@proj/${viteChildLib}`] = 'workspace:*'; |
| 98 | + return json; |
| 99 | + }); |
| 100 | + }; |
| 101 | + |
| 102 | + addDeps(esbuildParentLib); |
| 103 | + addDeps(rollupParentLib); |
| 104 | + addDeps(swcParentLib); |
| 105 | + addDeps(tscParentLib); |
| 106 | + addDeps(viteParentLib); |
| 107 | + |
| 108 | + const pmc = getPackageManagerCommand({ packageManager: pm }); |
| 109 | + runCommand(pmc.install); |
| 110 | + } |
| 111 | + |
| 112 | + // sync to ensure the TS project references are updated |
| 113 | + runCLI(`sync`); |
| 114 | + |
| 115 | + // check build |
| 116 | + expect(runCLI(`build ${esbuildParentLib}`)).toContain( |
| 117 | + `Successfully ran target build for project ${esbuildParentLib} and 5 tasks it depends on` |
| 118 | + ); |
| 119 | + expect(runCLI(`build ${rollupParentLib}`)).toContain( |
| 120 | + `Successfully ran target build for project ${rollupParentLib} and 5 tasks it depends on` |
| 121 | + ); |
| 122 | + expect(runCLI(`build ${swcParentLib}`)).toContain( |
| 123 | + `Successfully ran target build for project ${swcParentLib} and 5 tasks it depends on` |
| 124 | + ); |
| 125 | + expect(runCLI(`build ${tscParentLib}`)).toContain( |
| 126 | + `Successfully ran target build for project ${tscParentLib} and 5 tasks it depends on` |
| 127 | + ); |
| 128 | + expect(runCLI(`build ${viteParentLib}`)).toContain( |
| 129 | + `Successfully ran target build for project ${viteParentLib} and 5 tasks it depends on` |
| 130 | + ); |
| 131 | + |
| 132 | + // check typecheck |
| 133 | + expect(runCLI(`typecheck ${esbuildParentLib}`)).toContain( |
| 134 | + `Successfully ran target typecheck for project ${esbuildParentLib} and 5 tasks it depends on` |
| 135 | + ); |
| 136 | + expect(runCLI(`typecheck ${rollupParentLib}`)).toContain( |
| 137 | + `Successfully ran target typecheck for project ${rollupParentLib} and 5 tasks it depends on` |
| 138 | + ); |
| 139 | + expect(runCLI(`typecheck ${swcParentLib}`)).toContain( |
| 140 | + `Successfully ran target typecheck for project ${swcParentLib} and 5 tasks it depends on` |
| 141 | + ); |
| 142 | + expect(runCLI(`typecheck ${tscParentLib}`)).toContain( |
| 143 | + `Successfully ran target typecheck for project ${tscParentLib} and 5 tasks it depends on` |
| 144 | + ); |
| 145 | + expect(runCLI(`typecheck ${viteParentLib}`)).toContain( |
| 146 | + `Successfully ran target typecheck for project ${viteParentLib} and 5 tasks it depends on` |
| 147 | + ); |
| 148 | + |
| 149 | + // check lint |
| 150 | + expect(runCLI(`lint ${esbuildParentLib}`)).toContain( |
| 151 | + `Successfully ran target lint for project ${esbuildParentLib}` |
| 152 | + ); |
| 153 | + expect(runCLI(`lint ${rollupParentLib}`)).toContain( |
| 154 | + `Successfully ran target lint for project ${rollupParentLib}` |
| 155 | + ); |
| 156 | + expect(runCLI(`lint ${swcParentLib}`)).toContain( |
| 157 | + `Successfully ran target lint for project ${swcParentLib}` |
| 158 | + ); |
| 159 | + expect(runCLI(`lint ${tscParentLib}`)).toContain( |
| 160 | + `Successfully ran target lint for project ${tscParentLib}` |
| 161 | + ); |
| 162 | + expect(runCLI(`lint ${viteParentLib}`)).toContain( |
| 163 | + `Successfully ran target lint for project ${viteParentLib}` |
| 164 | + ); |
| 165 | + |
| 166 | + // check test |
| 167 | + expect(runCLI(`test ${esbuildParentLib}`)).toContain( |
| 168 | + `Successfully ran target test for project ${esbuildParentLib}` |
| 169 | + ); |
| 170 | + expect(runCLI(`test ${rollupParentLib}`)).toContain( |
| 171 | + `Successfully ran target test for project ${rollupParentLib}` |
| 172 | + ); |
| 173 | + expect(runCLI(`test ${swcParentLib}`)).toContain( |
| 174 | + `Successfully ran target test for project ${swcParentLib}` |
| 175 | + ); |
| 176 | + expect(runCLI(`test ${tscParentLib}`)).toContain( |
| 177 | + `Successfully ran target test for project ${tscParentLib}` |
| 178 | + ); |
| 179 | + expect(runCLI(`test ${viteParentLib}`)).toContain( |
| 180 | + `Successfully ran target test for project ${viteParentLib}` |
| 181 | + ); |
| 182 | + }, 300_000); |
| 183 | +}); |
0 commit comments