extension-develop 3.10.3 → 3.11.1

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 (52) hide show
  1. package/dist/215.cjs +350 -69
  2. package/dist/323.cjs +456 -26
  3. package/dist/324.cjs +15 -9
  4. package/dist/{270.cjs → 677.cjs} +3118 -504
  5. package/dist/ensure-hmr-for-scripts.cjs +50 -0
  6. package/dist/ensure-hmr-for-scripts.js +145 -0
  7. package/dist/extension-js-devtools/chrome/content_scripts/content-0.js +2 -2
  8. package/dist/extension-js-devtools/{chromium/content_scripts/styles.24e59c3d.css → chrome/content_scripts/styles.5456c644.css} +1 -1
  9. package/dist/extension-js-devtools/chrome/manifest.json +1 -1
  10. package/dist/extension-js-devtools/chrome/pages/centralized-logger.css +1 -1
  11. package/dist/extension-js-devtools/chrome/pages/welcome.css +1 -1
  12. package/dist/extension-js-devtools/chrome/pages/welcome.js +2 -2
  13. package/dist/extension-js-devtools/chrome/scripts/logger-client.js +1 -1
  14. package/dist/extension-js-devtools/chromium/content_scripts/content-0.js +2 -2
  15. package/dist/extension-js-devtools/{edge/content_scripts/styles.24e59c3d.css → chromium/content_scripts/styles.5456c644.css} +1 -1
  16. package/dist/extension-js-devtools/chromium/manifest.json +1 -1
  17. package/dist/extension-js-devtools/chromium/pages/centralized-logger.css +1 -1
  18. package/dist/extension-js-devtools/chromium/pages/welcome.css +1 -1
  19. package/dist/extension-js-devtools/chromium/pages/welcome.js +2 -2
  20. package/dist/extension-js-devtools/chromium/scripts/logger-client.js +1 -1
  21. package/dist/extension-js-devtools/edge/content_scripts/content-0.js +2 -2
  22. package/dist/extension-js-devtools/{firefox/content_scripts/styles.24e59c3d.css → edge/content_scripts/styles.5456c644.css} +1 -1
  23. package/dist/extension-js-devtools/edge/manifest.json +1 -1
  24. package/dist/extension-js-devtools/edge/pages/centralized-logger.css +1 -1
  25. package/dist/extension-js-devtools/edge/pages/welcome.css +1 -1
  26. package/dist/extension-js-devtools/edge/pages/welcome.js +2 -2
  27. package/dist/extension-js-devtools/edge/scripts/logger-client.js +1 -1
  28. package/dist/extension-js-devtools/firefox/content_scripts/content-0.js +2 -2
  29. package/dist/extension-js-devtools/{chrome/content_scripts/styles.24e59c3d.css → firefox/content_scripts/styles.5456c644.css} +1 -1
  30. package/dist/extension-js-devtools/firefox/manifest.json +2 -1
  31. package/dist/extension-js-devtools/firefox/pages/centralized-logger.css +1 -1
  32. package/dist/extension-js-devtools/firefox/pages/welcome.css +1 -1
  33. package/dist/extension-js-devtools/firefox/pages/welcome.js +2 -2
  34. package/dist/extension-js-devtools/firefox/scripts/logger-client.js +1 -1
  35. package/dist/extension-js-theme/chrome/manifest.json +1 -1
  36. package/dist/extension-js-theme/chromium/manifest.json +1 -1
  37. package/dist/extension-js-theme/edge/manifest.json +1 -1
  38. package/dist/extension-js-theme/firefox/manifest.json +1 -1
  39. package/dist/feature-scripts-content-script-wrapper.cjs +237 -0
  40. package/dist/feature-scripts-content-script-wrapper.js +237 -0
  41. package/dist/main-world-bridge.js +127 -0
  42. package/dist/minimum-chromium-file.js +10 -0
  43. package/dist/minimum-firefox-file.js +10 -0
  44. package/dist/minimum-script-file.js +31 -0
  45. package/dist/module.cjs +2098 -1784
  46. package/dist/package.json +3 -0
  47. package/dist/resolve-paths-loader.js +1350 -0
  48. package/package.json +5 -5
  49. package/dist/add-hmr-accept-code.cjs +0 -91
  50. package/dist/content-script-wrapper.cjs +0 -319
  51. package/dist/warn-no-default-export.cjs +0 -356
  52. package/webpack/webpack-lib/optional-dependencies.json +0 -20
