UNPKG

extension-develop

Version:
136 lines (131 loc) 5.52 kB
"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 ('undefined' != 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: ()=>deprecated_shadow_root }); const external_path_namespaceObject = require("path"); const external_fs_namespaceObject = require("fs"); const external_loader_utils_namespaceObject = require("loader-utils"); const external_schema_utils_namespaceObject = require("schema-utils"); const external_pintor_namespaceObject = require("pintor"); var external_pintor_default = /*#__PURE__*/ __webpack_require__.n(external_pintor_namespaceObject); external_path_namespaceObject.join(process.cwd(), 'node_modules/extension-develop/dist/certs'); const CHROMIUM_BASED_BROWSERS = [ 'chrome', 'edge' ]; const GECKO_BASED_BROWSERS = [ 'firefox' ]; [ ...CHROMIUM_BASED_BROWSERS, ...GECKO_BASED_BROWSERS ]; function getLoggingPrefix(feature, type) { if ('error' === type) return `${external_pintor_default().red('ERROR')} ${feature}`; if ('warn' === type) return `${external_pintor_default().brightYellow("\u25BA\u25BA\u25BA")} ${feature}`; const arrow = 'info' === type ? external_pintor_default().blue("\u25BA\u25BA\u25BA") : external_pintor_default().green("\u25BA\u25BA\u25BA"); return `${arrow} ${feature}`; } function deprecatedShadowRoot() { return `${getLoggingPrefix('DEPRECATION', 'warn')} Using ${external_pintor_default().yellow('window.__EXTENSION_SHADOW_ROOT__')} in content_scripts is deprecated\nand will be removed in a future version of Extension.js. To use content_scripts with\nthe shadow DOM, see one of the many examples at:\nhttps://github.com/extension-js/extension.js/tree/main/examples\n\nIf you really need to use the shadow DOM as-is, the latest version of Extension.js\nto support it is ${external_pintor_default().gray('extension@2.0.0-beta.9')}.\n`; } const schema = { type: 'object', properties: { test: { type: 'string' }, manifestPath: { type: 'string' } } }; function deprecated_shadow_root(source) { const options = this.getOptions(); const manifestPath = options.manifestPath; const projectPath = external_path_namespaceObject.dirname(manifestPath); const manifest = JSON.parse(external_fs_namespaceObject.readFileSync(manifestPath, 'utf8')); (0, external_schema_utils_namespaceObject.validate)(schema, options, { name: "scripts:deprecated-shadow-root", baseDataPath: 'options' }); const url = (0, external_loader_utils_namespaceObject.urlToRequest)(this.resourcePath); const patchCssTag = ` ;const appendStyleElementForLegacyShadowRoot = (legacyShadowRoot, stylesheets) => { if (typeof chrome !== 'undefined' || typeof browser !== 'undefined') { const styleElement = document.createElement('link') styleElement.rel = 'stylesheet' styleElement.href = (typeof chrome !== 'undefined' ? chrome : browser).runtime.getURL('content_scripts/content-0.css') legacyShadowRoot.appendChild(styleElement) } } function injectStyles() { const legacyShadowRoot = window.__EXTENSION_SHADOW_ROOT__ if (legacyShadowRoot) { appendStyleElementForLegacyShadowRoot(legacyShadowRoot) } else { // Use MutationObserver to wait for shadow root to be available const observer = new MutationObserver(() => { const shadowRoot = window.__EXTENSION_SHADOW_ROOT__ if (shadowRoot) { appendStyleElementForLegacyShadowRoot(shadowRoot) observer.disconnect() } }) observer.observe(document.body, { childList: true, subtree: true }) } };injectStyles();`; if (manifest.content_scripts) { for (const contentScript of manifest.content_scripts)if (contentScript.js) for (const js of contentScript.js){ const absoluteUrl = external_path_namespaceObject.resolve(projectPath, js); if (url.includes(absoluteUrl)) { if (source.includes('__EXTENSION_SHADOW_ROOT__')) { if ('development' === process.env.EXTENSION_ENV) console.warn(deprecatedShadowRoot()); return `${patchCssTag}${source}`; } return `${source}`; } } } return source; } exports["default"] = __webpack_exports__["default"]; for(var __webpack_i__ in __webpack_exports__)if (-1 === [ "default" ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__]; Object.defineProperty(exports, '__esModule', { value: true });