Skip to content

Commit

Permalink
fix: simplify workspace link in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
oscb committed Dec 5, 2023
1 parent 549ecc6 commit 9a1479a
Show file tree
Hide file tree
Showing 11 changed files with 220 additions and 118 deletions.
16 changes: 3 additions & 13 deletions examples/AnalyticsReactNativeExample/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
const path = require('path');
// Workspace packages used by the example app
// This is not required in a standalone production app
const corePackage = require('../../packages/core/package.json');
const sovranPackage = require('../../packages/sovran/package.json');

const basePath = path.join(__dirname, '..', '..', 'packages');

const { srcMap } = require('./workspace')

module.exports = {
presets: ['module:metro-react-native-babel-preset'],
Expand All @@ -14,11 +7,8 @@ module.exports = {
'module-resolver',
{
extensions: ['.tsx', '.ts', '.js', '.json'],
alias: {
[corePackage.name]: path.join(basePath, 'core', corePackage.source),
[sovranPackage.name]: path.join(basePath, 'sovran', sovranPackage.source),
},
alias: srcMap,
},
],
],
};
};
28 changes: 6 additions & 22 deletions examples/AnalyticsReactNativeExample/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,21 @@ const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
const path = require('path');
const escape = require('escape-string-regexp');
const exclusionList = require('metro-config/src/defaults/exclusionList');
// Workspace packages used by the example app
// This is not required in a standalone production app
const corePackage = require('../../packages/core/package.json');
const sovranPackage = require('../../packages/sovran/package.json');

const { peerDeps } = require('./workspace')
const modules = [...peerDeps];
const root = path.resolve(__dirname, '..', '..');
const modules = Object.keys({
...corePackage.peerDependencies,
...sovranPackage.peerDependencies
});

const defaultSourceExts =
require('metro-config/src/defaults/defaults').sourceExts;

/**
* Metro configuration
* https://facebook.github.io/metro/docs/configuration
*
* @type {import('metro-config').MetroConfig}
*/
const config = {
projectRoot: __dirname,
watchFolders: [root],

// We need to make sure that only one version is loaded for peerDependencies
// So we block them at the root, and alias them to the versions in example's node_modules
resolver: {
unstable_enableSymlinks: true,
// We need to make sure that only one version is loaded for peerDependencies
// So we block them at the root, and alias them to the versions in example's node_modules
blacklistRE: exclusionList(
modules.map(
(m) =>
Expand All @@ -42,10 +29,7 @@ const config = {
return acc;
}, {}),

// Used for E2E tests: Replaces files with the extensions specified if any. e.g. RN_SRC_EXT=e2e.mock.ts,e2e.mock.js
sourceExts: process.env.RN_SRC_EXT
? process.env.RN_SRC_EXT.split(',').concat(defaultSourceExts)
: defaultSourceExts,
sourceExts: defaultSourceExts,
},

transformer: {
Expand All @@ -58,4 +42,4 @@ const config = {
},
};

module.exports = mergeConfig(getDefaultConfig(__dirname), config);
module.exports = mergeConfig(getDefaultConfig(__dirname), config);
25 changes: 1 addition & 24 deletions examples/AnalyticsReactNativeExample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,11 @@
"pods": "pod-install --repo-update",
"lint": "eslint .",
"start": "react-native start",
"build:android": "yarn detox build --configuration android.emu.release",
"test:android": "yarn detox test --configuration android.emu.release",
"build:ios": "yarn detox build --configuration ios.sim.release",
"test:ios": "yarn detox test --configuration ios.sim.release",
"start:e2e": "RN_SRC_EXT=e2e.mock.ts,e2e.mock.js yarn start",
"android:deeplink": "adb shell am start -a android.intent.action.VIEW -d \"segmentreactnative://hello\" com.example.segmentanalyticsreactnative",
"ios:deeplink": "xcrun simctl openurl booted segmentreactnative://hello",
"android:emulator": "./android/device_setup.sh",
"clean": "yarn clean:ios && rimraf node_modules",
"clean:ios": "rimraf ios/build ios/Pods",
"e2e:ios": "concurrently \"yarn start:e2e\" \"yarn test:ios\"",
"e2e:android": "concurrently \"yarn start:e2e\" \"yarn test:android\""
"clean:ios": "rimraf ios/build ios/Pods"
},
"dependencies": {
"@react-native-async-storage/async-storage": "^1.0",
Expand All @@ -34,32 +27,16 @@
"react-native-screens": "^3.27.0"
},
"devDependencies": {
"@babel/core": "^7.23.3",
"@babel/preset-env": "^7.23.3",
"@babel/runtime": "^7.23.2",
"@react-native/eslint-config": "^0.72.2",
"@react-native/metro-config": "^0.72.11",
"@tsconfig/react-native": "^3.0.0",
"@types/jest": "^29.5.8",
"@types/react": "^18.2.37",
"@types/react-native": "0.72.6",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.2.1",
"babel-plugin-module-resolver": "^5.0.0",
"body-parser": "^1.20.0",
"concurrently": "^8.2.2",
"detox": "^20.13.5",
"eslint": "^8.19.0",
"express": "^4.17.1",
"jest": "^29.7.0",
"jest-circus": "^29.3.1",
"metro-react-native-babel-preset": "0.76.8",
"pod-install": "^0.1.39",
"prettier": "^2.4.1",
"react-test-renderer": "18.2.0",
"rimraf": "^3.0.2",
"ts-jest": "^29.0.3",
"ts-retry-promise": "^0.7.1",
"typescript": "^5.2.2"
},
"engines": {
Expand Down
13 changes: 2 additions & 11 deletions examples/AnalyticsReactNativeExample/react-native.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
const path = require('path');
const corePackage = require('../../packages/core/package.json');
const sovranPackage = require('../../packages/sovran/package.json');

const basePath = path.join(__dirname, '..', '..', 'packages');
const { rootMap } = require('./workspace') // Load the linked data

module.exports = {
dependencies: {
// Local packages need to be referenced here to be linked to the app
// This is not required in a standalone production app
[corePackage.name]: {
root: path.join(basePath, 'core'),
},
[sovranPackage.name]: {
root: path.join(basePath, 'sovran'),
},
...rootMap
},
};
5 changes: 5 additions & 0 deletions examples/AnalyticsReactNativeExample/workspace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { getLinkedData } = require('../linkHelper')

module.exports = {
...getLinkedData(['core', 'sovran'])
}
16 changes: 3 additions & 13 deletions examples/E2E/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
const path = require('path');
// Workspace packages used by the example app
// This is not required in a standalone production app
const corePackage = require('../../packages/core/package.json');
const sovranPackage = require('../../packages/sovran/package.json');

const basePath = path.join(__dirname, '..', '..', 'packages');

const { srcMap } = require('./workspace')

module.exports = {
presets: ['module:metro-react-native-babel-preset'],
Expand All @@ -14,11 +7,8 @@ module.exports = {
'module-resolver',
{
extensions: ['.tsx', '.ts', '.js', '.json'],
alias: {
[corePackage.name]: path.join(basePath, 'core', corePackage.source),
[sovranPackage.name]: path.join(basePath, 'sovran', sovranPackage.source),
},
alias: srcMap,
},
],
],
};
};
28 changes: 6 additions & 22 deletions examples/E2E/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,21 @@ const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
const path = require('path');
const escape = require('escape-string-regexp');
const exclusionList = require('metro-config/src/defaults/exclusionList');
// Workspace packages used by the example app
// This is not required in a standalone production app
const corePackage = require('../../packages/core/package.json');
const sovranPackage = require('../../packages/sovran/package.json');

