mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
RN: Flowify packages/react-native-scripts (#51671)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51671 Adds `flow` (or `noflow`) to all files in this directory and ensures that Flow succeeds (by adding type annotations, using minor refactors, or suppressing errors due to intentionally dynamic logic). This will help improve type safety when making changes both in these files as well as files that these depend on. Changelog: [Internal] Reviewed By: SamChou19815 Differential Revision: D75581879 fbshipit-source-id: 6dcd8cc55d0021973eeae2670c1ebceb6d69fa8f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1fd9508ecc
commit
e7a9322bdf
+10
-1
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -16,6 +17,7 @@ const {readFileSync} = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// Commander 12.0.0 changes from the global to named export
|
||||
// $FlowFixMe[signature-verification-failure]
|
||||
const program = commander.program ?? commander;
|
||||
|
||||
program.version(
|
||||
@@ -37,7 +39,14 @@ program
|
||||
.allowUnknownOption()
|
||||
.action(async function handleAction() {
|
||||
let config = null;
|
||||
let options = program.opts();
|
||||
let options = program
|
||||
.opts /*::<{
|
||||
configCmd?: string,
|
||||
loadConfig?: string,
|
||||
verbose: boolean,
|
||||
...
|
||||
}>*/
|
||||
();
|
||||
if (options.loadConfig != null) {
|
||||
config = JSON.parse(
|
||||
options.loadConfig.replace(/^\W*'/, '').replace(/'\W*$/, ''),
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -120,6 +121,7 @@ const SCHEMA_TEXT = `
|
||||
}
|
||||
`;
|
||||
|
||||
// $FlowFixMe[signature-verification-failure]
|
||||
const SCHEMA = JSON.parse(SCHEMA_TEXT);
|
||||
|
||||
module.exports = {
|
||||
|
||||
+5
-4
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -243,7 +244,7 @@ describe('delete empty files and folders', () => {
|
||||
|
||||
it("when path is folder and it's empty, removes it", () => {
|
||||
const targetFolder = 'build';
|
||||
const content = [];
|
||||
const content = [] as Array<string>;
|
||||
|
||||
let statSyncInvocationCount = 0;
|
||||
let readdirInvocationCount = 0;
|
||||
@@ -290,8 +291,8 @@ describe('delete empty files and folders', () => {
|
||||
path.normalize('build/notEmptyFile'),
|
||||
];
|
||||
|
||||
const emptyContent = [];
|
||||
let fileSizes = {};
|
||||
const emptyContent = [] as Array<string>;
|
||||
let fileSizes = {} as {[string]: number};
|
||||
fileSizes[path.normalize('build/emptyFile')] = 0;
|
||||
fileSizes[path.normalize('build/notEmptyFile')] = 32;
|
||||
|
||||
@@ -344,7 +345,7 @@ describe('delete empty files and folders', () => {
|
||||
it('when path is folder and it contains only empty folders, removes everything', () => {
|
||||
const targetFolder = 'build';
|
||||
const content = ['emptyFolder1', 'emptyFolder2'];
|
||||
const emptyContent = [];
|
||||
const emptyContent = [] as Array<string>;
|
||||
|
||||
let statSyncInvocation = [];
|
||||
let rmSyncInvocation = [];
|
||||
|
||||
+1
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
|
||||
+9
-4
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -19,11 +20,13 @@
|
||||
*
|
||||
* @return an object that can generate the code for the New Architecture.
|
||||
*/
|
||||
function getCodegen() {
|
||||
function getCodegen() /*: $FlowFixMe */ {
|
||||
let RNCodegen;
|
||||
try {
|
||||
// $FlowIgnore[cannot-resolve-module]
|
||||
RNCodegen = require('../../packages/react-native-codegen/lib/generators/RNCodegen.js');
|
||||
} catch (e) {
|
||||
// $FlowIgnore[cannot-resolve-module]
|
||||
RNCodegen = require('@react-native/codegen/lib/generators/RNCodegen.js');
|
||||
}
|
||||
if (!RNCodegen) {
|
||||
@@ -32,11 +35,13 @@ function getCodegen() {
|
||||
return RNCodegen;
|
||||
}
|
||||
|
||||
function getCombineJSToSchema() {
|
||||
function getCombineJSToSchema() /*: $FlowFixMe */ {
|
||||
let combineJSToSchema;
|
||||
try {
|
||||
// $FlowIgnore[cannot-resolve-module]
|
||||
combineJSToSchema = require('../../packages/react-native-codegen/lib/cli/combine/combine-js-to-schema.js');
|
||||
} catch (e) {
|
||||
// $FlowIgnore[cannot-resolve-module]
|
||||
combineJSToSchema = require('@react-native/codegen/lib/cli/combine/combine-js-to-schema.js');
|
||||
}
|
||||
if (!combineJSToSchema) {
|
||||
@@ -46,6 +51,6 @@ function getCombineJSToSchema() {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getCodegen: getCodegen,
|
||||
getCombineJSToSchema: getCombineJSToSchema,
|
||||
getCodegen,
|
||||
getCombineJSToSchema,
|
||||
};
|
||||
|
||||
+36
-26
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -21,11 +22,19 @@ const REACT_NATIVE_REPOSITORY_ROOT = path.join(
|
||||
'..',
|
||||
);
|
||||
|
||||
const REACT_NATIVE_PACKAGE_ROOT_FOLDER = path.join(__dirname, '..', '..', '..');
|
||||
const REACT_NATIVE_PACKAGE_ROOT_FOLDER = path.join(
|
||||
__dirname,
|
||||
'..',
|
||||
'..',
|
||||
'..',
|
||||
) /*:: as string */;
|
||||
const CODEGEN_REPO_PATH = `${REACT_NATIVE_REPOSITORY_ROOT}/packages/react-native-codegen`;
|
||||
|
||||
const RNCORE_CONFIGS = {
|
||||
ios: path.join(REACT_NATIVE_PACKAGE_ROOT_FOLDER, 'ReactCommon'),
|
||||
ios: path.join(
|
||||
REACT_NATIVE_PACKAGE_ROOT_FOLDER,
|
||||
'ReactCommon',
|
||||
) /*:: as string */,
|
||||
android: path.join(
|
||||
REACT_NATIVE_PACKAGE_ROOT_FOLDER,
|
||||
'ReactAndroid',
|
||||
@@ -33,42 +42,43 @@ const RNCORE_CONFIGS = {
|
||||
'generated',
|
||||
'source',
|
||||
'codegen',
|
||||
),
|
||||
) /*:: as string */,
|
||||
};
|
||||
|
||||
const CORE_LIBRARIES_WITH_OUTPUT_FOLDER = {
|
||||
rncore: RNCORE_CONFIGS,
|
||||
FBReactNativeSpec: {
|
||||
ios: path.join(
|
||||
REACT_NATIVE_PACKAGE_ROOT_FOLDER,
|
||||
'React',
|
||||
'FBReactNativeSpec',
|
||||
),
|
||||
android: path.join(
|
||||
REACT_NATIVE_PACKAGE_ROOT_FOLDER,
|
||||
'ReactAndroid',
|
||||
'build',
|
||||
'generated',
|
||||
'source',
|
||||
'codegen',
|
||||
),
|
||||
},
|
||||
};
|
||||
rncore: RNCORE_CONFIGS,
|
||||
FBReactNativeSpec: {
|
||||
ios: path.join(
|
||||
REACT_NATIVE_PACKAGE_ROOT_FOLDER,
|
||||
'React',
|
||||
'FBReactNativeSpec',
|
||||
) /*:: as string */,
|
||||
android: path.join(
|
||||
REACT_NATIVE_PACKAGE_ROOT_FOLDER,
|
||||
'ReactAndroid',
|
||||
'build',
|
||||
'generated',
|
||||
'source',
|
||||
'codegen',
|
||||
) /*:: as string */,
|
||||
},
|
||||
} /*:: as {[string]: $FlowFixMe} */;
|
||||
|
||||
const packageJsonPath = path.join(
|
||||
REACT_NATIVE_PACKAGE_ROOT_FOLDER,
|
||||
'package.json',
|
||||
);
|
||||
|
||||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath));
|
||||
// $FlowFixMe[signature-verification-failure]
|
||||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||
const REACT_NATIVE = packageJson.name;
|
||||
|
||||
const TEMPLATES_FOLDER_PATH = path.join(
|
||||
REACT_NATIVE_PACKAGE_ROOT_FOLDER,
|
||||
'scripts',
|
||||
'codegen',
|
||||
'templates',
|
||||
);
|
||||
REACT_NATIVE_PACKAGE_ROOT_FOLDER,
|
||||
'scripts',
|
||||
'codegen',
|
||||
'templates',
|
||||
) /*:: as string */;
|
||||
|
||||
module.exports = {
|
||||
CODEGEN_REPO_PATH,
|
||||
|
||||
Vendored
+2
-1
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -28,7 +29,7 @@ const APP_DEPENDENCY_PROVIDER_PODSPEC_TEMPLATE_PATH = path.join(
|
||||
'ReactAppDependencyProvider.podspec.template',
|
||||
);
|
||||
|
||||
function generateAppDependencyProvider(outputDir) {
|
||||
function generateAppDependencyProvider(outputDir /*: string */) {
|
||||
fs.mkdirSync(outputDir, {recursive: true});
|
||||
codegenLog('Generating RCTAppDependencyProvider');
|
||||
|
||||
|
||||
Vendored
+9
-4
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -23,13 +24,17 @@ const MODULES_PROTOCOLS_MM_TEMPLATE_PATH = path.join(
|
||||
'RCTModulesConformingToProtocolsProviderMM.template',
|
||||
);
|
||||
|
||||
function generateCustomURLHandlers(libraries, outputDir) {
|
||||
function generateCustomURLHandlers(
|
||||
libraries /*: $ReadOnlyArray<$FlowFixMe> */,
|
||||
outputDir /*: string */,
|
||||
) {
|
||||
const iosAnnotations = parseiOSAnnotations(libraries);
|
||||
|
||||
const imageURLLoaderModules = new Set();
|
||||
const imageDataDecoderModules = new Set();
|
||||
const urlRequestHandlersModules = new Set();
|
||||
const imageURLLoaderModules = new Set /*::<string>*/();
|
||||
const imageDataDecoderModules = new Set /*::<string>*/();
|
||||
const urlRequestHandlersModules = new Set /*::<string>*/();
|
||||
|
||||
// $FlowFixMe[missing-local-annot]]
|
||||
const wrapInArrayIfNecessary = value =>
|
||||
Array.isArray(value) || value == null ? value : [value];
|
||||
// Old API
|
||||
|
||||
Vendored
+1
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
|
||||
+25
-9
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -17,17 +18,22 @@ const os = require('os');
|
||||
const path = require('path');
|
||||
|
||||
function generateNativeCode(
|
||||
outputPath,
|
||||
schemaInfos,
|
||||
includesGeneratedCode,
|
||||
platform,
|
||||
) {
|
||||
outputPath /*: string */,
|
||||
schemaInfos /*: $ReadOnlyArray<$FlowFixMe> */,
|
||||
includesGeneratedCode /*: boolean */,
|
||||
platform /*: string */,
|
||||
) /*: Array<void> */ {
|
||||
return schemaInfos.map(schemaInfo => {
|
||||
generateCode(outputPath, schemaInfo, includesGeneratedCode, platform);
|
||||
});
|
||||
}
|
||||
|
||||
function generateCode(outputPath, schemaInfo, includesGeneratedCode, platform) {
|
||||
function generateCode(
|
||||
outputPath /*: string */,
|
||||
schemaInfo /*: $FlowFixMe */,
|
||||
includesGeneratedCode /*: boolean */,
|
||||
platform /*: string */,
|
||||
) {
|
||||
if (shouldSkipGenerationForRncore(schemaInfo, platform)) {
|
||||
codegenLog(
|
||||
'[Codegen - rncore] Skipping iOS code generation for rncore as it has been generated already.',
|
||||
@@ -65,11 +71,15 @@ function generateCode(outputPath, schemaInfo, includesGeneratedCode, platform) {
|
||||
const outputDir =
|
||||
reactNativeCoreLibraryOutputPath(libraryName, platform) ?? outputPath;
|
||||
fs.mkdirSync(outputDir, {recursive: true});
|
||||
// $FlowIssue[prop-missing] - `fs.cpSync` is missing in Flow libdefs.
|
||||
fs.cpSync(tmpOutputDir, outputDir, {recursive: true});
|
||||
codegenLog(`Generated artifacts: ${outputDir}`);
|
||||
}
|
||||
|
||||
function shouldSkipGenerationForRncore(schemaInfo, platform) {
|
||||
function shouldSkipGenerationForRncore(
|
||||
schemaInfo /*: $FlowFixMe */,
|
||||
platform /*: string */,
|
||||
) {
|
||||
if (platform !== 'ios' || schemaInfo.library.config.name !== 'rncore') {
|
||||
return false;
|
||||
}
|
||||
@@ -82,13 +92,19 @@ function shouldSkipGenerationForRncore(schemaInfo, platform) {
|
||||
);
|
||||
}
|
||||
|
||||
function reactNativeCoreLibraryOutputPath(libraryName, platform) {
|
||||
function reactNativeCoreLibraryOutputPath(
|
||||
libraryName /*: string */,
|
||||
platform /*: string */,
|
||||
) {
|
||||
return CORE_LIBRARIES_WITH_OUTPUT_FOLDER[libraryName]
|
||||
? CORE_LIBRARIES_WITH_OUTPUT_FOLDER[libraryName][platform]
|
||||
: null;
|
||||
}
|
||||
|
||||
function shouldSkipGenerationForFBReactNativeSpec(schemaInfo, platform) {
|
||||
function shouldSkipGenerationForFBReactNativeSpec(
|
||||
schemaInfo /*: $FlowFixMe */,
|
||||
platform /*: string */,
|
||||
) {
|
||||
if (
|
||||
platform !== 'ios' ||
|
||||
schemaInfo.library.config.name !== 'FBReactNativeSpec'
|
||||
|
||||
Vendored
+7
-6
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -28,10 +29,10 @@ const MODULE_PROVIDERS_MM_TEMPLATE_PATH = path.join(
|
||||
);
|
||||
|
||||
function generateRCTModuleProviders(
|
||||
projectRoot,
|
||||
pkgJson,
|
||||
libraries,
|
||||
outputDir,
|
||||
projectRoot /*: string */,
|
||||
pkgJson /*: $FlowFixMe */,
|
||||
libraries /*: $ReadOnlyArray<$FlowFixMe> */,
|
||||
outputDir /*: string */,
|
||||
) {
|
||||
fs.mkdirSync(outputDir, {recursive: true});
|
||||
// Generate Header File
|
||||
@@ -42,7 +43,7 @@ function generateRCTModuleProviders(
|
||||
codegenLog(`Generated artifact: ${finalPathH}`);
|
||||
|
||||
codegenLog('Generating RCTModuleProviders.mm');
|
||||
let modulesInLibraries = {};
|
||||
let modulesInLibraries = {} /*:: as {[string]: Array<$FlowFixMe>} */;
|
||||
|
||||
let app = pkgJson.codegenConfig
|
||||
? {config: pkgJson.codegenConfig, libraryPath: projectRoot}
|
||||
@@ -64,7 +65,7 @@ function generateRCTModuleProviders(
|
||||
// Old API
|
||||
moduleLibraries.forEach(({config, libraryPath}) => {
|
||||
const libraryName = JSON.parse(
|
||||
fs.readFileSync(path.join(libraryPath, 'package.json')),
|
||||
fs.readFileSync(path.join(libraryPath, 'package.json'), 'utf8'),
|
||||
).name;
|
||||
|
||||
if (config.ios?.modulesProvider) {
|
||||
|
||||
packages/react-native/scripts/codegen/generate-artifacts-executor/generateRCTThirdPartyComponents.js
Vendored
+13
-6
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -28,7 +29,10 @@ const THIRD_PARTY_COMPONENTS_MM_TEMPLATE_PATH = path.join(
|
||||
'RCTThirdPartyComponentsProviderMM.template',
|
||||
);
|
||||
|
||||
function generateRCTThirdPartyComponents(libraries, outputDir) {
|
||||
function generateRCTThirdPartyComponents(
|
||||
libraries /*: $ReadOnlyArray<$FlowFixMe> */,
|
||||
outputDir /*: string */,
|
||||
) {
|
||||
fs.mkdirSync(outputDir, {recursive: true});
|
||||
// Generate Header File
|
||||
codegenLog('Generating RCTThirdPartyComponentsProvider.h');
|
||||
@@ -41,7 +45,7 @@ function generateRCTThirdPartyComponents(libraries, outputDir) {
|
||||
codegenLog(`Generated artifact: ${finalPathH}`);
|
||||
|
||||
codegenLog('Generating RCTThirdPartyComponentsProvider.mm');
|
||||
let componentsInLibraries = {};
|
||||
let componentsInLibraries = {} /*:: as {[string]: Array<$FlowFixMe>} */;
|
||||
|
||||
const componentLibraries = libraries.filter(({config, libraryPath}) => {
|
||||
if (isReactNativeCoreLibrary(config.name) || config.type === 'modules') {
|
||||
@@ -50,13 +54,13 @@ function generateRCTThirdPartyComponents(libraries, outputDir) {
|
||||
return true;
|
||||
});
|
||||
|
||||
const librariesToCrawl = {};
|
||||
const librariesToCrawl = {} /*:: as {[string]: $FlowFixMe} */;
|
||||
|
||||
// Old API
|
||||
componentLibraries.forEach(library => {
|
||||
const {config, libraryPath} = library;
|
||||
const libraryName = JSON.parse(
|
||||
fs.readFileSync(path.join(libraryPath, 'package.json')),
|
||||
fs.readFileSync(path.join(libraryPath, 'package.json'), 'utf8'),
|
||||
).name;
|
||||
|
||||
librariesToCrawl[libraryName] = library;
|
||||
@@ -140,7 +144,10 @@ function generateRCTThirdPartyComponents(libraries, outputDir) {
|
||||
|
||||
// Given a path, return the paths of all the files with extension .mm in
|
||||
// the path dir and all its subdirectories.
|
||||
function findFilesWithExtension(filePath, extension) {
|
||||
function findFilesWithExtension(
|
||||
filePath /*: string */,
|
||||
extension /*: string */,
|
||||
) /*: Array<string> */ {
|
||||
const files = [];
|
||||
const dir = fs.readdirSync(filePath);
|
||||
dir.forEach(file => {
|
||||
@@ -172,7 +179,7 @@ function findFilesWithExtension(filePath, extension) {
|
||||
|
||||
// Given a filepath, read the file and look for a string that starts with 'Class<RCTComponentViewProtocol> '
|
||||
// and ends with 'Cls(void)'. Return the string between the two.
|
||||
function findRCTComponentViewProtocolClass(filepath) {
|
||||
function findRCTComponentViewProtocolClass(filepath /*: string */) {
|
||||
const fileContent = fs.readFileSync(filepath, 'utf8');
|
||||
const regex = /Class<RCTComponentViewProtocol> (.*)Cls\(/;
|
||||
const match = fileContent.match(regex);
|
||||
|
||||
Vendored
+1
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
|
||||
Vendored
+8
-7
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -25,10 +26,10 @@ const REACT_CODEGEN_PODSPEC_TEMPLATE_PATH = path.join(
|
||||
);
|
||||
|
||||
function generateReactCodegenPodspec(
|
||||
appPath,
|
||||
appPkgJson,
|
||||
outputPath,
|
||||
baseOutputPath,
|
||||
appPath /*: string */,
|
||||
appPkgJson /*: $FlowFixMe */,
|
||||
outputPath /*: string */,
|
||||
baseOutputPath /*: string */,
|
||||
) {
|
||||
const inputFiles = getInputFiles(appPath, appPkgJson);
|
||||
const codegenScript = codegenScripts(appPath, baseOutputPath);
|
||||
@@ -42,8 +43,8 @@ function generateReactCodegenPodspec(
|
||||
codegenLog(`Generated podspec: ${finalPathPodspec}`);
|
||||
}
|
||||
|
||||
function getInputFiles(appPath, appPkgJSon) {
|
||||
const jsSrcsDir = appPkgJSon.codegenConfig?.jsSrcsDir;
|
||||
function getInputFiles(appPath /*: string */, appPkgJson /*: $FlowFixMe */) {
|
||||
const jsSrcsDir = appPkgJson.codegenConfig?.jsSrcsDir;
|
||||
if (!jsSrcsDir) {
|
||||
return '[]';
|
||||
}
|
||||
@@ -70,7 +71,7 @@ function getInputFiles(appPath, appPkgJSon) {
|
||||
return `[${list}]`;
|
||||
}
|
||||
|
||||
function codegenScripts(appPath, outputPath) {
|
||||
function codegenScripts(appPath /*: string */, outputPath /*: string */) {
|
||||
const relativeAppPath = path.relative(outputPath, appPath);
|
||||
return `<<-SCRIPT
|
||||
pushd "$PODS_ROOT/../" > /dev/null
|
||||
|
||||
+15
-5
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -15,11 +16,17 @@ const fs = require('fs');
|
||||
const glob = require('glob');
|
||||
const path = require('path');
|
||||
|
||||
function generateSchemaInfos(libraries) {
|
||||
function generateSchemaInfos(
|
||||
libraries /*: $ReadOnlyArray<$FlowFixMe> */,
|
||||
) /*: Array<$FlowFixMe> */ {
|
||||
// $FlowFixMe[incompatible-call]
|
||||
return libraries.map(generateSchemaInfo);
|
||||
}
|
||||
|
||||
function generateSchemaInfo(library, platform) {
|
||||
function generateSchemaInfo(
|
||||
library /*: $FlowFixMe */,
|
||||
platform /*: string */,
|
||||
) /*: $FlowFixMe */ {
|
||||
const pathToJavaScriptSources = path.join(
|
||||
library.libraryPath,
|
||||
library.config.jsSrcsDir,
|
||||
@@ -45,7 +52,10 @@ function generateSchemaInfo(library, platform) {
|
||||
|
||||
const APPLE_PLATFORMS = ['ios', 'macos', 'tvos', 'visionos'];
|
||||
|
||||
function extractSupportedApplePlatforms(dependency, dependencyPath) {
|
||||
function extractSupportedApplePlatforms(
|
||||
dependency /*: string */,
|
||||
dependencyPath /*: string */,
|
||||
) /*: ?{[string]: boolean} */ {
|
||||
codegenLog('Searching for podspec in the project dependencies.', true);
|
||||
const podspecs = glob.sync('*.podspec', {cwd: dependencyPath});
|
||||
|
||||
@@ -80,7 +90,7 @@ function extractSupportedApplePlatforms(dependency, dependencyPath) {
|
||||
getCocoaPodsPlatformKey(platform),
|
||||
),
|
||||
}),
|
||||
{},
|
||||
{} /*:: as {[string]: boolean} */,
|
||||
);
|
||||
|
||||
const supportedPlatformsList = Object.keys(supportedPlatformsMap).filter(
|
||||
@@ -99,7 +109,7 @@ function extractSupportedApplePlatforms(dependency, dependencyPath) {
|
||||
}
|
||||
|
||||
// Cocoapods specific platform keys
|
||||
function getCocoaPodsPlatformKey(platformName) {
|
||||
function getCocoaPodsPlatformKey(platformName /*: string */) {
|
||||
if (platformName === 'macos') {
|
||||
return 'osx';
|
||||
}
|
||||
|
||||
+4
-3
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -27,12 +28,12 @@ const UNSTABLE_MODULES_REQUIRING_MAIN_QUEUE_SETUP_PROVIDER_MM_TEMPLATE_PATH =
|
||||
);
|
||||
|
||||
function generateUnstableModulesRequiringMainQueueSetupProvider(
|
||||
libraries,
|
||||
outputDir,
|
||||
libraries /*: $ReadOnlyArray<$FlowFixMe> */,
|
||||
outputDir /*: string */,
|
||||
) {
|
||||
const iosAnnotations = parseiOSAnnotations(libraries);
|
||||
|
||||
const modulesRequiringMainQueueSetup = new Set();
|
||||
const modulesRequiringMainQueueSetup = new Set /*::<string>*/();
|
||||
|
||||
// Old API
|
||||
libraries.forEach(library => {
|
||||
|
||||
+24
-10
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -58,11 +59,11 @@ const path = require('path');
|
||||
* @throws If it can't find a cli for the CodeGen.
|
||||
*/
|
||||
function execute(
|
||||
projectRoot,
|
||||
targetPlatform,
|
||||
baseOutputPath,
|
||||
source,
|
||||
runReactNativeCodegen = true,
|
||||
projectRoot /*: string */,
|
||||
targetPlatform /*: string */,
|
||||
baseOutputPath /*: string */,
|
||||
source /*: string */,
|
||||
runReactNativeCodegen /*: boolean */ = true,
|
||||
) {
|
||||
try {
|
||||
codegenLog(`Analyzing ${path.join(projectRoot, 'package.json')}`);
|
||||
@@ -161,7 +162,10 @@ function execute(
|
||||
return;
|
||||
}
|
||||
|
||||
function readOutputDirFromPkgJson(pkgJson, platform) {
|
||||
function readOutputDirFromPkgJson(
|
||||
pkgJson /*: $FlowFixMe */,
|
||||
platform /*: string */,
|
||||
) {
|
||||
const codegenConfig = pkgJson.codegenConfig;
|
||||
if (codegenConfig == null || typeof codegenConfig !== 'object') {
|
||||
return null;
|
||||
@@ -179,12 +183,19 @@ function readOutputDirFromPkgJson(pkgJson, platform) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function computeOutputPath(projectRoot, baseOutputPath, pkgJson, platform) {
|
||||
function computeOutputPath(
|
||||
projectRoot /*: string */,
|
||||
baseOutputPath /*: string */,
|
||||
pkgJson /*: $FlowFixMe */,
|
||||
platform /*: string */,
|
||||
) {
|
||||
if (baseOutputPath == null) {
|
||||
const outputDirFromPkgJson = readOutputDirFromPkgJson(pkgJson, platform);
|
||||
if (outputDirFromPkgJson != null) {
|
||||
// $FlowFixMe[reassign-const]
|
||||
baseOutputPath = path.join(projectRoot, outputDirFromPkgJson);
|
||||
} else {
|
||||
// $FlowFixMe[reassign-const]
|
||||
baseOutputPath = projectRoot;
|
||||
}
|
||||
}
|
||||
@@ -201,7 +212,7 @@ function computeOutputPath(projectRoot, baseOutputPath, pkgJson, platform) {
|
||||
return baseOutputPath;
|
||||
}
|
||||
|
||||
function defaultOutputPathForAndroid(baseOutputPath) {
|
||||
function defaultOutputPathForAndroid(baseOutputPath /*: string */) {
|
||||
return path.join(
|
||||
baseOutputPath,
|
||||
'android',
|
||||
@@ -213,11 +224,14 @@ function defaultOutputPathForAndroid(baseOutputPath) {
|
||||
);
|
||||
}
|
||||
|
||||
function defaultOutputPathForIOS(baseOutputPath) {
|
||||
function defaultOutputPathForIOS(baseOutputPath /*: string */) {
|
||||
return path.join(baseOutputPath, 'build', 'generated', 'ios');
|
||||
}
|
||||
|
||||
function mustGenerateNativeCode(includeLibraryPath, schemaInfo) {
|
||||
function mustGenerateNativeCode(
|
||||
includeLibraryPath /*: string */,
|
||||
schemaInfo /*: $FlowFixMe */,
|
||||
) {
|
||||
// If library's 'codegenConfig' sets 'includesGeneratedCode' to 'true',
|
||||
// then we assume that native code is shipped with the library,
|
||||
// and we don't need to generate it.
|
||||
|
||||
+50
-22
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -17,11 +18,13 @@ const {execSync} = require('child_process');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
function pkgJsonIncludesGeneratedCode(pkgJson) {
|
||||
function pkgJsonIncludesGeneratedCode(
|
||||
pkgJson /*: $FlowFixMe */,
|
||||
) /*: boolean */ {
|
||||
return pkgJson.codegenConfig && pkgJson.codegenConfig.includesGeneratedCode;
|
||||
}
|
||||
|
||||
const codegenLog = (text, info = false) => {
|
||||
const codegenLog = (text /*: string */, info /*: boolean */ = false) => {
|
||||
// ANSI escape codes for colors and formatting
|
||||
const reset = '\x1b[0m';
|
||||
const cyan = '\x1b[36m';
|
||||
@@ -32,12 +35,12 @@ const codegenLog = (text, info = false) => {
|
||||
console.log(`${cyan}${bold}[Codegen]${reset} ${color}${text}${reset}`);
|
||||
};
|
||||
|
||||
function readPkgJsonInDirectory(dir) {
|
||||
function readPkgJsonInDirectory(dir /*: string */) /*: $FlowFixMe */ {
|
||||
const pkgJsonPath = path.join(dir, 'package.json');
|
||||
if (!fs.existsSync(pkgJsonPath)) {
|
||||
throw `[Codegen] Error: ${pkgJsonPath} does not exist.`;
|
||||
}
|
||||
return JSON.parse(fs.readFileSync(pkgJsonPath));
|
||||
return JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
|
||||
}
|
||||
|
||||
function buildCodegenIfNeeded() {
|
||||
@@ -69,7 +72,7 @@ function buildCodegenIfNeeded() {
|
||||
// we don't know whether they will be populated up until the end of the process.
|
||||
//
|
||||
// @parameter filepath: the root path from which we want to remove the empty files and folders.
|
||||
function cleanupEmptyFilesAndFolders(filepath) {
|
||||
function cleanupEmptyFilesAndFolders(filepath /*: string */) {
|
||||
const stats = fs.statSync(filepath);
|
||||
|
||||
if (stats.isFile() && stats.size === 0) {
|
||||
@@ -94,20 +97,25 @@ function cleanupEmptyFilesAndFolders(filepath) {
|
||||
}
|
||||
}
|
||||
|
||||
function readReactNativeConfig(projectRoot) {
|
||||
function readReactNativeConfig(projectRoot /*: string */) /*: $FlowFixMe */ {
|
||||
const rnConfigFilePath = path.resolve(projectRoot, 'react-native.config.js');
|
||||
|
||||
if (!fs.existsSync(rnConfigFilePath)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// $FlowIgnore[unsupported-syntax]
|
||||
return require(rnConfigFilePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finding libraries!
|
||||
*/
|
||||
function findCodegenEnabledLibraries(pkgJson, projectRoot, reactNativeConfig) {
|
||||
function findCodegenEnabledLibraries(
|
||||
pkgJson /*: $FlowFixMe */,
|
||||
projectRoot /*: string */,
|
||||
reactNativeConfig /*: $FlowFixMe */,
|
||||
) /*: Array<$FlowFixMe> */ {
|
||||
const projectLibraries = findProjectRootLibraries(pkgJson, projectRoot);
|
||||
if (pkgJsonIncludesGeneratedCode(pkgJson)) {
|
||||
return projectLibraries;
|
||||
@@ -120,7 +128,10 @@ function findCodegenEnabledLibraries(pkgJson, projectRoot, reactNativeConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
function findProjectRootLibraries(pkgJson, projectRoot) {
|
||||
function findProjectRootLibraries(
|
||||
pkgJson /*: $FlowFixMe */,
|
||||
projectRoot /*: string */,
|
||||
) /*: Array<$FlowFixMe> */ {
|
||||
codegenLog('Searching for codegen-enabled libraries in the app.', true);
|
||||
|
||||
if (pkgJson.codegenConfig == null) {
|
||||
@@ -138,7 +149,10 @@ function findProjectRootLibraries(pkgJson, projectRoot) {
|
||||
return extractLibrariesFromJSON(pkgJson, projectRoot);
|
||||
}
|
||||
|
||||
function findLibrariesFromReactNativeConfig(projectRoot, rnConfig) {
|
||||
function findLibrariesFromReactNativeConfig(
|
||||
projectRoot /*: string */,
|
||||
rnConfig /*: $FlowFixMe */,
|
||||
) /*: Array<$FlowFixMe> */ {
|
||||
codegenLog(
|
||||
`Searching for codegen-enabled libraries in react-native.config.js`,
|
||||
true,
|
||||
@@ -168,7 +182,10 @@ function findLibrariesFromReactNativeConfig(projectRoot, rnConfig) {
|
||||
});
|
||||
}
|
||||
|
||||
function findExternalLibraries(pkgJson, projectRoot) {
|
||||
function findExternalLibraries(
|
||||
pkgJson /*: $FlowFixMe */,
|
||||
projectRoot /*: string */,
|
||||
) /*: Array<$FlowFixMe> */ {
|
||||
const dependencies = {
|
||||
...pkgJson.dependencies,
|
||||
...pkgJson.devDependencies,
|
||||
@@ -201,13 +218,16 @@ function findExternalLibraries(pkgJson, projectRoot) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
const configFile = JSON.parse(fs.readFileSync(configFilePath));
|
||||
const configFile = JSON.parse(fs.readFileSync(configFilePath, 'utf8'));
|
||||
const codegenConfigFileDir = path.dirname(configFilePath);
|
||||
return extractLibrariesFromJSON(configFile, codegenConfigFileDir);
|
||||
});
|
||||
}
|
||||
|
||||
function extractLibrariesFromJSON(configFile, dependencyPath) {
|
||||
function extractLibrariesFromJSON(
|
||||
configFile /*: $FlowFixMe */,
|
||||
dependencyPath /*: string */,
|
||||
) /*: Array<$FlowFixMe> */ {
|
||||
if (configFile.codegenConfig == null) {
|
||||
return [];
|
||||
}
|
||||
@@ -226,7 +246,7 @@ function extractLibrariesFromJSON(configFile, dependencyPath) {
|
||||
}
|
||||
}
|
||||
|
||||
function printDeprecationWarningIfNeeded(dependency) {
|
||||
function printDeprecationWarningIfNeeded(dependency /*: string */) {
|
||||
if (dependency === REACT_NATIVE) {
|
||||
return;
|
||||
}
|
||||
@@ -264,7 +284,10 @@ function printDeprecationWarningIfNeeded(dependency) {
|
||||
`);
|
||||
}
|
||||
|
||||
function extractLibrariesFromConfigurationArray(configFile, dependencyPath) {
|
||||
function extractLibrariesFromConfigurationArray(
|
||||
configFile /*: $FlowFixMe */,
|
||||
dependencyPath /*: string */,
|
||||
) {
|
||||
return configFile.codegenConfig.libraries.map(config => {
|
||||
return {
|
||||
config,
|
||||
@@ -273,7 +296,7 @@ function extractLibrariesFromConfigurationArray(configFile, dependencyPath) {
|
||||
});
|
||||
}
|
||||
|
||||
function isReactNativeCoreLibrary(libraryName) {
|
||||
function isReactNativeCoreLibrary(libraryName /*: string */) /*: boolean */ {
|
||||
return libraryName in CORE_LIBRARIES_WITH_OUTPUT_FOLDER;
|
||||
}
|
||||
|
||||
@@ -299,9 +322,11 @@ function isReactNativeCoreLibrary(libraryName) {
|
||||
* Validates that modules are defined in at most one library.
|
||||
* Validates that components are defined in at most one library.
|
||||
*/
|
||||
function parseiOSAnnotations(libraries) {
|
||||
const mLibraryMap = {};
|
||||
const cLibraryMap = {};
|
||||
function parseiOSAnnotations(
|
||||
libraries /*: $ReadOnlyArray<$FlowFixMe> */,
|
||||
) /*: {[string]: $FlowFixMe} */ {
|
||||
const mLibraryMap = {} /*:: as {[string]: $FlowFixMe} */;
|
||||
const cLibraryMap = {} /*:: as {[string]: $FlowFixMe} */;
|
||||
const map = {};
|
||||
|
||||
for (const library of libraries) {
|
||||
@@ -351,7 +376,7 @@ function parseiOSAnnotations(libraries) {
|
||||
return ` Component { "${moduleName}" } => Libraries{ ${libraryNamesString} }\n`;
|
||||
});
|
||||
|
||||
if (moduleConflicts.length > 0 || componentConflicts.legnth > 0) {
|
||||
if (moduleConflicts.length > 0 || componentConflicts.length > 0) {
|
||||
throw new Error(
|
||||
'Some components or modules are declared in more than one libraries: \n' +
|
||||
[...moduleConflicts, ...componentConflicts].join('\n'),
|
||||
@@ -361,9 +386,9 @@ function parseiOSAnnotations(libraries) {
|
||||
return map;
|
||||
}
|
||||
|
||||
function getLibraryName(library) {
|
||||
function getLibraryName(library /*: $FlowFixMe */) {
|
||||
return JSON.parse(
|
||||
fs.readFileSync(path.join(library.libraryPath, 'package.json')),
|
||||
fs.readFileSync(path.join(library.libraryPath, 'package.json'), 'utf8'),
|
||||
).name;
|
||||
}
|
||||
|
||||
@@ -372,7 +397,10 @@ function getLibraryName(library) {
|
||||
*
|
||||
* This is needed when selectively disabling libraries in react-native.config.js since codegen should exclude those libraries as well.
|
||||
*/
|
||||
function findDisabledLibrariesByPlatform(reactNativeConfig, platform) {
|
||||
function findDisabledLibrariesByPlatform(
|
||||
reactNativeConfig /*: $FlowFixMe */,
|
||||
platform /*: string */,
|
||||
) /*: Array<$FlowFixMe> */ {
|
||||
const dependencies = reactNativeConfig.dependencies ?? {};
|
||||
|
||||
return Object.keys(dependencies).filter(
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -14,22 +15,26 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const GENERATORS = {
|
||||
all: {
|
||||
android: ['componentsAndroid', 'modulesAndroid', 'modulesCxx'],
|
||||
ios: ['componentsIOS', 'modulesIOS', 'modulesCxx'],
|
||||
},
|
||||
components: {
|
||||
android: ['componentsAndroid'],
|
||||
ios: ['componentsIOS'],
|
||||
},
|
||||
modules: {
|
||||
android: ['modulesAndroid', 'modulesCxx'],
|
||||
ios: ['modulesIOS', 'modulesCxx'],
|
||||
},
|
||||
};
|
||||
all: {
|
||||
android: ['componentsAndroid', 'modulesAndroid', 'modulesCxx'],
|
||||
ios: ['componentsIOS', 'modulesIOS', 'modulesCxx'],
|
||||
},
|
||||
components: {
|
||||
android: ['componentsAndroid'],
|
||||
ios: ['componentsIOS'],
|
||||
},
|
||||
modules: {
|
||||
android: ['modulesAndroid', 'modulesCxx'],
|
||||
ios: ['modulesIOS', 'modulesCxx'],
|
||||
},
|
||||
} /*:: as {[string]: {[string]: $ReadOnlyArray<string>}} */;
|
||||
|
||||
function createOutputDirectoryIfNeeded(outputDirectory, libraryName) {
|
||||
function createOutputDirectoryIfNeeded(
|
||||
outputDirectory /*: string */,
|
||||
libraryName /*: string */,
|
||||
) {
|
||||
if (!outputDirectory) {
|
||||
// $FlowFixMe[reassign-const]
|
||||
outputDirectory = path.resolve(__dirname, '..', 'Libraries', libraryName);
|
||||
}
|
||||
fs.mkdirSync(outputDirectory, {recursive: true});
|
||||
@@ -43,7 +48,7 @@ function createOutputDirectoryIfNeeded(outputDirectory, libraryName) {
|
||||
* @return a valid schema
|
||||
* @throw an Error if the schema doesn't exists in a given path or if it can't be parsed.
|
||||
*/
|
||||
function readAndParseSchema(schemaPath) {
|
||||
function readAndParseSchema(schemaPath /*: string */) {
|
||||
const schemaText = fs.readFileSync(schemaPath, 'utf-8');
|
||||
|
||||
if (schemaText == null) {
|
||||
@@ -57,20 +62,20 @@ function readAndParseSchema(schemaPath) {
|
||||
}
|
||||
}
|
||||
|
||||
function validateLibraryType(libraryType) {
|
||||
function validateLibraryType(libraryType /*: string */) {
|
||||
if (GENERATORS[libraryType] == null) {
|
||||
throw new Error(`Invalid library type. ${libraryType}`);
|
||||
}
|
||||
}
|
||||
|
||||
function generateSpecFromInMemorySchema(
|
||||
platform,
|
||||
schema,
|
||||
outputDirectory,
|
||||
libraryName,
|
||||
packageName,
|
||||
libraryType,
|
||||
useLocalIncludePaths,
|
||||
platform /*: string */,
|
||||
schema /*: string */,
|
||||
outputDirectory /*: string */,
|
||||
libraryName /*: string */,
|
||||
packageName /*: string */,
|
||||
libraryType /*: string */,
|
||||
useLocalIncludePaths /*: boolean */,
|
||||
) {
|
||||
validateLibraryType(libraryType);
|
||||
createOutputDirectoryIfNeeded(outputDirectory, libraryName);
|
||||
@@ -105,13 +110,14 @@ function generateSpecFromInMemorySchema(
|
||||
}
|
||||
|
||||
function generateSpec(
|
||||
platform,
|
||||
schemaPath,
|
||||
outputDirectory,
|
||||
libraryName,
|
||||
packageName,
|
||||
libraryType,
|
||||
platform /*: string */,
|
||||
schemaPath /*: string */,
|
||||
outputDirectory /*: string */,
|
||||
libraryName /*: string */,
|
||||
packageName /*: string */,
|
||||
libraryType /*: string */,
|
||||
) {
|
||||
// $FlowFixMe[incompatible-call]
|
||||
generateSpecFromInMemorySchema(
|
||||
platform,
|
||||
readAndParseSchema(schemaPath),
|
||||
@@ -124,5 +130,5 @@ function generateSpec(
|
||||
|
||||
module.exports = {
|
||||
execute: generateSpec,
|
||||
generateSpecFromInMemorySchema: generateSpecFromInMemorySchema,
|
||||
generateSpecFromInMemorySchema,
|
||||
};
|
||||
|
||||
+3
-2
@@ -5,6 +5,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -14,7 +15,7 @@ const fs = require('fs');
|
||||
const {composeSourceMaps} = require('metro-source-map');
|
||||
|
||||
const argv = process.argv.slice(2);
|
||||
let outputPath;
|
||||
let outputPath /*: ?string */;
|
||||
for (let i = 0; i < argv.length; ) {
|
||||
if (argv[i] === '-o') {
|
||||
outputPath = argv[i + 1];
|
||||
@@ -58,7 +59,7 @@ if (!argv.length) {
|
||||
const composedMapJSON = JSON.stringify(
|
||||
composeSourceMaps([packagerSourcemap, compilerSourcemap]),
|
||||
);
|
||||
if (outputPath) {
|
||||
if (outputPath != null) {
|
||||
fs.writeFileSync(outputPath, composedMapJSON, 'utf8');
|
||||
} else {
|
||||
process.stdout.write(composedMapJSON);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
|
||||
-7
@@ -1,10 +1,3 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -33,4 +34,5 @@ const argv = yargs
|
||||
.usage('Usage: $0 -p [path to app] -t [target platform] -o [output path]')
|
||||
.demandOption(['p', 't']).argv;
|
||||
|
||||
// $FlowFixMe[prop-missing]
|
||||
executor.execute(argv.path, argv.targetPlatform, argv.outputPath, argv.source);
|
||||
|
||||
+11
-5
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -34,11 +35,15 @@ const argv = yargs
|
||||
).argv;
|
||||
|
||||
const GENERATORS = {
|
||||
android: [],
|
||||
ios: ['providerIOS'],
|
||||
};
|
||||
android: [],
|
||||
ios: ['providerIOS'],
|
||||
} /*:: as {[string]: $ReadOnlyArray<string>} */;
|
||||
|
||||
function generateProvider(platform, schemaListPath, outputDirectory) {
|
||||
function generateProvider(
|
||||
platform /*: string */,
|
||||
schemaListPath /*: string */,
|
||||
outputDirectory /*: string */,
|
||||
) {
|
||||
const schemaListText = fs.readFileSync(schemaListPath, 'utf-8');
|
||||
|
||||
if (schemaListText == null) {
|
||||
@@ -57,7 +62,7 @@ function generateProvider(platform, schemaListPath, outputDirectory) {
|
||||
throw new Error(`Can't parse schema to JSON. ${schemaListPath}`);
|
||||
}
|
||||
|
||||
const schemas = {};
|
||||
const schemas = {} /*:: as {[string]: $FlowFixMe} */;
|
||||
try {
|
||||
for (const libraryName of Object.keys(schemaPaths)) {
|
||||
const tmpSchemaText = fs.readFileSync(schemaPaths[libraryName], 'utf-8');
|
||||
@@ -83,6 +88,7 @@ function generateProvider(platform, schemaListPath, outputDirectory) {
|
||||
}
|
||||
|
||||
function main() {
|
||||
// $FlowFixMe[prop-missing]
|
||||
generateProvider(argv.platform, argv.schemaListPath, argv.outputDir);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -49,11 +50,17 @@ const argv = yargs
|
||||
|
||||
function main() {
|
||||
executor.execute(
|
||||
// $FlowFixMe[prop-missing]
|
||||
argv.platform,
|
||||
// $FlowFixMe[prop-missing]
|
||||
argv.schemaPath,
|
||||
// $FlowFixMe[prop-missing]
|
||||
argv.outputDir,
|
||||
// $FlowFixMe[prop-missing]
|
||||
argv.libraryName,
|
||||
// $FlowFixMe[prop-missing]
|
||||
argv.javaPackageName,
|
||||
// $FlowFixMe[prop-missing]
|
||||
argv.libraryType,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -35,8 +36,9 @@ const hermesTagSha = '5244f819b2f3949ca94a3a1bf75d54a8ed59d94a';
|
||||
const ROOT_DIR = path.normalize(path.join(__dirname, '../../..'));
|
||||
const SDKS_DIR = path.join(ROOT_DIR, 'sdks');
|
||||
|
||||
let execCalls, spawnCalls;
|
||||
let fs;
|
||||
let execCalls: $FlowFixMe;
|
||||
let spawnCalls: $FlowFixMe;
|
||||
let fs: $FlowFixMe;
|
||||
|
||||
jest.mock('child_process', () => ({
|
||||
execSync: jest.fn((command, options) => {
|
||||
@@ -153,6 +155,7 @@ describe('hermes-utils', () => {
|
||||
}),
|
||||
);
|
||||
fs = require('fs');
|
||||
// $FlowFixMe[prop-missing]
|
||||
fs.reset();
|
||||
|
||||
populateMockFilesystemWithHermesBuildScripts();
|
||||
|
||||
@@ -5,12 +5,14 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const {setHermesTag} = require('./hermes-utils');
|
||||
// $FlowFixMe[untyped-import]
|
||||
const inquirer = require('inquirer');
|
||||
/**
|
||||
* This script walks a releaser through bumping the Hermes version for a release.
|
||||
@@ -27,6 +29,7 @@ let argv = yargs.option('t', {
|
||||
}).argv;
|
||||
|
||||
async function main() {
|
||||
// $FlowFixMe[prop-missing]
|
||||
const hermesTag = argv.tag;
|
||||
const {confirmHermesTag} = await inquirer.prompt({
|
||||
type: 'confirm',
|
||||
@@ -42,6 +45,6 @@ async function main() {
|
||||
setHermesTag(hermesTag);
|
||||
}
|
||||
|
||||
main().then(() => {
|
||||
void main().then(() => {
|
||||
exit(0);
|
||||
});
|
||||
|
||||
+6
-1
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -41,9 +42,13 @@ let argv = yargs
|
||||
}).argv;
|
||||
|
||||
async function main() {
|
||||
// $FlowFixMe[prop-missing]
|
||||
const hermesDir = argv.inputDir;
|
||||
// $FlowFixMe[prop-missing]
|
||||
const buildType = argv.buildType;
|
||||
// $FlowFixMe[prop-missing]
|
||||
const excludeDebugSymbols = argv.excludeDebugSymbols;
|
||||
// $FlowFixMe[prop-missing]
|
||||
let tarballOutputDir = argv.outputDir;
|
||||
|
||||
if (!tarballOutputDir) {
|
||||
@@ -68,6 +73,6 @@ async function main() {
|
||||
return tarballOutputPath;
|
||||
}
|
||||
|
||||
main().then(() => {
|
||||
void main().then(() => {
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -24,11 +25,12 @@ let argv = yargs.option('b', {
|
||||
}).argv;
|
||||
|
||||
async function main() {
|
||||
// $FlowFixMe[prop-missing]
|
||||
const tarballName = getHermesPrebuiltArtifactsTarballName(argv.buildType);
|
||||
console.log(tarballName);
|
||||
return tarballName;
|
||||
}
|
||||
|
||||
main().then(() => {
|
||||
void main().then(() => {
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
+2
-2
@@ -224,9 +224,9 @@ set_target_properties(native-hermesc PROPERTIES
|
||||
}
|
||||
|
||||
function getHermesPrebuiltArtifactsTarballName(
|
||||
buildType /*: string */,
|
||||
buildType /*:: ?: string */,
|
||||
) /*: string */ {
|
||||
if (!buildType) {
|
||||
if (buildType == null) {
|
||||
throw Error('Did not specify build type.');
|
||||
}
|
||||
return `hermes-ios-${buildType.toLowerCase()}.tar.gz`;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
@@ -23,7 +24,7 @@ const {
|
||||
shouldUsePrebuiltHermesC,
|
||||
} = require('./hermes-utils');
|
||||
|
||||
async function main(isInCI) {
|
||||
async function main(isInCI /*: boolean */) {
|
||||
if (!shouldBuildHermesFromSource(isInCI)) {
|
||||
copyPodSpec();
|
||||
return;
|
||||
@@ -41,6 +42,6 @@ async function main(isInCI) {
|
||||
|
||||
const isInCI = process.env.CI === 'true';
|
||||
|
||||
main(isInCI).then(() => {
|
||||
void main(isInCI).then(() => {
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
+8
-2
@@ -4,17 +4,21 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
let reporter /*: $FlowFixMe */;
|
||||
|
||||
const logPath = process.env.RCT_PACKAGER_LOG_PATH;
|
||||
if (logPath != null && logPath !== '') {
|
||||
const JsonReporter = require('metro/src/lib/JsonReporter');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
module.exports = class extends JsonReporter {
|
||||
// $FlowFixMe[missing-type-arg]
|
||||
reporter = class extends JsonReporter {
|
||||
constructor() {
|
||||
fs.mkdirSync(path.dirname(logPath), {
|
||||
recursive: true,
|
||||
@@ -23,5 +27,7 @@ if (logPath != null && logPath !== '') {
|
||||
}
|
||||
};
|
||||
} else {
|
||||
module.exports = require('metro/src/lib/TerminalReporter');
|
||||
reporter = require('metro/src/lib/TerminalReporter');
|
||||
}
|
||||
|
||||
module.exports = reporter;
|
||||
|
||||
Reference in New Issue
Block a user