package/package.json CHANGED
@@ -21,11 +21,10 @@
21
21
  "types": "./dist/module.d.ts",
22
22
  "files": [
23
23
  "dist",
24
- "webpack/webpack-lib/build-dependencies.json",
25
- "webpack/webpack-lib/optional-dependencies.json"
24
+ "webpack/webpack-lib/build-dependencies.json"
26
25
  ],
27
26
  "name": "extension-develop",
28
- "version": "3.10.3",
27
+ "version": "3.11.1",
29
28
  "description": "Develop, build, preview, and package Extension.js projects.",
30
29
  "author": {
31
30
  "name": "Cezar Augusto",
@@ -41,9 +40,9 @@
41
40
  "registry": "https://registry.npmjs.org"
42
41
  },
43
42
  "scripts": {
44
- "prepublishOnly": "node scripts/sync-build-dependencies.mjs && rslib build && node ../../scripts/build-extensions.cjs",
43
+ "prepublishOnly": "node scripts/sync-build-dependencies.mjs && rslib build && node scripts/write-dist-js-aliases.mjs && node ../../scripts/build-extensions.cjs",
45
44
  "sync-build-deps": "node scripts/sync-build-dependencies.mjs",
46
- "compile": "rslib build",
45
+ "compile": "rslib build && node scripts/write-dist-js-aliases.mjs",
47
46
  "watch": "rslib build --watch",
48
47
  "test": "vitest run"
49
48
  },
@@ -90,6 +89,7 @@
90
89
  "firefox-location2": "3.0.0",
91
90
  "go-git-it": "^5.1.1",
92
91
  "ignore": "^7.0.5",
92
+ "isolated-deps": "0.1.0",
93
93
  "loader-utils": "^3.3.1",
94
94
  "magic-string": "^0.30.21",
95
95
  "parse5": "^8.0.0",
