MCPcopy
hub / github.com/webpack/webpack / applyWebpackOptionsInterception

Function applyWebpackOptionsInterception

lib/config/normalization.js:614–697  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

612 * @returns {{ options: WebpackOptionsNormalized, interception?: WebpackOptionsInterception }} options and interception
613 */
614const applyWebpackOptionsInterception = (options) => {
615 // Return origin options when backCompat is disabled
616 if (options.experiments.futureDefaults) {
617 return {
618 options
619 };
620 }
621
622 // TODO webpack 6 - remove compatibility logic and move `devtools` fully into `devtool` with multi-type support
623 let _devtool = options.devtool;
624 /** @type {WebpackOptionsNormalized["devtool"]} */
625 let cached;
626
627 const devtoolBackCompat = () => {
628 if (Array.isArray(_devtool)) {
629 if (cached) return cached;
630 // Prefer `all`, then `javascript`, then `css`
631 const match = ["all", "javascript", "css"]
632 .map((type) =>
633 /** @type {Extract<WebpackOptionsNormalized["devtool"], EXPECTED_ANY[]>} */ (
634 _devtool
635 ).find((item) => item.type === type)
636 )
637 .find(Boolean);
638
639 // If `devtool: []` is specified, return `false` here
640 return (cached = match ? match.use : false);
641 }
642 return _devtool;
643 };
644
645 /** @type {ProxyHandler<WebpackOptionsNormalized>} */
646 const handler = Object.create(null);
647 handler.get = (target, prop, receiver) => {
648 if (prop === "devtool") {
649 return devtoolBackCompat();
650 }
651 return Reflect.get(target, prop, receiver);
652 };
653 handler.set = (target, prop, value, receiver) => {
654 if (prop === "devtool") {
655 _devtool = value;
656 cached = undefined;
657 return true;
658 }
659 return Reflect.set(target, prop, value, receiver);
660 };
661 handler.deleteProperty = (target, prop) => {
662 if (prop === "devtool") {
663 _devtool = undefined;
664 cached = undefined;
665 return true;
666 }
667 return Reflect.deleteProperty(target, prop);
668 };
669 handler.defineProperty = (target, prop, descriptor) => {
670 if (prop === "devtool") {
671 _devtool = descriptor.value;

Callers 1

createCompilerFunction · 0.85

Calls 4

devtoolBackCompatFunction · 0.85
createMethod · 0.45
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected