Skip to content

Commit efc9e5c

Browse files
authored
fix(build): rename file so it can be required (#23)
Closes #22
1 parent a1b34f1 commit efc9e5c

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

other/cjs-ify.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
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...
18
import fs from 'fs'
29
import url from 'url'
310
import path from 'path'
411

512
const __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

816
const cjsPkgInfo = {
917
type: 'commonjs',
1018
main: './index.js',
1119
types: './index.d.ts',
1220
}
1321
fs.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+
)

0 commit comments

Comments
 (0)