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

Function getRenamedSpecifier

scripts/migrateDeps.mjs:834–919  ·  view source on GitHub ↗
(specifier, from, importedName, relative = true)

Source from the content-addressed store, hash-verified

832}
833
834function getRenamedSpecifier(specifier, from, importedName, relative = true) {
835 if (skipped.some(s => specifier.includes(s))) {
836 return specifier;
837 }
838
839 let parts = specifier.split('/');
840 let scope = parts.shift();
841 let pkg = scope;
842 if (pkg.startsWith('@')) {
843 pkg = parts.shift();
844 }
845
846 let monopackage;
847 if (scope === '@react-spectrum') {
848 monopackage = pkg === 's2' ? '@react-spectrum/s2' : '@adobe/react-spectrum';
849 } else if (scope.startsWith('@')) {
850 monopackage = scope.slice(1);
851 } else {
852 monopackage = scope;
853 }
854
855 let name = parts.join('/');
856
857 let [fromPkg] = parsePackage(from);
858 if (relative && fromPkg === monopackage) {
859 let subpath =
860 pkg === monopackage || monopackage === '@react-spectrum/s2' ? name : `${pkg}/${name}`;
861 let fullPath =
862 monopackage === 'react-aria-components' || monopackage === '@react-spectrum/s2'
863 ? `packages/${monopackage}/src/${subpath}`
864 : `packages/${monopackage}/src/${subpath}`;
865 let relative = path.relative(path.dirname(from), fullPath);
866 if (!relative.startsWith('.')) {
867 relative = './' + relative;
868 }
869 return relative;
870 }
871
872 if (monopackage === 'react-aria-components' || monopackage === '@react-spectrum/s2') {
873 return `${monopackage}/${name}`;
874 }
875
876 if (specifier === '@react-spectrum/theme-default') {
877 return '@adobe/react-spectrum/defaultTheme';
878 }
879
880 if (specifier === '@react-spectrum/theme-dark') {
881 return '@adobe/react-spectrum/darkTheme';
882 }
883
884 if (specifier === '@react-spectrum/theme-light') {
885 return '@adobe/react-spectrum/lightTheme';
886 }
887
888 let isPrivate = importedName == null || privateNames.has(importedName);
889 if (
890 ((monopackage === 'react-aria' || monopackage === 'react-stately') &&
891 (name === 'Virtualizer' || parentFile[name] === 'Virtualizer')) ||

Callers 1

getImportStatementsFunction · 0.85

Calls 3

parsePackageFunction · 0.85
sliceMethod · 0.80
hasMethod · 0.65

Tested by

no test coverage detected