|
|
import type { API, FileInfo, Options } from 'jscodeshift' |
|
|
import { createParserFromPath } from '../lib/parser' |
|
|
|
|
|
export default function transformer( |
|
|
file: FileInfo, |
|
|
_api: API, |
|
|
options: Options |
|
|
) { |
|
|
const j = createParserFromPath(file.path) |
|
|
const root = j(file.source) |
|
|
let hasChanges = false |
|
|
|
|
|
|
|
|
|
|
|
root |
|
|
.find(j.ImportDeclaration, { |
|
|
source: { value: '@next/font' }, |
|
|
}) |
|
|
.forEach((fontImport) => { |
|
|
hasChanges = true |
|
|
fontImport.node.source = j.stringLiteral('next/font') |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
root |
|
|
.find(j.ImportDeclaration, { |
|
|
source: { value: '@next/font/google' }, |
|
|
}) |
|
|
.forEach((fontImport) => { |
|
|
hasChanges = true |
|
|
fontImport.node.source = j.stringLiteral('next/font/google') |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
} |
|
|
|