From 67bc262b67504eecdeba6cd0d1ac4a02be73b0d8 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Thu, 14 Sep 2023 17:32:29 +0200 Subject: [PATCH] Revert "Revert "feat(turbopack): support next.js specific node polyfills"" (#55392) Reverts vercel/next.js#55385 Closes WEB-1565 --- .../crates/next-core/src/next_import_map.rs | 6 ++ .../polyfill/basic/input/app/app/client.tsx | 9 --- .../polyfill/basic/input/app/app/page.tsx | 10 ---- .../next/polyfill/basic/input/app/layout.tsx | 7 --- .../next/polyfill/basic/input/pages/index.tsx | 58 ------------------- .../next/polyfill/basic/input/pages/page.tsx | 20 ------- ...File(__q____q____q____star__0__-1ea14a.txt | 15 ----- ...File(__q____q____q____star__0__-9b3c3c.txt | 15 ----- ...FileSync(__q____q____q____star_-0b346e.txt | 15 ----- ...FileSync(__q____q____q____star_-c0b6ea.txt | 15 ----- ...(__q____q____q____star__0__star-05f14f.txt | 14 ----- ...(__q____q____q____star__0__star-a12dc8.txt | 14 ----- .../basic/node-builtins/app/layout.js | 12 ++++ test/turbopack-tests-manifest.js | 1 + 14 files changed, 19 insertions(+), 192 deletions(-) delete mode 100644 packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/app/client.tsx delete mode 100644 packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/app/page.tsx delete mode 100644 packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/layout.tsx delete mode 100644 packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/pages/index.tsx delete mode 100644 packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/pages/page.tsx delete mode 100644 packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.readFile(__q____q____q____star__0__-1ea14a.txt delete mode 100644 packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.readFile(__q____q____q____star__0__-9b3c3c.txt delete mode 100644 packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.readFileSync(__q____q____q____star_-0b346e.txt delete mode 100644 packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.readFileSync(__q____q____q____star_-c0b6ea.txt delete mode 100644 packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.stat(__q____q____q____star__0__star-05f14f.txt delete mode 100644 packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/issues/lint TP1004 fs.stat(__q____q____q____star__0__star-a12dc8.txt create mode 100644 test/development/basic/node-builtins/app/layout.js diff --git a/packages/next-swc/crates/next-core/src/next_import_map.rs b/packages/next-swc/crates/next-core/src/next_import_map.rs index 87ef801b78415..93572d8a68a90 100644 --- a/packages/next-swc/crates/next-core/src/next_import_map.rs +++ b/packages/next-swc/crates/next-core/src/next_import_map.rs @@ -661,6 +661,12 @@ pub async fn insert_next_shared_aliases( import_map.insert_singleton_alias("react", project_path); import_map.insert_singleton_alias("react-dom", project_path); + //https://github.com/vercel/next.js/blob/f94d4f93e4802f951063cfa3351dd5a2325724b3/packages/next/src/build/webpack-config.ts#L1196 + import_map.insert_exact_alias( + "setimmediate", + request_to_import_mapping(project_path, "next/dist/compiled/setimmediate"), + ); + insert_turbopack_dev_alias(import_map); insert_package_alias( import_map, diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/app/client.tsx b/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/app/client.tsx deleted file mode 100644 index 749f91bbf2ffd..0000000000000 --- a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/app/client.tsx +++ /dev/null @@ -1,9 +0,0 @@ -'use client' - -export default function Component() { - return ( -
- {Buffer.from('Hello Client Component', 'utf-8').toString()} -
- ) -} diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/app/page.tsx b/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/app/page.tsx deleted file mode 100644 index 64b66b231eb5e..0000000000000 --- a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/app/page.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import Component from './client' - -export default function Page() { - return ( -
- {Buffer.from('Hello Server Component', 'utf-8').toString()} - -
- ) -} diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/layout.tsx b/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/layout.tsx deleted file mode 100644 index 12c84680889be..0000000000000 --- a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/app/layout.tsx +++ /dev/null @@ -1,7 +0,0 @@ -export default function RootLayout({ children }: { children: any }) { - return ( - - {children} - - ) -} diff --git a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/pages/index.tsx b/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/pages/index.tsx deleted file mode 100644 index 7a12e89221ac3..0000000000000 --- a/packages/next-swc/crates/next-dev-tests/tests/integration/next/polyfill/basic/input/pages/index.tsx +++ /dev/null @@ -1,58 +0,0 @@ -import { useRef } from 'react' -import { Harness, useTestHarness } from '@turbo/pack-test-harness' - -export default function Page() { - const pageIframeRef = useRef(null) - const appIframeRef = useRef(null) - - useTestHarness((mod) => - runTests(mod, pageIframeRef.current!, appIframeRef.current) - ) - - return ( - <> -