Skip to content

Commit

Permalink
Fixing windows paths
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverryan committed Feb 9, 2021
1 parent 80c80b1 commit 1afd6fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
6 changes: 5 additions & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 9 additions & 13 deletions lib/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
});
}

Expand Down

0 comments on commit 1afd6fd

Please sign in to comment.