Skip to content

Commit

Permalink
fix(windows): JavaScriptMainModuleName is deprecated (#347)
Browse files Browse the repository at this point in the history
`JavaScriptMainModuleName` was deprecated in 0.64, and removed in
microsoft/react-native-windows@22e1206.
  • Loading branch information
tido64 committed Jun 18, 2021
1 parent 23ee720 commit d154511
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
45 changes: 26 additions & 19 deletions example/metro.config.windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
*/
const fs = require("fs");
const path = require("path");
const blacklist = require("metro-config/src/defaults/blacklist");

const exclusionList = (() => {
try {
return require("metro-config/src/defaults/exclusionList");
} catch (_) {
// `blacklist` was renamed to `exclusionList` in 0.60
return require("metro-config/src/defaults/blacklist");
}
})();

const rnPath = fs.realpathSync(
path.resolve(require.resolve("react-native/package.json"))
Expand All @@ -15,31 +23,30 @@ const rnwPath = fs.realpathSync(
path.resolve(require.resolve("react-native-windows/package.json"))
);

const blockList = exclusionList([
// Since there are multiple copies of react-native, we need to ensure that
// Metro only sees one of them. This should go when haste-map is removed.
new RegExp(`${(path.resolve(rnPath) + path.sep).replace(/[/\\]/g, "/")}.*`),

// This stops "react-native run-windows" from causing the metro server to
// crash if its already running
new RegExp(`${path.resolve(__dirname, "windows").replace(/[/\\]/g, "/")}.*`),

// Workaround for `EBUSY: resource busy or locked, open
// '~\msbuild.ProjectImports.zip'` when building with `yarn windows --release`
/.*\.ProjectImports\.zip/,
]);

module.exports = {
resolver: {
extraNodeModules: {
// Redirect react-native to react-native-windows
"react-native": rnwPath,
"react-native-windows": rnwPath,
},
// Include the macos platform in addition to the defaults because the fork includes macos, but doesn't declare it
platforms: ["ios", "android", "windesktop", "windows", "web", "macos"],
// Since there are multiple copies of react-native, we need to ensure that metro only sees one of them
// This should go in RN 0.61 when haste is removed
blacklistRE: blacklist([
new RegExp(
`${(path.resolve(rnPath) + path.sep).replace(/[/\\]/g, "/")}.*`
),

// This stops "react-native run-windows" from causing the metro server to crash if its already running
new RegExp(
`${path.resolve(__dirname, "windows").replace(/[/\\]/g, "/")}.*`
),

// Workaround for `EBUSY: resource busy or locked, open '~\msbuild.ProjectImports.zip'`
// when building with `yarn windows --release`
/.*\.ProjectImports\.zip/,
]),
platforms: ["windesktop", "windows"],
blacklistRE: blockList,
blockList,
},
transformer: {
getTransformOptions: async () => ({
Expand Down
4 changes: 4 additions & 0 deletions windows/ReactTestApp/ReactInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ void ReactInstance::LoadJSBundleFrom(JSBundleSource source)
auto instanceSettings = reactNativeHost_.InstanceSettings();
switch (source) {
case JSBundleSource::DevServer:
#if REACT_NATIVE_VERSION < 6400
instanceSettings.JavaScriptMainModuleName(L"index");
instanceSettings.JavaScriptBundleFile(L"");
#else
instanceSettings.JavaScriptBundleFile(L"index");
#endif
break;
case JSBundleSource::Embedded:
instanceSettings.JavaScriptBundleFile(winrt::to_hstring(GetBundleName()));
Expand Down

0 comments on commit d154511

Please sign in to comment.