-
-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(samples): Share monorepo config, remove broken promises resolve, …
…add react to blocked packages (#4494)
- Loading branch information
1 parent
40c35c5
commit d997097
Showing
13 changed files
with
113 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const path = require('path'); | ||
const exclusionList = require('metro-config/src/defaults/exclusionList'); | ||
|
||
/** | ||
* Packages used by the sample apps | ||
*/ | ||
const getMonorepoPackages = monorepoRoot => { | ||
return { | ||
'@sentry/react-native': path.resolve(monorepoRoot, 'packages/core'), | ||
}; | ||
}; | ||
|
||
/** | ||
* Block given packages present in the monorepo packages to avoid conflicts with the sample apps | ||
*/ | ||
const getBlockList = (monorepoPackages, excludedPackages) => { | ||
return Object.values(monorepoPackages) | ||
.map(p => excludedPackages.map(e => new RegExp(`${p}/node_modules/${e}/.*`))) | ||
.flat(); | ||
}; | ||
|
||
const withMonorepo = config => { | ||
const projectRoot = config.projectRoot; | ||
if (!projectRoot) { | ||
throw new Error('projectRoot is required'); | ||
} | ||
|
||
const monorepoRoot = path.resolve(projectRoot, '../..'); | ||
const monorepoPackages = getMonorepoPackages(monorepoRoot); | ||
|
||
config.resolver = config.resolver || {}; | ||
|
||
const blockList = [ | ||
...((Array.isArray(config.resolver.blockList) && config.resolver.blockList) || | ||
(!!config.resolver.blockList && [config.resolver.blockList]) || | ||
[]), | ||
...getBlockList(monorepoPackages, ['react-native', 'react']), | ||
new RegExp('.*\\android\\.*'), // Required for Windows in order to run the Sample. | ||
]; | ||
config.resolver.blockList = exclusionList(blockList); | ||
|
||
config.watchFolders = [...(config.watchFolders || []), projectRoot, ...Object.values(monorepoPackages)]; | ||
|
||
config.resolver.extraNodeModules = { | ||
...config.resolver.extraNodeModules, | ||
...monorepoPackages, | ||
'react-native': path.resolve(projectRoot, 'node_modules/react-native'), | ||
react: path.resolve(projectRoot, 'node_modules/react'), | ||
}; | ||
|
||
config.resolver.nodeModulesPaths = [ | ||
...(config.resolver.nodeModulesPaths || []), | ||
path.resolve(projectRoot, 'node_modules'), | ||
...Object.values(monorepoPackages).map(p => path.resolve(p, 'node_modules')), | ||
]; | ||
|
||
return config; | ||
}; | ||
|
||
module.exports = { | ||
withMonorepo, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "sentry-react-native-samples-utils", | ||
"version": "0.0.1", | ||
"description": "Internal Samples Utils", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"private": true, | ||
"dependencies": { | ||
"metro-config": "^0.81.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,20 @@ | ||
const path = require('path'); | ||
const { withSentryConfig } = require('@sentry/react-native/metro'); | ||
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config'); | ||
const exclusionList = require('metro-config/src/defaults/exclusionList'); | ||
|
||
const projectRoot = __dirname; | ||
const monorepoRoot = path.resolve(projectRoot, '../..'); | ||
|
||
// Only list the packages within your monorepo that your app uses. No need to add anything else. | ||
// If your monorepo tooling can give you the list of monorepo workspaces linked | ||
// in your app workspace, you can automate this list instead of hardcoding them. | ||
const monorepoPackages = { | ||
'@sentry/react-native': path.resolve(monorepoRoot, 'packages/core'), | ||
}; | ||
const { withMonorepo } = require('sentry-react-native-samples-utils/metro'); | ||
|
||
/** | ||
* Metro configuration | ||
* https://facebook.github.io/metro/docs/configuration | ||
* | ||
* @type {import('metro-config').MetroConfig} | ||
*/ | ||
const config = { | ||
projectRoot: __dirname, | ||
// 1. Watch the local app directory, and only the shared packages (limiting the scope and speeding it up) | ||
// Note how we change this from `monorepoRoot` to `projectRoot`. This is part of the optimization! | ||
watchFolders: [projectRoot, ...Object.values(monorepoPackages)], | ||
resolver: { | ||
resolverMainFields: ['react-native', 'main'], | ||
resolveRequest: (context, moduleName, platform) => { | ||
if (moduleName.includes('promise/')) { | ||
return context.resolveRequest( | ||
{ | ||
...context, | ||
// Ensures the promise module is resolved from the sample's node_modules. | ||
allowHaste: false, | ||
disableHierarchicalLookup: true, | ||
}, | ||
moduleName, | ||
platform, | ||
); | ||
} | ||
return context.resolveRequest(context, moduleName, platform); | ||
}, | ||
blockList: exclusionList([ | ||
new RegExp('.*\\android\\.*'), // Required for Windows in order to run the Sample. | ||
...Object.values(monorepoPackages).map( | ||
p => new RegExp(`${p}/node_modules/react-native/.*`), | ||
), | ||
]), | ||
// Add the monorepo workspaces as `extraNodeModules` to Metro. | ||
// If your monorepo tooling creates workspace symlinks in the `node_modules` directory, | ||
// you can either add symlink support to Metro or set the `extraNodeModules` to avoid the symlinks. | ||
// See: https://metrobundler.dev/docs/configuration/#extranodemodules | ||
extraNodeModules: { | ||
...monorepoPackages, | ||
'react-native': path.resolve(projectRoot, 'node_modules/react-native'), | ||
}, | ||
nodeModulesPaths: [ | ||
path.resolve(projectRoot, 'node_modules'), | ||
...Object.values(monorepoPackages).map(p => | ||
path.resolve(p, 'node_modules'), | ||
), | ||
], | ||
}, | ||
}; | ||
const config = {}; | ||
|
||
const mergedConfig = mergeConfig(getDefaultConfig(__dirname), config); | ||
|
||
const m = mergeConfig(getDefaultConfig(__dirname), config); | ||
module.exports = withSentryConfig(m, { | ||
const sentryConfig = withSentryConfig(mergedConfig, { | ||
annotateReactComponents: true, | ||
}); | ||
|
||
module.exports = withMonorepo(sentryConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,20 @@ | ||
const path = require('path'); | ||
const { withSentryConfig } = require('@sentry/react-native/metro'); | ||
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config'); | ||
const exclusionList = require('metro-config/src/defaults/exclusionList'); | ||
|
||
const projectRoot = __dirname; | ||
const monorepoRoot = path.resolve(projectRoot, '../..'); | ||
|
||
// Only list the packages within your monorepo that your app uses. No need to add anything else. | ||
// If your monorepo tooling can give you the list of monorepo workspaces linked | ||
// in your app workspace, you can automate this list instead of hardcoding them. | ||
const monorepoPackages = { | ||
'@sentry/react-native': path.resolve(monorepoRoot, 'packages/core'), | ||
}; | ||
const { withMonorepo } = require('sentry-react-native-samples-utils/metro'); | ||
|
||
/** | ||
* Metro configuration | ||
* https://reactnative.dev/docs/metro | ||
* | ||
* @type {import('metro-config').MetroConfig} | ||
*/ | ||
const config = { | ||
projectRoot: __dirname, | ||
// 1. Watch the local app directory, and only the shared packages (limiting the scope and speeding it up) | ||
// Note how we change this from `monorepoRoot` to `projectRoot`. This is part of the optimization! | ||
watchFolders: [projectRoot, ...Object.values(monorepoPackages)], | ||
resolver: { | ||
resolverMainFields: ['react-native', 'main'], | ||
resolveRequest: (context, moduleName, platform) => { | ||
if (moduleName.includes('promise/')) { | ||
return context.resolveRequest( | ||
{ | ||
...context, | ||
// Ensures the promise module is resolved from the sample's node_modules. | ||
allowHaste: false, | ||
disableHierarchicalLookup: true, | ||
}, | ||
moduleName, | ||
platform, | ||
); | ||
} | ||
return context.resolveRequest(context, moduleName, platform); | ||
}, | ||
blockList: exclusionList([ | ||
new RegExp('.*\\android\\.*'), // Required for Windows in order to run the Sample. | ||
...Object.values(monorepoPackages).map( | ||
p => new RegExp(`${p}/node_modules/react-native/.*`), | ||
), | ||
]), | ||
// Add the monorepo workspaces as `extraNodeModules` to Metro. | ||
// If your monorepo tooling creates workspace symlinks in the `node_modules` directory, | ||
// you can either add symlink support to Metro or set the `extraNodeModules` to avoid the symlinks. | ||
// See: https://metrobundler.dev/docs/configuration/#extranodemodules | ||
extraNodeModules: { | ||
...monorepoPackages, | ||
'react-native': path.resolve(projectRoot, 'node_modules/react-native'), | ||
}, | ||
nodeModulesPaths: [ | ||
path.resolve(projectRoot, 'node_modules'), | ||
...Object.values(monorepoPackages).map(p => | ||
path.resolve(p, 'node_modules'), | ||
), | ||
], | ||
}, | ||
}; | ||
const config = {}; | ||
|
||
const mergedConfig = mergeConfig(getDefaultConfig(__dirname), config); | ||
|
||
const m = mergeConfig(getDefaultConfig(__dirname), config); | ||
module.exports = withSentryConfig(m, { | ||
const sentryConfig = withSentryConfig(mergedConfig, { | ||
annotateReactComponents: true, | ||
}); | ||
|
||
module.exports = withMonorepo(sentryConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.