File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 1+ // This file exists because we want to develop our package with Native ESM
2+ // but distribute our package as CommonJS. We need to use native ESM because
3+ // several deps use ESM and it's just easier to integrate with them using native
4+ // ESM. But we want to expose CommonJS because our package consumers aren't ready
5+ // to consume native ESM packages yet...
6+
7+ // This is hopefully temporary...
18import fs from 'fs'
29import url from 'url'
310import path from 'path'
411
512const __dirname = path . dirname ( url . fileURLToPath ( import . meta. url ) )
6- const pkgPath = path . join ( __dirname , '../dist/package.json' )
13+ const distPath = path . join ( __dirname , '../dist' )
14+ const pkgPath = path . join ( distPath , 'package.json' )
715
816const cjsPkgInfo = {
917 type : 'commonjs' ,
1018 main : './index.js' ,
1119 types : './index.d.ts' ,
1220}
1321fs . writeFileSync ( pkgPath , JSON . stringify ( cjsPkgInfo ) )
22+
23+ // when babel compiles this file, it renames it from `.cjs` to `.js` but our
24+ // code imports it with the extension (becuase during dev we're native ESM so we
25+ // have to) and it's easier to update the extension than it would be to update
26+ // the import in the code during the build.
27+ fs . renameSync (
28+ path . join ( distPath , 'dirname-messed-up.js' ) ,
29+ path . join ( distPath , 'dirname-messed-up.cjs' ) ,
30+ )
You can’t perform that action at this time.
0 commit comments