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

Function writePrivateExports

scripts/migrateDeps.mjs:1053–1134  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1051}
1052
1053function writePrivateExports() {
1054 let privateExports = {};
1055
1056 for (let file of fs.globSync('packages/**/*.{ts,tsx,js}')) {
1057 let content = fs.readFileSync(file, 'utf8');
1058 let ast = parse(content, {
1059 sourceType: 'module',
1060 plugins: ['typescript', 'jsx', 'importAttributes'],
1061 sourceFilename: file,
1062 tokens: true,
1063 errorRecovery: true
1064 });
1065
1066 for (let item of ast.program.body) {
1067 if (
1068 item.type === 'ImportDeclaration' ||
1069 (item.type === 'ExportNamedDeclaration' && item.source)
1070 ) {
1071 if (item.source.value.includes('/private/')) {
1072 privateExports[item.source.value] ??= new Set();
1073 for (let specifier of item.specifiers) {
1074 let importedName =
1075 specifier.type === 'ImportSpecifier' ? specifier.imported.name : specifier.local.name;
1076 privateExports[item.source.value].add(importedName);
1077 }
1078 }
1079 }
1080 }
1081 }
1082
1083 console.log(privateExports);
1084 for (let specifier in privateExports) {
1085 let file = `packages/${specifier.replace('/private/', '/exports/private/')}.ts`;
1086 fs.mkdirSync(path.dirname(file), {recursive: true});
1087
1088 let contents = 'export {';
1089 let first = true;
1090 for (let exp of privateExports[specifier]) {
1091 if (!first) {
1092 contents += ', ';
1093 }
1094 first = false;
1095 if (
1096 (!/^(use|UNSTABLE_use)/.test(exp) &&
1097 /(Aria|Props|State|Options)$/.test(exp) &&
1098 exp !== 'filterDOMProps' &&
1099 exp !== 'getSyntheticLinkProps' &&
1100 exp !== 'baseStyleProps' &&
1101 exp !== 'viewStyleProps' &&
1102 exp !== 'convertStyleProps') ||
1103 exp === 'LayoutNode' ||
1104 exp === 'MultipleSelectionManager' ||
1105 exp === 'RectCorner' ||
1106 exp === 'InvalidationContext' ||
1107 exp === 'CollectionBuilderContext' ||
1108 exp === 'PartialNode' ||
1109 exp === 'Modality' ||
1110 exp === 'SelectableItemStates' ||

Callers 1

migrateDeps.mjsFile · 0.85

Calls 2

parseFunction · 0.70
addMethod · 0.65

Tested by

no test coverage detected