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

49 lines (48 loc) 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDefaultPort = getDefaultPort; exports.toFederationName = toFederationName; exports.normalizeScaffoldOptions = normalizeScaffoldOptions; const devkit_1 = require("@nx/devkit"); const internal_1 = require("@nx/devkit/internal"); // Default ports are split so a `consumer` + `provider` generated with no // overrides don't collide. Consumer gets the round base (the user navigates // to it); providers get base+1, base+2, etc., so a manifest pointing at // `consumer-base + 1` lines up with the first generated provider. // // Vite base deliberately avoids 5000 (macOS AirTunes binds it on the IPv4 // wildcard, leading to silent EADDRINUSE on `127.0.0.1`). const DEFAULT_BASE_PORTS = { vite: 5100, rsbuild: 3100, rspack: 8100, }; function getDefaultPort(bundler, surface) { const base = DEFAULT_BASE_PORTS[bundler]; return surface === 'consumer' ? base : base + 1; } // Federation `name` must be a JS identifier so the bundler can use it as a // global namespace. Hyphens are allowed in project names but invalid as an // identifier, so we coerce to underscores. function toFederationName(projectName) { if (!/[A-Za-z0-9]/.test(projectName)) { throw new Error(`Cannot derive a federation name from project name '${projectName}'. Use letters, digits, hyphens, or underscores.`); } const candidate = projectName .replace(/-/g, '_') .replace(/[^A-Za-z0-9_]/g, ''); if (/^[0-9]/.test(candidate)) { throw new Error(`Federation name '${candidate}' (derived from project '${projectName}') cannot start with a digit. Rename the project.`); } return candidate; } async function normalizeScaffoldOptions(tree, raw) { const bundler = raw.bundler ?? 'vite'; const { projectName, projectRoot } = await (0, internal_1.determineProjectNameAndRootOptions)(tree, { projectType: 'application', directory: raw.directory, }); const federationName = toFederationName((0, devkit_1.names)(projectName).fileName); const port = raw.port ?? getDefaultPort(bundler, raw.surface); return { projectName, federationName, bundler, port, projectRoot }; }