From 9d8d30a7e23744b4bda61fdf974585b387ddb526 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Wed, 16 Oct 2019 11:15:54 -0400 Subject: [PATCH] Ensure defaulted process.cwd() has been corrected to posix paths. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When `globby` is invoked with `globby('*', { absolute: true, gitignore: true })` on Windows systems, the assertion added in 4af038edf82f6be9fe71f003e5db53dae879e687 **always** triggers. This is because when we default the `cwd` in `normalizeOptions`, we didn't convert from `C:\\` style paths to forward slashes. The test added here was failing on Windows, example output prior to the fixes: ``` test ยป gitignore option with absolute option C:\Users\travis\build\rwjblue\globby\gitignore.js:52 51: 52: throw new Error(`Path ${p} is not in cwd ${cwd}`); 53: } Rejected promise returned by test. Reason: Error { message: 'Path C:/Users/travis/build/rwjblue/globby/a.tmp is not in cwd C:\\Users\\travis\\build\\rwjblue\\globby', } ``` --- gitignore.js | 2 +- test.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/gitignore.js b/gitignore.js index 8024ffc..3feaad6 100644 --- a/gitignore.js +++ b/gitignore.js @@ -83,7 +83,7 @@ const getFileSync = (file, cwd) => { const normalizeOptions = ({ ignore = [], - cwd = process.cwd() + cwd = slash(process.cwd()) } = {}) => { return {ignore, cwd}; }; diff --git a/test.js b/test.js index 165d46a..68749b1 100644 --- a/test.js +++ b/test.js @@ -298,6 +298,11 @@ test('gitignore option with stats option', async t => { t.false(actual.includes('node_modules')); }); +test('gitignore option with absolute option', async t => { + const result = await globby('*', {gitignore: true, absolute: true}); + t.false(result.includes('node_modules')); +}); + test('respects gitignore option false - stream', async t => { const actual = await getStream.array(globby.stream('*', {gitignore: false, onlyFiles: false})); t.true(actual.includes('node_modules'));