MCPcopy Create free account
hub / github.com/vanilla-extract-css/vanilla-extract / extractFilesFromCodeBlock

Function extractFilesFromCodeBlock

site/code-block-loader.js:40–62  ·  view source on GitHub ↗
(code)

Source from the content-addressed store, hash-verified

38};
39
40function extractFilesFromCodeBlock(code) {
41 const fileMatches = code.matchAll(/(?:\/\/\s(?<fileName>[\w.]+\.tsx?))/g);
42
43 let lastIndex = code.length - 1;
44
45 return Array.from(fileMatches, (match) => ({
46 ...match.groups,
47 index: match.index,
48 })).reduceRight((acc, curr) => {
49 const result = [
50 {
51 fileName: curr.fileName,
52 contents: code
53 .slice(curr.index + `// ${curr.fileName}`.length, lastIndex)
54 .trim(),
55 },
56 ...acc,
57 ];
58 lastIndex = curr.index;
59
60 return result;
61 }, []);
62}
63
64async function getCss(entrypointFile, files, rootContext) {
65 // Any relative file is considered virtual

Callers 1

loaderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…