( file: FileInfo, _api: API, options: Options )
| 2 | import { createParserFromPath } from '../lib/parser' |
| 3 | |
| 4 | export 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 | } |
nothing calls this directly
no test coverage detected