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

Fix tracing edge-runtime dependencies #39009

Merged
merged 6 commits into from Jul 26, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/next/build/utils.ts
Expand Up @@ -1148,7 +1148,6 @@ export async function copyTracedFiles(
const symlink = await fs.readlink(tracedFilePath).catch(() => null)

if (symlink) {
console.log('symlink', path.relative(tracingRoot, symlink))
await fs.symlink(symlink, fileOutputPath)
} else {
await fs.copyFile(tracedFilePath, fileOutputPath)
Expand Down
2 changes: 1 addition & 1 deletion packages/next/compiled/edge-runtime/index.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions packages/next/taskfile.js
Expand Up @@ -296,6 +296,15 @@ export async function ncc_edge_runtime(task, opts) {
.source(opts.src || relative(__dirname, require.resolve('edge-runtime')))
.ncc({ packageName: 'edge-runtime', externals })
.target('compiled/edge-runtime')

const outputFile = join(__dirname, 'compiled/edge-runtime/index.js')

await fs.writeFile(
outputFile,
(
await fs.readFile(outputFile, 'utf8')
).replace(/eval\("require"\)/g, 'require')
)
}

// eslint-disable-next-line camelcase
Expand Down
34 changes: 34 additions & 0 deletions test/production/required-server-files.test.ts
Expand Up @@ -1243,4 +1243,38 @@ describe('should set-up next', () => {
expect(envVariables.envProd).not.toBeUndefined()
expect(envVariables.envLocal).toBeUndefined()
})

it('should run middleware correctly without minimalMode', async () => {
await killApp(server)
const testServer = join(next.testDir, 'standalone/server.js')
await fs.writeFile(
testServer,
(
await fs.readFile(testServer, 'utf8')
).replace('minimalMode: true', 'minimalMode: false')
)
appPort = await findPort()
server = await initNextServerScript(
testServer,
/Listening on/,
{
...process.env,
PORT: appPort,
},
undefined,
{
cwd: next.testDir,
onStderr(msg) {
if (msg.includes('top-level')) {
errors.push(msg)
}
stderr += msg
},
}
)

const res = await fetchViaHTTP(appPort, '/')
expect(res.status).toBe(200)
expect(await res.text()).toContain('index page')
})
})
1 change: 1 addition & 0 deletions test/production/required-server-files/middleware.js
@@ -1,5 +1,6 @@
import { NextResponse } from 'next/server'

export async function middleware(req) {
console.log('middleware', req.url)
return NextResponse.next()
}