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

Revert "feat(turbopack): support next.js specific node polyfills" #55385

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 0 additions & 6 deletions packages/next-swc/crates/next-core/src/next_import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,12 +661,6 @@ 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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use client'

export default function Component() {
return (
<div id="client">
{Buffer.from('Hello Client Component', 'utf-8').toString()}
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Component from './client'

export default function Page() {
return (
<div id="server">
{Buffer.from('Hello Server Component', 'utf-8').toString()}
<Component />
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function RootLayout({ children }: { children: any }) {
return (
<html>
<body>{children}</body>
</html>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { useRef } from 'react'
import { Harness, useTestHarness } from '@turbo/pack-test-harness'

export default function Page() {
const pageIframeRef = useRef<HTMLIFrameElement | null>(null)
const appIframeRef = useRef<HTMLIFrameElement | null>(null)

useTestHarness((mod) =>
runTests(mod, pageIframeRef.current!, appIframeRef.current)
)

return (
<>
<iframe
style={{ width: 800, height: 600 }}
src="/app"
ref={appIframeRef}
/>
<iframe
style={{ width: 800, height: 600 }}
src="/page"
ref={pageIframeRef}
/>
</>
)
}

function runTests(
harness: Harness,
page: HTMLIFrameElement,
app: HTMLIFrameElement
) {
const TIMEOUT = 30000

it(
'should support Buffer on pages',
async () => {
await harness.waitForLoaded(page)
const server = await harness.waitForSelector(page, '#server')
expect(server.innerHTML).toContain('Hello Server Page')
const client = await harness.waitForSelector(page, '#client')
expect(client.innerHTML).toContain('Hello Client Page')
},
TIMEOUT
)

it(
'should support Buffer on app',
async () => {
await harness.waitForLoaded(app)
const server = await harness.waitForSelector(app, '#server')
expect(server.innerHTML).toContain('Hello Server Component')
const client = await harness.waitForSelector(app, '#client')
expect(client.innerHTML).toContain('Hello Client Component')
},
TIMEOUT
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useEffect, useState } from 'react'

export default function Page() {
const [state, setState] = useState('SSR')
useEffect(() => {
setState(
<div id="client">
{Buffer.from('Hello Client Page', 'utf-8').toString()}
</div>
)
}, [setState])
return (
<div>
<div id="server">
{Buffer.from('Hello Server Page', 'utf-8').toString()}
</div>
{state}
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
warning - [parse] [project]/packages/next/dist/server/lib/node-fs-methods.js /packages/next/dist/server/lib/node-fs-methods.js:18:19 lint TP1004 fs.readFile(???*0*) is very dynamic
14 | default: obj
15 | };
16 | }
17 | const nodeFs = {
+ v
18 + readFile: (f)=>_fs.default.promises.readFile(f),
+ ^
19 | readFileSync: (f)=>_fs.default.readFileSync(f),
20 | writeFile: (f, d)=>_fs.default.promises.writeFile(f, d),
21 | mkdir: (dir)=>_fs.default.promises.mkdir(dir, {
22 | recursive: true

- *0* f
⚠️ pattern without value
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
warning - [parse] [project]/packages/next/dist/server/lib/node-fs-methods.js /packages/next/dist/server/lib/node-fs-methods.js:18:19 lint TP1004 fs.readFile(???*0*) is very dynamic
14 | default: obj
15 | };
16 | }
17 | const nodeFs = {
+ v
18 + readFile: (f)=>_fs.default.promises.readFile(f),
+ ^
19 | readFileSync: (f)=>_fs.default.readFileSync(f),
20 | writeFile: (f, d)=>_fs.default.promises.writeFile(f, d),
21 | mkdir: (dir)=>_fs.default.promises.mkdir(dir, {
22 | recursive: true

- *0* f
⚠️ pattern without value
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
warning - [parse] [project]/packages/next/dist/server/lib/node-fs-methods.js /packages/next/dist/server/lib/node-fs-methods.js:19:23 lint TP1004 fs.readFileSync(???*0*) is very dynamic
15 | };
16 | }
17 | const nodeFs = {
18 | readFile: (f)=>_fs.default.promises.readFile(f),
+ v
19 + readFileSync: (f)=>_fs.default.readFileSync(f),
+ ^
20 | writeFile: (f, d)=>_fs.default.promises.writeFile(f, d),
21 | mkdir: (dir)=>_fs.default.promises.mkdir(dir, {
22 | recursive: true
23 | }),

- *0* f
⚠️ pattern without value
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
warning - [parse] [project]/packages/next/dist/server/lib/node-fs-methods.js /packages/next/dist/server/lib/node-fs-methods.js:19:23 lint TP1004 fs.readFileSync(???*0*) is very dynamic
15 | };
16 | }
17 | const nodeFs = {
18 | readFile: (f)=>_fs.default.promises.readFile(f),
+ v
19 + readFileSync: (f)=>_fs.default.readFileSync(f),
+ ^
20 | writeFile: (f, d)=>_fs.default.promises.writeFile(f, d),
21 | mkdir: (dir)=>_fs.default.promises.mkdir(dir, {
22 | recursive: true
23 | }),

- *0* f
⚠️ pattern without value
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
warning - [parse] [project]/packages/next/dist/server/lib/node-fs-methods.js /packages/next/dist/server/lib/node-fs-methods.js:24:15 lint TP1004 fs.stat(???*0*) is very dynamic
20 | writeFile: (f, d)=>_fs.default.promises.writeFile(f, d),
21 | mkdir: (dir)=>_fs.default.promises.mkdir(dir, {
22 | recursive: true
23 | }),
+ v
24 + stat: (f)=>_fs.default.promises.stat(f)
+ ^
25 | };
26 |
27 | //# sourceMappingURL=node-fs-methods.js.map

- *0* f
⚠️ pattern without value
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
warning - [parse] [project]/packages/next/dist/server/lib/node-fs-methods.js /packages/next/dist/server/lib/node-fs-methods.js:24:15 lint TP1004 fs.stat(???*0*) is very dynamic
20 | writeFile: (f, d)=>_fs.default.promises.writeFile(f, d),
21 | mkdir: (dir)=>_fs.default.promises.mkdir(dir, {
22 | recursive: true
23 | }),
+ v
24 + stat: (f)=>_fs.default.promises.stat(f)
+ ^
25 | };
26 |
27 | //# sourceMappingURL=node-fs-methods.js.map

- *0* f
⚠️ pattern without value
12 changes: 0 additions & 12 deletions test/development/basic/node-builtins/app/layout.js

This file was deleted.

1 change: 0 additions & 1 deletion test/turbopack-tests-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const enabledTests = [
'test/development/basic/emotion-swc.test.ts',
'test/development/basic/legacy-decorators.test.ts',
'test/development/basic/misc.test.ts',
'test/development/basic/node-builtins.test.ts',
'test/development/basic/next-rs-api.test.ts',
'test/development/basic/tailwind-jit.test.ts',
'test/development/basic/theme-ui.test.ts',
Expand Down