UNPKG

@nx/remix

Version:

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

76 lines (75 loc) 3.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getRemixConfigPathDetails = getRemixConfigPathDetails; exports.getRemixConfigPath = getRemixConfigPath; exports.getRemixConfigPathFromProjectRoot = getRemixConfigPathFromProjectRoot; exports.getRemixConfigValues = getRemixConfigValues; const devkit_1 = require("@nx/devkit"); const executor_utils_1 = require("./executor-utils"); function getRemixConfigPathDetails(tree, projectName) { const project = (0, devkit_1.readProjectConfiguration)(tree, projectName); if (!project) throw new Error(`Project does not exist: ${projectName}`); for (const ext of ['.mjs', '.cjs', '.js', '.mts', '.cts', '.ts']) { const configPath = (0, devkit_1.joinPathFragments)(project.root, `vite.config${ext}`); if (tree.exists(configPath)) { return [configPath, 'vite']; } } for (const ext of ['.mjs', '.cjs', '.js']) { const configPath = (0, devkit_1.joinPathFragments)(project.root, `remix.config${ext}`); if (tree.exists(configPath)) { return [configPath, 'classic']; } } } function getRemixConfigPath(tree, projectName) { const project = (0, devkit_1.readProjectConfiguration)(tree, projectName); if (!project) throw new Error(`Project does not exist: ${projectName}`); for (const ext of ['.mjs', '.cjs', '.js']) { const configPath = (0, devkit_1.joinPathFragments)(project.root, `remix.config${ext}`); if (tree.exists(configPath)) { return configPath; } } } function getRemixConfigPathFromProjectRoot(tree, projectRoot) { let pathToRemixConfig; for (const ext of ['.js', '.mjs', '.cjs']) { pathToRemixConfig = (0, devkit_1.joinPathFragments)(projectRoot, `remix.config${ext}`); if (tree.exists(pathToRemixConfig)) { return pathToRemixConfig; } } throw new Error(`Could not find a Remix Config File. Please ensure a "remix.config.js" file exists at the root of your project.`); } const _remixConfigCache = {}; async function getRemixConfigValues(tree, projectName) { const [configPath, configType] = getRemixConfigPathDetails(tree, projectName); const remixConfigPath = (0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, configPath); const cacheKey = `${projectName}/${remixConfigPath}`; let appConfig = _remixConfigCache[cacheKey]; let resolvedConfig; if (!appConfig) { if (configType === 'vite') { const { resolveConfig } = await (0, executor_utils_1.loadViteDynamicImport)(); const viteBuildConfig = (await resolveConfig({ configFile: configPath, mode: 'development', }, 'build')); appConfig = viteBuildConfig.__remixPluginContext?.remixConfig; } else { try { const importedConfig = await Function(`return import("${remixConfigPath}?t=${Date.now()}")`)(); appConfig = (importedConfig?.default || importedConfig); } catch { appConfig = require(remixConfigPath); } } _remixConfigCache[cacheKey] = appConfig; } return appConfig; }