Build the set of "anything that looks like an import or reference TO `target`'s stem".
(targetRel: string)
| 116 | |
| 117 | /** Build the set of "anything that looks like an import or reference TO `target`'s stem". */ |
| 118 | function buildReferencePatterns(targetRel: string): string[] { |
| 119 | const stem = path.basename(targetRel).replace(/\.[^.]+$/, ''); |
| 120 | const noExt = targetRel.replace(/\.[^.]+$/, ''); |
| 121 | return [ |
| 122 | // ES imports |
| 123 | `from './${stem}'`, `from "./${stem}"`, |
| 124 | `from '../${stem}'`, `from "../${stem}"`, |
| 125 | `from '${noExt}'`, `from "${noExt}"`, |
| 126 | `from '/${noExt}'`, `from "/${noExt}"`, |
| 127 | // require |
| 128 | `require('${stem}')`, `require("${stem}")`, |
| 129 | `require('${noExt}')`, `require("${noExt}")`, |
| 130 | // module path (in path-alias projects) |
| 131 | `'/${stem}'`, `"/${stem}"`, |
| 132 | `/${stem}'`, `/${stem}"`, |
| 133 | // Python |
| 134 | `import ${noExt.replace(/[/\\]/g, '.')}`, |
| 135 | `from ${noExt.replace(/[/\\]/g, '.')} import`, |
| 136 | ]; |
| 137 | } |
| 138 | |
| 139 | /** Extract `export` names (ES/TS only) from file content. Imperfect but pragmatic. */ |
| 140 | function extractExports(content: string): { name: string; line: number }[] { |