Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build!: migrate to type: "module" (WIP) #137

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

toyobayashi
Copy link
Owner

Although I think node16 not respecting __esModule makes the interoperability of ESM and CJS quite messy between runtime and bundler / TypeScript Compiler, it is undeniable that the community will continue move forward.

This PR changes the bundled files of emnapi packages to

dist/[name].js
    ESM for bundlers and Node.js, may contain `process.env.NODE_ENV` and external `import`

dist/[name].cjs
    CJS for bundlers and Node.js may contain `process.env.NODE_ENV` and external `require`

dist/[name].umd.cjs
    UMD for `<script>`, evaluate `process.env.NODE_ENV = false` at build time, all dependencies bundled

dist/[name].umd.min.cjs
    UMD for `<script>`, evaluate `process.env.NODE_ENV = true` at build time, all dependencies bundled

dist/[name].browser.js
    ESM for `<script type="module">`, evaluate `process.env.NODE_ENV = false` at build time, all dependencies bundled

dist/[name].browser.min.js
    ESM for `<script type="module">`, evaluate `process.env.NODE_ENV = true` at build time, all dependencies bundled

If runtime doesn't recognize module-sync condition, default resolve to CJS no matter using import or require to avoid dual-package hazard.

{
  "type": "module",
  "main": "./dist/[name].cjs",
  "module": "./dist/[name].js",
  "types": "./dist/[name].d.ts",
  "exports": {
    ".": {
      "types": {
        "module": "./dist/[name].d.ts",
        "module-sync": "./dist/[name].d.ts",
        "import": "./dist/[name].d.cts",
        "require": "./dist/[name].d.cts",
        "default": "./dist/[name].d.cts"
      },
      "module": "./dist/[name].js",
      "module-sync": "./dist/[name].js",
      "default": "./dist/[name].cjs"
    }
  }
}

When ESM becomes large enough in the community, I will migrate it to a pure ESM package.

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.

1 participant