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

Function name

packages/dev/parcel-namer-docs/DocsNamer.js:24–141  ·  view source on GitHub ↗
({bundle, bundleGraph, options})

Source from the content-addressed store, hash-verified

22
23module.exports = new Namer({
24 name({bundle, bundleGraph, options}) {
25 if (!process.env.DOCS_ENV) {
26 return null;
27 }
28
29 let main = bundle.getMainEntry();
30 if (main && main.meta.isMDX) {
31 // A docs page. Generate the correct URL for it based on its location.
32 // Get relative path to entry file from the project root (will be e.g. `packages/@react-spectrum/button/docs/Button.mdx`)
33 let entryFilePath = path.relative(options.projectRoot, main.filePath);
34 let parts = entryFilePath.split(path.sep);
35
36 let basename = path.basename(entryFilePath, path.extname(entryFilePath)) + '.html';
37
38 // For dev files, simply /PageName.html or /dir/PageName.html
39 if (parts[1] === 'dev') {
40 let devPath = parts.slice(4, -1);
41 // move /releases to v3/releases
42 if (devPath[0] === 'releases') {
43 return path.join('v3', ...devPath, basename);
44 }
45
46 // move /react-spectrum to v3 (aka getting started, etc)
47 if (devPath[0] === 'react-spectrum') {
48 return path.join('v3', ...devPath.slice(1), basename);
49 }
50
51 // move /react-aria and /react-stately to top-level
52 if (devPath[0] === 'react-aria' || devPath[0] === 'react-stately') {
53 return path.join(...devPath.slice(1), basename);
54 }
55
56 return path.join(...devPath, basename);
57 }
58
59 // // For @internationalized, group by package name.
60 if (parts[1] === '@internationalized') {
61 return path.join(parts[1].replace(/^@/, ''), parts[2], ...parts.slice(4, -1), basename);
62 }
63
64 if (parts[1] === 'react-aria-components') {
65 // check if a redirect exists for this react-aria-components page
66 // handle both top-level files and subdirectories like examples/
67 let subPath = parts.slice(3, -1);
68 return path.join('react-aria', ...subPath, basename);
69 }
70
71 // move @react-spectrum pages under /v3 aka components and stuff
72 let namespace = parts[1].replace(/^@/, '');
73 if (namespace === 'adobe' || namespace === 'react-spectrum') {
74 return `v3/${basename}`;
75 }
76
77 if (namespace === 'react-aria') {
78 if (
79 /use(Clipboard|Collator|.*Formatter|Drag.*|Drop.*|Field|Filter|Focus.*|Hover|Id|IsSSR|Keyboard|Label|Landmark|Locale|.*Press|Move|ObjectRef)\.html$/.test(
80 basename
81 )

Callers

nothing calls this directly

Calls 1

sliceMethod · 0.80

Tested by

no test coverage detected