Unverified Commit 06130e80 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub
parent fbdbd453
import fs from 'fs'
import path from 'path'
export const dynamic = 'force-dynamic'
export async function GET() {
// dummy call
fs.readdirSync(path.join(process.cwd(), 'public/exclude-me'))
return new Response('foo')
}
import fs from 'fs'
import path from 'path'
const getCmsData = require('some-cms')
try {
fs.readdirSync(path.join(process.cwd(), 'public/exclude-me'))
} catch (_) {}
export function fetchData() {
return getCmsData()
}
import fs from 'fs'
import path from 'path'
export function getData() {
return JSON.parse(
fs.readFileSync(path.join(process.cwd(), 'content/hello.json'), 'utf8')
)
}
const path = require('path')
module.exports = {
webpack(cfg, { isServer, nextRuntime }) {
console.log(cfg.entry)
const origEntry = cfg.entry
cfg.entry = async () => {
const origEntries = await origEntry()
if (isServer && nextRuntime === 'nodejs') {
const curEntry = origEntries['pages/_app']
origEntries['pages/_app'] = [
path.join(__dirname, 'lib/get-data.js'),
...curEntry,
]
console.log(origEntries)
}
return origEntries
}
return cfg
},
outputFileTracingIncludes: {
'/index': ['include-me/*'],
'/route1': ['include-me/*'],
},
outputFileTracingExcludes: {
'/index': ['public/exclude-me/**/*'],
'/route1': ['public/exclude-me/**/*'],
},
}
function getCmsData() {
return 'hello'
}
module.exports = getCmsData
import 'nested-structure/constants'
export default function Page() {
return <p>another page</p>
}
export function getStaticProps() {
return {
props: {},
}
}
import fs from 'fs'
import path from 'path'
import Image from 'next/image'
import testImage from '../public/test.jpg'
export default function Page(props) {
return (
<div>
<Image src={testImage} placeholder="blur" alt="test" />
</div>
)
}
export function getServerSideProps() {
try {
// this should be included in the trace since it's not an
// import
fs.readFileSync(path.join(process.cwd(), 'public/another.jpg'))
} catch (_) {}
return {
props: {},
}
}
import { fetchData } from '../lib/fetch-data'
export default function Page() {
return 'index page'
}
export function getStaticProps() {
fetchData()
return {
props: {},
}
}
import path from 'path'
import { nextTestSetup } from 'e2e-utils'
describe('build trace with extra entries', () => {
describe('production mode', () => {
const { next, isTurbopack, skipped } = nextTestSetup({
files: path.join(__dirname, 'app'),
skipStart: true,
skipDeployment: true,
})
if (skipped) return
//
//
//
//
it('should build and trace correctly', async () => {
const { exitCode } = await next.build()
expect(exitCode).toBe(0)
const appTrace = JSON.parse(
await next.readFile('.next/server/pages/_app.js.nft.json')
)
const indexTrace = JSON.parse(
await next.readFile('.next/server/pages/index.js.nft.json')
)
const anotherTrace = JSON.parse(
await next.readFile('.next/server/pages/another.js.nft.json')
)
const imageTrace = JSON.parse(
await next.readFile('.next/server/pages/image-import.js.nft.json')
)
const appDirRoute1Trace = JSON.parse(
await next.readFile('.next/server/app/route1/route.js.nft.json')
)
expect(appDirRoute1Trace.files).toContain(
'../../../../include-me/hello.txt'
)
expect(appDirRoute1Trace.files).toContain(
'../../../../include-me/second.txt'
)
expect(
appDirRoute1Trace.files.some(
(file: string) => file === '../../../../include-me-global.txt'
)
).toBe(true)
expect(
appDirRoute1Trace.files.some((file: string) =>
file.includes('exclude-me')
)
).toBe(false)
expect(appDirRoute1Trace.files).toEqual(
expect.arrayContaining([
'../../../../node_modules/pkg-behind-symlink/index.js',
'../../../../node_modules/pkg-behind-symlink/package.json',
])
)
expect(
appDirRoute1Trace.files.some((file: string) =>
file.startsWith('../../../../node_modules/pkg/')
)
).toBe(false)
const tracedFiles = [
...appTrace.files,
...indexTrace.files,
...anotherTrace.files,
...imageTrace.files,
]
if (!isTurbopack) {
expect(
tracedFiles.some((file: string) => file.endsWith('hello.json'))
).toBe(true)
}
expect(
tracedFiles.some((file: string) => file.includes('some-cms/index.js'))
).toBe(true)
expect(
tracedFiles.some(
(file: string) => file === '../../../include-me/hello.txt'
)
).toBe(true)
expect(
tracedFiles.some(
(file: string) => file === '../../../include-me/second.txt'
)
).toBe(true)
if (isTurbopack) {
// A symlink matched by outputFileTracingIncludes is traced as the symlink itself, even
// when it points at a directory. Files reached through it are traced at their resolved
// paths so deployment includes both the link and its target contents.
// The webpack tracer globs with `nodir: true`, which drops directory symlinks, so this
// only applies to Turbopack.
expect(
tracedFiles.some(
(file: string) => file === '../../../include-me/link-to-dir'
)
).toBe(true)
expect(
tracedFiles.some(
(file: string) => file === '../../../content/hello.json'
)
).toBe(true)
expect(
tracedFiles.some(
(file: string) =>
file === '../../../include-me/link-to-dir/hello.json'
)
).toBe(false)
expect(
appDirRoute1Trace.files.some(
(file: string) => file === '../../../../include-me/link-to-dir'
)
).toBe(true)
expect(
appDirRoute1Trace.files.some(
(file: string) => file === '../../../../content/hello.json'
)
).toBe(true)
}
expect(
indexTrace.files.some((file: string) => file.includes('exclude-me'))
).toBe(false)
expect(
tracedFiles.some((file: string) =>
file.includes('nested-structure/constants/package.json')
)
).toBe(true)
expect(
tracedFiles.some((file: string) =>
file.includes('nested-structure/package.json')
)
).toBe(true)
expect(
tracedFiles.some((file: string) =>
file.includes('nested-structure/dist/constants.js')
)
).toBe(true)
expect(
tracedFiles.some((file: string) => file.includes('public/another.jpg'))
).toBe(true)
expect(
tracedFiles.some((file: string) => file.includes('public/test.jpg'))
).toBe(false)
})
})
})
...@@ -63,6 +63,46 @@ describe('build trace with extra entries', () => { ...@@ -63,6 +63,46 @@ describe('build trace with extra entries', () => {
) )
).toBe(false) ).toBe(false)
if (isTurbopack) {
// A symlink matched by outputFileTracingIncludes is traced as the symlink itself, even
// when it points at a directory. Files reached through it are traced at their resolved
// paths so deployment includes both the link and its target contents.
// The webpack tracer globs with `nodir: true`, which drops directory symlinks, so this
// only applies to Turbopack.
const tracedFiles = [
...appTrace.files,
...indexTrace.files,
...anotherTrace.files,
...imageTrace.files,
]
expect(
tracedFiles.some(
(file: string) => file === '../../../include-me/link-to-dir'
)
).toBe(true)
expect(
tracedFiles.some(
(file: string) => file === '../../../content/hello.json'
)
).toBe(true)
expect(
tracedFiles.some(
(file: string) =>
file === '../../../include-me/link-to-dir/hello.json'
)
).toBe(false)
expect(
appDirRoute1Trace.files.some(
(file: string) => file === '../../../../include-me/link-to-dir'
)
).toBe(true)
expect(
appDirRoute1Trace.files.some(
(file: string) => file === '../../../../content/hello.json'
)
).toBe(true)
}
expect( expect(
indexTrace.files.filter( indexTrace.files.filter(
(file: string) => file.includes('chunks') && file.endsWith('.js') (file: string) => file.includes('chunks') && file.endsWith('.js')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment