Skip to content

Commit

Permalink
fix(perf): lazy load babel/code-frame (#55024)
Browse files Browse the repository at this point in the history
This changes to lazy import so that babel code-frame isn't loaded until it is needed.
  • Loading branch information
styfle committed Sep 6, 2023
1 parent 5471cd9 commit 9e8a19f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/next/src/lib/typescript/diagnosticFormatter.ts
@@ -1,4 +1,3 @@
import { codeFrameColumns } from 'next/dist/compiled/babel/code-frame'
import chalk from 'next/dist/compiled/chalk'
import path from 'path'

Expand Down Expand Up @@ -369,6 +368,7 @@ export function getFormattedDiagnostic(
message += reason + '\n'

if (!isLayoutOrPageError && diagnostic.file) {
const { codeFrameColumns } = require('next/dist/compiled/babel/code-frame')
const pos = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start!)
const line = pos.line + 1
const character = pos.character + 1
Expand Down
4 changes: 3 additions & 1 deletion packages/next/src/server/lib/router-utils/setup-dev.ts
Expand Up @@ -10,7 +10,6 @@ import {
} from '../../../build/swc'
import type { Socket } from 'net'
import ws from 'next/dist/compiled/ws'
import { codeFrameColumns } from 'next/dist/compiled/babel/code-frame'

import fs from 'fs'
import url from 'url'
Expand Down Expand Up @@ -237,6 +236,9 @@ async function startWatcher(opts: SetupOpts) {
start.column
} ${formattedTitle}`
if (source.source.content) {
const {
codeFrameColumns,
} = require('next/dist/compiled/babel/code-frame')
message +=
'\n\n' +
codeFrameColumns(
Expand Down

0 comments on commit 9e8a19f

Please sign in to comment.