Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add entrypoint tracing #25538

Merged
merged 41 commits into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5ddd237
Add ncc'd nft
ijjk May 27, 2021
7645c51
Add initial page tracing plugin
ijjk May 27, 2021
2c8df87
Include dynamic chunks and add outputting traces
ijjk May 28, 2021
963a210
Merge remote-tracking branch 'upstream/canary' into add/nft
ijjk May 28, 2021
6d4bd43
add check
ijjk May 28, 2021
5b1ed01
check name
ijjk May 28, 2021
11d1c38
Merge remote-tracking branch 'upstream/canary' into add/nft
ijjk May 28, 2021
61fb021
remove todo and clean up ignores
ijjk May 28, 2021
03f1235
Merge remote-tracking branch 'upstream/canary' into add/nft
ijjk Jun 16, 2021
3b5c026
Merge remote-tracking branch 'upstream/canary' into add/nft
ijjk Jun 26, 2021
9376530
update compiled
ijjk Jun 26, 2021
20aafbc
Add initial test for traces
ijjk Jun 26, 2021
8b69270
Update test for webpack 4
ijjk Jun 26, 2021
7419cd7
Merge remote-tracking branch 'upstream/canary' into add/nft
ijjk Jul 7, 2021
3ab3cd9
apply suggestions from review
ijjk Jul 7, 2021
02cfd01
only create traces with webpack 5
ijjk Jul 7, 2021
21f1752
lint-fix
ijjk Jul 7, 2021
71ccfd2
normalize test on windows
ijjk Jul 7, 2021
3c1e604
normalize files before output
ijjk Jul 7, 2021
8ae2785
update test
ijjk Jul 7, 2021
b2a6b41
Merge remote-tracking branch 'upstream/canary' into add/nft
ijjk Jul 12, 2021
0dbf716
Update plugin and add more tests
ijjk Jul 12, 2021
620121f
Merge remote-tracking branch 'upstream/canary' into add/nft
ijjk Jul 12, 2021
1631552
Merge remote-tracking branch 'upstream/canary' into add/nft
ijjk Jul 21, 2021
e401004
Apply suggestions from code review
ijjk Jul 21, 2021
7cab94e
Merge branch 'add/nft' of github.com:ijjk/next.js into add/nft
ijjk Jul 21, 2021
a2fb21f
Update tests
ijjk Jul 21, 2021
010ee05
Use relative paths for traces
ijjk Jul 21, 2021
a0138e9
Merge remote-tracking branch 'upstream/canary' into add/nft
ijjk Jul 21, 2021
cbd1b3a
Merge branch 'canary' into add/nft
ijjk Jul 21, 2021
4829836
Merge remote-tracking branch 'upstream/canary' into add/nft
ijjk Jul 21, 2021
0aa38fd
Merge branch 'add/nft' of github.com:ijjk/next.js into add/nft
ijjk Jul 21, 2021
98daa68
Merge remote-tracking branch 'upstream/canary' into add/nft
ijjk Aug 6, 2021
55111a3
Add experimental flag and include/exclude config
ijjk Aug 6, 2021
1f1f6e3
ncc glob
ijjk Aug 6, 2021
076d001
Merge remote-tracking branch 'upstream/canary' into add/nft
ijjk Aug 6, 2021
8bae9aa
update precompiled
ijjk Aug 6, 2021
b0133b8
Merge remote-tracking branch 'upstream/canary' into add/nft
ijjk Aug 12, 2021
5cfee37
Merge remote-tracking branch 'upstream/canary' into add/nft
ijjk Aug 16, 2021
9823923
Add excludes to nft ignore
ijjk Aug 16, 2021
2997ee2
Merge branch 'canary' into add/nft
ijjk Aug 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,8 @@ export default async function build(
const serverPropsPages = new Set<string>()
const additionalSsgPaths = new Map<string, Array<string>>()
const additionalSsgPathsEncoded = new Map<string, Array<string>>()
const pageTraceIncludes = new Map<string, Array<string>>()
const pageTraceExcludes = new Map<string, Array<string>>()
const pageInfos = new Map<string, PageInfo>()
const pagesManifest = JSON.parse(
await promises.readFile(manifestPath, 'utf8')
Expand Down Expand Up @@ -841,6 +843,11 @@ export default async function build(
)
})

if (config.experimental.nftTracing) {
pageTraceIncludes.set(page, workerResult.traceIncludes || [])
pageTraceExcludes.set(page, workerResult.traceExcludes || [])
}

if (
workerResult.isStatic === false &&
(workerResult.isHybridAmp || workerResult.isAmpOnly)
Expand Down Expand Up @@ -979,6 +986,63 @@ export default async function build(
)
}

if (config.experimental.nftTracing) {
const globOrig = require('next/dist/compiled/glob') as typeof import('next/dist/compiled/glob')
const glob = (pattern: string): Promise<string[]> => {
return new Promise((resolve, reject) => {
globOrig(pattern, { cwd: dir }, (err, files) => {
if (err) {
return reject(err)
}
resolve(files)
})
})
}

for (const page of pageKeys) {
const includeGlobs = pageTraceIncludes.get(page)
const excludeGlobs = pageTraceExcludes.get(page)

if (!includeGlobs?.length && !excludeGlobs?.length) {
continue
}

const traceFile = path.join(
distDir,
'server/pages',
`${page}.js.nft.json`
)
const traceContent = JSON.parse(
await promises.readFile(traceFile, 'utf8')
)
let includes: string[] = []
let excludes: string[] = []

if (includeGlobs?.length) {
for (const includeGlob of includeGlobs) {
includes.push(...(await glob(includeGlob)))
}
}

if (excludeGlobs?.length) {
for (const excludeGlob of excludeGlobs) {
excludes.push(...(await glob(excludeGlob)))
}
}

const combined = new Set([...traceContent.files, ...includes])
excludes.forEach((file) => combined.delete(file))

await promises.writeFile(
traceFile,
JSON.stringify({
version: traceContent.version,
files: [...combined],
})
)
}
}

if (serverPropsPages.size > 0 || ssgPages.size > 0) {
// We update the routes manifest after the build with the
// data routes since we can't determine these until after build
Expand Down
8 changes: 6 additions & 2 deletions packages/next/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { getRouteMatcher, getRouteRegex } from '../shared/lib/router/utils'
import { isDynamicRoute } from '../shared/lib/router/utils/is-dynamic'
import escapePathDelimiters from '../shared/lib/router/utils/escape-path-delimiters'
import { findPageFile } from '../server/lib/find-page-file'
import { GetStaticPaths } from 'next/types'
import { GetStaticPaths, PageConfig } from 'next/types'
import { denormalizePagePath } from '../server/normalize-page-path'
import { BuildManifest } from '../server/get-page-files'
import { removePathTrailingSlash } from '../client/normalize-trailing-slash'
Expand Down Expand Up @@ -831,6 +831,8 @@ export async function isPageStatic(
encodedPrerenderRoutes?: string[]
prerenderFallback?: boolean | 'blocking'
isNextImageImported?: boolean
traceIncludes?: string[]
traceExcludes?: string[]
}> {
const isPageStaticSpan = trace('is-page-static-utils', parentId)
return isPageStaticSpan.traceAsyncFn(async () => {
Expand Down Expand Up @@ -925,7 +927,7 @@ export async function isPageStatic(
}

const isNextImageImported = (global as any).__NEXT_IMAGE_IMPORTED
const config = mod.config || {}
const config: PageConfig = mod.config || {}
return {
isStatic: !hasStaticProps && !hasGetInitialProps && !hasServerProps,
isHybridAmp: config.amp === 'hybrid',
Expand All @@ -936,6 +938,8 @@ export async function isPageStatic(
hasStaticProps,
hasServerProps,
isNextImageImported,
traceIncludes: config.unstable_includeFiles || [],
traceExcludes: config.unstable_excludeFiles || [],
}
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') return {}
Expand Down
7 changes: 7 additions & 0 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import BuildStatsPlugin from './webpack/plugins/build-stats-plugin'
import ChunkNamesPlugin from './webpack/plugins/chunk-names-plugin'
import { JsConfigPathsPlugin } from './webpack/plugins/jsconfig-paths-plugin'
import { DropClientPage } from './webpack/plugins/next-drop-client-page-plugin'
import { TraceEntryPointsPlugin } from './webpack/plugins/next-trace-entrypoints-plugin'
import NextJsSsrImportPlugin from './webpack/plugins/nextjs-ssr-import'
import NextJsSSRModuleCachePlugin from './webpack/plugins/nextjs-ssr-module-cache'
import PagesManifestPlugin from './webpack/plugins/pages-manifest-plugin'
Expand Down Expand Up @@ -1245,6 +1246,12 @@ export default async function getBaseWebpackConfig(
pagesDir,
}),
!isServer && new DropClientPage(),
config.experimental.nftTracing &&
!isLikeServerless &&
isServer &&
!dev &&
isWebpack5 &&
new TraceEntryPointsPlugin({ appDir: dir }),
// Moment.js is an extremely popular library that bundles large locale files
// by default due to how Webpack interprets its code. This is a practical
// solution that requires the user to opt into importing specific locales.
Expand Down
Loading