Skip to content

Commit

Permalink
Ensure AMP optimizer is only excluded from trace when not used (#32577)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Dec 17, 2021
1 parent b8a552b commit f61e356
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/next/build/index.ts
Expand Up @@ -1214,6 +1214,8 @@ export default async function build(
).createHash('sha256')

cacheHash.update(require('next/package').version)
cacheHash.update(hasSsrAmpPages + '')
cacheHash.update(ciEnvironment.hasNextSupport + '')

await Promise.all(
lockFiles.map(async (lockFile) => {
Expand Down Expand Up @@ -1242,7 +1244,6 @@ export default async function build(
processCwd: dir,
ignore: [
'**/next/dist/pages/**/*',
'**/next/dist/compiled/@ampproject/toolbox-optimizer/**/*',
'**/next/dist/compiled/webpack/(bundle4|bundle5).js',
'**/node_modules/webpack5/**/*',
'**/next/dist/server/lib/squoosh/**/*.wasm',
Expand All @@ -1254,6 +1255,9 @@ export default async function build(
'**/node_modules/sharp/**/*',
]
: []),
...(!hasSsrAmpPages
? ['**/next/dist/compiled/@ampproject/toolbox-optimizer/**/*']
: []),
],
}
)
Expand Down
15 changes: 15 additions & 0 deletions test/integration/amphtml/pages/amp-ssr.js
@@ -0,0 +1,15 @@
export const config = { amp: true }

export default function Page() {
return (
<div>
<p id="only-amp">Only AMP for me...</p>
</div>
)
}

export function getServerSideProps() {
return {
props: {},
}
}
11 changes: 11 additions & 0 deletions test/integration/amphtml/test/index.test.js
Expand Up @@ -48,6 +48,17 @@ describe('AMP Usage', () => {
})
afterAll(() => stopApp(server))

it('should have amp optimizer in trace', async () => {
const trace = JSON.parse(
readFileSync(join(appDir, '.next/next-server.js.nft.json'), 'utf8')
)
expect(
trace.files.some((file) =>
file.replace(/\\/g, '/').includes('@ampproject/toolbox-optimizer')
)
).toBe(true)
})

it('should not contain missing files warning', async () => {
expect(output).toContain('Compiled successfully')
expect(output).not.toContain('Could not find files for')
Expand Down

0 comments on commit f61e356

Please sign in to comment.