UNPKG

@nx/angular

Version:

The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: - Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Playwright and Cypre

56 lines (55 loc) 2.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.executorsToAddPolyfillTo = void 0; exports.default = default_1; const devkit_1 = require("@nx/devkit"); const targets_1 = require("../../utils/targets"); exports.executorsToAddPolyfillTo = [ '@angular/build:application', '@angular-devkit/build-angular:application', '@nx/angular:application', '@angular-devkit/build-angular:browser-esbuild', '@nx/angular:browser-esbuild', ]; async function default_1(tree) { const projects = (0, devkit_1.getProjects)(tree); for (const [projectName, project] of projects) { if (project.projectType !== 'application') { continue; } let isUpdated = false; for (const target of Object.values(project.targets ?? {})) { if (!exports.executorsToAddPolyfillTo.includes(target.executor)) { continue; } const polyfills = target.options?.['polyfills']; if (Array.isArray(polyfills) && polyfills.some((polyfill) => typeof polyfill === 'string' && polyfill.startsWith('@angular/localize'))) { // the polyfill is already present, skip continue; } // Only add '@angular/localize/init' polyfill if 'localize' option is enabled for (const [, options] of (0, targets_1.allTargetOptions)(target)) { if (options['localize']) { target.options ??= {}; const polyfills = target.options['polyfills']; // Ensure polyfills is an array before pushing if (typeof polyfills === 'string') { target.options['polyfills'] = [polyfills]; } else if (!Array.isArray(polyfills)) { target.options['polyfills'] = []; } target.options['polyfills'].push('@angular/localize/init'); isUpdated = true; break; } } } if (isUpdated) { (0, devkit_1.updateProjectConfiguration)(tree, projectName, project); } } await (0, devkit_1.formatFiles)(tree); }