MCPcopy Index your code
hub / github.com/adobe/react-spectrum / iconWrapperPlugin

Function iconWrapperPlugin

vitest.browser.config.ts:120–162  ·  view source on GitHub ↗

* Handle S2 workflow icons. * * Resolves the SVG and wraps it with createIcon from Icon.tsx.

()

Source from the content-addressed store, hash-verified

118 * Resolves the SVG and wraps it with createIcon from Icon.tsx.
119 */
120function iconWrapperPlugin(): Plugin {
121 const VIRTUAL_PREFIX = '\0s2-icon:';
122 const iconsDir = path.resolve(s2Dir, 's2wf-icons');
123
124 // Build a map from icon name -> absolute SVG path
125 const iconMap = new Map<string, string>();
126 if (fs.existsSync(iconsDir)) {
127 for (const file of fs.readdirSync(iconsDir)) {
128 const match = file.match(/^S2_Icon_(.+)_20_N\.svg$/);
129 if (match) {
130 iconMap.set(match[1], path.resolve(iconsDir, file));
131 }
132 }
133 }
134
135 return {
136 name: 'icon-wrapper',
137 enforce: 'pre',
138 resolveId(source) {
139 if (source.startsWith('@react-spectrum/s2/icons/')) {
140 const iconName = source.replace('@react-spectrum/s2/icons/', '');
141 if (iconMap.has(iconName)) {
142 return VIRTUAL_PREFIX + iconName;
143 }
144 }
145 return null;
146 },
147 load(id) {
148 if (id.startsWith(VIRTUAL_PREFIX)) {
149 const iconName = id.slice(VIRTUAL_PREFIX.length);
150 const svgPath = iconMap.get(iconName);
151 if (svgPath) {
152 return [
153 `import {createIcon} from '${path.resolve(s2Dir, 'src/Icon.tsx').replaceAll('\\', '/')}';`,
154 `import SvgComponent from '${svgPath.replaceAll('\\', '/')}';`,
155 `export default /*#__PURE__*/ createIcon(SvgComponent);`
156 ].join('\n');
157 }
158 }
159 return null;
160 }
161 };
162}
163
164let unlock: ((value: any) => void) | null = null;
165

Callers 1

Calls 1

setMethod · 0.45

Tested by

no test coverage detected