UNPKG

@nx/rsbuild

Version:

The Nx Plugin for Rsbuild contains an Nx plugin, executors and utilities that support building applications using Rsbuild.

61 lines (60 loc) 2.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.updateDependencies = updateDependencies; exports.initGenerator = initGenerator; exports.initGeneratorInternal = initGeneratorInternal; const internal_1 = require("@nx/devkit/internal"); const devkit_1 = require("@nx/devkit"); const plugin_1 = require("../../plugins/plugin"); const versions_1 = require("../../utils/versions"); const version_utils_1 = require("../../utils/version-utils"); const assert_supported_rsbuild_version_1 = require("../../utils/assert-supported-rsbuild-version"); function updateDependencies(tree, schema) { const rsbuildVersions = (0, version_utils_1.getRsbuildVersionsForInstalledMajor)(tree); return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@nx/rsbuild': versions_1.nxVersion, '@rsbuild/core': rsbuildVersions.rsbuildVersion, }, undefined, schema.keepExistingVersions ?? true); } function initGenerator(tree, schema) { return initGeneratorInternal(tree, { addPlugin: false, ...schema }); } async function initGeneratorInternal(tree, schema) { (0, assert_supported_rsbuild_version_1.assertSupportedRsbuildVersion)(tree); const nxJson = (0, devkit_1.readNxJson)(tree); const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' && nxJson.useInferencePlugins !== false; schema.addPlugin ??= addPluginDefault; if (schema.addPlugin) { await (0, internal_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/rsbuild', plugin_1.createNodes, { buildTargetName: ['build', 'rsbuild:build', 'rsbuild-build'], devTargetName: ['dev', 'rsbuild:dev', 'rsbuild-dev'], previewTargetName: ['preview', 'rsbuild:preview', 'rsbuild-preview'], inspectTargetName: ['inspect', 'rsbuild:inspect', 'rsbuild-inspect'], typecheckTargetName: [ 'typecheck', 'rsbuild:typecheck', 'rsbuild-typecheck', ], buildDepsTargetName: [ 'build-deps', 'rsbuild:build-deps', 'rsbuild-build-deps', ], watchDepsTargetName: [ 'watch-deps', 'rsbuild:watch-deps', 'rsbuild-watch-deps', ], }, schema.updatePackageScripts); } const tasks = []; if (!schema.skipPackageJson) { tasks.push(updateDependencies(tree, schema)); } if (!schema.skipFormat) { await (0, devkit_1.formatFiles)(tree); } return (0, devkit_1.runTasksInSerial)(...tasks); } exports.default = initGenerator;