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
8eb701c1
Unverified
Commit
8eb701c1
authored
Apr 26, 2024
by
Sebastian Silbermann
Committed by
GitHub
Apr 26, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Combine necessary file for edge route in size calculation (#65053)
Closes NEXT-3228
parent
4e84f696
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
5 deletions
+53
-5
collect-stats.js
.github/actions/next-stats-action/src/run/collect-stats.js
+19
-5
stats-config.js
test/.stats-app/stats-config.js
+34
-0
No files found.
.github/actions/next-stats-action/src/run/collect-stats.js
View file @
8eb701c1
...
...
@@ -10,6 +10,10 @@ const { parse: urlParse } = require('url')
const
benchmarkUrl
=
require
(
'./benchmark-url'
)
const
{
statsAppDir
,
diffingDir
,
benchTitle
}
=
require
(
'../constants'
)
async
function
defaultGetRequiredFiles
(
nextAppDir
,
fileName
)
{
return
[
fileName
]
}
module
.
exports
=
async
function
collectStats
(
runConfig
=
{},
statsConfig
=
{},
...
...
@@ -136,7 +140,11 @@ module.exports = async function collectStats(
}
for
(
const
fileGroup
of
runConfig
.
filesToTrack
)
{
const
{
name
,
globs
}
=
fileGroup
const
{
getRequiredFiles
=
defaultGetRequiredFiles
,
name
,
globs
,
}
=
fileGroup
const
groupStats
=
{}
const
curFiles
=
new
Set
()
...
...
@@ -147,11 +155,17 @@ module.exports = async function collectStats(
for
(
const
file
of
curFiles
)
{
const
fileKey
=
path
.
basename
(
file
)
const
absPath
=
path
.
join
(
curDir
,
file
)
try
{
const
fileInfo
=
await
fs
.
stat
(
absPath
)
groupStats
[
fileKey
]
=
fileInfo
.
size
groupStats
[
`
${
fileKey
}
gzip`
]
=
await
gzipSize
.
file
(
absPath
)
let
parsedSizeSum
=
0
let
gzipSizeSum
=
0
for
(
const
requiredFile
of
await
getRequiredFiles
(
curDir
,
file
))
{
const
absPath
=
path
.
join
(
curDir
,
requiredFile
)
const
fileInfo
=
await
fs
.
stat
(
absPath
)
parsedSizeSum
+=
fileInfo
.
size
gzipSizeSum
+=
await
gzipSize
.
file
(
absPath
)
}
groupStats
[
fileKey
]
=
parsedSizeSum
groupStats
[
`
${
fileKey
}
gzip`
]
=
gzipSizeSum
}
catch
(
err
)
{
logger
.
error
(
'Failed to get file stats'
,
err
)
}
...
...
test/.stats-app/stats-config.js
View file @
8eb701c1
const
fs
=
require
(
'fs/promises'
)
const
path
=
require
(
'path'
)
const
clientGlobs
=
[
{
name
:
'Client Bundles (main, webpack)'
,
...
...
@@ -31,6 +34,37 @@ const clientGlobs = [
'.next/server/pages/edge-ssr.js'
,
'.next/server/app/app-edge-ssr/page.js'
,
],
getRequiredFiles
:
async
(
nextAppDir
,
fileName
)
=>
{
if
(
fileName
.
startsWith
(
'.next/server/app'
))
{
const
manifestJson
=
await
fs
.
readFile
(
path
.
join
(
nextAppDir
,
'.next/server/middleware-manifest.json'
)
)
const
manifest
=
JSON
.
parse
(
manifestJson
)
const
manifestFileEntry
=
path
.
relative
(
path
.
join
(
nextAppDir
,
'.next'
),
path
.
join
(
nextAppDir
,
fileName
)
)
const
functionEntry
=
Object
.
values
(
manifest
.
functions
).
find
(
(
entry
)
=>
{
return
entry
.
files
.
includes
(
manifestFileEntry
)
}
)
if
(
functionEntry
===
undefined
)
{
throw
new
Error
(
`
${
manifestFileEntry
}
is not listed in the files files of any functions in the manifest:\n`
+
JSON
.
stringify
(
manifest
,
null
,
2
)
)
}
return
functionEntry
.
files
.
map
((
file
)
=>
{
return
path
.
join
(
'.next'
,
file
)
})
}
else
{
return
[
fileName
]
}
},
},
{
name
:
'Middleware size'
,
...
...
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