Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
5d13e55a
Unverified
Commit
5d13e55a
authored
Apr 23, 2020
by
JJ Kasper
Committed by
GitHub
Apr 23, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure modern AMP client page bundles are removed (#12138)
parent
0a3b64d2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
296 additions
and
188 deletions
+296
-188
index.ts
packages/next/build/index.ts
+11
-8
next.config.js
test/integration/amphtml/next.config.js
+1
-0
index.test.js
test/integration/amphtml/test/index.test.js
+284
-180
No files found.
packages/next/build/index.ts
View file @
5d13e55a
...
@@ -551,15 +551,18 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -551,15 +551,18 @@ export default async function build(dir: string, conf = null): Promise<void> {
if
(
result
.
isAmpOnly
)
{
if
(
result
.
isAmpOnly
)
{
// ensure all AMP only bundles got removed
// ensure all AMP only bundles got removed
try
{
try
{
await
fsUnlink
(
const
clientBundle
=
path
.
join
(
path
.
join
(
distDir
,
distDir
,
'static'
,
'static'
,
buildId
,
buildId
,
'pages'
,
'pages'
,
actualPage
+
'.js'
actualPage
+
'.js'
)
)
)
await
fsUnlink
(
clientBundle
)
if
(
config
.
experimental
.
modern
)
{
await
fsUnlink
(
clientBundle
.
replace
(
/
\.
js$/
,
'.module.js'
))
}
}
catch
(
err
)
{
}
catch
(
err
)
{
if
(
err
.
code
!==
'ENOENT'
)
{
if
(
err
.
code
!==
'ENOENT'
)
{
throw
err
throw
err
...
...
test/integration/amphtml/next.config.js
View file @
5d13e55a
...
@@ -6,4 +6,5 @@ module.exports = {
...
@@ -6,4 +6,5 @@ module.exports = {
amp
:
{
amp
:
{
canonicalBase
:
'http://localhost:1234'
,
canonicalBase
:
'http://localhost:1234'
,
},
},
// edit here
}
}
test/integration/amphtml/test/index.test.js
View file @
5d13e55a
...
@@ -4,7 +4,13 @@ import { join } from 'path'
...
@@ -4,7 +4,13 @@ import { join } from 'path'
import
cheerio
from
'cheerio'
import
cheerio
from
'cheerio'
import
webdriver
from
'next-webdriver'
import
webdriver
from
'next-webdriver'
import
{
validateAMP
}
from
'amp-test-utils'
import
{
validateAMP
}
from
'amp-test-utils'
import
{
accessSync
,
readFileSync
,
writeFileSync
}
from
'fs'
import
{
accessSync
,
readFileSync
,
writeFileSync
,
writeFile
,
readFile
,
}
from
'fs-extra'
import
{
import
{
waitFor
,
waitFor
,
nextServer
,
nextServer
,
...
@@ -28,6 +34,7 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5
...
@@ -28,6 +34,7 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5
const
context
=
{}
const
context
=
{}
describe
(
'AMP Usage'
,
()
=>
{
describe
(
'AMP Usage'
,
()
=>
{
describe
(
'production mode'
,
()
=>
{
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
await
nextBuild
(
appDir
)
await
nextBuild
(
appDir
)
app
=
nextServer
({
app
=
nextServer
({
...
@@ -69,11 +76,19 @@ describe('AMP Usage', () => {
...
@@ -69,11 +76,19 @@ describe('AMP Usage', () => {
const
ampOnly
=
[
'only-amp'
,
'root-hmr'
,
'another-amp'
]
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'
)
)
).
toThrow
()
).
toThrow
()
expect
(()
=>
expect
(()
=>
accessSync
(
accessSync
(
join
(
appDir
,
'.next/server/static'
,
buildId
,
'pages'
,
pg
+
'.html'
)
join
(
appDir
,
'.next/server/static'
,
buildId
,
'pages'
,
pg
+
'.html'
)
)
)
).
not
.
toThrow
()
).
not
.
toThrow
()
expect
(()
=>
expect
(()
=>
...
@@ -92,7 +107,9 @@ describe('AMP Usage', () => {
...
@@ -92,7 +107,9 @@ describe('AMP Usage', () => {
$
(
$
(
$
(
'link[rel=preload]'
)
$
(
'link[rel=preload]'
)
.
toArray
()
.
toArray
()
.
find
(
i
=>
$
(
i
).
attr
(
'href'
)
===
'https://cdn.ampproject.org/v0.js'
)
.
find
(
i
=>
$
(
i
).
attr
(
'href'
)
===
'https://cdn.ampproject.org/v0.js'
)
).
attr
(
'href'
)
).
attr
(
'href'
)
).
toBe
(
'https://cdn.ampproject.org/v0.js'
)
).
toBe
(
'https://cdn.ampproject.org/v0.js'
)
})
})
...
@@ -202,14 +219,18 @@ describe('AMP Usage', () => {
...
@@ -202,14 +219,18 @@ describe('AMP Usage', () => {
const
html
=
await
renderViaHTTP
(
appPort
,
'/conflicting-tag?amp=1'
)
const
html
=
await
renderViaHTTP
(
appPort
,
'/conflicting-tag?amp=1'
)
const
$
=
cheerio
.
load
(
html
)
const
$
=
cheerio
.
load
(
html
)
await
validateAMP
(
html
)
await
validateAMP
(
html
)
expect
(
$
(
'meta[name=viewport]'
).
attr
(
'content'
)).
not
.
toBe
(
'something :p'
)
expect
(
$
(
'meta[name=viewport]'
).
attr
(
'content'
)).
not
.
toBe
(
'something :p'
)
})
})
it
(
'should allow manually setting canonical'
,
async
()
=>
{
it
(
'should allow manually setting canonical'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/manual-rels?amp=1'
)
const
html
=
await
renderViaHTTP
(
appPort
,
'/manual-rels?amp=1'
)
const
$
=
cheerio
.
load
(
html
)
const
$
=
cheerio
.
load
(
html
)
await
validateAMP
(
html
)
await
validateAMP
(
html
)
expect
(
$
(
'link[rel=canonical]'
).
attr
(
'href'
)).
toBe
(
'/my-custom-canonical'
)
expect
(
$
(
'link[rel=canonical]'
).
attr
(
'href'
)).
toBe
(
'/my-custom-canonical'
)
})
})
it
(
'should allow manually setting amphtml rel'
,
async
()
=>
{
it
(
'should allow manually setting amphtml rel'
,
async
()
=>
{
...
@@ -244,6 +265,89 @@ describe('AMP Usage', () => {
...
@@ -244,6 +265,89 @@ describe('AMP Usage', () => {
expect
(
styles
).
not
.
toMatch
(
/
\/\*
# sourceMappingURL=.*
\*\/
/
)
expect
(
styles
).
not
.
toMatch
(
/
\/\*
# sourceMappingURL=.*
\*\/
/
)
})
})
})
})
})
describe
(
'production mode modern'
,
()
=>
{
let
origNextConfig
=
''
const
nextConfigPath
=
join
(
appDir
,
'next.config.js'
)
beforeAll
(
async
()
=>
{
origNextConfig
=
await
readFile
(
nextConfigPath
,
'utf8'
)
await
writeFile
(
nextConfigPath
,
origNextConfig
.
replace
(
'// edit here'
,
`
experimental: {
modern: true
}
`
)
)
await
nextBuild
(
appDir
)
app
=
nextServer
({
dir
:
join
(
__dirname
,
'../'
),
dev
:
false
,
quiet
:
true
,
})
server
=
await
startApp
(
app
)
context
.
appPort
=
appPort
=
server
.
address
().
port
})
afterAll
(
async
()
=>
{
await
stopApp
(
server
)
await
writeFile
(
nextConfigPath
,
origNextConfig
)
})
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'
,
'another-amp'
]
for
(
const
pg
of
ampOnly
)
{
expect
(()
=>
accessSync
(
join
(
appDir
,
'.next/static'
,
buildId
,
'pages'
,
pg
+
'.js'
))
).
toThrow
()
expect
(()
=>
accessSync
(
join
(
appDir
,
'.next/server/static'
,
buildId
,
'pages'
,
pg
+
'.html'
)
)
).
not
.
toThrow
()
expect
(()
=>
accessSync
(
join
(
appDir
,
'.next/server/static'
,
buildId
,
'pages'
,
pg
+
'.js'
)
)
).
toThrow
()
}
})
it
(
'should not output modern client pages for AMP only'
,
async
()
=>
{
const
buildId
=
readFileSync
(
join
(
appDir
,
'.next/BUILD_ID'
),
'utf8'
)
const
ampOnly
=
[
'only-amp'
,
'root-hmr'
,
'another-amp'
]
for
(
const
pg
of
ampOnly
)
{
expect
(()
=>
accessSync
(
join
(
appDir
,
'.next/static'
,
buildId
,
'pages'
,
pg
+
'.module.js'
)
)
).
toThrow
()
expect
(()
=>
accessSync
(
join
(
appDir
,
'.next/server/static'
,
buildId
,
'pages'
,
pg
+
'.html'
)
)
).
not
.
toThrow
()
expect
(()
=>
accessSync
(
join
(
appDir
,
'.next/server/static'
,
buildId
,
'pages'
,
pg
+
'.module.js'
)
)
).
toThrow
()
}
})
})
describe
(
'AMP dev no-warn'
,
()
=>
{
describe
(
'AMP dev no-warn'
,
()
=>
{
let
dynamicAppPort
let
dynamicAppPort
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment