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

Turbopack: don't include AMP optimizer in NFT #77242

Merged
merged 2 commits into from
Mar 18, 2025
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
2 changes: 1 addition & 1 deletion packages/next/src/server/post-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function postProcessHTML(
{ inAmpMode, hybridAmp }: { inAmpMode: boolean; hybridAmp: boolean }
) {
const postProcessors: Array<PostProcessorFunction> = [
process.env.NEXT_RUNTIME !== 'edge' && inAmpMode
process.env.NEXT_RUNTIME !== 'edge' && inAmpMode && !process.env.TURBOPACK
? async (html: string) => {
const optimizeAmp = require('./optimize-amp')
.default as typeof import('./optimize-amp').default
Expand Down
15 changes: 8 additions & 7 deletions test/integration/amp-export-validation/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ const nextConfig = new File(join(appDir, 'next.config.js'))

let buildOutput

describe('AMP Validation on Export', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
// Turbopack does not support AMP rendering.
;(process.env.TURBOPACK ? describe.skip : describe)(
'AMP Validation on Export',
() => {
describe('production mode', () => {
beforeAll(async () => {
const { stdout = '', stderr = '' } = await nextBuild(appDir, [], {
stdout: true,
Expand Down Expand Up @@ -120,6 +121,6 @@ describe('AMP Validation on Export', () => {
nextConfig.restore()
}
})
}
)
})
})
}
)
15 changes: 8 additions & 7 deletions test/integration/amphtml-custom-optimizer/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ let app
let appPort
const appDir = join(__dirname, '../')

describe('AMP Custom Optimizer', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
// Turbopack does not support AMP rendering.
;(process.env.TURBOPACK ? describe.skip : describe)(
'AMP Custom Optimizer',
() => {
describe('production mode', () => {
it('should build and start for static page', async () => {
const { code } = await nextBuild(appDir)
expect(code).toBe(0)
Expand Down Expand Up @@ -54,6 +55,6 @@ describe('AMP Custom Optimizer', () => {
'script async src="https://cdn.ampproject.org/rtv/001515617716922/v0.mjs"'
)
})
}
)
})
})
}
)
25 changes: 11 additions & 14 deletions test/integration/amphtml-custom-validator/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,20 @@ const appDir = join(__dirname, '../')
;(process.env.TURBOPACK ? describe.skip : describe)(
'AMP Custom Validator',
() => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
it('should build and start successfully', async () => {
const { code } = await nextBuild(appDir)
expect(code).toBe(0)
describe('production mode', () => {
it('should build and start successfully', async () => {
const { code } = await nextBuild(appDir)
expect(code).toBe(0)

appPort = await findPort()
app = await nextStart(appDir, appPort)
appPort = await findPort()
app = await nextStart(appDir, appPort)

const html = await renderViaHTTP(appPort, '/')
await killApp(app)
const html = await renderViaHTTP(appPort, '/')
await killApp(app)

expect(html).toContain('Hello from AMP')
})
}
)
expect(html).toContain('Hello from AMP')
})
})
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
Expand Down
15 changes: 8 additions & 7 deletions test/integration/amphtml-fragment-style/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ const appDir = join(__dirname, '../')
let appPort
let app

describe('AMP Fragment Styles', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
// Turbopack does not support AMP rendering.
;(process.env.TURBOPACK ? describe.skip : describe)(
'AMP Fragment Styles',
() => {
describe('production mode', () => {
beforeAll(async () => {
await nextBuild(appDir, [])
appPort = await findPort()
Expand All @@ -34,6 +35,6 @@ describe('AMP Fragment Styles', () => {
expect(styles).toMatch(/background:(.*|)hotpink/)
expect(styles).toMatch(/font-size:(.*|)16\.4px/)
})
}
)
})
})
}
)
108 changes: 51 additions & 57 deletions test/integration/amphtml-ssg/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,66 +98,60 @@ const runTests = (isDev = false) => {
}
}

describe('AMP SSG Support', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
// Turbopack does not support AMP rendering.
;(process.env.TURBOPACK ? describe.skip : describe)('AMP SSG Support', () => {
describe('production mode', () => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
// TODO: use browser instead to do checks that now need filesystem access
builtServerPagesDir = join(appDir, '.next', 'server', 'pages')
})
afterAll(() => killApp(app))
runTests()
})

describe('development mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
})

describe('export mode', () => {
describe('production mode', () => {
let buildId

beforeAll(async () => {
nextConfig.write(`module.exports = { output: 'export' }`)
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
// TODO: use browser instead to do checks that now need filesystem access
builtServerPagesDir = join(appDir, '.next', 'server', 'pages')
buildId = await fs.readFile(join(appDir, '.next/BUILD_ID'), 'utf8')
})
afterAll(() => killApp(app))
runTests()
}
)
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)

afterAll(() => nextConfig.delete())

it('should have copied SSG files correctly', async () => {
const outFile = (file) => join(appDir, 'out', file)

expect(await fsExists(outFile('amp.html'))).toBe(true)
expect(await fsExists(outFile('index.html'))).toBe(true)
expect(await fsExists(outFile('hybrid.html'))).toBe(true)
expect(await fsExists(outFile('amp.amp.html'))).toBe(false)
expect(await fsExists(outFile('hybrid.amp.html'))).toBe(true)
expect(await fsExists(outFile('blog/post-1.html'))).toBe(true)
expect(await fsExists(outFile('blog/post-1.amp.html'))).toBe(true)

expect(
await fsExists(outFile(join('_next/data', buildId, 'amp.json')))
).toBe(true)

expect(
await fsExists(outFile(join('_next/data', buildId, 'hybrid.json')))
).toBe(true)
})
afterAll(() => killApp(app))
runTests(true)
}
)
describe('export mode', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
let buildId

beforeAll(async () => {
nextConfig.write(`module.exports = { output: 'export' }`)
await nextBuild(appDir)
buildId = await fs.readFile(join(appDir, '.next/BUILD_ID'), 'utf8')
})

afterAll(() => nextConfig.delete())

it('should have copied SSG files correctly', async () => {
const outFile = (file) => join(appDir, 'out', file)

expect(await fsExists(outFile('amp.html'))).toBe(true)
expect(await fsExists(outFile('index.html'))).toBe(true)
expect(await fsExists(outFile('hybrid.html'))).toBe(true)
expect(await fsExists(outFile('amp.amp.html'))).toBe(false)
expect(await fsExists(outFile('hybrid.amp.html'))).toBe(true)
expect(await fsExists(outFile('blog/post-1.html'))).toBe(true)
expect(await fsExists(outFile('blog/post-1.amp.html'))).toBe(true)

expect(
await fsExists(outFile(join('_next/data', buildId, 'amp.json')))
).toBe(true)

expect(
await fsExists(outFile(join('_next/data', buildId, 'hybrid.json')))
).toBe(true)
})
}
)
})
})
})
Loading
Loading