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!: Make package ESM-only, target modern browsers, use modern JSX transform #1470

Merged
merged 37 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ab7464d
delete `_useLocale` and `_IntlProvider` workarounds
amannn Oct 24, 2024
fd8dcad
some progress
amannn Oct 25, 2024
575aa46
migrate use-intl to explicit file extensions
amannn Oct 25, 2024
1c722d6
fix remaining files
amannn Oct 25, 2024
c609996
flip tsconfig
amannn Oct 25, 2024
9f408f5
getting somewhere
amannn Oct 25, 2024
148d2e1
safer
amannn Oct 25, 2024
110583d
modern jsx transform
amannn Oct 25, 2024
3e90772
dropped support for react 16.8
amannn Oct 25, 2024
149190b
Use `react-jsx` in tsconfig
amannn Oct 25, 2024
b501623
ignore runtime too
amannn Oct 25, 2024
212d667
remove commonjs plugin, target modern browsers
amannn Oct 25, 2024
3cd2b8f
fix tests
amannn Oct 25, 2024
ae7f4a7
explicit file extensions in next-intl
amannn Oct 28, 2024
19b172a
remove react imports
amannn Oct 28, 2024
a3c1760
file extensions for nextjs apis
amannn Oct 28, 2024
fbb3432
comments
amannn Oct 28, 2024
6c3f9bb
bundling working for next-intl
amannn Oct 28, 2024
04b6339
some cleanup
amannn Oct 28, 2024
75d89e5
reorder conditions
amannn Oct 28, 2024
56546a7
fix types
amannn Oct 28, 2024
016c087
workaround for use
amannn Oct 28, 2024
7c202dc
cjs build for plugin
amannn Oct 28, 2024
212e412
remove vite workaround
amannn Oct 28, 2024
48956f4
attempt adding cjs plugin types
amannn Oct 28, 2024
a579a41
fix cjs types for plugin
amannn Oct 28, 2024
45181d7
fix lint
amannn Oct 28, 2024
ad20925
fix jest
amannn Oct 28, 2024
86a3be3
fix lint
amannn Oct 28, 2024
b3a161f
decrease sizes
amannn Oct 28, 2024
088dd9d
Comments
amannn Oct 28, 2024
9d39785
unused ts-ignore
amannn Oct 28, 2024
c26f5cd
slightly shorter
amannn Oct 28, 2024
053acf9
bump size
amannn Oct 29, 2024
7ee2bb1
turbo and mjs config for a few examples
amannn Oct 29, 2024
f244584
move tools to own workspace
amannn Oct 29, 2024
0cb80f8
bump sizes
amannn Oct 29, 2024
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 examples/example-app-router-mixed-routing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "example-app-router-mixed-routing",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "next dev --turbo",
"lint": "eslint src && tsc && prettier src --check",
"test": "playwright test",
"build": "next build",
Expand Down
3 changes: 0 additions & 3 deletions examples/example-app-router-single-locale/next.config.js

This file was deleted.

8 changes: 8 additions & 0 deletions examples/example-app-router-single-locale/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import createNextIntlPlugin from 'next-intl/plugin';

const withNextIntl = createNextIntlPlugin();

/** @type {import('next').NextConfig} */
const nextConfig = {};

export default withNextIntl(nextConfig);
2 changes: 1 addition & 1 deletion examples/example-app-router-single-locale/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "example-app-router-single-locale",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "next dev --turbo",
"lint": "eslint src && tsc && prettier src --check",
"test": "playwright test",
"build": "next build",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import createNextIntlPlugin from 'next-intl/plugin';

const withNextIntl = createNextIntlPlugin();

/** @type {import('next').NextConfig} */
const nextConfig = {};

export default withNextIntl(nextConfig);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "example-app-router-without-i18n-routing",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "next dev --turbo",
"lint": "eslint src && tsc && prettier src --check",
"test": "playwright test",
"build": "next build",
Expand Down
8 changes: 0 additions & 8 deletions examples/example-app-router/next.config.js

This file was deleted.

10 changes: 10 additions & 0 deletions examples/example-app-router/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @ts-check

import createNextIntlPlugin from 'next-intl/plugin';

const withNextIntl = createNextIntlPlugin();

/** @type {import('next').NextConfig} */
const config = {};

export default withNextIntl(config);
2 changes: 1 addition & 1 deletion examples/example-app-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "example-app-router",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "next dev --turbo",
"lint": "eslint src && tsc && prettier src --check",
"test": "pnpm run test:playwright && pnpm run test:jest",
"test:playwright": "playwright test",
Expand Down
7 changes: 1 addition & 6 deletions examples/example-app-router/src/i18n/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ export default getRequestConfig(async ({requestLocale}) => {

return {
locale,
messages: (
await (locale === 'en'
? // When using Turbopack, this will enable HMR for `en`
import('../../messages/en.json')
: import(`../../messages/${locale}.json`))
).default
messages: (await import(`../../messages/${locale}.json`)).default
};
});
5 changes: 0 additions & 5 deletions examples/example-pages-router-advanced/config/babel.config.js

This file was deleted.

7 changes: 0 additions & 7 deletions examples/example-pages-router-advanced/config/jest.json

This file was deleted.

9 changes: 9 additions & 0 deletions examples/example-pages-router-advanced/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-env node */
const nextJest = require('next/jest');

const createJestConfig = nextJest({dir: './'});

