Unverified Commit d61eced9 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

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

parent fa5da6d2
...@@ -547,6 +547,25 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -547,6 +547,25 @@ export default async function build(dir: string, conf = null): Promise<void> {
hybridAmpPages.add(page) 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) { if (result.hasStaticProps) {
ssgPages.add(page) ssgPages.add(page)
isSsg = true isSsg = true
......
...@@ -665,6 +665,7 @@ export async function isPageStatic( ...@@ -665,6 +665,7 @@ export async function isPageStatic(
runtimeEnvConfig: any runtimeEnvConfig: any
): Promise<{ ): Promise<{
isStatic?: boolean isStatic?: boolean
isAmpOnly?: boolean
isHybridAmp?: boolean isHybridAmp?: boolean
hasServerProps?: boolean hasServerProps?: boolean
hasStaticProps?: boolean hasStaticProps?: boolean
...@@ -756,6 +757,7 @@ export async function isPageStatic( ...@@ -756,6 +757,7 @@ export async function isPageStatic(
return { return {
isStatic: !hasStaticProps && !hasGetInitialProps && !hasServerProps, isStatic: !hasStaticProps && !hasGetInitialProps && !hasServerProps,
isHybridAmp: config.amp === 'hybrid', isHybridAmp: config.amp === 'hybrid',
isAmpOnly: config.amp === true,
prerenderRoutes, prerenderRoutes,
prerenderFallback, prerenderFallback,
hasStaticProps, hasStaticProps,
......
import { useAmp } from 'next/amp'
const config = {
amp: true,
}
export default () => (useAmp() ? 'AMP mode' : 'Normal mode')
export { config }
...@@ -66,7 +66,7 @@ describe('AMP Usage', () => { ...@@ -66,7 +66,7 @@ describe('AMP Usage', () => {
it('should not output client pages for AMP only', async () => { it('should not output client pages for AMP only', async () => {
const buildId = readFileSync(join(appDir, '.next/BUILD_ID'), 'utf8') 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) { for (const pg of ampOnly) {
expect(() => expect(() =>
accessSync(join(appDir, '.next/static', buildId, 'pages', pg + '.js')) accessSync(join(appDir, '.next/static', buildId, 'pages', pg + '.js'))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment