UNPKG

@nx/rspack

Version:

The Nx Plugin for Rspack contains executors and generators that support building applications using Rspack.

73 lines (72 loc) 2.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.nxRspackComposablePlugin = void 0; exports.isNxRspackComposablePlugin = isNxRspackComposablePlugin; exports.composePlugins = composePlugins; exports.composePluginsSync = composePluginsSync; const devkit_1 = require("@nx/devkit"); const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup"); const configuration_1 = require("nx/src/config/configuration"); exports.nxRspackComposablePlugin = 'nxRspackComposablePlugin'; function isNxRspackComposablePlugin(a) { return a?.[exports.nxRspackComposablePlugin] === true; } function composePlugins(...plugins) { return Object.assign(async function combined(config, ctx) { // Rspack may be calling us as a standard config function. // Build up Nx context from environment variables. // This is to enable `@nx/rspack/plugin` to work with existing projects. if (ctx['env']) { ensureNxRspackExecutionContext(ctx); // Build this from scratch since what rspack passes us is the env, not config, // and `withNX()` creates a new config object anyway. config = {}; } for (const plugin of plugins) { const fn = await plugin; config = await fn(config, ctx); } return config; }, { [exports.nxRspackComposablePlugin]: true, }); } function composePluginsSync(...plugins) { return Object.assign(function combined(config, ctx) { for (const plugin of plugins) { config = plugin(config, ctx); } return config; }, { [exports.nxRspackComposablePlugin]: true, }); } function ensureNxRspackExecutionContext(ctx) { const projectName = process.env.NX_TASK_TARGET_PROJECT; const targetName = process.env.NX_TASK_TARGET_TARGET; const configurationName = process.env.NX_TASK_TARGET_CONFIGURATION; const projectGraph = (0, devkit_1.readCachedProjectGraph)(); const projectNode = projectGraph.nodes[projectName]; ctx.options ??= { root: devkit_1.workspaceRoot, projectRoot: projectNode.data.root, sourceRoot: (0, ts_solution_setup_1.getProjectSourceRoot)(projectNode.data), // These aren't actually needed since NxRspackPlugin and withNx both support them being undefined. assets: undefined, outputFileName: undefined, outputPath: undefined, rspackConfig: undefined, useTsconfigPaths: undefined, }; ctx.context ??= { projectName, targetName, configurationName, projectsConfigurations: (0, devkit_1.readProjectsConfigurationFromProjectGraph)(projectGraph), nxJsonConfiguration: (0, configuration_1.readNxJson)(devkit_1.workspaceRoot), cwd: process.cwd(), root: devkit_1.workspaceRoot, isVerbose: process.env['NX_VERBOSE_LOGGING'] === 'true', projectGraph, }; }