MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / load

Function load

packages/vite/configuration/javascript.ts:30–99  ·  view source on GitHub ↗
(id)

Source from the content-addressed store, hash-verified

28 return null;
29 },
30 load(id) {
31 if (id !== RESOLVED_ID) return null;
32 // Build a platform-filtered static module registry at build time using recursive fs walk (no fast-glob dependency).
33 const roots = [appRoot];
34 const styleExtsSet = new Set(['css', 'scss', 'less', 'sass']);
35 function walk(dir: string, out: string[]) {
36 let entries: string[] = [];
37 try {
38 entries = readdirSync(dir);
39 } catch {
40 return out;
41 }
42 for (const entry of entries) {
43 const full = path.posix.join(dir, entry);
44 let st: any;
45 try {
46 st = statSync(full);
47 } catch {
48 continue;
49 }
50 if (st.isDirectory()) walk(full, out);
51 else out.push(full);
52 }
53 return out;
54 }
55 function enumerate(filter: (ext: string) => boolean) {
56 const files: string[] = [];
57 for (const r of roots) walk(r, files);
58 return files.filter((f) => filter(f.split('.').pop() || ''));
59 }
60 function shouldExcludeAbsolute(p: string) {
61 const file = p.split('/').pop() || '';
62 if (file.startsWith('_')) return true;
63 if (/\.d\.ts$/.test(p)) return true;
64 if (/([.-]worker)\.(ts|js)$/.test(file)) return true;
65 const isAndroidTagged = /\.android\./.test(p);
66 const isIosTagged = /\.ios\./.test(p) || /\.visionos\./.test(p);
67 if (platform === 'android' && isIosTagged) return true;
68 if ((platform === 'ios' || platform === 'visionos') && isAndroidTagged) return true;
69 return false;
70 }
71 function toImportSpecifier(abs: string) {
72 return '/' + abs.replace(/^\/+/, '');
73 }
74 function toCtxKey(abs: string) {
75 let rel = abs;
76 if (rel.startsWith(appRootPrefix)) rel = rel.slice(appRootPrefix.length);
77 return './' + rel;
78 }
79 const xmlFiles = enumerate((ext) => ext === 'xml').filter((f) => !shouldExcludeAbsolute(f));
80 const styleFiles = enumerate((ext) => styleExtsSet.has(ext)).filter((f) => !shouldExcludeAbsolute(f));
81 const jsFiles = enumerate((ext) => ext === 'js').filter((f) => !shouldExcludeAbsolute(f));
82 let importLines: string[] = [];
83 let registryEntries: string[] = [];
84 let moduleMapLines: string[] = [];
85 let index = 0;
86 function pushImport(abs: string, raw: boolean) {
87 const id = `__m${index++}`;

Callers

nothing calls this directly

Calls 7

enumerateFunction · 0.85
forEachMethod · 0.80
joinMethod · 0.80
replaceMethod · 0.80
shouldExcludeAbsoluteFunction · 0.70
pushImportFunction · 0.70
filterMethod · 0.45

Tested by

no test coverage detected