From 52791512415416c91266d45255c7dffd3f1166a4 Mon Sep 17 00:00:00 2001 From: Bret Comnes Date: Tue, 27 Aug 2019 15:03:10 +0200 Subject: [PATCH] Correct path resolution when to/from paths match If you want to run post-css on the following arrangement: `postcss app/app.css -o app/app.bundle.css` Postcss-url will then save the copied assets to process.cwd(), which in this case is `.`. Not correct. It should copy the assets to `app/${assetsPath}`. This fix makes it so the assets are correctly copied to the same folder (presumably inside of a `assetsPath`. I'm not 100% sure what the intention of the original logic was, but it appeared to be guarding for when there was a missing `to` option. This will still preserve the original behavior when `to` is !existy and use process.cwd(). Apologies if this understanding is incorrect. --- src/lib/paths.js | 2 +- test/lib/paths.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/paths.js b/src/lib/paths.js index d7f76c4..23b0383 100644 --- a/src/lib/paths.js +++ b/src/lib/paths.js @@ -57,7 +57,7 @@ const getAssetsPath = (baseDir, assetsPath, relative) => * @returns {String} */ const getTargetDir = (dir) => - dir.from !== dir.to ? dir.to : process.cwd(); + dir.to != null ? dir.to : process.cwd(); /** * Stylesheet file path from decl diff --git a/test/lib/paths.js b/test/lib/paths.js index 3421759..df875bd 100644 --- a/test/lib/paths.js +++ b/test/lib/paths.js @@ -74,6 +74,10 @@ describe('paths', () => { ); assert.equal( paths.getTargetDir({ from: '/project', to: '/project' }), + '/project' + ); + assert.equal( + paths.getTargetDir({ from: '/project' }), process.cwd() ); });