Skip to content

Commit

Permalink
fix(Windows): Support for 0.63 (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 committed Sep 16, 2020
1 parent 20e2ca0 commit 86a3596
Show file tree
Hide file tree
Showing 24 changed files with 388 additions and 207 deletions.
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"react": "~16.8.6 || ~16.9.0 || ~16.11.0 || ~16.13.1",
"react-native": "^0.60.6 || ^0.61.5 || ^0.62.2 || ^0.63.2 || 1000.0.0",
"react-native-macos": "^0.60.0 || ^0.61.0 || ^0.62.0",
"react-native-windows": "^0.62.0"
"react-native-windows": "^0.62.0 || ^0.63.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
Expand Down
7 changes: 7 additions & 0 deletions example/windows/ReactTestAppTests/ManifestTests.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// Copyright (c) Microsoft Corporation
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//

#include "pch.h"

#include <CppUnitTest.h>
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@
"yargs": "^16.0.0"
},
"peerDependencies": {
"mustache": "^4.0.0",
"react": "~16.8.6 || ~16.9.0 || ~16.11.0 || ~16.13.1",
"react-native": "^0.60.6 || ^0.61.5 || ^0.62.2 || ^0.63.2 || 1000.0.0",
"react-native-macos": "^0.60.0 || ^0.61.0 || ^0.62.0",
"react-native-windows": "^0.62.0"
"react-native-windows": "^0.62.0 || ^0.63.0"
},
"peerDependenciesMeta": {
"mustache": {
"optional": true
},
"react-native-macos": {
"optional": true
},
Expand All @@ -62,9 +66,10 @@
"devDependencies": {
"@babel/core": "^7.0.0",
"@types/jest": "^26.0.0",
"@types/mustache": "^4.0.0",
"@types/node": "^12.0.0",
"eslint": "^7.9.0",
"eslint-plugin-jest": "^24.0.1",
"eslint-plugin-jest": "^24.0.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.20.6",
"jest": "^26.4.2",
Expand Down
25 changes: 13 additions & 12 deletions plopfile.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

const chalk = require("chalk");
//
// Copyright (c) Microsoft Corporation
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//

/**
* Returns whether the specified package is installed.
Expand Down Expand Up @@ -70,6 +68,7 @@ module.exports = (plop) => {
return [];
}

const chalk = require("chalk");
const path = require("path");

const { name, platforms } = answers;
Expand Down Expand Up @@ -347,8 +346,9 @@ module.exports = (plop) => {
}
} else {
console.warn(
chalk.yellow("[WARN] ") +
"Cannot find module 'react-native-macos'; skipping macOS target"
`${chalk.yellow(
"[WARN]"
)} Cannot find module 'react-native-macos'; skipping macOS target`
);
}
}
Expand Down Expand Up @@ -378,8 +378,9 @@ module.exports = (plop) => {
}
} else {
console.warn(
chalk.yellow("[WARN] ") +
"Cannot find module 'react-native-windows'; skipping Windows target"
`${chalk.yellow(
"[WARN]"
)} Cannot find module 'react-native-windows'; skipping Windows target`
);
}
}
Expand Down
7 changes: 7 additions & 0 deletions windows/ReactTestApp/App.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// Copyright (c) Microsoft Corporation
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//

#include "pch.h"

#include "App.h"
Expand Down
7 changes: 7 additions & 0 deletions windows/ReactTestApp/App.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// Copyright (c) Microsoft Corporation
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//

#pragma once

#include "App.xaml.g.h"
Expand Down
1 change: 0 additions & 1 deletion windows/ReactTestApp/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ReactTestApp">

</Application>
7 changes: 7 additions & 0 deletions windows/ReactTestApp/MainPage.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// Copyright (c) Microsoft Corporation
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//

#include "pch.h"

#include "MainPage.h"
Expand Down
7 changes: 7 additions & 0 deletions windows/ReactTestApp/MainPage.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// Copyright (c) Microsoft Corporation
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//

#pragma once

#include <any>
Expand Down
1 change: 0 additions & 1 deletion windows/ReactTestApp/MainPage.idl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

namespace ReactTestApp
{
[default_interface] runtimeclass MainPage : Windows.UI.Xaml.Controls.Page
Expand Down
7 changes: 7 additions & 0 deletions windows/ReactTestApp/Manifest.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// Copyright (c) Microsoft Corporation
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//

#include "pch.h"

#include "Manifest.h"
Expand Down
7 changes: 7 additions & 0 deletions windows/ReactTestApp/Manifest.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// Copyright (c) Microsoft Corporation
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//

#pragma once

#include <any>
Expand Down
14 changes: 8 additions & 6 deletions windows/ReactTestApp/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="mp uap rescap">
<Identity
Name="40411fc5-8e92-4d46-b68d-b62df44b1366"
Publisher="CN=AnastasiaOrishchenko"
Version="1.0.0.0" />
<Identity Name="40411fc5-8e92-4d46-b68d-b62df44b1366"
Publisher="CN=AnastasiaOrishchenko"
Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="40411fc5-8e92-4d46-b68d-b62df44b1366" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<Properties>
<DisplayName>ReactTestApp</DisplayName>
Expand All @@ -22,8 +21,11 @@
</Resources>
<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="ReactTestApp.App">
<uap:VisualElements DisplayName="ReactTestApp" Description="Project for a single page C++/WinRT Universal Windows Platform (UWP) app with no predefined layout"
Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" BackgroundColor="transparent">
<uap:VisualElements DisplayName="ReactTestApp"
Description="React Native test app for C++/WinRT Universal Windows Platform (UWP)"
Square150x150Logo="Assets\Square150x150Logo.png"
Square44x44Logo="Assets\Square44x44Logo.png"
BackgroundColor="transparent">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png">
</uap:DefaultTile>
<uap:SplashScreen Image="Assets\SplashScreen.png" />
Expand Down
102 changes: 57 additions & 45 deletions windows/ReactTestApp/ReactInstance.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// Copyright (c) Microsoft Corporation
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//

#include "pch.h"

#include "ReactInstance.h"
Expand All @@ -6,62 +13,67 @@

#include <winrt/Windows.Web.Http.Headers.h>

#include "ReactPackageProvider.h"

using ReactTestApp::ReactInstance;
using winrt::ReactTestApp::implementation::ReactPackageProvider;
using winrt::Windows::Foundation::IAsyncOperation;
using winrt::Windows::Foundation::Uri;
using winrt::Windows::Web::Http::HttpClient;

namespace ReactTestApp
ReactInstance::ReactInstance()
{
void ReactInstance::LoadJSBundleFrom(JSBundleSource source)
{
auto instanceSettings = reactNativeHost_.InstanceSettings();
instanceSettings.UseLiveReload(source == JSBundleSource::DevServer);
instanceSettings.UseWebDebugger(source == JSBundleSource::DevServer);
instanceSettings.UseFastRefresh(source == JSBundleSource::DevServer);
reactNativeHost_.PackageProviders().Append(winrt::make<ReactPackageProvider>());
}

switch (source) {
case JSBundleSource::DevServer:
instanceSettings.JavaScriptMainModuleName(L"index");
instanceSettings.JavaScriptBundleFile(L"");
break;
case JSBundleSource::Embedded:
winrt::hstring bundleFileName = winrt::to_hstring(GetBundleName());
instanceSettings.JavaScriptBundleFile(bundleFileName);
break;
}
void ReactInstance::LoadJSBundleFrom(JSBundleSource source)
{
auto instanceSettings = reactNativeHost_.InstanceSettings();
instanceSettings.UseLiveReload(source == JSBundleSource::DevServer);
instanceSettings.UseWebDebugger(source == JSBundleSource::DevServer);
instanceSettings.UseFastRefresh(source == JSBundleSource::DevServer);

reactNativeHost_.ReloadInstance();
switch (source) {
case JSBundleSource::DevServer:
instanceSettings.JavaScriptMainModuleName(L"index");
instanceSettings.JavaScriptBundleFile(L"");
break;
case JSBundleSource::Embedded:
winrt::hstring bundleFileName = winrt::to_hstring(GetBundleName());
instanceSettings.JavaScriptBundleFile(bundleFileName);
break;
}

std::string GetBundleName()
{
std::vector entryFileNames = {"index.windows",
"main.windows",
"index.native",
"main.native",
"index"
"main"};

for (std::string &&n : entryFileNames) {
std::string path = "Bundle\\" + n + ".bundle";
if (std::filesystem::exists(path)) {
return n;
}
}
reactNativeHost_.ReloadInstance();
}

return "";
}
std::string ReactTestApp::GetBundleName()
{
auto entryFileNames = {"index.windows",
"main.windows",
"index.native",
"main.native",
"index"
"main"};

IAsyncOperation<bool> IsDevServerRunning()
{
Uri uri(L"http://localhost:8081/status");
HttpClient httpClient;
try {
auto r = co_await httpClient.GetAsync(uri);
co_return r.IsSuccessStatusCode();
} catch (winrt::hresult_error &) {
co_return false;
for (std::string main : entryFileNames) {
std::string path = "Bundle\\" + main + ".bundle";
if (std::filesystem::exists(path)) {
return main;
}
}

} // namespace ReactTestApp
return "";
}

IAsyncOperation<bool> ReactTestApp::IsDevServerRunning()
{
Uri uri(L"http://localhost:8081/status");
HttpClient httpClient;
try {
auto r = co_await httpClient.GetAsync(uri);
co_return r.IsSuccessStatusCode();
} catch (winrt::hresult_error &) {
co_return false;
}
}
9 changes: 9 additions & 0 deletions windows/ReactTestApp/ReactInstance.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// Copyright (c) Microsoft Corporation
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//

#pragma once

#include <string>
Expand All @@ -15,6 +22,8 @@ namespace ReactTestApp
class ReactInstance
{
public:
ReactInstance();

auto &ReactHost()
{
return reactNativeHost_;
Expand Down
20 changes: 20 additions & 0 deletions windows/ReactTestApp/ReactPackageProvider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Copyright (c) Microsoft Corporation
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//

#include "pch.h"

#include "ReactPackageProvider.h"

#include <NativeModules.h>

using winrt::Microsoft::ReactNative::IReactPackageBuilder;
using winrt::ReactTestApp::implementation::ReactPackageProvider;

void ReactPackageProvider::CreatePackage(IReactPackageBuilder const &packageBuilder) noexcept
{
AddAttributedModules(packageBuilder);
}
19 changes: 19 additions & 0 deletions windows/ReactTestApp/ReactPackageProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Copyright (c) Microsoft Corporation
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//

#pragma once

#include <winrt/Microsoft.ReactNative.h>

namespace winrt::ReactTestApp::implementation
{
struct ReactPackageProvider
: implements<ReactPackageProvider, Microsoft::ReactNative::IReactPackageProvider> {
public:
void CreatePackage(Microsoft::ReactNative::IReactPackageBuilder const &) noexcept;
};
} // namespace winrt::ReactTestApp::implementation

0 comments on commit 86a3596

Please sign in to comment.