extension-develop 3.9.0-next.1 → 3.9.0-next.3

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.
@@ -3,9 +3,72 @@ const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
3
3
  return "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
4
4
  }();
5
5
  exports.ids = [
6
- "535"
6
+ "946"
7
7
  ];
8
8
  exports.modules = {
9
+ "./webpack/dev-server/compiler-hooks.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
10
+ __webpack_require__.d(__webpack_exports__, {
11
+ N: ()=>setupCompilerLifecycleHooks,
12
+ Z: ()=>setupCompilerDoneDiagnostics
13
+ });
14
+ var _messages__rspack_import_0 = __webpack_require__("./webpack/dev-server/messages.ts");
15
+ var _webpack_lib_branding__rspack_import_1 = __webpack_require__("./webpack/webpack-lib/branding.ts");
16
+ function setupCompilerLifecycleHooks(compiler) {
17
+ const verbose = '1' === String(process.env.EXTENSION_VERBOSE || '').trim();
18
+ compiler.hooks.invalid.tap('extension.js:invalid', ()=>{
19
+ if (verbose) console.log(_messages__rspack_import_0.eP());
20
+ });
21
+ compiler.hooks.failed.tap('extension.js:failed', (error)=>{
22
+ console.error(_messages__rspack_import_0.Nq(error));
23
+ });
24
+ }
25
+ function setupCompilerDoneDiagnostics(compiler, port) {
26
+ let reportedNoEntries = false;
27
+ compiler.hooks.done.tap('extension.js:done', (stats)=>{
28
+ try {
29
+ if (stats?.hasErrors?.()) {
30
+ const str = stats?.toString?.({
31
+ colors: true,
32
+ all: false,
33
+ errors: true,
34
+ warnings: true
35
+ });
36
+ if (str) console.error((0, _webpack_lib_branding__rspack_import_1.h)(str));
37
+ } else if (stats?.hasWarnings?.()) {
38
+ const str = stats?.toString?.({
39
+ colors: true,
40
+ all: false,
41
+ errors: false,
42
+ warnings: true
43
+ });
44
+ if (str) console.warn((0, _webpack_lib_branding__rspack_import_1.h)(str));
45
+ }
46
+ if (!reportedNoEntries && 'number' == typeof port) {
47
+ const info = stats.toJson({
48
+ all: false,
49
+ assets: true,
50
+ entrypoints: true
51
+ });
52
+ const hasAssets = Array.isArray(info?.assets) && info.assets.length > 0;
53
+ const entrypoints = info?.entrypoints || {};
54
+ const hasEntrypoints = entrypoints && Object.keys(entrypoints).length > 0;
55
+ if (!hasAssets && !hasEntrypoints) {
56
+ reportedNoEntries = true;
57
+ console.warn(_messages__rspack_import_0.nI(port));
58
+ }
59
+ }
60
+ } catch (error) {
61
+ const str = stats?.toString({
62
+ colors: true,
63
+ all: false,
64
+ errors: true,
65
+ warnings: true
66
+ });
67
+ if (str) console.error((0, _webpack_lib_branding__rspack_import_1.h)(str));
68
+ }
69
+ });
70
+ }
71
+ },
9
72
  "./webpack/webpack-config.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
10
73
  __webpack_require__.r(__webpack_exports__);