const { peerDeps } = require('./workspace')
const modules = [...peerDeps];
const root = path.resolve(__dirname, '..', '..');
const modules = Object.keys({
...corePackage.peerDependencies,
...sovranPackage.peerDependencies
});

const defaultSourceExts =
require('metro-config/src/defaults/defaults').sourceExts;

/**
* Metro configuration
* https://facebook.github.io/metro/docs/configuration
*
* @type {import('metro-config').MetroConfig}
*/
const config = {
projectRoot: __dirname,
watchFolders: [root],

// We need to make sure that only one version is loaded for peerDependencies
// So we block them at the root, and alias them to the versions in example's node_modules
resolver: {
unstable_enableSymlinks: true,
// We need to make sure that only one version is loaded for peerDependencies
// So we block them at the root, and alias them to the versions in example's node_modules
blacklistRE: exclusionList(
modules.map(
(m) =>
Expand All @@ -42,10 +29,7 @@ const config = {
return acc;
}, {}),

// Used for E2E tests: Replaces files with the extensions specified if any. e.g. RN_SRC_EXT=e2e.mock.ts,e2e.mock.js
sourceExts: process.env.RN_SRC_EXT
? process.env.RN_SRC_EXT.split(',').concat(defaultSourceExts)
: defaultSourceExts,
sourceExts: defaultSourceExts,
},

transformer: {
Expand All @@ -58,4 +42,4 @@ const config = {
},
};

module.exports = mergeConfig(getDefaultConfig(__dirname), config);
module.exports = mergeConfig(getDefaultConfig(__dirname), config);
15 changes: 2 additions & 13 deletions examples/E2E/react-native.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
const path = require('path');
const corePackage = require('../../packages/core/package.json');
const sovranPackage = require('../../packages/sovran/package.json');

const basePath = path.join(__dirname, '..', '..', 'packages');
const { rootMap } = require('./workspace') // Load the linked data

module.exports = {
dependencies: {
// Local packages need to be referenced here to be linked to the app
// This is not required in a standalone production app
[corePackage.name]: {
root: path.join(basePath, 'core'),
},
[sovranPackage.name]: {
root: path.join(basePath, 'sovran'),
},
...rootMap
},
};
5 changes: 5 additions & 0 deletions examples/E2E/workspace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { getLinkedData } = require('../linkHelper')

module.exports = {
...getLinkedData(['core', 'sovran'])
}
Loading

0 comments on commit 9a1479a

Please sign in to comment.