Skip to content

Commit 9291211

Browse files
Merge branch 'canary' into wbinnssmith/rm-flatmap
2 parents 290c1a7 + 7a08f00 commit 9291211

File tree

2 files changed

+48
-11
lines changed

2 files changed

+48
-11
lines changed

packages/next/src/build/collect-build-traces.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,16 @@ export async function collectBuildTraces({
233233
})
234234
}
235235
}
236-
const ignores = [
236+
const serverIgnores = [
237237
'**/*.d.ts',
238238
'**/*.map',
239239
isStandalone ? null : '**/next/dist/compiled/jest-worker/**/*',
240240
'**/next/dist/compiled/webpack/(bundle4|bundle5).js',
241241
'**/node_modules/webpack5/**/*',
242242
'**/next/dist/server/lib/squoosh/**/*.wasm',
243243
'**/next/dist/server/lib/route-resolver*',
244+
'**/next/dist/pages/**/*',
245+
244246
...(ciEnvironment.hasNextSupport
245247
? [
246248
// only ignore image-optimizer code when
@@ -261,12 +263,12 @@ export async function collectBuildTraces({
261263
...(config.experimental.outputFileTracingIgnores || []),
262264
].filter(nonNullable)
263265

264-
const ignoreFn = (pathname: string) => {
266+
const serverIgnoreFn = (pathname: string) => {
265267
if (path.isAbsolute(pathname) && !pathname.startsWith(root)) {
266268
return true
267269
}
268270

269-
return isMatch(pathname, ignores, {
271+
return isMatch(pathname, serverIgnores, {
270272
contains: true,
271273
dot: true,
272274
})
@@ -321,7 +323,7 @@ export async function collectBuildTraces({
321323
[minimalServerTracedFiles, minimalFiles],
322324
] as [Set<string>, string[]][]) {
323325
for (const file of files) {
324-
if (!ignoreFn(path.join(traceContext, file))) {
326+
if (!serverIgnoreFn(path.join(traceContext, file))) {
325327
addToTracedFiles(traceContext, file, set)
326328
}
327329
}
@@ -336,7 +338,6 @@ export async function collectBuildTraces({
336338
const result = await nodeFileTrace(chunksToTrace, {
337339
base: outputFileTracingRoot,
338340
processCwd: dir,
339-
ignore: ignoreFn,
340341
mixedModules: true,
341342
})
342343
const reasons = result.reasons
@@ -360,12 +361,7 @@ export async function collectBuildTraces({
360361
for (const curFile of curFiles || []) {
361362
const filePath = path.join(outputFileTracingRoot, curFile)
362363

363-
if (
364-
!isMatch(filePath, '**/next/dist/pages/**/*', {
365-
dot: true,
366-
contains: true,
367-
})
368-
) {
364+
if (!serverIgnoreFn(filePath)) {
369365
tracedFiles.add(
370366
path.relative(distDir, filePath).replace(/\\/g, '/')
371367
)

test/integration/image-optimizer/test/util.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,28 @@ export function runTests(ctx) {
147147
slowImageServer.stop()
148148
})
149149

150+
if (!isDev && ctx.isSharp && ctx.nextConfigImages) {
151+
it('should handle custom sharp usage', async () => {
152+
const res = await fetchViaHTTP(ctx.appPort, '/api/custom-sharp')
153+
154+
expect(res.status).toBe(200)
155+
expect(await res.json()).toEqual({ success: true })
156+
const traceFile = await fs.readJson(
157+
join(
158+
ctx.appDir,
159+
'.next',
160+
'server',
161+
'pages',
162+
'api',
163+
'custom-sharp.js.nft.json'
164+
)
165+
)
166+
expect(traceFile.files.some((file) => file.includes('sharp/build'))).toBe(
167+
true
168+
)
169+
})
170+
}
171+
150172
if (domains.length > 0) {
151173
it('should normalize invalid status codes', async () => {
152174
const url = `http://localhost:${
@@ -1435,6 +1457,20 @@ export const setupTests = (ctx) => {
14351457
})
14361458
curCtx.nextOutput = ''
14371459
nextConfig.replace('{ /* replaceme */ }', json)
1460+
1461+
if (curCtx.isSharp) {
1462+
await fs.writeFile(
1463+
join(curCtx.appDir, 'pages', 'api', 'custom-sharp.js'),
1464+
`
1465+
import sharp from 'sharp'
1466+
export default function handler(req, res) {
1467+
console.log(sharp)
1468+
res.json({ success: true })
1469+
}
1470+
`
1471+
)
1472+
}
1473+
14381474
await nextBuild(curCtx.appDir)
14391475
await cleanImagesDir(ctx)
14401476
curCtx.appPort = await findPort()
@@ -1452,6 +1488,11 @@ export const setupTests = (ctx) => {
14521488
})
14531489
afterAll(async () => {
14541490
nextConfig.restore()
1491+
if (curCtx.isSharp) {
1492+
await fs.remove(
1493+
join(curCtx.appDir, 'pages', 'api', 'custom-sharp.js')
1494+
)
1495+
}
14551496
if (curCtx.app) await killApp(curCtx.app)
14561497
})
14571498

0 commit comments

Comments
 (0)