MCPcopy Create free account
hub / github.com/adobe/react-spectrum / buildImportMap

Function buildImportMap

scripts/migrateDeps.mjs:515–539  ·  view source on GitHub ↗
(file)

Source from the content-addressed store, hash-verified

513}
514
515function 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
541function rewriteMonopackageImports(file, pkg, subpath) {
542 if (path.extname(file) === '.mdx') {

Callers 1

migrateDeps.mjsFile · 0.85

Calls 1

parseFunction · 0.70

Tested by

no test coverage detected