extension-develop 2.1.3 → 3.0.0-next.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. package/README.md +53 -25
  2. package/dist/930.js +44 -0
  3. package/dist/add-centralized-logger-script-background.js +220 -0
  4. package/dist/add-centralized-logger-script-content.js +172 -0
  5. package/dist/add-centralized-logger-script.js +332 -0
  6. package/dist/add-hmr-accept-code.js +5 -11
  7. package/dist/content-script-wrapper.js +166 -0
  8. package/dist/ensure-hmr-for-scripts.js +30 -11
  9. package/dist/minimum-chromium-file.js +6 -20
  10. package/dist/minimum-firefox-file.js +6 -12
  11. package/dist/module.js +11751 -9472
  12. package/dist/resolve-paths-loader.js +1387 -0
  13. package/dist/warn-no-default-export.js +121 -0
  14. package/package.json +21 -35
  15. package/dist/add-content-script-wrapper.js +0 -1789
  16. package/dist/build.d.ts +0 -2
  17. package/dist/cleanup.d.ts +0 -1
  18. package/dist/deprecated-shadow-root.js +0 -135
  19. package/dist/dev.d.ts +0 -2
  20. package/dist/develop-lib/config-types.d.ts +0 -86
  21. package/dist/develop-lib/extract-from-zip.d.ts +0 -1
  22. package/dist/develop-lib/find-nearest-package.d.ts +0 -2
  23. package/dist/develop-lib/generate-extension-types.d.ts +0 -1
  24. package/dist/develop-lib/generate-zip.d.ts +0 -2
  25. package/dist/develop-lib/get-extension-config.d.ts +0 -6
  26. package/dist/develop-lib/get-project-path.d.ts +0 -6
  27. package/dist/develop-lib/install-dependencies.d.ts +0 -2
  28. package/dist/develop-lib/messages.d.ts +0 -36
  29. package/dist/develop-lib/validate-user-dependencies.d.ts +0 -1
  30. package/dist/extensions/chrome-manager-extension/background.js +0 -84
  31. package/dist/extensions/chrome-manager-extension/define-initial-tab.js +0 -77
  32. package/dist/extensions/chrome-manager-extension/images/logo.png +0 -0
  33. package/dist/extensions/chrome-manager-extension/manifest.json +0 -17
  34. package/dist/extensions/chrome-manager-extension/pages/sakura-dark.css +0 -268
  35. package/dist/extensions/chrome-manager-extension/pages/sakura.css +0 -267
  36. package/dist/extensions/chrome-manager-extension/pages/welcome.html +0 -46
  37. package/dist/extensions/chrome-manager-extension/pages/welcome.js +0 -34
  38. package/dist/extensions/chrome-manager-extension/reload-service.js +0 -319
  39. package/dist/extensions/chromium-based-manager-extension/background.js +0 -84
  40. package/dist/extensions/chromium-based-manager-extension/define-initial-tab.js +0 -77
  41. package/dist/extensions/chromium-based-manager-extension/images/logo.png +0 -0
  42. package/dist/extensions/chromium-based-manager-extension/manifest.json +0 -17
  43. package/dist/extensions/chromium-based-manager-extension/pages/sakura-dark.css +0 -268
  44. package/dist/extensions/chromium-based-manager-extension/pages/sakura.css +0 -267
  45. package/dist/extensions/chromium-based-manager-extension/pages/welcome.html +0 -46
  46. package/dist/extensions/chromium-based-manager-extension/pages/welcome.js +0 -34
  47. package/dist/extensions/chromium-based-manager-extension/reload-service.js +0 -324
  48. package/dist/extensions/edge-manager-extension/background.js +0 -82
  49. package/dist/extensions/edge-manager-extension/define-initial-tab.js +0 -77
  50. package/dist/extensions/edge-manager-extension/images/logo.png +0 -0
  51. package/dist/extensions/edge-manager-extension/manifest.json +0 -17
  52. package/dist/extensions/edge-manager-extension/pages/sakura-dark.css +0 -268
  53. package/dist/extensions/edge-manager-extension/pages/sakura.css +0 -267
  54. package/dist/extensions/edge-manager-extension/pages/welcome.html +0 -46
  55. package/dist/extensions/edge-manager-extension/pages/welcome.js +0 -34
  56. package/dist/extensions/edge-manager-extension/reload-service.js +0 -321
  57. package/dist/extensions/firefox-manager-extension/background.js +0 -85
  58. package/dist/extensions/firefox-manager-extension/define-initial-tab.js +0 -64
  59. package/dist/extensions/firefox-manager-extension/images/logo.png +0 -0
  60. package/dist/extensions/firefox-manager-extension/manifest.json +0 -15
  61. package/dist/extensions/firefox-manager-extension/pages/sakura-dark.css +0 -268
  62. package/dist/extensions/firefox-manager-extension/pages/sakura.css +0 -267
  63. package/dist/extensions/firefox-manager-extension/pages/welcome.html +0 -46
  64. package/dist/extensions/firefox-manager-extension/pages/welcome.js +0 -34
  65. package/dist/extensions/firefox-manager-extension/reload-service.js +0 -178
  66. package/dist/extensions/gecko-based-manager-extension/background.js +0 -67
  67. package/dist/extensions/gecko-based-manager-extension/define-initial-tab.js +0 -69
  68. package/dist/extensions/gecko-based-manager-extension/images/logo.png +0 -0
  69. package/dist/extensions/gecko-based-manager-extension/manifest.json +0 -16
  70. package/dist/extensions/gecko-based-manager-extension/pages/sakura-dark.css +0 -268
  71. package/dist/extensions/gecko-based-manager-extension/pages/sakura.css +0 -267
  72. package/dist/extensions/gecko-based-manager-extension/pages/welcome.html +0 -46
  73. package/dist/extensions/gecko-based-manager-extension/pages/welcome.js +0 -34
  74. package/dist/extensions/gecko-based-manager-extension/reload-service.js +0 -171
  75. package/dist/inject-chromium-client-loader.js +0 -176
  76. package/dist/inject-firefox-client-loader.js +0 -169
  77. package/dist/minimum-content-file.js +0 -5
  78. package/dist/module.d.ts +0 -8
  79. package/dist/preview.d.ts +0 -2
  80. package/dist/rslib.config.d.ts +0 -3
  81. package/dist/start.d.ts +0 -2
  82. package/dist/types.d.ts +0 -11
  83. package/dist/vitest.config.d.mts +0 -2
  84. package/dist/webpack/dev-server.d.ts +0 -3
  85. package/dist/webpack/plugin-browsers/browsers-lib/add-progress-bar.d.ts +0 -1
  86. package/dist/webpack/plugin-browsers/browsers-lib/constants.d.ts +0 -5
  87. package/dist/webpack/plugin-browsers/browsers-lib/dynamic-extension-manager.d.ts +0 -35
  88. package/dist/webpack/plugin-browsers/browsers-lib/html-merge.d.ts +0 -1
  89. package/dist/webpack/plugin-browsers/browsers-lib/instance-manager.d.ts +0 -74
  90. package/dist/webpack/plugin-browsers/browsers-lib/messages.d.ts +0 -164
  91. package/dist/webpack/plugin-browsers/browsers-lib/rdp-wire.d.ts +0 -7
  92. package/dist/webpack/plugin-browsers/browsers-lib/shared-utils.d.ts +0 -16
  93. package/dist/webpack/plugin-browsers/browsers-types.d.ts +0 -131
  94. package/dist/webpack/plugin-browsers/index.d.ts +0 -41
  95. package/dist/webpack/plugin-browsers/run-chromium/browser-config.d.ts +0 -3
  96. package/dist/webpack/plugin-browsers/run-chromium/create-profile.d.ts +0 -10
  97. package/dist/webpack/plugin-browsers/run-chromium/index.d.ts +0 -28
  98. package/dist/webpack/plugin-browsers/run-chromium/master-preferences.d.ts +0 -161
  99. package/dist/webpack/plugin-browsers/run-chromium/setup-chrome-inspection/cdp-client.d.ts +0 -29
  100. package/dist/webpack/plugin-browsers/run-chromium/setup-chrome-inspection/index.d.ts +0 -25
  101. package/dist/webpack/plugin-browsers/run-firefox/firefox/binary-detector.d.ts +0 -15
  102. package/dist/webpack/plugin-browsers/run-firefox/firefox/browser-config.d.ts +0 -7
  103. package/dist/webpack/plugin-browsers/run-firefox/firefox/create-profile.d.ts +0 -13
  104. package/dist/webpack/plugin-browsers/run-firefox/firefox/master-preferences.d.ts +0 -95
  105. package/dist/webpack/plugin-browsers/run-firefox/index.d.ts +0 -26
  106. package/dist/webpack/plugin-browsers/run-firefox/remote-firefox/index.d.ts +0 -13
  107. package/dist/webpack/plugin-browsers/run-firefox/remote-firefox/message-utils.d.ts +0 -2
  108. package/dist/webpack/plugin-browsers/run-firefox/remote-firefox/messaging-client.d.ts +0 -42
  109. package/dist/webpack/plugin-browsers/run-firefox/remote-firefox/setup-firefox-inspection.d.ts +0 -31
  110. package/dist/webpack/plugin-compatibility/feature-browser-specific-fields.d.ts +0 -9
  111. package/dist/webpack/plugin-compatibility/feature-polyfill.d.ts +0 -12
  112. package/dist/webpack/plugin-compatibility/index.d.ts +0 -13
  113. package/dist/webpack/plugin-compilation/clean-dist.d.ts +0 -8
  114. package/dist/webpack/plugin-compilation/env.d.ts +0 -9
  115. package/dist/webpack/plugin-compilation/index.d.ts +0 -12
  116. package/dist/webpack/plugin-css/common-style-loaders.d.ts +0 -8
  117. package/dist/webpack/plugin-css/css-in-content-script-loader.d.ts +0 -11
  118. package/dist/webpack/plugin-css/css-in-html-loader.d.ts +0 -8
  119. package/dist/webpack/plugin-css/css-tools/less.d.ts +0 -4
  120. package/dist/webpack/plugin-css/css-tools/postcss.d.ts +0 -3
  121. package/dist/webpack/plugin-css/css-tools/sass.d.ts +0 -4
  122. package/dist/webpack/plugin-css/css-tools/stylelint.d.ts +0 -4
  123. package/dist/webpack/plugin-css/css-tools/tailwind.d.ts +0 -2
  124. package/dist/webpack/plugin-css/index.d.ts +0 -9
  125. package/dist/webpack/plugin-css/is-content-script.d.ts +0 -1
  126. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/action.d.ts +0 -2
  127. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/background.d.ts +0 -2
  128. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/browser_action.d.ts +0 -2
  129. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/chrome_url_overrides.d.ts +0 -2
  130. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/devtools_page.d.ts +0 -2
  131. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/index.d.ts +0 -2
  132. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/options_ui.d.ts +0 -2
  133. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/page_action.d.ts +0 -2
  134. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/sandbox.d.ts +0 -2
  135. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/side_panel.d.ts +0 -2
  136. package/dist/webpack/plugin-extension/data/manifest-fields/html-fields/sidebar_action.d.ts +0 -2
  137. package/dist/webpack/plugin-extension/data/manifest-fields/icons-fields/action.d.ts +0 -2
  138. package/dist/webpack/plugin-extension/data/manifest-fields/icons-fields/browser_action.d.ts +0 -2
  139. package/dist/webpack/plugin-extension/data/manifest-fields/icons-fields/browser_action.theme_icons.d.ts +0 -2
  140. package/dist/webpack/plugin-extension/data/manifest-fields/icons-fields/icons.d.ts +0 -2
  141. package/dist/webpack/plugin-extension/data/manifest-fields/icons-fields/index.d.ts +0 -2
  142. package/dist/webpack/plugin-extension/data/manifest-fields/icons-fields/normalize.d.ts +0 -6
  143. package/dist/webpack/plugin-extension/data/manifest-fields/icons-fields/page_action.d.ts +0 -2
  144. package/dist/webpack/plugin-extension/data/manifest-fields/icons-fields/sidebar_action.d.ts +0 -2
  145. package/dist/webpack/plugin-extension/data/manifest-fields/index.d.ts +0 -19
  146. package/dist/webpack/plugin-extension/data/manifest-fields/json-fields/declarative_net_request.d.ts +0 -2
  147. package/dist/webpack/plugin-extension/data/manifest-fields/json-fields/index.d.ts +0 -2
  148. package/dist/webpack/plugin-extension/data/manifest-fields/json-fields/storage.d.ts +0 -2
  149. package/dist/webpack/plugin-extension/data/manifest-fields/locales-fields/index.d.ts +0 -1
  150. package/dist/webpack/plugin-extension/data/manifest-fields/normalize.d.ts +0 -10
  151. package/dist/webpack/plugin-extension/data/manifest-fields/scripts-fields/background.d.ts +0 -2
  152. package/dist/webpack/plugin-extension/data/manifest-fields/scripts-fields/content_scripts.d.ts +0 -2
  153. package/dist/webpack/plugin-extension/data/manifest-fields/scripts-fields/index.d.ts +0 -2
  154. package/dist/webpack/plugin-extension/data/manifest-fields/scripts-fields/service_worker.d.ts +0 -2
  155. package/dist/webpack/plugin-extension/data/manifest-fields/scripts-fields/user_scripts.d.ts +0 -2
  156. package/dist/webpack/plugin-extension/data/manifest-fields/web-resources-fields/index.d.ts +0 -2
  157. package/dist/webpack/plugin-extension/data/special-folders/generate-entries.d.ts +0 -4
  158. package/dist/webpack/plugin-extension/data/special-folders/index.d.ts +0 -12
  159. package/dist/webpack/plugin-extension/feature-html/__spec__/html-lib/test-utils.d.ts +0 -18
  160. package/dist/webpack/plugin-extension/feature-html/html-lib/parse-html.d.ts +0 -8
  161. package/dist/webpack/plugin-extension/feature-html/html-lib/patch-html.d.ts +0 -8
  162. package/dist/webpack/plugin-extension/feature-html/html-lib/utils.d.ts +0 -18
  163. package/dist/webpack/plugin-extension/feature-html/index.d.ts +0 -37
  164. package/dist/webpack/plugin-extension/feature-html/steps/add-assets-to-compilation.d.ts +0 -11
  165. package/dist/webpack/plugin-extension/feature-html/steps/add-scripts-and-styles-to-compilation.d.ts +0 -10
  166. package/dist/webpack/plugin-extension/feature-html/steps/add-to-file-dependencies.d.ts +0 -10
  167. package/dist/webpack/plugin-extension/feature-html/steps/emit-html-file.d.ts +0 -9
  168. package/dist/webpack/plugin-extension/feature-html/steps/ensure-hmr-for-scripts.d.ts +0 -2
  169. package/dist/webpack/plugin-extension/feature-html/steps/handle-common-errors.d.ts +0 -10
  170. package/dist/webpack/plugin-extension/feature-html/steps/minimum-script-file.d.ts +0 -1
  171. package/dist/webpack/plugin-extension/feature-html/steps/throw-if-recompile-is-needed.d.ts +0 -13
  172. package/dist/webpack/plugin-extension/feature-html/steps/update-html-file.d.ts +0 -10
  173. package/dist/webpack/plugin-extension/feature-icons/index.d.ts +0 -25
  174. package/dist/webpack/plugin-extension/feature-icons/steps/add-to-file-dependencies.d.ts +0 -9
  175. package/dist/webpack/plugin-extension/feature-icons/steps/emit-file.d.ts +0 -9
  176. package/dist/webpack/plugin-extension/feature-json/index.d.ts +0 -18
  177. package/dist/webpack/plugin-extension/feature-locales/get-locales.d.ts +0 -1
  178. package/dist/webpack/plugin-extension/feature-locales/index.d.ts +0 -13
  179. package/dist/webpack/plugin-extension/feature-manifest/index.d.ts +0 -23
  180. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/background.d.ts +0 -10
  181. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/chrome_url_overrides.d.ts +0 -8
  182. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/commands.d.ts +0 -16
  183. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/content_scripts.d.ts +0 -7
  184. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/content_security_policy.d.ts +0 -4
  185. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/devtools_page.d.ts +0 -4
  186. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/icons.d.ts +0 -6
  187. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/index.d.ts +0 -2
  188. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/omnibox.d.ts +0 -2
  189. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/options_page.d.ts +0 -4
  190. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/options_ui.d.ts +0 -8
  191. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/page_action.d.ts +0 -8
  192. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/permissions.d.ts +0 -4
  193. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/sandbox.d.ts +0 -7
  194. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/sidebar_action.d.ts +0 -2
  195. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/storage.d.ts +0 -6
  196. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/theme.d.ts +0 -2
  197. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/user_scripts.d.ts +0 -2
  198. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/common/web_accessible_resources.d.ts +0 -9
  199. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/index.d.ts +0 -2
  200. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/background.d.ts +0 -10
  201. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/browser_action.d.ts +0 -12
  202. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/chrome_settings_overrides.d.ts +0 -24
  203. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/index.d.ts +0 -2
  204. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/page_action.d.ts +0 -1
  205. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/sidebar_action.d.ts +0 -1
  206. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv2/theme_experiment.d.ts +0 -2
  207. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/action.d.ts +0 -8
  208. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/background.d.ts +0 -10
  209. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/declarative_net_request.d.ts +0 -2
  210. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/host_permissions.d.ts +0 -2
  211. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/index.d.ts +0 -2
  212. package/dist/webpack/plugin-extension/feature-manifest/manifest-overrides/mv3/side_panel.d.ts +0 -2
  213. package/dist/webpack/plugin-extension/feature-manifest/steps/add-dependencies.d.ts +0 -6
  214. package/dist/webpack/plugin-extension/feature-manifest/steps/check-manifest-files.d.ts +0 -17
  215. package/dist/webpack/plugin-extension/feature-manifest/steps/emit-manifest.d.ts +0 -7
  216. package/dist/webpack/plugin-extension/feature-manifest/steps/throw-if-recompile.d.ts +0 -11
  217. package/dist/webpack/plugin-extension/feature-manifest/steps/update-manifest.d.ts +0 -9
  218. package/dist/webpack/plugin-extension/feature-scripts/index.d.ts +0 -27
  219. package/dist/webpack/plugin-extension/feature-scripts/scripts-lib/utils.d.ts +0 -3
  220. package/dist/webpack/plugin-extension/feature-scripts/steps/add-content-script-wrapper.d.ts +0 -2
  221. package/dist/webpack/plugin-extension/feature-scripts/steps/add-hmr-accept-code.d.ts +0 -2
  222. package/dist/webpack/plugin-extension/feature-scripts/steps/add-public-path-for-main-world.d.ts +0 -11
  223. package/dist/webpack/plugin-extension/feature-scripts/steps/add-public-path-runtime-module.d.ts +0 -4
  224. package/dist/webpack/plugin-extension/feature-scripts/steps/add-scripts.d.ts +0 -9
  225. package/dist/webpack/plugin-extension/feature-scripts/steps/deprecated-shadow-root.d.ts +0 -2
  226. package/dist/webpack/plugin-extension/feature-scripts/steps/javascript-content-script-wrapper.d.ts +0 -1
  227. package/dist/webpack/plugin-extension/feature-scripts/steps/minimum-content-file.d.ts +0 -0
  228. package/dist/webpack/plugin-extension/feature-scripts/steps/preact-content-script-wrapper.d.ts +0 -1
  229. package/dist/webpack/plugin-extension/feature-scripts/steps/react-content-script-wrapper.d.ts +0 -1
  230. package/dist/webpack/plugin-extension/feature-scripts/steps/svelte-content-script-wrapper.d.ts +0 -1
  231. package/dist/webpack/plugin-extension/feature-scripts/steps/typescript-content-script-wrapper.d.ts +0 -1
  232. package/dist/webpack/plugin-extension/feature-scripts/steps/vue-content-script-wrapper.d.ts +0 -1
  233. package/dist/webpack/plugin-extension/feature-special-folders/copy-public-folder.d.ts +0 -14
  234. package/dist/webpack/plugin-extension/feature-special-folders/index.d.ts +0 -19
  235. package/dist/webpack/plugin-extension/feature-special-folders/warn-upon-folder-changes.d.ts +0 -7
  236. package/dist/webpack/plugin-extension/feature-web-resources/clean-matches.d.ts +0 -7
  237. package/dist/webpack/plugin-extension/feature-web-resources/index.d.ts +0 -18
  238. package/dist/webpack/plugin-extension/index.d.ts +0 -10
  239. package/dist/webpack/plugin-js-frameworks/index.d.ts +0 -13
  240. package/dist/webpack/plugin-js-frameworks/js-tools/babel.d.ts +0 -16
  241. package/dist/webpack/plugin-js-frameworks/js-tools/preact.d.ts +0 -3
  242. package/dist/webpack/plugin-js-frameworks/js-tools/react.d.ts +0 -3
  243. package/dist/webpack/plugin-js-frameworks/js-tools/svelte.d.ts +0 -3
  244. package/dist/webpack/plugin-js-frameworks/js-tools/typescript.d.ts +0 -36
  245. package/dist/webpack/plugin-js-frameworks/js-tools/vue.d.ts +0 -3
  246. package/dist/webpack/plugin-js-frameworks/load-loader-options.d.ts +0 -1
  247. package/dist/webpack/plugin-reload/index.d.ts +0 -13
  248. package/dist/webpack/plugin-reload/reload-lib/messages.d.ts +0 -106
  249. package/dist/webpack/plugin-reload/reload-types.d.ts +0 -14
  250. package/dist/webpack/plugin-reload/start-server.d.ts +0 -4
  251. package/dist/webpack/plugin-reload/steps/create-web-socket-server/index.d.ts +0 -14
  252. package/dist/webpack/plugin-reload/steps/create-web-socket-server/web-socket-server/broadcast-message.d.ts +0 -2
  253. package/dist/webpack/plugin-reload/steps/create-web-socket-server/web-socket-server/message-dispatcher.d.ts +0 -2
  254. package/dist/webpack/plugin-reload/steps/create-web-socket-server/web-socket-server/servers.d.ts +0 -2
  255. package/dist/webpack/plugin-reload/steps/setup-chromium-reload-client/index.d.ts +0 -3
  256. package/dist/webpack/plugin-reload/steps/setup-chromium-reload-client/inject-chromium-client-loader.d.ts +0 -9
  257. package/dist/webpack/plugin-reload/steps/setup-chromium-reload-client/minimum-chromium-file.d.ts +0 -0
  258. package/dist/webpack/plugin-reload/steps/setup-firefox-reload-client/index.d.ts +0 -3
  259. package/dist/webpack/plugin-reload/steps/setup-firefox-reload-client/inject-firefox-client-loader.d.ts +0 -9
  260. package/dist/webpack/plugin-reload/steps/setup-firefox-reload-client/minimum-firefox-file.d.ts +0 -0
  261. package/dist/webpack/plugin-reload/steps/setup-reload-strategy/apply-manifest-dev-defaults/index.d.ts +0 -9
  262. package/dist/webpack/plugin-reload/steps/setup-reload-strategy/apply-manifest-dev-defaults/patch-background.d.ts +0 -15
  263. package/dist/webpack/plugin-reload/steps/setup-reload-strategy/apply-manifest-dev-defaults/patch-csp.d.ts +0 -5
  264. package/dist/webpack/plugin-reload/steps/setup-reload-strategy/apply-manifest-dev-defaults/patch-externally-connectable.d.ts +0 -10
  265. package/dist/webpack/plugin-reload/steps/setup-reload-strategy/apply-manifest-dev-defaults/patch-web-resources.d.ts +0 -10
  266. package/dist/webpack/plugin-reload/steps/setup-reload-strategy/generate-manager-extension.d.ts +0 -15
  267. package/dist/webpack/plugin-reload/steps/setup-reload-strategy/index.d.ts +0 -10
  268. package/dist/webpack/plugin-reload/steps/setup-reload-strategy/target-web-extension-plugin/index.d.ts +0 -13
  269. package/dist/webpack/plugin-static-assets/index.d.ts +0 -12
  270. package/dist/webpack/webpack-config.d.ts +0 -14
  271. package/dist/webpack/webpack-lib/auto-exit.d.ts +0 -1
  272. package/dist/webpack/webpack-lib/constants.d.ts +0 -4
  273. package/dist/webpack/webpack-lib/messages.d.ts +0 -121
  274. package/dist/webpack/webpack-lib/port-manager.d.ts +0 -27
  275. package/dist/webpack/webpack-lib/utils.d.ts +0 -23
  276. package/dist/webpack/webpack-types.d.ts +0 -49
