"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = (module)=>{
        var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    default: ()=>add_hmr_accept_code
});
const external_fs_namespaceObject = require("fs");
var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namespaceObject);
const external_path_namespaceObject = require("path");
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
const external_loader_utils_namespaceObject = require("loader-utils");
const external_schema_utils_namespaceObject = require("schema-utils");
const schema = {
    type: 'object',
    properties: {
        test: {
            type: 'string'
        },
        manifestPath: {
            type: 'string'
        },
        mode: {
            type: 'string'
        }
    }
};
function add_hmr_accept_code(source) {
    const options = this.getOptions();
    const manifestPath = options.manifestPath;
    const projectPath = external_path_default().dirname(manifestPath);
    const manifest = JSON.parse(external_fs_default().readFileSync(manifestPath, 'utf-8'));
    (0, external_schema_utils_namespaceObject.validate)(schema, options, {
        name: "scripts:add-hmr-accept-code",
        baseDataPath: 'options'
    });
    if (source.includes('import.meta.webpackHot')) return source;
    const url = (0, external_loader_utils_namespaceObject.urlToRequest)(this.resourcePath);
    const reloadCodeBackground = `
// Extension.js HMR registration (injected)
if (import.meta.webpackHot) { try { import.meta.webpackHot.accept(); } catch (_) {} }
  `;
    if (manifest.background) {
        if (manifest.background.scripts) for (const bgScript of manifest.background.scripts){
            const absoluteUrl = external_path_default().resolve(projectPath, bgScript);
            if (url.includes(absoluteUrl)) return `${reloadCodeBackground}${source}`;
        }
    }
    if (manifest.user_scripts) for (const userScript of manifest.user_scripts){
        const absoluteUrl = external_path_default().resolve(projectPath, userScript);
        if (url.includes(absoluteUrl)) return `${reloadCodeBackground}${source}`;
    }
    return source;
}
exports["default"] = __webpack_exports__["default"];
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "default"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
