From 1afd6fda949831166ebca3598389aa61eed08f9b Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Mon, 8 Feb 2021 21:13:53 -0500 Subject: [PATCH] Fixing windows paths --- lib/helpers.js | 6 +++++- lib/hooks.js | 22 +++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/helpers.js b/lib/helpers.js index 1df4153..da6c4e7 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -82,7 +82,11 @@ const reduceChunk = (files, chunk, options, auxiliaryFiles) => { return Array.from(chunk.files).reduce((prev, path) => { let name = chunk.name ? chunk.name : null; // chunk name, or for nameless chunks, just map the files directly. - name = name ? (options.useEntryKeys ? name : `${name}.${getFileType(path, options)}`) : path; + name = name + ? options.useEntryKeys && !path.endsWith('.map') + ? name + : `${name}.${getFileType(path, options)}` + : path; return prev.concat({ path, diff --git a/lib/hooks.js b/lib/hooks.js index 221bb0c..533651a 100644 --- a/lib/hooks.js +++ b/lib/hooks.js @@ -33,15 +33,7 @@ const beforeRunHook = ({ emitCountMap, manifestFileName }, compiler, callback) = }; const emitHook = function emit( - { - compiler, - emitCountMap, - manifestAssetId, - manifestFileName, - moduleAssets, - assetTypeModuleAssets, - options - }, + { compiler, emitCountMap, manifestAssetId, manifestFileName, moduleAssets, assetTypeModuleAssets, options }, compilation ) { const emitCount = emitCountMap.get(manifestFileName) - 1; @@ -142,11 +134,15 @@ const normalModuleLoaderHook = ({ moduleAssets, assetTypeModuleAssets }, loaderC // the "emitFile" callback is never called on asset modules // so, we create a different map that can be used later in the "emit" hook if (['asset', 'asset/inline', 'asset/resource', 'asset/source'].includes(module.type)) { + // This takes the userRequest (which is an absolute path) and turns it into + // a relative path to the root context. This is done so that the string + // will match asset.info.sourceFilename in the emit hook. + let sourceFilename = relative(loaderContext.rootContext, module.userRequest); + // at this point, Windows paths use \ in their paths + // but in the emit hook, asset.info.sourceFilename fill have UNIX slashes + sourceFilename = sourceFilename.replace(/\\/g, '/'); Object.assign(assetTypeModuleAssets, { - // This takes the userRequest (which is an absolute path) and turns it into - // a relative path to the root context. This is done so that the string - // will match asset.info.sourceFilename in the emit hook. - [relative(loaderContext.rootContext, module.userRequest)]: basename(module.userRequest) + [sourceFilename]: basename(module.userRequest) }); }