mirror of
https://github.com/react/react-native.git
synced 2026-09-28 13:23:09 +08:00
Create shared consts module for scripts
Summary: Tidy up, removes risk of breakage when relocating inner modules. Changelog: [Internal] Reviewed By: lunaleaps Differential Revision: D53813025 fbshipit-source-id: 43dc4a57191363546d6858cff311e260d416192f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
a80674fc7c
commit
80ec096e7c
@@ -9,6 +9,7 @@
|
||||
* @oncall react_native
|
||||
*/
|
||||
|
||||
const {PACKAGES_DIR} = require('../consts');
|
||||
const {
|
||||
buildConfig,
|
||||
getBabelConfig,
|
||||
@@ -26,8 +27,6 @@ const path = require('path');
|
||||
const prettier = require('prettier');
|
||||
const ts = require('typescript');
|
||||
|
||||
const REPO_ROOT = path.resolve(__dirname, '../..');
|
||||
const PACKAGES_DIR /*: string */ = path.join(REPO_ROOT, 'packages');
|
||||
const SRC_DIR = 'src';
|
||||
const BUILD_DIR = 'dist';
|
||||
const JS_FILES_PATTERN = '**/*.js';
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @flow strict
|
||||
* @format
|
||||
* @oncall react_native
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
|
||||
/**
|
||||
* The absolute path to the repo root.
|
||||
*/
|
||||
const REPO_ROOT /*: string */ = path.resolve(__dirname, '..');
|
||||
|
||||
/**
|
||||
* The absolute path to the packages directory (note: this directory alone may
|
||||
* not match the "workspaces" config in package.json).
|
||||
*/
|
||||
const PACKAGES_DIR /*: string */ = path.join(REPO_ROOT, 'packages');
|
||||
|
||||
/**
|
||||
* The absolute path to the repo scripts directory.
|
||||
*/
|
||||
const SCRIPTS_DIR /*: string */ = path.join(REPO_ROOT, 'scripts');
|
||||
|
||||
/**
|
||||
* The absolute path to the react-native package.
|
||||
*/
|
||||
const REACT_NATIVE_PACKAGE_DIR /*: string */ = path.join(
|
||||
REPO_ROOT,
|
||||
'packages',
|
||||
'react-native',
|
||||
);
|
||||
|
||||
module.exports = {
|
||||
PACKAGES_DIR,
|
||||
REACT_NATIVE_PACKAGE_DIR,
|
||||
REPO_ROOT,
|
||||
SCRIPTS_DIR,
|
||||
};
|
||||
@@ -9,6 +9,7 @@
|
||||
* @oncall react_native
|
||||
*/
|
||||
|
||||
const {PACKAGES_DIR} = require('../consts');
|
||||
const {parseArgs} = require('@pkgjs/parseargs');
|
||||
// $FlowFixMe[untyped-import]: TODO type ansi-styles
|
||||
const ansiStyles = require('ansi-styles');
|
||||
@@ -27,9 +28,6 @@ const supportsColor = require('supports-color');
|
||||
const DEVTOOLS_FRONTEND_REPO_URL =
|
||||
'https://github.com/facebookexperimental/rn-chrome-devtools-frontend';
|
||||
|
||||
const REPO_ROOT = path.resolve(__dirname, '../..');
|
||||
const PACKAGES_DIR /*: string */ = path.join(REPO_ROOT, 'packages');
|
||||
|
||||
const config = {
|
||||
allowPositionals: true,
|
||||
options: {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
'use strict';
|
||||
|
||||
const {retry} = require('../circleci/retry');
|
||||
const {REPO_ROOT} = require('../consts');
|
||||
const forEachPackage = require('../monorepo/for-each-package');
|
||||
const {
|
||||
VERDACCIO_SERVER_URL,
|
||||
@@ -21,9 +22,6 @@ const {
|
||||
const {parseArgs} = require('@pkgjs/parseargs');
|
||||
const chalk = require('chalk');
|
||||
const {execSync} = require('child_process');
|
||||
const path = require('path');
|
||||
|
||||
const REPO_ROOT = path.resolve(__dirname, '../..');
|
||||
|
||||
const config = {
|
||||
options: {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
* --retries [num] - how many times to retry possible flaky commands: yarn add and running tests, default 1
|
||||
*/
|
||||
|
||||
const {REACT_NATIVE_PACKAGE_DIR, REPO_ROOT, SCRIPTS_DIR} = require('../consts');
|
||||
const forEachPackage = require('../monorepo/for-each-package');
|
||||
const tryExecNTimes = require('./utils/try-n-times');
|
||||
const {setupVerdaccio} = require('./utils/verdaccio');
|
||||
@@ -30,10 +31,6 @@ const path = require('path');
|
||||
const {cd, cp, echo, exec, exit, mv} = require('shelljs');
|
||||
const argv = require('yargs').argv;
|
||||
|
||||
const SCRIPTS = path.join(__dirname, '..');
|
||||
const REPO_ROOT = path.join(__dirname, '../..');
|
||||
const REACT_NATIVE_PACKAGE_DIR = path.join(REPO_ROOT, 'packages/react-native');
|
||||
|
||||
const REACT_NATIVE_TEMP_DIR = exec(
|
||||
'mktemp -d /tmp/react-native-XXXXXXXX',
|
||||
).stdout.trim();
|
||||
@@ -150,7 +147,7 @@ try {
|
||||
'Failed to install appium. Most common reason is npm registry connectivity, try again.',
|
||||
);
|
||||
}
|
||||
cp(`${SCRIPTS}/android-e2e-test.js`, 'android-e2e-test.js');
|
||||
cp(`${SCRIPTS_DIR}/android-e2e-test.js`, 'android-e2e-test.js');
|
||||
cd('android');
|
||||
describe('Download Maven deps');
|
||||
exec('./gradlew :app:copyDownloadableDepsToLibs');
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const {REPO_ROOT} = require('../../consts');
|
||||
const {execSync, spawn} = require('child_process');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const REPO_ROOT = path.join(__dirname, '../../..');
|
||||
const NPM_CONFIG_PATH = path.join(REPO_ROOT, '.npmrc');
|
||||
const VERDACCIO_CONFIG_PATH = path.join(__dirname, '..', 'verdaccio.yml');
|
||||
const VERDACCIO_STORAGE_PATH = '/tmp/verdaccio';
|
||||
|
||||
@@ -8,12 +8,10 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
const {PACKAGES_DIR} = require('../consts');
|
||||
const {readdirSync, readFileSync} = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const REPO_ROOT = path.join(path.dirname(__filename), '..', '..');
|
||||
const PACKAGES_LOCATION = path.join(REPO_ROOT, 'packages');
|
||||
|
||||
const DEFAULT_OPTIONS /*: Options */ = {includeReactNative: false};
|
||||
|
||||
/*::
|
||||
@@ -51,13 +49,13 @@ const forEachPackage = (
|
||||
|
||||
// We filter react-native package on purpose, so that no CI's script will be executed for this package in future
|
||||
// Unless includeReactNative options is provided
|
||||
const packagesDirectories = getDirectories(PACKAGES_LOCATION).filter(
|
||||
const packagesDirectories = getDirectories(PACKAGES_DIR).filter(
|
||||
directoryName =>
|
||||
directoryName !== 'react-native' || includeReactNative === true,
|
||||
);
|
||||
|
||||
packagesDirectories.forEach(packageDirectory => {
|
||||
const packageAbsolutePath = path.join(PACKAGES_LOCATION, packageDirectory);
|
||||
const packageAbsolutePath = path.join(PACKAGES_DIR, packageDirectory);
|
||||
const packageRelativePathFromRoot = path.join('packages', packageDirectory);
|
||||
|
||||
const packageManifest = JSON.parse(
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
* and to make it more accessible for other devs to play around with.
|
||||
*/
|
||||
|
||||
const {REPO_ROOT} = require('../consts');
|
||||
const {initNewProjectFromSource} = require('../e2e/init-template-e2e');
|
||||
const updateTemplatePackage = require('../releases/update-template-package');
|
||||
const {
|
||||
@@ -36,8 +37,6 @@ const yargs = require('yargs');
|
||||
type Unwrap<T> = T extends Promise<infer U> ? U : T;
|
||||
*/
|
||||
|
||||
const REPO_ROOT = path.resolve(__dirname, '../..');
|
||||
|
||||
const argv = yargs
|
||||
.option('t', {
|
||||
alias: 'target',
|
||||
|
||||
@@ -22,11 +22,10 @@ const getNpmInfoMock = jest.fn();
|
||||
const generateAndroidArtifactsMock = jest.fn();
|
||||
const getPackagesMock = jest.fn();
|
||||
|
||||
const {REPO_ROOT} = require('../../consts');
|
||||
const {publishNpm} = require('../publish-npm');
|
||||
const path = require('path');
|
||||
|
||||
const REPO_ROOT = path.resolve(__filename, '../../../..');
|
||||
|
||||
let consoleLog;
|
||||
|
||||
describe('publish-npm', () => {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
import type {BuildType} from '../releases/utils/version-utils';
|
||||
*/
|
||||
|
||||
const {REPO_ROOT} = require('../consts');
|
||||
const {getNpmInfo, publishPackage} = require('../npm-utils');
|
||||
const {removeNewArchFlags} = require('../releases/remove-new-arch-flags');
|
||||
const {setReactNativeVersion} = require('../releases/set-rn-version');
|
||||
@@ -27,8 +28,6 @@ const {
|
||||
const path = require('path');
|
||||
const yargs = require('yargs');
|
||||
|
||||
const REPO_ROOT = path.resolve(__dirname, '../..');
|
||||
|
||||
/**
|
||||
* This script prepares a release version of react-native and may publish to NPM.
|
||||
* It is supposed to run in CI environment, not on a developer's machine.
|
||||
|
||||
@@ -23,11 +23,10 @@ jest.mock('fs', () => ({
|
||||
}));
|
||||
jest.mock('./../update-template-package', () => updateTemplatePackageMock);
|
||||
|
||||
const {REPO_ROOT} = require('../../consts');
|
||||
const {setReactNativeVersion} = require('../set-rn-version');
|
||||
const path = require('path');
|
||||
|
||||
const REPO_ROOT = path.resolve(__filename, '../../../..');
|
||||
|
||||
describe('setReactNativeVersion', () => {
|
||||
beforeAll(() => {
|
||||
readFileMock.mockImplementation(filePath => {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
import type {BuildType, Version} from './utils/version-utils';
|
||||
*/
|
||||
|
||||
const {REPO_ROOT} = require('../consts');
|
||||
const {applyPackageVersions} = require('../npm-utils');
|
||||
const {getNpmInfo} = require('../npm-utils');
|
||||
const updateTemplatePackage = require('./update-template-package');
|
||||
@@ -21,7 +22,6 @@ const {parseArgs} = require('@pkgjs/parseargs');
|
||||
const {promises: fs} = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const REPO_ROOT = path.join(path.dirname(__filename), '..', '..');
|
||||
const GRADLE_FILE_PATH = path.join(
|
||||
REPO_ROOT,
|
||||
'packages/react-native/ReactAndroid/gradle.properties',
|
||||
|
||||
@@ -11,6 +11,11 @@
|
||||
const setVersion = require('../index');
|
||||
const path = require('path');
|
||||
|
||||
jest.mock('../../../consts', () => ({
|
||||
REPO_ROOT: path.join(__dirname, '__fixtures__'),
|
||||
PACKAGES_DIR: path.join(__dirname, '__fixtures__', 'packages'),
|
||||
}));
|
||||
|
||||
let customWriteFileExpect = null;
|
||||
const writeFileMock = jest.fn().mockImplementation((filePath, content) => {
|
||||
if (customWriteFileExpect != null) {
|
||||
@@ -32,15 +37,6 @@ describe('setVersion', () => {
|
||||
});
|
||||
|
||||
beforeAll(() => {
|
||||
jest.mock('path', () => {
|
||||
// $FlowIgnore[underconstrained-implicit-instantiation]
|
||||
const originalPath = jest.requireActual('path');
|
||||
return {
|
||||
...originalPath,
|
||||
dirname: () => originalPath.join(__dirname, '__fixtures__/two/levels'),
|
||||
};
|
||||
});
|
||||
|
||||
jest.mock('fs', () => {
|
||||
// $FlowIgnore[underconstrained-implicit-instantiation]
|
||||
const originalFs = jest.requireActual('fs');
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
* @oncall react_native
|
||||
*/
|
||||
|
||||
const {REPO_ROOT} = require('../../consts');
|
||||
const fs = require('fs');
|
||||
const glob = require('glob');
|
||||
const path = require('path');
|
||||
|
||||
const REPO_ROOT = path.resolve(__dirname, '../../..');
|
||||
const WORKSPACES_CONFIG = 'packages/*';
|
||||
|
||||
/*::
|
||||
|
||||
Reference in New Issue
Block a user