Update to make sure AMP only bundles are always removed in pro… (#11527)

This commit is contained in:
JJ Kasper 2020-04-01 03:24:44 -05:00 committed by GitHub
parent fa5da6d220
commit d61eced9a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 1 deletions

View file

@ -547,6 +547,25 @@ export default async function build(dir: string, conf = null): Promise<void> {
hybridAmpPages.add(page)
}
if (result.isAmpOnly) {
// ensure all AMP only bundles got removed
try {
await fsUnlink(
path.join(
distDir,
'static',
buildId,
'pages',
actualPage + '.js'
)
)
} catch (err) {
if (err.code !== 'ENOENT') {
throw err
}
}
}
if (result.hasStaticProps) {
ssgPages.add(page)
isSsg = true

View file

@ -665,6 +665,7 @@ export async function isPageStatic(
runtimeEnvConfig: any
): Promise<{
isStatic?: boolean
isAmpOnly?: boolean
isHybridAmp?: boolean
hasServerProps?: boolean
hasStaticProps?: boolean
@ -756,6 +757,7 @@ export async function isPageStatic(
return {
isStatic: !hasStaticProps && !hasGetInitialProps && !hasServerProps,
isHybridAmp: config.amp === 'hybrid',
isAmpOnly: config.amp === true,
prerenderRoutes,
prerenderFallback,
hasStaticProps,

View file

@ -0,0 +1,8 @@
import { useAmp } from 'next/amp'
const config = {
amp: true,
}
export default () => (useAmp() ? 'AMP mode' : 'Normal mode')
export { config }

View file

@ -66,7 +66,7 @@ describe('AMP Usage', () => {
it('should not output client pages for AMP only', async () => {
const buildId = readFileSync(join(appDir, '.next/BUILD_ID'), 'utf8')
const ampOnly = ['only-amp', 'root-hmr']
const ampOnly = ['only-amp', 'root-hmr', 'another-amp']
for (const pg of ampOnly) {
expect(() =>
accessSync(join(appDir, '.next/static', buildId, 'pages', pg + '.js'))