MCPcopy
hub / github.com/vercel/next.js / transformer

Function transformer

packages/next-codemod/transforms/built-in-next-font.ts:4–47  ·  view source on GitHub ↗
(
  file: FileInfo,
  _api: API,
  options: Options
)

Source from the content-addressed store, hash-verified

2import { createParserFromPath } from '../lib/parser'
3
4export default function transformer(
5 file: FileInfo,
6 _api: API,
7 options: Options
8) {
9 const j = createParserFromPath(file.path)
10 const root = j(file.source)
11 let hasChanges = false
12
13 // Before: import { ... } from '@next/font'
14 // After: import { ... } from 'next/font'
15 root
16 .find(j.ImportDeclaration, {
17 source: { value: '@next/font' },
18 })
19 .forEach((fontImport) => {
20 hasChanges = true
21 fontImport.node.source = j.stringLiteral('next/font')
22 })
23
24 // Before: import { ... } from '@next/font/google'
25 // After: import { ... } from 'next/font/google'
26 root
27 .find(j.ImportDeclaration, {
28 source: { value: '@next/font/google' },
29 })
30 .forEach((fontImport) => {
31 hasChanges = true
32 fontImport.node.source = j.stringLiteral('next/font/google')
33 })
34
35 // Before: import localFont from '@next/font/local'
36 // After: import localFont from 'next/font/local'
37 root
38 .find(j.ImportDeclaration, {
39 source: { value: '@next/font/local' },
40 })
41 .forEach((fontImport) => {
42 hasChanges = true
43 fontImport.node.source = j.stringLiteral('next/font/local')
44 })
45
46 return hasChanges ? root.toSource(options) : file.source
47}

Callers

nothing calls this directly

Calls 4

createParserFromPathFunction · 0.90
jFunction · 0.50
forEachMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected