diff --git a/core/garment/__tests__/garment.test.ts b/core/garment/__tests__/garment.test.ts index afdd1ed..4a80089 100644 --- a/core/garment/__tests__/garment.test.ts +++ b/core/garment/__tests__/garment.test.ts @@ -63,4 +63,21 @@ describe('createFileInput', () => { expect(filesCount).toBe(2); }); + + test('should throw with a clear error message when rootDir does not exist', async () => { + const testDir = await initFixture('basic'); + + const nonExistingDirectory = Path.join(testDir, 'nonExistingDirectory'); + const generator = createFileInput({ + rootDir: nonExistingDirectory + }); + + const createFileInputForNonExistingRootDirectory = () => { + generator.next(); + }; + + expect(createFileInputForNonExistingRootDirectory).toThrow( + /nonExistingDirectory/ + ); + }); }); diff --git a/core/garment/src/garment.ts b/core/garment/src/garment.ts index 5706153..ec67ee6 100644 --- a/core/garment/src/garment.ts +++ b/core/garment/src/garment.ts @@ -1083,6 +1083,11 @@ 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, diff --git a/docs/Configuration.md b/docs/Configuration.md index 60cda1b..4dcf1b0 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -246,7 +246,7 @@ Defines which files are sent as an input to the runner. If defined as an object, } ``` -`rootDir: string` defines where the input files are. `include: string[]` and `exclude: string[]` define glob patterns to include to or exclude from files set. Note, that each runner can have a default `include` and `exclude` patterns, so the developer only needs to define a `rootDir`. If `input` is a `string` then it defines a `rootDir` and uses default values `[**/*]` for include and `[]` for exclude, or the ones defined by runner. +`rootDir: string` defines where the input files are. `include: string[]` and `exclude: string[]` define glob patterns to include to or exclude from files set. Note, that each runner can have a default `include` and `exclude` patterns, so the developer only needs to define a `rootDir`. If `input` is a `string` then it defines a `rootDir` and uses default values `[**/*]` for include and `[]` for exclude, or the ones defined by runner. Note that `rootDir` must exist and that when using globs, the non-magical part (the part before the first glob character) must exist. If not specified, the files from previous tasks will be passed as input files. If you want to receive both files from the disk and previous tasks, you should specify `pipe` option as `true` or glob pattern;