extension-develop 3.5.1 → 3.6.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.
package/dist/928.cjs CHANGED
@@ -184,6 +184,8 @@ exports.modules = {
184
184
  return frameworks.some((fw)=>hasDependency(projectPath, fw));
185
185
  }
186
186
  var config_loader = __webpack_require__("./webpack/webpack-lib/config-loader.ts");
187
+ var resolve_config = __webpack_require__("./webpack/feature-special-folders/folder-extensions/resolve-config.ts");
188
+ var get_data = __webpack_require__("./webpack/feature-special-folders/get-data.ts");
187
189
  var sanitize = __webpack_require__("./webpack/webpack-lib/sanitize.ts");
188
190
  var branding = __webpack_require__("./webpack/webpack-lib/branding.ts");
189
191
  function setupCompilerHooks(compiler, port) {
@@ -343,10 +345,18 @@ exports.modules = {
343
345
  const safeBrowserConfig = (0, sanitize.a)(browserConfig);
344
346
  const safeCommandConfig = (0, sanitize.a)(commandConfig);
345
347
  const safeDevOptions = (0, sanitize.a)(devOptions);
348
+ const specialFoldersData = (0, get_data.H)(packageJsonDir);
349
+ const mergedExtensionsConfig = safeDevOptions.extensions ?? safeCommandConfig.extensions ?? safeBrowserConfig.extensions ?? specialFoldersData.extensions;
350
+ const resolvedExtensionsConfig = await (0, resolve_config.R)({
351
+ projectRoot: packageJsonDir,
352
+ browser: devOptions.browser,
353
+ config: mergedExtensionsConfig
354
+ });
346
355
  const baseConfig = (0, webpack_config["default"])(projectStructure, {
347
356
  ...safeBrowserConfig,
348
357
  ...safeCommandConfig,
349
358
  ...safeDevOptions,
359
+ extensions: resolvedExtensionsConfig,
350
360
  browser: devOptions.browser,
351
361
  mode: 'development',
352
362
  instanceId: currentInstance.instanceId,
@@ -39,6 +39,31 @@ const external_fs_namespaceObject = require("fs");
39
39
  var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namespaceObject);
40
40
  const external_path_namespaceObject = require("path");
41
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
+ }
42
67
  const external_schema_utils_namespaceObject = require("schema-utils");
43
68
  const core_namespaceObject = require("@swc/core");
44
69
  const schema = {
@@ -115,7 +140,9 @@ function content_script_wrapper(source) {
115
140
  const options = this.getOptions();
116
141
  const compilation = this._compilation;
117
142
  const manifestPath = options.manifestPath;
118
- const projectPath = external_path_default().dirname(manifestPath);
143
+ const manifestDir = external_path_default().dirname(manifestPath);
144
+ const packageJsonPath = findNearestPackageJsonSync(manifestPath);
145
+ const packageJsonDir = packageJsonPath ? external_path_default().dirname(packageJsonPath) : manifestDir;
119
146
  const manifest = JSON.parse(external_fs_default().readFileSync(manifestPath, 'utf-8'));
120
147
  const isProd = 'production' === String(options && options.mode || '').toLowerCase();
121
148
  (0, external_schema_utils_namespaceObject.validate)(schema, options, {
@@ -129,14 +156,14 @@ function content_script_wrapper(source) {
129
156
  const runAtRaw = 'string' == typeof cs?.run_at ? cs.run_at : 'document_idle';
130
157
  const runAt = 'document_start' === runAtRaw || 'document_end' === runAtRaw || 'document_idle' === runAtRaw ? runAtRaw : 'document_idle';
131
158
  for (const js of jsList)declaredContentJsAbsEntries.push({
132
- abs: external_path_default().resolve(projectPath, js),
159
+ abs: external_path_default().resolve(manifestDir, js),
133
160
  runAt
134
161
  });
135
162
  }
136
163
  const resourceAbsPath = external_path_default().normalize(this.resourcePath);
137
164
  const declaredEntry = declaredContentJsAbsEntries.find((entry)=>resourceAbsPath === external_path_default().normalize(entry.abs));
138
165
  const isDeclaredContentScript = Boolean(declaredEntry);
139
- const scriptsDir = external_path_default().resolve(projectPath, "scripts");
166
+ const scriptsDir = external_path_default().resolve(packageJsonDir, "scripts");
140
167
  const relToScripts = external_path_default().relative(scriptsDir, resourceAbsPath);
141
168
  const isScriptsFolderScript = relToScripts && !relToScripts.startsWith('..') && !external_path_default().isAbsolute(relToScripts);
142
169
  const isContentScriptLike = isDeclaredContentScript || isScriptsFolderScript;
@@ -189,6 +216,47 @@ function content_script_wrapper(source) {
189
216
  '} catch (error) {',
190
217
  ' // Do nothing',
191
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) {}',
192
260
  'function loadInnerWrappedModule(){',
193
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) }`,
194
262
  '}',
@@ -213,7 +281,7 @@ function content_script_wrapper(source) {
213
281
  const cssSpecifiers = cssImportMatches.map((m)=>m.groups?.bare || m.groups?.from);
214
282
  const vueImportMatches = Array.from(source.matchAll(/import\s+(?:['\"](?<bare>[^'\"]+\.vue)['\"]|(?:(?:.+?)\s+from\s+['\"](?<from>[^'\"]+\.vue)['\"]))/g));
215
283
  const vueSpecifiers = vueImportMatches.map((m)=>m.groups?.bare || m.groups?.from);
216
- 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 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";
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";
217
285
  if (/\bexport\s+default\s+[A-Za-z_$][\w$]*\s*\(/.test(source) && !/\bexport\s+default\s+function\b/.test(source)) {
218
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`.'));
219
287
  return source;
@@ -15,6 +15,8 @@ __webpack_require__.r(__webpack_exports__);
15
15
  const EXTJS_MARK = '__extjs__';
16
16
  const REQ_TYPE = 'EXTJS_WTW_LOAD';
17
17
  const RES_TYPE = 'EXTJS_WTW_LOADED';
18
+ const EXTJS_BASE_KEY = '__EXTJS_EXTENSION_BASE__';
19
+ const EXTJS_BASE_ATTR = 'data-extjs-extension-base';
18
20
  function safeString(x) {
19
21
  return 'string' == typeof x && x.length > 0;
20
22
  }
@@ -30,6 +32,22 @@ function getRuntime() {
30
32
  } catch {}
31
33
  return null;
32
34
  }
35
+ function setExtensionBaseUrl() {
36
+ try {
37
+ const rt = getRuntime();
38
+ const getURL = rt?.runtime?.getURL;
39
+ if ('function' != typeof getURL) return;
40
+ const base = String(getURL('/'));
41
+ if (base) {
42
+ window[EXTJS_BASE_KEY] = base;
43
+ try {
44
+ const docEl = document && document.documentElement;
45
+ if (docEl && 'function' == typeof docEl.setAttribute) docEl.setAttribute(EXTJS_BASE_ATTR, base);
46
+ } catch {}
47
+ }
48
+ } catch {}
49
+ }
50
+ setExtensionBaseUrl();
33
51
  function resolveExtensionUrl(inputUrl) {
34
52
  if (!safeString(inputUrl)) return null;
35
53
  if (hasForbiddenProtocol(inputUrl)) return null;
@@ -12,14 +12,16 @@ var __webpack_require__ = {};
12
12
  })();
13
13
  var __webpack_exports__ = {};
14
14
  __webpack_require__.r(__webpack_exports__);
15
+ const safeLocation = "u" > typeof globalThis ? globalThis.location : void 0;
16
+ const safeHistory = "u" > typeof globalThis ? globalThis.history : void 0;
15
17
  try {
16
- if ('object' == typeof location && location && String(location.protocol || '').includes('-extension:')) {
17
- const q = String(location.search || '');
18
+ if ('object' == typeof safeLocation && safeLocation && String(safeLocation.protocol || '').includes('-extension:')) {
19
+ const q = String(safeLocation.search || '');
18
20
  if (q.toLowerCase().includes('webpack-dev-server-hot=false')) ;
19
- else if ('function' == typeof URL && 'object' == typeof history && history && 'function' == typeof history.replaceState) {
20
- const u = new URL(String(location.href));
21
+ else if ('function' == typeof URL && 'object' == typeof safeHistory && safeHistory && 'function' == typeof safeHistory.replaceState) {
22
+ const u = new URL(String(safeLocation.href));
21
23
  u.searchParams.set('webpack-dev-server-hot', 'false');
22
- history.replaceState(null, '', u.toString());
24
+ safeHistory.replaceState(null, '', u.toString());
23
25
  }
24
26
  }
25
27
  } catch {}