66"use strict" ;
77
88const util = require ( "util" ) ;
9+ const { fileUrlToPath } = require ( "../util/identifier" ) ;
910
1011/**
1112 * @import {
@@ -35,6 +36,28 @@ const util = require("util");
3536 * @property {WebpackOptionsNormalized["devtool"]= } devtool
3637 */
3738
39+ /**
40+ * Converts a file URL to the path it names. Anything that is not a string is
41+ * returned unchanged, so `false` and `undefined` pass through.
42+ * @template {string | false | undefined} T
43+ * @param {T } pathOrUrl an absolute path, a file URL, `false` or `undefined`
44+ * @returns {T } an absolute path, `false` or `undefined`
45+ */
46+ const optionalFileUrlToPath = ( pathOrUrl ) =>
47+ typeof pathOrUrl === "string"
48+ ? /** @type {T } */ ( fileUrlToPath ( pathOrUrl ) )
49+ : pathOrUrl ;
50+
51+ /**
52+ * Converts every file URL of a list to the path it names.
53+ * @param {(string | RegExp)[] } pathsOrUrls absolute paths, file URLs or regular expressions
54+ * @returns {(string | RegExp)[] } absolute paths and regular expressions
55+ */
56+ const fileUrlsToPaths = ( pathsOrUrls ) =>
57+ pathsOrUrls . map ( ( pathOrUrl ) =>
58+ typeof pathOrUrl === "string" ? fileUrlToPath ( pathOrUrl ) : pathOrUrl
59+ ) ;
60+
3861const handledDeprecatedNoEmitOnErrors = util . deprecate (
3962 /**
4063 * Handles the callback logic for this hook.
@@ -226,8 +249,8 @@ const getNormalizedWebpackOptions = (config) => ({
226249 buildDependencies : normalizeBuildDependencies (
227250 cache . buildDependencies
228251 ) ,
229- cacheDirectory : cache . cacheDirectory ,
230- cacheLocation : cache . cacheLocation ,
252+ cacheDirectory : optionalFileUrlToPath ( cache . cacheDirectory ) ,
253+ cacheLocation : optionalFileUrlToPath ( cache . cacheLocation ) ,
231254 hashAlgorithm : cache . hashAlgorithm ,
232255 compression : cache . compression ,
233256 idleTimeout : cache . idleTimeout ,
@@ -250,7 +273,7 @@ const getNormalizedWebpackOptions = (config) => ({
250273 }
251274 } )
252275 ) ,
253- context : config . context ,
276+ context : optionalFileUrlToPath ( config . context ) ,
254277 dependencies : config . dependencies ,
255278 devServer : optionalNestedConfig ( config . devServer , ( devServer ) => {
256279 if ( devServer === false ) return false ;
@@ -478,7 +501,7 @@ const getNormalizedWebpackOptions = (config) => ({
478501 : libraryBase . umdNamedDefine
479502 } ,
480503 module : output . module ,
481- path : output . path ,
504+ path : optionalFileUrlToPath ( output . path ) ,
482505 pathinfo : output . pathinfo ,
483506 publicPath : output . publicPath ,
484507 resourceHints : normalizeResourceHints ( output . resourceHints ) ,
@@ -520,14 +543,16 @@ const getNormalizedWebpackOptions = (config) => ({
520543 nestedArray ( config . plugins , ( p ) => p . filter ( Boolean ) )
521544 ) ,
522545 profile : config . profile ,
523- recordsInputPath :
546+ recordsInputPath : optionalFileUrlToPath (
524547 config . recordsInputPath !== undefined
525548 ? config . recordsInputPath
526- : config . recordsPath ,
527- recordsOutputPath :
549+ : config . recordsPath
550+ ) ,
551+ recordsOutputPath : optionalFileUrlToPath (
528552 config . recordsOutputPath !== undefined
529553 ? config . recordsOutputPath
530- : config . recordsPath ,
554+ : config . recordsPath
555+ ) ,
531556 resolve : nestedConfig ( config . resolve , ( resolve ) => ( {
532557 ...resolve ,
533558 byDependency : keyedNestedConfig ( resolve . byDependency , cloneObject )
@@ -563,9 +588,15 @@ const getNormalizedWebpackOptions = (config) => ({
563588 hash : contextModule . hash
564589 } )
565590 ) ,
566- immutablePaths : optionalNestedArray ( snapshot . immutablePaths , ( p ) => [ ...p ] ) ,
567- managedPaths : optionalNestedArray ( snapshot . managedPaths , ( p ) => [ ...p ] ) ,
568- unmanagedPaths : optionalNestedArray ( snapshot . unmanagedPaths , ( p ) => [ ...p ] )
591+ immutablePaths : optionalNestedArray (
592+ snapshot . immutablePaths ,
593+ fileUrlsToPaths
594+ ) ,
595+ managedPaths : optionalNestedArray ( snapshot . managedPaths , fileUrlsToPaths ) ,
596+ unmanagedPaths : optionalNestedArray (
597+ snapshot . unmanagedPaths ,
598+ fileUrlsToPaths
599+ )
569600 } ) ) ,
570601 stats : nestedConfig ( config . stats , ( stats ) => {
571602 if ( stats === false ) {
0 commit comments