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

feat!: move to ESM first with dual ESM/CJS subpackage exports #881

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = (api, targets) => {
export default (api, targets) => {
// https://babeljs.io/docs/en/config-files#config-function-api
const isTestEnv = api.env('test')

Expand Down
103 changes: 62 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,49 +1,67 @@
{
"name": "valtio",
"type": "module",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh, unfortunately, this is not acceptable. we try to keep cjs first. we plan esm first for valtio v3.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pr is for main, I can send another pr using commonjs to v2 branch (this PR should be closed)

"private": true,
"version": "1.13.2",
"description": "💊 Valtio makes proxy-state simple for React and Vanilla",
"main": "./index.js",
"types": "./index.d.ts",
"typesVersions": {
"<4.5": {
"esm/*": [
"ts3.4/*"
],
"*": [
"ts3.4/*"
]
}
},
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./esm/index.d.mts",
"default": "./esm/index.mjs"
},
"module": {
"types": "./esm/index.d.ts",
"default": "./esm/index.js"
},
"default": {
"types": "./index.d.ts",
"default": "./index.js"
}
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
"./macro": {
"import": "./dist/macro.mjs",
"require": "./dist/macro.cjs"
},
"./macro/vite": {
"import": "./dist/macro/vite.mjs",
"require": "./dist/macro/vite.cjs"
},
"./react": {
"import": "./dist/react.mjs",
"require": "./dist/react.cjs"
},
"./react/utils": {
"import": "./dist/react/utils.mjs",
"require": "./dist/react/utils.cjs"
},
"./utils": {
"import": "./dist/utils.mjs",
"require": "./dist/utils.cjs"
},
"./vanilla": {
"import": "./dist/vanilla.mjs",
"require": "./dist/vanilla.cjs"
},
"./vanilla/utils": {
"import": "./dist/vanilla/utils.mjs",
"require": "./dist/vanilla/utils.cjs"
}
},
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"typesVersions": {
"<4.5": {
"macro": ["./dist/ts3.4/macro.d.ts"],
"macro/vite": ["./dist/ts3.4/macro/vite.d.ts"],
"react": ["./dist/ts3.4/react.d.ts"],
"react/utils": ["./dist/ts3.4/react/utils.d.ts"],
"utils": ["./dist/ts3.4/utils.d.ts"],
"vanilla": ["./dist/ts3.4/vanilla.d.ts"],
"vanilla/utils": ["./dist/ts3.4/vanilla/utils.d.ts"],
"*": ["./dist/ts3.4/*"]
},
"./*": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why we need to avoid subpath patterns?

"import": {
"types": "./esm/*.d.mts",
"default": "./esm/*.mjs"
},
"module": {
"types": "./esm/*.d.ts",
"default": "./esm/*.js"
},
"default": {
"types": "./*.d.ts",
"default": "./*.js"
}
">=4.5": {
"macro": ["./dist/macro.d.ts"],
"macro/vite": ["./dist/macro/vite.d.ts"],
"react": ["./dist/react.d.ts"],
"react/utils": ["./dist/react/utils.d.ts"],
"utils": ["./dist/utils.d.ts"],
"vanilla": ["./dist/vanilla.d.ts"],
"vanilla/utils": ["./dist/vanilla/utils.d.ts"],
"*": ["./*"]
}
},
"files": [
Expand All @@ -52,17 +70,18 @@
"sideEffects": false,
"scripts": {
"prebuild": "shx rm -rf dist",
"build": "concurrently -m 8 'yarn:build:*'",
"build": "rollup -c --config-all && node scripts/patch-dts.mjs",
"old-build": "concurrently -m 8 'yarn:build:*'",
"build-watch": "concurrently -n watch: 'yarn:build:* --watch'",
"build:base": "rollup -c",
"build:utils": "rollup -c --config-utils",
"build:vanilla": "rollup -c --config-vanilla",
"build:vanilla_utils": "rollup -c --config-vanilla_utils",
"build:react": "rollup -c --config-react",
"build:react_utils": "rollup -c --config-react_utils",
"build:macro": "rollup -c --config-macro",
"build:macro_vite": "rollup -c --config-macro_vite",
"postbuild": "yarn patch-d-ts && yarn copy && yarn patch-macro-vite && yarn patch-ts3.4 && yarn patch-esm-ts",
"postbuild": "yarn copy",
"xpostbuild": "yarn patch-d-ts && yarn copy && yarn patch-macro-vite && yarn patch-ts3.4 && yarn patch-esm-ts",
"prettier": "prettier '*.{js,json,md}' '{src,tests,docs}/**/*.{ts,tsx,md,mdx}' --write",
"prettier:ci": "prettier '*.{js,json,md}' '{src,tests,docs}/**/*.{ts,tsx,md,mdx}' --list-different",
"eslint": "eslint --no-eslintrc --c .eslintrc.json --fix '*.{js,json,ts}' '{src,tests}/**/*.{ts,tsx}'",
Expand All @@ -71,7 +90,8 @@
"test": "vitest --ui --coverage",
"test:ci": "vitest",
"patch-d-ts": "node -e \"var {entries}=require('./rollup.config.js');require('shelljs').find('dist/**/*.d.ts').forEach(f=>{entries.forEach(({find,replacement})=>require('shelljs').sed('-i',new RegExp(' from \\''+find.source.slice(0,-1)+'\\';$'),' from \\''+replacement+'\\';',f));require('shelljs').sed('-i',/ from '(\\.[^']+)\\.ts';$/,' from \\'\\$1\\';',f)})\"",
"copy": "shx cp -r dist/src/* dist/esm && shx cp -r dist/src/* dist && shx rm -rf dist/{src,tests} && downlevel-dts dist dist/ts3.4 && shx cp package.json readme.md LICENSE dist && json -I -f dist/package.json -e \"this.private=false; this.devDependencies=undefined; this.optionalDependencies=undefined; this.scripts=undefined; this.prettier=undefined;\"",
"copy": "shx mkdir dist/esm && shx cp -r src/* dist/esm && shx rm -rf dist/{src,tests} && shx cp package.json readme.md LICENSE dist && json -I -f dist/package.json -e \"this.private=false; this.devDependencies=undefined; this.optionalDependencies=undefined; this.scripts=undefined; this.prettier=undefined;\"",
"xcopy": "shx cp -r dist/src/* dist/esm && shx cp -r dist/src/* dist && shx rm -rf dist/{src,tests} && downlevel-dts dist dist/ts3.4 && shx cp package.json readme.md LICENSE dist && json -I -f dist/package.json -e \"this.private=false; this.devDependencies=undefined; this.optionalDependencies=undefined; this.scripts=undefined; this.prettier=undefined;\"",
"patch-macro-vite": "shx cp dist/esm/macro/vite.d.ts dist/macro/ && shx cp dist/ts3.4/esm/macro/vite.d.ts dist/ts3.4/macro/",
"patch-ts3.4": "node -e \"require('shelljs').find('dist/ts3.4/**/*.d.ts').forEach(f=>{require('fs').appendFileSync(f,'declare type Awaited<T> = T extends Promise<infer V> ? V : T;');require('shelljs').sed('-i',/^declare type Snapshot<T> =/,'declare type Snapshot<T> = T extends SnapshotIgnore ? T : T extends Promise<unknown> ? Awaited<T> : T extends object ? { readonly [K in keyof T]: Snapshot2<T[K]> } : T; declare type Snapshot2<T> = T extends SnapshotIgnore ? T : T extends Promise<unknown> ? Awaited<T> : T extends object ? { readonly [K in keyof T]: T[K] } : T;;declare type _Snapshot<T> =',f)})\"",
"patch-esm-ts": "node -e \"require('shelljs').find('dist/esm/**/*.d.ts').forEach(f=>{var f2=f.replace(/\\.ts$/,'.mts');require('fs').copyFileSync(f,f2);require('shelljs').sed('-i',/ from '(\\.[^']+)';$/,' from \\'\\$1.mjs\\';',f2);require('shelljs').sed('-i',/^declare module '(\\.[^']+)'/,'declare module \\'\\$1.mjs\\'',f2)})\""
Expand Down Expand Up @@ -156,6 +176,7 @@
"react-dom": "^18.2.0",
"redux": "^5.0.1",
"rollup": "^4.12.0",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-esbuild": "^6.1.1",
"shx": "^0.3.4",
"ts-expect": "^1.3.0",
Expand Down
181 changes: 0 additions & 181 deletions rollup.config.js

This file was deleted.

Loading