Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/rstack/src/fmt/discoverPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface DiscoverFmtPathsOptions {
patterns?: string[];
/** Whether files inside node_modules may be discovered. */
withNodeModules?: boolean;
/** Returns whether a scanned path can be excluded during traversal. */
/** Returns whether a candidate path should be excluded. */
isIgnored?: (filePath: string, isDirectory: boolean) => boolean;
}

Expand Down Expand Up @@ -384,7 +384,9 @@ const discoverFmtPaths = async ({
} = await classifyPatterns(cwd, patterns, ignoredDirNames);
const directoryRoots = getOutermostPaths(directories);
const globMatchers = globs.map((pattern) => micromatch.matcher(pattern, { dot: true }));
const candidates = new Set(explicitFiles);
const candidates = new Set(
isIgnored ? explicitFiles.filter((filePath) => !isIgnored(filePath, false)) : explicitFiles,
);
const traversalRoots = getTraversalRoots(cwd, directoryRoots, globs);

if (traversalRoots.length) {
Expand Down
5 changes: 2 additions & 3 deletions packages/rstack/src/fmt/discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,16 @@ const discoverFmtFiles = async ({
? (filePath: string, isDirectory = false) =>
isExcluded(filePath) || isIgnored(filePath, isDirectory)
: isIgnored;
const candidates = await discoverFmtPaths({
const filePaths = await discoverFmtPaths({
cwd,
patterns,
withNodeModules,
isIgnored: shouldIgnore,
});
if (candidates.length === 0) {
if (filePaths.length === 0) {
return [];
}

const filePaths = candidates.filter((filePath) => !shouldIgnore(filePath));
const resolveOptions = createFmtOptionsResolver(config);
const files = filePaths.map((filePath) => createFileRequest(filePath, resolveOptions));
if (!files.some((file) => file.options.plugins?.length)) {
Expand Down
8 changes: 7 additions & 1 deletion packages/rstack/tests/fmt/discoverPaths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ test('lets explicit files bypass gitignore', async () => {
});
});

test('applies an external ignore matcher during traversal', async () => {
test('applies an external ignore matcher to traversed and explicit paths', async () => {
await withTempProject(async (rootPath) => {
writeProjectFile(rootPath, 'generated/nested/output.ts');
const ignoredFilePath = writeProjectFile(rootPath, 'src/ignored.ts');
Expand All @@ -160,9 +160,15 @@ test('applies an external ignore matcher during traversal', async () => {
patterns: ['generated'],
isIgnored,
});
const explicitIgnoredFile = await discoverFmtPaths({
cwd: rootPath,
patterns: [ignoredFilePath],
isIgnored,
});

expect(relativePaths(rootPath, files)).toEqual([path.join('src', 'index.ts')]);
expect(ignoredRoot).toEqual([]);
expect(explicitIgnoredFile).toEqual([]);
expect(checkedPaths).toContainEqual({ path: 'generated', isDirectory: true });
expect(checkedPaths).toContainEqual({
path: path.join('src', 'ignored.ts'),
Expand Down