MCPcopy
hub / github.com/mswjs/msw / getLibraryTarball

Function getLibraryTarball

test/modules/module-utils.ts:7–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5import packageJson from '../../package.json' with { type: 'json' }
6
7async 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
35export async function installLibrary(projectPath: string) {
36 const TARBALL_PATH = await getLibraryTarball()

Callers 1

installLibraryFunction · 0.85

Calls 2

invariantFunction · 0.85
errorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…