Skip to content

Commit

Permalink
fix: always create package.json with type regardless of esm option (#598
Browse files Browse the repository at this point in the history
)

This will provide more flexibilty to library authors such as specifying
`type: module` in their project's `package.json` without breaking the
commonjs output for the published code.
  • Loading branch information
satya164 authored Jul 26, 2024
1 parent a95d0de commit 5b45554
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
7 changes: 2 additions & 5 deletions docs/pages/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ You can verify whether ESM support is enabled by checking the configuration for
}
```

The `"esm": true` option enables ESM-compatible output. Here's what it does:
The `"esm": true` option enables ESM-compatible output by adding the `.js` extension to the import statements in the generated files.

- It adds the `.js` extension to the import statements in the generated files.
- It creates a `package.json` file in the output directory with the content: `{ "type": "module" }`

In addition, it's necessary to specify `"moduleResolution": "Bundler"` in your `tsconfig.json` file:
It's recommended to specify `"moduleResolution": "Bundler"` in your `tsconfig.json` file as well:

```json
{
Expand Down
9 changes: 3 additions & 6 deletions packages/react-native-builder-bob/src/utils/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,9 @@ export default async function compile({
}

await fs.mkdirp(output);

if (esm) {
await fs.writeJSON(path.join(output, 'package.json'), {
type: modules === 'commonjs' ? 'commonjs' : 'module',
});
}
await fs.writeJSON(path.join(output, 'package.json'), {
type: modules === 'commonjs' ? 'commonjs' : 'module',
});

await Promise.all(
files.map(async (filepath) => {
Expand Down

0 comments on commit 5b45554

Please sign in to comment.