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

Commit

Permalink
fix: Error for rootDir only when necessary (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephan-noel authored Dec 30, 2020
1 parent 27fa8bf commit a16a853
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
9 changes: 4 additions & 5 deletions core/garment/__tests__/garment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,19 @@ describe('createFileInput', () => {
expect(filesCount).toBe(2);
});

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

const nonExistingDirectory = Path.join(testDir, 'nonExistingDirectory');
const generator = createFileInput({
rootDir: nonExistingDirectory
rootDir: nonExistingDirectory,
include: ['*']
});

const createFileInputForNonExistingRootDirectory = () => {
generator.next();
};

expect(createFileInputForNonExistingRootDirectory).toThrow(
/nonExistingDirectory/
);
expect(createFileInputForNonExistingRootDirectory).not.toThrow();
});
});
3 changes: 2 additions & 1 deletion core/garment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"multimatch": "^4.0.0",
"normalize-path": "^3.0.0",
"tempy": "0.3.0",
"unionfs": "^4.4.0"
"unionfs": "^4.4.0",
"globby": "10.0.1"
},
"files": [
"lib",
Expand Down
23 changes: 10 additions & 13 deletions core/garment/src/garment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1127,19 +1127,16 @@ export function* createFileInput(
{ rootDir, files = [], include, exclude = [] }: Input,
fsInstance = fs
) {
if (!fsInstance.existsSync(rootDir)) {
throw new Error(`The path ${rootDir} does not exist, please check the input property
of your tasks in your garment.json file and verify that the "non-magical" part of your glob
is a path to an already existing directory`);
}
const filesFromGlob = include
? globby.sync(include, {
cwd: rootDir,
absolute: true,
ignore: exclude,
dot: true
})
: [];
const filesFromGlob =
fsInstance === fs && include && fsInstance.existsSync(rootDir)
? globby.sync(include, {
cwd: rootDir,
absolute: true,
ignore: exclude,
dot: true
})
: [];

const uniqueFiles = new Set([...files, ...filesFromGlob]);
for (const absolutePath of uniqueFiles) {
const content = fsInstance.readFileSync(absolutePath);
Expand Down

0 comments on commit a16a853

Please sign in to comment.