(code: string, importPath: string)
| 9 | name: 'extFormatPlugin', |
| 10 | |
| 11 | transform(code: string, importPath: string): TransformResult { |
| 12 | if (/\0/.test(importPath)) { |
| 13 | return null; |
| 14 | } |
| 15 | |
| 16 | const { ext, filePath, format } = normalizeFsPathQuery(importPath); |
| 17 | |
| 18 | // ?format= param takes precedence before file extension |
| 19 | switch (format) { |
| 20 | case 'url': |
| 21 | return { code: formatUrl(config, this, code, filePath, ext), map: null }; |
| 22 | case 'text': |
| 23 | return { code: formatText(code, filePath), map: null }; |
| 24 | } |
| 25 | |
| 26 | // didn't provide a ?format= param |
| 27 | // check if it's a known extension we should format |
| 28 | if (ext != null && FORMAT_TEXT_EXTS.includes(ext)) { |
| 29 | return { code: formatText(code, filePath), map: null }; |
| 30 | } |
| 31 | |
| 32 | if (ext != null && FORMAT_URL_MIME[ext]) { |
| 33 | return { code: formatUrl(config, this, code, filePath, ext), map: null }; |
| 34 | } |
| 35 | |
| 36 | return null; |
| 37 | }, |
| 38 | }; |
| 39 | }; |
| 40 |
nothing calls this directly
no test coverage detected