diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 8c3e30e5..ade4e590 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,9 +1,7 @@ name: Run PR checks -on: - # Triggers the workflow on push or pull request events but only for the master branch - pull_request: - branches: [master, dev] +on: pull_request + env: NX_BRANCH: ${{ github.event.number }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 01532d0d..93995249 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# [1.3.0](https://github.com/nx-dotnet/nx-dotnet/compare/v1.2.0...v1.3.0) (2021-08-23) + +### Bug Fixes + +- display project tag instead of [object Object] ([2dea7fc](https://github.com/nx-dotnet/nx-dotnet/commit/2dea7fcada490888dae1a3984ca00db1e7dc95d2)) +- **core:** use fully qualified project name in msbuild task ([2c54310](https://github.com/nx-dotnet/nx-dotnet/commit/2c543102d47f42638cbb20597c965cde85527b7f)) + +### Features + +- **core:** pickup `global.json` overrides at the project level ([49ce6bc](https://github.com/nx-dotnet/nx-dotnet/commit/49ce6bc5727a9c9789b701784363f582f0ee09ab)), closes [#87](https://github.com/nx-dotnet/nx-dotnet/issues/87) [#86](https://github.com/nx-dotnet/nx-dotnet/issues/86) + # [1.2.0](https://github.com/nx-dotnet/nx-dotnet/compare/v1.1.4...v1.2.0) (2021-08-20) ### Features diff --git a/docs/core/executors/test.md b/docs/core/executors/test.md index 43363311..6594cbb7 100644 --- a/docs/core/executors/test.md +++ b/docs/core/executors/test.md @@ -100,3 +100,7 @@ Runs test via the dotnet cli ### verbosity - (string): Sets the verbosity level of the command. For more information, see LoggerVerbosity. + +### watch + +- (boolean): Determines if `dotnet test` or `dotnet watch test` is used to execute tests. diff --git a/package.json b/package.json index c971bcb1..9ba0b419 100644 --- a/package.json +++ b/package.json @@ -112,5 +112,5 @@ "type": "git", "url": "https://github.com/nx-dotnet/nx-dotnet.git" }, - "version": "1.2.0" + "version": "1.3.0" } diff --git a/packages/core/package.json b/packages/core/package.json index 0493496d..7fd365f0 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -11,7 +11,7 @@ "email": "craigorycoppola+nxdotnet@gmail.com" }, "license": "MIT", - "version": "1.2.0", + "version": "1.3.0", "keywords": [ "Nx", ".NET", diff --git a/packages/core/src/executors/build/executor.ts b/packages/core/src/executors/build/executor.ts index eadc7554..04d77f5e 100644 --- a/packages/core/src/executors/build/executor.ts +++ b/packages/core/src/executors/build/executor.ts @@ -1,4 +1,5 @@ import { ExecutorContext } from '@nrwl/devkit'; +import { appRootPath } from '@nrwl/tao/src/utils/app-root'; import { dotnetBuildFlags, @@ -9,6 +10,7 @@ import { getExecutedProjectConfiguration, getProjectFileForNxProject, } from '@nx-dotnet/utils'; +import { resolve } from 'path'; import { BuildExecutorSchema } from './schema'; @@ -18,9 +20,15 @@ export default async function runExecutor( dotnetClient: DotNetClient = new DotNetClient(dotnetFactory()), ) { const nxProjectConfiguration = getExecutedProjectConfiguration(context); - const projectFilePath = await getProjectFileForNxProject( - nxProjectConfiguration, + dotnetClient.cwd = resolve(appRootPath, nxProjectConfiguration.root); + dotnetClient.printSdkVersion(); + const projectFilePath = resolve( + appRootPath, + await getProjectFileForNxProject(nxProjectConfiguration), ); + options.output = options.output + ? resolve(appRootPath, options.output) + : undefined; dotnetClient.build( projectFilePath, diff --git a/packages/core/src/executors/publish/executor.spec.ts b/packages/core/src/executors/publish/executor.spec.ts index 342fdb27..612a83c3 100644 --- a/packages/core/src/executors/publish/executor.spec.ts +++ b/packages/core/src/executors/publish/executor.spec.ts @@ -18,7 +18,7 @@ jest.mock('../../../../dotnet/src/lib/core/dotnet.client'); describe('Publish Executor', () => { let context: ExecutorContext; - let dotnetClient: DotNetClient; + let dotnetClient: jest.Mocked; beforeEach(() => { context = { @@ -42,7 +42,9 @@ describe('Publish Executor', () => { }, isVerbose: false, }; - dotnetClient = new DotNetClient(mockDotnetFactory()); + dotnetClient = new DotNetClient( + mockDotnetFactory(), + ) as jest.Mocked; }); afterEach(async () => { @@ -95,9 +97,21 @@ describe('Publish Executor', () => { } const res = await executor(options, context, dotnetClient); - expect( - (dotnetClient as jest.Mocked).publish, - ).toHaveBeenCalled(); + expect(dotnetClient.publish).toHaveBeenCalled(); + expect(res.success).toBeTruthy(); + }); + + it('should pass path relative to project root, not workspace root', async () => { + const directoryPath = `${root}/apps/my-app`; + try { + await fs.mkdir(directoryPath, { recursive: true }); + await Promise.all([fs.writeFile(`${directoryPath}/1.csproj`, '')]); + } catch (e) { + console.warn(e.message); + } + const res = await executor(options, context, dotnetClient); + expect(dotnetClient.publish).toHaveBeenCalled(); + expect(dotnetClient.cwd).toEqual(directoryPath); expect(res.success).toBeTruthy(); }); }); diff --git a/packages/core/src/executors/publish/executor.ts b/packages/core/src/executors/publish/executor.ts index 375db10c..22d42c27 100644 --- a/packages/core/src/executors/publish/executor.ts +++ b/packages/core/src/executors/publish/executor.ts @@ -1,4 +1,5 @@ import { ExecutorContext } from '@nrwl/devkit'; +import { appRootPath } from '@nrwl/tao/src/utils/app-root'; import { DotNetClient, @@ -9,6 +10,7 @@ import { getExecutedProjectConfiguration, getProjectFileForNxProject, } from '@nx-dotnet/utils'; +import { resolve } from 'path'; import { PublishExecutorSchema } from './schema'; @@ -18,14 +20,17 @@ export default async function runExecutor( dotnetClient: DotNetClient = new DotNetClient(dotnetFactory()), ) { const nxProjectConfiguration = getExecutedProjectConfiguration(context); + const cwd = resolve(appRootPath, nxProjectConfiguration.root); + dotnetClient.cwd = cwd; const projectFilePath = await getProjectFileForNxProject( nxProjectConfiguration, ); const { publishProfile, extraParameters, ...flags } = options; + flags.output = flags.output ? resolve(appRootPath, flags.output) : undefined; dotnetClient.publish( - projectFilePath, + resolve(appRootPath, projectFilePath), Object.keys(flags).map((x) => ({ flag: x as dotnetPublishFlags, value: (options as Record)[x], diff --git a/packages/core/src/executors/publish/schema.d.ts b/packages/core/src/executors/publish/schema.d.ts index 58a3df84..9ba230e3 100644 --- a/packages/core/src/executors/publish/schema.d.ts +++ b/packages/core/src/executors/publish/schema.d.ts @@ -3,6 +3,7 @@ import { dotnetPublishFlags } from '@nx-dotnet/dotnet'; export type PublishExecutorSchema = { [key in dotnetPublishFlags]?: string | boolean; } & { + output?: string; publishProfile?: string; extraParameters?: string; }; diff --git a/packages/core/src/executors/serve/executor.ts b/packages/core/src/executors/serve/executor.ts index 13e0f4a3..79df95a5 100644 --- a/packages/core/src/executors/serve/executor.ts +++ b/packages/core/src/executors/serve/executor.ts @@ -1,7 +1,8 @@ import { ExecutorContext } from '@nrwl/devkit'; +import { appRootPath } from '@nrwl/tao/src/utils/app-root'; import { ChildProcess } from 'child_process'; -import * as chockidar from 'chokidar'; +import { resolve as pathResolve } from 'path'; import { DotNetClient, @@ -10,17 +11,15 @@ import { dotnetRunOptions, } from '@nx-dotnet/dotnet'; import { - getDependantProjectsForNxProject, getExecutedProjectConfiguration, getProjectFileForNxProject, + handleChildProcessPassthrough, rimraf, } from '@nx-dotnet/utils'; import { ServeExecutorSchema } from './schema'; -let resolver: (returnObject: { success: boolean }) => void; let childProcess: ChildProcess; -let timeout: NodeJS.Timeout; let projectDirectory: string; export default function dotnetRunExecutor( @@ -29,90 +28,28 @@ export default function dotnetRunExecutor( dotnetClient: DotNetClient = new DotNetClient(dotnetFactory()), ): Promise<{ success: boolean }> { const nxProjectConfiguration = getExecutedProjectConfiguration(context); + const cwd = pathResolve(appRootPath, nxProjectConfiguration.root); + dotnetClient.cwd = cwd; - return getProjectFileForNxProject(nxProjectConfiguration).then((project) => { - projectDirectory = nxProjectConfiguration.root; - - return new Promise((resolve) => { - resolver = resolve; - - const watcher = chockidar.watch(nxProjectConfiguration.root); - - getDependantProjectsForNxProject( - context.projectName as string, - context.workspace, - (dependency) => { - watcher.add(dependency.root); - }, - ); - - watcher.on('all', (event, path) => { - if (path.includes('bin') || path.includes('obj')) { - return; - } - - if (timeout) { - clearTimeout(timeout); - } - - timeout = setTimeout(() => { - setupDotnetRun(dotnetClient, project, options); - }, 1000); - - console.log(event, path); - }); - }); - }); + return getProjectFileForNxProject(nxProjectConfiguration).then((project) => + runDotnetRun(dotnetClient, pathResolve(appRootPath, project), options), + ); } -const setupDotnetRun = ( +const runDotnetRun = ( dotnetClient: DotNetClient, project: string, options: ServeExecutorSchema, ) => { - if (childProcess) { - childProcess.kill('SIGTERM'); - } - const opts: dotnetRunOptions = Object.keys(options).map((x) => ({ flag: x as dotnetRunFlags, value: (options as Record)[x], })); - childProcess = dotnetClient.run(project, opts); - - childProcess.on('error', (err) => { - console.error(err); + childProcess = dotnetClient.run(project, true, opts); + return handleChildProcessPassthrough(childProcess).then(async () => { + await rimraf(projectDirectory + '/bin'); + await rimraf(projectDirectory + '/obj'); + return { success: true }; }); }; - -const exitHandler = async (options: { exit: boolean }, exitCode = 0) => { - console.log('Exit Handler Called'); - - await rimraf(projectDirectory + '/bin'); - await rimraf(projectDirectory + '/obj'); - - if (exitCode || exitCode === 0) console.log(exitCode); - - if (childProcess) { - childProcess.kill('SIGINT'); - } - resolver({ - success: true, - }); - - if (options.exit) process.exit(); -}; - -//do something when app is closing -process.on('exit', () => exitHandler({ exit: false })); - -//catches ctrl+c event -process.on('SIGINT', () => exitHandler({ exit: true })); - -// catches "kill pid" (for example: nodemon restart) -process.on('SIGUSR1', () => exitHandler({ exit: true })); -process.on('SIGUSR2', () => exitHandler({ exit: true })); - -//catches uncaught exceptions -process.on('uncaughtException', () => exitHandler({ exit: true })); diff --git a/packages/core/src/executors/test/executor.ts b/packages/core/src/executors/test/executor.ts index 19cad089..bff4c8cf 100644 --- a/packages/core/src/executors/test/executor.ts +++ b/packages/core/src/executors/test/executor.ts @@ -1,4 +1,7 @@ import { ExecutorContext } from '@nrwl/devkit'; +import { appRootPath } from '@nrwl/tao/src/utils/app-root'; + +import { resolve } from 'path'; import { DotNetClient, @@ -8,28 +11,42 @@ import { import { getExecutedProjectConfiguration, getProjectFileForNxProject, + handleChildProcessPassthrough, + isChildProcess, + rimraf, } from '@nx-dotnet/utils'; import { TestExecutorSchema } from './schema'; +let projectDirectory: string; + export default async function runExecutor( options: TestExecutorSchema, context: ExecutorContext, dotnetClient: DotNetClient = new DotNetClient(dotnetFactory()), -) { +): Promise<{ success: boolean }> { const nxProjectConfiguration = getExecutedProjectConfiguration(context); + projectDirectory = resolve(appRootPath, nxProjectConfiguration.root); const projectFilePath = await getProjectFileForNxProject( nxProjectConfiguration, ); + dotnetClient.cwd = projectDirectory; + const { watch, ...parsedOptions } = options; - dotnetClient.test( - projectFilePath, + const result = dotnetClient.test( + resolve(appRootPath, projectFilePath), + watch, Object.keys(options).map((x) => ({ flag: x as dotnetTestFlags, - value: (options as Record)[x], + value: (parsedOptions as Record)[x], })), ); + if (watch && isChildProcess(result)) { + await handleChildProcessPassthrough(result); + await rimraf(projectDirectory + '/bin'); + await rimraf(projectDirectory + '/obj'); + } return { success: true, }; diff --git a/packages/core/src/executors/test/schema.d.ts b/packages/core/src/executors/test/schema.d.ts index 4ddbc118..c45d7ec3 100644 --- a/packages/core/src/executors/test/schema.d.ts +++ b/packages/core/src/executors/test/schema.d.ts @@ -31,4 +31,5 @@ export interface TestExecutorSchema { | 'detailed' | 'diag' | 'diagnostic'; + watch?: boolean; } diff --git a/packages/core/src/executors/test/schema.json b/packages/core/src/executors/test/schema.json index 35088012..009ac39b 100644 --- a/packages/core/src/executors/test/schema.json +++ b/packages/core/src/executors/test/schema.json @@ -108,6 +108,11 @@ "diag", "diagnostic" ] + }, + "watch": { + "description": "Determines if `dotnet test` or `dotnet watch test` is used to execute tests.", + "type": "boolean", + "default": false } }, "required": [] diff --git a/packages/core/src/generators/utils/generate-project.ts b/packages/core/src/generators/utils/generate-project.ts index bc6b0951..50421b1b 100644 --- a/packages/core/src/generators/utils/generate-project.ts +++ b/packages/core/src/generators/utils/generate-project.ts @@ -195,7 +195,7 @@ export function setOutputPath( export function addPrebuildMsbuildTask( host: Tree, - options: { projectRoot: string; name: string }, + options: { projectRoot: string; projectName: string }, xml: XmlDocument, ) { const scriptPath = normalizePath( @@ -207,7 +207,7 @@ export function addPrebuildMsbuildTask( const fragment = new XmlDocument(` - + `); diff --git a/packages/core/src/migrations/1.2.0/add-module-boundaries-check/migrate.ts b/packages/core/src/migrations/1.2.0/add-module-boundaries-check/migrate.ts index c5174b46..326a4196 100644 --- a/packages/core/src/migrations/1.2.0/add-module-boundaries-check/migrate.ts +++ b/packages/core/src/migrations/1.2.0/add-module-boundaries-check/migrate.ts @@ -23,7 +23,11 @@ export default async function update(host: Tree) { .childrenNamed('Target') .some((x) => x.attr['Name'] === 'CheckNxModuleBoundaries') ) { - addPrebuildMsbuildTask(host, { name, projectRoot: project.root }, xml); + addPrebuildMsbuildTask( + host, + { projectName: name, projectRoot: project.root }, + xml, + ); host.write(projectFilePath, xml.toString()); } } diff --git a/packages/core/src/tasks/check-module-boundaries.ts b/packages/core/src/tasks/check-module-boundaries.ts index f0ed3a78..55a321ae 100644 --- a/packages/core/src/tasks/check-module-boundaries.ts +++ b/packages/core/src/tasks/check-module-boundaries.ts @@ -55,7 +55,9 @@ export async function checkModuleBoundariesForProject( ) ) { violations.push( - `${project} cannot depend on ${name}. Project tag ${constraint} is not satisfied.`, + `${project} cannot depend on ${name}. Project tag ${JSON.stringify( + constraint, + )} is not satisfied.`, ); } } @@ -75,9 +77,13 @@ export async function loadModuleBoundaries( ): Promise { const configured = readConfig(host).moduleBoundaries; if (!configured) { - const result = await new ESLint().calculateConfigForFile( - `${root}/non-existant.ts`, - ); + const result = await new ESLint() + .calculateConfigForFile(`${root}/non-existant.ts`) + .catch(() => + Promise.resolve({ + rules: { '@nrwl/nx/enforce-module-boundaries': [] }, + }), + ); const [, moduleBoundaryConfig] = result.rules['@nrwl/nx/enforce-module-boundaries']; return moduleBoundaryConfig?.depConstraints ?? []; diff --git a/packages/dotnet/package.json b/packages/dotnet/package.json index 1317f368..cef820d1 100644 --- a/packages/dotnet/package.json +++ b/packages/dotnet/package.json @@ -4,7 +4,7 @@ "main": "src/index.js", "dependencies": {}, "license": "MIT", - "version": "1.2.0", + "version": "1.3.0", "keywords": [ ".NET", "dotnet" diff --git a/packages/dotnet/src/lib/core/dotnet.client.ts b/packages/dotnet/src/lib/core/dotnet.client.ts index 9bfb829b..b7eb96fe 100644 --- a/packages/dotnet/src/lib/core/dotnet.client.ts +++ b/packages/dotnet/src/lib/core/dotnet.client.ts @@ -19,12 +19,13 @@ import { formatKeyMap, newKeyMap, publishKeyMap, + runKeyMap, testKeyMap, } from '../models'; import { LoadedCLI } from './dotnet.factory'; export class DotNetClient { - constructor(private cliCommand: LoadedCLI) {} + constructor(private cliCommand: LoadedCLI, public cwd?: string) {} new(template: dotnetTemplate, parameters?: dotnetNewOptions): Buffer { let cmd = `${this.cliCommand.command} new ${template}`; @@ -46,26 +47,56 @@ export class DotNetClient { return this.logAndExecute(cmd); } - run(project: string, parameters?: dotnetRunOptions): ChildProcess { - let cmd = `run --project ${project} `; + run( + project: string, + watch = false, + parameters?: dotnetRunOptions, + ): ChildProcess { + let cmd = watch + ? `watch --project ${project} run` + : `run -- project ${project}`; if (parameters) { - parameters = swapArrayFieldValueUsingMap(parameters, 'flag', testKeyMap); + parameters = swapArrayFieldValueUsingMap(parameters, 'flag', runKeyMap); const paramString = parameters ? getParameterString(parameters) : ''; cmd = `${cmd} ${paramString}`; } - console.log(`Executing Command: ${cmd}`); - return spawn(this.cliCommand.command, cmd.split(' '), { stdio: 'inherit' }); + console.log(`Executing Command: dotnet ${cmd}`); + return spawn(this.cliCommand.command, cmd.split(' '), { + stdio: 'inherit', + cwd: this.cwd, + }); } - test(project: string, parameters?: dotnetTestOptions): Buffer { - let cmd = `${this.cliCommand.command} test ${project}`; + test( + project: string, + watch?: boolean, + parameters?: dotnetTestOptions, + ): Buffer | ChildProcess { + let cmd = watch ? ` watch --project ${project} test` : `test ${project}`; + cmd = `${this.cliCommand.command} ${cmd}`; + if (parameters) { - parameters = swapArrayFieldValueUsingMap(parameters, 'flag', testKeyMap); - const paramString = parameters ? getParameterString(parameters) : ''; + const mappedParameters = swapArrayFieldValueUsingMap( + parameters, + 'flag', + testKeyMap, + ); + const paramString = getParameterString(mappedParameters); cmd = `${cmd} ${paramString}`; } - console.log(`Executing Command: ${cmd}`); - return this.logAndExecute(cmd); + if (!watch) { + return this.logAndExecute(cmd); + } else { + console.log(`Executing Command: ${cmd}`); + const params = cmd + .split(' ') + .slice(1) + .filter((x) => x.length); + return spawn(this.cliCommand.command, params, { + stdio: 'inherit', + cwd: this.cwd, + }); + } } addPackageReference( @@ -146,8 +177,12 @@ export class DotNetClient { return this.logAndExecute(cmd); } + printSdkVersion(): Buffer { + return this.logAndExecute('dotnet --version'); + } + private logAndExecute(cmd: string): Buffer { console.log(`Executing Command: ${cmd}`); - return execSync(cmd, { stdio: 'inherit' }); + return execSync(cmd, { stdio: 'inherit', cwd: this.cwd || process.cwd() }); } } diff --git a/packages/nx-ghpages/package.json b/packages/nx-ghpages/package.json index d0293710..0b5d1b46 100644 --- a/packages/nx-ghpages/package.json +++ b/packages/nx-ghpages/package.json @@ -1,6 +1,6 @@ { "name": "@nx-dotnet/nx-ghpages", - "version": "1.2.0", + "version": "1.3.0", "main": "src/index.js", "generators": "./generators.json", "executors": "./executors.json", diff --git a/packages/nxdoc/package.json b/packages/nxdoc/package.json index c1158969..f939031b 100644 --- a/packages/nxdoc/package.json +++ b/packages/nxdoc/package.json @@ -1,6 +1,6 @@ { "name": "@nx-dotnet/nxdoc", - "version": "1.2.0", + "version": "1.3.0", "main": "src/index.js", "generators": "./generators.json", "executors": "./executors.json", diff --git a/packages/typescript/package.json b/packages/typescript/package.json index 98b42626..ed875dcb 100644 --- a/packages/typescript/package.json +++ b/packages/typescript/package.json @@ -4,7 +4,7 @@ "generators": "./generators.json", "executors": "./executors.json", "license": "MIT", - "version": "1.2.0", + "version": "1.3.0", "keywords": [ "Nx", ".NET", diff --git a/packages/utils/package.json b/packages/utils/package.json index 6c61ca06..04f8c54b 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -4,7 +4,7 @@ "private": false, "dependencies": {}, "license": "MIT", - "version": "1.2.0", + "version": "1.3.0", "bugs": { "url": "https://github.com/nx-dotnet/nx-dotnet/issues?q=is%3Aopen", "email": "craigorycoppola+nxdotnet@gmail.com" diff --git a/packages/utils/src/lib/utility-functions/childprocess.ts b/packages/utils/src/lib/utility-functions/childprocess.ts new file mode 100644 index 00000000..e3a40b7d --- /dev/null +++ b/packages/utils/src/lib/utility-functions/childprocess.ts @@ -0,0 +1,46 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import * as cp from 'child_process'; +import { ChildProcess } from 'child_process'; + +/** + * TypeScript typings think ChildProcess is an interface, its a class. + */ +export function isChildProcess(obj: any): obj is cp.ChildProcess { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + return obj instanceof cp.ChildProcess; +} + +export async function handleChildProcessPassthrough( + childProcess: ChildProcess, +) { + let resolver: () => void; + + const exitHandler = async () => { + console.log('Exit Handler Called'); + + if (childProcess) { + childProcess.kill('SIGINT'); + childProcess.kill('SIGINT'); + } + process.removeListener('exit', exitHandler); + process.removeListener('SIGINT', exitHandler); + process.removeListener('SIGUSR1', exitHandler); + process.removeListener('SIGUSR2', exitHandler); + process.removeListener('uncaughtException', exitHandler); + resolver(); + }; + + //do something when app is closing + process.on('exit', exitHandler); + + //catches ctrl+c event + process.on('SIGINT', exitHandler); + + // catches "kill pid" (for example: nodemon restart) + process.on('SIGUSR1', exitHandler); + process.on('SIGUSR2', exitHandler); + + //catches uncaught exceptions + process.on('uncaughtException', exitHandler); +} diff --git a/packages/utils/src/lib/utility-functions/index.ts b/packages/utils/src/lib/utility-functions/index.ts index 0cd5fb02..6e40d39d 100644 --- a/packages/utils/src/lib/utility-functions/index.ts +++ b/packages/utils/src/lib/utility-functions/index.ts @@ -6,3 +6,5 @@ export * from './rimraf'; export * from './workspace'; export * from './config'; export * from './xml'; +export * from './is-buffer'; +export * from './childprocess'; diff --git a/packages/utils/src/lib/utility-functions/is-buffer.ts b/packages/utils/src/lib/utility-functions/is-buffer.ts new file mode 100644 index 00000000..330ca6b9 --- /dev/null +++ b/packages/utils/src/lib/utility-functions/is-buffer.ts @@ -0,0 +1,16 @@ +/*! + * Determine if an object is a Buffer + * + * @author Feross Aboukhadijeh + * @license MIT + */ + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function isBuffer(obj: any): obj is Buffer { + return ( + obj != null && + obj.constructor != null && + typeof obj.constructor.isBuffer === 'function' && + obj.constructor.isBuffer(obj) + ); +} diff --git a/packages/utils/src/lib/utility-functions/workspace.ts b/packages/utils/src/lib/utility-functions/workspace.ts index 57c18224..d62bdf40 100644 --- a/packages/utils/src/lib/utility-functions/workspace.ts +++ b/packages/utils/src/lib/utility-functions/workspace.ts @@ -5,9 +5,10 @@ import { Tree, WorkspaceJsonConfiguration, } from '@nrwl/devkit'; +import { appRootPath } from '@nrwl/tao/src/utils/app-root'; import { readFileSync } from 'fs'; -import { dirname, isAbsolute, resolve } from 'path'; +import { dirname, isAbsolute, relative, resolve } from 'path'; import { XmlDocument, XmlElement } from 'xmldoc'; import { NXDOTNET_TAG } from '../constants'; @@ -43,8 +44,14 @@ export function getDependantProjectsForNxProject( projectRoots[name] = resolve(project.root); }); - const netProjectFilePath = getProjectFileForNxProjectSync( - workspaceConfiguration.projects[targetProject], + const netProjectFilePath = relative( + process.cwd(), + resolve( + appRootPath, + getProjectFileForNxProjectSync( + workspaceConfiguration.projects[targetProject], + ), + ), ); const hostProjectDirectory = dirname(netProjectFilePath).replace(/\\/g, '/');