Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shared monorepo build setup #38718

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ commands:
- ~/.cache/yarn
key: << parameters.yarn_base_cache_key >>-{{ arch }}-{{ checksum "yarn.lock" }}

build_packages:
steps:
- run:
name: Build packages
command: yarn build

brew_install:
parameters:
package:
Expand Down Expand Up @@ -1775,6 +1781,7 @@ jobs:
cp $HERMES_WS_DIR/hermes-runtime-darwin/hermes-ios-release.tar.gz ./packages/react-native/ReactAndroid/external-artifacts/artifacts/hermes-ios-release.tar.gz
- run_yarn
- build_packages
- download_gradle_dependencies

# START: Stables and nightlies
Expand Down Expand Up @@ -1870,6 +1877,7 @@ jobs:
steps:
- checkout
- run_yarn
- build_packages
- run:
name: Set NPM auth token
command: echo "//registry.npmjs.org/:_authToken=${CIRCLE_NPM_TOKEN}" > ~/.npmrc
Expand Down
40 changes: 40 additions & 0 deletions flow-typed/npm/parseargs_v0.11.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* 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
*/

declare module '@pkgjs/parseargs' {
declare type ParseArgsOptionConfig = {
type: 'string' | 'boolean',
short?: string,
multiple?: boolean,
};

declare type ParseArgsOptionsConfig = {
[longOption: string]: ParseArgsOptionConfig,
};

declare export type ParseArgsConfig = {
strict?: boolean,
allowPositionals?: boolean,
tokens?: boolean,
options?: ParseArgsOptionsConfig,
args?: string[],
};

declare type ParsedResults = {
values: {
[longOption: string]: void | string | boolean | Array<string | boolean>,
},
positionals: string[],
...
};

declare export function parseArgs(config: ParseArgsConfig): ParsedResults;
}
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"scripts": {
"start": "cd packages/rn-tester && npm run start",
"android": "cd packages/rn-tester && npm run android",
"build": "node ./scripts/build/build.js",
"clean": "node ./scripts/build/clean.js",
"test": "jest",
"test-ci": "jest --maxWorkers=2 --ci --reporters=\"default\" --reporters=\"jest-junit\"",
"flow": "flow",
Expand Down Expand Up @@ -45,14 +47,20 @@
"@babel/eslint-parser": "^7.20.0",
"@babel/generator": "^7.20.0",
"@babel/plugin-transform-regenerator": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@babel/preset-flow": "^7.20.0",
"@definitelytyped/dtslint": "^0.0.127",
"@jest/create-cache-key-function": "^29.2.1",
"@pkgjs/parseargs": "^0.11.0",
"@react-native/metro-babel-transformer": "^0.73.11",
"@react-native/metro-config": "^0.73.0",
"@types/react": "^18.0.18",
"@typescript-eslint/parser": "^5.57.1",
"async": "^3.2.2",
"babel-plugin-minify-dead-code-elimination": "^0.5.2",
"babel-plugin-transform-define": "^2.1.2",
"babel-plugin-transform-flow-enums": "^0.0.2",
"chalk": "^4.0.0",
"clang-format": "^1.8.0",
"connect": "^3.6.5",
"eslint": "^8.19.0",
Expand All @@ -70,13 +78,15 @@
"eslint-plugin-redundant-undefined": "^0.4.0",
"eslint-plugin-relay": "^1.8.3",
"flow-bin": "^0.213.1",
"glob": "^7.1.1",
"hermes-eslint": "0.15.0",
"inquirer": "^7.1.0",
"jest": "^29.2.1",
"jest-junit": "^10.0.0",
"jscodeshift": "^0.14.0",
"metro-babel-register": "0.77.0",
"metro-memory-fs": "0.77.0",
"micromatch": "^4.0.4",
"mkdirp": "^0.5.1",
"mock-fs": "^5.1.4",
"prettier": "2.8.8",
Expand Down
13 changes: 0 additions & 13 deletions packages/dev-middleware/.babelrc

This file was deleted.

2 changes: 1 addition & 1 deletion packages/dev-middleware/index.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +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
* @flow
* @format
* @oncall react_native
*/
Expand Down
18 changes: 4 additions & 14 deletions packages/dev-middleware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,19 @@
"directory": "packages/dev-middleware"
},
"license": "MIT",
"exports": "./dist/index.js",
"exports": {
".": "./src/index.js",
"./package.json": "./package.json"
},
"files": [
"dist"
],
"scripts": {
"build": "yarn clean && babel src --out-dir dist",
"dev": "babel src --out-dir dist --source-maps --watch",
"clean": "rimraf dist",
"prepare": "yarn build"
},
"dependencies": {
"chrome-launcher": "^0.15.2",
"connect": "^3.6.5",
"node-fetch": "^2.2.0",
"temp-dir": "^2.0.0"
},
"devDependencies": {
"@babel/cli": "^7.20.0",
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@babel/preset-flow": "^7.20.0",
"rimraf": "^3.0.2"
},
"engines": {
"node": ">=18"
}
Expand Down
12 changes: 12 additions & 0 deletions packages/dev-middleware/src/index.flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* 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
*/

export {default as createDevMiddleware} from './createDevMiddleware';
12 changes: 10 additions & 2 deletions packages/dev-middleware/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @flow
* @format
* @oncall react_native
*/

export {default as createDevMiddleware} from './createDevMiddleware';
/*::
export type * from './index.flow';
*/

if (!process.env.BUILD_EXCLUDE_BABEL_REGISTER) {
require('../../../scripts/build/babel-register').registerForMonorepo();
}

module.exports = require('./index.flow');
54 changes: 54 additions & 0 deletions scripts/build/babel-register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* 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
* @format
* @oncall react_native
*/

const path = require('path');
const {PACKAGES_DIR} = require('./build');
const {buildConfig, getBabelConfig} = require('./config');

let isRegisteredForMonorepo = false;

/**
* Calling this function enables all Node.js packages to run from source when
* developing in the React Native repo.
*
* A call should located in each entry point file in a package (i.e. for all
* paths in "exports"), inside a special `if` condition that will be compiled
* away on build.
*
* if (!process.env.BUILD_EXCLUDE_BABEL_REGISTER) {
* require('../../../scripts/build/babel-register').registerForMonorepo();
* }
*/
function registerForMonorepo() {
if (isRegisteredForMonorepo) {
return;
}

for (const [packageName, {target}] of Object.entries(buildConfig.packages)) {
if (target === 'node') {
registerPackage(packageName);
}
}

isRegisteredForMonorepo = true;
}

function registerPackage(packageName /*: string */) {
const packageDir = path.join(PACKAGES_DIR, packageName);

require('@babel/register')({
...getBabelConfig(packageName),
root: packageDir,
ignore: [/\/node_modules\//],
});
}

module.exports = {registerForMonorepo};
Loading