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

Function Once

packages/vite/helpers/postcss-platform-config.ts:22–44  ·  view source on GitHub ↗
(root: any)

Source from the content-addressed store, hash-verified

20 {
21 postcssPlugin: 'ns-postcss-platform-import-rewrite',
22 Once(root: any) {
23 try {
24 const currentFile: string | undefined = root?.source?.input?.file;
25 if (!currentFile) return;
26 const currentDir = path.dirname(currentFile);
27 root.walkAtRules('import', (rule: any) => {
28 const m = /^\s*(?:url\()?["]?([^"')]+)["]?\)?/.exec(rule.params || '');
29 if (!m) return;
30 const spec = m[1];
31 if (!spec || !(spec.startsWith('.') || spec.startsWith('/'))) return;
32 if (!spec.endsWith('.css')) return;
33 const abs = path.isAbsolute(spec) ? spec : path.resolve(currentDir, spec);
34 if (existsSync(abs)) return;
35 const ext = platform === 'android' ? '.android.css' : '.ios.css';
36 const alt = abs.replace(/\.css$/, ext);
37 if (existsSync(alt)) {
38 let rel = path.relative(currentDir, alt).replace(/\\/g, '/');
39 if (!rel.startsWith('.')) rel = './' + rel;
40 rule.params = (rule.params as string).replace(spec, rel);
41 }
42 });
43 } catch {}
44 },
45 },
46 postcssImport({
47 resolve(id: string, basedir: string) {

Callers

nothing calls this directly

Calls 3

isAbsoluteMethod · 0.80
resolveMethod · 0.80
replaceMethod · 0.80

Tested by

no test coverage detected