@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
53 lines (51 loc) • 2.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = runExecutor;
const devkit_1 = require("@nx/devkit");
const fs_1 = require("fs");
const path_1 = require("path");
const dotnet_1 = require("@nx-dotnet/dotnet");
const utils_1 = require("@nx-dotnet/utils");
async function runExecutor(options, context, dotnetClient = new dotnet_1.DotNetClient((0, dotnet_1.dotnetFactory)())) {
const nxProjectConfiguration = (0, utils_1.getExecutedProjectConfiguration)(context);
removeOldArtifacts(context, nxProjectConfiguration);
dotnetClient.cwd = (0, path_1.resolve)(devkit_1.workspaceRoot, nxProjectConfiguration.root);
dotnetClient.printSdkVersion();
const projectFilePath = (0, path_1.resolve)(devkit_1.workspaceRoot, await (0, utils_1.getProjectFileForNxProject)(nxProjectConfiguration));
const { extraParameters, ...flags } = options;
options.output = options.output
? (0, path_1.resolve)(devkit_1.workspaceRoot, options.output)
: undefined;
dotnetClient.build(projectFilePath, flags, extraParameters);
return {
success: true,
};
}
function removeOldArtifacts(context, projectConfiguration) {
const outputs = context.target?.outputs?.map((output) => (0, path_1.join)(context.root, (0, utils_1.inlineNxTokens)(output, projectConfiguration)));
if (!outputs &&
Object.values(context.nxJsonConfiguration?.tasksRunnerOptions ?? {}).some((runnerOptions) => runnerOptions.options?.cacheableOperations?.includes(context.targetName))) {
throw new Error(`[nx-dotnet] ${context.projectGraph}:${context.targetName} is cacheable, but has no outputs listed.
This will result in cache hits not retrieving build artifacts, only terminal outputs.
See: https://nx.dev/reference/project-configuration#outputs`);
}
for (const output of outputs || []) {
if (
// No reason to clear build intermediates, just makes the resulting build command slower.
!output.includes('intermediates') &&
!output.endsWith('obj') &&
// Prevent exceptions from trying to rmdirSync(globPattern)
getStatsOrNull(output)?.isDirectory()) {
(0, fs_1.rmSync)(output, { recursive: true });
}
}
}
function getStatsOrNull(f) {
try {
return (0, fs_1.statSync)(f);
}
catch {
return null;
}
}
//# sourceMappingURL=executor.js.map