Skip to content

Commit

Permalink
Merge branch 'canary' into shu/8t6u
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding authored Feb 16, 2023
2 parents cc695d7 + c553452 commit b7cf55f
Show file tree
Hide file tree
Showing 33 changed files with 187 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/advanced-features/i18n-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ description: Next.js has built-in support for internationalized routing and lang

Next.js has built-in support for internationalized ([i18n](https://en.wikipedia.org/wiki/Internationalization_and_localization#Naming)) routing since `v10.0.0`. You can provide a list of locales, the default locale, and domain-specific locales and Next.js will automatically handle the routing.

The i18n routing support is currently meant to complement existing i18n library solutions like [`react-intl`](https://formatjs.io/docs/getting-started/installation), [`react-i18next`](https://react.i18next.com/), [`lingui`](https://lingui.js.org/), [`rosetta`](https://github.com/lukeed/rosetta), [`next-intl`](https://github.com/amannn/next-intl), [`next-translate`](https://github.com/aralroca/next-translate) and others by streamlining the routes and locale parsing.
The i18n routing support is currently meant to complement existing i18n library solutions like [`react-intl`](https://formatjs.io/docs/getting-started/installation), [`react-i18next`](https://react.i18next.com/), [`lingui`](https://lingui.dev/), [`rosetta`](https://github.com/lukeed/rosetta), [`next-intl`](https://github.com/amannn/next-intl), [`next-translate`](https://github.com/aralroca/next-translate) and others by streamlining the routes and locale parsing.

## Getting started

Expand Down
4 changes: 2 additions & 2 deletions examples/with-lingui/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# With Lingui example

This example shows a way to use [lingui.js](https://lingui.js.org) with next.js.
This example shows a way to use [Lingui](https://lingui.dev) with next.js.

It adds a webpack loader for the messages to avoid having to manually compile while developing as well as adds the compile step to the `next build` script for production builds.

Expand Down Expand Up @@ -32,7 +32,7 @@ Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&ut

### How to add more translated strings

To add new strings use the [react component](https://lingui.js.org/tutorials/react-patterns.html#common-i18n-patterns-in-react) `<Trans />` and then run `yarn export` to export the messages into `locale/{language}/messages.po`.
To add new strings use the [react component](https://lingui.dev/tutorials/react-patterns) `<Trans />` and then run `yarn export` to export the messages into `locale/{language}/messages.po`.

### How to add another language

Expand Down
4 changes: 2 additions & 2 deletions examples/with-lingui/locale/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ msgstr ""
"Language-Team: \n"
"Plural-Forms: \n"

#: pages/two.js:9
#: pages/two.js:8
msgid "Back home"
msgstr "Back home"

#: components/LangSwitcher.js:6
msgid "English"
msgstr "English"

#: pages/index.js:9
#: pages/index.js:8
msgid "Go to page 2"
msgstr "Go to page 2"

Expand Down
4 changes: 2 additions & 2 deletions examples/with-lingui/locale/sv/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ msgstr ""
"Language-Team: \n"
"Plural-Forms: \n"

#: pages/two.js:9
#: pages/two.js:8
msgid "Back home"
msgstr "Tillbaka hem"

#: components/LangSwitcher.js:6
msgid "English"
msgstr "Engelska"

#: pages/index.js:9
#: pages/index.js:8
msgid "Go to page 2"
msgstr "Gå till sida 2"

Expand Down
14 changes: 7 additions & 7 deletions examples/with-lingui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"extract": "lingui extract",
"extract": "NODE_ENV=development lingui extract",
"compile": "lingui compile"
},
"dependencies": {
"@lingui/react": "^3.10.2",
"@lingui/react": "^3.17.1",
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@babel/core": "7.14.5",
"@lingui/cli": "^3.10.2",
"@lingui/core": "3.10.2",
"@lingui/loader": "3.10.2",
"@lingui/macro": "^3.10.2",
"@babel/core": "7.20.12",
"@lingui/cli": "^3.17.1",
"@lingui/core": "3.17.1",
"@lingui/loader": "3.17.1",
"@lingui/macro": "^3.17.1",
"babel-plugin-macros": "^3.1.0"
}
}
14 changes: 9 additions & 5 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1717,12 +1717,16 @@ export default async function build(
require('next/dist/compiled/glob') as typeof import('next/dist/compiled/glob')
const glob = (pattern: string): Promise<string[]> => {
return new Promise((resolve, reject) => {
globOrig(pattern, { cwd: dir }, (err, files) => {
if (err) {
return reject(err)
globOrig(
pattern,
{ cwd: dir, nodir: true, dot: true },
(err, files) => {
if (err) {
return reject(err)
}
resolve(files)
}
resolve(files)
})
)
})
}

Expand Down
13 changes: 10 additions & 3 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -903,13 +903,13 @@ export default async function getBaseWebpackConfig(
const mainFieldsPerCompiler: Record<typeof compilerType, string[]> = {
[COMPILER_NAMES.server]: ['main', 'module'],
[COMPILER_NAMES.client]: ['browser', 'module', 'main'],
[COMPILER_NAMES.edgeServer]: ['browser', 'module', 'main'],
[COMPILER_NAMES.edgeServer]: ['edge-light', 'browser', 'module', 'main'],
}

const reactDir = path.dirname(require.resolve('react/package.json'))
const reactDomDir = path.dirname(require.resolve('react-dom/package.json'))

const resolveConfig = {
const resolveConfig: webpack.Configuration['resolve'] = {
// Disable .mjs for node_modules bundling
extensions: isNodeServer
? ['.js', '.mjs', '.tsx', '.ts', '.jsx', '.json', '.wasm']
Expand Down Expand Up @@ -1022,6 +1022,7 @@ export default async function getBaseWebpackConfig(
}
: undefined),
mainFields: mainFieldsPerCompiler[compilerType],
...(isEdgeServer && { conditionNames: ['edge-light', 'import', 'node'] }),
plugins: [],
}

Expand Down Expand Up @@ -1723,7 +1724,13 @@ export default async function getBaseWebpackConfig(
return true
},
resolve: {
conditionNames: ['react-server', 'node', 'import', 'require'],
conditionNames: [
'react-server',
...(!isEdgeServer ? [] : ['edge-light']),
'node',
'import',
'require',
],
alias: {
// If missing the alias override here, the default alias will be used which aliases
// react to the direct file path, not the package name. In that case the condition
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import edgeLightPackage from 'my-edge-light-package'
import edgeLightPackageExports from 'my-edge-light-package-exports'

export const runtime = 'edge'

export default function AppDirPage() {
return (
<pre id="result">
{JSON.stringify({ edgeLightPackage, edgeLightPackageExports }, null, 2)}
</pre>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function RootLayout({ children }) {
return (
<html>
<head />
<body>{children}</body>
</html>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { createNextDescribe } from 'e2e-utils'

createNextDescribe(
'edge-runtime uses edge-light import specifier for packages',
{
files: __dirname,
packageJson: {
scripts: {
setup: 'cp -r ./node_modules_bak/* ./node_modules',
build: 'yarn setup && next build',
dev: 'yarn setup && next dev',
start: 'next start',
},
},
installCommand: 'yarn',
startCommand: (global as any).isNextDev ? 'yarn dev' : 'yarn start',
buildCommand: 'yarn build',
skipDeployment: true,
},
({ next }) => {
// In case you need to test the response object
it('pages/api endpoints import the correct module', async () => {
const res = await next.fetch('/api/edge')
const html = await res.json()
expect(html).toEqual({
edgeLightPackage: 'edge-light',
edgeLightPackageExports: 'edge-light',
})
})

it('pages import the correct module', async () => {
const $ = await next.render$('/')
const text = JSON.parse($('pre#result').text())
expect(text).toEqual({
edgeLightPackage: 'edge-light',
edgeLightPackageExports: 'edge-light',
})
})

it('app-dir imports the correct module', async () => {
const $ = await next.render$('/app-dir')
const text = JSON.parse($('pre#result').text())
expect(text).toEqual({
edgeLightPackage: 'edge-light',
edgeLightPackageExports: 'edge-light',
})
})
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
experimental: {
appDir: true,
},
}

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

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

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

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

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

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

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'edge-light'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'import'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "my-edge-light-package-exports",
"main": "./require.js",
"exports": {
"edge-light": "./edge-light.js",
"require": "./require.js",
"import": "./import.js"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'require'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'edge-light'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'import'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "my-edge-light-package",
"main": "./require.js",
"module": "./import.js",
"edge-light": "./edge-light.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'require'
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import edgeLightPackage from 'my-edge-light-package'
import edgeLightPackageExports from 'my-edge-light-package-exports'
import { NextResponse } from 'next/server'

export const config = { runtime: 'edge' }

export default function MyEdgeFunction() {
return NextResponse.json({
edgeLightPackage,
edgeLightPackageExports,
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import edgeLightPackage from 'my-edge-light-package'
import edgeLightPackageExports from 'my-edge-light-package-exports'

export const config = { runtime: 'experimental-edge' }

export default function Index() {
return (
<pre id="result">
{JSON.stringify({ edgeLightPackage, edgeLightPackageExports }, null, 2)}
</pre>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
content
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
},
experimental: {
outputFileTracingIncludes: {
'/index': ['include-me/*'],
'/index': ['include-me/**/*'],
},
outputFileTracingExcludes: {
'/index': ['public/exclude-me/**/*'],
Expand Down
11 changes: 11 additions & 0 deletions test/integration/build-trace-extra-entries/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ describe('build trace with extra entries', () => {
expect(
indexTrace.files.some((file) => file.endsWith('hello.json'))
).toBeFalsy()
expect(
indexTrace.files.some((file) => file.endsWith('some-dir'))
).toBeFalsy()
expect(
indexTrace.files.some((file) =>
file.endsWith('.dot-folder/another-file.txt')
)
).toBe(true)
expect(
indexTrace.files.some((file) => file.endsWith('some-dir/file.txt'))
).toBe(true)
expect(
indexTrace.files.some((file) => file.includes('some-cms/index.js'))
).toBe(true)
Expand Down

0 comments on commit b7cf55f

Please sign in to comment.