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

Function intlJsonPlugin

vitest.browser.config.ts:25–57  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23
24// Handles ../intl/*.json and ../intl/<feature>/*.json imports.
25function intlJsonPlugin(): Plugin {
26 return {
27 name: 'intl-json-loader',
28 async resolveId(source, importer) {
29 if (importer && /\/intl\/.*\*.json$/.test(source)) {
30 const dir = path.dirname(importer);
31 const intlDir = path.resolve(dir, source.replace('*.json', ''));
32 return `virtual:intl-messages:${intlDir}`;
33 }
34 return null;
35 },
36 async load(id) {
37 if (id.startsWith('virtual:intl-messages:')) {
38 const intlDir = id.replace('virtual:intl-messages:', '');
39 try {
40 const files = fs.readdirSync(intlDir).filter(f => f.endsWith('.json'));
41 const messages: Record<string, Record<string, string>> = {};
42
43 for (const file of files) {
44 const locale = path.basename(file, '.json');
45 const content = fs.readFileSync(path.join(intlDir, file), 'utf-8');
46 messages[locale] = JSON.parse(content);
47 }
48
49 return `export default ${JSON.stringify(messages)};`;
50 } catch {
51 return 'export default {};';
52 }
53 }
54 return null;
55 }
56 };
57}
58
59// Resolve @react-spectrum/s2/illustrations/* imports
60function illustrationResolverPlugin(): Plugin {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected