Skip to content

Commit 9720168

Browse files
authored
fix(core): use strict proj glob pattern (#495)
1 parent 7b2f9d6 commit 9720168

File tree

9 files changed

+70
-15
lines changed

9 files changed

+70
-15
lines changed

packages/core/src/generators/import-projects/generator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { basename, dirname } from 'path';
1414
import { XmlDocument } from 'xmldoc';
1515

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

1818
import {
1919
GetBuildExecutorConfiguration,
@@ -80,11 +80,11 @@ async function addNewDotnetProject(
8080
async function getProjectFilesInWorkspace(host: Tree) {
8181
const { appsDir, libsDir } = getWorkspaceLayout(host);
8282
const newProjects = {
83-
newLibs: await glob(`${libsDir}/**/*.@(cs|fs|vb)proj`),
83+
newLibs: await glob(projPattern(libsDir)),
8484
newApps: [] as string[],
8585
};
8686
if (libsDir !== appsDir) {
87-
newProjects.newApps = await glob(`${appsDir}/**/*.@(cs|fs|vb)proj`);
87+
newProjects.newApps = await glob(projPattern(appsDir));
8888
}
8989
return newProjects;
9090
}

packages/utils/fixtures/cs/file.csproj

Whitespace-only changes.

packages/utils/fixtures/fs/file.fsproj

Whitespace-only changes.

packages/utils/fixtures/other/file.otherproj

Whitespace-only changes.

packages/utils/fixtures/vb/file.vbproj

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { isDryRun } from './args';
2+
3+
describe('Args util functions', () => {
4+
describe('isDryRun', () => {
5+
it('Should detect dry run flag', () => {
6+
const before = isDryRun();
7+
process.argv.push('--dry-run');
8+
const after = isDryRun();
9+
expect({ before, after }).toStrictEqual({ before: false, after: true });
10+
});
11+
});
12+
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { findProjectFileInPath, findProjectFileInPathSync } from './glob';
2+
3+
const dotnetProjectFiles = [
4+
'packages/utils/fixtures/cs/file.csproj',
5+
'packages/utils/fixtures/fs/file.fsproj',
6+
'packages/utils/fixtures/vb/file.vbproj',
7+
];
8+
9+
describe('Glob util functions', () => {
10+
describe('findProjectFileInPath', () => {
11+
it('should find .net project file', async () => {
12+
const result = await Promise.all([
13+
findProjectFileInPath('packages/utils/fixtures/cs'),
14+
findProjectFileInPath('packages/utils/fixtures/fs'),
15+
findProjectFileInPath('packages/utils/fixtures/vb'),
16+
]);
17+
18+
expect(result).toEqual(dotnetProjectFiles);
19+
});
20+
21+
it('should ignore non .net project files', async () => {
22+
await expect(
23+
findProjectFileInPath('packages/utils/fixtures/other'),
24+
).rejects.toThrow(
25+
`Unable to find a build-able project within project's source directory!`,
26+
);
27+
});
28+
});
29+
30+
describe('findProjectFileInPathSync', () => {
31+
it('should find .net project file synchronously', () => {
32+
const result = [
33+
findProjectFileInPathSync('packages/utils/fixtures/cs'),
34+
findProjectFileInPathSync('packages/utils/fixtures/fs'),
35+
findProjectFileInPathSync('packages/utils/fixtures/vb'),
36+
];
37+
38+
expect(result).toEqual(dotnetProjectFiles);
39+
});
40+
41+
it('should ignore non .net project files', () => {
42+
expect(() =>
43+
findProjectFileInPathSync('packages/utils/fixtures/other'),
44+
).toThrow(
45+
`Unable to find a build-able project within project's source directory!`,
46+
);
47+
});
48+
});
49+
});

packages/utils/src/lib/utility-functions/glob.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const globOptions = {
88
ignore: ['**/bin/**', '**/obj/**'],
99
};
1010

11+
export function projPattern(path: string): string {
12+
return `${path}/**/*.@(cs|fs|vb)proj`;
13+
}
14+
1115
/**
1216
* Wraps the fast-glob package.
1317
* @returns array of file paths
@@ -20,7 +24,7 @@ export function glob(path: string, cwd?: string): Promise<string[]> {
2024
}
2125

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

4145
export function findProjectFileInPathSync(path: string): string {
42-
const results = fg.sync(`${path}/**/*.*proj`, globOptions);
46+
const results = fg.sync(projPattern(path), globOptions);
4347
if (!results || results.length === 0) {
4448
throw new Error(
4549
"Unable to find a build-able project within project's source directory!",

packages/utils/src/lib/utility-functions/utils.spec.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)