@nx-dotnet/core
Version:
- Have an existing nx workspace. For creating this, see [nrwl's documentation](https://nx.dev/latest/angular/getting-started/nx-setup). - .NET SDK is installed, and `dotnet` is available on the path. For help on this, see [Microsoft's documentation](https
72 lines • 2.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.moveConfigToNxJson = moveConfigToNxJson;
const devkit_1 = require("@nx/devkit");
const utils_1 = require("@nx-dotnet/utils");
const node_assert_1 = require("node:assert");
const semver_1 = require("semver");
async function moveConfigToNxJson(tree) {
if ((0, semver_1.major)(devkit_1.NX_VERSION) < 17) {
warnLowVersion();
return;
}
const configFileConfig = (0, utils_1.readConfigFromRCFile)(tree);
if (!configFileConfig) {
return;
}
const nxJson = (0, devkit_1.readNxJson)(tree);
const pluginIndex = nxJson?.plugins?.findIndex((p) => typeof p === 'string'
? p === '@nx-dotnet/core'
: p.plugin === '@nx-dotnet/core');
if (!nxJson?.plugins || pluginIndex === undefined || pluginIndex < 0) {
return;
}
const plugin = nxJson.plugins[pluginIndex];
if (typeof plugin !== 'string') {
handleAlreadyMigratedConfig(plugin, configFileConfig, tree);
return;
}
nxJson.plugins[pluginIndex] = {
plugin,
options: configFileConfig,
};
tree.delete(utils_1.CONFIG_FILE_PATH);
(0, devkit_1.updateNxJson)(tree, nxJson);
await (0, devkit_1.formatFiles)(tree);
}
exports.default = moveConfigToNxJson;
function handleAlreadyMigratedConfig(plugin, configFileConfig, tree) {
const { options } = plugin;
if (deepEqual(options, configFileConfig)) {
tree.delete(utils_1.CONFIG_FILE_PATH);
}
else {
devkit_1.output.warn({
title: 'Partially migrated config detected.',
bodyLines: [
'In Nx 17 and higher, the nx-dotnet config should be stored in nx.json.',
],
});
}
}
function warnLowVersion() {
const command = process.argv[2];
if (command === 'generate' || command === 'g') {
devkit_1.output.warn({
title: 'Nx 17 and higher is required.',
bodyLines: [
'In Nx 17 and higher, the nx-dotnet config should be stored in nx.json. Prior to Nx 17, the config was stored in .nx-dotnetrc.json. If you wish to configure nx-dotnet within nx.json, migrate to Nx 17 first.',
],
});
}
}
function deepEqual(a, b) {
try {
(0, node_assert_1.deepStrictEqual)(a, b);
return true;
}
catch {
return false;
}
}
//# sourceMappingURL=generator.js.map