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

80 lines (79 loc) 4.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AngularDevkitKarmaMigrator = void 0; const devkit_1 = require("@nx/devkit"); const js_1 = require("@nx/js"); const path_1 = require("path"); const builder_migrator_1 = require("./builder.migrator"); class AngularDevkitKarmaMigrator extends builder_migrator_1.BuilderMigrator { constructor(tree, project, projectConfig, logger) { super(tree, ['@angular/build:karma', '@angular-devkit/build-angular:karma'], 'karma', project, projectConfig, logger); } migrate() { if (this.skipMigration) { return; } for (const [name, target] of this.targets) { this.moveFilePathsFromTargetToProjectRoot(target, [ 'karmaConfig', 'tsConfig', 'webWorkerTsConfig', ]); this.updateTargetConfiguration(name, target); this.updateTsConfigFileUsedByTestTarget(name, target); this.updateCacheableOperations([name]); } if (!this.targets.size && this.projectConfig.root === '') { // there could still be a karma.conf.js file in the root // so move to new location const karmaConfig = 'karma.conf.js'; if (this.tree.exists(karmaConfig)) { this.logger.info('No "test" target was found, but a root Karma config file was found in the project root. The file will be moved to the new location.'); this.moveProjectRootFile(karmaConfig); } } } updateTargetConfiguration(targetName, target) { if (!target.options) { this.logger.warn(`The target "${targetName}" is not specifying any options. Skipping updating the target configuration.`); return; } target.options.main = target.options.main && this.convertAsset(target.options.main); target.options.polyfills = Array.isArray(target.options.polyfills) ? target.options.polyfills.map((p) => this.convertSourceRootPath(p)) : target.options.polyfills && this.convertSourceRootPath(target.options.polyfills); target.options.tsConfig = target.options.tsConfig && (0, devkit_1.joinPathFragments)(this.project.newRoot, (0, path_1.basename)(target.options.tsConfig)); target.options.karmaConfig = target.options.karmaConfig && (0, devkit_1.joinPathFragments)(this.project.newRoot, (0, path_1.basename)(target.options.karmaConfig)); target.options.assets = target.options.assets && target.options.assets.map((asset) => this.convertAsset(asset)); target.options.styles = target.options.styles && target.options.styles.map((style) => this.convertAsset(style)); target.options.scripts = target.options.scripts && target.options.scripts.map((script) => this.convertAsset(script)); (0, devkit_1.updateProjectConfiguration)(this.tree, this.project.name, { ...this.projectConfig, }); } updateTsConfigFileUsedByTestTarget(targetName, target) { if (!target.options?.tsConfig) { this.logger.warn(`The "${targetName}" target does not have the "tsConfig" option configured. Skipping updating the tsConfig file.`); return; } if (!this.tree.exists(target.options.tsConfig)) { const originalTsConfigPath = this.originalProjectConfig.targets[targetName].options.tsConfig; this.logger.warn(`The tsConfig file "${originalTsConfigPath}" specified in the "${targetName}" target could not be found. Skipping updating the tsConfig file.`); return; } this.updateTsConfigFile(target.options.tsConfig, (0, js_1.getRootTsConfigPathInTree)(this.tree), (0, devkit_1.offsetFromRoot)(this.projectConfig.root)); } } exports.AngularDevkitKarmaMigrator = AngularDevkitKarmaMigrator;