-
Notifications
You must be signed in to change notification settings - Fork 30.3k
feat: add instrumentation hook #46002
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
Changes from 13 commits
3f39345
1cffc9b
182a58c
5eb8974
42621c1
18ef6c5
77cd616
f501bed
f92dc3c
10f657f
2371da1
7ae8c72
38ca451
ea85bac
4885f7c
bb5fa5c
b6f5f50
4e5f7bc
078e69b
8cf48f9
5d47498
f05ffdf
95f3ba8
5613843
be69f14
0eb406c
ceb1ef6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import { fileExists } from '../lib/file-exists' | |
| import Watchpack from 'next/dist/compiled/watchpack' | ||
| import stripAnsi from 'next/dist/compiled/strip-ansi' | ||
| import { warn } from '../build/output/log' | ||
| import { getPossibleInstrumentationHookFilenames } from '../build/utils' | ||
|
|
||
| let isTurboSession = false | ||
| let sessionStopHandled = false | ||
|
|
@@ -612,20 +613,50 @@ If you cannot make the changes above, but still want to try out\nNext.js v13 wit | |
| const watchedEntryLength = parentDir.split('/').length + 1 | ||
| const previousItems = new Set() | ||
|
|
||
| const files = getPossibleInstrumentationHookFilenames( | ||
| dir, | ||
| config.pageExtensions! | ||
| ) | ||
|
|
||
| const wp = new Watchpack({ | ||
| ignored: (entry: string) => { | ||
| // watch only one level | ||
| return !(entry.split('/').length <= watchedEntryLength) | ||
| return ( | ||
| !(entry.split('/').length <= watchedEntryLength) && | ||
| !files.includes(entry) | ||
| ) | ||
| }, | ||
| }) | ||
|
|
||
| wp.watch({ directories: [parentDir], startTime: 0 }) | ||
|
|
||
| let instrumentationFileTimeCache: number | undefined = undefined | ||
| wp.on('aggregated', () => { | ||
| const knownFiles = wp.getTimeInfoEntries() | ||
| const newFiles: string[] = [] | ||
| let hasPagesApp = false | ||
|
|
||
| // check if the `instrumentation.js` has changed | ||
| // if it has we need to restart the server | ||
| const instrumentationFile = [...knownFiles.keys()].find((key) => | ||
| files.includes(key) | ||
| ) | ||
| if (instrumentationFile) { | ||
| const instrumentationFileTime = | ||
| knownFiles.get(instrumentationFile)?.timestamp | ||
| if ( | ||
| instrumentationFileTimeCache !== undefined && | ||
| instrumentationFileTime !== instrumentationFileTimeCache | ||
| ) { | ||
| warn( | ||
| `The instrumentation file has changed, restarting the server to apply changes.` | ||
| ) | ||
| childProcessExitUnsub() | ||
| childProcess?.kill() | ||
| childProcessExitUnsub = setupFork() | ||
|
||
| } else { | ||
| instrumentationFileTimeCache = instrumentationFileTime | ||
| } | ||
| } | ||
|
|
||
| // if the dir still exists nothing to check | ||
| try { | ||
| const result = findPagesDir(dir, !!config.experimental?.appDir) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.