extension-develop 4.1.20 → 4.1.21
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/672~0.mjs +24 -1
- package/dist/747~0.mjs +4 -2
- package/dist/832~0.mjs +1 -1
- package/dist/840~0.mjs +432 -20
- package/dist/950~0.mjs +15 -24
- package/dist/command-preview.d.ts +8 -0
- package/dist/dev-server/control-bridge/consumer-client.d.ts +10 -0
- package/dist/dev-server/control-bridge/contracts.d.ts +42 -0
- package/dist/dev-server/control-bridge/logs-query.d.ts +16 -0
- package/dist/dev-server~0.mjs +2 -0
- package/dist/lib/addon-lint.d.ts +4 -1
- package/dist/lib/build-summary.d.ts +11 -0
- package/dist/lib/chunk-dependency-provenance.d.ts +14 -0
- package/dist/lib/constants.d.ts +1 -1
- package/dist/lib/manifest-utils.d.ts +2 -0
- package/dist/lib/messages.d.ts +3 -3
- package/dist/lib/package-manager.d.ts +2 -0
- package/dist/plugin-browsers/index.d.ts +28 -0
- package/dist/plugin-compilation/env.d.ts +2 -0
- package/dist/plugin-js-frameworks/js-frameworks-lib/messages.d.ts +1 -0
- package/dist/plugin-js-frameworks/js-tools/solid.d.ts +3 -0
- package/dist/plugin-js-frameworks/js-tools/typescript.d.ts +16 -0
- package/dist/plugin-perf-budgets/categorize.d.ts +2 -1
- package/dist/plugin-perf-budgets/index.d.ts +1 -1
- package/dist/plugin-reload/classify-reload.d.ts +4 -0
- package/dist/plugin-reload/index.d.ts +18 -0
- package/dist/plugin-special-folders/folder-extensions/types.d.ts +13 -0
- package/dist/plugin-web-extension/feature-manifest/messages.d.ts +1 -0
- package/dist/plugin-web-extension/feature-manifest/steps/apply-dev-defaults-lib/emitted-evidence.d.ts +22 -0
- package/dist/plugin-web-extension/feature-manifest/steps/apply-dev-defaults-lib/patch-background.d.ts +9 -0
- package/dist/plugin-web-extension/feature-manifest/steps/apply-dev-defaults-lib/patch-web-resources.d.ts +7 -16
- package/dist/plugin-web-extension/feature-manifest/steps/apply-dev-defaults.d.ts +6 -2
- package/dist/plugin-web-extension/feature-manifest/steps/warn-gecko-unsupported-apis.d.ts +2 -13
- package/dist/plugin-web-extension/feature-scripts/messages.d.ts +5 -0
- package/dist/plugin-web-extension/feature-scripts/steps/warn-page-context-worker.d.ts +5 -0
- package/dist/plugin-web-extension/feature-web-resources/collect-entry-imports.d.ts +1 -0
- package/dist/plugin-web-extension/feature-web-resources/web-resources-lib/messages.d.ts +1 -0
- package/dist/plugin-web-extension/feature-web-resources/web-resources-lib/unreachable-resources.d.ts +9 -0
- package/dist/rspack-config.d.ts +1 -1
- package/dist/rspack-config~0.mjs +430 -463
- package/dist/types.d.ts +190 -0
- package/package.json +1 -1
package/dist/rspack-config~0.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __extjsCreateRequire } from "node:module"; const require = __extjsCreateRequire(import.meta.url);
|
|
2
|
+
import core, { Compilation as core_Compilation, DefinePlugin, EntryPlugin, LightningCssMinimizerRspackPlugin, ProvidePlugin, SwcJsMinimizerRspackPlugin, WebpackError as core_WebpackError, experiments, javascript as core_javascript, library, rspack, sources as core_sources } from "@rspack/core";
|
|
2
3
|
import { createRequire } from "node:module";
|
|
3
4
|
import pintor from "pintor";
|
|
4
|
-
import core, { Compilation as core_Compilation, DefinePlugin, EntryPlugin, ProvidePlugin, WebpackError as core_WebpackError, javascript as core_javascript, library, rspack, sources as core_sources } from "@rspack/core";
|
|
5
5
|
import case_sensitive_paths_webpack_plugin from "case-sensitive-paths-webpack-plugin";
|
|
6
6
|
import { zipSync } from "fflate";
|
|
7
7
|
import ignore from "ignore";
|
|
@@ -14,12 +14,12 @@ import node_path from "node:path";
|
|
|
14
14
|
import { utils_isUrl, getBaseNode, parseHtml, manifestJsonOutputTarget, getExtname, getBaseHref, isResourceUnderDirs, getAssetsFromHtml, normalizeManifestOutputPath, manifestPageOutputTarget, canonicalizeDir, iconOutputPath, isFromIncludeList, htmlStaticAssetOutputName, isSpecialScheme, resolveStaticAttributeName, getHtmlPageDeclaredAssetPath, themeImageOutputPath, themeIconOutputPath, applyRewrittenStaticUrl, toResourceKey, cleanLeading, getFilePath, resolveAbsoluteFsPath, cleanAssetUrl, isHttpLike, resolveHtmlRefPath } from "./938~0.mjs";
|
|
15
15
|
import { prefix as messaging_prefix, isDebug } from "./852~0.mjs";
|
|
16
16
|
import { isChromiumBasedBrowser, CHROMIUM_FAMILY_ALIASES, GECKO_FAMILY_ALIASES, isWebkitBasedBrowser, isGeckoBasedBrowser } from "./331~0.mjs";
|
|
17
|
-
import { isUsingTypeScript, jsFrameworksIntegrationsEnabled, classifyEntrySurface, ensureTypeScriptConfig,
|
|
17
|
+
import { maybeUsePreact, isUsingTypeScript, jsFrameworksIntegrationsEnabled, maybeUseReact, isUsingVue, classifyEntrySurface, ensureTypeScriptConfig, resolveDevelopInstallRoot, loadLoaderOptions, getUserTypeScriptConfigFile, isUsingIntegration as messages_isUsingIntegration, maybeUseVue, maybeUseSolid, jsFrameworksHmrSummary, humanLine, ensureOptionalContractPackageResolved, jsFrameworksConfigsDetected, recordZipArtifact, hasDependency, resolveDevelopDistFile, isUsingJsxFramework, getJsxImportSource, swcParserForFile, isUsingReact, defaultSplitChunks } from "./840~0.mjs";
|
|
18
18
|
import { bundlerFatalError, bundlerRecompiling, browserRunnerDisabled, PlaywrightPlugin, publicFolderShadowed, resolveCompanionExtensionDirs, specialFoldersSetupSummary, noEntrypointsDetected, serverRestartRequiredFromSpecialFolderMessageOnly, specialFolderChangeDetected, spacerLine, messages_ready, getPreloadedEnvKeys, publicMustBeAtProjectRoot, computeExtensionsToLoad, getSpecialFoldersDataForCompiler } from "./832~0.mjs";
|
|
19
19
|
import { renderStatsBlocks, makeSanitizedConsole } from "./stats-handler~0.mjs";
|
|
20
20
|
import { stripBom, findNearestProjectManifestSync, PROJECT_MANIFEST_FILENAMES, parseJsonSafe, readProjectDependencies } from "./731~0.mjs";
|
|
21
21
|
import { EXTENSIONJS_CONTENT_SCRIPT_LAYER, getCanonicalContentScriptEntryName, parseCanonicalContentScriptAsset, CONTENT_SCRIPT_CSS_PROBE_MARKER_PREFIX, createContentScriptCssProbeMarkerPattern, getCanonicalContentScriptJsAssetName, getCanonicalContentScriptCssAssetName, isCanonicalContentScriptAsset } from "./640~0.mjs";
|
|
22
|
-
import { getURLDependencyMissing, findDroppedVendorKeys, isStaticThemeSource,
|
|
22
|
+
import { getURLDependencyMissing, findDroppedVendorKeys, isStaticThemeSource, workerStartedFromPageContext, importScriptsDependencyMissing, filterKeysForThisBrowser, findPrefixedManifestVersionKeys, injectedCompiledSourceLiteral, staticImportDependencyMissing, entrySplitAcrossInitialFiles, fetchedFileDependencyMissing, isStaticTheme, compiledSourceSpelling, injectedFileDependencyMissing, isValidManifestVersion, runtimeSetSurfaceDependencyMissing } from "./672~0.mjs";
|
|
23
23
|
import { packagingSourceFiles, debugBrowser, debugExtensionsToLoad, treeWithSourceFiles, debugOutputPath, manifestInvalidJson, getDirs, asAbsolute, treeWithDistFilesBrowser, packagingDistributionFiles, treeWithSourceAndDistFiles, toPosixPath as paths_toPosixPath, debugContextPath, noCompanionExtensionsResolved } from "./950~0.mjs";
|
|
24
24
|
import { cssMinifierDroppedRules, postCssConfigUnreadable, missingSassDependency, deadCssUrlRef, postCssPluginNotResolved, postCssConfigPluginsShape, cssIntegrationsEnabled, cssConfigsDetected, isUsingIntegration } from "./524~0.mjs";
|
|
25
25
|
import { minifierDroppedTokens, restoreVerbatimCssAssets } from "./88~0.mjs";
|
|
@@ -1193,6 +1193,24 @@ function vendorPrefixedKeyDropped(key, familyKey, vendor, browser) {
|
|
|
1193
1193
|
const vendorName = 'edge' === vendor ? 'Edge' : 'Chrome';
|
|
1194
1194
|
return `${messaging_prefix('warn')} ${pintor.yellow(key)} now applies only to ${vendorName} builds, so the ${pintor.blue(browser)} build dropped it.\nRename it to ${pintor.yellow(familyKey)} to keep it on every Chromium-based browser. Leave it as is if it's meant for ${vendorName} only.`;
|
|
1195
1195
|
}
|
|
1196
|
+
function prefixScope(prefix) {
|
|
1197
|
+
if ('chrome' === prefix) return 'Chrome';
|
|
1198
|
+
if ('edge' === prefix) return 'Edge';
|
|
1199
|
+
if ('chromium' === prefix) return 'Chromium-based';
|
|
1200
|
+
if ('firefox' === prefix || 'gecko' === prefix) return 'Firefox-based';
|
|
1201
|
+
if ('safari' === prefix || 'webkit' === prefix) return 'Safari';
|
|
1202
|
+
return prefix;
|
|
1203
|
+
}
|
|
1204
|
+
function manifestVersionLostForBrowser(browser, prefixedKeys, resolved) {
|
|
1205
|
+
const target = pintor.blue(browser);
|
|
1206
|
+
const field = pintor.yellow('manifest_version');
|
|
1207
|
+
const scoped = prefixedKeys.map((key)=>{
|
|
1208
|
+
const scope = prefixScope(key.substring(0, key.indexOf(':')));
|
|
1209
|
+
return `${pintor.yellow(key)} applies only to ${scope} builds`;
|
|
1210
|
+
});
|
|
1211
|
+
const lead = void 0 === resolved ? scoped.length ? `${scoped.join(', ')}, so the ${target} build has no ${field}.` : `The ${target} build has no ${field}.` : `The ${target} build resolved ${field} to ${pintor.yellow(JSON.stringify(resolved))}, and browsers load only 2 or 3.`;
|
|
1212
|
+
return `${messaging_prefix('error')} ${lead}\nNo browser loads a manifest without it, so the build was refused. Add a plain ${field}, or scope one to this browser: ${pintor.yellow('chromium:manifest_version')} for every Chromium-based browser, ${pintor.yellow('firefox:manifest_version')} for Firefox.`;
|
|
1213
|
+
}
|
|
1196
1214
|
function edgeStoreKeyDropped(browser) {
|
|
1197
1215
|
return `${messaging_prefix('warn')} Edge Add-ons refuses a package whose manifest carries ${pintor.yellow('key')}, so the ${pintor.blue(browser)} production build dropped it.\nPartner Center assigns the id that ${pintor.yellow('key')} pins everywhere else, so the field has no use in this package. Write it as ${pintor.yellow('chrome:key')} if it is meant for the Chrome Web Store build only.`;
|
|
1198
1216
|
}
|
|
@@ -1516,6 +1534,13 @@ function buildCanonicalManifest(manifestPath, manifest, browser, projectPath) {
|
|
|
1516
1534
|
return webkit.manifest;
|
|
1517
1535
|
}
|
|
1518
1536
|
const IMPORT_META_URL_RUNTIME = '(function(){var h=typeof document!=="undefined"&&document.baseURI||self.location.href;try{var g=globalThis,r=(g.browser||g.chrome).runtime.getURL("/");return h.indexOf(r)===0?h:r}catch(_){return h}})()';
|
|
1537
|
+
function importMetaUrlForEmitPath(emitPath) {
|
|
1538
|
+
const request = emitPath.replace(/\\/g, '/').replace(/^\/+/, '');
|
|
1539
|
+
return `(function(){try{var g=globalThis;return (g.browser||g.chrome).runtime.getURL(${toJsStringLiteral(request)})}catch(_){return ${IMPORT_META_URL_RUNTIME}}})()`;
|
|
1540
|
+
}
|
|
1541
|
+
function toJsStringLiteral(value) {
|
|
1542
|
+
return JSON.stringify(value).replace(/[<>\u007f-\uffff]/g, (char)=>`\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`);
|
|
1543
|
+
}
|
|
1519
1544
|
function resolveProcessShim() {
|
|
1520
1545
|
const candidate = __rspack_external_node_path_806ed179.join(__rspack_import_meta_dirname__, '..', 'runtime', 'process-shim.cjs');
|
|
1521
1546
|
try {
|
|
@@ -1628,7 +1653,6 @@ class EnvPlugin {
|
|
|
1628
1653
|
filteredEnvVars['import.meta.dirname'] = 'undefined';
|
|
1629
1654
|
filteredEnvVars['import.meta.filename'] = 'undefined';
|
|
1630
1655
|
filteredEnvVars.global = 'globalThis';
|
|
1631
|
-
filteredEnvVars['import.meta.url'] = IMPORT_META_URL_RUNTIME;
|
|
1632
1656
|
const injectedCount = Object.keys(filteredEnvVars).filter((k)=>k.startsWith('process.env.EXTENSION_PUBLIC_')).length;
|
|
1633
1657
|
if (isDebug()) console.log(envInjectedPublicVars(injectedCount));
|
|
1634
1658
|
const processShim = resolveProcessShim();
|
|
@@ -1637,6 +1661,11 @@ class EnvPlugin {
|
|
|
1637
1661
|
filteredEnvVars.process = '({env:{},argv:[],platform:"browser",browser:true,versions:{},nextTick:function(cb){Promise.resolve().then(function(){cb()})}})';
|
|
1638
1662
|
}
|
|
1639
1663
|
new DefinePlugin(filteredEnvVars).apply(compiler);
|
|
1664
|
+
const importMetaUrl = new DefinePlugin({
|
|
1665
|
+
'import.meta.url': IMPORT_META_URL_RUNTIME
|
|
1666
|
+
});
|
|
1667
|
+
importMetaUrl.affectedHooks = 'thisCompilation';
|
|
1668
|
+
importMetaUrl.apply(compiler);
|
|
1640
1669
|
if (processShim) new ProvidePlugin({
|
|
1641
1670
|
process: processShim
|
|
1642
1671
|
}).apply(compiler);
|
|
@@ -2902,294 +2931,8 @@ function getResolvedManifestFieldsData(options) {
|
|
|
2902
2931
|
return data;
|
|
2903
2932
|
}
|
|
2904
2933
|
}
|
|
2905
|
-
let preact_userMessageDelivered = false;
|
|
2906
|
-
function isUsingPreact(projectPath) {
|
|
2907
|
-
if (hasDependency(projectPath, 'preact')) {
|
|
2908
|
-
if (!preact_userMessageDelivered) {
|
|
2909
|
-
if (isDebug()) console.log(`${messaging_prefix('debug')} ${messages_isUsingIntegration('Preact')}`);
|
|
2910
|
-
preact_userMessageDelivered = true;
|
|
2911
|
-
}
|
|
2912
|
-
return true;
|
|
2913
|
-
}
|
|
2914
|
-
return false;
|
|
2915
|
-
}
|
|
2916
|
-
async function maybeUsePreact(projectPath) {
|
|
2917
|
-
if (!isUsingPreact(projectPath)) return;
|
|
2918
|
-
const requireFromProject = createRequire(__rspack_external_node_path_806ed179.join(projectPath, 'package.json'));
|
|
2919
|
-
const resolveFromProject = (id)=>{
|
|
2920
|
-
try {
|
|
2921
|
-
return requireFromProject.resolve(id);
|
|
2922
|
-
} catch {
|
|
2923
|
-
return;
|
|
2924
|
-
}
|
|
2925
|
-
};
|
|
2926
|
-
const preactPkgJson = resolveFromProject('preact/package.json');
|
|
2927
|
-
const preactDir = preactPkgJson ? __rspack_external_node_path_806ed179.dirname(preactPkgJson) : void 0;
|
|
2928
|
-
const preactCompat = resolveFromProject('preact/compat');
|
|
2929
|
-
const preactTestUtils = resolveFromProject('preact/test-utils');
|
|
2930
|
-
const preactJsxRuntime = resolveFromProject('preact/jsx-runtime');
|
|
2931
|
-
const preactJsxDevRuntime = resolveFromProject('preact/jsx-dev-runtime');
|
|
2932
|
-
const alias = {};
|
|
2933
|
-
if (preactJsxRuntime) alias['preact/jsx-runtime'] = preactJsxRuntime;
|
|
2934
|
-
if (preactJsxDevRuntime) alias['preact/jsx-dev-runtime'] = preactJsxDevRuntime;
|
|
2935
|
-
if (preactDir) alias.preact = preactDir;
|
|
2936
|
-
if (preactCompat) {
|
|
2937
|
-
alias.react = preactCompat;
|
|
2938
|
-
alias['react-dom'] = preactCompat;
|
|
2939
|
-
}
|
|
2940
|
-
if (preactTestUtils) alias['react-dom/test-utils'] = preactTestUtils;
|
|
2941
|
-
if (preactJsxRuntime) alias['react/jsx-runtime'] = preactJsxRuntime;
|
|
2942
|
-
if (preactJsxDevRuntime) alias['react/jsx-dev-runtime'] = preactJsxDevRuntime;
|
|
2943
|
-
return {
|
|
2944
|
-
plugins: [],
|
|
2945
|
-
loaders: void 0,
|
|
2946
|
-
alias
|
|
2947
|
-
};
|
|
2948
|
-
}
|
|
2949
|
-
let react_userMessageDelivered = false;
|
|
2950
|
-
function isUsingReact(projectPath) {
|
|
2951
|
-
if (hasDependency(projectPath, 'react')) {
|
|
2952
|
-
if (!react_userMessageDelivered) {
|
|
2953
|
-
if (isDebug()) console.log(`${messaging_prefix('debug')} ${messages_isUsingIntegration('React')}`);
|
|
2954
|
-
react_userMessageDelivered = true;
|
|
2955
|
-
}
|
|
2956
|
-
return true;
|
|
2957
|
-
}
|
|
2958
|
-
return false;
|
|
2959
|
-
}
|
|
2960
|
-
async function maybeUseReact(projectPath, options = {}) {
|
|
2961
|
-
if (!isUsingReact(projectPath)) return;
|
|
2962
|
-
const requireFromProject = createRequire(__rspack_external_node_path_806ed179.join(projectPath, 'package.json'));
|
|
2963
|
-
let reactPath;
|
|
2964
|
-
let reactDomPath;
|
|
2965
|
-
let reactDomClientPath;
|
|
2966
|
-
let jsxRuntimePath;
|
|
2967
|
-
let jsxDevRuntimePath;
|
|
2968
|
-
try {
|
|
2969
|
-
reactPath = requireFromProject.resolve('react');
|
|
2970
|
-
} catch {}
|
|
2971
|
-
try {
|
|
2972
|
-
reactDomPath = requireFromProject.resolve('react-dom');
|
|
2973
|
-
} catch {}
|
|
2974
|
-
try {
|
|
2975
|
-
reactDomClientPath = requireFromProject.resolve('react-dom/client');
|
|
2976
|
-
} catch {}
|
|
2977
|
-
try {
|
|
2978
|
-
jsxRuntimePath = requireFromProject.resolve('react/jsx-runtime');
|
|
2979
|
-
} catch {}
|
|
2980
|
-
try {
|
|
2981
|
-
jsxDevRuntimePath = requireFromProject.resolve('react/jsx-dev-runtime');
|
|
2982
|
-
} catch {}
|
|
2983
|
-
const alias = {};
|
|
2984
|
-
if (reactPath) alias.react$ = reactPath;
|
|
2985
|
-
if (reactDomPath) alias['react-dom$'] = reactDomPath;
|
|
2986
|
-
if (reactDomClientPath) alias['react-dom/client'] = reactDomClientPath;
|
|
2987
|
-
if (jsxRuntimePath) alias['react/jsx-runtime'] = jsxRuntimePath;
|
|
2988
|
-
if (jsxDevRuntimePath) alias['react/jsx-dev-runtime'] = jsxDevRuntimePath;
|
|
2989
|
-
if (true === options.disableRefresh) return {
|
|
2990
|
-
plugins: [],
|
|
2991
|
-
loaders: void 0,
|
|
2992
|
-
alias
|
|
2993
|
-
};
|
|
2994
|
-
resolveOptionalContractPackageWithoutInstall({
|
|
2995
|
-
contractId: 'react-refresh',
|
|
2996
|
-
projectPath,
|
|
2997
|
-
dependencyId: 'react-refresh'
|
|
2998
|
-
});
|
|
2999
|
-
const ReactRefreshPlugin = loadOptionalContractModuleWithoutInstall({
|
|
3000
|
-
contractId: 'react-refresh',
|
|
3001
|
-
projectPath,
|
|
3002
|
-
dependencyId: '@rspack/plugin-react-refresh',
|
|
3003
|
-
moduleAdapter: (mod)=>mod && (mod.default || mod.ReactRefreshRspackPlugin) || mod
|
|
3004
|
-
});
|
|
3005
|
-
const reactPlugins = [
|
|
3006
|
-
new ReactRefreshPlugin({
|
|
3007
|
-
overlay: false,
|
|
3008
|
-
...void 0 === options.refreshExclude ? {} : {
|
|
3009
|
-
exclude: options.refreshExclude
|
|
3010
|
-
}
|
|
3011
|
-
})
|
|
3012
|
-
];
|
|
3013
|
-
return {
|
|
3014
|
-
plugins: reactPlugins,
|
|
3015
|
-
loaders: void 0,
|
|
3016
|
-
alias
|
|
3017
|
-
};
|
|
3018
|
-
}
|
|
3019
|
-
let solid_userMessageDelivered = false;
|
|
3020
|
-
function isUsingSolid(projectPath) {
|
|
3021
|
-
if (hasDependency(projectPath, 'solid-js')) {
|
|
3022
|
-
if (!solid_userMessageDelivered) {
|
|
3023
|
-
if (isDebug()) console.log(`${messaging_prefix('debug')} ${messages_isUsingIntegration('Solid')}`);
|
|
3024
|
-
solid_userMessageDelivered = true;
|
|
3025
|
-
}
|
|
3026
|
-
return true;
|
|
3027
|
-
}
|
|
3028
|
-
return false;
|
|
3029
|
-
}
|
|
3030
|
-
async function maybeUseSolid(projectPath) {
|
|
3031
|
-
if (!isUsingSolid(projectPath)) return;
|
|
3032
|
-
const requireFromProject = createRequire(__rspack_external_node_path_806ed179.join(projectPath, 'package.json'));
|
|
3033
|
-
const resolveFromProject = (id)=>{
|
|
3034
|
-
try {
|
|
3035
|
-
return requireFromProject.resolve(id);
|
|
3036
|
-
} catch {
|
|
3037
|
-
return;
|
|
3038
|
-
}
|
|
3039
|
-
};
|
|
3040
|
-
const adapter = resolveDevelopDistFile('solid-jsx-runtime');
|
|
3041
|
-
const hyperscript = resolveFromProject('solid-js/h');
|
|
3042
|
-
const alias = {
|
|
3043
|
-
'solid-js/jsx-runtime$': adapter,
|
|
3044
|
-
'solid-js/jsx-dev-runtime$': adapter
|
|
3045
|
-
};
|
|
3046
|
-
if (hyperscript) alias['solid-js/h$'] = hyperscript;
|
|
3047
|
-
return {
|
|
3048
|
-
plugins: [],
|
|
3049
|
-
loaders: void 0,
|
|
3050
|
-
alias
|
|
3051
|
-
};
|
|
3052
|
-
}
|
|
3053
|
-
let load_loader_options_userMessageDelivered = false;
|
|
3054
|
-
function resolveLoaderConfigPath(projectPath, framework) {
|
|
3055
|
-
const candidates = [
|
|
3056
|
-
__rspack_external_node_path_806ed179.join(projectPath, `${framework}.loader.ts`),
|
|
3057
|
-
__rspack_external_node_path_806ed179.join(projectPath, `${framework}.loader.mts`),
|
|
3058
|
-
__rspack_external_node_path_806ed179.join(projectPath, `${framework}.loader.js`),
|
|
3059
|
-
__rspack_external_node_path_806ed179.join(projectPath, `${framework}.loader.mjs`)
|
|
3060
|
-
];
|
|
3061
|
-
return candidates.find((p)=>__rspack_external_node_fs_1b05aee1.existsSync(p)) || null;
|
|
3062
|
-
}
|
|
3063
|
-
async function loadLoaderOptions(projectPath, framework) {
|
|
3064
|
-
const configPath = resolveLoaderConfigPath(projectPath, framework);
|
|
3065
|
-
if (configPath) {
|
|
3066
|
-
if (!load_loader_options_userMessageDelivered && isDebug()) {
|
|
3067
|
-
const display = __rspack_external_node_path_806ed179.basename(configPath);
|
|
3068
|
-
console.log(isUsingCustomLoader(display));
|
|
3069
|
-
load_loader_options_userMessageDelivered = true;
|
|
3070
|
-
}
|
|
3071
|
-
try {
|
|
3072
|
-
const module = await import(pathToFileURL(configPath).href);
|
|
3073
|
-
return module.default || module;
|
|
3074
|
-
} catch (err) {
|
|
3075
|
-
const error = err;
|
|
3076
|
-
console.error(`Error loading ${framework} loader options: ${error.message}`);
|
|
3077
|
-
throw err;
|
|
3078
|
-
}
|
|
3079
|
-
}
|
|
3080
|
-
return null;
|
|
3081
|
-
}
|
|
3082
|
-
let vue_userMessageDelivered = false;
|
|
3083
|
-
function isUsingVue(projectPath) {
|
|
3084
|
-
const using = hasDependency(projectPath, 'vue');
|
|
3085
|
-
if (using && !vue_userMessageDelivered) {
|
|
3086
|
-
if (isDebug()) console.log(`${messaging_prefix('debug')} ${messages_isUsingIntegration('Vue')}`);
|
|
3087
|
-
vue_userMessageDelivered = true;
|
|
3088
|
-
}
|
|
3089
|
-
return using;
|
|
3090
|
-
}
|
|
3091
|
-
function resolveVueBundlerEntry(requireFromProject, id) {
|
|
3092
|
-
try {
|
|
3093
|
-
const manifestPath = requireFromProject.resolve(`${id}/package.json`);
|
|
3094
|
-
const manifest = JSON.parse(__rspack_external_node_fs_1b05aee1.readFileSync(manifestPath, 'utf8'));
|
|
3095
|
-
if ('string' == typeof manifest.module && manifest.module) {
|
|
3096
|
-
const entry = __rspack_external_node_path_806ed179.join(__rspack_external_node_path_806ed179.dirname(manifestPath), manifest.module);
|
|
3097
|
-
if (__rspack_external_node_fs_1b05aee1.existsSync(entry)) return entry;
|
|
3098
|
-
}
|
|
3099
|
-
} catch {}
|
|
3100
|
-
try {
|
|
3101
|
-
return requireFromProject.resolve(id);
|
|
3102
|
-
} catch {
|
|
3103
|
-
return;
|
|
3104
|
-
}
|
|
3105
|
-
}
|
|
3106
|
-
async function maybeUseVue(projectPath, mode = 'development') {
|
|
3107
|
-
if (!isUsingVue(projectPath)) return;
|
|
3108
|
-
const vueLoaderPath = await ensureOptionalContractPackageResolved({
|
|
3109
|
-
contractId: 'vue',
|
|
3110
|
-
projectPath,
|
|
3111
|
-
dependencyId: 'vue-loader'
|
|
3112
|
-
});
|
|
3113
|
-
const VueLoaderPlugin = await ensureOptionalContractModuleLoaded({
|
|
3114
|
-
contractId: 'vue',
|
|
3115
|
-
projectPath,
|
|
3116
|
-
dependencyId: 'vue-loader',
|
|
3117
|
-
moduleAdapter: (mod)=>mod?.VueLoaderPlugin || mod?.default?.VueLoaderPlugin
|
|
3118
|
-
});
|
|
3119
|
-
const customOptions = await loadLoaderOptions(projectPath, 'vue');
|
|
3120
|
-
const defaultLoaders = [
|
|
3121
|
-
{
|
|
3122
|
-
test: /\.vue$/,
|
|
3123
|
-
loader: vueLoaderPath,
|
|
3124
|
-
options: {
|
|
3125
|
-
experimentalInlineMatchResource: true,
|
|
3126
|
-
...customOptions || {}
|
|
3127
|
-
},
|
|
3128
|
-
include: projectPath,
|
|
3129
|
-
exclude: /node_modules/
|
|
3130
|
-
}
|
|
3131
|
-
];
|
|
3132
|
-
const isProd = 'production' === mode;
|
|
3133
|
-
const defaultPlugins = [
|
|
3134
|
-
new VueLoaderPlugin(),
|
|
3135
|
-
new DefinePlugin({
|
|
3136
|
-
__VUE_OPTIONS_API__: JSON.stringify(true),
|
|
3137
|
-
__VUE_PROD_DEVTOOLS__: JSON.stringify(!isProd),
|
|
3138
|
-
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: JSON.stringify(!isProd)
|
|
3139
|
-
})
|
|
3140
|
-
];
|
|
3141
|
-
const requireFromProject = createRequire(__rspack_external_node_path_806ed179.join(projectPath, 'package.json'));
|
|
3142
|
-
const resolveFromProject = (id)=>resolveVueBundlerEntry(requireFromProject, id);
|
|
3143
|
-
const alias = {};
|
|
3144
|
-
const vuePath = resolveFromProject('vue');
|
|
3145
|
-
const vueRuntimeDom = resolveFromProject('@vue/runtime-dom');
|
|
3146
|
-
const vueRuntimeCore = resolveFromProject('@vue/runtime-core');
|
|
3147
|
-
const vueShared = resolveFromProject('@vue/shared');
|
|
3148
|
-
if (vuePath) alias.vue$ = vuePath;
|
|
3149
|
-
if (vueRuntimeDom) alias['@vue/runtime-dom'] = vueRuntimeDom;
|
|
3150
|
-
if (vueRuntimeCore) alias['@vue/runtime-core'] = vueRuntimeCore;
|
|
3151
|
-
if (vueShared) alias['@vue/shared'] = vueShared;
|
|
3152
|
-
return {
|
|
3153
|
-
plugins: defaultPlugins,
|
|
3154
|
-
loaders: defaultLoaders,
|
|
3155
|
-
alias
|
|
3156
|
-
};
|
|
3157
|
-
}
|
|
3158
|
-
function isUsingJsxFramework(projectPath) {
|
|
3159
|
-
return isUsingReact(projectPath) || isUsingPreact(projectPath) || isUsingSolid(projectPath) || isUsingVue(projectPath);
|
|
3160
|
-
}
|
|
3161
|
-
function getJsxImportSource(projectPath) {
|
|
3162
|
-
if (isUsingSolid(projectPath)) return 'solid-js';
|
|
3163
|
-
if (isUsingPreact(projectPath) && !isUsingReact(projectPath)) return 'preact';
|
|
3164
|
-
if (isUsingVue(projectPath) && !isUsingReact(projectPath) && !isUsingPreact(projectPath)) return 'vue';
|
|
3165
|
-
return 'react';
|
|
3166
|
-
}
|
|
3167
|
-
function swcParserForFile(resourcePath, jsxInPlainJs) {
|
|
3168
|
-
const clean = String(resourcePath || '').split('?')[0];
|
|
3169
|
-
const ext = __rspack_external_node_path_806ed179.extname(clean).toLowerCase();
|
|
3170
|
-
if ('.tsx' === ext || '.mtsx' === ext) return {
|
|
3171
|
-
syntax: "typescript",
|
|
3172
|
-
tsx: true,
|
|
3173
|
-
dynamicImport: true
|
|
3174
|
-
};
|
|
3175
|
-
if ('.ts' === ext || '.mts' === ext || '.cts' === ext) return {
|
|
3176
|
-
syntax: "typescript",
|
|
3177
|
-
tsx: false,
|
|
3178
|
-
dynamicImport: true
|
|
3179
|
-
};
|
|
3180
|
-
if ('.jsx' === ext || '.mjsx' === ext) return {
|
|
3181
|
-
syntax: "ecmascript",
|
|
3182
|
-
jsx: true,
|
|
3183
|
-
dynamicImport: true
|
|
3184
|
-
};
|
|
3185
|
-
return {
|
|
3186
|
-
syntax: "ecmascript",
|
|
3187
|
-
jsx: jsxInPlainJs,
|
|
3188
|
-
dynamicImport: true
|
|
3189
|
-
};
|
|
3190
|
-
}
|
|
3191
2934
|
let svelte_userMessageDelivered = false;
|
|
3192
|
-
function
|
|
2935
|
+
function resolveFromProject(id, projectPath) {
|
|
3193
2936
|
for (const base of [
|
|
3194
2937
|
projectPath,
|
|
3195
2938
|
process.cwd()
|
|
@@ -3246,10 +2989,10 @@ async function maybeUseSvelte(projectPath, mode) {
|
|
|
3246
2989
|
}
|
|
3247
2990
|
}
|
|
3248
2991
|
];
|
|
3249
|
-
const sveltePackageJson =
|
|
2992
|
+
const sveltePackageJson = resolveFromProject('svelte/package.json', projectPath);
|
|
3250
2993
|
const sveltePackageRoot = sveltePackageJson ? __rspack_external_node_path_806ed179.dirname(sveltePackageJson) : void 0;
|
|
3251
2994
|
const resolveClientSubpath = (relative)=>{
|
|
3252
|
-
const direct =
|
|
2995
|
+
const direct = resolveFromProject(`svelte/${relative}`, projectPath);
|
|
3253
2996
|
if (direct) return direct;
|
|
3254
2997
|
if (!sveltePackageRoot) return;
|
|
3255
2998
|
const fromRoot = __rspack_external_node_path_806ed179.join(sveltePackageRoot, relative);
|
|
@@ -7179,16 +6922,10 @@ class TraceRun {
|
|
|
7179
6922
|
async function compileRuntimeLoadedFiles(compilation, compiler, requests) {
|
|
7180
6923
|
if (0 === requests.length) return [];
|
|
7181
6924
|
const before = new Set(compilation.getAssets().map((asset)=>asset.name));
|
|
7182
|
-
for (const
|
|
7183
|
-
|
|
7184
|
-
|
|
7185
|
-
|
|
7186
|
-
const group = requests.filter((request)=>request.format === format);
|
|
7187
|
-
if (0 !== group.length) await compileTracedFiles({
|
|
7188
|
-
compilation,
|
|
7189
|
-
compiler
|
|
7190
|
-
}, format, group);
|
|
7191
|
-
}
|
|
6925
|
+
for (const request of requests)await compileTracedFile({
|
|
6926
|
+
compilation,
|
|
6927
|
+
compiler
|
|
6928
|
+
}, request);
|
|
7192
6929
|
return compilation.getAssets().map((asset)=>asset.name).filter((name)=>!before.has(name));
|
|
7193
6930
|
}
|
|
7194
6931
|
function planTracedFile(opts) {
|
|
@@ -7272,21 +7009,24 @@ function isFile(candidate) {
|
|
|
7272
7009
|
return false;
|
|
7273
7010
|
}
|
|
7274
7011
|
}
|
|
7275
|
-
async function
|
|
7012
|
+
async function compileTracedFile(host, request) {
|
|
7276
7013
|
const { compilation, compiler } = host;
|
|
7277
|
-
const isModule = 'module' === format;
|
|
7278
|
-
const
|
|
7279
|
-
const
|
|
7280
|
-
|
|
7281
|
-
|
|
7282
|
-
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
|
|
7286
|
-
|
|
7287
|
-
|
|
7288
|
-
|
|
7289
|
-
const
|
|
7014
|
+
const isModule = 'module' === request.format;
|
|
7015
|
+
const chunkLoading = isModule ? 'import' : 'importScripts' === request.context ? "import-scripts" : 'jsonp';
|
|
7016
|
+
const entry = new EntryPlugin(compiler.context, request.sourcePath, {
|
|
7017
|
+
name: request.emitPath.replace(/\.[^./]+$/, ''),
|
|
7018
|
+
filename: request.emitPath,
|
|
7019
|
+
chunkLoading,
|
|
7020
|
+
...isModule ? {
|
|
7021
|
+
library: {
|
|
7022
|
+
type: 'module'
|
|
7023
|
+
}
|
|
7024
|
+
} : {}
|
|
7025
|
+
});
|
|
7026
|
+
const importMetaUrl = new DefinePlugin({
|
|
7027
|
+
'import.meta.url': importMetaUrlForEmitPath(request.emitPath)
|
|
7028
|
+
});
|
|
7029
|
+
const child = compilation.createChildCompiler(`${TraceRuntimeLoadedFiles.name}:${request.format}`, {
|
|
7290
7030
|
filename: '[name].js',
|
|
7291
7031
|
module: isModule,
|
|
7292
7032
|
iife: false,
|
|
@@ -7296,8 +7036,11 @@ async function compileTracedFiles(host, format, requests) {
|
|
|
7296
7036
|
type: 'module'
|
|
7297
7037
|
} : void 0,
|
|
7298
7038
|
clean: false
|
|
7299
|
-
},
|
|
7300
|
-
|
|
7039
|
+
}, [
|
|
7040
|
+
entry,
|
|
7041
|
+
importMetaUrl
|
|
7042
|
+
]);
|
|
7043
|
+
new core_javascript.EnableChunkLoadingPlugin(chunkLoading).apply(child);
|
|
7301
7044
|
if (isModule) new library.EnableLibraryPlugin('module').apply(child);
|
|
7302
7045
|
child.options.entry = {};
|
|
7303
7046
|
child.options.optimization = {
|
|
@@ -7313,7 +7056,7 @@ async function compileTracedFiles(host, format, requests) {
|
|
|
7313
7056
|
await new Promise((resolve)=>{
|
|
7314
7057
|
child.runAsChild((error, _entries, childCompilation)=>{
|
|
7315
7058
|
if (error) {
|
|
7316
|
-
const failure = new core_WebpackError(`Compiling runtime-loaded ${
|
|
7059
|
+
const failure = new core_WebpackError(`Compiling runtime-loaded ${request.emitPath} failed: ${error.message}`);
|
|
7317
7060
|
failure.name = 'RuntimeLoadedFileCompileFailed';
|
|
7318
7061
|
compilation.errors.push(failure);
|
|
7319
7062
|
}
|
|
@@ -10663,6 +10406,71 @@ function partiallyGatedWarning(api, relative) {
|
|
|
10663
10406
|
if (!note) return null;
|
|
10664
10407
|
return `manifest.json does not declare the "${api}" permission, but ${relative} uses chrome.${api}. The dev build injects "${api}" so the same code may behave differently once packaged: ${note}. Add "${api}" to permissions in manifest.json if you read those fields.`;
|
|
10665
10408
|
}
|
|
10409
|
+
const EMITTED_SCRIPT_RE = /\.[cm]?js$/;
|
|
10410
|
+
const MAX_SOURCE_BYTES = 1048576;
|
|
10411
|
+
const MAX_ASSET_BYTES = 16777216;
|
|
10412
|
+
const MAX_COMPRESS_BYTES = 4194304;
|
|
10413
|
+
function shippableText(text) {
|
|
10414
|
+
if (text.length > MAX_COMPRESS_BYTES) return text;
|
|
10415
|
+
try {
|
|
10416
|
+
const compressed = experiments?.swc?.minifySync(text, {
|
|
10417
|
+
compress: true,
|
|
10418
|
+
mangle: false
|
|
10419
|
+
});
|
|
10420
|
+
return 'string' == typeof compressed?.code ? compressed.code : text;
|
|
10421
|
+
} catch {
|
|
10422
|
+
return text;
|
|
10423
|
+
}
|
|
10424
|
+
}
|
|
10425
|
+
function readEmittedScripts(compilation) {
|
|
10426
|
+
const scripts = new Map();
|
|
10427
|
+
let assets;
|
|
10428
|
+
try {
|
|
10429
|
+
assets = compilation.getAssets?.() || [];
|
|
10430
|
+
} catch {
|
|
10431
|
+
return scripts;
|
|
10432
|
+
}
|
|
10433
|
+
for (const asset of assets)if (EMITTED_SCRIPT_RE.test(asset.name)) try {
|
|
10434
|
+
const raw = asset.source.source();
|
|
10435
|
+
const text = 'string' == typeof raw ? raw : raw.toString('utf-8');
|
|
10436
|
+
if (text.length > MAX_ASSET_BYTES) continue;
|
|
10437
|
+
scripts.set(asset.name, text);
|
|
10438
|
+
} catch {}
|
|
10439
|
+
return scripts;
|
|
10440
|
+
}
|
|
10441
|
+
function readProjectSource(resource) {
|
|
10442
|
+
try {
|
|
10443
|
+
if (__rspack_external_node_fs_1b05aee1.statSync(resource).size > MAX_SOURCE_BYTES) return;
|
|
10444
|
+
return __rspack_external_node_fs_1b05aee1.readFileSync(resource, 'utf-8');
|
|
10445
|
+
} catch {
|
|
10446
|
+
return;
|
|
10447
|
+
}
|
|
10448
|
+
}
|
|
10449
|
+
function emittedFilesOf(compilation, module) {
|
|
10450
|
+
if (!compilation.chunkGraph) return;
|
|
10451
|
+
try {
|
|
10452
|
+
const files = [];
|
|
10453
|
+
for (const chunk of compilation.chunkGraph.getModuleChunksIterable(module))for (const file of chunk.files || [])files.push(file);
|
|
10454
|
+
return files;
|
|
10455
|
+
} catch {
|
|
10456
|
+
return;
|
|
10457
|
+
}
|
|
10458
|
+
}
|
|
10459
|
+
function patchWebkitBackground(manifest, browser) {
|
|
10460
|
+
if (!isWebkitBasedBrowser(String(browser))) return manifest;
|
|
10461
|
+
const background = manifest.background;
|
|
10462
|
+
if (!background || !background.service_worker || background.scripts) return manifest;
|
|
10463
|
+
const { service_worker, type, ...rest } = background;
|
|
10464
|
+
return {
|
|
10465
|
+
...manifest,
|
|
10466
|
+
background: {
|
|
10467
|
+
...rest,
|
|
10468
|
+
scripts: [
|
|
10469
|
+
service_worker
|
|
10470
|
+
]
|
|
10471
|
+
}
|
|
10472
|
+
};
|
|
10473
|
+
}
|
|
10666
10474
|
function persistentPatchFor(manifest) {
|
|
10667
10475
|
return 3 === manifest.manifest_version ? {} : {
|
|
10668
10476
|
persistent: true
|
|
@@ -10690,12 +10498,16 @@ function patchBackground(manifest, browser) {
|
|
|
10690
10498
|
...persistentPatchFor(manifest)
|
|
10691
10499
|
}
|
|
10692
10500
|
};
|
|
10693
|
-
|
|
10501
|
+
const injected = {
|
|
10502
|
+
...manifest,
|
|
10694
10503
|
background: {
|
|
10695
10504
|
...manifest.background || {},
|
|
10696
10505
|
service_worker: 'background/service_worker.js'
|
|
10697
10506
|
}
|
|
10698
10507
|
};
|
|
10508
|
+
return {
|
|
10509
|
+
background: patchWebkitBackground(injected, browser).background
|
|
10510
|
+
};
|
|
10699
10511
|
}
|
|
10700
10512
|
return {
|
|
10701
10513
|
background: {
|
|
@@ -10841,87 +10653,88 @@ function patchExternallyConnectable(manifest) {
|
|
|
10841
10653
|
};
|
|
10842
10654
|
return {};
|
|
10843
10655
|
}
|
|
10656
|
+
function cleanMatches(matches) {
|
|
10657
|
+
return matches.map((match)=>{
|
|
10658
|
+
try {
|
|
10659
|
+
const url = new URL(match.replace(/^\*:\/\//, 'https://'));
|
|
10660
|
+
if (match.endsWith(url.pathname)) return `${match.substring(0, match.length - url.pathname.length)}/*`;
|
|
10661
|
+
if ('/' === url.pathname) return `${match}/*`;
|
|
10662
|
+
return match;
|
|
10663
|
+
} catch {
|
|
10664
|
+
return match;
|
|
10665
|
+
}
|
|
10666
|
+
});
|
|
10667
|
+
}
|
|
10668
|
+
const DEV_RUNTIME_RESOURCES = [
|
|
10669
|
+
'hot/*',
|
|
10670
|
+
'extension-js-control.json'
|
|
10671
|
+
];
|
|
10672
|
+
function patch_web_resources_contentScriptMatches(manifest) {
|
|
10673
|
+
const scripts = manifest.content_scripts || [];
|
|
10674
|
+
return Array.from(new Set(cleanMatches(scripts.flatMap((script)=>script.matches || [])))).sort();
|
|
10675
|
+
}
|
|
10844
10676
|
function patchWebResourcesV2(manifest) {
|
|
10845
|
-
const defaultResources = [
|
|
10846
|
-
'/*.json',
|
|
10847
|
-
'/*.js',
|
|
10848
|
-
'/*.css',
|
|
10849
|
-
'/*.scss',
|
|
10850
|
-
'/*.sass',
|
|
10851
|
-
'/*.less',
|
|
10852
|
-
'*.styl',
|
|
10853
|
-
"/scripts/*.js",
|
|
10854
|
-
"/scripts/*.css",
|
|
10855
|
-
'/hot/*',
|
|
10856
|
-
'/*.png',
|
|
10857
|
-
'/*.jpg',
|
|
10858
|
-
'/*.jpeg',
|
|
10859
|
-
'/*.svg',
|
|
10860
|
-
'/*.gif',
|
|
10861
|
-
'/*.webp',
|
|
10862
|
-
'/*.ico',
|
|
10863
|
-
'/*.avif',
|
|
10864
|
-
'/*.wasm',
|
|
10865
|
-
'/*.bin'
|
|
10866
|
-
];
|
|
10867
10677
|
const resources = manifest.web_accessible_resources;
|
|
10868
|
-
|
|
10869
|
-
|
|
10870
|
-
for (const resource of
|
|
10678
|
+
const webResources = new Set(resources || []);
|
|
10679
|
+
if (0 === patch_web_resources_contentScriptMatches(manifest).length) return Array.from(webResources);
|
|
10680
|
+
for (const resource of DEV_RUNTIME_RESOURCES)webResources.add(resource);
|
|
10871
10681
|
return Array.from(webResources);
|
|
10872
10682
|
}
|
|
10873
10683
|
function patchWebResourcesV3(manifest) {
|
|
10874
|
-
const
|
|
10875
|
-
|
|
10876
|
-
|
|
10877
|
-
'/*.css',
|
|
10878
|
-
'/*.scss',
|
|
10879
|
-
'/*.sass',
|
|
10880
|
-
'/*.less',
|
|
10881
|
-
'*.styl',
|
|
10882
|
-
"/scripts/*.js",
|
|
10883
|
-
"/scripts/*.css",
|
|
10884
|
-
'/hot/*',
|
|
10885
|
-
'/*.png',
|
|
10886
|
-
'/*.jpg',
|
|
10887
|
-
'/*.jpeg',
|
|
10888
|
-
'/*.svg',
|
|
10889
|
-
'/*.gif',
|
|
10890
|
-
'/*.webp',
|
|
10891
|
-
'/*.ico',
|
|
10892
|
-
'/*.avif',
|
|
10893
|
-
'/*.wasm',
|
|
10894
|
-
'/*.bin'
|
|
10895
|
-
];
|
|
10684
|
+
const existing = manifest.web_accessible_resources || [];
|
|
10685
|
+
const matches = patch_web_resources_contentScriptMatches(manifest);
|
|
10686
|
+
if (0 === matches.length) return existing;
|
|
10896
10687
|
return [
|
|
10897
|
-
...
|
|
10688
|
+
...existing,
|
|
10898
10689
|
{
|
|
10899
|
-
resources:
|
|
10900
|
-
|
|
10901
|
-
|
|
10902
|
-
|
|
10690
|
+
resources: [
|
|
10691
|
+
...DEV_RUNTIME_RESOURCES
|
|
10692
|
+
],
|
|
10693
|
+
matches
|
|
10903
10694
|
}
|
|
10904
10695
|
];
|
|
10905
10696
|
}
|
|
10697
|
+
function patchWebResources(manifest) {
|
|
10698
|
+
const patched = 3 === manifest.manifest_version ? patchWebResourcesV3(manifest) : patchWebResourcesV2(manifest);
|
|
10699
|
+
if (!patched.length) return {};
|
|
10700
|
+
return {
|
|
10701
|
+
web_accessible_resources: patched
|
|
10702
|
+
};
|
|
10703
|
+
}
|
|
10906
10704
|
function findInjectedOnlyPermissionUses(compilation, declared, injected) {
|
|
10907
10705
|
const firstOffenderByApi = new Map();
|
|
10908
10706
|
const candidates = injected.filter((api)=>!declared.has(api));
|
|
10909
10707
|
if (!candidates.length) return firstOffenderByApi;
|
|
10910
|
-
|
|
10911
|
-
|
|
10912
|
-
|
|
10913
|
-
|
|
10914
|
-
|
|
10915
|
-
|
|
10916
|
-
|
|
10917
|
-
|
|
10918
|
-
|
|
10919
|
-
|
|
10920
|
-
|
|
10921
|
-
|
|
10922
|
-
|
|
10923
|
-
|
|
10924
|
-
|
|
10708
|
+
const emitted = readEmittedScripts(compilation);
|
|
10709
|
+
const shipped = new Map();
|
|
10710
|
+
const shippedText = (file)=>{
|
|
10711
|
+
if (shipped.has(file)) return shipped.get(file);
|
|
10712
|
+
const text = emitted.get(file);
|
|
10713
|
+
if (void 0 === text) return;
|
|
10714
|
+
const compressed = shippableText(text);
|
|
10715
|
+
shipped.set(file, compressed);
|
|
10716
|
+
return compressed;
|
|
10717
|
+
};
|
|
10718
|
+
for (const outer of compilation.modules){
|
|
10719
|
+
const inner = outer.modules ? [
|
|
10720
|
+
...outer.modules
|
|
10721
|
+
] : [
|
|
10722
|
+
outer
|
|
10723
|
+
];
|
|
10724
|
+
for (const module of inner){
|
|
10725
|
+
const resource = scannableSourcePath(module.resource);
|
|
10726
|
+
if (!resource) continue;
|
|
10727
|
+
const source = readProjectSource(resource);
|
|
10728
|
+
if (void 0 !== source) for (const api of candidates){
|
|
10729
|
+
if (firstOffenderByApi.has(api)) continue;
|
|
10730
|
+
const useRe = new RegExp(`\\b(?:chrome|browser)\\s*\\.\\s*${api}\\b`);
|
|
10731
|
+
if (!useRe.test(source)) continue;
|
|
10732
|
+
const files = emittedFilesOf(compilation, outer);
|
|
10733
|
+
if (!files || files.some((file)=>{
|
|
10734
|
+
const text = shippedText(file);
|
|
10735
|
+
return void 0 !== text && useRe.test(text);
|
|
10736
|
+
})) firstOffenderByApi.set(api, resource);
|
|
10737
|
+
}
|
|
10925
10738
|
}
|
|
10926
10739
|
if (firstOffenderByApi.size === candidates.length) break;
|
|
10927
10740
|
}
|
|
@@ -11002,7 +10815,7 @@ class ApplyDevDefaults {
|
|
|
11002
10815
|
...hostPermissionsPatch,
|
|
11003
10816
|
...patchBackground(canonicalManifest, this.browser),
|
|
11004
10817
|
...patchExternallyConnectable(canonicalManifest),
|
|
11005
|
-
|
|
10818
|
+
...patchWebResources(canonicalManifest)
|
|
11006
10819
|
};
|
|
11007
10820
|
try {
|
|
11008
10821
|
const declared = new Set(canonicalManifest.permissions || []);
|
|
@@ -11242,6 +11055,17 @@ function collectContentScriptAsyncChunkFiles(compilation) {
|
|
|
11242
11055
|
});
|
|
11243
11056
|
return result;
|
|
11244
11057
|
}
|
|
11058
|
+
function collectPageContextEntryFiles(compilation) {
|
|
11059
|
+
const result = {};
|
|
11060
|
+
if ('function' != typeof compilation.entrypoints?.forEach) return result;
|
|
11061
|
+
compilation.entrypoints.forEach((entry, entryName)=>{
|
|
11062
|
+
if (!isPageContextEntry(String(entryName))) return;
|
|
11063
|
+
const files = new Set();
|
|
11064
|
+
for (const chunk of toFileArray(entry.chunks))for (const file of toFileArray(chunk.files))if (file.endsWith('.js')) files.add(unixify(file));
|
|
11065
|
+
if (files.size > 0) result[String(entryName)] = Array.from(files).sort();
|
|
11066
|
+
});
|
|
11067
|
+
return result;
|
|
11068
|
+
}
|
|
11245
11069
|
function collectContentScriptEntryImports(compilation, includeList) {
|
|
11246
11070
|
const entryImports = {};
|
|
11247
11071
|
const contentEntryNames = new Set(Object.keys(includeList || {}).filter((k)=>isPageContextEntry(k)));
|
|
@@ -11312,18 +11136,6 @@ function collectContentScriptEntryImports(compilation, includeList) {
|
|
|
11312
11136
|
}
|
|
11313
11137
|
return entryImports;
|
|
11314
11138
|
}
|
|
11315
|
-
function cleanMatches(matches) {
|
|
11316
|
-
return matches.map((match)=>{
|
|
11317
|
-
try {
|
|
11318
|
-
const url = new URL(match.replace(/^\*:\/\//, 'https://'));
|
|
11319
|
-
if (match.endsWith(url.pathname)) return `${match.substring(0, match.length - url.pathname.length)}/*`;
|
|
11320
|
-
if ('/' === url.pathname) return `${match}/*`;
|
|
11321
|
-
return match;
|
|
11322
|
-
} catch {
|
|
11323
|
-
return match;
|
|
11324
|
-
}
|
|
11325
|
-
});
|
|
11326
|
-
}
|
|
11327
11139
|
function warFieldError(filePath, opts) {
|
|
11328
11140
|
const displayPath = opts?.overrideNotFoundPath || filePath;
|
|
11329
11141
|
const lines = [];
|
|
@@ -11366,6 +11178,14 @@ function warInvalidMatchPattern(pattern) {
|
|
|
11366
11178
|
lines.push(`Update the pattern in your ${pintor.blue('manifest.json')} file. See ${pintor.underline('https://developer.chrome.com/docs/extensions/reference/manifest/web-accessible-resources#manifest_declaration')} for the format.`);
|
|
11367
11179
|
return lines.join('\n');
|
|
11368
11180
|
}
|
|
11181
|
+
function warUnreachableResource(resource, entryName) {
|
|
11182
|
+
const lines = [];
|
|
11183
|
+
lines.push(`${pintor.underline(entryName)} asks the extension for ${pintor.blue(resource)}, but ${pintor.blue('web_accessible_resources')} does not list it.`);
|
|
11184
|
+
lines.push("The browser refuses it with a SecurityError because a content script reads extension files with the page's origin.");
|
|
11185
|
+
lines.push(`Add it to ${pintor.blue('web_accessible_resources')} in ${pintor.blue('manifest.json')}, scoped to the matches that need it.`);
|
|
11186
|
+
lines.push(`Learn more: ${pintor.underline('https://extension.js.org/docs/development/web-accessible-resources')}`);
|
|
11187
|
+
return lines.join('\n');
|
|
11188
|
+
}
|
|
11369
11189
|
function entryImportsSummary(entryCount, totalResources) {
|
|
11370
11190
|
return `${messaging_prefix('debug')} war entryImports entries=${String(entryCount)} resources=${String(totalResources)}`;
|
|
11371
11191
|
}
|
|
@@ -11609,6 +11429,54 @@ function resolveUserDeclaredWAR(compilation, manifestPath, manifest, browser) {
|
|
|
11609
11429
|
v3
|
|
11610
11430
|
};
|
|
11611
11431
|
}
|
|
11432
|
+
function normalizeResourcePath(value) {
|
|
11433
|
+
return String(value || '').replace(/\\/g, '/').replace(/^\.\//, '').replace(/^\/+/, '');
|
|
11434
|
+
}
|
|
11435
|
+
function escapeRegex(value) {
|
|
11436
|
+
return value.replace(/[.+^${}()|[\]\\]/g, '\\$&');
|
|
11437
|
+
}
|
|
11438
|
+
function globToRegex(pattern) {
|
|
11439
|
+
const escaped = pattern.split('*').map((segment)=>escapeRegex(segment)).join('.*');
|
|
11440
|
+
return new RegExp(`^${escaped}$`);
|
|
11441
|
+
}
|
|
11442
|
+
function isResourceCovered(declared, candidate) {
|
|
11443
|
+
const target = normalizeResourcePath(candidate);
|
|
11444
|
+
for (const entry of declared){
|
|
11445
|
+
const pattern = normalizeResourcePath(entry);
|
|
11446
|
+
if (pattern === target) return true;
|
|
11447
|
+
if (pattern.includes('*')) try {
|
|
11448
|
+
if (globToRegex(pattern).test(target)) return true;
|
|
11449
|
+
} catch {}
|
|
11450
|
+
}
|
|
11451
|
+
return false;
|
|
11452
|
+
}
|
|
11453
|
+
const GET_URL_LITERAL_PATTERN = /getURL\s*\(\s*["'`]([^"'`\n)]+)["'`]\s*\)/g;
|
|
11454
|
+
const MAX_SCANNED_SOURCE_BYTES = 4194304;
|
|
11455
|
+
function collectGetUrlLiterals(source) {
|
|
11456
|
+
if (!source || source.length > MAX_SCANNED_SOURCE_BYTES) return [];
|
|
11457
|
+
const found = new Set();
|
|
11458
|
+
const pattern = new RegExp(GET_URL_LITERAL_PATTERN.source, 'g');
|
|
11459
|
+
let match = pattern.exec(source);
|
|
11460
|
+
while(match){
|
|
11461
|
+
const name = normalizeResourcePath(match[1]);
|
|
11462
|
+
if (name && !name.includes('${')) found.add(name);
|
|
11463
|
+
match = pattern.exec(source);
|
|
11464
|
+
}
|
|
11465
|
+
return Array.from(found).sort();
|
|
11466
|
+
}
|
|
11467
|
+
const TOOLING_RESOURCES = new Set([
|
|
11468
|
+
'manifest.json',
|
|
11469
|
+
'extension-js-control.json'
|
|
11470
|
+
]);
|
|
11471
|
+
function findUnreachableRuntimeResources(options) {
|
|
11472
|
+
const emitted = new Set(options.emittedAssetNames.map((name)=>normalizeResourcePath(name)));
|
|
11473
|
+
return collectGetUrlLiterals(options.source).filter((name)=>{
|
|
11474
|
+
if (TOOLING_RESOURCES.has(name)) return false;
|
|
11475
|
+
if (name.startsWith('hot/')) return false;
|
|
11476
|
+
if (!emitted.has(name)) return false;
|
|
11477
|
+
return !isResourceCovered(options.declaredResources, name);
|
|
11478
|
+
});
|
|
11479
|
+
}
|
|
11612
11480
|
function generate_manifest_getAssetSource(compilation, filename) {
|
|
11613
11481
|
const byGet = 'function' == typeof compilation.getAsset ? compilation.getAsset(filename) : void 0;
|
|
11614
11482
|
const byAssets = !byGet && compilation.assets ? compilation.assets[filename] : void 0;
|
|
@@ -11636,16 +11504,16 @@ function generate_manifest_getAssetSource(compilation, filename) {
|
|
|
11636
11504
|
function hasWildcardPattern(pattern) {
|
|
11637
11505
|
return /[*?[\]]/.test(pattern);
|
|
11638
11506
|
}
|
|
11639
|
-
function
|
|
11507
|
+
function generate_manifest_escapeRegex(s) {
|
|
11640
11508
|
return s.replace(/[.+^${}()|\\]/g, '\\$&');
|
|
11641
11509
|
}
|
|
11642
|
-
function
|
|
11643
|
-
const escaped = pattern.split('*').map((seg)=>
|
|
11510
|
+
function generate_manifest_globToRegex(pattern) {
|
|
11511
|
+
const escaped = pattern.split('*').map((seg)=>generate_manifest_escapeRegex(seg)).join('.*');
|
|
11644
11512
|
return new RegExp(`^${escaped}$`);
|
|
11645
11513
|
}
|
|
11646
11514
|
function isCoveredByExistingGlobs(existingPatterns, candidate) {
|
|
11647
11515
|
for (const existingPattern of existingPatterns)if (hasWildcardPattern(existingPattern)) try {
|
|
11648
|
-
const re =
|
|
11516
|
+
const re = generate_manifest_globToRegex(existingPattern);
|
|
11649
11517
|
if (re.test(candidate)) return true;
|
|
11650
11518
|
} catch {}
|
|
11651
11519
|
return false;
|
|
@@ -11686,6 +11554,42 @@ function toCanonicalContentScriptCss(jsFile) {
|
|
|
11686
11554
|
if (!/^content_scripts\/content-\d+\.js$/.test(normalized)) return;
|
|
11687
11555
|
return normalized.replace(/\.js$/, '.css');
|
|
11688
11556
|
}
|
|
11557
|
+
function declaredWarResources(manifest) {
|
|
11558
|
+
const war = manifest.web_accessible_resources;
|
|
11559
|
+
if (!Array.isArray(war)) return [];
|
|
11560
|
+
return war.flatMap((entry)=>{
|
|
11561
|
+
if ('string' == typeof entry) return [
|
|
11562
|
+
entry
|
|
11563
|
+
];
|
|
11564
|
+
const resources = entry.resources;
|
|
11565
|
+
return Array.isArray(resources) ? resources.map((r)=>String(r)) : [];
|
|
11566
|
+
});
|
|
11567
|
+
}
|
|
11568
|
+
function warnOnUnreachableResources(compilation, manifest) {
|
|
11569
|
+
try {
|
|
11570
|
+
const declared = declaredWarResources(manifest);
|
|
11571
|
+
const emittedAssetNames = listEmittedAssetNames(compilation);
|
|
11572
|
+
const entryFiles = collectPageContextEntryFiles(compilation);
|
|
11573
|
+
const reported = new Set();
|
|
11574
|
+
for (const [entryName, files] of Object.entries(entryFiles))for (const file of files){
|
|
11575
|
+
const unreachable = findUnreachableRuntimeResources({
|
|
11576
|
+
source: generate_manifest_getAssetSource(compilation, file),
|
|
11577
|
+
emittedAssetNames,
|
|
11578
|
+
declaredResources: declared
|
|
11579
|
+
});
|
|
11580
|
+
for (const resource of unreachable){
|
|
11581
|
+
const key = `${entryName}:${resource}`;
|
|
11582
|
+
if (reported.has(key)) continue;
|
|
11583
|
+
reported.add(key);
|
|
11584
|
+
compilation.warnings = compilation.warnings || [];
|
|
11585
|
+
const warning = new core_WebpackError(warUnreachableResource(resource, entryName));
|
|
11586
|
+
warning.name = 'UnreachableWebAccessibleResourceWarning';
|
|
11587
|
+
warning.file = file;
|
|
11588
|
+
compilation.warnings.push(warning);
|
|
11589
|
+
}
|
|
11590
|
+
}
|
|
11591
|
+
} catch {}
|
|
11592
|
+
}
|
|
11689
11593
|
function generateManifestPatches(compilation, manifestPath, entryImports, browser) {
|
|
11690
11594
|
const canonicalManifest = getManifestContent(compilation, manifestPath);
|
|
11691
11595
|
const resolved = resolveUserDeclaredWAR(compilation, manifestPath, canonicalManifest, browser);
|
|
@@ -11825,6 +11729,7 @@ function generateManifestPatches(compilation, manifestPath, entryImports, browse
|
|
|
11825
11729
|
matches: Array.from(new Set(entry.matches)).sort()
|
|
11826
11730
|
})).sort((a, b)=>a.matches.join(',').localeCompare(b.matches.join(',')));
|
|
11827
11731
|
} else if (webAccessibleResourcesV2.length > 0) canonicalManifest.web_accessible_resources = Array.from(new Set(webAccessibleResourcesV2)).sort();
|
|
11732
|
+
warnOnUnreachableResources(compilation, canonicalManifest);
|
|
11828
11733
|
const source = JSON.stringify(canonicalManifest, null, 2);
|
|
11829
11734
|
const rawSource = new core_sources.RawSource(source);
|
|
11830
11735
|
setCurrentManifestContent(compilation, source);
|
|
@@ -13130,21 +13035,6 @@ function patchGeckoBackground(manifest, browser) {
|
|
|
13130
13035
|
}
|
|
13131
13036
|
};
|
|
13132
13037
|
}
|
|
13133
|
-
function patchWebkitBackground(manifest, browser) {
|
|
13134
|
-
if (!isWebkitBasedBrowser(String(browser))) return manifest;
|
|
13135
|
-
const background = manifest.background;
|
|
13136
|
-
if (!background || !background.service_worker || background.scripts) return manifest;
|
|
13137
|
-
const { service_worker, type, ...rest } = background;
|
|
13138
|
-
return {
|
|
13139
|
-
...manifest,
|
|
13140
|
-
background: {
|
|
13141
|
-
...rest,
|
|
13142
|
-
scripts: [
|
|
13143
|
-
service_worker
|
|
13144
|
-
]
|
|
13145
|
-
}
|
|
13146
|
-
};
|
|
13147
|
-
}
|
|
13148
13038
|
const webkitUnsupportedApis = {
|
|
13149
13039
|
sidePanel: safariSidePanelUnsupported,
|
|
13150
13040
|
offscreen: safariOffscreenUnsupported,
|
|
@@ -13305,48 +13195,26 @@ function scanTargets(manifestVersion, engine) {
|
|
|
13305
13195
|
});
|
|
13306
13196
|
return targets;
|
|
13307
13197
|
}
|
|
13308
|
-
const EMITTED_SCRIPT_RE = /\.[cm]?js$/;
|
|
13309
|
-
const MAX_SOURCE_BYTES = 1048576;
|
|
13310
|
-
const MAX_ASSET_BYTES = 16777216;
|
|
13311
|
-
function readEmittedScripts(compilation) {
|
|
13312
|
-
const scripts = new Map();
|
|
13313
|
-
let assets;
|
|
13314
|
-
try {
|
|
13315
|
-
assets = compilation.getAssets?.() || [];
|
|
13316
|
-
} catch {
|
|
13317
|
-
return scripts;
|
|
13318
|
-
}
|
|
13319
|
-
for (const asset of assets)if (EMITTED_SCRIPT_RE.test(asset.name)) try {
|
|
13320
|
-
const raw = asset.source.source();
|
|
13321
|
-
const text = 'string' == typeof raw ? raw : raw.toString('utf-8');
|
|
13322
|
-
if (text.length > MAX_ASSET_BYTES) continue;
|
|
13323
|
-
scripts.set(asset.name, text);
|
|
13324
|
-
} catch {}
|
|
13325
|
-
return scripts;
|
|
13326
|
-
}
|
|
13327
|
-
function readProjectSource(resource) {
|
|
13328
|
-
try {
|
|
13329
|
-
if (__rspack_external_node_fs_1b05aee1.statSync(resource).size > MAX_SOURCE_BYTES) return;
|
|
13330
|
-
return __rspack_external_node_fs_1b05aee1.readFileSync(resource, 'utf-8');
|
|
13331
|
-
} catch {
|
|
13332
|
-
return;
|
|
13333
|
-
}
|
|
13334
|
-
}
|
|
13335
|
-
function emittedFilesOf(compilation, module) {
|
|
13336
|
-
if (!compilation.chunkGraph) return;
|
|
13337
|
-
try {
|
|
13338
|
-
const files = [];
|
|
13339
|
-
for (const chunk of compilation.chunkGraph.getModuleChunksIterable(module))for (const file of chunk.files || [])files.push(file);
|
|
13340
|
-
return files;
|
|
13341
|
-
} catch {
|
|
13342
|
-
return;
|
|
13343
|
-
}
|
|
13344
|
-
}
|
|
13345
13198
|
function findGeckoUnsupportedApiUses(compilation, manifestVersion, engine = 'gecko', requireEmittedEvidence = false) {
|
|
13346
13199
|
const targets = scanTargets(manifestVersion, engine);
|
|
13347
13200
|
const emitted = readEmittedScripts(compilation);
|
|
13348
13201
|
const explained = new Set();
|
|
13349
13202
|
const uses = new Map();
|
|
13203
|
+
const shipped = new Map();
|
|
13204
|
+
const shippedText = (file)=>{
|
|
13205
|
+
if (shipped.has(file)) return shipped.get(file);
|
|
13206
|
+
const text = emitted.get(file);
|
|
13207
|
+
if (void 0 === text) return;
|
|
13208
|
+
const compressed = requireEmittedEvidence ? shippableText(text) : text;
|
|
13209
|
+
shipped.set(file, compressed);
|
|
13210
|
+
return compressed;
|
|
13211
|
+
};
|
|
13212
|
+
const carries = (file, target)=>{
|
|
13213
|
+
const raw = emitted.get(file);
|
|
13214
|
+
if (void 0 === raw || !target.test(raw)) return false;
|
|
13215
|
+
const text = shippedText(file);
|
|
13216
|
+
return void 0 !== text && target.test(text);
|
|
13217
|
+
};
|
|
13350
13218
|
for (const outer of compilation.modules){
|
|
13351
13219
|
const inner = outer.modules ? [
|
|
13352
13220
|
...outer.modules
|
|
@@ -13362,10 +13230,7 @@ function findGeckoUnsupportedApiUses(compilation, manifestVersion, engine = 'gec
|
|
|
13362
13230
|
if (uses.has(key) || !target.test(source)) continue;
|
|
13363
13231
|
const files = emittedFilesOf(compilation, outer);
|
|
13364
13232
|
if (files) {
|
|
13365
|
-
const carrying = files.filter((file)=>
|
|
13366
|
-
const text = emitted.get(file);
|
|
13367
|
-
return void 0 !== text && target.test(text);
|
|
13368
|
-
});
|
|
13233
|
+
const carrying = files.filter((file)=>carries(file, target));
|
|
13369
13234
|
if (!carrying.length) continue;
|
|
13370
13235
|
for (const file of carrying)explained.add(`${target.key}\0${file}`);
|
|
13371
13236
|
} else if (requireEmittedEvidence) continue;
|
|
@@ -13383,9 +13248,9 @@ function findGeckoUnsupportedApiUses(compilation, manifestVersion, engine = 'gec
|
|
|
13383
13248
|
if (!compilation.chunkGraph) return [
|
|
13384
13249
|
...uses.values()
|
|
13385
13250
|
];
|
|
13386
|
-
for (const
|
|
13251
|
+
for (const name of emitted.keys())for (const target of targets){
|
|
13387
13252
|
const key = `${target.key}\0${name}`;
|
|
13388
|
-
if (!explained.has(key) && target
|
|
13253
|
+
if (!explained.has(key) && carries(name, target)) uses.set(key, {
|
|
13389
13254
|
api: target.api,
|
|
13390
13255
|
...target.member ? {
|
|
13391
13256
|
member: target.member
|
|
@@ -13471,6 +13336,7 @@ class UpdateManifest {
|
|
|
13471
13336
|
if (dropReason) reportToCompilation(compilation, compiler, 'conflicts' === dropReason ? pageActionDroppedForBrowserAction(String(this.browser)) : pageActionNotSupportedByBrowser(String(this.browser)), 'warning', 'manifest.json');
|
|
13472
13337
|
if (hasMv2SandboxPolicy(forBrowser)) reportToCompilation(compilation, compiler, mv2SandboxPolicyDropped(String(this.browser)), 'warning', 'manifest.json');
|
|
13473
13338
|
for (const dropped of findDroppedVendorKeys(manifest, this.browser))if (dropped.appliedBefore) reportToCompilation(compilation, compiler, vendorPrefixedKeyDropped(dropped.path, dropped.familyPath, dropped.vendor, String(this.browser)), 'warning', 'manifest.json');
|
|
13339
|
+
if (!isValidManifestVersion(forBrowser.manifest_version)) reportToCompilation(compilation, compiler, manifestVersionLostForBrowser(String(this.browser), findPrefixedManifestVersionKeys(manifest), forBrowser.manifest_version), 'error', 'manifest.json');
|
|
13474
13340
|
const projectPath = compiler.options.context || __rspack_external_node_path_806ed179.dirname(this.manifestPath);
|
|
13475
13341
|
let patchedManifest = buildCanonicalManifest(this.manifestPath, manifest, this.browser, projectPath);
|
|
13476
13342
|
if ('production' === compiler.options.mode) {
|
|
@@ -14029,6 +13895,100 @@ function parsesAsModule(source) {
|
|
|
14029
13895
|
return false;
|
|
14030
13896
|
}
|
|
14031
13897
|
}
|
|
13898
|
+
const WORKER_FROM_URL = /new\s+Worker\s*\(\s*(?:\/\*[\s\S]*?\*\/\s*)?new\s+URL\s*\(/;
|
|
13899
|
+
const EXTENSION_BASES = [
|
|
13900
|
+
/^import\.meta\.url$/,
|
|
13901
|
+
/^[A-Za-z_$][\w$]*\.b$/,
|
|
13902
|
+
/^(?:chrome|browser)\.runtime\.getURL\(/,
|
|
13903
|
+
/^["'`](?:chrome-extension|moz-extension|safari-web-extension):\/\//
|
|
13904
|
+
];
|
|
13905
|
+
const JS_ASSET = /\.m?js$/i;
|
|
13906
|
+
function readCallArguments(source, from) {
|
|
13907
|
+
const args = [];
|
|
13908
|
+
let depth = 0;
|
|
13909
|
+
let start = from;
|
|
13910
|
+
for(let i = from; i < source.length; i++){
|
|
13911
|
+
const char = source[i];
|
|
13912
|
+
if ('"' === char || "'" === char || '`' === char) {
|
|
13913
|
+
i = skipQuoted(source, i, char);
|
|
13914
|
+
continue;
|
|
13915
|
+
}
|
|
13916
|
+
if ('/' === char && '*' === source[i + 1]) {
|
|
13917
|
+
const end = source.indexOf('*/', i + 2);
|
|
13918
|
+
i = -1 === end ? source.length : end + 1;
|
|
13919
|
+
continue;
|
|
13920
|
+
}
|
|
13921
|
+
if ('/' === char && '/' === source[i + 1]) {
|
|
13922
|
+
const end = source.indexOf('\n', i + 2);
|
|
13923
|
+
i = -1 === end ? source.length : end;
|
|
13924
|
+
continue;
|
|
13925
|
+
}
|
|
13926
|
+
if ('(' === char || '[' === char || '{' === char) {
|
|
13927
|
+
depth++;
|
|
13928
|
+
continue;
|
|
13929
|
+
}
|
|
13930
|
+
if (')' === char || ']' === char || '}' === char) {
|
|
13931
|
+
if (0 === depth) {
|
|
13932
|
+
args.push(source.slice(start, i));
|
|
13933
|
+
return args;
|
|
13934
|
+
}
|
|
13935
|
+
depth--;
|
|
13936
|
+
continue;
|
|
13937
|
+
}
|
|
13938
|
+
if (',' === char && 0 === depth) {
|
|
13939
|
+
args.push(source.slice(start, i));
|
|
13940
|
+
start = i + 1;
|
|
13941
|
+
}
|
|
13942
|
+
}
|
|
13943
|
+
}
|
|
13944
|
+
function skipQuoted(source, from, quote) {
|
|
13945
|
+
for(let i = from + 1; i < source.length; i++){
|
|
13946
|
+
if ('\\' === source[i]) {
|
|
13947
|
+
i++;
|
|
13948
|
+
continue;
|
|
13949
|
+
}
|
|
13950
|
+
if (source[i] === quote) return i;
|
|
13951
|
+
}
|
|
13952
|
+
return source.length;
|
|
13953
|
+
}
|
|
13954
|
+
function resolvesAgainstExtension(base) {
|
|
13955
|
+
const text = (base ?? '').replace(/\s+/g, '');
|
|
13956
|
+
if (!text) return true;
|
|
13957
|
+
return EXTENSION_BASES.some((shape)=>shape.test(text));
|
|
13958
|
+
}
|
|
13959
|
+
function startsWorkerFromExtensionUrl(source) {
|
|
13960
|
+
const call = new RegExp(WORKER_FROM_URL.source, 'g');
|
|
13961
|
+
let match = call.exec(source);
|
|
13962
|
+
while(match){
|
|
13963
|
+
const args = readCallArguments(source, match.index + match[0].length);
|
|
13964
|
+
if (args && resolvesAgainstExtension(args[1])) return true;
|
|
13965
|
+
match = call.exec(source);
|
|
13966
|
+
}
|
|
13967
|
+
return false;
|
|
13968
|
+
}
|
|
13969
|
+
class WarnPageContextWorker {
|
|
13970
|
+
apply(compiler) {
|
|
13971
|
+
if (!compiler?.hooks?.thisCompilation?.tap) return;
|
|
13972
|
+
compiler.hooks.thisCompilation.tap("scripts:warn-page-context-worker", (compilation)=>{
|
|
13973
|
+
compilation.hooks.processAssets.tap({
|
|
13974
|
+
name: "scripts:warn-page-context-worker",
|
|
13975
|
+
stage: core_Compilation.PROCESS_ASSETS_STAGE_REPORT
|
|
13976
|
+
}, ()=>{
|
|
13977
|
+
for (const asset of compilation.getAssets()){
|
|
13978
|
+
const name = String(asset.name || '');
|
|
13979
|
+
if (!JS_ASSET.test(name)) continue;
|
|
13980
|
+
const surface = classifyEntrySurface(name);
|
|
13981
|
+
if ("content_script" !== surface && "script" !== surface) continue;
|
|
13982
|
+
const source = String(asset.source?.source() || '');
|
|
13983
|
+
if (!startsWorkerFromExtensionUrl(source)) continue;
|
|
13984
|
+
const warning = new core_WebpackError(workerStartedFromPageContext(name, surface));
|
|
13985
|
+
warning.file = name;
|
|
13986
|
+
compilation.warnings.push(warning);
|
|
13987
|
+
}
|
|
13988
|
+
});
|
|
13989
|
+
});
|
|
13990
|
+
}
|
|
13991
|
+
}
|
|
14032
13992
|
class WarnSplitInitialChunks {
|
|
14033
13993
|
apply(compiler) {
|
|
14034
13994
|
if (!compiler?.hooks?.thisCompilation?.tap) return;
|
|
@@ -14085,6 +14045,7 @@ class ScriptsPlugin {
|
|
|
14085
14045
|
if ('production' === compiler.options.mode) new AddPublicPathRuntimeModule().apply(compiler);
|
|
14086
14046
|
new ValidateEmittedScriptSyntax().apply(compiler);
|
|
14087
14047
|
new WarnSplitInitialChunks().apply(compiler);
|
|
14048
|
+
new WarnPageContextWorker().apply(compiler);
|
|
14088
14049
|
}
|
|
14089
14050
|
}
|
|
14090
14051
|
class CollectContentEntryImports {
|
|
@@ -14883,6 +14844,12 @@ function webpackConfig(projectStructure, devOptions) {
|
|
|
14883
14844
|
optimization: {
|
|
14884
14845
|
emitOnErrors: false,
|
|
14885
14846
|
minimize: 'production' === devOptions.mode,
|
|
14847
|
+
minimizer: [
|
|
14848
|
+
new SwcJsMinimizerRspackPlugin(),
|
|
14849
|
+
new LightningCssMinimizerRspackPlugin({
|
|
14850
|
+
removeUnusedLocalIdents: false
|
|
14851
|
+
})
|
|
14852
|
+
],
|
|
14886
14853
|
sideEffects: true,
|
|
14887
14854
|
usedExports: 'global',
|
|
14888
14855
|
concatenateModules: 'production' === devOptions.mode,
|