Skip to content

Commit

Permalink
ESM module export (#821)
Browse files Browse the repository at this point in the history
* test: add reproduction repo for module export

Repo is copied from #816 inside to test in future

* fix(all-settled): bundler esm import
fix(async): bundler esm import
fix(core-v1): bundler esm import
fix(core): bundler esm import
fix(effects): bundler esm import
fix(eslint-plugin): bundler esm import
fix(form-web): bundler esm import
fix(form): bundler esm import
fix(framework): bundler esm import
fix(hooks): bundler esm import
fix(jsx): bundler esm import
fix(lens): bundler esm import
fix(logger): bundler esm import
fix(npm-cookie-baker): bundler esm import
fix(npm-history): bundler esm import
fix(npm-lit): bundler esm import
fix(npm-react): bundler esm import
fix(npm-solid-js): bundler esm import
fix(npm-svelte): bundler esm import
fix(npm-vue): bundler esm import
fix(persist-web-storage): bundler esm import
fix(persist): bundler esm import
fix(primitives): bundler esm import
fix(react-v1): bundler esm import
fix(testing): bundler esm import
fix(timer): bundler esm import
fix(undo): bundler esm import
fix(url): bundler esm import
fix(utils): bundler esm import
fix(web-fetch): bundler esm import
fix(web): bundler esm import

Reatom used to use package.json#module field to declare esm modules.
Turns out it was only in draft spec and never was standardized.
So instead of relying on non-standard behaviour we use .mjs which is
standard nodejs mechanizm.

Should fix #816 #806 #573

* fix(new-package-template): use mjs in module export

* test: implement cjs and esm check test

* chore: install test files
  • Loading branch information
BANOnotIT committed Jun 14, 2024
1 parent 31c7ad2 commit b8bb007
Show file tree
Hide file tree
Showing 41 changed files with 205 additions and 69 deletions.
46 changes: 43 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/all-settled/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"exports": {
"types": "./build/index.d.ts",
"require": "./build/index.js",
"default": "./build/index.module.js"
"default": "./build/index.mjs"
},
"main": "build/index.js",
"module": "build/index.module.js",
"module": "build/index.mjs",
"types": "build/index.d.ts",
"browserslist": [
"last 1 year"
Expand Down
4 changes: 2 additions & 2 deletions packages/async/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"exports": {
"types": "./build/index.d.ts",
"require": "./build/index.js",
"default": "./build/index.module.js"
"default": "./build/index.mjs"
},
"main": "build/index.js",
"module": "build/index.module.js",
"module": "build/index.mjs",
"types": "build/index.d.ts",
"browserslist": [
"last 1 year"
Expand Down
10 changes: 10 additions & 0 deletions packages/cjs-import-check/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#reatom CJS issue
Reproduce for CJS-related reatom issue

This repo is used to reproduce problems with import of "module" exported files.

```
yarn
yarn build
yarn start
```
20 changes: 20 additions & 0 deletions packages/cjs-import-check/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@reatom-private/cjs-import-check",
"version": "1.0.0",
"main": "index.js",
"type": "commonjs",
"private": true,
"license": "MIT",
"dependencies": {
"@reatom/framework": "^3.4.37"
},
"scripts": {
"build": "tsc -p tsconfig.json",
"start": "node ./dist/hello.js",
"pretest": "npm run build",
"test": "node ./dist/hello.js"
},
"devDependencies": {
"typescript": "5.4.5"
}
}
4 changes: 4 additions & 0 deletions packages/cjs-import-check/src/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const {atom, createCtx} = require('@reatom/framework')
const me = atom('check ✅', 'me')
const ctx = createCtx()
console.log('CommonJS import:', ctx.get(me))
14 changes: 14 additions & 0 deletions packages/cjs-import-check/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"rootDir": "src",
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "Node10",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"outDir": "./dist",
},
}