@@ -1,91 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.n = (module)=>{
5
- var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
- __webpack_require__.d(getter, {
7
- a: getter
8
- });
9
- return getter;
10
- };
11
- })();
12
- (()=>{
13
- __webpack_require__.d = (exports1, definition)=>{
14
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
- enumerable: true,
16
- get: definition[key]
17
- });
18
- };
19
- })();
20
- (()=>{
21
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
- })();
23
- (()=>{
24
- __webpack_require__.r = (exports1)=>{
25
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
- value: 'Module'
27
- });
28
- Object.defineProperty(exports1, '__esModule', {
29
- value: true
30
- });
31
- };
32
- })();
33
- var __webpack_exports__ = {};
34
- __webpack_require__.r(__webpack_exports__);
35
- __webpack_require__.d(__webpack_exports__, {
36
- default: ()=>add_hmr_accept_code
37
- });
38
- const external_fs_namespaceObject = require("fs");
39
- var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namespaceObject);
40
- const external_path_namespaceObject = require("path");
41
- var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
42
- const external_loader_utils_namespaceObject = require("loader-utils");
43
- const external_schema_utils_namespaceObject = require("schema-utils");
44
- const schema = {
45
- type: 'object',
46
- properties: {
47
- test: {
48
- type: 'string'
49
- },
50
- manifestPath: {
51
- type: 'string'
52
- },
53
- mode: {
54
- type: 'string'
55
- }
56
- }
57
- };
58
- function add_hmr_accept_code(source) {
59
- const options = this.getOptions();
60
- const manifestPath = options.manifestPath;
61
- const projectPath = external_path_default().dirname(manifestPath);
62
- const manifest = JSON.parse(external_fs_default().readFileSync(manifestPath, 'utf-8'));
63
- (0, external_schema_utils_namespaceObject.validate)(schema, options, {
64
- name: "scripts:add-hmr-accept-code",
65
- baseDataPath: 'options'
66
- });
67
- if (source.includes('import.meta.webpackHot')) return source;
68
- const url = (0, external_loader_utils_namespaceObject.urlToRequest)(this.resourcePath);
69
- const reloadCodeBackground = `
70
- // Extension.js HMR registration (injected)
71
- if (import.meta.webpackHot) { try { import.meta.webpackHot.accept(); } catch (_) {} }
72
- `;
73
- if (manifest.background) {
74
- if (manifest.background.scripts) for (const bgScript of manifest.background.scripts){
75
- const absoluteUrl = external_path_default().resolve(projectPath, bgScript);
76
- if (url.includes(absoluteUrl)) return `${reloadCodeBackground}${source}`;
77
- }
78
- }
79
- if (manifest.user_scripts) for (const userScript of manifest.user_scripts){
80
- const absoluteUrl = external_path_default().resolve(projectPath, userScript);
81
- if (url.includes(absoluteUrl)) return `${reloadCodeBackground}${source}`;
82
- }
83
- return source;
84
- }
85
- exports["default"] = __webpack_exports__["default"];
86
- for(var __rspack_i in __webpack_exports__)if (-1 === [
87
- "default"
88
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
89
- Object.defineProperty(exports, '__esModule', {
90
- value: true
91
- });
@@ -1,319 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.n = (module)=>{
5
- var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
- __webpack_require__.d(getter, {
7
- a: getter
8
- });
9
- return getter;
10
- };
11
- })();
12
- (()=>{
13
- __webpack_require__.d = (exports1, definition)=>{
14
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
- enumerable: true,
16
- get: definition[key]
17
- });
18
- };
19
- })();
20
- (()=>{
21
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
- })();
23
- (()=>{
24
- __webpack_require__.r = (exports1)=>{
25
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
- value: 'Module'
27
- });
28
- Object.defineProperty(exports1, '__esModule', {
29
- value: true
30
- });
31
- };
32
- })();
33
- var __webpack_exports__ = {};
34
- __webpack_require__.r(__webpack_exports__);
35
- __webpack_require__.d(__webpack_exports__, {
36
- default: ()=>content_script_wrapper
37
- });
38
- const external_fs_namespaceObject = require("fs");
39
- var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namespaceObject);
40
- const external_path_namespaceObject = require("path");
41
- var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
42
- function findUpLocalSync(filename, options) {
43
- const root = external_path_namespaceObject.parse(options.cwd).root;
44
- let currentDir = options.cwd;
45
- while(true){
46
- const candidate = external_path_namespaceObject.join(currentDir, filename);
47
- try {
48
- const stat = external_fs_namespaceObject.statSync(candidate);
49
- if (stat.isFile()) return candidate;
50
- } catch {}
51
- if (currentDir === root) return;
52
- currentDir = external_path_namespaceObject.dirname(currentDir);
53
- }
54
- }
55
- function findNearestPackageJsonSync(manifestPath) {
56
- try {
57
- const manifestDir = external_path_namespaceObject.dirname(manifestPath);
58
- const packageJsonPath = findUpLocalSync('package.json', {
59
- cwd: manifestDir
60
- });
61
- return packageJsonPath || null;
62
- } catch (error) {
63
- console.warn('Failed to find package.json:', error);
64
- return null;
65
- }
66
- }
67
- const external_schema_utils_namespaceObject = require("schema-utils");
68
- const core_namespaceObject = require("@swc/core");
69
- const schema = {
70
- type: 'object',
71
- properties: {
72
- test: {
73
- type: 'string'
74
- },
75
- manifestPath: {
76
- type: 'string'
77
- },
78
- mode: {
79
- type: 'string'
80
- }
81
- }
82
- };
83
- function getSourceSignature(source) {
84
- const head = String(source || '').slice(0, 64);
85
- const tail = String(source || '').slice(-64);
86
- return `${String(source || '').length}:${head}:${tail}`;
87
- }
88
- function hasDefaultExport(source, resourcePath, compilation) {
89
- try {
90
- const ext = external_path_default().extname(resourcePath).toLowerCase();
91
- const isTS = '.ts' === ext || '.tsx' === ext || '.mts' === ext || '.mtsx' === ext;
92
- const isJSX = '.jsx' === ext || '.tsx' === ext || '.mjsx' === ext || '.mtsx' === ext;
93
- const abs = external_path_default().normalize(resourcePath);
94
- const sig = getSourceSignature(source);
95
- if (compilation) {
96
- compilation.__extjsHasDefaultExportCache ??= new Map();
97
- const cacheKey = `${abs}|${sig}`;
98
- const cached = compilation.__extjsHasDefaultExportCache.get(cacheKey);
99
- if ('boolean' == typeof cached) return cached;
100
- }
101
- const ast = (0, core_namespaceObject.parseSync)(source, {
102
- syntax: isTS ? "typescript" : "ecmascript",
103
- tsx: isTS && isJSX,
104
- jsx: !isTS && isJSX,
105
- decorators: true,
106
- dynamicImport: true,
107
- importAssertions: true,
108
- topLevelAwait: true
109
- });
110
- const body = Array.isArray(ast?.body) ? ast.body : [];
111
- for (const item of body)if (item && 'object' == typeof item) {
112
- if ('ExportDefaultDeclaration' === item.type || 'ExportDefaultExpression' === item.type) {
113
- if (compilation) compilation.__extjsHasDefaultExportCache?.set(`${abs}|${sig}`, true);
114
- return true;
115
- }
116
- if ('ExportNamedDeclaration' === item.type && Array.isArray(item.specifiers)) {
117
- for (const s of item.specifiers)if (s && 'object' == typeof s) {
118
- if ('ExportDefaultSpecifier' === s.type) return true;
119
- if ('ExportSpecifier' === s.type) {
120
- const exported = s.exported;
121
- if (exported && 'object' == typeof exported && ('Identifier' === exported.type && 'default' === exported.value || 'Ident' === exported.type && 'default' === exported.value || 'Str' === exported.type && 'default' === exported.value)) {
122
- if (compilation) compilation.__extjsHasDefaultExportCache?.set(`${abs}|${sig}`, true);
123
- return true;
124
- }
125
- }
126
- }
127
- }
128
- }
129
- if (compilation) compilation.__extjsHasDefaultExportCache?.set(`${abs}|${sig}`, false);
130
- return false;
131
- } catch (e) {
132
- const fallback = source.includes('export default');
133
- try {
134
- compilation?.__extjsHasDefaultExportCache?.set(`${external_path_default().normalize(resourcePath)}|${getSourceSignature(source)}`, fallback);
135
- } catch (error) {}
136
- return fallback;
137
- }
138
- }
139
- function content_script_wrapper(source) {
140
- const options = this.getOptions();
141
- const compilation = this._compilation;
142
- const manifestPath = options.manifestPath;
143
- const manifestDir = external_path_default().dirname(manifestPath);
144
- const packageJsonPath = findNearestPackageJsonSync(manifestPath);
145
- const packageJsonDir = packageJsonPath ? external_path_default().dirname(packageJsonPath) : manifestDir;
146
- const manifest = JSON.parse(external_fs_default().readFileSync(manifestPath, 'utf-8'));
147
- const isProd = 'production' === String(options && options.mode || '').toLowerCase();
148
- (0, external_schema_utils_namespaceObject.validate)(schema, options, {
149
- name: "scripts:content-script-wrapper",
150
- baseDataPath: 'options'
151
- });
152
- const declaredContentJsAbsEntries = [];
153
- const contentScripts = Array.isArray(manifest.content_scripts) ? manifest.content_scripts : [];
154
- for (const cs of contentScripts){
155
- const jsList = Array.isArray(cs?.js) ? cs.js : [];
156
- const runAtRaw = 'string' == typeof cs?.run_at ? cs.run_at : 'document_idle';
157
- const runAt = 'document_start' === runAtRaw || 'document_end' === runAtRaw || 'document_idle' === runAtRaw ? runAtRaw : 'document_idle';
158
- for (const js of jsList)declaredContentJsAbsEntries.push({
159
- abs: external_path_default().resolve(manifestDir, js),
160
- runAt
161
- });
162
- }
163
- const resourceAbsPath = external_path_default().normalize(this.resourcePath);
164
- const declaredEntry = declaredContentJsAbsEntries.find((entry)=>resourceAbsPath === external_path_default().normalize(entry.abs));
165
- const isDeclaredContentScript = Boolean(declaredEntry);
166
- const scriptsDir = external_path_default().resolve(packageJsonDir, "scripts");
167
- const relToScripts = external_path_default().relative(scriptsDir, resourceAbsPath);
168
- const isScriptsFolderScript = relToScripts && !relToScripts.startsWith('..') && !external_path_default().isAbsolute(relToScripts);
169
- const isContentScriptLike = isDeclaredContentScript || isScriptsFolderScript;
170
- const runAt = declaredEntry?.runAt || 'document_idle';
171
- if (!isContentScriptLike) return source;
172
- const resourceQuery = String(this.resourceQuery || '');
173
- const isInnerWrapperRequest = /\b__extjs_inner=1\b/.test(resourceQuery);
174
- if (!isInnerWrapperRequest) {
175
- if (isProd) {
176
- if (!isContentScriptLike) return source;
177
- if (!hasDefaultExport(source, this.resourcePath, compilation)) return source;
178
- if (source.includes('__EXTENSIONJS_MOUNT_WRAPPED__')) return source;
179
- const replaced = source.replace(/\bexport\s+default\b/, 'const __EXTENSIONJS_default__ =');
180
- let defaultName;
181
- {
182
- const m1 = source.match(/\bexport\s+default\s+function\s+([A-Za-z_$][\w$]*)\s*\(/);
183
- if (m1) defaultName = m1[1];
184
- else {
185
- const m2 = source.match(/\bexport\s+default\s+([A-Za-z_$][\w$]*)\b/);
186
- if (m2) defaultName = m2[1];
187
- }
188
- }
189
- let cleaned = replaced;
190
- if (defaultName) {
191
- const callPattern = new RegExp(`(^|\\n|;)\\s*${defaultName}\\s*\\(\\s*\\)\\s*;?\\s*(?=\\n|$)`, 'g');
192
- const next = cleaned.replace(callPattern, (_m, p1)=>p1 || '\n');
193
- if (next !== cleaned) {
194
- cleaned = next;
195
- this.emitWarning?.(new Error(`Removed direct call to ${defaultName}() to prevent double mount; wrapper handles mounting.`));
196
- }
197
- }
198
- const runtimeProdInline = "function __EXTENSIONJS_whenReady(runAt, cb){\n try {\n if (typeof document === 'undefined') { cb(); return function(){} }\n if (runAt === 'document_start') { cb(); return function(){} }\n var isDone = false;\n function isReady(){\n if (runAt === 'document_end') return document.readyState === 'interactive' || document.readyState === 'complete';\n if (runAt === 'document_idle') return document.readyState !== 'loading';\n return document.readyState === 'complete';\n }\n if (isReady()) { cb(); return function(){} }\n var onReady = function(){\n try {\n if (isDone) return;\n if (isReady()) { isDone = true; document.removeEventListener('readystatechange', onReady); cb(); }\n } catch (e) {}\n };\n document.addEventListener('readystatechange', onReady);\n return function(){ try { if (!isDone) document.removeEventListener('readystatechange', onReady); } catch (e) {} };\n } catch (e) { try { cb(); } catch (_) {} return function(){} }\n}\nfunction __EXTENSIONJS_mount(mount, runAt){\n var cleanup;\n var cancelReady = function(){};\n if (typeof mount !== \"function\") { try { console.warn(\"[extension.js] content script default export must be a function; skipping mount\") } catch (_) {} return function(){} }\n function apply(){ try { cleanup = mount() } catch (e) { try { console.warn(\"[extension.js] content script default export failed to run\", e) } catch (_) {} } }\n function unmount(){ try { cancelReady && cancelReady(); } catch (e) {} try { if (typeof cleanup === 'function') cleanup() } catch (e2) {} }\n cancelReady = __EXTENSIONJS_whenReady(runAt, apply);\n return unmount;\n}\n";
199
- const injected = `${runtimeProdInline}${cleaned}\n;/* __EXTENSIONJS_MOUNT_WRAPPED__ */\ntry { __EXTENSIONJS_mount(__EXTENSIONJS_default__, ${JSON.stringify(runAt)}) } catch (error) {}\nexport default __EXTENSIONJS_default__\n`;
200
- return injected;
201
- }
202
- const innerSpecifier = JSON.stringify(this.resourcePath.replace(/\\/g, '/') + '?__extjs_inner=1');
203
- const proxyCode = [
204
- "/* extension.js content script proxy */",
205
- 'try {',
206
- " if (typeof location === 'object' && location && !String(location.protocol || '').includes('-extension:')) {",
207
- " var __extjsProto = (typeof Object === 'function' && Object.getPrototypeOf) ? Object.getPrototypeOf(location) : null;",
208
- " if (__extjsProto && typeof __extjsProto.reload === 'function' && !__extjsProto.__extjsReloadPatched) {",
209
- ' __extjsProto.__extjsReloadPatched = true;',
210
- ' __extjsProto.__extjsOrigReload = __extjsProto.reload;',
211
- ' __extjsProto.reload = function(){',
212
- " try { console.warn('[extension.js] blocked HMR-triggered location.reload() in content script context to prevent infinite reload loop. Fix the syntax error and HMR will recover on next successful compile.'); } catch (error) {}",
213
- ' };',
214
- ' }',
215
- ' }',
216
- '} catch (error) {',
217
- ' // Do nothing',
218
- '}',
219
- 'try {',
220
- ' if (typeof __webpack_require__ === "function" || typeof __webpack_require__ === "object") {',
221
- ' var __extjsHasRuntime = !!(__webpack_require__.webExtRt && __webpack_require__.webExtRt.runtime && typeof __webpack_require__.webExtRt.runtime.getURL === "function");',
222
- ' if (!__extjsHasRuntime) {',
223
- ' var __extjsGetBase = function(){',
224
- ' try {',
225
- ' if (typeof document === "object" && document && document.documentElement) {',
226
- ' return document.documentElement.getAttribute("data-extjs-extension-base") || "";',
227
- ' }',
228
- ' } catch (e) {}',
229
- ' return "";',
230
- ' };',
231
- ' var __extjsBase = __extjsGetBase();',
232
- ' if (__extjsBase) {',
233
- ' __webpack_require__.p = __extjsBase.replace(/\\/+$/, "/");',
234
- ' }',
235
- ' var __extjsOrigHmrF = __webpack_require__.hmrF;',
236
- ' if (typeof __extjsOrigHmrF === "function") {',
237
- ' __webpack_require__.hmrF = function(){',
238
- ' var base = __extjsGetBase();',
239
- ' if (base) {',
240
- ' __webpack_require__.p = base.replace(/\\/+$/, "/");',
241
- ' }',
242
- ' return __extjsOrigHmrF();',
243
- ' };',
244
- ' }',
245
- ' if (!__extjsBase) {',
246
- ' var __extjsRetries = 0;',
247
- ' var __extjsUpdateBase = function(){',
248
- ' var base = __extjsGetBase();',
249
- ' if (base) {',
250
- ' __webpack_require__.p = base.replace(/\\/+$/, "/");',
251
- ' } else if (__extjsRetries++ < 50) {',
252
- ' setTimeout(__extjsUpdateBase, 100);',
253
- ' }',
254
- ' };',
255
- ' __extjsUpdateBase();',
256
- ' }',
257
- ' }',
258
- ' }',
259
- '} catch (e) {}',
260
- 'function loadInnerWrappedModule(){',
261
- ` try { import(/* webpackMode: "eager" */ ${innerSpecifier}).catch(function(e){ console.warn('[extension.js] content script failed to load. waiting for next successful compile', e) }) } catch (e) { console.warn('[extension.js] content script failed to load. waiting for next successful compile', e) }`,
262
- '}',
263
- 'loadInnerWrappedModule()',
264
- 'try {',
265
- ' var hotModuleReplacement = (typeof module !== "undefined" && module && module.hot) ? module.hot : null;',
266
- ' if (hotModuleReplacement) {',
267
- ' var isExtensionJsDisposed = false;',
268
- ' if (typeof hotModuleReplacement.dispose === "function") hotModuleReplacement.dispose(function(){ isExtensionJsDisposed = true });',
269
- ' // Accept updates, but avoid triggering reload from inside accept callback',
270
- ' // (it can run during disposal and cause "[HMR] unexpected require(...) from disposed module" warnings).',
271
- ' if (typeof hotModuleReplacement.accept === "function") hotModuleReplacement.accept();',
272
- ' if (typeof hotModuleReplacement.addStatusHandler === "function") hotModuleReplacement.addStatusHandler(function(status){ if (isExtensionJsDisposed) return; if (status === "idle") loadInnerWrappedModule(); });',
273
- ' }',
274
- '} catch (error) {}'
275
- ].join('\n');
276
- return proxyCode;
277
- }
278
- if (!hasDefaultExport(source, this.resourcePath, compilation)) return source;
279
- if (source.includes('__EXTENSIONJS_MOUNT_WRAPPED__')) return source;
280
- const cssImportMatches = Array.from(source.matchAll(/import\s+(?:['\"](?<bare>[^'\"]+\.(css|sass|scss|less))['\"]|(?:(?:.+?)\s+from\s+['\"](?<from>[^'\"]+\.(css|sass|scss|less))['\"]))/g));
281
- const cssSpecifiers = cssImportMatches.map((m)=>m.groups?.bare || m.groups?.from);
282
- const vueImportMatches = Array.from(source.matchAll(/import\s+(?:['\"](?<bare>[^'\"]+\.vue)['\"]|(?:(?:.+?)\s+from\s+['\"](?<from>[^'\"]+\.vue)['\"]))/g));
283
- const vueSpecifiers = vueImportMatches.map((m)=>m.groups?.bare || m.groups?.from);
284
- const runtimeInline = "function __EXTENSIONJS_whenReady(runAt, cb){\n try {\n if (typeof document === 'undefined') { cb(); return function(){} }\n if (runAt === 'document_start') { cb(); return function(){} }\n var isDone = false;\n function isReady(){\n if (runAt === 'document_end') return document.readyState === 'interactive' || document.readyState === 'complete';\n if (runAt === 'document_idle') return document.readyState !== 'loading';\n return document.readyState === 'complete';\n }\n if (isReady()) { cb(); return function(){} }\n var onReady = function(){\n try {\n if (isDone) return;\n if (isReady()) { isDone = true; document.removeEventListener('readystatechange', onReady); cb(); }\n } catch (e) {}\n };\n document.addEventListener('readystatechange', onReady);\n return function(){ try { if (!isDone) document.removeEventListener('readystatechange', onReady); } catch (e) {} };\n } catch (e) { try { cb(); } catch (_) {} return function(){} }\n}\nfunction __EXTENSIONJS_mountWithHMR(mount, runAt){\n var cleanup;\n var cancelReady = function(){};\n if (typeof mount !== \"function\") { try { console.warn(\"[extension.js] content script default export must be a function; skipping mount\") } catch (_) {} return function(){} }\n function apply(){ try { cleanup = mount() } catch (e) { try { console.warn(\"[extension.js] content script default export failed to run\", e) } catch (_) {} } }\n function unmount(){ try { cancelReady && cancelReady(); } catch (e) {} try { if (typeof cleanup === 'function') cleanup() } catch (e2) {} }\n function remount(){ unmount(); apply(); }\n cancelReady = __EXTENSIONJS_whenReady(runAt, apply);\n if (import.meta.webpackHot) {\n if (typeof import.meta.webpackHot.accept === \"function\") import.meta.webpackHot.accept();\n if (typeof import.meta.webpackHot.dispose === \"function\") import.meta.webpackHot.dispose(unmount);\n if (typeof import.meta.webpackHot.addStatusHandler === \"function\") {\n import.meta.webpackHot.addStatusHandler(function(s){ if (s==='abort'||s==='fail') { console.warn('[extension.js] HMR status:', s) } });\n }\n }\n try {\n var hot = (typeof module !== \"undefined\" && module && module.hot) ? module.hot : null;\n if (hot) {\n if (typeof hot.accept === \"function\") hot.accept();\n if (typeof hot.dispose === \"function\") hot.dispose(unmount);\n if (typeof hot.addStatusHandler === \"function\") {\n hot.addStatusHandler(function(s){ if (s==='abort'||s==='fail') { console.warn('[extension.js] HMR status:', s) } });\n }\n }\n } catch (e) {}\n var cssEvt='__EXTENSIONJS_CSS_UPDATE__';\n var onCss=function(){ remount() };\n window.addEventListener(cssEvt, onCss);\n return function(){ window.removeEventListener(cssEvt, onCss); unmount(); };\n}\n";
285
- if (/\bexport\s+default\s+[A-Za-z_$][\w$]*\s*\(/.test(source) && !/\bexport\s+default\s+function\b/.test(source)) {
286
- this.emitWarning?.(new Error('Default export appears to be an invocation. Export a function reference instead: `export default function init(){}` or `export default init`.'));
287
- return source;
288
- }
289
- const replaced = source.replace(/\bexport\s+default\b/, 'const __EXTENSIONJS_default__ =');
290
- let defaultName;
291
- {
292
- const m1 = source.match(/\bexport\s+default\s+function\s+([A-Za-z_$][\w$]*)\s*\(/);
293
- if (m1) defaultName = m1[1];
294
- else {
295
- const m2 = source.match(/\bexport\s+default\s+([A-Za-z_$][\w$]*)\b/);
296
- if (m2) defaultName = m2[1];
297
- }
298
- }
299
- let cleaned = replaced;
300
- if (defaultName) {
301
- const callPattern = new RegExp(`(^|\\n|;)\\s*${defaultName}\\s*\\(\\s*\\)\\s*;?\\s*(?=\\n|$)`, 'g');
302
- const next = cleaned.replace(callPattern, (_m, p1)=>p1 || '\n');
303
- if (next !== cleaned) {
304
- cleaned = next;
305
- this.emitWarning?.(new Error(`Removed direct call to ${defaultName}() to prevent double mount; wrapper handles mounting.`));
306
- }
307
- }
308
- const cssAccepts = cssSpecifiers.length ? `\ntry {\n if (import.meta.webpackHot) {\n ${cssSpecifiers.map((s)=>`import.meta.webpackHot.accept(${JSON.stringify(s)}, () => { try { window.dispatchEvent(new CustomEvent('__EXTENSIONJS_CSS_UPDATE__')) } catch (error) {} })`).join('\n ')}\n }\n} catch (error) {}\n` : '';
309
- const vueAccepts = vueSpecifiers.length ? `\ntry {\n if (import.meta.webpackHot) {\n ${vueSpecifiers.map((s)=>`import.meta.webpackHot.accept(${JSON.stringify(s)}, () => { try { window.dispatchEvent(new CustomEvent('__EXTENSIONJS_CSS_UPDATE__')) } catch (error) {} })`).join('\n ')}\n }\n} catch (error) {}\n` : '';
310
- const injected = `${runtimeInline}${cleaned}\n;/* __EXTENSIONJS_MOUNT_WRAPPED__ */\ntry { __EXTENSIONJS_mountWithHMR(__EXTENSIONJS_default__, ${JSON.stringify(runAt)}) } catch (error) {}\n${cssAccepts}${vueAccepts}export default __EXTENSIONJS_default__\n`;
311
- return injected;
312
- }
313
- exports["default"] = __webpack_exports__["default"];
314
- for(var __rspack_i in __webpack_exports__)if (-1 === [
315
- "default"
316
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
317
- Object.defineProperty(exports, '__esModule', {
318
- value: true
319
- });