MCPcopy
hub / github.com/facebook/docusaurus / genChunkName

Function genChunkName

packages/docusaurus/src/server/codegen/codegenRoutes.ts:55–82  ·  view source on GitHub ↗
(
  modulePath: string,
  prefix?: string,
  preferredName?: string,
  shortId: boolean = process.env.NODE_ENV === 'production',
)

Source from the content-addressed store, hash-verified

53 * other characters. Useful for bundle size. Defaults to `true` in production.
54 */
55export function genChunkName(
56 modulePath: string,
57 prefix?: string,
58 preferredName?: string,
59 shortId: boolean = process.env.NODE_ENV === 'production',
60): string {
61 let chunkName = chunkNameCache.get(modulePath);
62 if (!chunkName) {
63 if (shortId) {
64 chunkName = simpleHash(modulePath, 8);
65 } else {
66 let str = modulePath;
67 if (preferredName) {
68 const shortHash = simpleHash(modulePath, 3);
69 str = `${preferredName}${shortHash}`;
70 }
71 const name = docuHash(str);
72 chunkName = prefix ? `${prefix}---${name}` : name;
73 }
74 const seenCount = (chunkNameCount.get(chunkName) ?? 0) + 1;
75 if (seenCount > 1) {
76 chunkName += seenCount.toString(36);
77 }
78 chunkNameCache.set(modulePath, chunkName);
79 chunkNameCount.set(chunkName, seenCount);
80 }
81 return chunkName;
82}
83
84/**
85 * Takes a piece of route config, and serializes it into raw JS code. The shape

Callers 2

genChunkNamesFunction · 0.85

Calls 2

simpleHashFunction · 0.90
docuHashFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…