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: Add full ESM support via an import export condition #1115

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
11 changes: 0 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,9 @@
"publish": "lerna publish"
},
"devDependencies": {
"@babel/core": "^7.24.7",
"@babel/preset-env": "^7.24.7",
"@babel/preset-react": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"@lerna-lite/cli": "^3.7.0",
"@lerna-lite/publish": "^3.7.0",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-replace": "^5.0.7",
"@rollup/plugin-terser": "^0.4.3",
"conventional-changelog-conventionalcommits": "^7.0.0",
"execa": "^9.2.0",
"rollup": "^4.18.0",
"turbo": "^2.0.4"
},
"packageManager": "[email protected]"
Expand Down
83 changes: 83 additions & 0 deletions packages/next-intl/.size-limit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import type {SizeLimitConfig} from 'size-limit';

const config: SizeLimitConfig = [
{
name: './ (ESM)',
path: 'dist/esm/index.mjs',
limit: '13.31 kB'
},
{
name: './ (no useTranslations, ESM)',
path: 'dist/esm/index.mjs',
import:
'{useLocale, IntlProvider, useNow, useTimeZone, useMessages, useFormatter}',
limit: '1.64 kB'
},
{
name: './ (CJS)',
path: 'dist/cjs/index.js',
limit: '17.475 kB'
},
{
name: './ (react-server)',
path: 'dist/esm/index.mjs',
limit: '13.255 kB'
},

{
name: './navigation (ESM)',
path: 'dist/esm/navigation.mjs',
limit: '2.415 kB'
},
{
name: './navigation (CJS)',
path: 'dist/cjs/navigation.js',
limit: '19.256 kB'
},
{
name: './navigation (react-server)',
path: 'dist/esm/navigation.react-server.mjs',
// React's `cache` could have a side effect, therefore `createTranslator` is bundled
limit: '14.765 kB'
},

{
name: './server (ESM)',
path: 'dist/esm/server.mjs',
limit: '1 kB'
},
{
name: './server (CJS)',
path: 'dist/cjs/server.js',
limit: '1 kB'
},
{
name: './server (react-server)',
path: 'dist/esm/server.react-server.mjs',
limit: '13.165 kB'
},

{
name: './middleware (ESM)',
path: 'dist/esm/middleware.mjs',
limit: '5.285 kB'
},
{
name: './middleware (CJS)',
path: 'dist/cjs/middleware.js',
limit: '5.645 kB'
},

{
name: './routing (ESM)',
path: 'dist/esm/routing.mjs',
limit: '1 kB'
},
{
name: './routing (CJS)',
path: 'dist/cjs/routing.js',
limit: '1 kB'
}
];

module.exports = config;
2 changes: 1 addition & 1 deletion packages/next-intl/config.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import config from './dist/types/src/config';
import config from './dist/cjs/config';

export = config;
2 changes: 1 addition & 1 deletion packages/next-intl/middleware.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import createMiddleware from './dist/types/src/middleware';
import createMiddleware from './dist/cjs/middleware';

export = createMiddleware;
2 changes: 1 addition & 1 deletion packages/next-intl/navigation.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './dist/types/src/navigation.react-client';
export * from './dist/cjs/navigation';
160 changes: 100 additions & 60 deletions packages/next-intl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"url": "https://github.com/amannn/next-intl"
},
"scripts": {
"build": "rm -rf dist && rollup -c",
"build": "bunchee && node scripts/patch-dist.mjs",
"test": "TZ=Europe/Berlin vitest",
"lint": "pnpm run lint:source && pnpm run lint:package",
"lint:source": "eslint src test && tsc --noEmit",
Expand All @@ -26,40 +26,114 @@
"postpublish": "git checkout . && rm ./README.md",
"size": "size-limit"
},
"main": "./dist/index.react-client.js",
"module": "./dist/esm/index.react-client.js",
"typings": "./dist/types/src/index.react-client.d.ts",
"type": "commonjs",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.mjs",
"typings": "./dist/cjs/index.d.ts",
"exports": {
".": {
"types": "./dist/types/src/index.react-client.d.ts",
"react-server": "./dist/esm/index.react-server.js",
"default": "./dist/index.react-client.js"
"react-server": "./dist/esm/index.react-server.mjs",
"import": {
"types": "./dist/esm/index.d.mts",
"development": "./dist/esm/index.development.mjs",
"production": "./dist/esm/index.production.mjs",
"default": "./dist/esm/index.mjs"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"development": "./dist/cjs/index.development.js",
"production": "./dist/cjs/index.production.js",
"default": "./dist/cjs/index.js"
},
"default": "./dist/cjs/index.js"
},
"./server": {
"types": "./server.d.ts",
"react-server": "./dist/esm/server.react-server.js",
"default": "./dist/server.react-client.js"
"react-server": "./dist/esm/server.react-server.mjs",
"import": {
"types": "./dist/esm/server.d.mts",
"development": "./dist/esm/server.development.mjs",
"production": "./dist/esm/server.production.mjs",
"default": "./dist/esm/server.mjs"
},
"require": {
"types": "./dist/cjs/server.d.ts",
"development": "./dist/cjs/server.development.js",
"production": "./dist/cjs/server.production.js",
"default": "./dist/cjs/server.js"
},
"default": "./dist/cjs/server.js"
},
"./config": {
"types": "./config.d.ts",
"default": "./dist/config.js"
"import": {
"types": "./dist/esm/config.d.mts",
"development": "./dist/esm/config.development.mjs",
"production": "./dist/esm/config.production.mjs",
"default": "./dist/esm/config.mjs"
},
"require": {
"types": "./dist/cjs/config.d.ts",
"development": "./dist/cjs/config.development.js",
"production": "./dist/cjs/config.production.js",
"default": "./dist/cjs/config.js"
},
"default": "./dist/cjs/config.js"
},
"./middleware": {
"types": "./middleware.d.ts",
"default": "./dist/middleware.js"
"import": {
"types": "./dist/esm/middleware.d.mts",
"development": "./dist/esm/middleware.development.mjs",
"production": "./dist/esm/middleware.production.mjs",
"default": "./dist/esm/middleware.mjs"
},
"require": {
"types": "./dist/cjs/middleware.d.ts",
"development": "./dist/cjs/middleware.development.js",
"production": "./dist/cjs/middleware.production.js",
"default": "./dist/cjs/middleware.js"
},
"default": "./dist/cjs/middleware.js"
},
"./navigation": {
"types": "./navigation.d.ts",
"react-server": "./dist/esm/navigation.react-server.js",
"default": "./dist/navigation.react-client.js"
"react-server": "./dist/esm/navigation.react-server.mjs",
"import": {
"types": "./dist/esm/navigation.d.mts",
"development": "./dist/esm/navigation.development.mjs",
"production": "./dist/esm/navigation.production.mjs",
"default": "./dist/esm/navigation.mjs"
},
"require": {
"types": "./dist/cjs/navigation.d.ts",
"development": "./dist/cjs/navigation.development.js",
"production": "./dist/cjs/navigation.production.js",
"default": "./dist/cjs/navigation.js"
},
"default": "./dist/cjs/navigation.js"
},
"./routing": {
"types": "./routing.d.ts",
"default": "./dist/routing.js"
"import": {
"types": "./dist/esm/routing.d.mts",
"development": "./dist/esm/routing.development.mjs",
"production": "./dist/esm/routing.production.mjs",
"default": "./dist/esm/routing.mjs"
},
"require": {
"types": "./dist/cjs/routing.d.ts",
"development": "./dist/cjs/routing.development.js",
"production": "./dist/cjs/routing.production.js",
"default": "./dist/cjs/routing.js"
},
"default": "./dist/cjs/routing.js"
},
"./plugin": {
"types": "./plugin.d.ts",
"default": "./dist/plugin.js"
"import": {
"types": "./dist/esm/plugin.d.mts",
"default": "./dist/esm/plugin.mjs"
},
"require": {
"types": "./dist/cjs/plugin.d.ts",
"default": "./dist/cjs/plugin.js"
},
"default": "./dist/cjs/plugin.js"
}
},
"files": [
Expand Down Expand Up @@ -96,59 +170,25 @@
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.3",
"@edge-runtime/vm": "^3.2.0",
"@size-limit/preset-big-lib": "^8.2.6",
"@size-limit/preset-small-lib": "^11.1.4",
"@testing-library/react": "^16.0.0",
"@types/negotiator": "^0.6.3",
"@types/node": "^20.14.5",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"bunchee": "^5.3.2",
"eslint": "^8.56.0",
"eslint-config-molindo": "^7.0.0",
"eslint-plugin-deprecation": "^3.0.0",
"glob": "^10.4.2",
"next": "^14.2.4",
"path-to-regexp": "^6.2.2",
"publint": "^0.2.8",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"rollup": "^4.18.0",
"rollup-plugin-preserve-directives": "0.4.0",
"size-limit": "^8.2.6",
"size-limit": "^11.1.4",
"typescript": "^5.5.3",
"vitest": "^2.0.2"
},
"prettier": "../../.prettierrc.json",
"size-limit": [
{
"path": "dist/production/index.react-client.js",
"limit": "16.055 KB"
},
{
"path": "dist/production/index.react-server.js",
"limit": "16.875 KB"
},
{
"path": "dist/production/navigation.react-client.js",
"limit": "3.55 KB"
},
{
"path": "dist/production/navigation.react-server.js",
"limit": "18.355 KB"
},
{
"path": "dist/production/server.react-client.js",
"limit": "1 KB"
},
{
"path": "dist/production/server.react-server.js",
"limit": "16.025 KB"
},
{
"path": "dist/production/middleware.js",
"limit": "11.515 KB"
},
{
"path": "dist/production/routing.js",
"limit": "0 KB"
}
]
"prettier": "../../.prettierrc.json"
}
9 changes: 1 addition & 8 deletions packages/next-intl/plugin.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
import {NextConfig} from 'next';

function createNextIntlPlugin(
i18nPath?: string
): (config?: NextConfig) => NextConfig;

// Currently only available via CJS
export = createNextIntlPlugin;
export {default} from './dist/cjs/plugin'
49 changes: 0 additions & 49 deletions packages/next-intl/rollup.config.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion packages/next-intl/routing.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './dist/types/src/routing';
export * from './dist/cjs/routing';
Loading
Loading