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

Function prelinkPackage

packages/vite/helpers/prelink-angular.ts:47–77  ·  view source on GitHub ↗
(req: NodeRequire, pkgName: string, cacheRoot: string, debug: boolean)

Source from the content-addressed store, hash-verified

45}
46
47async function prelinkPackage(req: NodeRequire, pkgName: string, cacheRoot: string, debug: boolean) {
48 const pkgEntry = req.resolve(path.join(pkgName, 'package.json'));
49 const pkgDir = path.dirname(pkgEntry);
50 const fesmDir = path.join(pkgDir, 'fesm2022');
51 if (!(await pathExists(fesmDir))) return;
52 // Lazy load linker deps from app
53 let babel: any = null;
54 let createLinker: any = null;
55 try {
56 const babelPath = req.resolve('@babel/core');
57 const linkerPath = req.resolve('@angular/compiler-cli/linker/babel');
58 babel = await import(babelPath);
59 const linkerMod: any = await import(linkerPath);
60 createLinker = linkerMod.createLinkerPlugin || linkerMod.createEs2015LinkerPlugin;
61 } catch {
62 return; // Can't link without deps; skip quietly
63 }
64 const destDir = path.join(cacheRoot, pkgName, 'fesm2022');
65 await ensureDir(destDir);
66 const files = (await fs.readdir(fesmDir)).filter((f) => f.endsWith('.mjs'));
67 for (const file of files) {
68 const srcFile = path.join(fesmDir, file);
69 const cacheFile = path.join(destDir, file);
70 await copyOrLinkInto(babel, createLinker, srcFile, cacheFile);
71 if (debug) {
72 try {
73 console.log(`[ns-angular-prelink] cached`, `${pkgName}/fesm2022/${file}`);
74 } catch {}
75 }
76 }
77}
78
79export function createAngularPrelinkPlugin(projectRoot?: string): Plugin {
80 const req = createRequire(projectRoot ? projectRoot + '/package.json' : import.meta.url);

Callers 2

configFunction · 0.85
buildStartFunction · 0.85

Calls 7

pathExistsFunction · 0.85
ensureDirFunction · 0.85
copyOrLinkIntoFunction · 0.85
resolveMethod · 0.80
joinMethod · 0.80
filterMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected