"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resourceRuleFallback = void 0;
const constants_1 = require("./constants");
const resourceRuleFallback = (rules = []) => {
    const innerRules = [];
    const outerRules = [];
    for (const rule of rules) {
        if (!rule) {
            continue;
        }
        if (
        // "..." refers to the webpack defaults
        rule === '...' ||
            // this is a special case, put the mjs fullySpecified rule in the outside
            (rule.resolve && !rule.mimetype)) {
            outerRules.push(rule);
        }
        else if (rule.oneOf &&
            !(rule.test ||
                rule.exclude ||
                rule.resource ||
                rule.issuer ||
                rule.mimetype)) {
            rule.oneOf.forEach(item => {
                if (item) {
                    innerRules.push(item);
                }
            });
        }
        else {
            innerRules.push(rule);
        }
    }
    const fileLoader = {
        exclude: [
            constants_1.JS_REGEX,
            constants_1.TS_REGEX,
            // exclude `html` and `json`, they get processed by webpack internal loaders.
            /\.html$/,
            /\.json$/,
        ],
        type: 'asset/resource',
    };
    return [...outerRules, { oneOf: [...innerRules, fileLoader] }];
};
exports.resourceRuleFallback = resourceRuleFallback;
