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

Function createPublicExports

scripts/migrateDeps.mjs:921–1051  ·  view source on GitHub ↗
(file, monopackage, scope, pkg)

Source from the content-addressed store, hash-verified

919}
920
921function createPublicExports(file, monopackage, scope, pkg) {
922 if (!importMap[monopackage]) {
923 return;
924 }
925
926 let content = fs.readFileSync(file, 'utf8');
927 let ast = recast.parse(content, {
928 parser: {
929 parse() {
930 return parse(content, {
931 sourceType: 'module',
932 plugins: ['typescript', 'jsx', 'importAttributes'],
933 sourceFilename: file,
934 tokens: true,
935 errorRecovery: true
936 });
937 }
938 }
939 });
940
941 let groups = {};
942 let unmatched = [];
943 let specifiers = [];
944 let typeSpecifiers = [];
945 for (let node of ast.program.body) {
946 if (node.type === 'ExportNamedDeclaration' && node.source) {
947 if (node.source.value.startsWith('./')) {
948 if (node.exportKind === 'type') {
949 typeSpecifiers.push(...node.specifiers);
950 } else {
951 specifiers.push(...node.specifiers);
952 }
953 } else {
954 unmatched.push(node);
955 }
956
957 node.specifiers = node.specifiers.filter(s => {
958 if (s.exported.name === 'theme') {
959 s.exported = s.local;
960 return true;
961 }
962 return importMap[monopackage][s.exported.name];
963 });
964 if (node.source.value.startsWith('./') && node.specifiers.length > 0) {
965 let source = node.source.value.slice(2);
966 node.source.value = pkg ? `../src/${pkg}/${source}` : `../src/${source}`;
967 if (
968 standalone.has(source) ||
969 (monopackage === 'react-aria-components' && source === 'utils')
970 ) {
971 groups[source] ||= [];
972 groups[source].push(node);
973 } else if (parentFile[source]) {
974 groups[parentFile[source]] ||= [];
975 groups[parentFile[source]].push(node);
976 }
977 }
978 }

Callers 2

migratePackageFunction · 0.85
migrateToMonopackageFunction · 0.85

Calls 6

getImportStatementsFunction · 0.85
pushMethod · 0.80
sliceMethod · 0.80
filterMethod · 0.65
hasMethod · 0.65
parseMethod · 0.45

Tested by

no test coverage detected