mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
Firefox [finally supports `ExecutionWorld.MAIN`](https://bugzilla.mozilla.org/show_bug.cgi?id=1736575) in content scripts, which means we can migrate the browser extension to Manifest V3. This PR also removes a bunch of no longer required explicit branching for Firefox case, when we are using Manifest V3-only APIs. We are also removing XMLHttpRequest injection, which is no longer needed and restricted in Manifest V3. The new standardized approach (same as in Chromium) doesn't violate CSP rules, which means that extension can finally be used for apps running in production mode.
52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
const chromeManifest = require('../react-devtools-extensions/chrome/manifest.json');
|
|
const firefoxManifest = require('../react-devtools-extensions/firefox/manifest.json');
|
|
|
|
const minChromeVersion = parseInt(chromeManifest.minimum_chrome_version, 10);
|
|
const minFirefoxVersion = parseInt(
|
|
firefoxManifest.browser_specific_settings.gecko.strict_min_version,
|
|
10,
|
|
);
|
|
validateVersion(minChromeVersion);
|
|
validateVersion(minFirefoxVersion);
|
|
|
|
function validateVersion(version) {
|
|
if (version > 0 && version < 200) {
|
|
return;
|
|
}
|
|
throw new Error('Suspicious browser version in manifest: ' + version);
|
|
}
|
|
|
|
module.exports = api => {
|
|
const isTest = api.env('test');
|
|
const targets = {};
|
|
if (isTest) {
|
|
targets.node = 'current';
|
|
} else {
|
|
targets.chrome = minChromeVersion.toString();
|
|
targets.firefox = minFirefoxVersion.toString();
|
|
|
|
let additionalTargets = process.env.BABEL_CONFIG_ADDITIONAL_TARGETS;
|
|
if (additionalTargets) {
|
|
additionalTargets = JSON.parse(additionalTargets);
|
|
for (const target in additionalTargets) {
|
|
targets[target] = additionalTargets[target];
|
|
}
|
|
}
|
|
}
|
|
const plugins = [
|
|
['@babel/plugin-transform-flow-strip-types'],
|
|
['@babel/plugin-proposal-class-properties', {loose: false}],
|
|
];
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
plugins.push(['@babel/plugin-transform-react-jsx-source']);
|
|
}
|
|
return {
|
|
plugins,
|
|
presets: [
|
|
['@babel/preset-env', {targets}],
|
|
'@babel/preset-react',
|
|
'@babel/preset-flow',
|
|
],
|
|
};
|
|
};
|