Skip to content

Commit

Permalink
Update to make sure AMP only bundles are always removed in pro… (#11527)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Apr 1, 2020
1 parent fa5da6d commit d61eced
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
19 changes: 19 additions & 0 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions packages/next/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ export async function isPageStatic(
runtimeEnvConfig: any
): Promise<{
isStatic?: boolean
isAmpOnly?: boolean
isHybridAmp?: boolean
hasServerProps?: boolean
hasStaticProps?: boolean
Expand Down Expand Up @@ -756,6 +757,7 @@ export async function isPageStatic(
return {
isStatic: !hasStaticProps && !hasGetInitialProps && !hasServerProps,
isHybridAmp: config.amp === 'hybrid',
isAmpOnly: config.amp === true,
prerenderRoutes,
prerenderFallback,
hasStaticProps,
Expand Down
8 changes: 8 additions & 0 deletions test/integration/amphtml/pages/another-amp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useAmp } from 'next/amp'

const config = {
amp: true,
}

export default () => (useAmp() ? 'AMP mode' : 'Normal mode')
export { config }
2 changes: 1 addition & 1 deletion test/integration/amphtml/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down

0 comments on commit d61eced

Please sign in to comment.