From 186f8ddbc1591d5a98731b482cfa4e99db420385 Mon Sep 17 00:00:00 2001 From: Emmanuel Chambon Date: Fri, 6 Jan 2023 15:27:02 +0100 Subject: [PATCH 1/2] feat!: publish packages as ESM only BREAKING CHANGE: packages are ESM only --- README.md | 4 +- packages/jest-helpers/package.json | 6 ++- packages/outdated-browser/package.json | 8 +-- packages/random-name/package.json | 10 ++-- packages/regex/package.json | 10 ++-- packages/use-dataloader/package.json | 10 ++-- packages/use-gtm/package.json | 10 ++-- packages/use-i18n/package.json | 10 ++-- packages/use-media/package.json | 10 ++-- packages/use-query-params/package.json | 10 ++-- packages/use-random-name/package.json | 10 ++-- packages/use-segment/package.json | 7 +-- packages/use-storage/package.json | 10 ++-- packages/validate-icu-locales/package.json | 3 ++ rollup.config.mjs | 63 +++++++++------------- 15 files changed, 88 insertions(+), 93 deletions(-) diff --git a/README.md b/README.md index 821518f48..6f03360d7 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,9 @@ The browserlist we are currently using is available in the [rollup.config.mjs](. ### On build outputs -We only output ESM modules. +We only output ESM modules. Please [read this](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c). + +Compiled modules supports Node > 14, the last two versions of any browsers and any browsers with more than 1% of marketshare at the time of release. ### On commits diff --git a/packages/jest-helpers/package.json b/packages/jest-helpers/package.json index ec9296094..9f25c47ed 100644 --- a/packages/jest-helpers/package.json +++ b/packages/jest-helpers/package.json @@ -3,9 +3,13 @@ "version": "2.0.25", "description": "A package for utilities jest functions", "type": "module", + "engines": { + "node": ">=14.x" + }, + "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "types": "dist/index.d.ts", + "jsnext:main": "dist/index.js", "publishConfig": { "access": "public" }, diff --git a/packages/outdated-browser/package.json b/packages/outdated-browser/package.json index 492f30abf..831de2f8a 100644 --- a/packages/outdated-browser/package.json +++ b/packages/outdated-browser/package.json @@ -3,12 +3,12 @@ "version": "1.2.1", "description": "A small web script to display outdated banner", "type": "module", + "engines": { + "node": ">=14.x" + }, "main": "dist/index.js", "module": "dist/index.js", - "types": "dist/index.d.ts", - "browser": { - "dist/index.js": "./dist/index.browser.js" - }, + "jsnext:main": "dist/index.js", "publishConfig": { "access": "public" }, diff --git a/packages/random-name/package.json b/packages/random-name/package.json index e8ec7502e..5d398d307 100644 --- a/packages/random-name/package.json +++ b/packages/random-name/package.json @@ -3,13 +3,13 @@ "version": "3.0.3", "description": "A small utility to generate a random name", "type": "module", + "engines": { + "node": ">=14.x" + }, + "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "types": "dist/index.d.ts", - "sideEffects": false, - "browser": { - "dist/index.js": "./dist/index.browser.js" - }, + "jsnext:main": "dist/index.js", "publishConfig": { "access": "public" }, diff --git a/packages/regex/package.json b/packages/regex/package.json index c43b22c7e..47a4e628d 100644 --- a/packages/regex/package.json +++ b/packages/regex/package.json @@ -3,13 +3,13 @@ "version": "2.9.1", "description": "A small utility to use regex", "type": "module", + "engines": { + "node": ">=14.x" + }, + "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "types": "dist/index.d.ts", - "sideEffects": false, - "browser": { - "dist/index.js": "./dist/index.browser.js" - }, + "jsnext:main": "dist/index.js", "publishConfig": { "access": "public" }, diff --git a/packages/use-dataloader/package.json b/packages/use-dataloader/package.json index 3d4e0920a..3cc1ec94e 100644 --- a/packages/use-dataloader/package.json +++ b/packages/use-dataloader/package.json @@ -9,13 +9,13 @@ "dataloader" ], "type": "module", + "engines": { + "node": ">=14.x" + }, + "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "types": "dist/index.d.ts", - "sideEffects": false, - "browser": { - "dist/index.js": "./dist/index.browser.js" - }, + "jsnext:main": "dist/index.js", "publishConfig": { "access": "public" }, diff --git a/packages/use-gtm/package.json b/packages/use-gtm/package.json index c99b7f66a..640b32e12 100644 --- a/packages/use-gtm/package.json +++ b/packages/use-gtm/package.json @@ -11,13 +11,13 @@ "gtm" ], "type": "module", + "engines": { + "node": ">=14.x" + }, + "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "types": "dist/index.d.ts", - "sideEffects": false, - "browser": { - "dist/index.js": "./dist/index.browser.js" - }, + "jsnext:main": "dist/index.js", "publishConfig": { "access": "public" }, diff --git a/packages/use-i18n/package.json b/packages/use-i18n/package.json index e498fff57..5c3d7ac7a 100644 --- a/packages/use-i18n/package.json +++ b/packages/use-i18n/package.json @@ -11,13 +11,13 @@ "react-intl" ], "type": "module", + "engines": { + "node": ">=14.x" + }, + "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "types": "dist/index.d.ts", - "sideEffects": false, - "browser": { - "dist/index.js": "./dist/index.browser.js" - }, + "jsnext:main": "dist/index.js", "publishConfig": { "access": "public" }, diff --git a/packages/use-media/package.json b/packages/use-media/package.json index 5abcb21ed..0d030d2b0 100644 --- a/packages/use-media/package.json +++ b/packages/use-media/package.json @@ -10,13 +10,13 @@ "media queries" ], "type": "module", + "engines": { + "node": ">=14.x" + }, + "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "types": "dist/index.d.ts", - "sideEffects": false, - "browser": { - "dist/index.js": "./dist/index.browser.js" - }, + "jsnext:main": "dist/index.js", "publishConfig": { "access": "public" }, diff --git a/packages/use-query-params/package.json b/packages/use-query-params/package.json index 1c9891f27..4fa00b0f8 100644 --- a/packages/use-query-params/package.json +++ b/packages/use-query-params/package.json @@ -12,13 +12,13 @@ "query-params" ], "type": "module", + "engines": { + "node": ">=14.x" + }, + "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "types": "dist/index.d.ts", - "sideEffects": false, - "browser": { - "dist/index.js": "./dist/index.browser.js" - }, + "jsnext:main": "dist/index.js", "publishConfig": { "access": "public" }, diff --git a/packages/use-random-name/package.json b/packages/use-random-name/package.json index 94ac21594..5ba6eee9f 100644 --- a/packages/use-random-name/package.json +++ b/packages/use-random-name/package.json @@ -3,13 +3,13 @@ "version": "0.2.6", "description": "A small react utility to generate a random name", "type": "module", + "engines": { + "node": ">=14.x" + }, + "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "types": "dist/index.d.ts", - "sideEffects": false, - "browser": { - "dist/index.js": "./dist/index.browser.js" - }, + "jsnext:main": "dist/index.js", "publishConfig": { "access": "public" }, diff --git a/packages/use-segment/package.json b/packages/use-segment/package.json index b60f18d00..47563281d 100644 --- a/packages/use-segment/package.json +++ b/packages/use-segment/package.json @@ -9,13 +9,10 @@ "segment" ], "type": "module", + "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "types": "dist/index.d.ts", - "sideEffects": false, - "browser": { - "dist/index.js": "./dist/index.browser.js" - }, + "jsnext:main": "dist/index.js", "publishConfig": { "access": "public" }, diff --git a/packages/use-storage/package.json b/packages/use-storage/package.json index 158dad020..fbd98d7d7 100644 --- a/packages/use-storage/package.json +++ b/packages/use-storage/package.json @@ -3,13 +3,13 @@ "version": "1.1.3", "description": "A React hook to interact with local/session storage in reactive way", "type": "module", + "engines": { + "node": ">=14.x" + }, + "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "types": "dist/index.d.ts", - "sideEffects": false, - "browser": { - "dist/index.js": "./dist/index.browser.js" - }, + "jsnext:main": "dist/index.js", "publishConfig": { "access": "public" }, diff --git a/packages/validate-icu-locales/package.json b/packages/validate-icu-locales/package.json index 859bbb0d3..fbe72cbab 100644 --- a/packages/validate-icu-locales/package.json +++ b/packages/validate-icu-locales/package.json @@ -8,6 +8,9 @@ "cli" ], "type": "module", + "engines": { + "node": ">=14.x" + }, "bin": { "validate-icu": "dist/index.js" }, diff --git a/rollup.config.mjs b/rollup.config.mjs index 484c3ad2b..d7f4bdb67 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -1,6 +1,5 @@ import { babel } from '@rollup/plugin-babel' import { nodeResolve } from '@rollup/plugin-node-resolve' -import builtins from 'builtin-modules' import { readPackage } from 'read-pkg' import dts from 'rollup-plugin-dts' import { preserveShebangs } from 'rollup-plugin-preserve-shebangs' @@ -8,29 +7,31 @@ import { visualizer } from 'rollup-plugin-visualizer' const PROFILE = !!process.env.PROFILE -const getConfig = (pkg, isBrowser = false) => { - const targets = isBrowser - ? ` - > 1%, - last 2 versions, - not IE > 0, - not IE_Mob > 0 - ` - : { node: 'current' } +const pkg = await readPackage() - const external = id => - [ - ...Object.keys(pkg.dependencies || {}), - ...Object.keys(pkg.peerDependencies || {}), - ...(isBrowser ? [] : builtins), - ].find(dep => new RegExp(`^${dep}`).test(id)) +const targets = ` + > 1%, + last 2 versions, + not IE > 0, + not IE_Mob > 0 + node > 14 +` - return { +const external = id => + [ + ...Object.keys(pkg.dependencies || {}), + ...Object.keys(pkg.peerDependencies || {}), + ...[], + ].find(dep => new RegExp(`^${dep}`).test(id)) + +export default [ + { external, input: './src/index.ts', output: { - file: isBrowser ? 'dist/index.browser.js' : 'dist/index.js', + dir: 'dist', format: 'es', + preserveModules: true }, plugins: [ babel({ @@ -52,7 +53,6 @@ const getConfig = (pkg, isBrowser = false) => { ], }), nodeResolve({ - browser: isBrowser, extensions: ['.mjs', '.js', '.json', '.ts', '.tsx'], preferBuiltins: true, }), @@ -65,21 +65,10 @@ const getConfig = (pkg, isBrowser = false) => { open: true, }), ].filter(Boolean), - } -} - -export default async () => { - const pkg = await readPackage() - - const doesAlsoTargetBrowser = 'browser' in pkg - - return [ - getConfig(pkg), - doesAlsoTargetBrowser && getConfig(pkg, true), - { - input: './src/index.ts', - output: [{ file: 'dist/index.d.ts', format: 'es' }], - plugins: [dts()], - }, - ].filter(Boolean) -} + }, + { + input: './src/index.ts', + output: [{ file: 'dist/index.d.ts', format: 'es' }], + plugins: [dts()], + }, +] From 24a48aeccca1ab6cf87e620ec27c95338ffdaabb Mon Sep 17 00:00:00 2001 From: Emmanuel Chambon Date: Fri, 6 Jan 2023 15:47:42 +0100 Subject: [PATCH 2/2] fix: add back types, remove jsnext:main --- packages/jest-helpers/package.json | 2 +- packages/outdated-browser/package.json | 2 +- packages/random-name/package.json | 2 +- packages/regex/package.json | 2 +- packages/use-dataloader/package.json | 2 +- packages/use-gtm/package.json | 2 +- packages/use-i18n/package.json | 2 +- packages/use-media/package.json | 2 +- packages/use-query-params/package.json | 2 +- packages/use-random-name/package.json | 2 +- packages/use-segment/package.json | 2 +- packages/use-storage/package.json | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/jest-helpers/package.json b/packages/jest-helpers/package.json index 9f25c47ed..7ee30a33d 100644 --- a/packages/jest-helpers/package.json +++ b/packages/jest-helpers/package.json @@ -9,7 +9,7 @@ "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "jsnext:main": "dist/index.js", + "types": "dist/index.d.ts", "publishConfig": { "access": "public" }, diff --git a/packages/outdated-browser/package.json b/packages/outdated-browser/package.json index 831de2f8a..01616d0dd 100644 --- a/packages/outdated-browser/package.json +++ b/packages/outdated-browser/package.json @@ -8,7 +8,7 @@ }, "main": "dist/index.js", "module": "dist/index.js", - "jsnext:main": "dist/index.js", + "types": "dist/index.d.ts", "publishConfig": { "access": "public" }, diff --git a/packages/random-name/package.json b/packages/random-name/package.json index 5d398d307..7bac7dd8d 100644 --- a/packages/random-name/package.json +++ b/packages/random-name/package.json @@ -9,7 +9,7 @@ "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "jsnext:main": "dist/index.js", + "types": "dist/index.d.ts", "publishConfig": { "access": "public" }, diff --git a/packages/regex/package.json b/packages/regex/package.json index 47a4e628d..be4af4efa 100644 --- a/packages/regex/package.json +++ b/packages/regex/package.json @@ -9,7 +9,7 @@ "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "jsnext:main": "dist/index.js", + "types": "dist/index.d.ts", "publishConfig": { "access": "public" }, diff --git a/packages/use-dataloader/package.json b/packages/use-dataloader/package.json index 3cc1ec94e..eb503ecbb 100644 --- a/packages/use-dataloader/package.json +++ b/packages/use-dataloader/package.json @@ -15,7 +15,7 @@ "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "jsnext:main": "dist/index.js", + "types": "dist/index.d.ts", "publishConfig": { "access": "public" }, diff --git a/packages/use-gtm/package.json b/packages/use-gtm/package.json index 640b32e12..94e607ed7 100644 --- a/packages/use-gtm/package.json +++ b/packages/use-gtm/package.json @@ -17,7 +17,7 @@ "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "jsnext:main": "dist/index.js", + "types": "dist/index.d.ts", "publishConfig": { "access": "public" }, diff --git a/packages/use-i18n/package.json b/packages/use-i18n/package.json index 5c3d7ac7a..57e4c172e 100644 --- a/packages/use-i18n/package.json +++ b/packages/use-i18n/package.json @@ -17,7 +17,7 @@ "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "jsnext:main": "dist/index.js", + "types": "dist/index.d.ts", "publishConfig": { "access": "public" }, diff --git a/packages/use-media/package.json b/packages/use-media/package.json index 0d030d2b0..c5bb76411 100644 --- a/packages/use-media/package.json +++ b/packages/use-media/package.json @@ -16,7 +16,7 @@ "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "jsnext:main": "dist/index.js", + "types": "dist/index.d.ts", "publishConfig": { "access": "public" }, diff --git a/packages/use-query-params/package.json b/packages/use-query-params/package.json index 4fa00b0f8..b02feef5d 100644 --- a/packages/use-query-params/package.json +++ b/packages/use-query-params/package.json @@ -18,7 +18,7 @@ "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "jsnext:main": "dist/index.js", + "types": "dist/index.d.ts", "publishConfig": { "access": "public" }, diff --git a/packages/use-random-name/package.json b/packages/use-random-name/package.json index 5ba6eee9f..87db8b173 100644 --- a/packages/use-random-name/package.json +++ b/packages/use-random-name/package.json @@ -9,7 +9,7 @@ "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "jsnext:main": "dist/index.js", + "types": "dist/index.d.ts", "publishConfig": { "access": "public" }, diff --git a/packages/use-segment/package.json b/packages/use-segment/package.json index 47563281d..605b5b87d 100644 --- a/packages/use-segment/package.json +++ b/packages/use-segment/package.json @@ -12,7 +12,7 @@ "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "jsnext:main": "dist/index.js", + "types": "dist/index.d.ts", "publishConfig": { "access": "public" }, diff --git a/packages/use-storage/package.json b/packages/use-storage/package.json index fbd98d7d7..d78733cc3 100644 --- a/packages/use-storage/package.json +++ b/packages/use-storage/package.json @@ -9,7 +9,7 @@ "sideEffects": false, "main": "dist/index.js", "module": "dist/index.js", - "jsnext:main": "dist/index.js", + "types": "dist/index.d.ts", "publishConfig": { "access": "public" },