Skip to content

Commit 7c70436

Browse files
authored
Turbopack: don't include AMP optimizer in NFT (#77242)
Webpack has this in the NFT ignore list, but [Turbopack doesn't support AMP at all](https://nextjs.org/docs/app/api-reference/turbopack#unsupported-and-unplanned-features). So just completely disable that code path so that it also doesn't get included in NFT and upload unnecessary files to the server. Also disables all not-already disabled AMP tests for Turbopack
1 parent 3ab033d commit 7c70436

File tree

7 files changed

+344
-374
lines changed

7 files changed

+344
-374
lines changed

packages/next/src/server/post-process.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async function postProcessHTML(
2121
{ inAmpMode, hybridAmp }: { inAmpMode: boolean; hybridAmp: boolean }
2222
) {
2323
const postProcessors: Array<PostProcessorFunction> = [
24-
process.env.NEXT_RUNTIME !== 'edge' && inAmpMode
24+
process.env.NEXT_RUNTIME !== 'edge' && inAmpMode && !process.env.TURBOPACK
2525
? async (html: string) => {
2626
const optimizeAmp = require('./optimize-amp')
2727
.default as typeof import('./optimize-amp').default

test/integration/amp-export-validation/test/index.test.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ const nextConfig = new File(join(appDir, 'next.config.js'))
1212

1313
let buildOutput
1414

15-
describe('AMP Validation on Export', () => {
16-
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
17-
'production mode',
18-
() => {
15+
// Turbopack does not support AMP rendering.
16+
;(process.env.TURBOPACK ? describe.skip : describe)(
17+
'AMP Validation on Export',
18+
() => {
19+
describe('production mode', () => {
1920
beforeAll(async () => {
2021
const { stdout = '', stderr = '' } = await nextBuild(appDir, [], {
2122
stdout: true,
@@ -120,6 +121,6 @@ describe('AMP Validation on Export', () => {
120121
nextConfig.restore()
121122
}
122123
})
123-
}
124-
)
125-
})
124+
})
125+
}
126+
)

test/integration/amphtml-custom-optimizer/test/index.test.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ let app
1313
let appPort
1414
const appDir = join(__dirname, '../')
1515

16-
describe('AMP Custom Optimizer', () => {
17-
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
18-
'production mode',
19-
() => {
16+
// Turbopack does not support AMP rendering.
17+
;(process.env.TURBOPACK ? describe.skip : describe)(
18+
'AMP Custom Optimizer',
19+
() => {
20+
describe('production mode', () => {
2021
it('should build and start for static page', async () => {
2122
const { code } = await nextBuild(appDir)
2223
expect(code).toBe(0)
@@ -54,6 +55,6 @@ describe('AMP Custom Optimizer', () => {
5455
'script async src="https://cdn.ampproject.org/rtv/001515617716922/v0.mjs"'
5556
)
5657
})
57-
}
58-
)
59-
})
58+
})
59+
}
60+
)

test/integration/amphtml-custom-validator/test/index.test.js

+11-14
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,20 @@ const appDir = join(__dirname, '../')
1818
;(process.env.TURBOPACK ? describe.skip : describe)(
1919
'AMP Custom Validator',
2020
() => {
21-
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
22-
'production mode',
23-
() => {
24-
it('should build and start successfully', async () => {
25-
const { code } = await nextBuild(appDir)
26-
expect(code).toBe(0)
21+
describe('production mode', () => {
22+
it('should build and start successfully', async () => {
23+
const { code } = await nextBuild(appDir)
24+
expect(code).toBe(0)
2725

28-
appPort = await findPort()
29-
app = await nextStart(appDir, appPort)
26+
appPort = await findPort()
27+
app = await nextStart(appDir, appPort)
3028

31-
const html = await renderViaHTTP(appPort, '/')
32-
await killApp(app)
29+
const html = await renderViaHTTP(appPort, '/')
30+
await killApp(app)
3331

34-
expect(html).toContain('Hello from AMP')
35-
})
36-
}
37-
)
32+
expect(html).toContain('Hello from AMP')
33+
})
34+
})
3835
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
3936
'development mode',
4037
() => {

test/integration/amphtml-fragment-style/test/index.test.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ const appDir = join(__dirname, '../')
1515
let appPort
1616
let app
1717

18-
describe('AMP Fragment Styles', () => {
19-
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
20-
'production mode',
21-
() => {
18+
// Turbopack does not support AMP rendering.
19+
;(process.env.TURBOPACK ? describe.skip : describe)(
20+
'AMP Fragment Styles',
21+
() => {
22+
describe('production mode', () => {
2223
beforeAll(async () => {
2324
await nextBuild(appDir, [])
2425
appPort = await findPort()
@@ -34,6 +35,6 @@ describe('AMP Fragment Styles', () => {
3435
expect(styles).toMatch(/background:(.*|)hotpink/)
3536
expect(styles).toMatch(/font-size:(.*|)16\.4px/)
3637
})
37-
}
38-
)
39-
})
38+
})
39+
}
40+
)

test/integration/amphtml-ssg/test/index.test.js

+51-57
Original file line numberDiff line numberDiff line change
@@ -98,66 +98,60 @@ const runTests = (isDev = false) => {
9898
}
9999
}
100100

101-
describe('AMP SSG Support', () => {
102-
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
103-
'production mode',
104-
() => {
101+
// Turbopack does not support AMP rendering.
102+
;(process.env.TURBOPACK ? describe.skip : describe)('AMP SSG Support', () => {
103+
describe('production mode', () => {
104+
beforeAll(async () => {
105+
await nextBuild(appDir)
106+
appPort = await findPort()
107+
app = await nextStart(appDir, appPort)
108+
// TODO: use browser instead to do checks that now need filesystem access
109+
builtServerPagesDir = join(appDir, '.next', 'server', 'pages')
110+
})
111+
afterAll(() => killApp(app))
112+
runTests()
113+
})
114+
115+
describe('development mode', () => {
116+
beforeAll(async () => {
117+
appPort = await findPort()
118+
app = await launchApp(appDir, appPort)
119+
})
120+
afterAll(() => killApp(app))
121+
runTests(true)
122+
})
123+
124+
describe('export mode', () => {
125+
describe('production mode', () => {
126+
let buildId
127+
105128
beforeAll(async () => {
129+
nextConfig.write(`module.exports = { output: 'export' }`)
106130
await nextBuild(appDir)
107-
appPort = await findPort()
108-
app = await nextStart(appDir, appPort)
109-
// TODO: use browser instead to do checks that now need filesystem access
110-
builtServerPagesDir = join(appDir, '.next', 'server', 'pages')
131+
buildId = await fs.readFile(join(appDir, '.next/BUILD_ID'), 'utf8')
111132
})
112-
afterAll(() => killApp(app))
113-
runTests()
114-
}
115-
)
116-
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
117-
'development mode',
118-
() => {
119-
beforeAll(async () => {
120-
appPort = await findPort()
121-
app = await launchApp(appDir, appPort)
133+
134+
afterAll(() => nextConfig.delete())
135+
136+
it('should have copied SSG files correctly', async () => {
137+
const outFile = (file) => join(appDir, 'out', file)
138+
139+
expect(await fsExists(outFile('amp.html'))).toBe(true)
140+
expect(await fsExists(outFile('index.html'))).toBe(true)
141+
expect(await fsExists(outFile('hybrid.html'))).toBe(true)
142+
expect(await fsExists(outFile('amp.amp.html'))).toBe(false)
143+
expect(await fsExists(outFile('hybrid.amp.html'))).toBe(true)
144+
expect(await fsExists(outFile('blog/post-1.html'))).toBe(true)
145+
expect(await fsExists(outFile('blog/post-1.amp.html'))).toBe(true)
146+
147+
expect(
148+
await fsExists(outFile(join('_next/data', buildId, 'amp.json')))
149+
).toBe(true)
150+
151+
expect(
152+
await fsExists(outFile(join('_next/data', buildId, 'hybrid.json')))
153+
).toBe(true)
122154
})
123-
afterAll(() => killApp(app))
124-
runTests(true)
125-
}
126-
)
127-
describe('export mode', () => {
128-
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
129-
'production mode',
130-
() => {
131-
let buildId
132-
133-
beforeAll(async () => {
134-
nextConfig.write(`module.exports = { output: 'export' }`)
135-
await nextBuild(appDir)
136-
buildId = await fs.readFile(join(appDir, '.next/BUILD_ID'), 'utf8')
137-
})
138-
139-
afterAll(() => nextConfig.delete())
140-
141-
it('should have copied SSG files correctly', async () => {
142-
const outFile = (file) => join(appDir, 'out', file)
143-
144-
expect(await fsExists(outFile('amp.html'))).toBe(true)
145-
expect(await fsExists(outFile('index.html'))).toBe(true)
146-
expect(await fsExists(outFile('hybrid.html'))).toBe(true)
147-
expect(await fsExists(outFile('amp.amp.html'))).toBe(false)
148-
expect(await fsExists(outFile('hybrid.amp.html'))).toBe(true)
149-
expect(await fsExists(outFile('blog/post-1.html'))).toBe(true)
150-
expect(await fsExists(outFile('blog/post-1.amp.html'))).toBe(true)
151-
152-
expect(
153-
await fsExists(outFile(join('_next/data', buildId, 'amp.json')))
154-
).toBe(true)
155-
156-
expect(
157-
await fsExists(outFile(join('_next/data', buildId, 'hybrid.json')))
158-
).toBe(true)
159-
})
160-
}
161-
)
155+
})
162156
})
163157
})

0 commit comments

Comments
 (0)