4 changes: 2 additions & 2 deletions packages/core-v1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"exports": {
"types": "./build/index.d.ts",
"require": "./build/index.js",
"default": "./build/index.module.js"
"default": "./build/index.mjs"
},
"main": "build/index.js",
"module": "build/index.module.js",
"module": "build/index.mjs",
"types": "build/index.d.ts",
"browserslist": [
"last 1 year"
Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"exports": {
"types": "./build/index.d.ts",
"require": "./build/index.js",
"default": "./build/index.module.js"
"default": "./build/index.mjs"
},
"main": "build/index.js",
"module": "build/index.module.js",
"module": "build/index.mjs",
"types": "build/index.d.ts",
"sideEffects": false,
"browserslist": [
Expand Down
4 changes: 2 additions & 2 deletions packages/effects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"exports": {
"types": "./build/index.d.ts",
"require": "./build/index.js",
"default": "./build/index.module.js"
"default": "./build/index.mjs"
},
"main": "build/index.js",
"module": "build/index.module.js",
"module": "build/index.mjs",
"types": "build/index.d.ts",
"browserslist": [
"last 1 year"
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"exports": {
"types": "./build/index.d.ts",
"require": "./build/index.js",
"default": "./build/index.module.js"
"default": "./build/index.mjs"
},
"main": "build/index.js",
"module": "build/index.module.js",
"module": "build/index.mjs",
"types": "build/index.d.ts",
"browserslist": [
"node 16"
Expand Down
10 changes: 10 additions & 0 deletions packages/esm-import-check/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#reatom esm issue
Reproduce for ESM-related reatom issue

This repo is used to reproduce problems with import of "module" exported files.

```
yarn
yarn build
yarn start
```
20 changes: 20 additions & 0 deletions packages/esm-import-check/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@reatom-private/esm-import-check",
"version": "1.0.0",
"main": "index.js",
"type": "module",
"license": "MIT",
"private": true,
"dependencies": {
"@reatom/framework": "^3.4.37"
},
"scripts": {
"build": "tsc -p tsconfig.json",
"start": "node ./dist/hello.js",
"pretest": "npm run build",
"test": "node ./dist/hello.js"
},
"devDependencies": {
"typescript": "5.4.5"
}
}
4 changes: 4 additions & 0 deletions packages/esm-import-check/src/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {atom, createCtx} from '@reatom/framework'
const me = atom('check ✅', 'me')
const ctx = createCtx()
console.log('ESM import:', ctx.get(me))
14 changes: 14 additions & 0 deletions packages/esm-import-check/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"rootDir": "src",
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "Bundler",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"outDir": "./dist",
},
}

4 changes: 2 additions & 2 deletions packages/form-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"exports": {
"types": "./build/index.d.ts",
"require": "./build/index.js",
"default": "./build/index.module.js"
"default": "./build/index.mjs"
},
"main": "build/index.js",
"module": "build/index.module.js",
"module": "build/index.mjs",
"types": "build/index.d.ts",
"browserslist": [
"last 1 year"
Expand Down
4 changes: 2 additions & 2 deletions packages/form/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"exports": {
"types": "./build/index.d.ts",
"require": "./build/index.js",
"default": "./build/index.module.js"
"default": "./build/index.mjs"
},
"main": "build/index.js",
"module": "build/index.module.js",
"module": "build/index.mjs",
"types": "build/index.d.ts",
"browserslist": [
"last 1 year"
Expand Down
4 changes: 2 additions & 2 deletions packages/framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"exports": {
"types": "./build/index.d.ts",
"require": "./build/index.js",
"default": "./build/index.module.js"
"default": "./build/index.mjs"
},
"main": "build/index.js",
"module": "build/index.module.js",
"module": "build/index.mjs",
"types": "build/index.d.ts",
"browserslist": ["last 1 year"],
"minify": { "mangle": false },
Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"exports": {
"types": "./build/index.d.ts",
"require": "./build/index.js",
"default": "./build/index.module.js"
"default": "./build/index.mjs"
},
"main": "build/index.js",
"module": "build/index.module.js",
"module": "build/index.mjs",
"types": "build/index.d.ts",
"browserslist": [
"last 1 year"
Expand Down
8 changes: 4 additions & 4 deletions packages/jsx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
"exports": {
".": {
"types": "./build/index.d.ts",
"default": "./build/index.module.js"
"default": "./build/index.mjs"
},
"./jsx-runtime": {
"types": "./build/index.d.ts",
"default": "./build/index.module.js"
"default": "./build/index.mjs"
},
"./jsx-dev-runtime": {
"types": "./build/index.d.ts",
"default": "./build/index.module.js"
"default": "./build/index.mjs"
}
},
"main": "build/index.js",
"module": "build/index.module.js",
"module": "build/index.mjs",
"types": "build/index.d.ts",
"browserslist": [
"last 1 year"
Expand Down
4 changes: 2 additions & 2 deletions packages/lens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"exports": {
"types": "./build/index.d.ts",
"require": "./build/index.js",
"default": "./build/index.module.js"
"default": "./build/index.mjs"
},
"main": "build/index.js",
"module": "build/index.module.js",
"module": "build/index.mjs",
"types": "build/index.d.ts",
"browserslist": [
"last 1 year"
Expand Down
4 changes: 2 additions & 2 deletions packages/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"exports": {
"types": "./build/index.d.ts",
"require": "./build/index.js",
"default": "./build/index.module.js"
"default": "./build/index.mjs"
},
"main": "build/index.js",
"module": "build/index.module.js",
"module": "build/index.mjs",
"types": "build/index.d.ts",
"browserslist": [
"last 1 year"
Expand Down
4 changes: 2 additions & 2 deletions packages/npm-cookie-baker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"exports": {
"types": "./build/index.d.ts",
"require": "./build/index.js",
"default": "./build/index.module.js"
"default": "./build/index.mjs"
},
"main": "build/index.js",
"module": "build/index.module.js",
"module": "build/index.mjs",
"types": "build/index.d.ts",
"browserslist": [
"last 1 year"
Expand Down
4 changes: 2 additions & 2 deletions packages/npm-history/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"exports": {
"types": "./build/index.d.ts",
"require": "./build/index.js",
"default": "./build/index.module.js"
"default": "./build/index.mjs"
},
"main": "build/index.js",
"module": "build/index.module.js",
"module": "build/index.mjs",
"types": "build/index.d.ts",
"browserslist": [
"last 1 year"
Expand Down
Loading

0 comments on commit b8bb007

Please sign in to comment.