Skip to content

Commit

Permalink
fix(core): use strict proj glob pattern (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhanovr authored Aug 19, 2022
1 parent 7b2f9d6 commit 9720168
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 15 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/generators/import-projects/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { basename, dirname } from 'path';
import { XmlDocument } from 'xmldoc';

import { glob, iterateChildrenByPath } from '@nx-dotnet/utils';
import { glob, iterateChildrenByPath, projPattern } from '@nx-dotnet/utils';

import {
GetBuildExecutorConfiguration,
Expand Down Expand Up @@ -80,11 +80,11 @@ async function addNewDotnetProject(
async function getProjectFilesInWorkspace(host: Tree) {
const { appsDir, libsDir } = getWorkspaceLayout(host);
const newProjects = {
newLibs: await glob(`${libsDir}/**/*.@(cs|fs|vb)proj`),
newLibs: await glob(projPattern(libsDir)),
newApps: [] as string[],
};
if (libsDir !== appsDir) {
newProjects.newApps = await glob(`${appsDir}/**/*.@(cs|fs|vb)proj`);
newProjects.newApps = await glob(projPattern(appsDir));
}
return newProjects;
}
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
12 changes: 12 additions & 0 deletions packages/utils/src/lib/utility-functions/args.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { isDryRun } from './args';

describe('Args util functions', () => {
describe('isDryRun', () => {
it('Should detect dry run flag', () => {
const before = isDryRun();
process.argv.push('--dry-run');
const after = isDryRun();
expect({ before, after }).toStrictEqual({ before: false, after: true });
});
});
});
49 changes: 49 additions & 0 deletions packages/utils/src/lib/utility-functions/glob.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { findProjectFileInPath, findProjectFileInPathSync } from './glob';

const dotnetProjectFiles = [
'packages/utils/fixtures/cs/file.csproj',
'packages/utils/fixtures/fs/file.fsproj',
'packages/utils/fixtures/vb/file.vbproj',
];

describe('Glob util functions', () => {
describe('findProjectFileInPath', () => {
it('should find .net project file', async () => {
const result = await Promise.all([
findProjectFileInPath('packages/utils/fixtures/cs'),
findProjectFileInPath('packages/utils/fixtures/fs'),
findProjectFileInPath('packages/utils/fixtures/vb'),
]);

expect(result).toEqual(dotnetProjectFiles);
});

it('should ignore non .net project files', async () => {
await expect(
findProjectFileInPath('packages/utils/fixtures/other'),
).rejects.toThrow(
`Unable to find a build-able project within project's source directory!`,
);
});
});

describe('findProjectFileInPathSync', () => {
it('should find .net project file synchronously', () => {
const result = [
findProjectFileInPathSync('packages/utils/fixtures/cs'),
findProjectFileInPathSync('packages/utils/fixtures/fs'),
findProjectFileInPathSync('packages/utils/fixtures/vb'),
];

expect(result).toEqual(dotnetProjectFiles);
});

it('should ignore non .net project files', () => {
expect(() =>
findProjectFileInPathSync('packages/utils/fixtures/other'),
).toThrow(
`Unable to find a build-able project within project's source directory!`,
);
});
});
});
8 changes: 6 additions & 2 deletions packages/utils/src/lib/utility-functions/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const globOptions = {
ignore: ['**/bin/**', '**/obj/**'],
};

export function projPattern(path: string): string {
return `${path}/**/*.@(cs|fs|vb)proj`;
}

/**
* Wraps the fast-glob package.
* @returns array of file paths
Expand All @@ -20,7 +24,7 @@ export function glob(path: string, cwd?: string): Promise<string[]> {
}

export function findProjectFileInPath(path: string): Promise<string> {
return glob(`${path}/**/*.*proj`).then((results) => {
return glob(projPattern(path)).then((results) => {
if (!results || results.length === 0) {
throw new Error(
"Unable to find a build-able project within project's source directory!",
Expand All @@ -39,7 +43,7 @@ export function findProjectFileInPath(path: string): Promise<string> {
}

export function findProjectFileInPathSync(path: string): string {
const results = fg.sync(`${path}/**/*.*proj`, globOptions);
const results = fg.sync(projPattern(path), globOptions);
if (!results || results.length === 0) {
throw new Error(
"Unable to find a build-able project within project's source directory!",
Expand Down
10 changes: 0 additions & 10 deletions packages/utils/src/lib/utility-functions/utils.spec.ts

This file was deleted.

0 comments on commit 9720168

Please sign in to comment.