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
1 change: 1 addition & 0 deletions packages/cli-plugin-metro/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
"dependencies": {
"@react-native-community/cli-server-api": "^11.0.1",
"@react-native-community/cli-tools": "^11.0.1",
"@react-native/metro-config": "^0.72.1",
"chalk": "^4.1.2",
"execa": "^5.0.0",
"metro": "0.76.0",
Expand Down
47 changes: 35 additions & 12 deletions packages/cli-plugin-metro/src/tools/loadMetroConfig.ts
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
import fs from 'fs';
import path from 'path';
import {ConfigT, InputConfigT, loadConfig, resolveConfig} from 'metro-config';
import {
ConfigT,
InputConfigT,
loadConfig,
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 {reactNativePlatformResolver} from './metroPlatformResolver';
Expand DownExpand Up@@ -67,8 +75,8 @@ export interface ConfigOptionsT {
/**
* Load Metro config.
*
* Allows the CLI to override certain defaults in the base `metro.config.js`
* based on dynamic user options in `ctx`.
* Allows the CLI to override select values in `metro.config.js` based on
* dynamic user options in `ctx`.
*/
export default async function loadMetroConfig(
ctx: ConfigLoadingContext,
Expand All@@ -89,17 +97,32 @@ export default async function loadMetroConfig(
// @ts-ignore resolveConfig return value is mistyped
logger.debug(`Reading Metro config from ${projectConfig.filepath}`);

try {
require.resolve('@react-native/metro-config', {
paths: [ctx.root],
});
} catch (e) {
if (
!/['"']@react-native\/metro-config['"']/.test(
fs
// @ts-ignore resolveConfig return value is mistyped
.readFileSync(projectConfig.filepath, 'utf8'),
)
) {
logger.warn(
"From React Native 0.72, your 'metro.config.js' file should " +
"extend '@react-native/metro-config', however it's not present in your " +
"project's devDependencies. Please install '@react-native/metro-config'.",
'From React Native 0.72, your metro.config.js file should extend' +
"'@react-native/metro-config'. Please see the React Native 0.72 " +
'changelog, or copy the template at:\n' +
'https://github.com/facebook/react-native/blob/main/packages/react-native/template/metro.config.js',
Comment on lines +108 to +111

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for adding a reference to copy the config

@huntiehuntieApr 3, 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.

ty, ideal reference is once we have a URL for the changelog/upgrade helper :)

);
logger.warn('Falling back to internal defaults.');

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

return mergeConfig(loadedConfig, overrideConfig);
}

return loadConfig({cwd: ctx.root, ...options}, overrideConfig);
return mergeConfig(
await loadConfig({cwd: ctx.root, ...options}),
overrideConfig,
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
declare module '@react-native/metro-config' {
import type {ConfigT} from 'metro-config';

export function getDefaultConfig(projectRoot: string): ConfigT;
}
28 changes: 28 additions & 0 deletions yarn.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -2673,6 +2673,21 @@
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.72.1":
version "0.72.1"
resolved "https://registry.yarnpkg.com/@react-native/js-polyfills/-/js-polyfills-0.72.1.tgz#905343ef0c51256f128256330fccbdb35b922291"
integrity sha512-cRPZh2rBswFnGt5X5EUEPs0r+pAsXxYsifv/fgy9ZLQokuT52bPH+9xjDR+7TafRua5CttGW83wP4TntRcWNDA==

"@react-native/metro-config@^0.72.1":
version "0.72.1"
resolved "https://registry.yarnpkg.com/@react-native/metro-config/-/metro-config-0.72.1.tgz#57f212700db2d160e8beff6163558310c2c82220"
integrity sha512-BxGfuMK/cXwJxChE4/T6nE4qOdwGLM9iUFFKpcyh9Nks0702qTTvwpjkFbJvlkpe4yulAZh8CKLJrRDVzGGbfQ==
dependencies:
"@react-native/js-polyfills" "^0.72.1"
metro-config "0.76.0"
metro-react-native-babel-transformer "0.76.0"
metro-runtime "0.76.0"

"@sinonjs/commons@^1.7.0":
version "1.7.1"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.7.1.tgz#da5fd19a5f71177a53778073978873964f49acf1"
Expand DownExpand Up@@ -8916,6 +8931,19 @@ metro-react-native-babel-preset@0.76.0:
babel-plugin-transform-flow-enums "^0.0.2"
react-refresh "^0.4.0"

metro-react-native-babel-transformer@0.76.0:
version "0.76.0"
resolved "https://registry.yarnpkg.com/metro-react-native-babel-transformer/-/metro-react-native-babel-transformer-0.76.0.tgz#8c8872f0d3a0ec9dad2480df53c92c10eac92c79"
integrity sha512-mLyUiGq2qPoEwV3oncD82HOtM4wAl8YmXtGY17D4iqH6/5pE32lRnDDYt0WnJYACZDs3RB3MhTjGCM7rJNwn/A==
dependencies:
"@babel/core" "^7.20.0"
babel-preset-fbjs "^3.4.0"
hermes-parser "0.8.0"
metro-babel-transformer "0.76.0"
metro-react-native-babel-preset "0.76.0"
metro-source-map "0.76.0"
nullthrows "^1.1.1"

metro-resolver@0.76.0:
version "0.76.0"
resolved "https://registry.yarnpkg.com/metro-resolver/-/metro-resolver-0.76.0.tgz#3fa778adbab30859023a89e7a1241f4eb68171f2"
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
fix: Fix merge of CLI Metro config overrides, add soft fallback to RN defaults by huntie · Pull Request #1896 · 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
1 change: 1 addition & 0 deletions packages/cli-plugin-metro/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
"dependencies": {
"@react-native-community/cli-server-api": "^11.0.1",
"@react-native-community/cli-tools": "^11.0.1",
"@react-native/metro-config": "^0.72.1",
"chalk": "^4.1.2",
"execa": "^5.0.0",
"metro": "0.76.0",
Expand Down
47 changes: 35 additions & 12 deletions packages/cli-plugin-metro/src/tools/loadMetroConfig.ts
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
import fs from 'fs';
import path from 'path';
import {ConfigT, InputConfigT, loadConfig, resolveConfig} from 'metro-config';
import {
ConfigT,
InputConfigT,
loadConfig,
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 {reactNativePlatformResolver} from './metroPlatformResolver';
Expand DownExpand Up@@ -67,8 +75,8 @@ export interface ConfigOptionsT {
/**
* Load Metro config.
*
* Allows the CLI to override certain defaults in the base `metro.config.js`
* based on dynamic user options in `ctx`.
* Allows the CLI to override select values in `metro.config.js` based on
* dynamic user options in `ctx`.
*/
export default async function loadMetroConfig(
ctx: ConfigLoadingContext,
Expand All@@ -89,17 +97,32 @@ export default async function loadMetroConfig(
// @ts-ignore resolveConfig return value is mistyped
logger.debug(`Reading Metro config from ${projectConfig.filepath}`);

try {
require.resolve('@react-native/metro-config', {
paths: [ctx.root],
});
} catch (e) {
if (
!/['"']@react-native\/metro-config['"']/.test(
fs
// @ts-ignore resolveConfig return value is mistyped
.readFileSync(projectConfig.filepath, 'utf8'),
)
) {
logger.warn(
"From React Native 0.72, your 'metro.config.js' file should " +
"extend '@react-native/metro-config', however it's not present in your " +
"project's devDependencies. Please install '@react-native/metro-config'.",
'From React Native 0.72, your metro.config.js file should extend' +
"'@react-native/metro-config'. Please see the React Native 0.72 " +
'changelog, or copy the template at:\n' +
'https://github.com/facebook/react-native/blob/main/packages/react-native/template/metro.config.js',
Comment on lines +108 to +111

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for adding a reference to copy the config

@huntiehuntieApr 3, 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.

ty, ideal reference is once we have a URL for the changelog/upgrade helper :)

);
logger.warn('Falling back to internal defaults.');

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

return mergeConfig(loadedConfig, overrideConfig);
}

return loadConfig({cwd: ctx.root, ...options}, overrideConfig);
return mergeConfig(
await loadConfig({cwd: ctx.root, ...options}),
overrideConfig,
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
declare module '@react-native/metro-config' {
import type {ConfigT} from 'metro-config';

export function getDefaultConfig(projectRoot: string): ConfigT;
}
28 changes: 28 additions & 0 deletions yarn.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -2673,6 +2673,21 @@
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.72.1":
version "0.72.1"
resolved "https://registry.yarnpkg.com/@react-native/js-polyfills/-/js-polyfills-0.72.1.tgz#905343ef0c51256f128256330fccbdb35b922291"
integrity sha512-cRPZh2rBswFnGt5X5EUEPs0r+pAsXxYsifv/fgy9ZLQokuT52bPH+9xjDR+7TafRua5CttGW83wP4TntRcWNDA==

"@react-native/metro-config@^0.72.1":
version "0.72.1"
resolved "https://registry.yarnpkg.com/@react-native/metro-config/-/metro-config-0.72.1.tgz#57f212700db2d160e8beff6163558310c2c82220"
integrity sha512-BxGfuMK/cXwJxChE4/T6nE4qOdwGLM9iUFFKpcyh9Nks0702qTTvwpjkFbJvlkpe4yulAZh8CKLJrRDVzGGbfQ==
dependencies:
"@react-native/js-polyfills" "^0.72.1"
metro-config "0.76.0"
metro-react-native-babel-transformer "0.76.0"
metro-runtime "0.76.0"

"@sinonjs/commons@^1.7.0":
version "1.7.1"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.7.1.tgz#da5fd19a5f71177a53778073978873964f49acf1"
Expand DownExpand Up@@ -8916,6 +8931,19 @@ metro-react-native-babel-preset@0.76.0:
babel-plugin-transform-flow-enums "^0.0.2"
react-refresh "^0.4.0"

metro-react-native-babel-transformer@0.76.0:
version "0.76.0"
resolved "https://registry.yarnpkg.com/metro-react-native-babel-transformer/-/metro-react-native-babel-transformer-0.76.0.tgz#8c8872f0d3a0ec9dad2480df53c92c10eac92c79"
integrity sha512-mLyUiGq2qPoEwV3oncD82HOtM4wAl8YmXtGY17D4iqH6/5pE32lRnDDYt0WnJYACZDs3RB3MhTjGCM7rJNwn/A==
dependencies:
"@babel/core" "^7.20.0"
babel-preset-fbjs "^3.4.0"
hermes-parser "0.8.0"
metro-babel-transformer "0.76.0"
metro-react-native-babel-preset "0.76.0"
metro-source-map "0.76.0"
nullthrows "^1.1.1"

metro-resolver@0.76.0:
version "0.76.0"
resolved "https://registry.yarnpkg.com/metro-resolver/-/metro-resolver-0.76.0.tgz#3fa778adbab30859023a89e7a1241f4eb68171f2"
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' fix: Fix merge of CLI Metro config overrides, add soft fallback to RN defaults by huntie · Pull Request #1896 · 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
1 change: 1 addition & 0 deletions packages/cli-plugin-metro/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
"dependencies": {
"@react-native-community/cli-server-api": "^11.0.1",
"@react-native-community/cli-tools": "^11.0.1",
"@react-native/metro-config": "^0.72.1",
"chalk": "^4.1.2",
"execa": "^5.0.0",
"metro": "0.76.0",
Expand Down
47 changes: 35 additions & 12 deletions packages/cli-plugin-metro/src/tools/loadMetroConfig.ts
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
import fs from 'fs';
import path from 'path';
import {ConfigT, InputConfigT, loadConfig, resolveConfig} from 'metro-config';
import {
ConfigT,
InputConfigT,
loadConfig,
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 {reactNativePlatformResolver} from './metroPlatformResolver';
Expand DownExpand Up@@ -67,8 +75,8 @@ export interface ConfigOptionsT {
/**
* Load Metro config.
*
* Allows the CLI to override certain defaults in the base `metro.config.js`
* based on dynamic user options in `ctx`.
* Allows the CLI to override select values in `metro.config.js` based on
* dynamic user options in `ctx`.
*/
export default async function loadMetroConfig(
ctx: ConfigLoadingContext,
Expand All@@ -89,17 +97,32 @@ export default async function loadMetroConfig(
// @ts-ignore resolveConfig return value is mistyped
logger.debug(`Reading Metro config from ${projectConfig.filepath}`);

try {
require.resolve('@react-native/metro-config', {
paths: [ctx.root],
});
} catch (e) {
if (
!/['"']@react-native\/metro-config['"']/.test(
fs
// @ts-ignore resolveConfig return value is mistyped
.readFileSync(projectConfig.filepath, 'utf8'),
)
) {
logger.warn(
"From React Native 0.72, your 'metro.config.js' file should " +
"extend '@react-native/metro-config', however it's not present in your " +
"project's devDependencies. Please install '@react-native/metro-config'.",
'From React Native 0.72, your metro.config.js file should extend' +
"'@react-native/metro-config'. Please see the React Native 0.72 " +
'changelog, or copy the template at:\n' +
'https://github.com/facebook/react-native/blob/main/packages/react-native/template/metro.config.js',
Comment on lines +108 to +111

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for adding a reference to copy the config

@huntiehuntieApr 3, 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.

ty, ideal reference is once we have a URL for the changelog/upgrade helper :)

);
logger.warn('Falling back to internal defaults.');

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

return mergeConfig(loadedConfig, overrideConfig);
}

return loadConfig({cwd: ctx.root, ...options}, overrideConfig);
return mergeConfig(
await loadConfig({cwd: ctx.root, ...options}),
overrideConfig,
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
declare module '@react-native/metro-config' {
import type {ConfigT} from 'metro-config';

export function getDefaultConfig(projectRoot: string): ConfigT;
}
28 changes: 28 additions & 0 deletions yarn.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -2673,6 +2673,21 @@
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.72.1":
version "0.72.1"
resolved "https://registry.yarnpkg.com/@react-native/js-polyfills/-/js-polyfills-0.72.1.tgz#905343ef0c51256f128256330fccbdb35b922291"
integrity sha512-cRPZh2rBswFnGt5X5EUEPs0r+pAsXxYsifv/fgy9ZLQokuT52bPH+9xjDR+7TafRua5CttGW83wP4TntRcWNDA==

"@react-native/metro-config@^0.72.1":
version "0.72.1"
resolved "https://registry.yarnpkg.com/@react-native/metro-config/-/metro-config-0.72.1.tgz#57f212700db2d160e8beff6163558310c2c82220"
integrity sha512-BxGfuMK/cXwJxChE4/T6nE4qOdwGLM9iUFFKpcyh9Nks0702qTTvwpjkFbJvlkpe4yulAZh8CKLJrRDVzGGbfQ==
dependencies:
"@react-native/js-polyfills" "^0.72.1"
metro-config "0.76.0"
metro-react-native-babel-transformer "0.76.0"
metro-runtime "0.76.0"

"@sinonjs/commons@^1.7.0":
version "1.7.1"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.7.1.tgz#da5fd19a5f71177a53778073978873964f49acf1"
Expand DownExpand Up@@ -8916,6 +8931,19 @@ metro-react-native-babel-preset@0.76.0:
babel-plugin-transform-flow-enums "^0.0.2"
react-refresh "^0.4.0"

metro-react-native-babel-transformer@0.76.0:
version "0.76.0"
resolved "https://registry.yarnpkg.com/metro-react-native-babel-transformer/-/metro-react-native-babel-transformer-0.76.0.tgz#8c8872f0d3a0ec9dad2480df53c92c10eac92c79"
integrity sha512-mLyUiGq2qPoEwV3oncD82HOtM4wAl8YmXtGY17D4iqH6/5pE32lRnDDYt0WnJYACZDs3RB3MhTjGCM7rJNwn/A==
dependencies:
"@babel/core" "^7.20.0"
babel-preset-fbjs "^3.4.0"
hermes-parser "0.8.0"
metro-babel-transformer "0.76.0"
metro-react-native-babel-preset "0.76.0"
metro-source-map "0.76.0"
nullthrows "^1.1.1"

metro-resolver@0.76.0:
version "0.76.0"
resolved "https://registry.yarnpkg.com/metro-resolver/-/metro-resolver-0.76.0.tgz#3fa778adbab30859023a89e7a1241f4eb68171f2"
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', '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('^' + ".*" + ' fix: Fix merge of CLI Metro config overrides, add soft fallback to RN defaults by huntie · Pull Request #1896 · 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
1 change: 1 addition & 0 deletions packages/cli-plugin-metro/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
"dependencies": {
"@react-native-community/cli-server-api": "^11.0.1",
"@react-native-community/cli-tools": "^11.0.1",
"@react-native/metro-config": "^0.72.1",
"chalk": "^4.1.2",
"execa": "^5.0.0",
"metro": "0.76.0",
Expand Down
47 changes: 35 additions & 12 deletions packages/cli-plugin-metro/src/tools/loadMetroConfig.ts
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
import fs from 'fs';
import path from 'path';
import {ConfigT, InputConfigT, loadConfig, resolveConfig} from 'metro-config';
import {
ConfigT,
InputConfigT,
loadConfig,
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 {reactNativePlatformResolver} from './metroPlatformResolver';
Expand DownExpand Up@@ -67,8 +75,8 @@ export interface ConfigOptionsT {
/**
* Load Metro config.
*
* Allows the CLI to override certain defaults in the base `metro.config.js`
* based on dynamic user options in `ctx`.
* Allows the CLI to override select values in `metro.config.js` based on
* dynamic user options in `ctx`.
*/
export default async function loadMetroConfig(
ctx: ConfigLoadingContext,
Expand All@@ -89,17 +97,32 @@ export default async function loadMetroConfig(
// @ts-ignore resolveConfig return value is mistyped
logger.debug(`Reading Metro config from ${projectConfig.filepath}`);

try {
require.resolve('@react-native/metro-config', {
paths: [ctx.root],
});
} catch (e) {
if (
!/['"']@react-native\/metro-config['"']/.test(
fs
// @ts-ignore resolveConfig return value is mistyped
.readFileSync(projectConfig.filepath, 'utf8'),
)
) {
logger.warn(
"From React Native 0.72, your 'metro.config.js' file should " +
"extend '@react-native/metro-config', however it's not present in your " +
"project's devDependencies. Please install '@react-native/metro-config'.",
'From React Native 0.72, your metro.config.js file should extend' +
"'@react-native/metro-config'. Please see the React Native 0.72 " +
'changelog, or copy the template at:\n' +
'https://github.com/facebook/react-native/blob/main/packages/react-native/template/metro.config.js',
Comment on lines +108 to +111

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for adding a reference to copy the config

@huntiehuntieApr 3, 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.

ty, ideal reference is once we have a URL for the changelog/upgrade helper :)

);
logger.warn('Falling back to internal defaults.');

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

return mergeConfig(loadedConfig, overrideConfig);
}

return loadConfig({cwd: ctx.root, ...options}, overrideConfig);
return mergeConfig(
await loadConfig({cwd: ctx.root, ...options}),
overrideConfig,
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
declare module '@react-native/metro-config' {
import type {ConfigT} from 'metro-config';

export function getDefaultConfig(projectRoot: string): ConfigT;
}
28 changes: 28 additions & 0 deletions yarn.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -2673,6 +2673,21 @@
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.72.1":
version "0.72.1"
resolved "https://registry.yarnpkg.com/@react-native/js-polyfills/-/js-polyfills-0.72.1.tgz#905343ef0c51256f128256330fccbdb35b922291"
integrity sha512-cRPZh2rBswFnGt5X5EUEPs0r+pAsXxYsifv/fgy9ZLQokuT52bPH+9xjDR+7TafRua5CttGW83wP4TntRcWNDA==

"@react-native/metro-config@^0.72.1":
version "0.72.1"
resolved "https://registry.yarnpkg.com/@react-native/metro-config/-/metro-config-0.72.1.tgz#57f212700db2d160e8beff6163558310c2c82220"
integrity sha512-BxGfuMK/cXwJxChE4/T6nE4qOdwGLM9iUFFKpcyh9Nks0702qTTvwpjkFbJvlkpe4yulAZh8CKLJrRDVzGGbfQ==
dependencies:
"@react-native/js-polyfills" "^0.72.1"
metro-config "0.76.0"
metro-react-native-babel-transformer "0.76.0"
metro-runtime "0.76.0"

"@sinonjs/commons@^1.7.0":
version "1.7.1"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.7.1.tgz#da5fd19a5f71177a53778073978873964f49acf1"
Expand DownExpand Up@@ -8916,6 +8931,19 @@ metro-react-native-babel-preset@0.76.0:
babel-plugin-transform-flow-enums "^0.0.2"
react-refresh "^0.4.0"

metro-react-native-babel-transformer@0.76.0:
version "0.76.0"
resolved "https://registry.yarnpkg.com/metro-react-native-babel-transformer/-/metro-react-native-babel-transformer-0.76.0.tgz#8c8872f0d3a0ec9dad2480df53c92c10eac92c79"
integrity sha512-mLyUiGq2qPoEwV3oncD82HOtM4wAl8YmXtGY17D4iqH6/5pE32lRnDDYt0WnJYACZDs3RB3MhTjGCM7rJNwn/A==
dependencies:
"@babel/core" "^7.20.0"
babel-preset-fbjs "^3.4.0"
hermes-parser "0.8.0"
metro-babel-transformer "0.76.0"
metro-react-native-babel-preset "0.76.0"
metro-source-map "0.76.0"
nullthrows "^1.1.1"

metro-resolver@0.76.0:
version "0.76.0"
resolved "https://registry.yarnpkg.com/metro-resolver/-/metro-resolver-0.76.0.tgz#3fa778adbab30859023a89e7a1241f4eb68171f2"
Expand Down
, '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" + ' fix: Fix merge of CLI Metro config overrides, add soft fallback to RN defaults by huntie · Pull Request #1896 · 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
1 change: 1 addition & 0 deletions packages/cli-plugin-metro/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
"dependencies": {
"@react-native-community/cli-server-api": "^11.0.1",
"@react-native-community/cli-tools": "^11.0.1",
"@react-native/metro-config": "^0.72.1",
"chalk": "^4.1.2",
"execa": "^5.0.0",
"metro": "0.76.0",
Expand Down
47 changes: 35 additions & 12 deletions packages/cli-plugin-metro/src/tools/loadMetroConfig.ts
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
import fs from 'fs';
import path from 'path';
import {ConfigT, InputConfigT, loadConfig, resolveConfig} from 'metro-config';
import {
ConfigT,
InputConfigT,
loadConfig,
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 {reactNativePlatformResolver} from './metroPlatformResolver';
Expand DownExpand Up@@ -67,8 +75,8 @@ export interface ConfigOptionsT {
/**
* Load Metro config.
*
* Allows the CLI to override certain defaults in the base `metro.config.js`
* based on dynamic user options in `ctx`.
* Allows the CLI to override select values in `metro.config.js` based on
* dynamic user options in `ctx`.
*/
export default async function loadMetroConfig(
ctx: ConfigLoadingContext,
Expand All@@ -89,17 +97,32 @@ export default async function loadMetroConfig(
// @ts-ignore resolveConfig return value is mistyped
logger.debug(`Reading Metro config from ${projectConfig.filepath}`);

try {
require.resolve('@react-native/metro-config', {
paths: [ctx.root],
});
} catch (e) {
if (
!/['"']@react-native\/metro-config['"']/.test(
fs
// @ts-ignore resolveConfig return value is mistyped
.readFileSync(projectConfig.filepath, 'utf8'),
)
) {
logger.warn(
"From React Native 0.72, your 'metro.config.js' file should " +
"extend '@react-native/metro-config', however it's not present in your " +
"project's devDependencies. Please install '@react-native/metro-config'.",
'From React Native 0.72, your metro.config.js file should extend' +
"'@react-native/metro-config'. Please see the React Native 0.72 " +
'changelog, or copy the template at:\n' +
'https://github.com/facebook/react-native/blob/main/packages/react-native/template/metro.config.js',
Comment on lines +108 to +111

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for adding a reference to copy the config

@huntiehuntieApr 3, 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.

ty, ideal reference is once we have a URL for the changelog/upgrade helper :)

);
logger.warn('Falling back to internal defaults.');

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

return mergeConfig(loadedConfig, overrideConfig);
}

return loadConfig({cwd: ctx.root, ...options}, overrideConfig);
return mergeConfig(
await loadConfig({cwd: ctx.root, ...options}),
overrideConfig,
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
declare module '@react-native/metro-config' {
import type {ConfigT} from 'metro-config';

export function getDefaultConfig(projectRoot: string): ConfigT;
}
28 changes: 28 additions & 0 deletions yarn.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -2673,6 +2673,21 @@
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.72.1":
version "0.72.1"
resolved "https://registry.yarnpkg.com/@react-native/js-polyfills/-/js-polyfills-0.72.1.tgz#905343ef0c51256f128256330fccbdb35b922291"
integrity sha512-cRPZh2rBswFnGt5X5EUEPs0r+pAsXxYsifv/fgy9ZLQokuT52bPH+9xjDR+7TafRua5CttGW83wP4TntRcWNDA==

"@react-native/metro-config@^0.72.1":
version "0.72.1"
resolved "https://registry.yarnpkg.com/@react-native/metro-config/-/metro-config-0.72.1.tgz#57f212700db2d160e8beff6163558310c2c82220"
integrity sha512-BxGfuMK/cXwJxChE4/T6nE4qOdwGLM9iUFFKpcyh9Nks0702qTTvwpjkFbJvlkpe4yulAZh8CKLJrRDVzGGbfQ==
dependencies:
"@react-native/js-polyfills" "^0.72.1"
metro-config "0.76.0"
metro-react-native-babel-transformer "0.76.0"
metro-runtime "0.76.0"

"@sinonjs/commons@^1.7.0":
version "1.7.1"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.7.1.tgz#da5fd19a5f71177a53778073978873964f49acf1"
Expand DownExpand Up@@ -8916,6 +8931,19 @@ metro-react-native-babel-preset@0.76.0:
babel-plugin-transform-flow-enums "^0.0.2"
react-refresh "^0.4.0"

metro-react-native-babel-transformer@0.76.0:
version "0.76.0"
resolved "https://registry.yarnpkg.com/metro-react-native-babel-transformer/-/metro-react-native-babel-transformer-0.76.0.tgz#8c8872f0d3a0ec9dad2480df53c92c10eac92c79"
integrity sha512-mLyUiGq2qPoEwV3oncD82HOtM4wAl8YmXtGY17D4iqH6/5pE32lRnDDYt0WnJYACZDs3RB3MhTjGCM7rJNwn/A==
dependencies:
"@babel/core" "^7.20.0"
babel-preset-fbjs "^3.4.0"
hermes-parser "0.8.0"
metro-babel-transformer "0.76.0"
metro-react-native-babel-preset "0.76.0"
metro-source-map "0.76.0"
nullthrows "^1.1.1"

metro-resolver@0.76.0:
version "0.76.0"
resolved "https://registry.yarnpkg.com/metro-resolver/-/metro-resolver-0.76.0.tgz#3fa778adbab30859023a89e7a1241f4eb68171f2"
Expand Down
, '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('^' + ".*" + ' fix: Fix merge of CLI Metro config overrides, add soft fallback to RN defaults by huntie · Pull Request #1896 · 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
1 change: 1 addition & 0 deletions packages/cli-plugin-metro/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
"dependencies": {
"@react-native-community/cli-server-api": "^11.0.1",
"@react-native-community/cli-tools": "^11.0.1",
"@react-native/metro-config": "^0.72.1",
"chalk": "^4.1.2",
"execa": "^5.0.0",
"metro": "0.76.0",
Expand Down
47 changes: 35 additions & 12 deletions packages/cli-plugin-metro/src/tools/loadMetroConfig.ts
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
import fs from 'fs';
import path from 'path';
import {ConfigT, InputConfigT, loadConfig, resolveConfig} from 'metro-config';
import {
ConfigT,
InputConfigT,
loadConfig,
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 {reactNativePlatformResolver} from './metroPlatformResolver';
Expand DownExpand Up@@ -67,8 +75,8 @@ export interface ConfigOptionsT {
/**
* Load Metro config.
*
* Allows the CLI to override certain defaults in the base `metro.config.js`
* based on dynamic user options in `ctx`.
* Allows the CLI to override select values in `metro.config.js` based on
* dynamic user options in `ctx`.
*/
export default async function loadMetroConfig(
ctx: ConfigLoadingContext,
Expand All@@ -89,17 +97,32 @@ export default async function loadMetroConfig(
// @ts-ignore resolveConfig return value is mistyped
logger.debug(`Reading Metro config from ${projectConfig.filepath}`);

try {
require.resolve('@react-native/metro-config', {
paths: [ctx.root],
});
} catch (e) {
if (
!/['"']@react-native\/metro-config['"']/.test(
fs
// @ts-ignore resolveConfig return value is mistyped
.readFileSync(projectConfig.filepath, 'utf8'),
)
) {
logger.warn(
"From React Native 0.72, your 'metro.config.js' file should " +
"extend '@react-native/metro-config', however it's not present in your " +
"project's devDependencies. Please install '@react-native/metro-config'.",
'From React Native 0.72, your metro.config.js file should extend' +
"'@react-native/metro-config'. Please see the React Native 0.72 " +
'changelog, or copy the template at:\n' +
'https://github.com/facebook/react-native/blob/main/packages/react-native/template/metro.config.js',
Comment on lines +108 to +111

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for adding a reference to copy the config

@huntiehuntieApr 3, 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.

ty, ideal reference is once we have a URL for the changelog/upgrade helper :)

);
logger.warn('Falling back to internal defaults.');

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

return mergeConfig(loadedConfig, overrideConfig);
}

return loadConfig({cwd: ctx.root, ...options}, overrideConfig);
return mergeConfig(
await loadConfig({cwd: ctx.root, ...options}),
overrideConfig,
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
declare module '@react-native/metro-config' {
import type {ConfigT} from 'metro-config';

export function getDefaultConfig(projectRoot: string): ConfigT;
}
28 changes: 28 additions & 0 deletions yarn.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -2673,6 +2673,21 @@
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.72.1":
version "0.72.1"
resolved "https://registry.yarnpkg.com/@react-native/js-polyfills/-/js-polyfills-0.72.1.tgz#905343ef0c51256f128256330fccbdb35b922291"
integrity sha512-cRPZh2rBswFnGt5X5EUEPs0r+pAsXxYsifv/fgy9ZLQokuT52bPH+9xjDR+7TafRua5CttGW83wP4TntRcWNDA==

"@react-native/metro-config@^0.72.1":
version "0.72.1"
resolved "https://registry.yarnpkg.com/@react-native/metro-config/-/metro-config-0.72.1.tgz#57f212700db2d160e8beff6163558310c2c82220"
integrity sha512-BxGfuMK/cXwJxChE4/T6nE4qOdwGLM9iUFFKpcyh9Nks0702qTTvwpjkFbJvlkpe4yulAZh8CKLJrRDVzGGbfQ==
dependencies:
"@react-native/js-polyfills" "^0.72.1"
metro-config "0.76.0"
metro-react-native-babel-transformer "0.76.0"
metro-runtime "0.76.0"

"@sinonjs/commons@^1.7.0":
version "1.7.1"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.7.1.tgz#da5fd19a5f71177a53778073978873964f49acf1"
Expand DownExpand Up@@ -8916,6 +8931,19 @@ metro-react-native-babel-preset@0.76.0:
babel-plugin-transform-flow-enums "^0.0.2"
react-refresh "^0.4.0"

metro-react-native-babel-transformer@0.76.0:
version "0.76.0"
resolved "https://registry.yarnpkg.com/metro-react-native-babel-transformer/-/metro-react-native-babel-transformer-0.76.0.tgz#8c8872f0d3a0ec9dad2480df53c92c10eac92c79"
integrity sha512-mLyUiGq2qPoEwV3oncD82HOtM4wAl8YmXtGY17D4iqH6/5pE32lRnDDYt0WnJYACZDs3RB3MhTjGCM7rJNwn/A==
dependencies:
"@babel/core" "^7.20.0"
babel-preset-fbjs "^3.4.0"
hermes-parser "0.8.0"
metro-babel-transformer "0.76.0"
metro-react-native-babel-preset "0.76.0"
metro-source-map "0.76.0"
nullthrows "^1.1.1"

metro-resolver@0.76.0:
version "0.76.0"
resolved "https://registry.yarnpkg.com/metro-resolver/-/metro-resolver-0.76.0.tgz#3fa778adbab30859023a89e7a1241f4eb68171f2"
Expand Down
, '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: Fix merge of CLI Metro config overrides, add soft fallback to RN defaults by huntie · Pull Request #1896 · 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
1 change: 1 addition & 0 deletions packages/cli-plugin-metro/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
"dependencies": {
"@react-native-community/cli-server-api": "^11.0.1",
"@react-native-community/cli-tools": "^11.0.1",
"@react-native/metro-config": "^0.72.1",
"chalk": "^4.1.2",
"execa": "^5.0.0",
"metro": "0.76.0",
Expand Down
47 changes: 35 additions & 12 deletions packages/cli-plugin-metro/src/tools/loadMetroConfig.ts
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
import fs from 'fs';
import path from 'path';
import {ConfigT, InputConfigT, loadConfig, resolveConfig} from 'metro-config';
import {
ConfigT,
InputConfigT,
loadConfig,
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 {reactNativePlatformResolver} from './metroPlatformResolver';
Expand DownExpand Up@@ -67,8 +75,8 @@ export interface ConfigOptionsT {
/**
* Load Metro config.
*
* Allows the CLI to override certain defaults in the base `metro.config.js`
* based on dynamic user options in `ctx`.
* Allows the CLI to override select values in `metro.config.js` based on
* dynamic user options in `ctx`.
*/
export default async function loadMetroConfig(
ctx: ConfigLoadingContext,
Expand All@@ -89,17 +97,32 @@ export default async function loadMetroConfig(
// @ts-ignore resolveConfig return value is mistyped
logger.debug(`Reading Metro config from ${projectConfig.filepath}`);

try {
require.resolve('@react-native/metro-config', {
paths: [ctx.root],
});
} catch (e) {
if (
!/['"']@react-native\/metro-config['"']/.test(
fs
// @ts-ignore resolveConfig return value is mistyped
.readFileSync(projectConfig.filepath, 'utf8'),
)
) {
logger.warn(
"From React Native 0.72, your 'metro.config.js' file should " +
"extend '@react-native/metro-config', however it's not present in your " +
"project's devDependencies. Please install '@react-native/metro-config'.",
'From React Native 0.72, your metro.config.js file should extend' +
"'@react-native/metro-config'. Please see the React Native 0.72 " +
'changelog, or copy the template at:\n' +
'https://github.com/facebook/react-native/blob/main/packages/react-native/template/metro.config.js',
Comment on lines +108 to +111

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for adding a reference to copy the config

@huntiehuntieApr 3, 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.

ty, ideal reference is once we have a URL for the changelog/upgrade helper :)

);
logger.warn('Falling back to internal defaults.');

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

return mergeConfig(loadedConfig, overrideConfig);
}

return loadConfig({cwd: ctx.root, ...options}, overrideConfig);
return mergeConfig(
await loadConfig({cwd: ctx.root, ...options}),
overrideConfig,
);
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
declare module '@react-native/metro-config' {
import type {ConfigT} from 'metro-config';

export function getDefaultConfig(projectRoot: string): ConfigT;
}
28 changes: 28 additions & 0 deletions yarn.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -2673,6 +2673,21 @@
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.72.1":
version "0.72.1"
resolved "https://registry.yarnpkg.com/@react-native/js-polyfills/-/js-polyfills-0.72.1.tgz#905343ef0c51256f128256330fccbdb35b922291"
integrity sha512-cRPZh2rBswFnGt5X5EUEPs0r+pAsXxYsifv/fgy9ZLQokuT52bPH+9xjDR+7TafRua5CttGW83wP4TntRcWNDA==

"@react-native/metro-config@^0.72.1":
version "0.72.1"
resolved "https://registry.yarnpkg.com/@react-native/metro-config/-/metro-config-0.72.1.tgz#57f212700db2d160e8beff6163558310c2c82220"
integrity sha512-BxGfuMK/cXwJxChE4/T6nE4qOdwGLM9iUFFKpcyh9Nks0702qTTvwpjkFbJvlkpe4yulAZh8CKLJrRDVzGGbfQ==
dependencies:
"@react-native/js-polyfills" "^0.72.1"
metro-config "0.76.0"
metro-react-native-babel-transformer "0.76.0"
metro-runtime "0.76.0"

"@sinonjs/commons@^1.7.0":
version "1.7.1"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.7.1.tgz#da5fd19a5f71177a53778073978873964f49acf1"
Expand DownExpand Up@@ -8916,6 +8931,19 @@ metro-react-native-babel-preset@0.76.0:
babel-plugin-transform-flow-enums "^0.0.2"
react-refresh "^0.4.0"

metro-react-native-babel-transformer@0.76.0:
version "0.76.0"
resolved "https://registry.yarnpkg.com/metro-react-native-babel-transformer/-/metro-react-native-babel-transformer-0.76.0.tgz#8c8872f0d3a0ec9dad2480df53c92c10eac92c79"
integrity sha512-mLyUiGq2qPoEwV3oncD82HOtM4wAl8YmXtGY17D4iqH6/5pE32lRnDDYt0WnJYACZDs3RB3MhTjGCM7rJNwn/A==
dependencies:
"@babel/core" "^7.20.0"
babel-preset-fbjs "^3.4.0"
hermes-parser "0.8.0"
metro-babel-transformer "0.76.0"
metro-react-native-babel-preset "0.76.0"
metro-source-map "0.76.0"
nullthrows "^1.1.1"

metro-resolver@0.76.0:
version "0.76.0"
resolved "https://registry.yarnpkg.com/metro-resolver/-/metro-resolver-0.76.0.tgz#3fa778adbab30859023a89e7a1241f4eb68171f2"
Expand Down