@@ -1,1789 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
9
- };
10
- })();
11
- (()=>{
12
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
- })();
14
- (()=>{
15
- __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
- value: 'Module'
18
- });
19
- Object.defineProperty(exports1, '__esModule', {
20
- value: true
21
- });
22
- };
23
- })();
24
- var __webpack_exports__ = {};
25
- __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- default: ()=>add_content_script_wrapper
28
- });
29
- const external_path_namespaceObject = require("path");
30
- const external_fs_namespaceObject = require("fs");
31
- const external_loader_utils_namespaceObject = require("loader-utils");
32
- const external_schema_utils_namespaceObject = require("schema-utils");
33
- function extractCSSImports(source) {
34
- const cssImports = [];
35
- const lines = source.split('\n');
36
- const cssImportPatterns = [
37
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]/,
38
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*;?\s*$/,
39
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*from\s+['"][^'"]*['"]/
40
- ];
41
- for (const line of lines){
42
- const trimmedLine = line.trim();
43
- if (!(trimmedLine.startsWith('//') || trimmedLine.startsWith('/*'))) for (const pattern of cssImportPatterns){
44
- const match = pattern.exec(line);
45
- if (match) {
46
- const cssPath = match[1];
47
- if (cssPath && !cssImports.includes(cssPath)) cssImports.push(cssPath);
48
- }
49
- }
50
- }
51
- return cssImports;
52
- }
53
- function generateReactWrapperCode(source, resourcePath) {
54
- external_path_namespaceObject.basename(resourcePath, external_path_namespaceObject.extname(resourcePath));
55
- const cssImports = extractCSSImports(source);
56
- const resourceDir = external_path_namespaceObject.dirname(resourcePath);
57
- if ('development' === process.env.EXTENSION_ENV) console.log("[Extension.js] Detected React framework with CSS imports:", cssImports);
58
- const cssContentMap = {};
59
- for (const cssImport of cssImports)try {
60
- const cssPath = external_path_namespaceObject.resolve(resourceDir, cssImport);
61
- if (external_fs_namespaceObject.existsSync(cssPath)) {
62
- const cssContent = external_fs_namespaceObject.readFileSync(cssPath, 'utf-8');
63
- const escapedCSS = cssContent.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\${/g, '\\${').replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
64
- cssContentMap[cssImport] = escapedCSS;
65
- if ('development' === process.env.EXTENSION_ENV) console.log(`[Extension.js] Read CSS content for ${cssImport}, length: ${cssContent.length}`);
66
- } else if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] CSS file not found: ${cssPath}`);
67
- } catch (error) {
68
- if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] Failed to read CSS file ${cssImport}:`, error);
69
- }
70
- const wrapperCode = `
71
- // React Content Script Wrapper - Auto-generated by Extension.js
72
- // This wrapper provides Shadow DOM isolation and CSS injection for React content scripts
73
-
74
- // Original React content script source (directive processed)
75
- ${source.replace(/'use shadow-dom'/g, "// 'use shadow-dom'").replace(/"use shadow-dom"/g, '// "use shadow-dom"')}
76
-
77
- // Content script options interface
78
- export interface ContentScriptOptions {
79
- rootElement?: string
80
- rootClassName?: string
81
- stylesheets?: string[]
82
- }
83
-
84
- // Content script instance interface
85
- export interface ContentScriptInstance {
86
- mount: (container: HTMLElement) => void
87
- unmount: () => void
88
- }
89
-
90
- // React Content script wrapper class
91
- class ReactContentScriptWrapper {
92
- private rootElement: HTMLElement | null = null
93
- private shadowRoot: ShadowRoot | null = null
94
- private styleElement: HTMLStyleElement | null = null
95
- private renderFunction: (container: HTMLElement) => (() => void) | void
96
- private unmountFunction: (() => void) | null = null
97
- private options: ContentScriptOptions
98
-
99
- constructor(renderFunction: (container: HTMLElement) => (() => void) | void, options: ContentScriptOptions = {}) {
100
- this.renderFunction = renderFunction
101
- this.options = {
102
- rootElement: 'extension-root',
103
- rootClassName: undefined, // React handles its own styling
104
- stylesheets: ${JSON.stringify(cssImports.length > 0 ? cssImports : [
105
- './styles.css'
106
- ])},
107
- ...options
108
- }
109
- }
110
-
111
- async mount(container?: HTMLElement): Promise<void> {
112
- console.log('[Extension.js] React wrapper mount called')
113
- if (this.rootElement) {
114
- this.unmount()
115
- }
116
-
117
- // Create root element - React handles its own container styling
118
- this.rootElement = container || document.createElement('div')
119
- this.rootElement.id = this.options.rootElement!
120
- if (this.options.rootClassName) {
121
- this.rootElement.className = this.options.rootClassName
122
- }
123
- // React component handles its own styling
124
-
125
- // Create shadow root for style isolation
126
- this.shadowRoot = this.rootElement.attachShadow({ mode: 'open' })
127
-
128
- // Create a host element inside the shadow root for rendering
129
- const host = document.createElement('div')
130
- this.shadowRoot.appendChild(host)
131
-
132
- // Inject styles FIRST
133
- console.log('[Extension.js] About to inject styles')
134
- await this.injectStyles()
135
-
136
- // Render React content
137
- console.log('[Extension.js] About to render React content')
138
- const result = this.renderFunction(host)
139
- if (typeof result === 'function') {
140
- this.unmountFunction = result
141
- }
142
-
143
- // Append to document if no container provided
144
- if (!container) {
145
- document.body.appendChild(this.rootElement)
146
- }
147
-
148
- console.log('[Extension.js] React wrapper mount complete')
149
- }
150
-
151
- unmount() {
152
- if (this.unmountFunction) {
153
- this.unmountFunction()
154
- this.unmountFunction = null
155
- }
156
-
157
- if (this.rootElement && this.rootElement.parentNode) {
158
- this.rootElement.parentNode.removeChild(this.rootElement)
159
- }
160
-
161
- this.rootElement = null
162
- this.shadowRoot = null
163
- this.styleElement = null
164
- }
165
-
166
- // Inject styles with hardcoded CSS content for React templates
167
- private async injectStyles(): Promise<void> {
168
- console.log('[Extension.js] React injectStyles called')
169
- const targetRoot = this.shadowRoot || this.rootElement!
170
-
171
- // Create style element
172
- this.styleElement = document.createElement('style')
173
- targetRoot.appendChild(this.styleElement)
174
-
175
- // Fetch CSS content
176
- try {
177
- console.log('[Extension.js] About to fetch CSS')
178
- const cssContent = await this.fetchCSS()
179
- console.log('[Extension.js] CSS fetched, length:', cssContent.length)
180
- this.styleElement.textContent = cssContent
181
- console.log('[Extension.js] React CSS injected successfully')
182
- } catch (error) {
183
- console.error('[Extension.js] Failed to inject React CSS:', error)
184
- }
185
-
186
- // Setup HMR for CSS files
187
- this.setupCSSHMR()
188
- }
189
-
190
- // Fetch CSS with hardcoded content for React templates
191
- private async fetchCSS(): Promise<string> {
192
- let allCSS = ''
193
-
194
- console.log('[Extension.js] Processing React stylesheets:', this.options.stylesheets)
195
-
196
- // CSS content map is injected at build time
197
- const cssContentMap: Record<string, string> = ${JSON.stringify(cssContentMap)}
198
-
199
- for (const stylesheet of this.options.stylesheets) {
200
- try {
201
- console.log('[Extension.js] Processing React stylesheet:', stylesheet)
202
- // Check if we have hardcoded content for this stylesheet
203
- if (cssContentMap[stylesheet]) {
204
- const cssContent = cssContentMap[stylesheet]
205
- allCSS += cssContent + '\n'
206
- console.log('[Extension.js] Successfully injected React', stylesheet, 'content')
207
- continue
208
- }
209
-
210
- // For stylesheets without hardcoded content, try to fetch them
211
- const cssUrl = new URL(stylesheet, import.meta.url)
212
- const response = await fetch(cssUrl)
213
- const text = await response.text()
214
- if (response.ok) {
215
- allCSS += text + '\n'
216
- console.log('[Extension.js] Successfully fetched stylesheet:', stylesheet)
217
- } else {
218
- console.warn('[Extension.js] Failed to fetch CSS:', stylesheet)
219
- }
220
- } catch (error) {
221
- console.warn('[Extension.js] Failed to fetch React CSS:', stylesheet, error)
222
- }
223
- }
224
-
225
- const result = allCSS || '/* No CSS loaded */'
226
- console.log('[Extension.js] Final CSS result length:', result.length)
227
- return result
228
- }
229
-
230
- // Setup CSS HMR for React templates
231
- private setupCSSHMR() {
232
- if (!import.meta.webpackHot) return
233
-
234
- // Setup HMR for each CSS file
235
- for (const stylesheet of this.options.stylesheets) {
236
- import.meta.webpackHot?.accept(stylesheet, async () => {
237
- try {
238
- const cssContent = await this.fetchCSS()
239
- if (this.styleElement) {
240
- this.styleElement.textContent = cssContent
241
- console.log('[Extension.js] React CSS updated via HMR:', stylesheet)
242
- }
243
- } catch (error) {
244
- console.error('[Extension.js] Failed to update React CSS via HMR:', stylesheet, error)
245
- }
246
- })
247
- }
248
- }
249
- }
250
-
251
- // Initialize React content script with wrapper
252
- function initializeReactContentScript(
253
- options: ContentScriptOptions,
254
- renderFunction: (container: HTMLElement) => (() => void) | void
255
- ): ContentScriptInstance {
256
- const wrapper = new ReactContentScriptWrapper(renderFunction, options)
257
-
258
- return {
259
- mount: (container?: HTMLElement) => wrapper.mount(container),
260
- unmount: () => wrapper.unmount()
261
- }
262
- }
263
-
264
- // Auto-initialize the React content script with the wrapper
265
- export function autoInitializeReactContentScript(
266
- options: ContentScriptOptions = {}
267
- ): ContentScriptInstance {
268
- // Get the render function from the imported contentScript
269
- const renderFunction = contentScript(options)
270
-
271
- // Initialize with the wrapper using the detected CSS imports
272
- return initializeReactContentScript(options, renderFunction)
273
- }
274
-
275
- // Simple initialization for React
276
- let unmount: (() => void) | undefined
277
-
278
- async function initialize() {
279
- console.log('[Extension.js] React wrapper initialize called')
280
- if (unmount) {
281
- console.log('[Extension.js] Unmounting previous React instance')
282
- unmount()
283
- }
284
-
285
- // Get the render function from the contentScript function
286
- const renderFunction = contentScript({})
287
- const wrapper = new ReactContentScriptWrapper(renderFunction, {})
288
- await wrapper.mount()
289
- unmount = () => wrapper.unmount()
290
- console.log('[Extension.js] React wrapper initialization complete')
291
- }
292
-
293
- if (import.meta.webpackHot) {
294
- import.meta.webpackHot?.accept()
295
- import.meta.webpackHot?.dispose(() => unmount?.())
296
-
297
- // Accept changes to this file
298
- import.meta.webpackHot?.accept(() => {
299
- initialize()
300
- })
301
- }
302
-
303
- if (document.readyState === 'complete') {
304
- initialize()
305
- } else {
306
- document.addEventListener('readystatechange', () => {
307
- if (document.readyState === 'complete') {
308
- initialize()
309
- }
310
- })
311
- }
312
-
313
- export default ReactContentScriptWrapper
314
- `;
315
- return wrapperCode;
316
- }
317
- function vue_content_script_wrapper_extractCSSImports(source) {
318
- const cssImports = [];
319
- const lines = source.split('\n');
320
- const cssImportPatterns = [
321
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]/,
322
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*;?\s*$/,
323
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*from\s+['"][^'"]*['"]/
324
- ];
325
- for (const line of lines){
326
- const trimmedLine = line.trim();
327
- if (!(trimmedLine.startsWith('//') || trimmedLine.startsWith('/*'))) for (const pattern of cssImportPatterns){
328
- const match = pattern.exec(line);
329
- if (match) {
330
- const cssPath = match[1];
331
- if (cssPath && !cssImports.includes(cssPath)) cssImports.push(cssPath);
332
- }
333
- }
334
- }
335
- return cssImports;
336
- }
337
- function generateVueWrapperCode(source, resourcePath) {
338
- external_path_namespaceObject.basename(resourcePath, external_path_namespaceObject.extname(resourcePath));
339
- const cssImports = vue_content_script_wrapper_extractCSSImports(source);
340
- const resourceDir = external_path_namespaceObject.dirname(resourcePath);
341
- if ('development' === process.env.EXTENSION_ENV) console.log("[Extension.js] Detected Vue framework with CSS imports:", cssImports);
342
- const cssContentMap = {};
343
- for (const cssImport of cssImports)try {
344
- const cssPath = external_path_namespaceObject.resolve(resourceDir, cssImport);
345
- if (external_fs_namespaceObject.existsSync(cssPath)) {
346
- const cssContent = external_fs_namespaceObject.readFileSync(cssPath, 'utf-8');
347
- const escapedCSS = cssContent.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\${/g, '\\${').replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
348
- cssContentMap[cssImport] = escapedCSS;
349
- if ('development' === process.env.EXTENSION_ENV) console.log(`[Extension.js] Read CSS content for ${cssImport}, length: ${cssContent.length}`);
350
- } else if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] CSS file not found: ${cssPath}`);
351
- } catch (error) {
352
- if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] Failed to read CSS file ${cssImport}:`, error);
353
- }
354
- const wrapperCode = `
355
- // Vue Content Script Wrapper - Auto-generated by Extension.js
356
- // This wrapper provides Shadow DOM isolation and CSS injection for Vue content scripts
357
-
358
- // Original Vue content script source (directive processed)
359
- ${source.replace(/'use shadow-dom'/g, "// 'use shadow-dom'").replace(/"use shadow-dom"/g, '// "use shadow-dom"')}
360
-
361
- // Content script options interface
362
- export interface ContentScriptOptions {
363
- rootElement?: string
364
- rootClassName?: string
365
- stylesheets?: string[]
366
- }
367
-
368
- // Content script instance interface
369
- export interface ContentScriptInstance {
370
- mount: (container: HTMLElement) => void
371
- unmount: () => void
372
- }
373
-
374
- // Vue Content script wrapper class
375
- class VueContentScriptWrapper {
376
- private rootElement: HTMLElement | null = null
377
- private shadowRoot: ShadowRoot | null = null
378
- private styleElement: HTMLStyleElement | null = null
379
- private renderFunction: (container: HTMLElement) => (() => void) | void
380
- private unmountFunction: (() => void) | null = null
381
- private options: ContentScriptOptions
382
-
383
- constructor(renderFunction: (container: HTMLElement) => (() => void) | void, options: ContentScriptOptions = {}) {
384
- this.renderFunction = renderFunction
385
- this.options = {
386
- rootElement: 'extension-root',
387
- rootClassName: undefined, // Vue handles its own styling
388
- stylesheets: ${JSON.stringify(cssImports.length > 0 ? cssImports : [
389
- './styles.css'
390
- ])},
391
- ...options
392
- }
393
- }
394
-
395
- async mount(container?: HTMLElement): Promise<void> {
396
- console.log('[Extension.js] Vue wrapper mount called')
397
- if (this.rootElement) {
398
- this.unmount()
399
- }
400
-
401
- // Create root element - Vue handles its own container styling
402
- this.rootElement = container || document.createElement('div')
403
- this.rootElement.id = this.options.rootElement!
404
- if (this.options.rootClassName) {
405
- this.rootElement.className = this.options.rootClassName
406
- }
407
- // Vue component handles its own styling
408
-
409
- // Create shadow root for style isolation
410
- this.shadowRoot = this.rootElement.attachShadow({ mode: 'open' })
411
-
412
- // Create a host element inside the shadow root for rendering
413
- const host = document.createElement('div')
414
- this.shadowRoot.appendChild(host)
415
-
416
- // Inject styles FIRST
417
- console.log('[Extension.js] About to inject styles')
418
- await this.injectStyles()
419
-
420
- // Render Vue content
421
- console.log('[Extension.js] About to render Vue content')
422
- const result = this.renderFunction(host)
423
- if (typeof result === 'function') {
424
- this.unmountFunction = result
425
- }
426
-
427
- // Append to document if no container provided
428
- if (!container) {
429
- document.body.appendChild(this.rootElement)
430
- }
431
-
432
- console.log('[Extension.js] Vue wrapper mount complete')
433
- }
434
-
435
- unmount() {
436
- if (this.unmountFunction) {
437
- this.unmountFunction()
438
- this.unmountFunction = null
439
- }
440
-
441
- if (this.rootElement && this.rootElement.parentNode) {
442
- this.rootElement.parentNode.removeChild(this.rootElement)
443
- }
444
-
445
- this.rootElement = null
446
- this.shadowRoot = null
447
- this.styleElement = null
448
- }
449
-
450
- // Inject styles with hardcoded CSS content for Vue templates
451
- private async injectStyles(): Promise<void> {
452
- console.log('[Extension.js] Vue injectStyles called')
453
- const targetRoot = this.shadowRoot || this.rootElement!
454
-
455
- // Create style element
456
- this.styleElement = document.createElement('style')
457
- targetRoot.appendChild(this.styleElement)
458
-
459
- // Fetch CSS content
460
- try {
461
- console.log('[Extension.js] About to fetch CSS')
462
- const cssContent = await this.fetchCSS()
463
- console.log('[Extension.js] CSS fetched, length:', cssContent.length)
464
- this.styleElement.textContent = cssContent
465
- console.log('[Extension.js] Vue CSS injected successfully')
466
- } catch (error) {
467
- console.error('[Extension.js] Failed to inject Vue CSS:', error)
468
- }
469
-
470
- // Setup HMR for CSS files
471
- this.setupCSSHMR()
472
- }
473
-
474
- // Fetch CSS with hardcoded content for Vue templates
475
- private async fetchCSS(): Promise<string> {
476
- let allCSS = ''
477
-
478
- console.log('[Extension.js] Processing Vue stylesheets:', this.options.stylesheets)
479
-
480
- // CSS content map is injected at build time
481
- const cssContentMap: Record<string, string> = ${JSON.stringify(cssContentMap)}
482
-
483
- for (const stylesheet of this.options.stylesheets) {
484
- try {
485
- console.log('[Extension.js] Processing Vue stylesheet:', stylesheet)
486
- // Check if we have hardcoded content for this stylesheet
487
- if (cssContentMap[stylesheet]) {
488
- const cssContent = cssContentMap[stylesheet]
489
- allCSS += cssContent + '\n'
490
- console.log('[Extension.js] Successfully injected Vue', stylesheet, 'content')
491
- continue
492
- }
493
-
494
- // For stylesheets without hardcoded content, try to fetch them
495
- const cssUrl = new URL(stylesheet, import.meta.url)
496
- const response = await fetch(cssUrl)
497
- const text = await response.text()
498
- if (response.ok) {
499
- allCSS += text + '\n'
500
- console.log('[Extension.js] Successfully fetched stylesheet:', stylesheet)
501
- } else {
502
- console.warn('[Extension.js] Failed to fetch CSS:', stylesheet)
503
- }
504
- } catch (error) {
505
- console.warn('[Extension.js] Failed to fetch Vue CSS:', stylesheet, error)
506
- }
507
- }
508
-
509
- return allCSS
510
- }
511
-
512
- // Setup CSS HMR for Vue templates
513
- private setupCSSHMR() {
514
- if (!import.meta.webpackHot) return
515
-
516
- // Setup HMR for each CSS file
517
- for (const stylesheet of this.options.stylesheets) {
518
- import.meta.webpackHot?.accept(stylesheet, async () => {
519
- try {
520
- const cssContent = await this.fetchCSS()
521
- if (this.styleElement) {
522
- this.styleElement.textContent = cssContent
523
- console.log('[Extension.js] Vue CSS updated via HMR:', stylesheet)
524
- }
525
- } catch (error) {
526
- console.error('[Extension.js] Failed to update Vue CSS via HMR:', stylesheet, error)
527
- }
528
- })
529
- }
530
- }
531
- }
532
-
533
- // Initialize Vue content script with wrapper
534
- function initializeVueContentScript(
535
- options: ContentScriptOptions,
536
- renderFunction: (container: HTMLElement) => (() => void) | void
537
- ): ContentScriptInstance {
538
- const wrapper = new VueContentScriptWrapper(renderFunction, options)
539
-
540
- return {
541
- mount: (container?: HTMLElement) => wrapper.mount(container),
542
- unmount: () => wrapper.unmount()
543
- }
544
- }
545
-
546
- // Auto-initialize the Vue content script with the wrapper
547
- export function autoInitializeVueContentScript(
548
- options: ContentScriptOptions = {}
549
- ): ContentScriptInstance {
550
- // Get the render function from the imported contentScript
551
- const renderFunction = contentScript(options)
552
-
553
- // Initialize with the wrapper using the detected CSS imports
554
- return initializeVueContentScript(options, renderFunction)
555
- }
556
-
557
- // Simple initialization for Vue
558
- let unmount: (() => void) | undefined
559
-
560
- async function initialize() {
561
- console.log('[Extension.js] Vue wrapper initialize called')
562
- if (unmount) {
563
- console.log('[Extension.js] Unmounting previous Vue instance')
564
- unmount()
565
- }
566
-
567
- // Get the render function from the contentScript function
568
- const renderFunction = contentScript({})
569
- const wrapper = new VueContentScriptWrapper(renderFunction, {})
570
- await wrapper.mount()
571
- unmount = () => wrapper.unmount()
572
- console.log('[Extension.js] Vue wrapper initialization complete')
573
- }
574
-
575
- if (import.meta.webpackHot) {
576
- import.meta.webpackHot?.accept()
577
- import.meta.webpackHot?.dispose(() => unmount?.())
578
-
579
- // Accept changes to this file
580
- import.meta.webpackHot?.accept(() => {
581
- initialize()
582
- })
583
- }
584
-
585
- if (document.readyState === 'complete') {
586
- initialize()
587
- } else {
588
- document.addEventListener('readystatechange', () => {
589
- if (document.readyState === 'complete') {
590
- initialize()
591
- }
592
- })
593
- }
594
-
595
- export default VueContentScriptWrapper
596
- `;
597
- return wrapperCode;
598
- }
599
- function svelte_content_script_wrapper_extractCSSImports(source) {
600
- const cssImports = [];
601
- const lines = source.split('\n');
602
- const cssImportPatterns = [
603
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]/,
604
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*;?\s*$/,
605
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*from\s+['"][^'"]*['"]/
606
- ];
607
- for (const line of lines){
608
- const trimmedLine = line.trim();
609
- if (!(trimmedLine.startsWith('//') || trimmedLine.startsWith('/*'))) for (const pattern of cssImportPatterns){
610
- const match = pattern.exec(line);
611
- if (match) {
612
- const cssPath = match[1];
613
- if (cssPath && !cssImports.includes(cssPath)) cssImports.push(cssPath);
614
- }
615
- }
616
- }
617
- return cssImports;
618
- }
619
- function generateSvelteWrapperCode(source, resourcePath) {
620
- external_path_namespaceObject.basename(resourcePath, external_path_namespaceObject.extname(resourcePath));
621
- const cssImports = svelte_content_script_wrapper_extractCSSImports(source);
622
- const resourceDir = external_path_namespaceObject.dirname(resourcePath);
623
- if ('development' === process.env.EXTENSION_ENV) console.log("[Extension.js] Detected Svelte framework with CSS imports:", cssImports);
624
- const cssContentMap = {};
625
- for (const cssImport of cssImports)try {
626
- const cssPath = external_path_namespaceObject.resolve(resourceDir, cssImport);
627
- if (external_fs_namespaceObject.existsSync(cssPath)) {
628
- const cssContent = external_fs_namespaceObject.readFileSync(cssPath, 'utf-8');
629
- const escapedCSS = cssContent.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\${/g, '\\${').replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
630
- cssContentMap[cssImport] = escapedCSS;
631
- if ('development' === process.env.EXTENSION_ENV) console.log(`[Extension.js] Read CSS content for ${cssImport}, length: ${cssContent.length}`);
632
- } else if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] CSS file not found: ${cssPath}`);
633
- } catch (error) {
634
- if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] Failed to read CSS file ${cssImport}:`, error);
635
- }
636
- const wrapperCode = `
637
- // Svelte Content Script Wrapper - Auto-generated by Extension.js
638
- // This wrapper provides Shadow DOM isolation and CSS injection for Svelte content scripts
639
-
640
- // Original Svelte content script source (directive processed)
641
- ${source.replace(/'use shadow-dom'/g, "// 'use shadow-dom'").replace(/"use shadow-dom"/g, '// "use shadow-dom"')}
642
-
643
- // Content script options interface
644
- export interface ContentScriptOptions {
645
- rootElement?: string
646
- rootClassName?: string
647
- stylesheets?: string[]
648
- }
649
-
650
- // Content script instance interface
651
- export interface ContentScriptInstance {
652
- mount: (container: HTMLElement) => void
653
- unmount: () => void
654
- }
655
-
656
- // Svelte Content script wrapper class
657
- class SvelteContentScriptWrapper {
658
- private rootElement: HTMLElement | null = null
659
- private shadowRoot: ShadowRoot | null = null
660
- private styleElement: HTMLStyleElement | null = null
661
- private renderFunction: (container: HTMLElement) => (() => void) | void
662
- private unmountFunction: (() => void) | null = null
663
- private options: ContentScriptOptions
664
-
665
- constructor(renderFunction: (container: HTMLElement) => (() => void) | void, options: ContentScriptOptions = {}) {
666
- this.renderFunction = renderFunction
667
- this.options = {
668
- rootElement: 'extension-root',
669
- rootClassName: undefined, // Svelte handles its own styling
670
- stylesheets: ${JSON.stringify(cssImports.length > 0 ? cssImports : [
671
- './styles.css'
672
- ])},
673
- ...options
674
- }
675
- }
676
-
677
- async mount(container?: HTMLElement): Promise<void> {
678
- console.log('[Extension.js] Svelte wrapper mount called')
679
- if (this.rootElement) {
680
- this.unmount()
681
- }
682
-
683
- // Create root element - Svelte handles its own container styling
684
- this.rootElement = container || document.createElement('div')
685
- this.rootElement.id = this.options.rootElement!
686
- if (this.options.rootClassName) {
687
- this.rootElement.className = this.options.rootClassName
688
- }
689
- // Svelte component handles its own styling
690
-
691
- // Create shadow root for style isolation
692
- this.shadowRoot = this.rootElement.attachShadow({ mode: 'open' })
693
-
694
- // Create a host element inside the shadow root for rendering
695
- const host = document.createElement('div')
696
- this.shadowRoot.appendChild(host)
697
-
698
- // Inject styles FIRST
699
- console.log('[Extension.js] About to inject styles')
700
- await this.injectStyles()
701
-
702
- // Render Svelte content
703
- console.log('[Extension.js] About to render Svelte content')
704
- const result = this.renderFunction(host)
705
- if (typeof result === 'function') {
706
- this.unmountFunction = result
707
- }
708
-
709
- // Append to document if no container provided
710
- if (!container) {
711
- document.body.appendChild(this.rootElement)
712
- }
713
-
714
- console.log('[Extension.js] Svelte wrapper mount complete')
715
- }
716
-
717
- unmount() {
718
- if (this.unmountFunction) {
719
- this.unmountFunction()
720
- this.unmountFunction = null
721
- }
722
-
723
- if (this.rootElement && this.rootElement.parentNode) {
724
- this.rootElement.parentNode.removeChild(this.rootElement)
725
- }
726
-
727
- this.rootElement = null
728
- this.shadowRoot = null
729
- this.styleElement = null
730
- }
731
-
732
- // Inject styles with hardcoded CSS content for Svelte templates
733
- private async injectStyles(): Promise<void> {
734
- console.log('[Extension.js] Svelte injectStyles called')
735
- const targetRoot = this.shadowRoot || this.rootElement!
736
-
737
- // Create style element
738
- this.styleElement = document.createElement('style')
739
- targetRoot.appendChild(this.styleElement)
740
-
741
- // Fetch CSS content
742
- try {
743
- console.log('[Extension.js] About to fetch CSS')
744
- const cssContent = await this.fetchCSS()
745
- console.log('[Extension.js] CSS fetched, length:', cssContent.length)
746
- this.styleElement.textContent = cssContent
747
- console.log('[Extension.js] Svelte CSS injected successfully')
748
- } catch (error) {
749
- console.error('[Extension.js] Failed to inject Svelte CSS:', error)
750
- }
751
-
752
- // Setup HMR for CSS files
753
- this.setupCSSHMR()
754
- }
755
-
756
- // Fetch CSS with hardcoded content for Svelte templates
757
- private async fetchCSS(): Promise<string> {
758
- let allCSS = ''
759
-
760
- console.log('[Extension.js] Processing Svelte stylesheets:', this.options.stylesheets)
761
-
762
- // CSS content map is injected at build time
763
- const cssContentMap: Record<string, string> = ${JSON.stringify(cssContentMap)}
764
-
765
- for (const stylesheet of this.options.stylesheets) {
766
- try {
767
- console.log('[Extension.js] Processing Svelte stylesheet:', stylesheet)
768
- // Check if we have hardcoded content for this stylesheet
769
- if (cssContentMap[stylesheet]) {
770
- const cssContent = cssContentMap[stylesheet]
771
- allCSS += cssContent + '\n'
772
- console.log('[Extension.js] Successfully injected Svelte', stylesheet, 'content')
773
- continue
774
- }
775
-
776
- // For stylesheets without hardcoded content, try to fetch them
777
- const cssUrl = new URL(stylesheet, import.meta.url)
778
- const response = await fetch(cssUrl)
779
- const text = await response.text()
780
- if (response.ok) {
781
- allCSS += text + '\n'
782
- console.log('[Extension.js] Successfully fetched stylesheet:', stylesheet)
783
- } else {
784
- console.warn('[Extension.js] Failed to fetch CSS:', stylesheet)
785
- }
786
- } catch (error) {
787
- console.warn('[Extension.js] Failed to fetch Svelte CSS:', stylesheet, error)
788
- }
789
- }
790
-
791
- return allCSS
792
- }
793
-
794
- // Setup CSS HMR for Svelte templates
795
- private setupCSSHMR() {
796
- if (!import.meta.webpackHot) return
797
-
798
- // Setup HMR for each CSS file
799
- for (const stylesheet of this.options.stylesheets) {
800
- import.meta.webpackHot?.accept(stylesheet, async () => {
801
- try {
802
- const cssContent = await this.fetchCSS()
803
- if (this.styleElement) {
804
- this.styleElement.textContent = cssContent
805
- console.log('[Extension.js] Svelte CSS updated via HMR:', stylesheet)
806
- }
807
- } catch (error) {
808
- console.error('[Extension.js] Failed to update Svelte CSS via HMR:', stylesheet, error)
809
- }
810
- })
811
- }
812
- }
813
- }
814
-
815
- // Initialize Svelte content script with wrapper
816
- function initializeSvelteContentScript(
817
- options: ContentScriptOptions,
818
- renderFunction: (container: HTMLElement) => (() => void) | void
819
- ): ContentScriptInstance {
820
- const wrapper = new SvelteContentScriptWrapper(renderFunction, options)
821
-
822
- return {
823
- mount: (container?: HTMLElement) => wrapper.mount(container),
824
- unmount: () => wrapper.unmount()
825
- }
826
- }
827
-
828
- // Auto-initialize the Svelte content script with the wrapper
829
- export function autoInitializeSvelteContentScript(
830
- options: ContentScriptOptions = {}
831
- ): ContentScriptInstance {
832
- // Get the render function from the imported contentScript
833
- const renderFunction = contentScript(options)
834
-
835
- // Initialize with the wrapper using the detected CSS imports
836
- return initializeSvelteContentScript(options, renderFunction)
837
- }
838
-
839
- // Simple initialization for Svelte
840
- let unmount: (() => void) | undefined
841
-
842
- async function initialize() {
843
- console.log('[Extension.js] Svelte wrapper initialize called')
844
- if (unmount) {
845
- console.log('[Extension.js] Unmounting previous Svelte instance')
846
- unmount()
847
- }
848
-
849
- // Get the render function from the contentScript function
850
- const renderFunction = contentScript({})
851
- const wrapper = new SvelteContentScriptWrapper(renderFunction, {})
852
- await wrapper.mount()
853
- unmount = () => wrapper.unmount()
854
- console.log('[Extension.js] Svelte wrapper initialization complete')
855
- }
856
-
857
- if (import.meta.webpackHot) {
858
- import.meta.webpackHot?.accept()
859
- import.meta.webpackHot?.dispose(() => unmount?.())
860
-
861
- // Accept changes to this file
862
- import.meta.webpackHot?.accept(() => {
863
- initialize()
864
- })
865
- }
866
-
867
- if (document.readyState === 'complete') {
868
- initialize()
869
- } else {
870
- document.addEventListener('readystatechange', () => {
871
- if (document.readyState === 'complete') {
872
- initialize()
873
- }
874
- })
875
- }
876
-
877
- export default SvelteContentScriptWrapper
878
- `;
879
- return wrapperCode;
880
- }
881
- function preact_content_script_wrapper_extractCSSImports(source) {
882
- const cssImports = [];
883
- const lines = source.split('\n');
884
- const cssImportPatterns = [
885
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]/,
886
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*;?\s*$/,
887
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*from\s+['"][^'"]*['"]/
888
- ];
889
- for (const line of lines){
890
- const trimmedLine = line.trim();
891
- if (!(trimmedLine.startsWith('//') || trimmedLine.startsWith('/*'))) for (const pattern of cssImportPatterns){
892
- const match = pattern.exec(line);
893
- if (match) {
894
- const cssPath = match[1];
895
- if (cssPath && !cssImports.includes(cssPath)) cssImports.push(cssPath);
896
- }
897
- }
898
- }
899
- return cssImports;
900
- }
901
- function generatePreactWrapperCode(source, resourcePath) {
902
- external_path_namespaceObject.basename(resourcePath, external_path_namespaceObject.extname(resourcePath));
903
- const cssImports = preact_content_script_wrapper_extractCSSImports(source);
904
- const resourceDir = external_path_namespaceObject.dirname(resourcePath);
905
- if ('development' === process.env.EXTENSION_ENV) console.log("[Extension.js] Detected Preact framework with CSS imports:", cssImports);
906
- const cssContentMap = {};
907
- for (const cssImport of cssImports)try {
908
- const cssPath = external_path_namespaceObject.resolve(resourceDir, cssImport);
909
- if (external_fs_namespaceObject.existsSync(cssPath)) {
910
- const cssContent = external_fs_namespaceObject.readFileSync(cssPath, 'utf-8');
911
- const escapedCSS = cssContent.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\${/g, '\\${').replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
912
- cssContentMap[cssImport] = escapedCSS;
913
- if ('development' === process.env.EXTENSION_ENV) console.log(`[Extension.js] Read CSS content for ${cssImport}, length: ${cssContent.length}`);
914
- } else if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] CSS file not found: ${cssPath}`);
915
- } catch (error) {
916
- if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] Failed to read CSS file ${cssImport}:`, error);
917
- }
918
- const wrapperCode = `
919
- // Preact Content Script Wrapper - Auto-generated by Extension.js
920
- // This wrapper provides Shadow DOM isolation and CSS injection for Preact content scripts
921
-
922
- // Original Preact content script source (directive processed)
923
- ${source.replace(/'use shadow-dom'/g, "// 'use shadow-dom'").replace(/"use shadow-dom"/g, '// "use shadow-dom"')}
924
-
925
- // Content script options interface
926
- export interface ContentScriptOptions {
927
- rootElement?: string
928
- rootClassName?: string
929
- stylesheets?: string[]
930
- }
931
-
932
- // Content script instance interface
933
- export interface ContentScriptInstance {
934
- mount: (container: HTMLElement) => void
935
- unmount: () => void
936
- }
937
-
938
- // Preact Content script wrapper class
939
- class PreactContentScriptWrapper {
940
- private rootElement: HTMLElement | null = null
941
- private shadowRoot: ShadowRoot | null = null
942
- private styleElement: HTMLStyleElement | null = null
943
- private renderFunction: (container: HTMLElement) => (() => void) | void
944
- private unmountFunction: (() => void) | null = null
945
- private options: ContentScriptOptions
946
-
947
- constructor(renderFunction: (container: HTMLElement) => (() => void) | void, options: ContentScriptOptions = {}) {
948
- this.renderFunction = renderFunction
949
- this.options = {
950
- rootElement: 'extension-root',
951
- rootClassName: undefined, // Preact handles its own styling
952
- stylesheets: ${JSON.stringify(cssImports.length > 0 ? cssImports : [
953
- './styles.css'
954
- ])},
955
- ...options
956
- }
957
- }
958
-
959
- async mount(container?: HTMLElement): Promise<void> {
960
- console.log('[Extension.js] Preact wrapper mount called')
961
- if (this.rootElement) {
962
- this.unmount()
963
- }
964
-
965
- // Create root element - Preact handles its own container styling
966
- this.rootElement = container || document.createElement('div')
967
- this.rootElement.id = this.options.rootElement!
968
- if (this.options.rootClassName) {
969
- this.rootElement.className = this.options.rootClassName
970
- }
971
- // Preact component handles its own styling
972
-
973
- // Create shadow root for style isolation
974
- this.shadowRoot = this.rootElement.attachShadow({ mode: 'open' })
975
-
976
- // Inject styles FIRST
977
- console.log('[Extension.js] About to inject styles')
978
- await this.injectStyles()
979
-
980
- // Render Preact content
981
- console.log('[Extension.js] About to render Preact content')
982
- const result = this.renderFunction(this.shadowRoot as any)
983
- if (typeof result === 'function') {
984
- this.unmountFunction = result
985
- }
986
-
987
- // Append to document if no container provided
988
- if (!container) {
989
- document.body.appendChild(this.rootElement)
990
- }
991
-
992
- console.log('[Extension.js] Preact wrapper mount complete')
993
- }
994
-
995
- unmount() {
996
- if (this.unmountFunction) {
997
- this.unmountFunction()
998
- this.unmountFunction = null
999
- }
1000
-
1001
- if (this.rootElement && this.rootElement.parentNode) {
1002
- this.rootElement.parentNode.removeChild(this.rootElement)
1003
- }
1004
-
1005
- this.rootElement = null
1006
- this.shadowRoot = null
1007
- this.styleElement = null
1008
- }
1009
-
1010
- // Inject styles with hardcoded CSS content for Preact templates
1011
- private async injectStyles(): Promise<void> {
1012
- console.log('[Extension.js] Preact injectStyles called')
1013
- const targetRoot = this.shadowRoot || this.rootElement!
1014
-
1015
- // Create style element
1016
- this.styleElement = document.createElement('style')
1017
- targetRoot.appendChild(this.styleElement)
1018
-
1019
- // Fetch CSS content
1020
- try {
1021
- console.log('[Extension.js] About to fetch CSS')
1022
- const cssContent = await this.fetchCSS()
1023
- console.log('[Extension.js] CSS fetched, length:', cssContent.length)
1024
- this.styleElement.textContent = cssContent
1025
- console.log('[Extension.js] Preact CSS injected successfully')
1026
- } catch (error) {
1027
- console.error('[Extension.js] Failed to inject Preact CSS:', error)
1028
- }
1029
-
1030
- // Setup HMR for CSS files
1031
- this.setupCSSHMR()
1032
- }
1033
-
1034
- // Fetch CSS with hardcoded content for Preact templates
1035
- private async fetchCSS(): Promise<string> {
1036
- let allCSS = ''
1037
-
1038
- console.log('[Extension.js] Processing Preact stylesheets:', this.options.stylesheets)
1039
-
1040
- // CSS content map is injected at build time
1041
- const cssContentMap: Record<string, string> = ${JSON.stringify(cssContentMap)}
1042
-
1043
- for (const stylesheet of this.options.stylesheets) {
1044
- try {
1045
- console.log('[Extension.js] Processing Preact stylesheet:', stylesheet)
1046
- // Check if we have hardcoded content for this stylesheet
1047
- if (cssContentMap[stylesheet]) {
1048
- const cssContent = cssContentMap[stylesheet]
1049
- allCSS += cssContent + '\\n'
1050
- console.log(\`[Extension.js] Successfully injected Preact \${stylesheet} content\`)
1051
- continue
1052
- }
1053
-
1054
- // For stylesheets without hardcoded content, try to fetch them
1055
- const cssUrl = new URL(stylesheet, import.meta.url)
1056
- const response = await fetch(cssUrl)
1057
- const text = await response.text()
1058
- if (response.ok) {
1059
- allCSS += text + '\\n'
1060
- console.log('[Extension.js] Successfully fetched stylesheet:', stylesheet)
1061
- } else {
1062
- console.warn('[Extension.js] Failed to fetch CSS:', stylesheet)
1063
- }
1064
- } catch (error) {
1065
- console.warn('[Extension.js] Failed to fetch Preact CSS:', stylesheet, error)
1066
- }
1067
- }
1068
-
1069
- return allCSS
1070
- }
1071
-
1072
- // Setup CSS HMR for Preact templates
1073
- private setupCSSHMR() {
1074
- if (!import.meta.webpackHot) return
1075
-
1076
- // Setup HMR for each CSS file
1077
- for (const stylesheet of this.options.stylesheets) {
1078
- import.meta.webpackHot?.accept(stylesheet, async () => {
1079
- try {
1080
- const cssContent = await this.fetchCSS()
1081
- if (this.styleElement) {
1082
- this.styleElement.textContent = cssContent
1083
- console.log('[Extension.js] Preact CSS updated via HMR:', stylesheet)
1084
- }
1085
- } catch (error) {
1086
- console.error('[Extension.js] Failed to update Preact CSS via HMR:', stylesheet, error)
1087
- }
1088
- })
1089
- }
1090
- }
1091
- }
1092
-
1093
- // Initialize Preact content script with wrapper
1094
- function initializePreactContentScript(
1095
- options: ContentScriptOptions,
1096
- renderFunction: (container: HTMLElement) => (() => void) | void
1097
- ): ContentScriptInstance {
1098
- const wrapper = new PreactContentScriptWrapper(renderFunction, options)
1099
-
1100
- return {
1101
- mount: (container?: HTMLElement) => wrapper.mount(container),
1102
- unmount: () => wrapper.unmount()
1103
- }
1104
- }
1105
-
1106
- // Auto-initialize the Preact content script with the wrapper
1107
- export function autoInitializePreactContentScript(
1108
- options: ContentScriptOptions = {}
1109
- ): ContentScriptInstance {
1110
- // Get the render function from the imported contentScript
1111
- const renderFunction = contentScript(options)
1112
-
1113
- // Initialize with the wrapper using the detected CSS imports
1114
- return initializePreactContentScript(options, renderFunction)
1115
- }
1116
-
1117
- // Simple initialization for Preact
1118
- let unmount: (() => void) | undefined
1119
-
1120
- async function initialize() {
1121
- console.log('[Extension.js] Preact wrapper initialize called')
1122
- if (unmount) {
1123
- console.log('[Extension.js] Unmounting previous Preact instance')
1124
- unmount()
1125
- }
1126
-
1127
- // Get the render function from the contentScript function
1128
- const renderFunction = contentScript({})
1129
- const wrapper = new PreactContentScriptWrapper(renderFunction, {})
1130
- await wrapper.mount()
1131
- unmount = () => wrapper.unmount()
1132
- console.log('[Extension.js] Preact wrapper initialization complete')
1133
- }
1134
-
1135
- if (import.meta.webpackHot) {
1136
- import.meta.webpackHot?.accept()
1137
- import.meta.webpackHot?.dispose(() => unmount?.())
1138
-
1139
- // Accept changes to this file
1140
- import.meta.webpackHot?.accept(() => {
1141
- initialize()
1142
- })
1143
- }
1144
-
1145
- if (document.readyState === 'complete') {
1146
- initialize()
1147
- } else {
1148
- document.addEventListener('readystatechange', () => {
1149
- if (document.readyState === 'complete') {
1150
- initialize()
1151
- }
1152
- })
1153
- }
1154
-
1155
- export default PreactContentScriptWrapper
1156
- `;
1157
- return wrapperCode;
1158
- }
1159
- function typescript_content_script_wrapper_extractCSSImports(source) {
1160
- const cssImports = [];
1161
- const lines = source.split('\n');
1162
- const cssImportPatterns = [
1163
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]/,
1164
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*;?\s*$/,
1165
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*from\s+['"][^'"]*['"]/
1166
- ];
1167
- for (const line of lines){
1168
- const trimmedLine = line.trim();
1169
- if (!(trimmedLine.startsWith('//') || trimmedLine.startsWith('/*'))) for (const pattern of cssImportPatterns){
1170
- const match = pattern.exec(line);
1171
- if (match) {
1172
- const cssPath = match[1];
1173
- if (cssPath && !cssImports.includes(cssPath)) cssImports.push(cssPath);
1174
- }
1175
- }
1176
- }
1177
- return cssImports;
1178
- }
1179
- function generateTypeScriptWrapperCode(source, resourcePath) {
1180
- external_path_namespaceObject.basename(resourcePath, external_path_namespaceObject.extname(resourcePath));
1181
- const cssImports = typescript_content_script_wrapper_extractCSSImports(source);
1182
- const resourceDir = external_path_namespaceObject.dirname(resourcePath);
1183
- if ('development' === process.env.EXTENSION_ENV) console.log("[Extension.js] Detected TypeScript framework with CSS imports:", cssImports);
1184
- const cssContentMap = {};
1185
- for (const cssImport of cssImports)try {
1186
- const cssPath = external_path_namespaceObject.resolve(resourceDir, cssImport);
1187
- if (external_fs_namespaceObject.existsSync(cssPath)) {
1188
- const cssContent = external_fs_namespaceObject.readFileSync(cssPath, 'utf-8');
1189
- const escapedCSS = cssContent.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\${/g, '\\${').replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
1190
- cssContentMap[cssImport] = escapedCSS;
1191
- if ('development' === process.env.EXTENSION_ENV) console.log(`[Extension.js] Read CSS content for ${cssImport}, length: ${cssContent.length}`);
1192
- } else if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] CSS file not found: ${cssPath}`);
1193
- } catch (error) {
1194
- if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] Failed to read CSS file ${cssImport}:`, error);
1195
- }
1196
- const wrapperCode = `
1197
- // TypeScript Content Script Wrapper - Auto-generated by Extension.js
1198
- // This wrapper provides Shadow DOM isolation and CSS injection for TypeScript content scripts
1199
-
1200
- // Original TypeScript content script source (directive processed)
1201
- ${source.replace(/'use shadow-dom'/g, "// 'use shadow-dom'").replace(/"use shadow-dom"/g, '// "use shadow-dom"')}
1202
-
1203
- // Content script options interface
1204
- export interface ContentScriptOptions {
1205
- rootElement?: string
1206
- rootClassName?: string
1207
- stylesheets?: string[]
1208
- }
1209
-
1210
- // Content script instance interface
1211
- export interface ContentScriptInstance {
1212
- mount: (container: HTMLElement) => void
1213
- unmount: () => void
1214
- }
1215
-
1216
- // TypeScript Content script wrapper class
1217
- class TypeScriptContentScriptWrapper {
1218
- private rootElement: HTMLElement | null = null
1219
- private shadowRoot: ShadowRoot | null = null
1220
- private styleElement: HTMLStyleElement | null = null
1221
- private renderFunction: (container: HTMLElement) => (() => void) | void
1222
- private unmountFunction: (() => void) | null = null
1223
- private options: ContentScriptOptions
1224
-
1225
- constructor(renderFunction: (container: HTMLElement) => (() => void) | void, options: ContentScriptOptions = {}) {
1226
- this.renderFunction = renderFunction
1227
- this.options = {
1228
- rootElement: 'extension-root',
1229
- rootClassName: undefined, // TypeScript handles its own styling
1230
- stylesheets: ${JSON.stringify(cssImports)},
1231
- ...options
1232
- }
1233
- }
1234
-
1235
- async mount(container?: HTMLElement): Promise<void> {
1236
- console.log('[Extension.js] TypeScript wrapper mount called')
1237
- if (this.rootElement) {
1238
- this.unmount()
1239
- }
1240
-
1241
- // Create root element - TypeScript handles its own container styling
1242
- this.rootElement = container || document.createElement('div')
1243
- this.rootElement.id = this.options.rootElement!
1244
- if (this.options.rootClassName) {
1245
- this.rootElement.className = this.options.rootClassName
1246
- }
1247
-
1248
- // Create shadow root for style isolation
1249
- this.shadowRoot = this.rootElement.attachShadow({ mode: 'open' })
1250
-
1251
- // Inject styles FIRST
1252
- console.log('[Extension.js] About to inject styles')
1253
- await this.injectStyles()
1254
-
1255
- // Render TypeScript content
1256
- console.log('[Extension.js] About to render TypeScript content')
1257
- const result = this.renderFunction(this.shadowRoot as any)
1258
- if (typeof result === 'function') {
1259
- this.unmountFunction = result
1260
- }
1261
-
1262
- // Append to document if no container provided
1263
- if (!container) {
1264
- document.body.appendChild(this.rootElement)
1265
- }
1266
-
1267
- console.log('[Extension.js] TypeScript wrapper mount complete')
1268
- }
1269
-
1270
- unmount() {
1271
- if (this.unmountFunction) {
1272
- this.unmountFunction()
1273
- this.unmountFunction = null
1274
- }
1275
-
1276
- if (this.rootElement && this.rootElement.parentNode) {
1277
- this.rootElement.parentNode.removeChild(this.rootElement)
1278
- }
1279
-
1280
- this.rootElement = null
1281
- this.shadowRoot = null
1282
- this.styleElement = null
1283
- }
1284
-
1285
- // Inject styles with hardcoded CSS content for TypeScript templates
1286
- private async injectStyles(): Promise<void> {
1287
- console.log('[Extension.js] TypeScript injectStyles called')
1288
- const targetRoot = this.shadowRoot || this.rootElement!
1289
-
1290
- // Create style element
1291
- this.styleElement = document.createElement('style')
1292
- targetRoot.appendChild(this.styleElement)
1293
-
1294
- // Fetch CSS content
1295
- try {
1296
- console.log('[Extension.js] About to fetch CSS')
1297
- const cssContent = await this.fetchCSS()
1298
- console.log('[Extension.js] CSS fetched, length:', cssContent.length)
1299
- this.styleElement.textContent = cssContent
1300
- console.log('[Extension.js] TypeScript CSS injected successfully')
1301
- } catch (error) {
1302
- console.error('[Extension.js] Failed to inject TypeScript CSS:', error)
1303
- }
1304
-
1305
- // Setup HMR for CSS files
1306
- this.setupCSSHMR()
1307
- }
1308
-
1309
- // Fetch CSS with hardcoded content for TypeScript templates
1310
- private async fetchCSS(): Promise<string> {
1311
- let allCSS = ''
1312
-
1313
- console.log('[Extension.js] Processing TypeScript stylesheets:', this.options.stylesheets)
1314
-
1315
- // CSS content map is injected at build time
1316
- const cssContentMap: Record<string, string> = ${JSON.stringify(cssContentMap)}
1317
-
1318
- for (const stylesheet of this.options.stylesheets) {
1319
- try {
1320
- console.log('[Extension.js] Processing TypeScript stylesheet:', stylesheet)
1321
- // Check if we have hardcoded content for this stylesheet
1322
- if (cssContentMap[stylesheet]) {
1323
- const cssContent = cssContentMap[stylesheet]
1324
- allCSS += cssContent + '\\n'
1325
- console.log(\`[Extension.js] Successfully injected TypeScript \${stylesheet} content\`)
1326
- continue
1327
- }
1328
-
1329
- // For stylesheets without hardcoded content, try to fetch them
1330
- const cssUrl = new URL(stylesheet, import.meta.url)
1331
- const response = await fetch(cssUrl)
1332
- const text = await response.text()
1333
- if (response.ok) {
1334
- allCSS += text + '\\n'
1335
- console.log('[Extension.js] Successfully fetched stylesheet:', stylesheet)
1336
- } else {
1337
- console.warn('[Extension.js] Failed to fetch CSS:', stylesheet)
1338
- }
1339
- } catch (error) {
1340
- console.warn('[Extension.js] Failed to fetch TypeScript CSS:', stylesheet, error)
1341
- }
1342
- }
1343
-
1344
- return allCSS
1345
- }
1346
-
1347
- // Setup CSS HMR for TypeScript templates
1348
- private setupCSSHMR() {
1349
- if (!import.meta.webpackHot) return
1350
-
1351
- // Setup HMR for each CSS file
1352
- for (const stylesheet of this.options.stylesheets) {
1353
- import.meta.webpackHot?.accept(stylesheet, async () => {
1354
- try {
1355
- const cssContent = await this.fetchCSS()
1356
- if (this.styleElement) {
1357
- this.styleElement.textContent = cssContent
1358
- console.log('[Extension.js] TypeScript CSS updated via HMR:', stylesheet)
1359
- }
1360
- } catch (error) {
1361
- console.error('[Extension.js] Failed to update TypeScript CSS via HMR:', stylesheet, error)
1362
- }
1363
- })
1364
- }
1365
- }
1366
- }
1367
-
1368
- // Initialize TypeScript content script with wrapper
1369
- function initializeTypeScriptContentScript(
1370
- options: ContentScriptOptions,
1371
- renderFunction: (container: HTMLElement) => (() => void) | void
1372
- ): ContentScriptInstance {
1373
- const wrapper = new TypeScriptContentScriptWrapper(renderFunction, options)
1374
-
1375
- return {
1376
- mount: (container?: HTMLElement) => wrapper.mount(container),
1377
- unmount: () => wrapper.unmount()
1378
- }
1379
- }
1380
-
1381
- // Auto-initialize the TypeScript content script with the wrapper
1382
- export function autoInitializeTypeScriptContentScript(
1383
- options: ContentScriptOptions = {}
1384
- ): ContentScriptInstance {
1385
- // Get the render function from the imported contentScript
1386
- const renderFunction = contentScript(options)
1387
-
1388
- // Initialize with the wrapper using the detected CSS imports
1389
- return initializeTypeScriptContentScript(options, renderFunction)
1390
- }
1391
-
1392
- // Simple initialization for TypeScript
1393
- let unmount: (() => void) | undefined
1394
-
1395
- async function initialize() {
1396
- console.log('[Extension.js] TypeScript wrapper initialize called')
1397
- if (unmount) {
1398
- console.log('[Extension.js] Unmounting previous TypeScript instance')
1399
- unmount()
1400
- }
1401
-
1402
- // Get the render function from the contentScript function
1403
- const renderFunction = contentScript({})
1404
- const wrapper = new TypeScriptContentScriptWrapper(renderFunction, {})
1405
- await wrapper.mount()
1406
- unmount = () => wrapper.unmount()
1407
- console.log('[Extension.js] TypeScript wrapper initialization complete')
1408
- }
1409
-
1410
- if (import.meta.webpackHot) {
1411
- import.meta.webpackHot?.accept()
1412
- import.meta.webpackHot?.dispose(() => unmount?.())
1413
-
1414
- // Accept changes to this file
1415
- import.meta.webpackHot?.accept(() => {
1416
- initialize()
1417
- })
1418
- }
1419
-
1420
- if (document.readyState === 'complete') {
1421
- initialize()
1422
- } else {
1423
- document.addEventListener('readystatechange', () => {
1424
- if (document.readyState === 'complete') {
1425
- initialize()
1426
- }
1427
- })
1428
- }
1429
-
1430
- export default TypeScriptContentScriptWrapper
1431
- `;
1432
- return wrapperCode;
1433
- }
1434
- function javascript_content_script_wrapper_extractCSSImports(source) {
1435
- const cssImports = [];
1436
- const lines = source.split('\n');
1437
- const cssImportPatterns = [
1438
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]/,
1439
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*;?\s*$/,
1440
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*from\s+['"][^'"]*['"]/
1441
- ];
1442
- for (const line of lines){
1443
- const trimmedLine = line.trim();
1444
- if (!(trimmedLine.startsWith('//') || trimmedLine.startsWith('/*'))) for (const pattern of cssImportPatterns){
1445
- const match = pattern.exec(line);
1446
- if (match) {
1447
- const cssPath = match[1];
1448
- if (cssPath && !cssImports.includes(cssPath)) cssImports.push(cssPath);
1449
- }
1450
- }
1451
- }
1452
- return cssImports;
1453
- }
1454
- function generateJavaScriptWrapperCode(source, resourcePath) {
1455
- external_path_namespaceObject.basename(resourcePath, external_path_namespaceObject.extname(resourcePath));
1456
- const cssImports = javascript_content_script_wrapper_extractCSSImports(source);
1457
- const resourceDir = external_path_namespaceObject.dirname(resourcePath);
1458
- if ('development' === process.env.EXTENSION_ENV) console.log("[Extension.js] Detected JavaScript framework with CSS imports:", cssImports);
1459
- const cssContentMap = {};
1460
- for (const cssImport of cssImports)try {
1461
- const cssPath = external_path_namespaceObject.resolve(resourceDir, cssImport);
1462
- if (external_fs_namespaceObject.existsSync(cssPath)) {
1463
- const cssContent = external_fs_namespaceObject.readFileSync(cssPath, 'utf-8');
1464
- const escapedCSS = cssContent.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\${/g, '\\${').replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
1465
- cssContentMap[cssImport] = escapedCSS;
1466
- if ('development' === process.env.EXTENSION_ENV) console.log(`[Extension.js] Read CSS content for ${cssImport}, length: ${cssContent.length}`);
1467
- } else if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] CSS file not found: ${cssPath}`);
1468
- } catch (error) {
1469
- if ('development' === process.env.EXTENSION_ENV) console.warn(`[Extension.js] Failed to read CSS file ${cssImport}:`, error);
1470
- }
1471
- const wrapperCode = `
1472
- // JavaScript Content Script Wrapper - Auto-generated by Extension.js
1473
- // This wrapper provides Shadow DOM isolation and CSS injection for JavaScript content scripts
1474
-
1475
- // Original JavaScript content script source (directive processed)
1476
- ${source.replace(/'use shadow-dom'/g, "// 'use shadow-dom'").replace(/"use shadow-dom"/g, '// "use shadow-dom"')}
1477
-
1478
- // Content script wrapper class
1479
- class JavaScriptContentScriptWrapper {
1480
- constructor(renderFunction, options = {}) {
1481
- this.renderFunction = renderFunction
1482
- this.options = {
1483
- rootElement: 'extension-root',
1484
- rootClassName: undefined,
1485
- stylesheets: ${JSON.stringify(cssImports.length > 0 ? cssImports : [
1486
- './styles.css'
1487
- ])},
1488
- ...options
1489
- }
1490
- this.rootElement = null
1491
- this.shadowRoot = null
1492
- this.styleElement = null
1493
- this.unmountFunction = null
1494
- }
1495
-
1496
- async mount(container) {
1497
- console.log('[Extension.js] JavaScript wrapper mount called')
1498
- if (this.rootElement) {
1499
- this.unmount()
1500
- }
1501
-
1502
- // Create root element
1503
- this.rootElement = container || document.createElement('div')
1504
- this.rootElement.id = this.options.rootElement
1505
- if (this.options.rootClassName) {
1506
- this.rootElement.className = this.options.rootClassName
1507
- }
1508
-
1509
- // Create shadow root for style isolation
1510
- this.shadowRoot = this.rootElement.attachShadow({ mode: 'open' })
1511
-
1512
- // Inject styles FIRST
1513
- console.log('[Extension.js] About to inject styles')
1514
- await this.injectStyles()
1515
-
1516
- // Render content using the original contentScript function
1517
- console.log('[Extension.js] About to render JavaScript content')
1518
- const result = this.renderFunction(this.shadowRoot)
1519
- if (typeof result === 'function') {
1520
- this.unmountFunction = result
1521
- }
1522
-
1523
- // Append to document if no container provided
1524
- if (!container) {
1525
- document.body.appendChild(this.rootElement)
1526
- }
1527
-
1528
- console.log('[Extension.js] JavaScript wrapper mount complete')
1529
- }
1530
-
1531
- unmount() {
1532
- if (this.unmountFunction) {
1533
- this.unmountFunction()
1534
- this.unmountFunction = null
1535
- }
1536
-
1537
- if (this.rootElement && this.rootElement.parentNode) {
1538
- this.rootElement.parentNode.removeChild(this.rootElement)
1539
- }
1540
-
1541
- this.rootElement = null
1542
- this.shadowRoot = null
1543
- this.styleElement = null
1544
- }
1545
-
1546
- async injectStyles() {
1547
- console.log('[Extension.js] JavaScript injectStyles called')
1548
- const targetRoot = this.shadowRoot || this.rootElement
1549
-
1550
- // Create style element
1551
- this.styleElement = document.createElement('style')
1552
- targetRoot.appendChild(this.styleElement)
1553
-
1554
- // Fetch CSS content
1555
- try {
1556
- console.log('[Extension.js] About to fetch CSS')
1557
- const cssContent = await this.fetchCSS()
1558
- console.log('[Extension.js] CSS fetched, length:', cssContent.length)
1559
- this.styleElement.textContent = cssContent
1560
- console.log('[Extension.js] JavaScript CSS injected successfully')
1561
- } catch (error) {
1562
- console.error('[Extension.js] Failed to inject JavaScript CSS:', error)
1563
- }
1564
-
1565
- // Setup HMR for CSS files
1566
- this.setupCSSHMR()
1567
- }
1568
-
1569
- async fetchCSS() {
1570
- let allCSS = ''
1571
-
1572
- console.log('[Extension.js] Processing JavaScript stylesheets:', this.options.stylesheets)
1573
-
1574
- // CSS content map is injected at build time
1575
- const cssContentMap = ${JSON.stringify(cssContentMap)}
1576
-
1577
- for (const stylesheet of this.options.stylesheets) {
1578
- try {
1579
- console.log('[Extension.js] Processing JavaScript stylesheet:', stylesheet)
1580
- // Check if we have hardcoded content for this stylesheet
1581
- if (cssContentMap[stylesheet]) {
1582
- const cssContent = cssContentMap[stylesheet]
1583
- allCSS += cssContent + '\\n'
1584
- console.log(\`[Extension.js] Successfully injected JavaScript \${stylesheet} content\`)
1585
- continue
1586
- }
1587
-
1588
- // For stylesheets without hardcoded content, try to fetch them
1589
- const cssUrl = new URL(stylesheet, import.meta.url)
1590
- const response = await fetch(cssUrl)
1591
- const text = await response.text()
1592
- if (response.ok) {
1593
- allCSS += text + '\\n'
1594
- console.log('[Extension.js] Successfully fetched stylesheet:', stylesheet)
1595
- } else {
1596
- console.warn('[Extension.js] Failed to fetch CSS:', stylesheet)
1597
- }
1598
- } catch (error) {
1599
- console.warn('[Extension.js] Failed to fetch JavaScript CSS:', stylesheet, error)
1600
- }
1601
- }
1602
-
1603
- return allCSS
1604
- }
1605
-
1606
- setupCSSHMR() {
1607
- if (!import.meta.webpackHot) return
1608
-
1609
- // Setup HMR for each CSS file
1610
- for (const stylesheet of this.options.stylesheets) {
1611
- import.meta.webpackHot?.accept(stylesheet, async () => {
1612
- try {
1613
- const cssContent = await this.fetchCSS()
1614
- if (this.styleElement) {
1615
- this.styleElement.textContent = cssContent
1616
- console.log('[Extension.js] JavaScript CSS updated via HMR:', stylesheet)
1617
- }
1618
- } catch (error) {
1619
- console.error('[Extension.js] Failed to update JavaScript CSS via HMR:', stylesheet, error)
1620
- }
1621
- })
1622
- }
1623
- }
1624
- }
1625
-
1626
- // Initialize JavaScript content script with wrapper
1627
- function initializeJavaScriptContentScript(options, renderFunction) {
1628
- const wrapper = new JavaScriptContentScriptWrapper(renderFunction, options)
1629
-
1630
- return {
1631
- mount: (container) => wrapper.mount(container),
1632
- unmount: () => wrapper.unmount()
1633
- }
1634
- }
1635
-
1636
- // Simple initialization for JavaScript
1637
- let unmount
1638
-
1639
- async function initialize() {
1640
- console.log('[Extension.js] JavaScript wrapper initialize called')
1641
- if (unmount) {
1642
- console.log('[Extension.js] Unmounting previous JavaScript instance')
1643
- unmount()
1644
- }
1645
-
1646
- // Get the render function from the contentScript function
1647
- const renderFunction = contentScript({})
1648
- const wrapper = new JavaScriptContentScriptWrapper(renderFunction, {})
1649
- await wrapper.mount()
1650
- unmount = () => wrapper.unmount()
1651
- console.log('[Extension.js] JavaScript wrapper initialization complete')
1652
- }
1653
-
1654
- if (import.meta.webpackHot) {
1655
- import.meta.webpackHot?.accept()
1656
- import.meta.webpackHot?.dispose(() => unmount?.())
1657
-
1658
- // Accept changes to this file
1659
- import.meta.webpackHot?.accept(() => {
1660
- initialize()
1661
- })
1662
- }
1663
-
1664
- if (document.readyState === 'complete') {
1665
- initialize()
1666
- } else {
1667
- document.addEventListener('readystatechange', () => {
1668
- if (document.readyState === 'complete') {
1669
- initialize()
1670
- }
1671
- })
1672
- }
1673
-
1674
- export default JavaScriptContentScriptWrapper
1675
- `;
1676
- return wrapperCode;
1677
- }
1678
- const schema = {
1679
- type: 'object',
1680
- properties: {
1681
- test: {
1682
- type: 'string'
1683
- },
1684
- manifestPath: {
1685
- type: 'string'
1686
- },
1687
- mode: {
1688
- type: 'string'
1689
- },
1690
- includeList: {
1691
- type: 'object'
1692
- },
1693
- excludeList: {
1694
- type: 'object'
1695
- }
1696
- }
1697
- };
1698
- function add_content_script_wrapper_extractCSSImports(source) {
1699
- const cssImports = [];
1700
- const lines = source.split('\n');
1701
- const cssImportPatterns = [
1702
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]/,
1703
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*;?\s*$/,
1704
- /^\s*import\s+['"]([^'"]*\.(?:css|scss|sass|less|module\.css))['"]\s*from\s+['"][^'"]*['"]/
1705
- ];
1706
- for (const line of lines){
1707
- const trimmedLine = line.trim();
1708
- if (!(trimmedLine.startsWith('//') || trimmedLine.startsWith('/*'))) for (const pattern of cssImportPatterns){
1709
- const match = pattern.exec(line);
1710
- if (match) {
1711
- const cssPath = match[1];
1712
- if (cssPath && !cssImports.includes(cssPath)) cssImports.push(cssPath);
1713
- }
1714
- }
1715
- }
1716
- return cssImports;
1717
- }
1718
- function detectFramework(resourcePath, projectPath) {
1719
- try {
1720
- const packageJsonPath = external_path_namespaceObject.join(projectPath, 'package.json');
1721
- if (!external_fs_namespaceObject.existsSync(packageJsonPath)) {
1722
- if (resourcePath.endsWith('.ts') && !resourcePath.endsWith('.d.ts')) return "typescript";
1723
- return "javascript";
1724
- }
1725
- const packageJson = JSON.parse(external_fs_namespaceObject.readFileSync(packageJsonPath, 'utf-8'));
1726
- const dependencies = packageJson.dependencies || {};
1727
- const devDependencies = packageJson.devDependencies || {};
1728
- const allDeps = {
1729
- ...dependencies,
1730
- ...devDependencies
1731
- };
1732
- if (allDeps['react'] || allDeps['@types/react']) return 'react';
1733
- if (allDeps['vue'] || allDeps['@vue/runtime-core']) return 'vue';
1734
- if (allDeps['svelte'] || allDeps['@svelte/runtime']) return 'svelte';
1735
- if (allDeps['preact'] || allDeps['@preact/preset-vite']) return 'preact';
1736
- if (allDeps["typescript"] || allDeps['@types/node'] || resourcePath.endsWith('.ts') || resourcePath.endsWith('.tsx')) return "typescript";
1737
- return "javascript";
1738
- } catch (error) {
1739
- if ('development' === process.env.EXTENSION_ENV) console.warn('[Extension.js] Error detecting framework from package.json:', error);
1740
- if (resourcePath.endsWith('.ts') && !resourcePath.endsWith('.d.ts')) return "typescript";
1741
- return "javascript";
1742
- }
1743
- }
1744
- function generateFrameworkWrapperCode(source, framework, resourcePath) {
1745
- external_path_namespaceObject.basename(resourcePath, external_path_namespaceObject.extname(resourcePath));
1746
- const cssImports = add_content_script_wrapper_extractCSSImports(source);
1747
- if ('development' === process.env.EXTENSION_ENV) console.log(`\u{1F50D} Detected ${framework} framework with CSS imports:`, cssImports);
1748
- if ('react' === framework) return generateReactWrapperCode(source, resourcePath);
1749
- if ('vue' === framework) return generateVueWrapperCode(source, resourcePath);
1750
- if ('svelte' === framework) return generateSvelteWrapperCode(source, resourcePath);
1751
- if ('preact' === framework) return generatePreactWrapperCode(source, resourcePath);
1752
- if ("typescript" === framework) return generateTypeScriptWrapperCode(source, resourcePath);
1753
- if ("javascript" === framework) return generateJavaScriptWrapperCode(source, resourcePath);
1754
- return generateTypeScriptWrapperCode(source, resourcePath);
1755
- }
1756
- function shouldUseWrapper(source, manifest, projectPath, url) {
1757
- const hasShadowDomDirective = source.includes("'use shadow-dom'") || source.includes('"use shadow-dom"');
1758
- if (!manifest.content_scripts) return false;
1759
- for (const contentScript of manifest.content_scripts)if (contentScript.js) for (const js of contentScript.js){
1760
- const absoluteUrl = external_path_namespaceObject.resolve(projectPath, js);
1761
- if (url.includes(absoluteUrl)) return hasShadowDomDirective;
1762
- }
1763
- return false;
1764
- }
1765
- function add_content_script_wrapper(source) {
1766
- const options = this.getOptions();
1767
- const manifestPath = options.manifestPath;
1768
- const projectPath = external_path_namespaceObject.dirname(manifestPath);
1769
- const manifest = JSON.parse(external_fs_namespaceObject.readFileSync(manifestPath, 'utf-8'));
1770
- (0, external_schema_utils_namespaceObject.validate)(schema, options, {
1771
- name: "scripts:add-content-script-wrapper",
1772
- baseDataPath: 'options'
1773
- });
1774
- const url = (0, external_loader_utils_namespaceObject.urlToRequest)(this.resourcePath);
1775
- if (!shouldUseWrapper(source, manifest, projectPath, url)) return source;
1776
- const framework = detectFramework(this.resourcePath, projectPath);
1777
- if (framework) {
1778
- const wrapperCode = generateFrameworkWrapperCode(source, framework, this.resourcePath);
1779
- return wrapperCode;
1780
- }
1781
- return source;
1782
- }
1783
- exports["default"] = __webpack_exports__["default"];
1784
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
1785
- "default"
1786
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
1787
- Object.defineProperty(exports, '__esModule', {
1788
- value: true
1789
- });