11
74
  __webpack_require__.d(__webpack_exports__, {
@@ -213,6 +276,17 @@ exports.modules = {
213
276
  return obj;
214
277
  }
215
278
  class WarnUponFolderChanges {
279
+ getContextDependencyPaths(projectPath) {
280
+ const dependencies = new Set();
281
+ for (const folder of [
282
+ 'pages',
283
+ "scripts"
284
+ ]){
285
+ const folderPath = external_path_.join(projectPath, folder);
286
+ dependencies.add(external_fs_.existsSync(folderPath) ? folderPath : projectPath);
287
+ }
288
+ return Array.from(dependencies);
289
+ }
216
290
  throwCompilationError(compilation, folder, filePath, isAddition) {
217
291
  const addingOrRemoving = isAddition ? 'Adding' : 'Removing';
218
292
  const typeOfAsset = 'pages' === folder ? 'HTML pages' : "script files";
@@ -272,10 +346,7 @@ exports.modules = {
272
346
  });
273
347
  compiler.hooks.thisCompilation.tap('special-folders:warn-upon-folder-changes', (compilation)=>{
274
348
  const projectPath = compiler.options.context || process.cwd();
275
- const pagesPath = external_path_.join(projectPath, 'pages');
276
- const scriptsPath = external_path_.join(projectPath, "scripts");
277
- compilation.contextDependencies?.add(pagesPath);
278
- compilation.contextDependencies?.add(scriptsPath);
349
+ for (const dependencyPath of this.getContextDependencyPaths(projectPath))compilation.contextDependencies?.add(dependencyPath);
279
350
  this.applyPendingChanges(compilation);
280
351
  });
281
352
  }
@@ -752,6 +823,7 @@ exports.modules = {
752
823
  }
753
824
  }
754
825
  boring_define_property(BoringPlugin, "name", 'plugin-boring');
826
+ var compiler_hooks = __webpack_require__("./webpack/dev-server/compiler-hooks.ts");
755
827
  function plugin_compilation_define_property(obj, key, value) {
756
828
  if (key in obj) Object.defineProperty(obj, key, {
757
829
  value: value,
@@ -777,6 +849,7 @@ exports.modules = {
777
849
  if (message.includes('Critical dependency: the request of a dependency is an expression') && /[\\\/]@ffmpeg[\\\/]ffmpeg[\\\/]dist[\\\/]esm[\\\/](classes|worker)\.js$/.test(modulePath)) return true;
778
850
  if (message.includes('Critical dependency: the request of a dependency is an expression') && /[\\\/]@techstark[\\\/]opencv-js[\\\/]dist[\\\/]opencv\.js$/.test(modulePath)) return true;
779
851
  if (message.includes('Critical dependency: the request of a dependency is an expression') && /[\\\/]@sqlite\.org[\\\/]sqlite-wasm[\\\/]dist[\\\/]sqlite3-worker1\.mjs$/.test(modulePath)) return true;
852
+ if (message.includes('Critical dependency: require function is used in a way in which dependencies cannot be statically extracted') && /[\\\/]@vue[\\\/]compiler-sfc[\\\/]dist[\\\/]compiler-sfc\.esm-browser\.js$/.test(modulePath)) return true;
780
853
  return message.includes('Accessing import.meta directly is unsupported') && /[\\\/]@huggingface[\\\/]transformers[\\\/].*transformers\.web\.js$/.test(modulePath);
781
854
  } catch {
782
855
  return false;
@@ -817,6 +890,7 @@ exports.modules = {
817
890
  manifestPath: this.manifestPath,
818
891
  browser: this.browser || 'chrome'
819
892
  }).apply(compiler);
893
+ (0, compiler_hooks.Z)(compiler, this.port);
820
894
  }
821
895
  constructor(options){
822
896
  plugin_compilation_define_property(this, "manifestPath", void 0);
@@ -825,12 +899,14 @@ exports.modules = {
825
899
  plugin_compilation_define_property(this, "zip", void 0);
826
900
  plugin_compilation_define_property(this, "zipSource", void 0);
827
901
  plugin_compilation_define_property(this, "zipFilename", void 0);
902
+ plugin_compilation_define_property(this, "port", void 0);
828
903
  this.manifestPath = options.manifestPath;
829
904
  this.browser = options.browser || 'chrome';
830
905
  this.clean = options.clean ?? true;
831
906
  this.zip = options.zip;
832
907
  this.zipSource = options.zipSource;
833
908
  this.zipFilename = options.zipFilename;
909
+ this.port = options.port;
834
910
  }
835
911
  }
836
912
  plugin_compilation_define_property(CompilationPlugin, "name", 'plugin-compilation');
@@ -1424,7 +1500,7 @@ exports.modules = {
1424
1500
  }
1425
1501
  compiler.options.module.rules = [
1426
1502
  {
1427
- test: /\.(js|mjs|jsx|mjsx|ts|mts|tsx|mtsx)$/,
1503
+ test: /\.(js|cjs|mjs|jsx|mjsx|ts|mts|tsx|mtsx)$/,
1428
1504
  include: Array.from(new Set([
1429
1505
  tsRoot,
1430
1506
  manifestDir,
@@ -1565,46 +1641,6 @@ exports.modules = {
1565
1641
  ].filter(Boolean);
1566
1642
  return parts.join(' — ');
1567
1643
  }
1568
- function emit_manifest_define_property(obj, key, value) {
1569
- if (key in obj) Object.defineProperty(obj, key, {
1570
- value: value,
1571
- enumerable: true,
1572
- configurable: true,
1573
- writable: true
1574
- });
1575
- else obj[key] = value;
1576
- return obj;
1577
- }
1578
- class EmitManifest {
1579
- apply(compiler) {
1580
- compiler.hooks.thisCompilation.tap('manifest:emit-manifest', (compilation)=>{
1581
- compilation.hooks.processAssets.tap({
1582
- name: 'manifest:emit-manifest',
1583
- stage: core_.Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS
1584
- }, ()=>{
1585
- let jsonContent;
1586
- try {
1587
- const content = external_fs_.readFileSync(this.manifestPath, 'utf-8');
1588
- jsonContent = JSON.parse(content);
1589
- if ('$schema' in jsonContent) delete jsonContent['$schema'];
1590
- } catch (error) {
1591
- const err = new (core_default()).WebpackError(manifestInvalidError(error));
1592
- err.file = 'manifest.json';
1593
- compilation.errors.push(err);
1594
- return;
1595
- }
1596
- const jsonString = JSON.stringify(jsonContent, null, 2);
1597
- const outputFilename = 'manifest.json';
1598
- compilation.emitAsset(outputFilename, new core_.sources.RawSource(jsonString));
1599
- if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.log(manifestEmitSuccess());
1600
- });
1601
- });
1602
- }
1603
- constructor(options){
1604
- emit_manifest_define_property(this, "manifestPath", void 0);
1605
- this.manifestPath = options.manifestPath;
1606
- }
1607
- }
1608
1644
  function getFilename(feature, filePath) {
1609
1645
  const entryExt = external_path_.extname(filePath);
1610
1646
  let fileOutputpath = feature;
@@ -1921,9 +1957,24 @@ exports.modules = {
1921
1957
  }
1922
1958
  };
1923
1959
  }
1960
+ function isBundledContentPath(filePath, ext) {
1961
+ const normalized = String(filePath || '').replace(/\\/g, '/');
1962
+ return new RegExp(`^content_scripts/content-\\d+\\.${ext}$`).test(normalized);
1963
+ }
1964
+ function isAlreadyBundledContentScripts(contentScripts) {
1965
+ if (!Array.isArray(contentScripts) || 0 === contentScripts.length) return false;
1966
+ return contentScripts.every((contentObj)=>{
1967
+ const js = Array.isArray(contentObj?.js) ? contentObj.js : [];
1968
+ const css = Array.isArray(contentObj?.css) ? contentObj.css : [];
1969
+ return js.every((filePath)=>isBundledContentPath(filePath, 'js')) && css.every((filePath)=>isBundledContentPath(filePath, 'css'));
1970
+ });
1971
+ }
1924
1972
  function content_scripts_contentScripts(manifest, manifestPath) {
1925
1973
  if (!manifest.content_scripts) return;
1926
1974
  const original = manifest.content_scripts;
1975
+ if (isAlreadyBundledContentScripts(original)) return {
1976
+ content_scripts: original
1977
+ };
1927
1978
  const originalCount = original.length;
1928
1979
  const result = [];
1929
1980
  let bridgeOrdinal = 0;
@@ -2064,6 +2115,7 @@ exports.modules = {
2064
2115
  function normalizeOutputPath(originalPath) {
2065
2116
  if (!originalPath) return originalPath;
2066
2117
  const unix = originalPath.replace(/\\/g, '/');
2118
+ if (/[*?\[\]{}]/.test(unix)) return unix;
2067
2119
  if (/^\/public\//i.test(unix)) return unix.replace(/^\/public\//i, '');
2068
2120
  if (/^(?:\.\/)?public\//i.test(unix)) return unix.replace(/^(?:\.\/)?public\//i, '');
2069
2121
  if (/^\//.test(unix)) return unix.replace(/^\//, '');
@@ -2147,35 +2199,48 @@ exports.modules = {
2147
2199
  if (Object.keys(backgroundMerged).length) merged.background = backgroundMerged;
2148
2200
  return JSON.stringify(merged, null, 2);
2149
2201
  }
2202
+ const INTERNAL_MANIFEST_SOURCE = '__extensionjs_manifest_source__';
2203
+ function manifest_parseJsonSafe(text) {
2204
+ const normalized = text && 0xfeff === text.charCodeAt(0) ? text.slice(1) : text;
2205
+ return JSON.parse(normalized || '{}');
2206
+ }
2207
+ function readAssetSource(asset) {
2208
+ if (!asset) return '';
2209
+ const source = asset.source;
2210
+ if ('string' == typeof source) return source;
2211
+ if ('function' == typeof source) {
2212
+ const out = source();
2213
+ return 'string' == typeof out ? out : String(out || '');
2214
+ }
2215
+ if (source && 'function' == typeof source.source) {
2216
+ const out = source.source();
2217
+ return 'string' == typeof out ? out : String(out || '');
2218
+ }
2219
+ return '';
2220
+ }
2221
+ function setOriginalManifestContent(compilation, source) {
2222
+ compilation[INTERNAL_MANIFEST_SOURCE] = source;
2223
+ }
2224
+ function getOriginalManifestContent(compilation) {
2225
+ return compilation[INTERNAL_MANIFEST_SOURCE];
2226
+ }
2150
2227
  function getManifestContent(compilation, manifestPath) {
2151
- const readAssetSource = (asset)=>{
2152
- if (!asset) return '';
2153
- const source = asset.source;
2154
- if ('string' == typeof source) return source;
2155
- if ('function' == typeof source) {
2156
- const out = source();
2157
- return 'string' == typeof out ? out : String(out || '');
2158
- }
2159
- if (source && 'function' == typeof source.source) {
2160
- const out = source.source();
2161
- return 'string' == typeof out ? out : String(out || '');
2162
- }
2163
- return '';
2164
- };
2165
2228
  const getAsset = compilation.getAsset;
2166
2229
  if ('function' == typeof getAsset) {
2167
2230
  const manifestAsset = getAsset.call(compilation, 'manifest.json');
2168
2231
  const manifest = readAssetSource(manifestAsset);
2169
- if (manifest) return JSON.parse(manifest);
2232
+ if (manifest) return manifest_parseJsonSafe(manifest);
2170
2233
  }
2171
2234
  const manifestAsset = compilation.assets?.['manifest.json'];
2172
2235
  if (manifestAsset) {
2173
2236
  const manifest = readAssetSource(manifestAsset);
2174
- if (manifest) return JSON.parse(manifest);
2237
+ if (manifest) return manifest_parseJsonSafe(manifest);
2175
2238
  }
2239
+ const originalManifest = getOriginalManifestContent(compilation);
2240
+ if (originalManifest) return manifest_parseJsonSafe(originalManifest);
2176
2241
  try {
2177
2242
  const text = external_fs_.readFileSync(manifestPath, 'utf8');
2178
- return JSON.parse(text);
2243
+ return manifest_parseJsonSafe(text);
2179
2244
  } catch {
2180
2245
  return require(manifestPath);
2181
2246
  }
@@ -2207,6 +2272,53 @@ exports.modules = {
2207
2272
  });
2208
2273
  return patchedManifest;
2209
2274
  }
2275
+ function buildCanonicalManifest(manifestPath, manifest, browser) {
2276
+ const filteredManifest = manifest_filterKeysForThisBrowser(manifest, browser);
2277
+ return {
2278
+ ...filteredManifest,
2279
+ ...JSON.parse(getManifestOverrides(manifestPath, filteredManifest))
2280
+ };
2281
+ }
2282
+ function emit_manifest_define_property(obj, key, value) {
2283
+ if (key in obj) Object.defineProperty(obj, key, {
2284
+ value: value,
2285
+ enumerable: true,
2286
+ configurable: true,
2287
+ writable: true
2288
+ });
2289
+ else obj[key] = value;
2290
+ return obj;
2291
+ }
2292
+ class EmitManifest {
2293
+ apply(compiler) {
2294
+ compiler.hooks.thisCompilation.tap('manifest:emit-manifest', (compilation)=>{
2295
+ compilation.hooks.processAssets.tap({
2296
+ name: 'manifest:emit-manifest',
2297
+ stage: core_.Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS
2298
+ }, ()=>{
2299
+ let jsonContent;
2300
+ try {
2301
+ const content = external_fs_.readFileSync(this.manifestPath, 'utf-8');
2302
+ jsonContent = JSON.parse(content);
2303
+ if ('$schema' in jsonContent) delete jsonContent['$schema'];
2304
+ } catch (error) {
2305
+ const err = new (core_default()).WebpackError(manifestInvalidError(error));
2306
+ err.file = 'manifest.json';
2307
+ compilation.errors.push(err);
2308
+ return;
2309
+ }
2310
+ const jsonString = JSON.stringify(jsonContent, null, 2);
2311
+ setOriginalManifestContent(compilation, jsonString);
2312
+ compilation.emitAsset('manifest.json', new core_.sources.RawSource(jsonString));
2313
+ if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.log(manifestEmitSuccess());
2314
+ });
2315
+ });
2316
+ }
2317
+ constructor(options){
2318
+ emit_manifest_define_property(this, "manifestPath", void 0);
2319
+ this.manifestPath = options.manifestPath;
2320
+ }
2321
+ }
2210
2322
  function update_manifest_define_property(obj, key, value) {
2211
2323
  if (key in obj) Object.defineProperty(obj, key, {
2212
2324
  value: value,
@@ -2231,16 +2343,12 @@ exports.modules = {
2231
2343
  compiler.hooks.thisCompilation.tap('manifest:update-manifest', (compilation)=>{
2232
2344
  compilation.hooks.processAssets.tap({
2233
2345
  name: 'manifest:update-manifest',
2234
- stage: core_.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
2346
+ stage: core_.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE + 1
2235
2347
  }, ()=>{
2236
2348
  if (compilation.errors.length > 0) return;
2237
2349
  const manifest = getManifestContent(compilation, this.manifestPath);
2238
- const manifestForBrowser = manifest_filterKeysForThisBrowser(manifest, this.browser);
2239
- const overrides = getManifestOverrides(this.manifestPath, manifestForBrowser);
2240
- const patchedManifest = {
2241
- ...manifestForBrowser,
2242
- ...JSON.parse(overrides)
2243
- };
2350
+ const patchedManifest = buildCanonicalManifest(this.manifestPath, manifest, this.browser);
2351
+ const overrides = getManifestOverrides(this.manifestPath, manifest);
2244
2352
  if ('development' === compiler.options.mode) {
2245
2353
  if (patchedManifest.content_scripts) patchedManifest.content_scripts = this.applyDevOverrides(patchedManifest);
2246
2354
  }
@@ -2257,7 +2365,8 @@ exports.modules = {
2257
2365
  } catch {}
2258
2366
  const source = JSON.stringify(patchedManifest, null, 2);
2259
2367
  const rawSource = new core_.sources.RawSource(source);
2260
- compilation.updateAsset('manifest.json', rawSource);
2368
+ if (compilation.getAsset('manifest.json')) compilation.updateAsset('manifest.json', rawSource);
2369
+ else compilation.emitAsset('manifest.json', rawSource);
2261
2370
  });
2262
2371
  });
2263
2372
  }
@@ -2268,6 +2377,39 @@ exports.modules = {
2268
2377
  this.browser = options.browser || 'chrome';
2269
2378
  }
2270
2379
  }
2380
+ function writeFileAtomically(targetPath, content) {
2381
+ const directory = external_path_.dirname(targetPath);
2382
+ const tempPath = external_path_.join(directory, `.manifest.${process.pid}.${Date.now()}.${Math.random().toString(16).slice(2)}.tmp`);
2383
+ external_fs_.mkdirSync(directory, {
2384
+ recursive: true
2385
+ });
2386
+ external_fs_.writeFileSync(tempPath, content, 'utf-8');
2387
+ external_fs_.renameSync(tempPath, targetPath);
2388
+ }
2389
+ class PersistManifestToDisk {
2390
+ apply(compiler) {
2391
+ compiler.hooks.thisCompilation.tap('manifest:persist-manifest', (compilation)=>{
2392
+ compilation.hooks.processAssets.tap({
2393
+ name: 'manifest:persist-manifest',
2394
+ stage: core_.Compilation.PROCESS_ASSETS_STAGE_REPORT + 1000
2395
+ }, ()=>{
2396
+ if (compilation.errors.length > 0) return;
2397
+ const manifestAsset = compilation.getAsset('manifest.json');
2398
+ const outputPath = compilation.outputOptions.path || compiler.options.output?.path;
2399
+ if (!manifestAsset || !outputPath) return;
2400
+ const manifestSource = manifestAsset.source.source().toString();
2401
+ const manifestOutputPath = external_path_.join(outputPath, 'manifest.json');
2402
+ try {
2403
+ writeFileAtomically(manifestOutputPath, manifestSource);
2404
+ } catch (error) {
2405
+ const err = new (core_default()).WebpackError(`Failed to persist manifest.json to disk: ${error.message}`);
2406
+ err.file = 'manifest.json';
2407
+ compilation.errors.push(err);
2408
+ }
2409
+ });
2410
+ });
2411
+ }
2412
+ }
2271
2413
  function add_dependencies_define_property(obj, key, value) {
2272
2414
  if (key in obj) Object.defineProperty(obj, key, {
2273
2415
  value: value,
@@ -2410,20 +2552,25 @@ exports.modules = {
2410
2552
  'sidebar_action/default_panel.html'
2411
2553
  ];
2412
2554
  compiler.hooks.thisCompilation.tap(ManifestLegacyWarnings.name, (compilation)=>{
2413
- const asset = compilation.getAsset('manifest.json');
2414
- if (!asset) return;
2415
- const text = asset.source.source().toString();
2416
- let count = 0;
2417
- legacy.forEach((needle)=>{
2418
- if (text.includes(needle)) {
2419
- const warn = new core_.WebpackError(legacyManifestPathWarning(needle));
2420
- warn.name = 'ManifestLegacyWarning';
2421
- warn.file = 'manifest.json';
2422
- compilation.warnings.push(warn);
2423
- count++;
2424
- }
2555
+ compilation.hooks.processAssets.tap({
2556
+ name: ManifestLegacyWarnings.name,
2557
+ stage: core_.Compilation.PROCESS_ASSETS_STAGE_REPORT
2558
+ }, ()=>{
2559
+ const asset = compilation.getAsset('manifest.json');
2560
+ if (!asset) return;
2561
+ const text = asset.source.source().toString();
2562
+ let count = 0;
2563
+ legacy.forEach((needle)=>{
2564
+ if (text.includes(needle)) {
2565
+ const warn = new core_.WebpackError(legacyManifestPathWarning(needle));
2566
+ warn.name = 'ManifestLegacyWarning';
2567
+ warn.file = 'manifest.json';
2568
+ compilation.warnings.push(warn);
2569
+ count++;
2570
+ }
2571
+ });
2572
+ if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.log(manifestLegacyWarningsSummary(count));
2425
2573
  });
2426
- if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.log(manifestLegacyWarningsSummary(count));
2427
2574
  });
2428
2575
  }
2429
2576
  }
@@ -2442,12 +2589,14 @@ exports.modules = {
2442
2589
  apply(compiler) {
2443
2590
  if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.log(manifestIncludeSummary(String(this.browser || 'chrome'), this.manifestPath));
2444
2591
  new EmitManifest({
2445
- manifestPath: this.manifestPath
2592
+ manifestPath: this.manifestPath,
2593
+ browser: this.browser
2446
2594
  }).apply(compiler);
2447
2595
  new UpdateManifest({
2448
2596
  manifestPath: this.manifestPath,
2449
2597
  browser: this.browser
2450
2598
  }).apply(compiler);
2599
+ new PersistManifestToDisk().apply(compiler);
2451
2600
  new AddDependencies([
2452
2601
  this.manifestPath
2453
2602
  ]).apply(compiler);
@@ -3699,7 +3848,7 @@ exports.modules = {
3699
3848
  browser: this.browser
3700
3849
  }).apply(compiler);
3701
3850
  if ('production' !== (compiler.options.mode || 'development')) compiler.options.module.rules.push({
3702
- test: /\.(js|mjs|jsx|mjsx|ts|mts|tsx|mtsx)$/,
3851
+ test: /\.(js|cjs|mjs|jsx|mjsx|ts|mts|tsx|mtsx)$/,
3703
3852
  include: [
3704
3853
  external_path_.dirname(this.manifestPath)
3705
3854
  ],
@@ -3765,7 +3914,7 @@ exports.modules = {
3765
3914
  const fileAssets = scriptEntries.filter((scriptAsset)=>{
3766
3915
  const validFile = external_fs_.existsSync(scriptAsset);
3767
3916
  const assetExtension = external_path_.extname(scriptAsset);
3768
- return validFile && ('.js' === assetExtension || '.mjs' === assetExtension || '.jsx' === assetExtension || '.ts' === assetExtension || '.tsx' === assetExtension);
3917
+ return validFile && ('.js' === assetExtension || '.cjs' === assetExtension || '.mjs' === assetExtension || '.jsx' === assetExtension || '.mjsx' === assetExtension || '.ts' === assetExtension || '.mts' === assetExtension || '.mtsx' === assetExtension || '.tsx' === assetExtension);
3769
3918
  });
3770
3919
  return fileAssets;
3771
3920
  }
@@ -3788,19 +3937,34 @@ exports.modules = {
3788
3937
  current = parent;
3789
3938
  }
3790
3939
  }
3940
+ function resolveExistingFile(candidates) {
3941
+ const suffixes = [
3942
+ '',
3943
+ '.js',
3944
+ '.cjs',
3945
+ '.mjs'
3946
+ ];
3947
+ for (const candidate of candidates)if (candidate) for (const suffix of suffixes){
3948
+ const resolved = suffix ? `${candidate}${suffix}` : candidate;
3949
+ if (external_fs_default().existsSync(resolved)) return resolved;
3950
+ }
3951
+ }
3952
+ function resolveMainWorldBridgeSourcePath(options) {
3953
+ const lookupDir = options?.lookupDir || __dirname;
3954
+ const packageRoot = options?.packageRoot || findPackageRoot(lookupDir);
3955
+ return resolveExistingFile([
3956
+ external_path_default().resolve(lookupDir, 'main-world-bridge'),
3957
+ packageRoot ? external_path_default().resolve(packageRoot, "webpack/plugin-web-extension/feature-scripts/steps/setup-reload-strategy/add-content-script-wrapper/main-world-bridge") : void 0,
3958
+ packageRoot ? external_path_default().resolve(packageRoot, 'dist', 'main-world-bridge') : void 0
3959
+ ]);
3960
+ }
3791
3961
  function getMainWorldBridgeScripts(manifestPath) {
3792
3962
  const bridgeScripts = {};
3793
3963
  try {
3794
3964
  const raw = JSON.parse(external_fs_default().readFileSync(manifestPath, 'utf-8'));
3795
3965
  const contentScripts = Array.isArray(raw?.content_scripts) ? raw.content_scripts : [];
3796
3966
  const originalCount = contentScripts.length;
3797
- const packageRoot = findPackageRoot(__dirname);
3798
- const bridgeSourceCandidates = [
3799
- external_path_default().resolve(__dirname, 'main-world-bridge.js'),
3800
- packageRoot ? external_path_default().resolve(packageRoot, "webpack/plugin-extension/feature-scripts/steps/setup-reload-strategy/add-content-script-wrapper/main-world-bridge.js") : void 0,
3801
- packageRoot ? external_path_default().resolve(packageRoot, 'main-world-bridge.js') : void 0
3802
- ].filter((candidate)=>Boolean(candidate));
3803
- const bridgeSource = bridgeSourceCandidates.find((p)=>external_fs_default().existsSync(p)) || void 0;
3967
+ const bridgeSource = resolveMainWorldBridgeSourcePath();
3804
3968
  if (!bridgeSource) return bridgeScripts;
3805
3969
  let bridgeOrdinal = 0;
3806
3970
  for(let i = 0; i < contentScripts.length; i++){
@@ -3849,7 +4013,7 @@ exports.modules = {
3849
4013
  packageJsonDir
3850
4014
  ];
3851
4015
  compiler.options.module.rules.push({
3852
- test: /\.(js|mjs|jsx|mjsx|ts|mts|tsx|mtsx)$/,
4016
+ test: /\.(js|cjs|mjs|jsx|mjsx|ts|mts|tsx|mtsx)$/,
3853
4017
  include: includeDirs,
3854
4018
  exclude: [
3855
4019
  /([\\/])node_modules\1/
@@ -3866,7 +4030,7 @@ exports.modules = {
3866
4030
  });
3867
4031
  if ('production' !== compiler.options.mode) {
3868
4032
  compiler.options.module.rules.push({
3869
- test: /\.(js|mjs|jsx|mjsx|ts|mts|tsx|mtsx)$/,
4033
+ test: /\.(js|cjs|mjs|jsx|mjsx|ts|mts|tsx|mtsx)$/,
3870
4034
  include: includeDirs,
3871
4035
  exclude: [
3872
4036
  /([\\/])node_modules\1/
@@ -3883,7 +4047,7 @@ exports.modules = {
3883
4047
  enforce: 'pre'
3884
4048
  });
3885
4049
  compiler.options.module.rules.push({
3886
- test: /\.(js|mjs|jsx|mjsx|ts|mts|tsx|mtsx)$/,
4050
+ test: /\.(js|cjs|mjs|jsx|mjsx|ts|mts|tsx|mtsx)$/,
3887
4051
  include: includeDirs,
3888
4052
  exclude: [
3889
4053
  /([\\/])node_modules\1/
@@ -4978,64 +5142,10 @@ Set background.noDynamicEntryWarning to true to disable this warning.
4978
5142
  }
4979
5143
  const webpack_target_webextension_fork = WebExtensionPlugin;
4980
5144
  function manifest_getManifestContent(compilation, manifestPath) {
4981
- const readAssetSource = (asset)=>{
4982
- if (!asset) return '';
4983
- const source = asset.source;
4984
- if ('string' == typeof source) return source;
4985
- if ('function' == typeof source) {
4986
- const out = source();
4987
- return 'string' == typeof out ? out : String(out || '');
4988
- }
4989
- if (source && 'function' == typeof source.source) {
4990
- const out = source.source();
4991
- return 'string' == typeof out ? out : String(out || '');
4992
- }
4993
- return '';
4994
- };
4995
- const getAsset = compilation.getAsset;
4996
- if ('function' == typeof getAsset) {
4997
- const manifestAsset = getAsset.call(compilation, 'manifest.json');
4998
- const manifest = readAssetSource(manifestAsset);
4999
- if (manifest) return JSON.parse(manifest);
5000
- }
5001
- const manifestAsset = compilation.assets?.['manifest.json'];
5002
- if (manifestAsset) {
5003
- const manifest = readAssetSource(manifestAsset);
5004
- if (manifest) return JSON.parse(manifest);
5005
- }
5006
- try {
5007
- const text = external_fs_.readFileSync(manifestPath, 'utf8');
5008
- return JSON.parse(text);
5009
- } catch {
5010
- return require(manifestPath);
5011
- }
5145
+ return getManifestContent(compilation, manifestPath);
5012
5146
  }
5013
5147
  function scripts_lib_manifest_filterKeysForThisBrowser(manifest, browser) {
5014
- const CHROMIUM_BASED_BROWSERS = [
5015
- 'chrome',
5016
- 'edge'
5017
- ];
5018
- const GECKO_BASED_BROWSERS = [
5019
- 'firefox'
5020
- ];
5021
- const isChromiumTarget = CHROMIUM_BASED_BROWSERS.includes(browser) || String(browser).includes('chromium');
5022
- const isGeckoTarget = GECKO_BASED_BROWSERS.includes(browser) || String(browser).includes('gecko');
5023
- const chromiumPrefixes = new Set([
5024
- 'chromium',
5025
- 'chrome',
5026
- 'edge'
5027
- ]);
5028
- const geckoPrefixes = new Set([
5029
- 'gecko',
5030
- 'firefox'
5031
- ]);
5032
- const patchedManifest = JSON.parse(JSON.stringify(manifest), function(key, value) {
5033
- const indexOfColon = key.indexOf(':');
5034
- if (-1 === indexOfColon) return value;
5035
- const prefix = key.substring(0, indexOfColon);
5036
- if (prefix === browser || isChromiumTarget && chromiumPrefixes.has(prefix) || isGeckoTarget && geckoPrefixes.has(prefix)) this[key.substring(indexOfColon + 1)] = value;
5037
- });
5038
- return patchedManifest;
5148
+ return manifest_filterKeysForThisBrowser(manifest, browser);
5039
5149
  }
5040
5150
  function backgroundIsRequiredMessageOnly(backgroundChunkName) {
5041
5151
  return `Check the ${external_pintor_default().yellow(backgroundChunkName.replace('/', '.'))} field in your ${external_pintor_default().yellow('manifest.json')} file.`;
@@ -5319,18 +5429,16 @@ Set background.noDynamicEntryWarning to true to disable this warning.
5319
5429
  }
5320
5430
  class ApplyManifestDevDefaults {
5321
5431
  generateManifestPatches(compilation) {
5322
- const manifest = manifest_getManifestContent(compilation, this.manifestPath);
5323
- const browser = this.browser;
5324
- const filtered = scripts_lib_manifest_filterKeysForThisBrowser(manifest, browser);
5432
+ const canonicalManifest = manifest_getManifestContent(compilation, this.manifestPath);
5325
5433
  const patchedManifest = {
5326
- ...filtered,
5327
- content_security_policy: 3 === filtered.manifest_version ? patchV3CSP(filtered) : patchV2CSP(filtered),
5328
- ...3 === filtered.manifest_version ? filtered.permissions ? {
5434
+ ...canonicalManifest,
5435
+ content_security_policy: 3 === canonicalManifest.manifest_version ? patchV3CSP(canonicalManifest) : patchV2CSP(canonicalManifest),
5436
+ ...3 === canonicalManifest.manifest_version ? canonicalManifest.permissions ? {
5329
5437
  permissions: [
5330
5438
  ...new Set([
5331
5439
  "scripting",
5332
5440
  'management',
5333
- ...filtered.permissions
5441
+ ...canonicalManifest.permissions
5334
5442
  ])
5335
5443
  ]
5336
5444
  } : {
@@ -5339,9 +5447,9 @@ Set background.noDynamicEntryWarning to true to disable this warning.
5339
5447
  'management'
5340
5448
  ]
5341
5449
  } : {},
5342
- ...patchBackground(filtered, this.browser),
5343
- ...patchExternallyConnectable(manifest),
5344
- web_accessible_resources: 3 === filtered.manifest_version ? patchWebResourcesV3(filtered) : patchWebResourcesV2(filtered)
5450
+ ...patchBackground(canonicalManifest, this.browser),
5451
+ ...patchExternallyConnectable(canonicalManifest),
5452
+ web_accessible_resources: 3 === canonicalManifest.manifest_version ? patchWebResourcesV3(canonicalManifest) : patchWebResourcesV2(canonicalManifest)
5345
5453
  };
5346
5454
  const source = JSON.stringify(patchedManifest, null, 2);
5347
5455
  const rawSource = new core_.sources.RawSource(source);
@@ -6987,14 +7095,14 @@ Set background.noDynamicEntryWarning to true to disable this warning.
6987
7095
  return false;
6988
7096
  }
6989
7097
  function generateManifestPatches(compilation, manifestPath, entryImports, browser) {
6990
- const manifest = getManifestContent(compilation, manifestPath);
6991
- const resolved = resolveUserDeclaredWAR(compilation, manifestPath, manifest, browser);
6992
- const webAccessibleResourcesV3 = 3 === manifest.manifest_version ? resolved.v3.map((g)=>({
7098
+ const canonicalManifest = getManifestContent(compilation, manifestPath);
7099
+ const resolved = resolveUserDeclaredWAR(compilation, manifestPath, canonicalManifest, browser);
7100
+ const webAccessibleResourcesV3 = 3 === canonicalManifest.manifest_version ? resolved.v3.map((g)=>({
6993
7101
  matches: g.matches,
6994
7102
  resources: Array.from(g.resources)
6995
7103
  })) : [];
6996
- const webAccessibleResourcesV2 = 2 === manifest.manifest_version ? Array.from(resolved.v2) : [];
6997
- if (3 === manifest.manifest_version && Array.isArray(manifest.content_scripts)) for (const contentScript of manifest.content_scripts){
7104
+ const webAccessibleResourcesV2 = 2 === canonicalManifest.manifest_version ? Array.from(resolved.v2) : [];
7105
+ if (3 === canonicalManifest.manifest_version && Array.isArray(canonicalManifest.content_scripts)) for (const contentScript of canonicalManifest.content_scripts){
6998
7106
  const matches = contentScript.matches || [];
6999
7107
  const normalizedMatches = cleanMatches(matches);
7000
7108
  const jsFiles = Array.isArray(contentScript.js) ? contentScript.js : [];
@@ -7029,12 +7137,12 @@ Set background.noDynamicEntryWarning to true to disable this warning.
7029
7137
  }
7030
7138
  }
7031
7139
  for (const [entryName, resources] of Object.entries(entryImports)){
7032
- const contentScript = manifest.content_scripts?.find((script)=>script.js?.some((jsFile)=>jsFile.includes(entryName)));
7140
+ const contentScript = canonicalManifest.content_scripts?.find((script)=>script.js?.some((jsFile)=>jsFile.includes(entryName)));
7033
7141
  if (contentScript) {
7034
7142
  const matches = contentScript.matches || [];
7035
7143
  const filteredResources = resources.filter((resource)=>!resource.endsWith('.map') && !resource.endsWith('.js'));
7036
7144
  if (0 === filteredResources.length) continue;
7037
- if (3 === manifest.manifest_version) {
7145
+ if (3 === canonicalManifest.manifest_version) {
7038
7146
  const normalizedMatches = cleanMatches(matches);
7039
7147
  const existingResource = webAccessibleResourcesV3.find((resourceEntry)=>{
7040
7148
  const a = [
@@ -7066,11 +7174,11 @@ Set background.noDynamicEntryWarning to true to disable this warning.
7066
7174
  });
7067
7175
  }
7068
7176
  }
7069
- if (3 === manifest.manifest_version) {
7177
+ if (3 === canonicalManifest.manifest_version) {
7070
7178
  const assetKeys = Object.keys(compilation.assets || {});
7071
7179
  const staticAssets = assetKeys.filter((k)=>k.startsWith('assets/')).filter((k)=>!k.endsWith('.js') && !k.endsWith('.map')).sort();
7072
7180
  if (staticAssets.length > 0) {
7073
- const allMatches = Array.from(new Set((manifest.content_scripts || []).flatMap((cs)=>cs.matches || [])));
7181
+ const allMatches = Array.from(new Set((canonicalManifest.content_scripts || []).flatMap((cs)=>cs.matches || [])));
7074
7182
  const normalizedMatches = cleanMatches(allMatches);
7075
7183
  const existing = webAccessibleResourcesV3.find((entry)=>{
7076
7184
  const a = [
@@ -7096,11 +7204,11 @@ Set background.noDynamicEntryWarning to true to disable this warning.
7096
7204
  }
7097
7205
  }
7098
7206
  const fontExtRe = /\.(woff2?|eot|ttf|otf)$/i;
7099
- if (3 === manifest.manifest_version) {
7207
+ if (3 === canonicalManifest.manifest_version) {
7100
7208
  const assetKeys = Object.keys(compilation.assets || {});
7101
7209
  const fontAssets = assetKeys.filter((k)=>fontExtRe.test(k)).filter((k)=>!k.startsWith('assets/')).filter((k)=>!k.startsWith("content_scripts/")).sort();
7102
7210
  if (fontAssets.length > 0) {
7103
- const allMatches = Array.from(new Set((manifest.content_scripts || []).flatMap((cs)=>cs.matches || [])));
7211
+ const allMatches = Array.from(new Set((canonicalManifest.content_scripts || []).flatMap((cs)=>cs.matches || [])));
7104
7212
  const normalizedMatches = cleanMatches(allMatches);
7105
7213
  if (normalizedMatches.length > 0) {
7106
7214
  const existing = webAccessibleResourcesV3.find((entry)=>{
@@ -7126,18 +7234,18 @@ Set background.noDynamicEntryWarning to true to disable this warning.
7126
7234
  });
7127
7235
  }
7128
7236
  }
7129
- } else if (2 === manifest.manifest_version) {
7237
+ } else if (2 === canonicalManifest.manifest_version) {
7130
7238
  const assetKeys = Object.keys(compilation.assets || {});
7131
7239
  const fontAssets = assetKeys.filter((k)=>fontExtRe.test(k)).sort();
7132
7240
  if (fontAssets.length > 0) {
7133
7241
  for (const r of fontAssets)if (!webAccessibleResourcesV2.includes(r)) webAccessibleResourcesV2.push(r);
7134
7242
  }
7135
7243
  }
7136
- if (3 === manifest.manifest_version) {
7244
+ if (3 === canonicalManifest.manifest_version) {
7137
7245
  const assetKeys = Object.keys(compilation.assets || {});
7138
7246
  const cssUnderContentScripts = assetKeys.filter((k)=>k.startsWith("content_scripts/")).filter((k)=>k.endsWith('.css')).sort();
7139
7247
  if (cssUnderContentScripts.length > 0) {
7140
- const allMatches = Array.from(new Set((manifest.content_scripts || []).flatMap((cs)=>cs.matches || [])));
7248
+ const allMatches = Array.from(new Set((canonicalManifest.content_scripts || []).flatMap((cs)=>cs.matches || [])));
7141
7249
  const normalizedMatches = cleanMatches(allMatches);
7142
7250
  if (normalizedMatches.length > 0) {
7143
7251
  const existing = webAccessibleResourcesV3.find((entry)=>{
@@ -7164,18 +7272,18 @@ Set background.noDynamicEntryWarning to true to disable this warning.
7164
7272
  }
7165
7273
  }
7166
7274
  }
7167
- if (3 === manifest.manifest_version) {
7168
- if (webAccessibleResourcesV3.length > 0) manifest.web_accessible_resources = webAccessibleResourcesV3.map((entry)=>({
7275
+ if (3 === canonicalManifest.manifest_version) {
7276
+ if (webAccessibleResourcesV3.length > 0) canonicalManifest.web_accessible_resources = webAccessibleResourcesV3.map((entry)=>({
7169
7277
  resources: Array.from(new Set(entry.resources)).sort(),
7170
7278
  matches: Array.from(new Set(entry.matches)).sort()
7171
7279
  })).sort((a, b)=>a.matches.join(',').localeCompare(b.matches.join(',')));
7172
- } else if (webAccessibleResourcesV2.length > 0) manifest.web_accessible_resources = Array.from(new Set(webAccessibleResourcesV2)).sort();
7173
- const source = JSON.stringify(manifest, null, 2);
7280
+ } else if (webAccessibleResourcesV2.length > 0) canonicalManifest.web_accessible_resources = Array.from(new Set(webAccessibleResourcesV2)).sort();
7281
+ const source = JSON.stringify(canonicalManifest, null, 2);
7174
7282
  const rawSource = new core_.sources.RawSource(source);
7175
7283
  if ('true' === process.env.EXTENSION_AUTHOR_MODE) try {
7176
- const v3Groups = 3 === manifest.manifest_version ? webAccessibleResourcesV3.length : 0;
7177
- const v3ResourcesTotal = 3 === manifest.manifest_version ? webAccessibleResourcesV3.reduce((sum, g)=>sum + (g.resources?.length || 0), 0) : 0;
7178
- const v2Resources = 2 === manifest.manifest_version ? webAccessibleResourcesV2.length : 0;
7284
+ const v3Groups = 3 === canonicalManifest.manifest_version ? webAccessibleResourcesV3.length : 0;
7285
+ const v3ResourcesTotal = 3 === canonicalManifest.manifest_version ? webAccessibleResourcesV3.reduce((sum, g)=>sum + (g.resources?.length || 0), 0) : 0;
7286
+ const v2Resources = 2 === canonicalManifest.manifest_version ? webAccessibleResourcesV2.length : 0;
7179
7287
  console.log(warPatchedSummary(v3Groups, v3ResourcesTotal, v2Resources));
7180
7288
  } catch {}
7181
7289
  if (compilation.getAsset('manifest.json')) compilation.updateAsset('manifest.json', rawSource);
@@ -7345,9 +7453,6 @@ Set background.noDynamicEntryWarning to true to disable this warning.
7345
7453
  function compatibilityPolyfillDisabled(browser) {
7346
7454
  return `${external_pintor_default().gray('►►►')} Compatibility: Polyfill ${external_pintor_default().gray('disabled')} for ${capitalizedBrowserName(browser)}`;
7347
7455
  }
7348
- function compatibilityManifestFilteredKeys(browser, filteredCount) {
7349
- return `${external_pintor_default().gray('►►►')} Compatibility: Filtered ${external_pintor_default().gray(String(filteredCount))} manifest key(s) for ${capitalizedBrowserName(browser)}`;
7350
- }
7351
7456
  function feature_polyfill_define_property(obj, key, value) {
7352
7457
  if (key in obj) Object.defineProperty(obj, key, {
7353
7458
  value: value,
@@ -7389,117 +7494,6 @@ Set background.noDynamicEntryWarning to true to disable this warning.
7389
7494
  this.browser = options.browser || 'chrome';
7390
7495
  }
7391
7496
  }
7392
- function manifest_parseJsonSafe(text) {
7393
- const s = text && 0xfeff === text.charCodeAt(0) ? text.slice(1) : text;
7394
- return JSON.parse(s || '{}');
7395
- }
7396
- function compatibility_lib_manifest_getManifestContent(compilation, manifestPath) {
7397
- const readAssetSource = (asset)=>{
7398
- if (!asset) return '';
7399
- const source = asset.source;
7400
- if ('string' == typeof source) return source;
7401
- if ('function' == typeof source) {
7402
- const out = source();
7403
- return 'string' == typeof out ? out : String(out || '');
7404
- }
7405
- if (source && 'function' == typeof source.source) {
7406
- const out = source.source();
7407
- return 'string' == typeof out ? out : String(out || '');
7408
- }
7409
- return '';
7410
- };
7411
- const getAsset = compilation.getAsset;
7412
- if ('function' == typeof getAsset) {
7413
- const manifestAsset = getAsset.call(compilation, 'manifest.json');
7414
- const manifest = readAssetSource(manifestAsset);
7415
- if (manifest) return manifest_parseJsonSafe(manifest);
7416
- }
7417
- const manifestAsset = compilation.assets?.['manifest.json'];
7418
- if (manifestAsset) {
7419
- const manifest = readAssetSource(manifestAsset);
7420
- if (manifest) return manifest_parseJsonSafe(manifest);
7421
- }
7422
- try {
7423
- const text = external_fs_.readFileSync(manifestPath, 'utf8');
7424
- return manifest_parseJsonSafe(text);
7425
- } catch {
7426
- return require(manifestPath);
7427
- }
7428
- }
7429
- function compatibility_lib_manifest_filterKeysForThisBrowser(manifest, browser) {
7430
- const CHROMIUM_BASED_BROWSERS = [
7431
- 'chrome',
7432
- 'edge'
7433
- ];
7434
- const GECKO_BASED_BROWSERS = [
7435
- 'firefox'
7436
- ];
7437
- const isChromiumTarget = CHROMIUM_BASED_BROWSERS.includes(browser) || String(browser).includes('chromium');
7438
- const isGeckoTarget = GECKO_BASED_BROWSERS.includes(browser) || String(browser).includes('gecko');
7439
- const chromiumPrefixes = new Set([
7440
- 'chromium',
7441
- 'chrome',
7442
- 'edge'
7443
- ]);
7444
- const geckoPrefixes = new Set([
7445
- 'gecko',
7446
- 'firefox'
7447
- ]);
7448
- const patchedManifest = JSON.parse(JSON.stringify(manifest), function(key, value) {
7449
- const indexOfColon = key.indexOf(':');
7450
- if (-1 === indexOfColon) return value;
7451
- const prefix = key.substring(0, indexOfColon);
7452
- if (prefix === browser || isChromiumTarget && chromiumPrefixes.has(prefix) || isGeckoTarget && geckoPrefixes.has(prefix)) this[key.substring(indexOfColon + 1)] = value;
7453
- });
7454
- return patchedManifest;
7455
- }
7456
- function feature_browser_specific_fields_define_property(obj, key, value) {
7457
- if (key in obj) Object.defineProperty(obj, key, {
7458
- value: value,
7459
- enumerable: true,
7460
- configurable: true,
7461
- writable: true
7462
- });
7463
- else obj[key] = value;
7464
- return obj;
7465
- }
7466
- function countBrowserPrefixedKeys(obj) {
7467
- if (!obj || 'object' != typeof obj) return 0;
7468
- if (Array.isArray(obj)) return obj.reduce((sum, v)=>sum + countBrowserPrefixedKeys(v), 0);
7469
- let total = 0;
7470
- for (const key of Object.keys(obj)){
7471
- if (key.includes(':')) total++;
7472
- total += countBrowserPrefixedKeys(obj[key]);
7473
- }
7474
- return total;
7475
- }
7476
- class BrowserSpecificFieldsPlugin {
7477
- patchManifest(manifest) {
7478
- const patchedManifest = compatibility_lib_manifest_filterKeysForThisBrowser(manifest, this.browser);
7479
- return JSON.stringify(patchedManifest, null, 2);
7480
- }
7481
- apply(compiler) {
7482
- compiler.hooks.compilation.tap('compatibility:browser-specific-fields', (compilation)=>{
7483
- compilation.hooks.processAssets.tap({
7484
- name: 'compatibility:browser-specific-fields',
7485
- stage: core_.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE
7486
- }, ()=>{
7487
- const manifest = compatibility_lib_manifest_getManifestContent(compilation, this.manifestPath);
7488
- const filteredCount = countBrowserPrefixedKeys(manifest);
7489
- const patchedSource = this.patchManifest(manifest);
7490
- const rawSource = new core_.sources.RawSource(patchedSource);
7491
- compilation.updateAsset('manifest.json', rawSource);
7492
- if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.log(compatibilityManifestFilteredKeys(this.browser, filteredCount));
7493
- });
7494
- });
7495
- }
7496
- constructor(options){
7497
- feature_browser_specific_fields_define_property(this, "browser", void 0);
7498
- feature_browser_specific_fields_define_property(this, "manifestPath", void 0);
7499
- this.manifestPath = options.manifestPath;
7500
- this.browser = options.browser || 'chrome';
7501
- }
7502
- }
7503
7497
  function plugin_compatibility_define_property(obj, key, value) {
7504
7498
  if (key in obj) Object.defineProperty(obj, key, {
7505
7499
  value: value,
@@ -7521,10 +7515,6 @@ Set background.noDynamicEntryWarning to true to disable this warning.
7521
7515
  }).apply(compiler);
7522
7516
  } else if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.log(compatibilityPolyfillSkipped('Firefox bundles browser.* APIs', this.browser));
7523
7517
  } else if ('true' === process.env.EXTENSION_AUTHOR_MODE) console.log(compatibilityPolyfillDisabled(this.browser));
7524
- new BrowserSpecificFieldsPlugin({
7525
- manifestPath: this.manifestPath,
7526
- browser: this.browser || 'chrome'
7527
- }).apply(compiler);
7528
7518
  }
7529
7519
  constructor(options){
7530
7520
  plugin_compatibility_define_property(this, "manifestPath", void 0);
@@ -8047,6 +8037,7 @@ Set background.noDynamicEntryWarning to true to disable this warning.
8047
8037
  function formatHtmlSentinelEnd() {
8048
8038
  return '<<<EXTJS_HTML_END>>>';
8049
8039
  }
8040
+ var manifest_readiness = __webpack_require__("./webpack/plugin-browsers/run-chromium/manifest-readiness.ts");
8050
8041
  function chromium_hard_reload_define_property(obj, key, value) {
8051
8042
  if (key in obj) Object.defineProperty(obj, key, {
8052
8043
  value: value,
@@ -8140,6 +8131,13 @@ Set background.noDynamicEntryWarning to true to disable this warning.
8140
8131
  reason: reason || 'unknown',
8141
8132
  browser: this.options?.browser
8142
8133
  });
8134
+ const extensionRoot = this.ctx.getExtensionRoot();
8135
+ if (extensionRoot) {
8136
+ const manifestReady = await (0, manifest_readiness.f)(extensionRoot, {
8137
+ timeoutMs: 8000
8138
+ });
8139
+ if (!manifestReady) return void this.logger?.warn?.('[reload] manifest.json did not stabilize before hard reload');
8140
+ }
8143
8141
  const reloadTimeoutMs = 8000;
8144
8142
  const ok = await Promise.race([
8145
8143
  ctrl.hardReload(),
@@ -10265,7 +10263,8 @@ Set background.noDynamicEntryWarning to true to disable this warning.
10265
10263
  clean: devOptions.output.clean,
10266
10264
  zip: true === devOptions.zip,
10267
10265
  zipSource: true === devOptions.zipSource,
10268
- zipFilename: devOptions.zipFilename
10266
+ zipFilename: devOptions.zipFilename,
10267
+ port: 'string' == typeof devOptions.port ? parseInt(devOptions.port, 10) : devOptions.port
10269
10268
  }),
10270
10269
  new StaticAssetsPlugin({
10271
10270
  manifestPath,