@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
52 lines • 2.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = removeOutputOption;
/* eslint-disable @typescript-eslint/no-unused-vars */
const devkit_1 = require("@nx/devkit");
const path_1 = require("path");
const xmldoc_1 = require("xmldoc");
const utils_1 = require("@nx-dotnet/utils");
async function removeOutputOption(host) {
const projects = await (0, utils_1.getNxDotnetProjects)(host);
for (const [name, projectConfiguration] of projects.entries()) {
const projectFile = await (0, utils_1.getProjectFileForNxProject)(projectConfiguration);
if (projectFile) {
const xml = new xmldoc_1.XmlDocument(host.read(projectFile, 'utf-8'));
const outputPath = xml
.childNamed('PropertyGroup')
?.childNamed('OutputPath');
if (!outputPath) {
devkit_1.logger.warn(`Skipping ${name} because it does not have OutputPath set in ${(0, path_1.basename)(projectFile)}`);
continue;
}
let xmlOutputPath = outputPath.val;
xmlOutputPath = (0, devkit_1.normalizePath)((0, path_1.resolve)(host.root, projectConfiguration.root, xmlOutputPath));
const buildTargets = findBuildTargets(projectConfiguration.targets || {});
buildTargets.forEach((buildTarget) => {
const shouldUpdate = updateBuildTargetOptions(host, name, buildTarget, xmlOutputPath);
if (shouldUpdate)
(0, devkit_1.updateProjectConfiguration)(host, name, projectConfiguration);
});
}
}
}
function updateBuildTargetOptions(host, projectName, configuration, xmlOutputPath) {
const outputPath = (0, devkit_1.normalizePath)((0, path_1.resolve)(host.root, configuration.options.output));
if (outputPath !== xmlOutputPath) {
devkit_1.logger.info(`Skipping ${projectName} since .csproj OutputPath is set differently from --output parameter`);
devkit_1.logger.info(`- .csproj OutputPath: ${xmlOutputPath}`);
devkit_1.logger.info(`- project.json output: ${outputPath}`);
return false;
}
const output = configuration.options.output;
const outputs = configuration.outputs || [];
delete configuration.options.output;
configuration.options['noIncremental'] = true;
configuration.outputs = outputs.filter((x) => x !== '{options.output}');
configuration.outputs.push(output);
return true;
}
function findBuildTargets(targets) {
return Object.values(targets).filter((configuration) => configuration.executor === '@nx-dotnet/core:build');
}
//# sourceMappingURL=remove-output-option.js.map