Skip to content

Commit

Permalink
Merge pull request #429 from tsedio/fix-barrels-nested-directories
Browse files Browse the repository at this point in the history
fix(barrels): fix glob pattern to discover nested directory
  • Loading branch information
Romakita authored Dec 13, 2024
2 parents 4899d18 + 6436e87 commit fce6cf3
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/barrels/bin/barrels.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {getConfig} from "./get-config.js";

async function build() {
const {directory = ["./src"], exclude = ["**/__mock__", "**/__mocks__", "**/*.spec.ts", "**/*.benchmark.ts"]} = await getConfig();

await generateBarrels({exclude, directory, cwd: process.cwd()});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const file2 = "file2";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const file3 = "file3";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const file3 = "file3";
6 changes: 6 additions & 0 deletions packages/barrels/test/__mock__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"noEmit": true
},
"include": ["**/*"]
}
29 changes: 29 additions & 0 deletions packages/barrels/test/barrels.integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,38 @@ describe("barrels.integration.ts", () => {

const result1 = await fs.readFile(join(cwd, "scenario-2", "sub-directory-2", "index.ts"), "utf-8");

assert.strictEqual(
result1,
"/**\n" + " * @file Automatically generated by @tsed/barrels.\n" + " */\n" + 'export * from "./file2.js";\n'
);
});
// eslint-disable-next-line vitest/expect-expect
it("should generate barrels (with multiple directories and nested subdirectories)", async () => {
const cwd = join(import.meta.dirname, "__mock__");
// Test code here
await generateBarrels({
cwd,
directory: ["./scenario-3/sub-directory-1", "./scenario-3/sub-directory-2"],
exclude: ["**/__mock__", "**/__mocks__", "**/*.spec.ts"],
delete: true
});

const result = await fs.readFile(join(cwd, "scenario-2", "sub-directory-1", "index.ts"), "utf-8");

assert.strictEqual(
result,
"/**\n" + " * @file Automatically generated by @tsed/barrels.\n" + " */\n" + 'export * from "./file2.js";\n'
);

const result1 = await fs.readFile(join(cwd, "scenario-3", "sub-directory-1", "index.ts"), "utf-8");

assert.strictEqual(
result1,
"/**\n" +
" * @file Automatically generated by @tsed/barrels.\n" +
" */\n" +
'export * from "./file2.js";\n' +
'export * from "./sub-path/file3.js";\n'
);
});
});

0 comments on commit fce6cf3

Please sign in to comment.