| 513 | } |
| 514 | |
| 515 | function buildImportMap(file) { |
| 516 | let content = fs.readFileSync(file, 'utf8'); |
| 517 | let ast = parse(content, { |
| 518 | sourceType: 'module', |
| 519 | plugins: ['typescript', 'jsx', 'importAttributes'], |
| 520 | sourceFilename: file, |
| 521 | tokens: true, |
| 522 | errorRecovery: true |
| 523 | }); |
| 524 | |
| 525 | let map = {}; |
| 526 | for (let node of ast.program.body) { |
| 527 | if (node.type === 'ExportNamedDeclaration' && node.source) { |
| 528 | for (let specifier of node.specifiers) { |
| 529 | let name = |
| 530 | specifier.exported.type === 'Identifier' |
| 531 | ? specifier.exported.name |
| 532 | : specifier.exported.value; |
| 533 | map[name] = [node.source.value, specifier.local.name]; |
| 534 | } |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | return map; |
| 539 | } |
| 540 | |
| 541 | function rewriteMonopackageImports(file, pkg, subpath) { |
| 542 | if (path.extname(file) === '.mdx') { |