Skip to content

Commit 6e55c7f

Browse files
committed
docs: note about monorepo usage
1 parent daa82e1 commit 6e55c7f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,40 @@ it('exports snapshot', async () => {
9191

9292
[A more complete usage example in Shiki](https://github.com/shikijs/shiki/commit/ece4b02a82febea02349ad200e0d07ab59a6a304)
9393

94+
### Monorepo Usage
95+
96+
Since this utility is only a function, you can compose it freely to fit your monorepo structure.
97+
98+
If you want to snapshot all packages in your pnpm monorepo, here is an example we use in VueUse:
99+
100+
```ts
101+
import yaml from 'js-yaml'
102+
import { x } from 'tinyexec'
103+
import { describe, expect, it } from 'vitest'
104+
import { getPackageExportsManifest } from 'vitest-package-exports'
105+
106+
describe('exports-snapshot', async () => {
107+
const packages: { name: string, path: string, private?: boolean }[] = JSON.parse(
108+
await x('pnpm', ['ls', '--only-projects', '-r', '--json']).then(r => r.stdout),
109+
)
110+
111+
for (const pkg of packages) {
112+
if (pkg.private)
113+
continue
114+
it(`${pkg.name}`, async () => {
115+
const manifest = await getPackageExportsManifest({
116+
importMode: 'src',
117+
cwd: pkg.path,
118+
})
119+
await expect(yaml.dump(manifest.exports, { sortKeys: (a, b) => a.localeCompare(b) }))
120+
.toMatchFileSnapshot(`./exports/${pkg.name.split('/').pop()}.yaml`)
121+
})
122+
}
123+
})
124+
```
125+
126+
This will create a file snapshot for each package in the `./exports` directory.
127+
94128
## How it works
95129

96130
When `getPackageExportsManifest` is called, it will:

0 commit comments

Comments
 (0)