From 4b66781c202e087a7e8b6bd7a886c5bbc684b566 Mon Sep 17 00:00:00 2001 From: Keith Melmon Date: Tue, 7 Apr 2020 11:46:46 -0700 Subject: [PATCH 01/12] first version --- packages/E2ETest/metro.config.js | 7 +- packages/E2ETest/postinstall.js | 4 + packages/E2ETest/react-native.config.js | 3 +- .../metro.config.js | 8 +- .../react-native.config.js | 3 +- packages/playground/metro.config.js | 8 +- packages/playground/react-native.config.js | 2 +- vnext/.gitignore | 1 + vnext/.npmignore | 1 + vnext/Scripts/copyRNLibraries.js | 16 ++- vnext/Scripts/installRNW.js | 116 ++++++++++++++++++ vnext/Scripts/postinstall.js | 8 ++ vnext/just-task.js | 6 +- .../templates/metro.config.js | 10 +- .../templates/react-native.config.js | 2 +- vnext/package.json | 7 +- ...d.js => RCTNetworkingWinShared.windows.js} | 0 ...ventTypes.js => CoreEventTypes.windows.js} | 0 ... => NativePlatformConstantsWin.windows.js} | 0 .../react-native-windows-implementation.ts} | 9 +- .../typings-index.ts | 0 vnext/tsconfig.json | 2 +- 22 files changed, 178 insertions(+), 35 deletions(-) create mode 100644 vnext/Scripts/installRNW.js create mode 100644 vnext/Scripts/postinstall.js rename vnext/src/Libraries/Network/{RCTNetworkingWinShared.js => RCTNetworkingWinShared.windows.js} (100%) rename vnext/src/Libraries/Types/{CoreEventTypes.js => CoreEventTypes.windows.js} (100%) rename vnext/src/Libraries/Utilities/{NativePlatformConstantsWin.js => NativePlatformConstantsWin.windows.js} (100%) rename vnext/src/Libraries/{react-native/react-native-implementation.windows.ts => react-native-windows/react-native-windows-implementation.ts} (81%) rename vnext/src/Libraries/{react-native => react-native-windows}/typings-index.ts (100%) diff --git a/packages/E2ETest/metro.config.js b/packages/E2ETest/metro.config.js index fbeeed5942a..2791272a69c 100644 --- a/packages/E2ETest/metro.config.js +++ b/packages/E2ETest/metro.config.js @@ -13,6 +13,8 @@ const rnPath = fs.realpathSync( ); const rnwPath = path.resolve(__dirname, '../../vnext'); +const rnInstallPath = fs.realpathSync(path.resolve(rnwPath, './react-native-installation')); + module.exports = { // WatchFolders is only needed due to the yarn workspace layout of node_modules, we need to watch the symlinked locations separately watchFolders: [ @@ -24,9 +26,8 @@ module.exports = { resolver: { extraNodeModules: { - // Redirect metro to rnwPath instead of node_modules/react-native-windows, since metro doesn't like symlinks - 'react-native': rnwPath, - 'react-native-windows': rnwPath, + // Redirect react-native to the installation path, up and over in vnext/react-native-installation + 'react-native': rnInstallPath, }, // 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'], diff --git a/packages/E2ETest/postinstall.js b/packages/E2ETest/postinstall.js index ea656da5b18..d5c1df36bd8 100644 --- a/packages/E2ETest/postinstall.js +++ b/packages/E2ETest/postinstall.js @@ -40,3 +40,7 @@ link( 'rnpm-plugin-windows', path.resolve(require.resolve('rnpm-plugin-windows/package.json'), '..'), ); + +require('react-native-windows/scripts/installRNW').installRNW(); + + diff --git a/packages/E2ETest/react-native.config.js b/packages/E2ETest/react-native.config.js index 25b1f17a2da..c5567078bb1 100644 --- a/packages/E2ETest/react-native.config.js +++ b/packages/E2ETest/react-native.config.js @@ -1,3 +1,4 @@ +const path = require('path'); module.exports = { - reactNativePath: '../../vnext', + reactNativePath: path.resolve(__dirname, '../../vnext/react-native-installation'), }; diff --git a/packages/microsoft-reactnative-sampleapps/metro.config.js b/packages/microsoft-reactnative-sampleapps/metro.config.js index fd0f93293e9..1be58488c9e 100644 --- a/packages/microsoft-reactnative-sampleapps/metro.config.js +++ b/packages/microsoft-reactnative-sampleapps/metro.config.js @@ -13,6 +13,8 @@ const rnPath = fs.realpathSync( ); const rnwPath = path.resolve(__dirname, '../../vnext'); +const rnInstallPath = fs.realpathSync(path.resolve(rnwPath, './react-native-installation')); + module.exports = { // WatchFolders is only needed due to the yarn workspace layout of node_modules, we need to watch the symlinked locations separately watchFolders: [ @@ -24,14 +26,12 @@ module.exports = { resolver: { extraNodeModules: { - // Redirect metro to rnwPath instead of node_modules/react-native-windows, since metro doesn't like symlinks - 'react-native': rnwPath, - 'react-native-windows': rnwPath, + // Redirect react-native to the installation path, up and over in vnext/react-native-installation + 'react-native': rnInstallPath, }, // 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 away after RN 0.60 when haste is removed blacklistRE: blacklist([ new RegExp( '.*microsoft-reactnative-sampleapps/msbuild.*'.replace(/[/\\]/g, '\\/'), diff --git a/packages/microsoft-reactnative-sampleapps/react-native.config.js b/packages/microsoft-reactnative-sampleapps/react-native.config.js index 25b1f17a2da..c5567078bb1 100644 --- a/packages/microsoft-reactnative-sampleapps/react-native.config.js +++ b/packages/microsoft-reactnative-sampleapps/react-native.config.js @@ -1,3 +1,4 @@ +const path = require('path'); module.exports = { - reactNativePath: '../../vnext', + reactNativePath: path.resolve(__dirname, '../../vnext/react-native-installation'), }; diff --git a/packages/playground/metro.config.js b/packages/playground/metro.config.js index f019392ca1c..4dc6ce483f2 100644 --- a/packages/playground/metro.config.js +++ b/packages/playground/metro.config.js @@ -15,6 +15,8 @@ const rnwPath = fs.realpathSync( path.resolve(require.resolve('react-native-windows/package.json'), '..'), ); +const rnInstallPath = fs.realpathSync(path.resolve(rnwPath, './react-native-installation')); + module.exports = { // WatchFolders is only needed due to the yarn workspace layout of node_modules, we need to watch the symlinked locations separately watchFolders: [ @@ -26,14 +28,12 @@ module.exports = { resolver: { extraNodeModules: { - // Redirect react-native to react-native-windows - 'react-native': rnwPath, - 'react-native-windows': rnwPath, + // Redirect react-native to the installation path, up and over in vnext/react-native-installation + 'react-native': rnInstallPath, }, // 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, '/')}.*`, diff --git a/packages/playground/react-native.config.js b/packages/playground/react-native.config.js index fffebf99369..9ca11979341 100644 --- a/packages/playground/react-native.config.js +++ b/packages/playground/react-native.config.js @@ -2,6 +2,6 @@ const fs = require('fs'); const path = require('path'); module.exports = { reactNativePath: fs.realpathSync( - path.resolve(require.resolve('react-native-windows/package.json'), '..'), + path.resolve(require.resolve('react-native-windows/package.json'), '../react-native-installation'), ), }; diff --git a/vnext/.gitignore b/vnext/.gitignore index b6b6994f050..a33b41b2c05 100644 --- a/vnext/.gitignore +++ b/vnext/.gitignore @@ -53,6 +53,7 @@ node_modules /RNTester /RNTester.* /index.* +/react-native-installation # Visual Studio .vs/ diff --git a/vnext/.npmignore b/vnext/.npmignore index d5ca56801b8..3f17094c5f4 100644 --- a/vnext/.npmignore +++ b/vnext/.npmignore @@ -23,6 +23,7 @@ ReactWindows-Universal.sln ReactWindows-Desktop.sln RNTester.* RNTester/ +react-native-installation src/ target temp diff --git a/vnext/Scripts/copyRNLibraries.js b/vnext/Scripts/copyRNLibraries.js index 89e4e7ac4d7..31817ebfe69 100644 --- a/vnext/Scripts/copyRNLibraries.js +++ b/vnext/Scripts/copyRNLibraries.js @@ -83,7 +83,9 @@ exports.copyRNLibraries = baseDir => { require.resolve('react-native-windows/package.json'), ); - copyDirectories(reactNativeWindowsPath, baseDir, [ + const rnInstallationPath = path.resolve(reactNativeWindowsPath, './react-native-installation'); + + copyDirectories(reactNativeWindowsPath, rnInstallationPath, [ { src: 'ReactCopies/RNTester', dest: 'RNTester', @@ -95,6 +97,16 @@ exports.copyRNLibraries = baseDir => { }, ]); + copyDirectories(baseDir, rnInstallationPath, [ + { + src: 'RNTester', + dest: 'RNTester', + mergeFiles: true, + }, + ]); + +/* +// TODO: figure out what to do with these copyDirectories(reactNativePath, baseDir, [ { src: 'flow', @@ -117,6 +129,7 @@ exports.copyRNLibraries = baseDir => { dest: 'packages/react-native-codegen/src', }, ]); +*/ copyDirectories(baseDir, baseDir, [ { @@ -126,5 +139,4 @@ exports.copyRNLibraries = baseDir => { }, ]); - copyFile(reactNativePath, baseDir, 'rn-get-polyfills.js'); }; diff --git a/vnext/Scripts/installRNW.js b/vnext/Scripts/installRNW.js new file mode 100644 index 00000000000..04e2d4550a7 --- /dev/null +++ b/vnext/Scripts/installRNW.js @@ -0,0 +1,116 @@ +/** + * @format + */ +// @ts-check +const path = require('path'); +const fs = require('fs'); +const glob = require('glob'); +const rimraf = require('rimraf'); + +function retryOnError(errorCode, func) { + const startTime = Date.now(); + + while (true) { + try { + func(); + return true; + } catch (ex) { + if (ex.code !== errorCode) { + throw ex; + } + } + + if (Date.now() - startTime > 5000) { + return false; + } + } +} + +function copyDirectories(srcPath, targetPath, dirSpecs) { + dirSpecs.forEach(dirSpec => { + if (dirSpec.mergeFiles !== true) { + // rimraf issue 72: We will see ENOTEMPTY if Windows is still holding a + // lock to a file in our directory. E.g. if we get unlucky with timing + // and antivirus decides to run. Keep on spinning until we're able to + // delete the directory. + let deleted = retryOnError('ENOTEMPTY', () => { + if (dirSpec.rmFilter === undefined) { + rimraf.sync(path.resolve(targetPath, dirSpec.dest)); + } else { + rimraf.sync( + path.resolve(targetPath, dirSpec.dest + path.sep + dirSpec.filter), + ); + } + }); + + if (!deleted) { + throw new Error( + 'Timed out trying to delete directory. Ensure no locks are being held to project files and try again.', + ); + } + } + + const curSrcPath = path.resolve(srcPath, dirSpec.src); + const curTargetPath = path.resolve(targetPath, dirSpec.dest); + + glob.sync('**/*.{js,png,gif,h}', {cwd: curSrcPath}).forEach(file => { + const dir = path.dirname(file); + const targetDir = path.resolve(curTargetPath, dir); + const targetFile = path.resolve(curTargetPath, file); + + fs.mkdirSync(targetDir, {recursive: true}); + fs.writeFileSync( + targetFile, + fs.readFileSync(path.join(curSrcPath, file)), + ); + }); + }); +} + +function copyFile(srcPath, targetPath, filename) { + fs.writeFileSync( + path.resolve(targetPath, filename), + fs.readFileSync(path.resolve(srcPath, filename)), + ); +} + + +exports.installRNW = installationPath => { + const reactNativePath = path.dirname( + require.resolve('react-native/package.json'), + ); + + const reactNativeWindowsPath = path.dirname( + require.resolve('react-native-windows/package.json'), + ); + + if (!fs.existsSync(installationPath)) { + fs.mkdirSync(installationPath); + } + + copyDirectories(reactNativePath, installationPath, [ + { + src: 'flow', + dest: 'flow', + }, + { + src: 'jest', + dest: 'jest', + }, + { + src: 'Libraries', + dest: 'Libraries', + }, + ]); + + copyFile(reactNativePath, installationPath, 'rn-get-polyfills.js'); + copyFile(reactNativePath, installationPath, 'package.json'); + + copyDirectories(reactNativeWindowsPath, installationPath, [ + { + src: 'Libraries', + dest: 'Libraries', + mergeFiles: true, + }, + ]); +}; \ No newline at end of file diff --git a/vnext/Scripts/postinstall.js b/vnext/Scripts/postinstall.js new file mode 100644 index 00000000000..c5d4ed43e6f --- /dev/null +++ b/vnext/Scripts/postinstall.js @@ -0,0 +1,8 @@ +/** + * @format + */ +// @ts-check + +const path = require('path'); +const installationPath = path.resolve(require.resolve('react-native-windows/package.json'), '../../../react-native-installation'); +require('./installRNW').installRNW(installationPath); \ No newline at end of file diff --git a/vnext/just-task.js b/vnext/just-task.js index 69610303a00..49bd3b4b90d 100644 --- a/vnext/just-task.js +++ b/vnext/just-task.js @@ -53,6 +53,9 @@ task('copyFlowFiles', () => { task('initRNLibraries', () => { require('./Scripts/copyRNLibraries').copyRNLibraries(__dirname); }); +task('installRNW', () => { + require('./Scripts/installRNW').installRNW(path.resolve(__dirname, './react-native-installation')); +}); task('ts', () => { return tscTask({ @@ -77,9 +80,10 @@ task( 'build', series( condition('clean', () => true || argv().clean), - 'initRNLibraries', 'copyFlowFiles', 'ts', + 'installRNW', + 'initRNLibraries', condition('apiExtractorVerify', () => argv().ci), ), ); diff --git a/vnext/local-cli/generator-windows/templates/metro.config.js b/vnext/local-cli/generator-windows/templates/metro.config.js index 2ed937d5378..15d7ed6dc7b 100644 --- a/vnext/local-cli/generator-windows/templates/metro.config.js +++ b/vnext/local-cli/generator-windows/templates/metro.config.js @@ -15,17 +15,17 @@ const rnwPath = fs.realpathSync( path.resolve(require.resolve('react-native-windows/package.json'), '..'), ); +const rnInstallPath = fs.realpathSync(path.resolve(rnwPath, '../../../react-native-installation')); + module.exports = { resolver: { extraNodeModules: { - // Redirect react-native to react-native-windows - 'react-native': rnwPath, - 'react-native-windows': rnwPath, + // Redirect react-native to the installation path + 'react-native': rnInstallPath, }, // 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, '/')}.*`, @@ -37,7 +37,7 @@ module.exports = { ), ]), }, - transformer: { + transformer: { getTransformOptions: async () => ({ transform: { experimentalImportSupport: false, diff --git a/vnext/local-cli/generator-windows/templates/react-native.config.js b/vnext/local-cli/generator-windows/templates/react-native.config.js index cedd9d380ae..aefbc6c0b7a 100644 --- a/vnext/local-cli/generator-windows/templates/react-native.config.js +++ b/vnext/local-cli/generator-windows/templates/react-native.config.js @@ -1,5 +1,5 @@ const fs = require('fs'); const path = require('path'); module.exports = { - reactNativePath: fs.realpathSync(path.resolve(require.resolve('react-native-windows/package.json'), '..')), + reactNativePath: fs.realpathSync(path.resolve(require.resolve('react-native-windows/package.json'), '../../../react-native-installation')), }; diff --git a/vnext/package.json b/vnext/package.json index c083a62f80c..177169341dc 100644 --- a/vnext/package.json +++ b/vnext/package.json @@ -8,8 +8,8 @@ "directory": "vnext" }, "description": "ReactNative Windows implementation using react-native's c++ ReactCommon bridge", - "main": "Libraries/react-native/react-native-implementation.windows.js", - "typings": "Libraries/react-native/typings-index.d.ts", + "main": "Libraries/react-native-windows/react-native-windows-implementation.js", + "typings": "Libraries/react-native-windows/typings-index.d.ts", "scripts": { "api": "just-scripts api", "build": "just-scripts build", @@ -20,7 +20,8 @@ "lint": "just-scripts lint", "start": "react-native start", "watch": "tsc -w", - "validate-overrides": "override validate ./src/overrides.json ./ReactCopies/overrides.json ./DeforkingPatches/overrides.json" + "validate-overrides": "override validate ./src/overrides.json ./ReactCopies/overrides.json ./DeforkingPatches/overrides.json", + "postinstall": "node scripts/postinstall.js" }, "dependencies": { "@babel/runtime": "^7.8.4", diff --git a/vnext/src/Libraries/Network/RCTNetworkingWinShared.js b/vnext/src/Libraries/Network/RCTNetworkingWinShared.windows.js similarity index 100% rename from vnext/src/Libraries/Network/RCTNetworkingWinShared.js rename to vnext/src/Libraries/Network/RCTNetworkingWinShared.windows.js diff --git a/vnext/src/Libraries/Types/CoreEventTypes.js b/vnext/src/Libraries/Types/CoreEventTypes.windows.js similarity index 100% rename from vnext/src/Libraries/Types/CoreEventTypes.js rename to vnext/src/Libraries/Types/CoreEventTypes.windows.js diff --git a/vnext/src/Libraries/Utilities/NativePlatformConstantsWin.js b/vnext/src/Libraries/Utilities/NativePlatformConstantsWin.windows.js similarity index 100% rename from vnext/src/Libraries/Utilities/NativePlatformConstantsWin.js rename to vnext/src/Libraries/Utilities/NativePlatformConstantsWin.windows.js diff --git a/vnext/src/Libraries/react-native/react-native-implementation.windows.ts b/vnext/src/Libraries/react-native-windows/react-native-windows-implementation.ts similarity index 81% rename from vnext/src/Libraries/react-native/react-native-implementation.windows.ts rename to vnext/src/Libraries/react-native-windows/react-native-windows-implementation.ts index abecb382f2e..1fc15389abb 100644 --- a/vnext/src/Libraries/react-native/react-native-implementation.windows.ts +++ b/vnext/src/Libraries/react-native-windows/react-native-windows-implementation.ts @@ -1,13 +1,6 @@ /* This file is used as the root export of this package. - Since react-native is removing haste as a module lookup mechanism, - we need to re-export the whole of react-native from react-native-windows. - - We also export the things that are actually exposed to users as part of react-native-windows. - Following how react-native exports everything, we export using inline requires - to support the inline require optimizations that the various react-native bundlers use. - NOTE: when adding exports here, they should also be added to the `typings-index.ts` file, which will provide proper type information for these exports. @@ -15,7 +8,7 @@ */ import * as ReactNativeWindows from './typings-index'; -const ReactNativeImplementation = require('./react-native-implementation.js'); +const ReactNativeImplementation = {}; Object.defineProperty(ReactNativeImplementation, 'DatePicker', { get: () => { diff --git a/vnext/src/Libraries/react-native/typings-index.ts b/vnext/src/Libraries/react-native-windows/typings-index.ts similarity index 100% rename from vnext/src/Libraries/react-native/typings-index.ts rename to vnext/src/Libraries/react-native-windows/typings-index.ts diff --git a/vnext/tsconfig.json b/vnext/tsconfig.json index d59b7578ce7..81045541acf 100644 --- a/vnext/tsconfig.json +++ b/vnext/tsconfig.json @@ -16,7 +16,7 @@ "strict": true, "rootDir": "src", "paths": { - "react-native-windows": ["src/Libraries/react-native/typings-index"] // This mapping is relative to "baseUrl" + "react-native-windows": ["src/Libraries/react-native-windows/typings-index"] // This mapping is relative to "baseUrl" } }, "include": ["src"], From b25318bfa82c76e194bc1e16e309a1b7107cd783 Mon Sep 17 00:00:00 2001 From: Keith Melmon Date: Fri, 10 Apr 2020 11:55:55 -0700 Subject: [PATCH 02/12] Change files --- ...eact-native-windows-2020-04-10-11-55-54-metro-fix.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 change/react-native-windows-2020-04-10-11-55-54-metro-fix.json diff --git a/change/react-native-windows-2020-04-10-11-55-54-metro-fix.json b/change/react-native-windows-2020-04-10-11-55-54-metro-fix.json new file mode 100644 index 00000000000..9164f490912 --- /dev/null +++ b/change/react-native-windows-2020-04-10-11-55-54-metro-fix.json @@ -0,0 +1,8 @@ +{ + "type": "prerelease", + "comment": "refactor react-native-windows install to better support metro", + "packageName": "react-native-windows", + "email": "kmelmon@microsoft.com", + "dependentChangeType": "patch", + "date": "2020-04-10T18:55:54.788Z" +} \ No newline at end of file From beea8af91c0ae29c4f8e08e1be949b301466c852 Mon Sep 17 00:00:00 2001 From: Keith Melmon Date: Fri, 10 Apr 2020 12:01:37 -0700 Subject: [PATCH 03/12] fixup e2etest --- packages/E2ETest/postinstall.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/E2ETest/postinstall.js b/packages/E2ETest/postinstall.js index d5c1df36bd8..55d39473b0a 100644 --- a/packages/E2ETest/postinstall.js +++ b/packages/E2ETest/postinstall.js @@ -41,6 +41,5 @@ link( path.resolve(require.resolve('rnpm-plugin-windows/package.json'), '..'), ); -require('react-native-windows/scripts/installRNW').installRNW(); From 2e1c124ca47fa7440a98a652d14510906f1c61fb Mon Sep 17 00:00:00 2001 From: Keith Melmon Date: Fri, 10 Apr 2020 23:07:30 -0700 Subject: [PATCH 04/12] fixup react-native-win32, take 1 --- packages/react-native-win32/.gitignore | 3 +- .../Scripts/copyRNWin32Libraries.js | 90 +++++++++++++++++++ packages/react-native-win32/just-task.js | 7 +- packages/react-native-win32/metro.config.js | 8 +- packages/react-native-win32/package.json | 6 +- .../react-native-win32/react-native.config.js | 3 +- vnext/Scripts/copyRNLibraries.js | 2 +- vnext/Scripts/installRNW.js | 6 +- vnext/Scripts/postinstall.js | 3 +- 9 files changed, 110 insertions(+), 18 deletions(-) create mode 100644 packages/react-native-win32/Scripts/copyRNWin32Libraries.js diff --git a/packages/react-native-win32/.gitignore b/packages/react-native-win32/.gitignore index a16c2e663b4..8bf7912d683 100644 --- a/packages/react-native-win32/.gitignore +++ b/packages/react-native-win32/.gitignore @@ -9,4 +9,5 @@ /RNTester /RNTester.* /temp -/WorkingHeaders \ No newline at end of file +/WorkingHeaders +/react-native-installation diff --git a/packages/react-native-win32/Scripts/copyRNWin32Libraries.js b/packages/react-native-win32/Scripts/copyRNWin32Libraries.js new file mode 100644 index 00000000000..31023ea97ac --- /dev/null +++ b/packages/react-native-win32/Scripts/copyRNWin32Libraries.js @@ -0,0 +1,90 @@ +/** + * @format + */ +// @ts-check +const path = require('path'); +const fs = require('fs'); +const glob = require('glob'); +const rimraf = require('rimraf'); + +function retryOnError(errorCode, func) { + const startTime = Date.now(); + + while (true) { + try { + func(); + return true; + } catch (ex) { + if (ex.code !== errorCode) { + throw ex; + } + } + + if (Date.now() - startTime > 5000) { + return false; + } + } +} + +function copyDirectories(srcPath, targetPath, dirSpecs) { + dirSpecs.forEach(dirSpec => { + if (dirSpec.mergeFiles !== true) { + // rimraf issue 72: We will see ENOTEMPTY if Windows is still holding a + // lock to a file in our directory. E.g. if we get unlucky with timing + // and antivirus decides to run. Keep on spinning until we're able to + // delete the directory. + let deleted = retryOnError('ENOTEMPTY', () => { + if (dirSpec.rmFilter === undefined) { + rimraf.sync(path.resolve(targetPath, dirSpec.dest)); + } else { + rimraf.sync( + path.resolve(targetPath, dirSpec.dest + path.sep + dirSpec.filter), + ); + } + }); + + if (!deleted) { + throw new Error( + 'Timed out trying to delete directory. Ensure no locks are being held to project files and try again.', + ); + } + } + + const curSrcPath = path.resolve(srcPath, dirSpec.src); + const curTargetPath = path.resolve(targetPath, dirSpec.dest); + + glob.sync('**/*.{js,png,gif,h}', {cwd: curSrcPath}).forEach(file => { + const dir = path.dirname(file); + const targetDir = path.resolve(curTargetPath, dir); + const targetFile = path.resolve(curTargetPath, file); + + fs.mkdirSync(targetDir, {recursive: true}); + fs.writeFileSync( + targetFile, + fs.readFileSync(path.join(curSrcPath, file)), + ); + }); + }); +} + +function copyFile(srcPath, targetPath, filename) { + fs.writeFileSync( + path.resolve(targetPath, filename), + fs.readFileSync(path.resolve(srcPath, filename)), + ); +} + +exports.copyRNWin32Libraries = baseDir => { + + const rnInstallationPath = path.resolve(baseDir, './react-native-installation'); + + copyDirectories(baseDir, rnInstallationPath, [ + { + src: 'RNTester', + dest: 'RNTester', + mergeFiles: true, + ]); + + copyFile(baseDir, rnInstallationPath, 'RNTester.js'); + copyFile(baseDir, rnInstallationPath, 'RNTester.js.map'); +}; diff --git a/packages/react-native-win32/just-task.js b/packages/react-native-win32/just-task.js index e56e4b66486..cbd17e35c4a 100644 --- a/packages/react-native-win32/just-task.js +++ b/packages/react-native-win32/just-task.js @@ -52,7 +52,9 @@ task('copyPngFiles', () => { task('initRNLibraries', () => { require('../../vnext/scripts/copyRNLibraries').copyRNLibraries(__dirname); }); - +task('installRNW', () => { + require('../../vnext/Scripts/installRNW').installRNW(__dirname, path.resolve(__dirname, './react-native-installation')); +}); task('flow-check', () => { require('child_process').execSync('npx flow check', { stdio: 'inherit' }); }); @@ -94,10 +96,11 @@ task( 'build', series( condition('clean', () => argv().clean), - 'initRNLibraries', 'copyFlowFiles', 'copyPngFiles', 'ts', + 'installRNW', + 'initRNLibraries', condition('apiExtractorVerify', () => argv().ci), ), ); diff --git a/packages/react-native-win32/metro.config.js b/packages/react-native-win32/metro.config.js index 6b24f49cc0c..8763db2818e 100644 --- a/packages/react-native-win32/metro.config.js +++ b/packages/react-native-win32/metro.config.js @@ -10,7 +10,7 @@ const rnPath = fs.realpathSync( path.resolve(require.resolve('react-native/package.json'), '..'), ), ); -const rnw32Path = __dirname; +const rnInstallPath = path.resolve(__dirname, './react-native-installation'); module.exports = { // WatchFolders is only needed due to the yarn workspace layout of node_modules, we need to watch the symlinked locations separately @@ -21,9 +21,9 @@ module.exports = { resolver: { extraNodeModules: { - // Redirect react-native and react-native-windows to this folder - 'react-native': rnw32Path, - 'react-native-win32': rnw32Path, + // Redirect react-native to the installation path + 'react-native-windows': rnInstallPath, + 'react-native': rnInstallPath, }, // Include the macos platform in addition to the defaults because the fork includes macos, but doesn't declare it platforms: [ diff --git a/packages/react-native-win32/package.json b/packages/react-native-win32/package.json index 5e8ad7cfb8d..163424783e3 100644 --- a/packages/react-native-win32/package.json +++ b/packages/react-native-win32/package.json @@ -3,11 +3,11 @@ "version": "0.0.0-master.3", "description": "Implementation of react native on top of Office's Win32 platform.", "license": "MIT", - "main": "./Libraries/react-native/react-native-implementation.win32.js", - "typings": "./Libraries/react-native/typings-main.d.ts", + "main": "Libraries/react-native/react-native-implementation.win32.js", + "typings": "Libraries/react-native/typings-main.d.ts", "scripts": { "build": "just-scripts build", - "bundle": "just-scripts prepareBundle && react-native bundle --platform win32 --entry-file RNTester.js --bundle-output dist/win32/dev/RNTester.bundle --assets-dest dist/win32/dev --sourcemap-output ./dist/win32/dev/sourcemap.js", + "bundle": "just-scripts prepareBundle && react-native bundle --platform win32 --entry-file react-native-installation/RNTester.js --bundle-output dist/win32/dev/RNTester.bundle --assets-dest dist/win32/dev --sourcemap-output ./dist/win32/dev/sourcemap.js", "change": "beachball change", "clean": "just-scripts clean", "flow-check": "flow check", diff --git a/packages/react-native-win32/react-native.config.js b/packages/react-native-win32/react-native.config.js index 74538a4cf09..edef3553ae1 100644 --- a/packages/react-native-win32/react-native.config.js +++ b/packages/react-native-win32/react-native.config.js @@ -1,5 +1,6 @@ // @ts-check +const path = require('path'); module.exports = { platforms: { win32: { @@ -11,5 +12,5 @@ module.exports = { // ***** // This is only used when building bundles within react-native-win32. - reactNativePath: '.', + reactNativePath: path.resolve(__dirname, './react-native-installation'), }; diff --git a/vnext/Scripts/copyRNLibraries.js b/vnext/Scripts/copyRNLibraries.js index 31817ebfe69..2061e49ce77 100644 --- a/vnext/Scripts/copyRNLibraries.js +++ b/vnext/Scripts/copyRNLibraries.js @@ -83,7 +83,7 @@ exports.copyRNLibraries = baseDir => { require.resolve('react-native-windows/package.json'), ); - const rnInstallationPath = path.resolve(reactNativeWindowsPath, './react-native-installation'); + const rnInstallationPath = path.resolve(baseDir, './react-native-installation'); copyDirectories(reactNativeWindowsPath, rnInstallationPath, [ { diff --git a/vnext/Scripts/installRNW.js b/vnext/Scripts/installRNW.js index 04e2d4550a7..5351c7efd59 100644 --- a/vnext/Scripts/installRNW.js +++ b/vnext/Scripts/installRNW.js @@ -75,15 +75,11 @@ function copyFile(srcPath, targetPath, filename) { } -exports.installRNW = installationPath => { +exports.installRNW = (reactNativeWindowsPath, installationPath) => { const reactNativePath = path.dirname( require.resolve('react-native/package.json'), ); - const reactNativeWindowsPath = path.dirname( - require.resolve('react-native-windows/package.json'), - ); - if (!fs.existsSync(installationPath)) { fs.mkdirSync(installationPath); } diff --git a/vnext/Scripts/postinstall.js b/vnext/Scripts/postinstall.js index c5d4ed43e6f..9e86a5e0442 100644 --- a/vnext/Scripts/postinstall.js +++ b/vnext/Scripts/postinstall.js @@ -4,5 +4,6 @@ // @ts-check const path = require('path'); -const installationPath = path.resolve(require.resolve('react-native-windows/package.json'), '../../../react-native-installation'); +const reactNativeWindowsPath = require.resolve('react-native-windows/package.json'); +const installationPath = path.resolve(reactNativeWindowsPath, '../../../react-native-installation'); require('./installRNW').installRNW(installationPath); \ No newline at end of file From 087ffe1c106050e42e37a23f94ce863064ed686e Mon Sep 17 00:00:00 2001 From: Keith Melmon Date: Fri, 10 Apr 2020 23:22:18 -0700 Subject: [PATCH 05/12] fixup react-native-win32, take 2 --- packages/react-native-win32/Scripts/copyRNWin32Libraries.js | 1 + packages/react-native-win32/just-task.js | 4 ++++ vnext/Scripts/postinstall.js | 2 +- vnext/just-task.js | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/react-native-win32/Scripts/copyRNWin32Libraries.js b/packages/react-native-win32/Scripts/copyRNWin32Libraries.js index 31023ea97ac..8d5649730e8 100644 --- a/packages/react-native-win32/Scripts/copyRNWin32Libraries.js +++ b/packages/react-native-win32/Scripts/copyRNWin32Libraries.js @@ -83,6 +83,7 @@ exports.copyRNWin32Libraries = baseDir => { src: 'RNTester', dest: 'RNTester', mergeFiles: true, + }, ]); copyFile(baseDir, rnInstallationPath, 'RNTester.js'); diff --git a/packages/react-native-win32/just-task.js b/packages/react-native-win32/just-task.js index cbd17e35c4a..c93bbba8782 100644 --- a/packages/react-native-win32/just-task.js +++ b/packages/react-native-win32/just-task.js @@ -55,6 +55,9 @@ task('initRNLibraries', () => { task('installRNW', () => { require('../../vnext/Scripts/installRNW').installRNW(__dirname, path.resolve(__dirname, './react-native-installation')); }); +task('copyRNWin32Libraries', () => { + require('./Scripts/copyRNWin32Libraries').copyRNWin32Libraries(__dirname); +}); task('flow-check', () => { require('child_process').execSync('npx flow check', { stdio: 'inherit' }); }); @@ -101,6 +104,7 @@ task( 'ts', 'installRNW', 'initRNLibraries', + 'copyRNWin32Libraries', condition('apiExtractorVerify', () => argv().ci), ), ); diff --git a/vnext/Scripts/postinstall.js b/vnext/Scripts/postinstall.js index 9e86a5e0442..45559260e80 100644 --- a/vnext/Scripts/postinstall.js +++ b/vnext/Scripts/postinstall.js @@ -6,4 +6,4 @@ const path = require('path'); const reactNativeWindowsPath = require.resolve('react-native-windows/package.json'); const installationPath = path.resolve(reactNativeWindowsPath, '../../../react-native-installation'); -require('./installRNW').installRNW(installationPath); \ No newline at end of file +require('./installRNW').installRNW(reactNativeWindowsPath, installationPath); \ No newline at end of file diff --git a/vnext/just-task.js b/vnext/just-task.js index 49bd3b4b90d..f28e306d28c 100644 --- a/vnext/just-task.js +++ b/vnext/just-task.js @@ -54,7 +54,7 @@ task('initRNLibraries', () => { require('./Scripts/copyRNLibraries').copyRNLibraries(__dirname); }); task('installRNW', () => { - require('./Scripts/installRNW').installRNW(path.resolve(__dirname, './react-native-installation')); + require('./Scripts/installRNW').installRNW(__dirname, path.resolve(__dirname, './react-native-installation')); }); task('ts', () => { From 83dc7da4904922fdf91c429b622e0818c0ff945b Mon Sep 17 00:00:00 2001 From: Keith Melmon Date: Sat, 11 Apr 2020 14:23:33 -0700 Subject: [PATCH 06/12] fix integration tests --- vnext/IntegrationTests/TestRunner.cpp | 5 +- vnext/Scripts/copyRNLibraries.js | 5 + vnext/metro.config.js | 7 +- vnext/react-native.config.js | 3 +- .../RCTNetworkingWinShared.windesktop.js | 62 +++++++ .../Types/CoreEventTypes.windesktop.js | 151 ++++++++++++++++++ .../NativePlatformConstantsWin.windesktop.js | 28 ++++ 7 files changed, 255 insertions(+), 6 deletions(-) create mode 100644 vnext/src/Libraries/Network/RCTNetworkingWinShared.windesktop.js create mode 100644 vnext/src/Libraries/Types/CoreEventTypes.windesktop.js create mode 100644 vnext/src/Libraries/Utilities/NativePlatformConstantsWin.windesktop.js diff --git a/vnext/IntegrationTests/TestRunner.cpp b/vnext/IntegrationTests/TestRunner.cpp index 067cfa398ee..26037bd583a 100644 --- a/vnext/IntegrationTests/TestRunner.cpp +++ b/vnext/IntegrationTests/TestRunner.cpp @@ -80,8 +80,9 @@ TestResult TestRunner::RunTest(string &&bundlePath, string &&appName, NativeLogg // React instance scope { - shared_ptr instance = - GetInstance(std::move(bundlePath), std::move(modules), std::move(devSettings)); + string realBundlePath = "react-native-installation/" + bundlePath; + shared_ptr instance = + GetInstance(std::move(realBundlePath), std::move(modules), std::move(devSettings)); InitializeLogging([&result, &functionCalled](RCTLogLevel logLevel, const char *message) { if (TestStatus::Pending != result.Status) diff --git a/vnext/Scripts/copyRNLibraries.js b/vnext/Scripts/copyRNLibraries.js index 2061e49ce77..6281a736743 100644 --- a/vnext/Scripts/copyRNLibraries.js +++ b/vnext/Scripts/copyRNLibraries.js @@ -103,6 +103,11 @@ exports.copyRNLibraries = baseDir => { dest: 'RNTester', mergeFiles: true, }, + { + src: 'IntegrationTests', + dest: 'IntegrationTests', + mergeFiles: true, + }, ]); /* diff --git a/vnext/metro.config.js b/vnext/metro.config.js index fc58dcd5d72..237011a4fb4 100644 --- a/vnext/metro.config.js +++ b/vnext/metro.config.js @@ -11,6 +11,7 @@ const rnPath = fs.realpathSync( ), ); const rnwPath = __dirname; +const rnInstallPath = path.resolve(__dirname, './react-native-installation'); module.exports = { // WatchFolders is only needed due to the yarn workspace layout of node_modules, we need to watch the symlinked locations separately @@ -21,9 +22,9 @@ module.exports = { resolver: { extraNodeModules: { - // Redirect react-native and react-native-windows to this folder - 'react-native': rnwPath, - 'react-native-windows': rnwPath, + // Redirect react-native and react-native-windows to the installation folder + 'react-native-windows': rnInstallPath, + 'react-native': rnInstallPath, }, // 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'], diff --git a/vnext/react-native.config.js b/vnext/react-native.config.js index 1e6961a0d12..2d2d111a65a 100644 --- a/vnext/react-native.config.js +++ b/vnext/react-native.config.js @@ -1,4 +1,5 @@ // @ts-check +const path = require('path'); const projectConfig = require('./local-cli/config/projectConfig'); const dependencyConfig = require('./local-cli/config/dependencyConfig'); @@ -17,5 +18,5 @@ module.exports = { // ***** // This is only used when building bundles within react-native-windows. - reactNativePath: '.', + reactNativePath: path.resolve(__dirname, './react-native-installation'), }; diff --git a/vnext/src/Libraries/Network/RCTNetworkingWinShared.windesktop.js b/vnext/src/Libraries/Network/RCTNetworkingWinShared.windesktop.js new file mode 100644 index 00000000000..f63e8a1c74c --- /dev/null +++ b/vnext/src/Libraries/Network/RCTNetworkingWinShared.windesktop.js @@ -0,0 +1,62 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + * + * @format + * @flow + */ + +'use strict'; + +const NativeEventEmitter = require('../EventEmitter/NativeEventEmitter'); +const RCTNetworkingNative = require('../BatchedBridge/NativeModules') + .Networking; +const convertRequestBody = require('./convertRequestBody'); + +import type {RequestBody} from './convertRequestBody'; + +import type {NativeResponseType} from './XMLHttpRequest'; + +class RCTNetworking extends NativeEventEmitter { + constructor() { + super(RCTNetworkingNative); + } + + sendRequest( + method: string, + trackingName: string, + url: string, + headers: Object, + data: RequestBody, + responseType: NativeResponseType, + incrementalUpdates: boolean, + timeout: number, + callback: (requestId: number) => any, + withCredentials: boolean, + ) { + const body = convertRequestBody(data); + RCTNetworkingNative.sendRequest( + { + method, + url, + data: {...body, trackingName}, + headers, + responseType, + incrementalUpdates, + timeout, + withCredentials, + }, + callback, + ); + } + + abortRequest(requestId: number) { + RCTNetworkingNative.abortRequest(requestId); + } + + clearCookies(callback: (result: boolean) => any) { + RCTNetworkingNative.clearCookies(callback); + } +} + +module.exports = new RCTNetworking(); diff --git a/vnext/src/Libraries/Types/CoreEventTypes.windesktop.js b/vnext/src/Libraries/Types/CoreEventTypes.windesktop.js new file mode 100644 index 00000000000..8d8489b8ad8 --- /dev/null +++ b/vnext/src/Libraries/Types/CoreEventTypes.windesktop.js @@ -0,0 +1,151 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict + * @format + */ + +'use strict'; + +export type SyntheticEvent = $ReadOnly<{| + bubbles: ?boolean, + cancelable: ?boolean, + currentTarget: number, + defaultPrevented: ?boolean, + dispatchConfig: $ReadOnly<{| + registrationName: string, + |}>, + eventPhase: ?number, + preventDefault: () => void, + isDefaultPrevented: () => boolean, + stopPropagation: () => void, + isPropagationStopped: () => boolean, + isTrusted: ?boolean, + nativeEvent: T, + persist: () => void, + target: ?number, + timeStamp: number, + type: ?string, +|}>; + +export type ResponderSyntheticEvent = $ReadOnly<{| + ...SyntheticEvent, + touchHistory: $ReadOnly<{| + indexOfSingleActiveTouch: number, + mostRecentTimeStamp: number, + numberActiveTouches: number, + touchBank: $ReadOnlyArray< + $ReadOnly<{| + touchActive: boolean, + startPageX: number, + startPageY: number, + startTimeStamp: number, + currentPageX: number, + currentPageY: number, + currentTimeStamp: number, + previousPageX: number, + previousPageY: number, + previousTimeStamp: number, + |}>, + >, + |}>, +|}>; + +export type Layout = $ReadOnly<{| + x: number, + y: number, + width: number, + height: number, +|}>; + +export type TextLayout = $ReadOnly<{| + ...Layout, + ascender: number, + capHeight: number, + descender: number, + text: string, + xHeight: number, +|}>; + +export type LayoutEvent = SyntheticEvent< + $ReadOnly<{| + layout: Layout, + |}>, +>; + +export type TextLayoutEvent = SyntheticEvent< + $ReadOnly<{| + lines: Array, + |}>, +>; + +export type PressEvent = ResponderSyntheticEvent< + $ReadOnly<{| + altKey: ?boolean, // TODO(macOS) + button: ?number, // TODO(macOS) + changedTouches: $ReadOnlyArray<$PropertyType>, + ctrlKey: ?boolean, // TODO(macOS) + force: number, + identifier: number, + locationX: number, + locationY: number, + metaKey: ?boolean, // TODO(macOS) + pageX: number, + pageY: number, + shiftKey: ?boolean, // TODO(macOS) + target: ?number, + timestamp: number, + touches: $ReadOnlyArray<$PropertyType>, + |}>, +>; + +export type ScrollEvent = SyntheticEvent< + $ReadOnly<{| + contentInset: $ReadOnly<{| + bottom: number, + left: number, + right: number, + top: number, + |}>, + contentOffset: $ReadOnly<{| + y: number, + x: number, + |}>, + contentSize: $ReadOnly<{| + height: number, + width: number, + |}>, + layoutMeasurement: $ReadOnly<{| + height: number, + width: number, + |}>, + targetContentOffset?: $ReadOnly<{| + y: number, + x: number, + |}>, + velocity?: $ReadOnly<{| + y: number, + x: number, + |}>, + zoomScale?: number, + responderIgnoreScroll?: boolean, + key?: string, // TODO(macOS) + |}>, +>; + +// [Windows +export type KeyEvent = SyntheticEvent< + $ReadOnly<{| + altKey: boolean, + ctrlKey: boolean, + metaKey: boolean, + shiftKey: boolean, + key: string, + code: string, + eventPhase: number, + |}>, +>; +// Windows] diff --git a/vnext/src/Libraries/Utilities/NativePlatformConstantsWin.windesktop.js b/vnext/src/Libraries/Utilities/NativePlatformConstantsWin.windesktop.js new file mode 100644 index 00000000000..523a4f10f02 --- /dev/null +++ b/vnext/src/Libraries/Utilities/NativePlatformConstantsWin.windesktop.js @@ -0,0 +1,28 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + * + * @format + * @flow + */ + +'use strict'; + +import type {TurboModule} from '../TurboModule/RCTExport'; +import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry'; + +export interface Spec extends TurboModule { + +getConstants: () => {| + isTesting: boolean, + reactNativeVersion: {| + major: number, + minor: number, + patch: number, + prerelease: ?number, + |}, + |}; +} + +export default (TurboModuleRegistry.getEnforcing( + 'PlatformConstants', +): Spec); From 3d18fed800a46f393ae6654202bd1e2ee4fc5bf8 Mon Sep 17 00:00:00 2001 From: Keith Melmon Date: Sat, 11 Apr 2020 14:57:30 -0700 Subject: [PATCH 07/12] Change files --- ...-react-native-win32-2020-04-11-14-57-30-metro-fix.json | 8 ++++++++ ...eact-native-windows-2020-04-11-14-57-30-metro-fix.json | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 change/@office-iss-react-native-win32-2020-04-11-14-57-30-metro-fix.json create mode 100644 change/react-native-windows-2020-04-11-14-57-30-metro-fix.json diff --git a/change/@office-iss-react-native-win32-2020-04-11-14-57-30-metro-fix.json b/change/@office-iss-react-native-win32-2020-04-11-14-57-30-metro-fix.json new file mode 100644 index 00000000000..b0ee5b3106d --- /dev/null +++ b/change/@office-iss-react-native-win32-2020-04-11-14-57-30-metro-fix.json @@ -0,0 +1,8 @@ +{ + "type": "prerelease", + "comment": "refactor react-native-windows installation for better metro support", + "packageName": "@office-iss/react-native-win32", + "email": "kmelmon@microsoft.com", + "dependentChangeType": "patch", + "date": "2020-04-11T21:57:04.043Z" +} \ No newline at end of file diff --git a/change/react-native-windows-2020-04-11-14-57-30-metro-fix.json b/change/react-native-windows-2020-04-11-14-57-30-metro-fix.json new file mode 100644 index 00000000000..7998e193193 --- /dev/null +++ b/change/react-native-windows-2020-04-11-14-57-30-metro-fix.json @@ -0,0 +1,8 @@ +{ + "type": "prerelease", + "comment": "refactor react-native-windows installation for better metro support", + "packageName": "react-native-windows", + "email": "kmelmon@microsoft.com", + "dependentChangeType": "patch", + "date": "2020-04-11T21:57:30.042Z" +} \ No newline at end of file From a51b23347587bdb8543a45a5597683f11712b823 Mon Sep 17 00:00:00 2001 From: Keith Melmon Date: Sat, 11 Apr 2020 15:11:37 -0700 Subject: [PATCH 08/12] fixup more references --- .ado/windows-vs-pr.yml | 2 +- vnext/IntegrationTests/TestRunner.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.ado/windows-vs-pr.yml b/.ado/windows-vs-pr.yml index b425c0dffbd..78c9e91f926 100644 --- a/.ado/windows-vs-pr.yml +++ b/.ado/windows-vs-pr.yml @@ -403,7 +403,7 @@ jobs: displayName: Check the metro bundle server inputs: targetType: 'inline' - script: Invoke-WebRequest -Uri "http://localhost:8081/IntegrationTests/IntegrationTestsApp.bundle?platform=windesktop&dev=true" + script: Invoke-WebRequest -Uri "http://localhost:8081/react-native-installation/IntegrationTests/IntegrationTestsApp.bundle?platform=windesktop&dev=true" condition: failed() - template: templates/stop-packagers.yml diff --git a/vnext/IntegrationTests/TestRunner.cpp b/vnext/IntegrationTests/TestRunner.cpp index 26037bd583a..4dcb9f820cb 100644 --- a/vnext/IntegrationTests/TestRunner.cpp +++ b/vnext/IntegrationTests/TestRunner.cpp @@ -81,7 +81,7 @@ TestResult TestRunner::RunTest(string &&bundlePath, string &&appName, NativeLogg // React instance scope { string realBundlePath = "react-native-installation/" + bundlePath; - shared_ptr instance = + shared_ptr instance = GetInstance(std::move(realBundlePath), std::move(modules), std::move(devSettings)); InitializeLogging([&result, &functionCalled](RCTLogLevel logLevel, const char *message) { From 283746d1909f5d9629f622ea01133215b5f0bb31 Mon Sep 17 00:00:00 2001 From: Keith Melmon Date: Sat, 11 Apr 2020 15:22:25 -0700 Subject: [PATCH 09/12] fixup another path --- vnext/api-extractor.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vnext/api-extractor.json b/vnext/api-extractor.json index c1cf1a85d14..135cdccd952 100644 --- a/vnext/api-extractor.json +++ b/vnext/api-extractor.json @@ -1,6 +1,6 @@ { "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", - "mainEntryPointFilePath": "./Libraries/react-native/typings-index.d.ts", + "mainEntryPointFilePath": "./Libraries/react-native-windows/typings-index.d.ts", "docModel": { "enabled": true }, From 50a2675912255cc15bfb5573e8a147982eabeff8 Mon Sep 17 00:00:00 2001 From: Keith Melmon Date: Sat, 11 Apr 2020 16:05:34 -0700 Subject: [PATCH 10/12] more fixes for integration tests --- vnext/Desktop.IntegrationTests/WebSocketIntegrationTest.cpp | 2 +- .../WebSocketJSExecutorIntegrationTest.cpp | 2 +- vnext/Scripts/IntegrationTests.ps1 | 2 +- vnext/Scripts/Tfs/Start-TestServers.ps1 | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vnext/Desktop.IntegrationTests/WebSocketIntegrationTest.cpp b/vnext/Desktop.IntegrationTests/WebSocketIntegrationTest.cpp index 5c342d1b111..2b4b736880a 100644 --- a/vnext/Desktop.IntegrationTests/WebSocketIntegrationTest.cpp +++ b/vnext/Desktop.IntegrationTests/WebSocketIntegrationTest.cpp @@ -181,7 +181,7 @@ TEST_CLASS (WebSocketIntegrationTest) // string url = "ws://localhost:5555/"; auto ws = IWebSocketResource::Make(url); string json = - "{\"inject\":{},\"id\":1,\"method\":\"executeApplicationScript\",\"url\":\"http://localhost:8081/IntegrationTests/IntegrationTestsApp.bundle?platform=ios&dev=true\"}"; + "{\"inject\":{},\"id\":1,\"method\":\"executeApplicationScript\",\"url\":\"http://localhost:8081/react-native-installation/IntegrationTests/IntegrationTestsApp.bundle?platform=ios&dev=true\"}"; // string json = "{}"; std::mutex mutex; condition_variable condition; diff --git a/vnext/Desktop.IntegrationTests/WebSocketJSExecutorIntegrationTest.cpp b/vnext/Desktop.IntegrationTests/WebSocketJSExecutorIntegrationTest.cpp index 3f17ddbd59d..27590d03c33 100644 --- a/vnext/Desktop.IntegrationTests/WebSocketJSExecutorIntegrationTest.cpp +++ b/vnext/Desktop.IntegrationTests/WebSocketJSExecutorIntegrationTest.cpp @@ -65,7 +65,7 @@ TEST_CLASS (WebSocketJSExecutorIntegrationTest) { // Point to an existing script accessible via the repository's packaging // service. auto bigString = unique_ptr( - new JSBigStdString("http://localhost:8081/IntegrationTests/IntegrationTestsApp.bundle?platform=ios&dev=true")); + new JSBigStdString("http://localhost:8081/react-native-installation/IntegrationTests/IntegrationTestsApp.bundle?platform=ios&dev=true")); jse->loadApplicationScript(std::move(bigString), ""); jsQueue->quitSynchronous(); diff --git a/vnext/Scripts/IntegrationTests.ps1 b/vnext/Scripts/IntegrationTests.ps1 index d530a63acd7..396a8c16ca1 100644 --- a/vnext/Scripts/IntegrationTests.ps1 +++ b/vnext/Scripts/IntegrationTests.ps1 @@ -80,7 +80,7 @@ if (! $NoServers) { Start-Sleep -Seconds $Delay # Preload the RNTesterApp integration bundle for better performance in integration tests. - Invoke-WebRequest -Uri "http://localhost:8081/IntegrationTests/IntegrationTestsApp.bundle?platform=windesktop&dev=true" | Out-Null + Invoke-WebRequest -Uri "http://localhost:8081/react-native-installation/IntegrationTests/IntegrationTestsApp.bundle?platform=windesktop&dev=true" | Out-Null } } diff --git a/vnext/Scripts/Tfs/Start-TestServers.ps1 b/vnext/Scripts/Tfs/Start-TestServers.ps1 index 52a8deb86f4..73b6ef4bc39 100644 --- a/vnext/Scripts/Tfs/Start-TestServers.ps1 +++ b/vnext/Scripts/Tfs/Start-TestServers.ps1 @@ -39,7 +39,7 @@ if ($Preload) { Start-Sleep -Seconds $SleepSeconds # Preload the RNTesterApp integration bundle for better performance in integration tests. - Invoke-WebRequest -Uri "http://localhost:8081/IntegrationTests/IntegrationTestsApp.bundle?platform=windesktop&dev=true" | Out-Null + Invoke-WebRequest -Uri "http://localhost:8081/react-native-installation/IntegrationTests/IntegrationTestsApp.bundle?platform=windesktop&dev=true" | Out-Null Write-Host 'Done preloading bundles.' } From 88c07eef8dd178e4e1076251499e77cc388ebe49 Mon Sep 17 00:00:00 2001 From: Keith Melmon Date: Sat, 11 Apr 2020 16:49:24 -0700 Subject: [PATCH 11/12] fix bug in postinstall, clang format cleanup --- .../WebSocketJSExecutorIntegrationTest.cpp | 4 ++-- vnext/Scripts/postinstall.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vnext/Desktop.IntegrationTests/WebSocketJSExecutorIntegrationTest.cpp b/vnext/Desktop.IntegrationTests/WebSocketJSExecutorIntegrationTest.cpp index 27590d03c33..25a2b5c9cf1 100644 --- a/vnext/Desktop.IntegrationTests/WebSocketJSExecutorIntegrationTest.cpp +++ b/vnext/Desktop.IntegrationTests/WebSocketJSExecutorIntegrationTest.cpp @@ -64,8 +64,8 @@ TEST_CLASS (WebSocketJSExecutorIntegrationTest) { bool connected = jse->ConnectAsync("ws://localhost:8081/debugger-proxy?role=client", move(errorCallback)).get(); // Point to an existing script accessible via the repository's packaging // service. - auto bigString = unique_ptr( - new JSBigStdString("http://localhost:8081/react-native-installation/IntegrationTests/IntegrationTestsApp.bundle?platform=ios&dev=true")); + auto bigString = unique_ptr(new JSBigStdString( + "http://localhost:8081/react-native-installation/IntegrationTests/IntegrationTestsApp.bundle?platform=ios&dev=true")); jse->loadApplicationScript(std::move(bigString), ""); jsQueue->quitSynchronous(); diff --git a/vnext/Scripts/postinstall.js b/vnext/Scripts/postinstall.js index 45559260e80..8833060bbca 100644 --- a/vnext/Scripts/postinstall.js +++ b/vnext/Scripts/postinstall.js @@ -4,6 +4,6 @@ // @ts-check const path = require('path'); -const reactNativeWindowsPath = require.resolve('react-native-windows/package.json'); -const installationPath = path.resolve(reactNativeWindowsPath, '../../../react-native-installation'); +const reactNativeWindowsPath = path.resolve(require.resolve('react-native-windows/package.json'), '..'); +const installationPath = path.resolve(reactNativeWindowsPath, '../../react-native-installation'); require('./installRNW').installRNW(reactNativeWindowsPath, installationPath); \ No newline at end of file From 0891ee9b9cc9a4b49122cd3057ea83d20b05f838 Mon Sep 17 00:00:00 2001 From: Keith Melmon Date: Sat, 11 Apr 2020 17:05:35 -0700 Subject: [PATCH 12/12] fix lint errors --- vnext/.eslintignore | 3 ++- vnext/Scripts/copyRNLibraries.js | 8 +++++--- vnext/Scripts/installRNW.js | 3 +-- vnext/Scripts/postinstall.js | 12 +++++++++--- vnext/just-task.js | 5 ++++- .../generator-windows/templates/metro.config.js | 6 ++++-- 6 files changed, 25 insertions(+), 12 deletions(-) diff --git a/vnext/.eslintignore b/vnext/.eslintignore index e8f78012d7b..29e3b7f73d0 100644 --- a/vnext/.eslintignore +++ b/vnext/.eslintignore @@ -8,4 +8,5 @@ /RNTester /index.* /RNTester.* -/jest \ No newline at end of file +/jest +/react-native-installation \ No newline at end of file diff --git a/vnext/Scripts/copyRNLibraries.js b/vnext/Scripts/copyRNLibraries.js index 6281a736743..5e76b3d714e 100644 --- a/vnext/Scripts/copyRNLibraries.js +++ b/vnext/Scripts/copyRNLibraries.js @@ -83,7 +83,10 @@ exports.copyRNLibraries = baseDir => { require.resolve('react-native-windows/package.json'), ); - const rnInstallationPath = path.resolve(baseDir, './react-native-installation'); + const rnInstallationPath = path.resolve( + baseDir, + './react-native-installation', + ); copyDirectories(reactNativeWindowsPath, rnInstallationPath, [ { @@ -110,7 +113,7 @@ exports.copyRNLibraries = baseDir => { }, ]); -/* + /* // TODO: figure out what to do with these copyDirectories(reactNativePath, baseDir, [ { @@ -143,5 +146,4 @@ exports.copyRNLibraries = baseDir => { mergeFiles: true, }, ]); - }; diff --git a/vnext/Scripts/installRNW.js b/vnext/Scripts/installRNW.js index 5351c7efd59..d7a1636a7ed 100644 --- a/vnext/Scripts/installRNW.js +++ b/vnext/Scripts/installRNW.js @@ -74,7 +74,6 @@ function copyFile(srcPath, targetPath, filename) { ); } - exports.installRNW = (reactNativeWindowsPath, installationPath) => { const reactNativePath = path.dirname( require.resolve('react-native/package.json'), @@ -109,4 +108,4 @@ exports.installRNW = (reactNativeWindowsPath, installationPath) => { mergeFiles: true, }, ]); -}; \ No newline at end of file +}; diff --git a/vnext/Scripts/postinstall.js b/vnext/Scripts/postinstall.js index 8833060bbca..17992b13e07 100644 --- a/vnext/Scripts/postinstall.js +++ b/vnext/Scripts/postinstall.js @@ -4,6 +4,12 @@ // @ts-check const path = require('path'); -const reactNativeWindowsPath = path.resolve(require.resolve('react-native-windows/package.json'), '..'); -const installationPath = path.resolve(reactNativeWindowsPath, '../../react-native-installation'); -require('./installRNW').installRNW(reactNativeWindowsPath, installationPath); \ No newline at end of file +const reactNativeWindowsPath = path.resolve( + require.resolve('react-native-windows/package.json'), + '..', +); +const installationPath = path.resolve( + reactNativeWindowsPath, + '../../react-native-installation', +); +require('./installRNW').installRNW(reactNativeWindowsPath, installationPath); diff --git a/vnext/just-task.js b/vnext/just-task.js index f28e306d28c..4b8df31a884 100644 --- a/vnext/just-task.js +++ b/vnext/just-task.js @@ -54,7 +54,10 @@ task('initRNLibraries', () => { require('./Scripts/copyRNLibraries').copyRNLibraries(__dirname); }); task('installRNW', () => { - require('./Scripts/installRNW').installRNW(__dirname, path.resolve(__dirname, './react-native-installation')); + require('./Scripts/installRNW').installRNW( + __dirname, + path.resolve(__dirname, './react-native-installation'), + ); }); task('ts', () => { diff --git a/vnext/local-cli/generator-windows/templates/metro.config.js b/vnext/local-cli/generator-windows/templates/metro.config.js index 15d7ed6dc7b..333b0c8d794 100644 --- a/vnext/local-cli/generator-windows/templates/metro.config.js +++ b/vnext/local-cli/generator-windows/templates/metro.config.js @@ -15,7 +15,9 @@ const rnwPath = fs.realpathSync( path.resolve(require.resolve('react-native-windows/package.json'), '..'), ); -const rnInstallPath = fs.realpathSync(path.resolve(rnwPath, '../../../react-native-installation')); +const rnInstallPath = fs.realpathSync( + path.resolve(rnwPath, '../../../react-native-installation'), +); module.exports = { resolver: { @@ -37,7 +39,7 @@ module.exports = { ), ]), }, - transformer: { + transformer: { getTransformOptions: async () => ({ transform: { experimentalImportSupport: false,