Skip to content

Commit a881f6f

Browse files
committed
fix(nx-infra-plugin): resolve glob pattern failures on Windows
The glob library requires forward slashes as path separators across all platforms, but path.join() creates backslashes on Windows. Glob interprets backslashes as escape characters rather than path separators, causing pattern matching to fail and executors to process zero files on Windows. Created normalizeGlobPathForWindows() utility function and applied it to build-typescript and add-license-headers executors. Also changed empty file list from warning to error for fail-fast behavior.
1 parent 6a20995 commit a881f6f

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

packages/nx-infra-plugin/src/executors/add-license-headers/executor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { PromiseExecutor, logger } from '@nx/devkit';
22
import * as path from 'path';
33
import { glob } from 'glob';
44
import { AddLicenseHeadersExecutorSchema } from './schema';
5-
import { resolveProjectPath } from '../../utils/path-resolver';
5+
import { resolveProjectPath, normalizeGlobPathForWindows } from '../../utils/path-resolver';
66
import { logError } from '../../utils/error-handler';
77
import { readJson, readFileText, writeFileText } from '../../utils/file-operations';
88

@@ -80,7 +80,7 @@ const runExecutor: PromiseExecutor<AddLicenseHeadersExecutorSchema> = async (opt
8080
const banner = renderTemplate(bannerTemplate, data);
8181

8282
try {
83-
const pattern = path.join(targetDirectory, GLOB_PATTERN);
83+
const pattern = normalizeGlobPathForWindows(path.join(targetDirectory, GLOB_PATTERN));
8484
const files = await glob(pattern);
8585

8686
logger.info(`Adding license headers to ${files.length} files...`);

packages/nx-infra-plugin/src/executors/build-typescript/executor.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as path from 'path';
44
import { glob } from 'glob';
55
import { BuildTypescriptExecutorSchema } from './schema';
66
import { TsConfig, CompilerOptions } from '../../utils/types';
7-
import { resolveProjectPath } from '../../utils/path-resolver';
7+
import { resolveProjectPath, normalizeGlobPathForWindows } from '../../utils/path-resolver';
88
import { logError } from '../../utils/error-handler';
99
import { readFileText, exists, ensureDir } from '../../utils/file-operations';
1010

@@ -69,9 +69,9 @@ const runExecutor: PromiseExecutor<BuildTypescriptExecutorSchema> = async (optio
6969
await ensureDir(outDir);
7070

7171
const srcPattern = options.srcPattern || DEFAULT_SRC_PATTERN;
72-
const globPattern = path.join(absoluteProjectRoot, srcPattern);
72+
const globPattern = normalizeGlobPathForWindows(path.join(absoluteProjectRoot, srcPattern));
7373
const excludePattern = options.excludePattern
74-
? path.join(absoluteProjectRoot, options.excludePattern)
74+
? normalizeGlobPathForWindows(path.join(absoluteProjectRoot, options.excludePattern))
7575
: undefined;
7676

7777
const sourceFiles = await glob(globPattern, {
@@ -80,12 +80,12 @@ const runExecutor: PromiseExecutor<BuildTypescriptExecutorSchema> = async (optio
8080
ignore: excludePattern ? [excludePattern] : [],
8181
});
8282

83-
logger.info(`Building ${module.toUpperCase()} for ${sourceFiles.length} source files...`);
84-
8583
if (sourceFiles.length === 0) {
86-
logger.warn(`No source files matched pattern: ${srcPattern}`);
84+
throw new Error(`No source files matched pattern: ${srcPattern}`);
8785
}
8886

87+
logger.info(`Building ${module.toUpperCase()} for ${sourceFiles.length} source files...`);
88+
8989
const parsedConfig = ts.parseJsonConfigFileContent(
9090
tsconfigContent,
9191
ts.sys,

packages/nx-infra-plugin/src/utils/path-resolver.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ export function resolveFromProject(context: ExecutorContext, relativePath: strin
3030
export function resolveFromWorkspace(context: ExecutorContext, relativePath: string): string {
3131
return path.join(context.root, relativePath);
3232
}
33+
34+
export function normalizeGlobPathForWindows(filePath: string): string {
35+
return filePath.replace(/\\/g, '/');
36+
}

0 commit comments

Comments
 (0)