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

Function generateBundle

packages/vite/configuration/angular.ts:186–262  ·  view source on GitHub ↗
(_options, bundle)

Source from the content-addressed store, hash-verified

184 apply: 'build' as const,
185 enforce: 'post' as const,
186 async generateBundle(_options, bundle) {
187 function isNsAngularPolyfillsChunk(chunk: any): boolean {
188 if (!chunk || !(chunk as any).modules) return false;
189 return Object.keys((chunk as any).modules).some((m) => m.includes('node_modules/@nativescript/angular/fesm2022/nativescript-angular-polyfills.mjs'));
190 }
191 const { babel, linkerPlugin } = await ensureSharedAngularLinker(process.cwd());
192 if (!babel || !linkerPlugin) return;
193 const strict = process.env.NS_STRICT_NG_LINK === '1' || process.env.NS_STRICT_NG_LINK === 'true';
194 const enforceStrict = process.env.NS_STRICT_NG_LINK_ENFORCE === '1' || process.env.NS_STRICT_NG_LINK_ENFORCE === 'true';
195 const debug = process.env.VITE_DEBUG_LOGS === '1' || process.env.VITE_DEBUG_LOGS === 'true';
196 const unlinked: string[] = [];
197 for (const [fileName, chunk] of Object.entries(bundle)) {
198 if (!fileName.endsWith('.mjs') && !fileName.endsWith('.js')) continue;
199 if (chunk && (chunk as any).type === 'chunk') {
200 const code = (chunk as any).code as string;
201 if (!code) continue;
202 const isNsPolyfills = isNsAngularPolyfillsChunk(chunk);
203 try {
204 const res = await (babel as any).transformAsync(code, {
205 filename: fileName,
206 configFile: false,
207 babelrc: false,
208 sourceMaps: false,
209 compact: false,
210 plugins: [linkerPlugin],
211 });
212 const finalCode = res?.code && res.code !== code ? res.code : code;
213 if (finalCode !== code) {
214 (chunk as any).code = finalCode;
215 if (debug) {
216 try {
217 console.log('[ns-angular-linker][post] linked', fileName, isNsPolyfills ? '(polyfills)' : '');
218 } catch {}
219 }
220 }
221 if (strict && !isNsPolyfills && containsRealNgDeclare(finalCode)) {
222 unlinked.push(fileName);
223 }
224 } catch {
225 if (strict) unlinked.push(fileName);
226 }
227 }
228 }
229 if (strict && unlinked.length) {
230 const details: string[] = [];
231 for (const fname of unlinked) {
232 const chunk: any = (bundle as any)[fname];
233 const modIds = chunk?.modules
234 ? Object.keys(chunk.modules)
235 .filter((m) => /node_modules\/(?:@angular|@nativescript\/angular)\//.test(m))
236 .slice(0, 8)
237 : [];
238 const isOnlyPolyfills = modIds.length > 0 && modIds.every((m) => m.includes('node_modules/@nativescript/angular/fesm2022/nativescript-angular-polyfills.mjs'));
239 if (isOnlyPolyfills) continue;
240 let snippet = '';
241 try {
242 const code = (chunk as any).code as string;
243 const idx = code.indexOf('ɵɵngDeclare');

Callers

nothing calls this directly

Calls 15

containsRealNgDeclareFunction · 0.85
everyMethod · 0.80
includesMethod · 0.80
indexOfMethod · 0.80
replaceMethod · 0.80
joinMethod · 0.80
warnMethod · 0.80
keysMethod · 0.65
logMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected