From 26e47caeb00479815ffac3139be0e296d0671171 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Tue, 20 Feb 2018 22:15:34 +0300 Subject: [PATCH] fix(index): normalize and concat paths via `path.join()` --- src/index.js | 6 +++--- test/options/__snapshots__/outputPath.test.js.snap | 2 +- test/options/__snapshots__/publicPath.test.js.snap | 2 +- test/options/__snapshots__/useRelativePath.test.js.snap | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index 23edabe..ffff9f2 100644 --- a/src/index.js +++ b/src/index.js @@ -32,9 +32,9 @@ export default function loader(content) { const relativePath = relativeUrl && `${path.dirname(relativeUrl)}/`; // eslint-disable-next-line no-bitwise if (~relativePath.indexOf('../')) { - outputPath = path.posix.join(outputPath, relativePath, url); + outputPath = path.join(outputPath, relativePath, url); } else { - outputPath = relativePath + url; + outputPath = path.join(relativePath, url); } } @@ -43,7 +43,7 @@ export default function loader(content) { if (options.publicPath !== undefined) { // support functions as publicPath to generate them dynamically publicPath = JSON.stringify( - typeof options.publicPath === 'function' ? options.publicPath(url) : options.publicPath + url, + typeof options.publicPath === 'function' ? options.publicPath(url) : path.join(options.publicPath || '', url), ); } else { publicPath = `__webpack_public_path__ + ${JSON.stringify(outputPath)}`; diff --git a/test/options/__snapshots__/outputPath.test.js.snap b/test/options/__snapshots__/outputPath.test.js.snap index 23b27e8..d8d2d41 100644 --- a/test/options/__snapshots__/outputPath.test.js.snap +++ b/test/options/__snapshots__/outputPath.test.js.snap @@ -77,7 +77,7 @@ Object { "assets": Array [ "output_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png", ], - "source": "module.exports = \\"public_path9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", + "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", } `; diff --git a/test/options/__snapshots__/publicPath.test.js.snap b/test/options/__snapshots__/publicPath.test.js.snap index 55bbb1a..ce726ca 100644 --- a/test/options/__snapshots__/publicPath.test.js.snap +++ b/test/options/__snapshots__/publicPath.test.js.snap @@ -23,6 +23,6 @@ Object { "assets": Array [ "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", ], - "source": "module.exports = \\"public_path9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", + "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", } `; diff --git a/test/options/__snapshots__/useRelativePath.test.js.snap b/test/options/__snapshots__/useRelativePath.test.js.snap index afc3e3d..08bd912 100644 --- a/test/options/__snapshots__/useRelativePath.test.js.snap +++ b/test/options/__snapshots__/useRelativePath.test.js.snap @@ -30,8 +30,8 @@ Object { exports[`Options useRelativePath \`true\` with relative \`context\` 1`] = ` Object { "assets": Array [ - "./9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", ], - "source": "module.exports = __webpack_public_path__ + \\"./9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", + "source": "module.exports = __webpack_public_path__ + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", } `;