UNPKG

@nx/react

Version:

The React plugin for Nx contains executors and generators for managing React applications and libraries within an Nx workspace. It provides: - Integration with libraries such as Jest, Vitest, Playwright, Cypress, and Storybook. - Generators for applica

63 lines (62 loc) 3.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.normalizeOptions = normalizeOptions; const devkit_1 = require("@nx/devkit"); const internal_1 = require("@nx/devkit/internal"); const assertion_1 = require("../../../utils/assertion"); const find_free_port_1 = require("./find-free-port"); const internal_2 = require("@nx/js/internal"); async function normalizeOptions(host, options) { await (0, internal_1.ensureRootProjectName)(options, 'application'); const { projectName, names: projectNames, projectRoot: appProjectRoot, importPath, } = await (0, internal_1.determineProjectNameAndRootOptions)(host, { name: options.name, projectType: 'application', directory: options.directory, rootProject: options.rootProject, }); const nxJson = (0, devkit_1.readNxJson)(host); const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' && nxJson.useInferencePlugins !== false; options.addPlugin ??= addPlugin; options.rootProject = appProjectRoot === '.'; const isUsingTsSolutionConfig = (0, internal_2.isUsingTsSolutionSetup)(host); const appProjectName = !isUsingTsSolutionConfig || options.name ? projectName : importPath; const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`; const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`; const parsedTags = options.tags ? options.tags.split(',').map((s) => s.trim()) : []; const fileName = 'app'; (0, assertion_1.assertValidStyle)(options.style); (0, assertion_1.assertValidReactRouter)(options.useReactRouter, options.bundler); if (options.useReactRouter && !options.bundler) { options.bundler = 'vite'; } options.useReactRouter = options.routing ? options.useReactRouter : false; const normalized = { ...options, projectName: appProjectName, appProjectRoot, importPath, e2eProjectName, e2eProjectRoot, parsedTags, fileName, hasStyles: options.style !== 'none', names: (0, devkit_1.names)(projectNames.projectSimpleName), isUsingTsSolutionConfig, useProjectJson: options.useProjectJson ?? !isUsingTsSolutionConfig, }; normalized.routing = normalized.routing ?? false; normalized.useReactRouter = normalized.useReactRouter ?? false; normalized.strict = normalized.strict ?? true; normalized.classComponent = normalized.classComponent ?? false; normalized.compiler = normalized.compiler ?? 'babel'; normalized.bundler = normalized.bundler ?? 'webpack'; normalized.unitTestRunner = normalized.unitTestRunner ?? 'jest'; normalized.e2eTestRunner = normalized.e2eTestRunner ?? 'playwright'; normalized.inSourceTests = normalized.minimal || normalized.inSourceTests; normalized.devServerPort ??= options.port ?? (0, find_free_port_1.findFreePort)(host); normalized.minimal = normalized.minimal ?? false; return normalized; }