File tree Expand file tree Collapse file tree 1 file changed +30
-1
lines changed
Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -201,7 +201,11 @@ const cjsConfig = defineConfig({
201201 format : 'cjs' ,
202202 } ,
203203 external : Object . keys ( pkg . dependencies ) ,
204- plugins : [ ...createSharedNodePlugins ( { } ) , bundleSizeLimit ( 175 ) ] ,
204+ plugins : [
205+ ...createSharedNodePlugins ( { } ) ,
206+ bundleSizeLimit ( 175 ) ,
207+ exportCheck ( ) ,
208+ ] ,
205209} )
206210
207211export default defineConfig ( [
@@ -342,4 +346,29 @@ function bundleSizeLimit(limit: number): Plugin {
342346 }
343347}
344348
349+ function exportCheck ( ) : Plugin {
350+ return {
351+ name : 'export-check' ,
352+ async writeBundle ( ) {
353+ // escape import so that it's not bundled while config load
354+ const dynImport = ( id : string ) => import ( id )
355+
356+ const esmNamespace = await dynImport ( './dist/node/index.js' )
357+ const cjsModuleExports = ( await dynImport ( './index.cjs' ) ) . default
358+ const cjsModuleExportsKeys = new Set (
359+ Object . getOwnPropertyNames ( cjsModuleExports ) ,
360+ )
361+ const lackingExports = Object . keys ( esmNamespace ) . filter (
362+ ( key ) => ! cjsModuleExportsKeys . has ( key ) ,
363+ )
364+ if ( lackingExports . length > 0 ) {
365+ this . error (
366+ `Exports missing from cjs build: ${ lackingExports . join ( ', ' ) } .` +
367+ ` Please update index.cjs or src/publicUtils.ts.` ,
368+ )
369+ }
370+ } ,
371+ }
372+ }
373+
345374// #endregion
You can’t perform that action at this time.
0 commit comments