') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); fix: Drop @react-native/metro-config dep for RN 0.72 config fallback by huntie · Pull Request #1899 · react-native-community/cli · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/cli-plugin-metro/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,13 +9,14 @@
"dependencies": {
"@react-native-community/cli-server-api": "12.0.0-alpha.0",
"@react-native-community/cli-tools": "12.0.0-alpha.0",
"@react-native/metro-config": "^0.73.0",
"chalk": "^4.1.2",
"execa": "^5.0.0",
"metro": "0.76.0",
"metro-config": "0.76.0",
"metro-core": "0.76.0",
"metro-react-native-babel-transformer": "0.76.0",
"metro-resolver": "0.76.0",
"metro-runtime": "0.76.0",
Comment on lines +17 to +19

@huntiehuntieApr 4, 2023

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"readline": "^1.3.0"
},
"devDependencies": {
Expand Down
87 changes: 87 additions & 0 deletions packages/cli-plugin-metro/src/tools/getDefaultMetroConfig.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
import type {InputConfigT} from 'metro-config';
import path from 'path';
import type {ConfigLoadingContext} from './loadMetroConfig';

/**
* This module reproduces defaults from the @react-native/metro-config package,
* used in ./loadMetroConfig.js to provide a soft upgrade process when upgrading
* to React Native 0.72.
*
* These values will be used when:
* - RN CLI 11.x or greater is present in a project (from React Native 0.72).
* - The project has not yet followed the upgrade instructions to update
* metro.config.js to extend '@react-native/metro-config'.
*
* Until we remove this file in a future release, updates should be made both
* here and in '@react-native/metro-config'. (Note: Updates to these values are
* generally rare.)
*
* TODO(@huntie): Remove this file in a future React Native release.
*/

/**
* @deprecated (React Native 0.72.0) Defaults should be updated here and in
* https://github.com/facebook/react-native/tree/main/package/metro-config/index.js
*/
const INTERNAL_CALLSITES_REGEX = new RegExp(
[
'/Libraries/Renderer/implementations/.+\\.js$',
'/Libraries/BatchedBridge/MessageQueue\\.js$',
'/Libraries/YellowBox/.+\\.js$',
'/Libraries/LogBox/.+\\.js$',
'/Libraries/Core/Timers/.+\\.js$',
'/Libraries/WebSocket/.+\\.js$',
'/Libraries/vendor/.+\\.js$',
'/node_modules/react-devtools-core/.+\\.js$',
'/node_modules/react-refresh/.+\\.js$',
'/node_modules/scheduler/.+\\.js$',
'/node_modules/event-target-shim/.+\\.js$',
'/node_modules/invariant/.+\\.js$',
'/node_modules/react-native/index.js$',
'/metro-runtime/.+\\.js$',
'^\\[native code\\]$',
].join('|'),
);

/**
* Get the static Metro config defaults for a React Native project.
*
* @deprecated (React Native 0.72.0) Defaults should be updated here and in
* https://github.com/facebook/react-native/tree/main/package/metro-config/index.js
*/
export default function getDefaultMetroConfig(
ctx: ConfigLoadingContext,
): InputConfigT {
return {
resolver: {
resolverMainFields: ['react-native', 'browser', 'main'],
unstable_conditionNames: ['require', 'react-native'],
},
serializer: {
getPolyfills: () =>
require(path.join(ctx.reactNativePath, 'rn-get-polyfills'))(),
Comment on lines +61 to +62

@huntiehuntieApr 4, 2023

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored (https://github.com/react-native-community/cli/pull/1875/files#diff-3eb3e1e81b924a57b22a630c633912f2f8777b5a201992591c8a3517fb63f525L76-L77).

Deviates from @react-native/metro-config, which references the standalone package @react-native/js-polyfills (technically, this was/is the first circular dep edge case!). These are equivalent, but allows this repo to not reference the RN-hosted package (see removal in yarn.lock).

https://github.com/facebook/react-native/blob/bece6500f7d6374eab09917c9afd3bf6142f0b61/packages/metro-config/index.js#L47-L49

},
server: {
port: Number(process.env.RCT_METRO_PORT) || 8081,
},
symbolicator: {
customizeFrame: (frame: {file?: string}) => {
const collapse = Boolean(
frame.file && INTERNAL_CALLSITES_REGEX.test(frame.file),
);
return {collapse};
},
},
transformer: {
allowOptionalDependencies: true,
assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',
asyncRequireModulePath: require.resolve(
'metro-runtime/src/modules/asyncRequire',
),
babelTransformerPath: require.resolve(
'metro-react-native-babel-transformer',
),
},
watchFolders: [],
};
}
6 changes: 3 additions & 3 deletions packages/cli-plugin-metro/src/tools/loadMetroConfig.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,9 +7,9 @@ import {
mergeConfig,
resolveConfig,
} from 'metro-config';
import {getDefaultConfig} from '@react-native/metro-config';
import {CLIError, logger} from '@react-native-community/cli-tools';
import type {Config} from '@react-native-community/cli-types';
import getDefaultMetroConfig from './getDefaultMetroConfig';
import {reactNativePlatformResolver} from './metroPlatformResolver';

export type {Config};
Expand DownExpand Up@@ -114,8 +114,8 @@ export default async function loadMetroConfig(

const loadedConfig = await loadConfig(
{cwd: ctx.root, ...options},
// Provide @react-native/metro-config defaults on top of Metro defaults
getDefaultConfig(ctx.root),
// Provide React Native defaults on top of Metro defaults
getDefaultMetroConfig(ctx),
);

return mergeConfig(loadedConfig, overrideConfig);
Expand Down
15 changes: 0 additions & 15 deletions yarn.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -2673,21 +2673,6 @@
resolved "https://registry.yarnpkg.com/@react-native-community/eslint-plugin/-/eslint-plugin-1.1.0.tgz#e42b1bef12d2415411519fd528e64b593b1363dc"
integrity sha512-W/J0fNYVO01tioHjvYWQ9m6RgndVtbElzYozBq1ZPrHO/iCzlqoySHl4gO/fpCl9QEFjvJfjPgtPMTMlsoq5DQ==

"@react-native/js-polyfills@^0.73.0":
version "0.73.0"
resolved "https://registry.yarnpkg.com/@react-native/js-polyfills/-/js-polyfills-0.73.0.tgz#d1becae77740c705392122684a55b373e610ab63"
integrity sha512-3/+q+l86xvV8xjx29On9/Dn0eWjo5MHYuuALHqyOlQIs3vLk/rQB4rn4izObiurhH3utXxqVnbOk+TB9yJo4ng==

"@react-native/metro-config@^0.73.0":
version "0.73.0"
resolved "https://registry.yarnpkg.com/@react-native/metro-config/-/metro-config-0.73.0.tgz#7601d2f4ba2252a4e359f8fda21008daf5f31eb2"
integrity sha512-b+q8Ot6nxPE2PXEua20Q0vhXYpVtVjUaTX/hv+7mL5hLzKeIWq/bIxF04GLWT93BBjGSlL0xaZ7iGIQNN75Hog==
dependencies:
"@react-native/js-polyfills" "^0.73.0"
metro-config "0.76.0"
metro-react-native-babel-transformer "0.76.0"
metro-runtime "0.76.0"

Comment on lines -2676 to -2690

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All dependencies on packages published from facebook/react-native are dropped.

"@sinonjs/commons@^1.7.0":
version "1.7.1"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.7.1.tgz#da5fd19a5f71177a53778073978873964f49acf1"
Expand Down