Skip to content

Use TS export assignment for better ESM/CJS compatibility#41

Merged
ide merged 1 commit into
mainfrom
ts-export
Jul 27, 2022
Merged

Use TS export assignment for better ESM/CJS compatibility#41
ide merged 1 commit into
mainfrom
ts-export

Conversation

@ide
Copy link
Copy Markdown
Member

@ide ide commented Jul 27, 2022

Why

Fixes #37

Using export = is a good way to make TS emit code that works with both CJS and ESM as long as the consumer uses esModuleInterop: true.

How

Needed to use namespace merging so that the spawnAsync function could be the assigned export (export = allows only one thing to be exported from the entire file).

Removed index.js since we can import from the TS file directly.

Test Plan

  • Types: Added TypeScript imports to the Jest test file, where types are checked.
  • CJS: Unit test verifies that CJS imports work. Tested end-to-end:
npm pack
cd /tmp
mkdir test
cd test
npm init
yarn add <path to packed tgz>
node
await require('@expo/spawn-async')('echo', ['hi'])

Why
---
Using `export =` is a good way to make TS emit code that works with both CJS and ESM as long as the consumer uses `esModuleInterop: true`.

How
---
Needed to use namespace merging so that the spawnAsync function could be the assigned export (`export =` allows only one thing to be exported from the entire file).

Removed `index.js` since we can import from the TS file directly.

Test Plan
---
- Types: Added TypeScript imports to the Jest test file, where types are checked.
- CJS: Unit test verifies that CJS imports work. Tested end-to-end:
```
npm pack
cd /tmp
mkdir test
cd test
npm init
yarn add <path to packed tgz>
node
await require('@expo/spawn-async')('echo', ['hi'])
```
@ide ide merged commit 08eb4b7 into main Jul 27, 2022
@ide ide deleted the ts-export branch July 27, 2022 01:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot use with ESM module

1 participant