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
77380507
Unverified
Commit
77380507
authored
Mar 25, 2020
by
JJ Kasper
Committed by
GitHub
Mar 25, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure to copy AMP SSG files during export (#11331)
* Make sure to copy AMP SSG files during export * bump * bump
parent
e7842aff
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
6 deletions
+45
-6
index.ts
packages/next/export/index.ts
+11
-0
index.test.js
test/integration/amphtml-ssg/test/index.test.js
+34
-6
No files found.
packages/next/export/index.ts
View file @
77380507
...
@@ -3,6 +3,7 @@ import findUp from 'find-up'
...
@@ -3,6 +3,7 @@ import findUp from 'find-up'
import
{
import
{
copyFile
as
copyFileOrig
,
copyFile
as
copyFileOrig
,
existsSync
,
existsSync
,
exists
as
existsOrig
,
mkdir
as
mkdirOrig
,
mkdir
as
mkdirOrig
,
readFileSync
,
readFileSync
,
writeFileSync
,
writeFileSync
,
...
@@ -37,6 +38,7 @@ import { normalizePagePath } from '../next-server/server/normalize-page-path'
...
@@ -37,6 +38,7 @@ import { normalizePagePath } from '../next-server/server/normalize-page-path'
const
copyFile
=
promisify
(
copyFileOrig
)
const
copyFile
=
promisify
(
copyFileOrig
)
const
mkdir
=
promisify
(
mkdirOrig
)
const
mkdir
=
promisify
(
mkdirOrig
)
const
exists
=
promisify
(
existsOrig
)
const
createProgress
=
(
total
:
number
,
label
=
'Exporting'
)
=>
{
const
createProgress
=
(
total
:
number
,
label
=
'Exporting'
)
=>
{
let
curProgress
=
0
let
curProgress
=
0
...
@@ -381,12 +383,21 @@ export default async function(
...
@@ -381,12 +383,21 @@ export default async function(
subFolders
&&
route
!==
'/index'
?
`
${
sep
}
index`
:
''
subFolders
&&
route
!==
'/index'
?
`
${
sep
}
index`
:
''
}
.html`
}
.html`
)
)
const
ampHtmlDest
=
join
(
outDir
,
`
${
route
}
.amp
${
subFolders
?
`
${
sep
}
index`
:
''
}
.html`
)
const
jsonDest
=
join
(
pagesDataDir
,
`
${
route
}
.json`
)
const
jsonDest
=
join
(
pagesDataDir
,
`
${
route
}
.json`
)
await
mkdir
(
dirname
(
htmlDest
),
{
recursive
:
true
})
await
mkdir
(
dirname
(
htmlDest
),
{
recursive
:
true
})
await
mkdir
(
dirname
(
jsonDest
),
{
recursive
:
true
})
await
mkdir
(
dirname
(
jsonDest
),
{
recursive
:
true
})
await
copyFile
(
`
${
orig
}
.html`
,
htmlDest
)
await
copyFile
(
`
${
orig
}
.html`
,
htmlDest
)
await
copyFile
(
`
${
orig
}
.json`
,
jsonDest
)
await
copyFile
(
`
${
orig
}
.json`
,
jsonDest
)
if
(
await
exists
(
`
${
orig
}
.amp.html`
))
{
await
mkdir
(
dirname
(
ampHtmlDest
),
{
recursive
:
true
})
await
copyFile
(
`
${
orig
}
.amp.html`
,
ampHtmlDest
)
}
})
})
)
)
}
}
...
...
test/integration/amphtml-ssg/test/index.test.js
View file @
77380507
...
@@ -11,6 +11,7 @@ import {
...
@@ -11,6 +11,7 @@ import {
launchApp
,
launchApp
,
killApp
,
killApp
,
nextStart
,
nextStart
,
nextExport
,
}
from
'next-test-utils'
}
from
'next-test-utils'
const
appDir
=
join
(
__dirname
,
'../'
)
const
appDir
=
join
(
__dirname
,
'../'
)
...
@@ -21,6 +22,12 @@ let app
...
@@ -21,6 +22,12 @@ let app
jasmine
.
DEFAULT_TIMEOUT_INTERVAL
=
1000
*
60
*
2
jasmine
.
DEFAULT_TIMEOUT_INTERVAL
=
1000
*
60
*
2
const
fsExists
=
file
=>
fs
.
access
(
file
)
.
then
(()
=>
true
)
.
catch
(()
=>
false
)
const
runTests
=
(
isDev
=
false
)
=>
{
const
runTests
=
(
isDev
=
false
)
=>
{
it
(
'should load an amp first page correctly'
,
async
()
=>
{
it
(
'should load an amp first page correctly'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/amp'
)
const
html
=
await
renderViaHTTP
(
appPort
,
'/amp'
)
...
@@ -51,12 +58,6 @@ const runTests = (isDev = false) => {
...
@@ -51,12 +58,6 @@ const runTests = (isDev = false) => {
})
})
if
(
!
isDev
)
{
if
(
!
isDev
)
{
const
fsExists
=
file
=>
fs
.
access
(
file
)
.
then
(()
=>
true
)
.
catch
(()
=>
false
)
const
builtPage
=
file
=>
join
(
builtServerPagesDir
,
file
)
const
builtPage
=
file
=>
join
(
builtServerPagesDir
,
file
)
it
(
'should output prerendered files correctly during build'
,
async
()
=>
{
it
(
'should output prerendered files correctly during build'
,
async
()
=>
{
...
@@ -121,4 +122,31 @@ describe('AMP SSG Support', () => {
...
@@ -121,4 +122,31 @@ describe('AMP SSG Support', () => {
afterAll
(()
=>
killApp
(
app
))
afterAll
(()
=>
killApp
(
app
))
runTests
(
true
)
runTests
(
true
)
})
})
describe
(
'export mode'
,
()
=>
{
let
buildId
beforeAll
(
async
()
=>
{
await
nextBuild
(
appDir
)
await
nextExport
(
appDir
,
{
outdir
:
join
(
appDir
,
'out'
)
})
buildId
=
await
fs
.
readFile
(
join
(
appDir
,
'.next/BUILD_ID'
),
'utf8'
)
})
it
(
'should have copied SSG files correctly'
,
async
()
=>
{
const
outFile
=
file
=>
join
(
appDir
,
'out'
,
file
)
expect
(
await
fsExists
(
outFile
(
'amp.html'
))).
toBe
(
true
)
expect
(
await
fsExists
(
outFile
(
'index.html'
))).
toBe
(
true
)
expect
(
await
fsExists
(
outFile
(
'hybrid.html'
))).
toBe
(
true
)
expect
(
await
fsExists
(
outFile
(
'amp.amp.html'
))).
toBe
(
false
)
expect
(
await
fsExists
(
outFile
(
'hybrid.amp.html'
))).
toBe
(
true
)
expect
(
await
fsExists
(
outFile
(
join
(
'_next/data'
,
buildId
,
'amp.json'
)))
).
toBe
(
true
)
expect
(
await
fsExists
(
outFile
(
join
(
'_next/data'
,
buildId
,
'hybrid.json'
)))
).
toBe
(
true
)
})
})
})
})
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