Skip to content

Commit

Permalink
Fix #2121
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Dec 11, 2022
1 parent ff5cb55 commit c86c52e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Unreleased

### Bug Fixes

- If `src/` and `src/x` are specified as entry points, `src/` will no longer be ignored, #2121.

## v0.23.22 (2022-12-11)

### Features
Expand Down
9 changes: 5 additions & 4 deletions src/lib/utils/fs.ts
Expand Up @@ -148,13 +148,14 @@ export function glob(
do {
const dir = dirs.shift()!;

if (options?.includeDirectories && mini.match(dir.join("/"))) {
result.push(dir.join("/"));
}

for (const child of fs.readdirSync(dir.join("/"), {
withFileTypes: true,
})) {
if (
child.isFile() ||
(options?.includeDirectories && child.isDirectory())
) {
if (child.isFile()) {
const childPath = [...dir, child.name].join("/");
if (mini.match(childPath)) {
result.push(childPath);
Expand Down
41 changes: 41 additions & 0 deletions src/test/utils/fs.test.ts
@@ -0,0 +1,41 @@
import { Project, tempdirProject } from "@typestrong/fs-fixture-builder";
import { deepStrictEqual as equal } from "assert";
import { basename } from "path";
import { glob } from "../../lib/utils/fs";

describe("fs.ts", () => {
let fix: Project;
beforeEach(() => {
fix = tempdirProject();
});

afterEach(() => {
fix.rm();
});

describe("glob", () => {
it("handles root match", () => {
fix.write();

const result = glob(fix.cwd, fix.cwd, { includeDirectories: true });
equal(result, [fix.cwd]);
});

it("Handles basic globbing", () => {
fix.addFile("test.ts");
fix.addFile("test2.ts");
fix.addFile("a.ts");
fix.addFile("b.js");
fix.write();

equal(
glob(`${fix.cwd}/*.ts`, fix.cwd).map((f) => basename(f)),
["a.ts", "test.ts", "test2.ts"]
);
equal(
glob(`**/test*.ts`, fix.cwd).map((f) => basename(f)),
["test.ts", "test2.ts"]
);
});
});
});

0 comments on commit c86c52e

Please sign in to comment.