Skip to content

Commit b6aa14b

Browse files
authored
FIX: broken main imports (#63)
* FIX: expose additional document types * FIX: broken main imports * CHORE: bump version * FIX: include version in dist cjs/esm package.json files
1 parent 610b5db commit b6aa14b

File tree

6 files changed

+37
-10887
lines changed

6 files changed

+37
-10887
lines changed

build.sh

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,7 @@ npm run build:cjs
1111
node ./fix-esm-imports.mjs
1212

1313
# Add package.json file to esm subtree
14-
cat >dist/esm/package.json <<!EOF
15-
{
16-
"type": "module"
17-
}
18-
!EOF
14+
node ./create-package-json.js dist/esm/package.json module
1915

2016
# Add package.json file to cjs subtree
21-
cat >dist/cjs/package.json <<!EOF
22-
{
23-
"type": "commonjs"
24-
}
25-
!EOF
17+
node ./create-package-json.js dist/cjs/package.json commonjs

create-package-json.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
const { version } = require("./package.json");
4+
5+
const [filepath, type] = process.argv.slice(2);
6+
7+
fs.writeFileSync(
8+
path.join(__dirname, filepath),
9+
JSON.stringify({ version, type }, undefined, 2)
10+
);

fix-esm-imports.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ function fixImportsAtFile(filePath) {
3232
}
3333

3434
const [, importPath] = line.split(`"`);
35+
if (importPath.includes(".json")) {
36+
return `import { createRequire } from "module";
37+
const require = createRequire(import.meta.url);
38+
const { version } = require("${importPath}");`;
39+
}
40+
3541
const fullPath = path.join(filePath, "..", importPath);
3642
if (!fs.existsSync(fullPath)) {
3743
return line.replace(IMPORT_REGEXP, '$1.js"');

0 commit comments

Comments
 (0)