@@ -91,6 +91,40 @@ it('exports snapshot', async () => {
91
91
92
92
[ A more complete usage example in Shiki] ( https://github.com/shikijs/shiki/commit/ece4b02a82febea02349ad200e0d07ab59a6a304 )
93
93
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
+
94
128
## How it works
95
129
96
130
When ` getPackageExportsManifest ` is called, it will:
0 commit comments