From f3b231ccf1fb632640858de47a568892204bcb5c Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Thu, 16 Feb 2023 12:45:08 -0800 Subject: [PATCH 1/3] Fix folders included in trace (#46011) We should not include directories themselves in the trace files so this ensures they are excluded and adds a test case for this. x-ref: [slack thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1676568891229219?thread_ts=1676543026.736539&cid=C03S8ED1DKM) ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) --- packages/next/src/build/index.ts | 14 +++++++++----- .../app/include-me/.dot-folder/another-file.txt | 1 + .../app/include-me/some-dir/file.txt | 1 + .../build-trace-extra-entries/app/next.config.js | 2 +- .../build-trace-extra-entries/test/index.test.js | 11 +++++++++++ 5 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 test/integration/build-trace-extra-entries/app/include-me/.dot-folder/another-file.txt create mode 100644 test/integration/build-trace-extra-entries/app/include-me/some-dir/file.txt diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index fa3a28bbd6329..4dbabf4165a9e 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -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 => { 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) - }) + ) }) } diff --git a/test/integration/build-trace-extra-entries/app/include-me/.dot-folder/another-file.txt b/test/integration/build-trace-extra-entries/app/include-me/.dot-folder/another-file.txt new file mode 100644 index 0000000000000..b6fc4c620b67d --- /dev/null +++ b/test/integration/build-trace-extra-entries/app/include-me/.dot-folder/another-file.txt @@ -0,0 +1 @@ +hello \ No newline at end of file diff --git a/test/integration/build-trace-extra-entries/app/include-me/some-dir/file.txt b/test/integration/build-trace-extra-entries/app/include-me/some-dir/file.txt new file mode 100644 index 0000000000000..6b584e8ece562 --- /dev/null +++ b/test/integration/build-trace-extra-entries/app/include-me/some-dir/file.txt @@ -0,0 +1 @@ +content \ No newline at end of file diff --git a/test/integration/build-trace-extra-entries/app/next.config.js b/test/integration/build-trace-extra-entries/app/next.config.js index c9f5e197007b5..37dc43828fe2f 100644 --- a/test/integration/build-trace-extra-entries/app/next.config.js +++ b/test/integration/build-trace-extra-entries/app/next.config.js @@ -21,7 +21,7 @@ module.exports = { }, experimental: { outputFileTracingIncludes: { - '/index': ['include-me/*'], + '/index': ['include-me/**/*'], }, outputFileTracingExcludes: { '/index': ['public/exclude-me/**/*'], diff --git a/test/integration/build-trace-extra-entries/test/index.test.js b/test/integration/build-trace-extra-entries/test/index.test.js index 1513257a629d5..e14cc432195f4 100644 --- a/test/integration/build-trace-extra-entries/test/index.test.js +++ b/test/integration/build-trace-extra-entries/test/index.test.js @@ -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) From 282c1a06372c79b173bb5fbccde7c8bb3f87aa92 Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Thu, 16 Feb 2023 23:30:34 +0200 Subject: [PATCH 2/3] [edge] support edge-light exports when bundling edge functions (#45188) This PR implements `edge-light` as a main field for bundling edge functions as defined in https://runtime-keys.proposal.wintercg.org Resolves EC-614 ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) --------- --- packages/next/src/build/webpack-config.ts | 13 +++-- .../app/app-dir/page.js | 12 +++++ .../app/layout.js | 8 +++ ...ight-import-specifier-for-packages.test.ts | 49 +++++++++++++++++++ .../next.config.js | 5 ++ .../edge-light.js | 1 + .../my-edge-light-package-exports/import.js | 1 + .../package.json | 9 ++++ .../my-edge-light-package-exports/require.js | 1 + .../my-edge-light-package/edge-light.js | 1 + .../my-edge-light-package/import.js | 1 + .../my-edge-light-package/package.json | 6 +++ .../my-edge-light-package/require.js | 1 + .../edge-light.js | 1 + .../my-edge-light-package-exports/import.js | 1 + .../package.json | 9 ++++ .../my-edge-light-package-exports/require.js | 1 + .../my-edge-light-package/edge-light.js | 1 + .../my-edge-light-package/import.js | 1 + .../my-edge-light-package/package.json | 6 +++ .../my-edge-light-package/require.js | 1 + .../pages/api/edge.js | 12 +++++ .../pages/index.js | 12 +++++ 23 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/app/app-dir/page.js create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/app/layout.js create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/edge-runtime-uses-edge-light-import-specifier-for-packages.test.ts create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/next.config.js create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package-exports/edge-light.js create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package-exports/import.js create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package-exports/package.json create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package-exports/require.js create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package/edge-light.js create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package/import.js create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package/package.json create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package/require.js create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package-exports/edge-light.js create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package-exports/import.js create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package-exports/package.json create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package-exports/require.js create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package/edge-light.js create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package/import.js create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package/package.json create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package/require.js create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/pages/api/edge.js create mode 100644 test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/pages/index.js diff --git a/packages/next/src/build/webpack-config.ts b/packages/next/src/build/webpack-config.ts index 2cc7341cad837..9b1a0bbf76509 100644 --- a/packages/next/src/build/webpack-config.ts +++ b/packages/next/src/build/webpack-config.ts @@ -903,13 +903,13 @@ export default async function getBaseWebpackConfig( const mainFieldsPerCompiler: Record = { [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'] @@ -1022,6 +1022,7 @@ export default async function getBaseWebpackConfig( } : undefined), mainFields: mainFieldsPerCompiler[compilerType], + ...(isEdgeServer && { conditionNames: ['edge-light', 'import', 'node'] }), plugins: [], } @@ -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 diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/app/app-dir/page.js b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/app/app-dir/page.js new file mode 100644 index 0000000000000..e3987339c6b12 --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/app/app-dir/page.js @@ -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 ( +
+      {JSON.stringify({ edgeLightPackage, edgeLightPackageExports }, null, 2)}
+    
+ ) +} diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/app/layout.js b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/app/layout.js new file mode 100644 index 0000000000000..6d7e1ed585862 --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/app/layout.js @@ -0,0 +1,8 @@ +export default function RootLayout({ children }) { + return ( + + + {children} + + ) +} diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/edge-runtime-uses-edge-light-import-specifier-for-packages.test.ts b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/edge-runtime-uses-edge-light-import-specifier-for-packages.test.ts new file mode 100644 index 0000000000000..b611fcc722147 --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/edge-runtime-uses-edge-light-import-specifier-for-packages.test.ts @@ -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', + }) + }) + } +) diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/next.config.js b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/next.config.js new file mode 100644 index 0000000000000..cfa3ac3d7aa94 --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/next.config.js @@ -0,0 +1,5 @@ +module.exports = { + experimental: { + appDir: true, + }, +} diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package-exports/edge-light.js b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package-exports/edge-light.js new file mode 100644 index 0000000000000..0cc6ebe9ad550 --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package-exports/edge-light.js @@ -0,0 +1 @@ +export default 'edge-light' diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package-exports/import.js b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package-exports/import.js new file mode 100644 index 0000000000000..b4dd8a6c96d5f --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package-exports/import.js @@ -0,0 +1 @@ +export default 'import' diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package-exports/package.json b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package-exports/package.json new file mode 100644 index 0000000000000..2efc88f080b74 --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package-exports/package.json @@ -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" + } +} diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package-exports/require.js b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package-exports/require.js new file mode 100644 index 0000000000000..67b9a8353c0b1 --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package-exports/require.js @@ -0,0 +1 @@ +module.exports = 'require' diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package/edge-light.js b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package/edge-light.js new file mode 100644 index 0000000000000..0cc6ebe9ad550 --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package/edge-light.js @@ -0,0 +1 @@ +export default 'edge-light' diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package/import.js b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package/import.js new file mode 100644 index 0000000000000..b4dd8a6c96d5f --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package/import.js @@ -0,0 +1 @@ +export default 'import' diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package/package.json b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package/package.json new file mode 100644 index 0000000000000..766d89b595ffc --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package/package.json @@ -0,0 +1,6 @@ +{ + "name": "my-edge-light-package", + "main": "./require.js", + "module": "./import.js", + "edge-light": "./edge-light.js" +} diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package/require.js b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package/require.js new file mode 100644 index 0000000000000..67b9a8353c0b1 --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules/my-edge-light-package/require.js @@ -0,0 +1 @@ +module.exports = 'require' diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package-exports/edge-light.js b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package-exports/edge-light.js new file mode 100644 index 0000000000000..0cc6ebe9ad550 --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package-exports/edge-light.js @@ -0,0 +1 @@ +export default 'edge-light' diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package-exports/import.js b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package-exports/import.js new file mode 100644 index 0000000000000..b4dd8a6c96d5f --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package-exports/import.js @@ -0,0 +1 @@ +export default 'import' diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package-exports/package.json b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package-exports/package.json new file mode 100644 index 0000000000000..2efc88f080b74 --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package-exports/package.json @@ -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" + } +} diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package-exports/require.js b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package-exports/require.js new file mode 100644 index 0000000000000..67b9a8353c0b1 --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package-exports/require.js @@ -0,0 +1 @@ +module.exports = 'require' diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package/edge-light.js b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package/edge-light.js new file mode 100644 index 0000000000000..0cc6ebe9ad550 --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package/edge-light.js @@ -0,0 +1 @@ +export default 'edge-light' diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package/import.js b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package/import.js new file mode 100644 index 0000000000000..b4dd8a6c96d5f --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package/import.js @@ -0,0 +1 @@ +export default 'import' diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package/package.json b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package/package.json new file mode 100644 index 0000000000000..766d89b595ffc --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package/package.json @@ -0,0 +1,6 @@ +{ + "name": "my-edge-light-package", + "main": "./require.js", + "module": "./import.js", + "edge-light": "./edge-light.js" +} diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package/require.js b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package/require.js new file mode 100644 index 0000000000000..67b9a8353c0b1 --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/node_modules_bak/my-edge-light-package/require.js @@ -0,0 +1 @@ +module.exports = 'require' diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/pages/api/edge.js b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/pages/api/edge.js new file mode 100644 index 0000000000000..531d4a9d46ee1 --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/pages/api/edge.js @@ -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, + }) +} diff --git a/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/pages/index.js b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/pages/index.js new file mode 100644 index 0000000000000..81d7434c2fd6a --- /dev/null +++ b/test/e2e/edge-runtime-uses-edge-light-import-specifier-for-packages/pages/index.js @@ -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 ( +
+      {JSON.stringify({ edgeLightPackage, edgeLightPackageExports }, null, 2)}
+    
+ ) +} From c55345267e44b20a7a85926501308a1afe94cc9a Mon Sep 17 00:00:00 2001 From: Andrii Bodnar <29282228+andrii-bodnar@users.noreply.github.com> Date: Fri, 17 Feb 2023 00:15:53 +0200 Subject: [PATCH 3/3] chore(examples): update with-lingui example (#46007) This PR updates the `with-lingui` example's dependencies and the actual Lingui site URL ## Documentation / Examples - [x] Make sure the linting passes by running `pnpm build && pnpm lint` - [x] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md) --- docs/advanced-features/i18n-routing.md | 2 +- examples/with-lingui/README.md | 4 ++-- examples/with-lingui/locale/en/messages.po | 4 ++-- examples/with-lingui/locale/sv/messages.po | 4 ++-- examples/with-lingui/package.json | 14 +++++++------- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/advanced-features/i18n-routing.md b/docs/advanced-features/i18n-routing.md index c1daba16eb951..6ef388b60856c 100644 --- a/docs/advanced-features/i18n-routing.md +++ b/docs/advanced-features/i18n-routing.md @@ -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 diff --git a/examples/with-lingui/README.md b/examples/with-lingui/README.md index 3a4499a00c415..262d5a9c38ac6 100644 --- a/examples/with-lingui/README.md +++ b/examples/with-lingui/README.md @@ -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. @@ -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) `` 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) `` and then run `yarn export` to export the messages into `locale/{language}/messages.po`. ### How to add another language diff --git a/examples/with-lingui/locale/en/messages.po b/examples/with-lingui/locale/en/messages.po index 6739f174063db..557f024a0c066 100644 --- a/examples/with-lingui/locale/en/messages.po +++ b/examples/with-lingui/locale/en/messages.po @@ -13,7 +13,7 @@ msgstr "" "Language-Team: \n" "Plural-Forms: \n" -#: pages/two.js:9 +#: pages/two.js:8 msgid "Back home" msgstr "Back home" @@ -21,7 +21,7 @@ msgstr "Back home" msgid "English" msgstr "English" -#: pages/index.js:9 +#: pages/index.js:8 msgid "Go to page 2" msgstr "Go to page 2" diff --git a/examples/with-lingui/locale/sv/messages.po b/examples/with-lingui/locale/sv/messages.po index 94b478891fd1e..e2a8bcfd3d567 100644 --- a/examples/with-lingui/locale/sv/messages.po +++ b/examples/with-lingui/locale/sv/messages.po @@ -13,7 +13,7 @@ msgstr "" "Language-Team: \n" "Plural-Forms: \n" -#: pages/two.js:9 +#: pages/two.js:8 msgid "Back home" msgstr "Tillbaka hem" @@ -21,7 +21,7 @@ msgstr "Tillbaka hem" msgid "English" msgstr "Engelska" -#: pages/index.js:9 +#: pages/index.js:8 msgid "Go to page 2" msgstr "Gå till sida 2" diff --git a/examples/with-lingui/package.json b/examples/with-lingui/package.json index 6e69c36f98b40..ce899deb7fec8 100644 --- a/examples/with-lingui/package.json +++ b/examples/with-lingui/package.json @@ -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" } }