-
Notifications
You must be signed in to change notification settings - Fork 28k
/
Copy pathbuilt-in-next-font.ts
46 lines (41 loc) · 1.24 KB
/
built-in-next-font.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import type { API, FileInfo, Options } from 'jscodeshift'
export default function transformer(
file: FileInfo,
api: API,
options: Options
) {
const j = api.jscodeshift.withParser('tsx')
const root = j(file.source)
let hasChanges = false
// Before: import { ... } from '@next/font'
// After: import { ... } from 'next/font'
root
.find(j.ImportDeclaration, {
source: { value: '@next/font' },
})
.forEach((fontImport) => {
hasChanges = true
fontImport.node.source = j.stringLiteral('next/font')
})
// Before: import { ... } from '@next/font/google'
// After: import { ... } from 'next/font/google'
root
.find(j.ImportDeclaration, {
source: { value: '@next/font/google' },
})
.forEach((fontImport) => {
hasChanges = true
fontImport.node.source = j.stringLiteral('next/font/google')
})
// Before: import localFont from '@next/font/local'
// After: import localFont from 'next/font/local'
root
.find(j.ImportDeclaration, {
source: { value: '@next/font/local' },
})
.forEach((fontImport) => {
hasChanges = true
fontImport.node.source = j.stringLiteral('next/font/local')
})
return hasChanges ? root.toSource(options) : file.source
}