()
| 5 | import packageJson from '../../package.json' with { type: 'json' } |
| 6 | |
| 7 | async function getLibraryTarball(): Promise<string> { |
| 8 | const ROOT_PATH = new URL('../..', import.meta.url) |
| 9 | const packFilename = `msw-${packageJson.version}.tgz` |
| 10 | const packPath = url.fileURLToPath(new URL(packFilename, ROOT_PATH)) |
| 11 | |
| 12 | /** |
| 13 | * @note Beware that you need to remove the tarball after |
| 14 | * the test run is done. Don't want to use a stale tgarball, do you? |
| 15 | */ |
| 16 | if (fs.existsSync(packPath)) { |
| 17 | return packPath |
| 18 | } |
| 19 | |
| 20 | const out = spawnSync('pnpm', ['pack'], { cwd: ROOT_PATH }) |
| 21 | |
| 22 | if (out.error) { |
| 23 | console.error(out.error) |
| 24 | } |
| 25 | |
| 26 | invariant( |
| 27 | fs.existsSync(packPath), |
| 28 | 'Failed to pack the library at "%s": packing does not produce the package file', |
| 29 | packPath, |
| 30 | ) |
| 31 | |
| 32 | return packPath |
| 33 | } |
| 34 | |
| 35 | export async function installLibrary(projectPath: string) { |
| 36 | const TARBALL_PATH = await getLibraryTarball() |
no test coverage detected
searching dependent graphs…