Skip to content
This repository was archived by the owner on Jan 3, 2024. It is now read-only.

Commit a16a853

Browse files
authored
fix: Error for rootDir only when necessary (#29)
1 parent 27fa8bf commit a16a853

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

core/garment/__tests__/garment.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,19 @@ describe('createFileInput', () => {
6464
expect(filesCount).toBe(2);
6565
});
6666

67-
test('should throw with a clear error message when rootDir does not exist', async () => {
67+
test('should NOT throw when rootDir does not exist, allowing for input globs in garment.json whose rootDir may or may not exist', async () => {
6868
const testDir = await initFixture('basic');
6969

7070
const nonExistingDirectory = Path.join(testDir, 'nonExistingDirectory');
7171
const generator = createFileInput({
72-
rootDir: nonExistingDirectory
72+
rootDir: nonExistingDirectory,
73+
include: ['*']
7374
});
7475

7576
const createFileInputForNonExistingRootDirectory = () => {
7677
generator.next();
7778
};
7879

79-
expect(createFileInputForNonExistingRootDirectory).toThrow(
80-
/nonExistingDirectory/
81-
);
80+
expect(createFileInputForNonExistingRootDirectory).not.toThrow();
8281
});
8382
});

core/garment/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"multimatch": "^4.0.0",
1919
"normalize-path": "^3.0.0",
2020
"tempy": "0.3.0",
21-
"unionfs": "^4.4.0"
21+
"unionfs": "^4.4.0",
22+
"globby": "10.0.1"
2223
},
2324
"files": [
2425
"lib",

core/garment/src/garment.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,19 +1127,16 @@ export function* createFileInput(
11271127
{ rootDir, files = [], include, exclude = [] }: Input,
11281128
fsInstance = fs
11291129
) {
1130-
if (!fsInstance.existsSync(rootDir)) {
1131-
throw new Error(`The path ${rootDir} does not exist, please check the input property
1132-
of your tasks in your garment.json file and verify that the "non-magical" part of your glob
1133-
is a path to an already existing directory`);
1134-
}
1135-
const filesFromGlob = include
1136-
? globby.sync(include, {
1137-
cwd: rootDir,
1138-
absolute: true,
1139-
ignore: exclude,
1140-
dot: true
1141-
})
1142-
: [];
1130+
const filesFromGlob =
1131+
fsInstance === fs && include && fsInstance.existsSync(rootDir)
1132+
? globby.sync(include, {
1133+
cwd: rootDir,
1134+
absolute: true,
1135+
ignore: exclude,
1136+
dot: true
1137+
})
1138+
: [];
1139+
11431140
const uniqueFiles = new Set([...files, ...filesFromGlob]);
11441141
for (const absolutePath of uniqueFiles) {
11451142
const content = fsInstance.readFileSync(absolutePath);

0 commit comments

Comments
 (0)