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

Ensure AMP optimizer is only excluded from trace when not used #32577

Merged
merged 2 commits into from Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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