module.exports = createJestConfig({
testEnvironment: 'jsdom',
rootDir: 'src'
});
2 changes: 1 addition & 1 deletion examples/example-pages-router-advanced/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"scripts": {
"dev": "next dev",
"lint": "eslint src && tsc && prettier src --check",
"test": "jest --config config/jest.json",
"test": "jest",
"build": "next build",
"start": "next start"
},
Expand Down
9 changes: 2 additions & 7 deletions examples/example-use-intl/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import {defineConfig} from 'vite';
import react from '@vitejs/plugin-react';
import {defineConfig} from 'vite';

export default defineConfig({
plugins: [react()],

// TODO: Remove after use-intl has full ESM support
// https://vitejs.dev/guide/dep-pre-bundling#monorepos-and-linked-dependencies
optimizeDeps: {include: ['use-intl']},
build: {commonjsOptions: {include: [/use-intl/, /node_modules/]}}
plugins: [react()]
});
11 changes: 0 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,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.9.0",
"@lerna-lite/publish": "^3.9.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.2.3"
},
"pnpm": {
Expand Down
82 changes: 26 additions & 56 deletions packages/next-intl/.size-limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,52 @@ import type {SizeLimitConfig} from 'size-limit';

const config: SizeLimitConfig = [
{
name: "import * from 'next-intl' (react-client)",
path: 'dist/production/index.react-client.js',
limit: '14.125 KB'
name: "import * from 'next-intl' (react-client, production)",
path: 'dist/esm/production/index.react-client.js',
limit: '13.205 KB'
},
{
name: "import * from 'next-intl' (react-server)",
path: 'dist/production/index.react-server.js',
limit: '14.845 KB'
},
{
name: "import {createSharedPathnamesNavigation} from 'next-intl/navigation' (react-client)",
path: 'dist/production/navigation.react-client.js',
import: '{createSharedPathnamesNavigation}',
limit: '4.045 KB'
name: "import {NextIntlClientProvider} from 'next-intl' (react-client, production)",
import: '{NextIntlClientProvider}',
path: 'dist/esm/production/index.react-client.js',
limit: '1.035 KB'
},
{
name: "import {createLocalizedPathnamesNavigation} from 'next-intl/navigation' (react-client)",
path: 'dist/production/navigation.react-client.js',
import: '{createLocalizedPathnamesNavigation}',
limit: '4.045 KB'
name: "import * from 'next-intl' (react-server, production)",
path: 'dist/esm/production/index.react-server.js',
limit: '14.165 KB'
},
{
name: "import {createNavigation} from 'next-intl/navigation' (react-client)",
path: 'dist/production/navigation.react-client.js',
name: "import {createNavigation} from 'next-intl/navigation' (react-client, production)",
path: 'dist/esm/production/navigation.react-client.js',
import: '{createNavigation}',
limit: '4.055 KB'
},
{
name: "import {createSharedPathnamesNavigation} from 'next-intl/navigation' (react-server)",
path: 'dist/production/navigation.react-server.js',
import: '{createSharedPathnamesNavigation}',
limit: '16.795 KB'
},
{
name: "import {createLocalizedPathnamesNavigation} from 'next-intl/navigation' (react-server)",
path: 'dist/production/navigation.react-server.js',
import: '{createLocalizedPathnamesNavigation}',
limit: '16.785 KB'
limit: '2.525 KB'
},
{
name: "import {createNavigation} from 'next-intl/navigation' (react-server)",
path: 'dist/production/navigation.react-server.js',
name: "import {createNavigation} from 'next-intl/navigation' (react-server, production)",
path: 'dist/esm/production/navigation.react-server.js',
import: '{createNavigation}',
limit: '16.8 KB'
limit: '3.425 KB'
},
{
name: "import * from 'next-intl/server' (react-client)",
path: 'dist/production/server.react-client.js',
name: "import * from 'next-intl/server' (react-client, production)",
path: 'dist/esm/production/server.react-client.js',
limit: '1 KB'
},
{
name: "import * from 'next-intl/server' (react-server)",
path: 'dist/production/server.react-server.js',
limit: '14.035 KB'
name: "import * from 'next-intl/server' (react-server, production)",
path: 'dist/esm/production/server.react-server.js',
limit: '13.385 KB'
},
{
name: "import createMiddleware from 'next-intl/middleware'",
path: 'dist/production/middleware.js',
limit: '9.725 KB'
name: "import * from 'next-intl/middleware' (production)",
path: 'dist/esm/production/middleware.js',
limit: '9.295 KB'
},
{
name: "import * from 'next-intl/routing'",
path: 'dist/production/routing.js',
name: "import * from 'next-intl/routing' (production)",
path: 'dist/esm/production/routing.js',
limit: '1 KB'
},
{
name: "import * from 'next-intl' (react-client, ESM)",
path: 'dist/esm/index.react-client.js',
import: '*',
limit: '14.295 kB'
},
{
name: "import {NextIntlProvider} from 'next-intl' (react-client, ESM)",
path: 'dist/esm/index.react-client.js',
import: '{NextIntlClientProvider}',
limit: '1.55 kB'
}
];

Expand Down
3 changes: 2 additions & 1 deletion packages/next-intl/config.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from './dist/types/src/config';
// Needed for projects with `moduleResolution: 'node'`
import config from './dist/types/config';

export = config;
3 changes: 2 additions & 1 deletion packages/next-intl/middleware.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import createMiddleware from './dist/types/src/middleware';
// Needed for projects with `moduleResolution: 'node'`
import createMiddleware from './dist/types/middleware';

export = createMiddleware;
3 changes: 2 additions & 1 deletion packages/next-intl/navigation.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './dist/types/src/navigation.react-client';
// Needed for projects with `moduleResolution: 'node'`
export * from './dist/types/navigation.react-client';
Loading
Loading