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

Conversation

huntie
Copy link
Member

@huntie huntie commented Aug 1, 2023

Summary:

NOTE: Replaces #38240

Context

RFC: Decoupling Flipper from React Native core: react-native-community/discussions-and-proposals#641

Changes

To support incoming new React Native packages around debugging (including migrating over @react-native-community/cli-plugin-metro) — which target Node.js and require a build step, this PR adds a minimal shared build setup across the react-native monorepo.

The setup is closely inspired/based on the build scripts in Jest, Metro, and React Native CLI — and is a simple set of script wrappers around Babel. These are available as build commands at the root of the repo:

  • yarn build — Builds all configured packages. Functionally, this:
    • Outputs a dist/ directory with built files.
    • Rewrites package.json "exports" to update every ./src/* reference to ./dist/* (source of truth).
  • scripts/build/babel-register.js — Allows running all Node.js entry points from source, similar to the current setup in facebook/metro. (Example entry point file in this PR: packages/dev-middleware/src/index.js)

Build configuration (i.e. Babel config) is shared as a set standard across the monorepo, and packages are opted-in to requiring a build, configured in scripts/build.config.js.

const buildConfig /*: BuildConfig */ = {
  // The packages to include for build and their build options
  packages: {
    'dev-middleware': {target: 'node'},
  },
};

For now, there is a single target: 'node' option — this is necessary as react-native, unlike the above other projects, is a repository with packages targeting several runtimes. We may, in future, introduce a build step for other, non-Node, packages — which may be useful for things such as auto-generated TypeScript definitions.

Differences from the Metro setup

  • References (and compiles out) repo-local scripts/build/babel-register.js — removing need for an npm-published dependency.

Current integration points

  • CircleCIyarn build is added to the build_npm_package and find_and_publish_bumped_packages jobs.

New Node.js package(s) are not load bearing quite yet: There are not yet any built packages added to the dependencies of packages/react-native/, so this will be further tested in a later PR (and is actively being done in an internal commit stack).

Alternative designs

Per-package config file

Replace scripts/build/config.js with a package-defined key in in package.json, similar to Jest's publishConfig.

"buildConfig": {
  "type": "node"
},

This would be the only customisation required, with a single Babel config still standardised. Another option this might receive in future is enableTypeScriptCodgeen.

Rollup

More sophisticated build tool for Node.js, used by the React codebase (albeit within a custom script setup as well).

Lerna and Nx

  • Most sophisticated setup enabling caching and optimised cloud runs.
  • Probably the most likely thing we'll move towards at a later stage.

Changelog: [Internal]

Differential Revision: D47760330

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner fb-exported labels Aug 1, 2023
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D47760330

@github-actions
Copy link

github-actions bot commented Aug 1, 2023

Warnings
⚠️ 🔒 package.json - Changes were made to package.json. This will require a manual import by a Facebook employee.

Generated by 🚫 dangerJS against d9f3a0e

huntie added a commit to huntie/react-native-website that referenced this pull request Aug 1, 2023
Removes mandatory run of `yarn build/watch` when developing Node.js packages — matching the updated build setup in facebook/react-native#38718 (these packages are now set up to run from source during development).

Partially reverts facebook#3788 "[docs] Add guidance on repo build scripts"
@analysis-bot
Copy link

analysis-bot commented Aug 1, 2023

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,894,554 -1
android hermes armeabi-v7a 7,943,106 -4
android hermes x86 9,292,438 -2
android hermes x86_64 9,193,963 -3
android jsc arm64-v8a 9,481,107 -1
android jsc armeabi-v7a 8,422,649 -1
android jsc x86 9,465,124 -1
android jsc x86_64 9,779,363 -3

Base commit: 0fb7163
Branch: main

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D47760330

huntie added a commit to huntie/react-native that referenced this pull request Aug 2, 2023
Summary:
Pull Request resolved: facebook#38718

> NOTE: Replaces facebook#38240

## Context

RFC: Decoupling Flipper from React Native core: react-native-community/discussions-and-proposals#641

## Changes

To support incoming new React Native packages around debugging (including migrating over [`react-native-community/cli-plugin-metro`](https://github.com/react-native-community/cli/tree/main/packages/cli-plugin-metro)) — which target Node.js and require a build step, this PR adds a minimal shared build setup across the `react-native` monorepo.

The setup is closely inspired/based on the build scripts in Jest, Metro, and React Native CLI — and is a simple set of script wrappers around Babel. These are available as build commands at the root of the repo:

- `yarn build` — Builds all configured packages. Functionally, this:
  - Outputs a `dist/` directory with built files.
  - Rewrites package.json `"exports"` to update every `./src/*` reference to `./dist/*` (source of truth).
- `scripts/build/babel-register.js` — Allows running all Node.js entry points from source, similar to the current setup in [facebook/metro](https://github.com/facebook/metro). (Example entry point file in this PR: `packages/dev-middleware/src/index.js`)

Build configuration (i.e. Babel config) is shared as a set standard across the monorepo, and **packages are opted-in to requiring a build**, configured in `scripts/build.config.js`.

```
const buildConfig /*: BuildConfig */ = {
  // The packages to include for build and their build options
  packages: {
    'dev-middleware': {target: 'node'},
  },
};
```

For now, there is a single `target: 'node'` option — this is necessary as `react-native`, unlike the above other projects, is a repository with packages targeting several runtimes. We may, in future, introduce a build step for other, non-Node, packages — which may be useful for things such as auto-generated TypeScript definitions.

 {F1043312771}

**Differences from the Metro setup**

- References (and compiles out) repo-local `scripts/build/babel-register.js` — removing need for an npm-published dependency.

## Current integration points

- **CircleCI** — `yarn build` is added to the `build_npm_package` and `find_and_publish_bumped_packages` jobs.

**New Node.js package(s) are not load bearing quite yet**: There are not yet any built packages added to the dependencies of `packages/react-native/`, so this will be further tested in a later PR (and is actively being done in an internal commit stack).

### Alternative designs

**Per-package config file**

Replace `scripts/build/config.js` with a package-defined key in in `package.json`, similar to Jest's [`publishConfig`](https://github.com/jestjs/jest/blob/1f019afdcdfc54a6664908bb45f343db4e3d0848/packages/jest-cli/package.json#L87C3-L89C4).

```
"buildConfig": {
  "type": "node"
},
```

This would be the only customisation required, with a single Babel config still standardised. Another option this might receive in future is `enableTypeScriptCodgeen`.

**Rollup**

More sophisticated build tool for Node.js, used by the React codebase (albeit within a custom script setup as well).

**Lerna and Nx**

- Most sophisticated setup enabling caching and optimised cloud runs.
- Probably the most likely thing we'll move towards at a later stage.

Changelog: [Internal]

Differential Revision: D47760330

fbshipit-source-id: 2c0128f7a3c54e222d3f640f8d2bf48264f23813
Summary:
Pull Request resolved: facebook#38718

> NOTE: Replaces facebook#38240

## Context

RFC: Decoupling Flipper from React Native core: react-native-community/discussions-and-proposals#641

## Changes

To support incoming new React Native packages around debugging (including migrating over [`react-native-community/cli-plugin-metro`](https://github.com/react-native-community/cli/tree/main/packages/cli-plugin-metro)) — which target Node.js and require a build step, this PR adds a minimal shared build setup across the `react-native` monorepo.

The setup is closely inspired/based on the build scripts in Jest, Metro, and React Native CLI — and is a simple set of script wrappers around Babel. These are available as build commands at the root of the repo:

- `yarn build` — Builds all configured packages. Functionally, this:
  - Outputs a `dist/` directory with built files.
  - Rewrites package.json `"exports"` to update every `./src/*` reference to `./dist/*` (source of truth).
- `scripts/build/babel-register.js` — Allows running all Node.js entry points from source, similar to the current setup in [facebook/metro](https://github.com/facebook/metro). (Example entry point file in this PR: `packages/dev-middleware/src/index.js`)

Build configuration (i.e. Babel config) is shared as a set standard across the monorepo, and **packages are opted-in to requiring a build**, configured in `scripts/build.config.js`.

```
const buildConfig /*: BuildConfig */ = {
  // The packages to include for build and their build options
  packages: {
    'dev-middleware': {target: 'node'},
  },
};
```

For now, there is a single `target: 'node'` option — this is necessary as `react-native`, unlike the above other projects, is a repository with packages targeting several runtimes. We may, in future, introduce a build step for other, non-Node, packages — which may be useful for things such as auto-generated TypeScript definitions.

 {F1043312771}

**Differences from the Metro setup**

- References (and compiles out) repo-local `scripts/build/babel-register.js` — removing need for an npm-published dependency.

## Current integration points

- **CircleCI** — `yarn build` is added to the `build_npm_package` and `find_and_publish_bumped_packages` jobs.

**New Node.js package(s) are not load bearing quite yet**: There are not yet any built packages added to the dependencies of `packages/react-native/`, so this will be further tested in a later PR (and is actively being done in an internal commit stack).

### Alternative designs

**Per-package config file**

Replace `scripts/build/config.js` with a package-defined key in in `package.json`, similar to Jest's [`publishConfig`](https://github.com/jestjs/jest/blob/1f019afdcdfc54a6664908bb45f343db4e3d0848/packages/jest-cli/package.json#L87C3-L89C4).

```
"buildConfig": {
  "type": "node"
},
```

This would be the only customisation required, with a single Babel config still standardised. Another option this might receive in future is `enableTypeScriptCodgeen`.

**Rollup**

More sophisticated build tool for Node.js, used by the React codebase (albeit within a custom script setup as well).

**Lerna and Nx**

- Most sophisticated setup enabling caching and optimised cloud runs.
- Probably the most likely thing we'll move towards at a later stage.

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D47760330

fbshipit-source-id: 456b506f9e50a43bae9bc902f36910253a0681e0
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D47760330

@github-actions
Copy link

github-actions bot commented Aug 3, 2023

This pull request was successfully merged by @huntie in cd8f5d1.

When will my fix make it into a release? | Upcoming Releases

@github-actions github-actions bot added the Merged This PR has been merged. label Aug 3, 2023
huntie added a commit to huntie/react-native that referenced this pull request Aug 14, 2023
Summary:
This PR adds auto-generation of Typescript definitions from Flow source code for packages using the shared monorepo build setup (facebook#38718).

Today, these are the following Node.js packages:

- `packages/community-cli-plugin`
- `packages/dev-middleware` (⬅️ `emitTypeScriptDefs` enabled)

This also improves emitted Flow definitions (`.js.flow`), by using [`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator) to strip implementations.

**All changes**

- Include `flow-api-translator` and configure this to emit type definitions as part of `yarn build`.
    - Add translation from Flow source to TypeScript definitions (`.d.ts`) adjacent to each built file.
    - Improve emitted Flow definitions (`.js.flow`), by using `flow-api-translator` to strip implementations (previously, source files were copied). The Flow and TS defs now mirror each other.
-  Add `emitFlowDefs` and `emitTypeScriptDefs` options to build config to configure the above.
- Integrate TypeScript compiler to perform program validation on emitted `.d.ts` files.
     - This is based on this guide: https://github.com/microsoft/TypeScript-wiki/blob/main/Using-the-Compiler-API.md#a-minimal-compiler.
- Throw an exception on the `rewritePackageExports` step if a package does not define an `"exports"` field.

**Notes on [`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator)**

This project is experimental but is in a more mature state than when we evaluated it earlier in 2023.
- It's now possible to run this tool on our new Node.js packages, since they are exclusively authored using `import`/`export` syntax (a requirement of the tool).
- As a safety net, we run the TypeScript compiler against the generated program, which will fail the build.

Changelog: [Internal]

Differential Revision: D48312463

fbshipit-source-id: bdf3e9be0e106f2fe7215fbff6a046fddfd36ae5
huntie added a commit to huntie/react-native that referenced this pull request Aug 14, 2023
Summary:
Pull Request resolved: facebook#38990

This PR adds auto-generation of Typescript definitions from Flow source code for packages using the shared monorepo build setup (facebook#38718).

Today, these are the following Node.js packages:

- `packages/community-cli-plugin`
- `packages/dev-middleware` (⬅️ `emitTypeScriptDefs` enabled)

This also improves emitted Flow definitions (`.js.flow`), by using [`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator) to strip implementations.

**All changes**

- Include `flow-api-translator` and configure this to emit type definitions as part of `yarn build`.
    - Add translation from Flow source to TypeScript definitions (`.d.ts`) adjacent to each built file.
    - Improve emitted Flow definitions (`.js.flow`), by using `flow-api-translator` to strip implementations (previously, source files were copied). The Flow and TS defs now mirror each other.
-  Add `emitFlowDefs` and `emitTypeScriptDefs` options to build config to configure the above.
- Integrate TypeScript compiler to perform program validation on emitted `.d.ts` files.
     - This is based on this guide: https://github.com/microsoft/TypeScript-wiki/blob/main/Using-the-Compiler-API.md#a-minimal-compiler.
- Throw an exception on the `rewritePackageExports` step if a package does not define an `"exports"` field.
- Add minimal `flow-typed` definitions for `typescript` 😄.

**Notes on [`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator)**

This project is experimental but is in a more mature state than when we evaluated it earlier in 2023.
- It's now possible to run this tool on our new Node.js packages, since they are exclusively authored using `import`/`export` syntax (a requirement of the tool).
- As a safety net, we run the TypeScript compiler against the generated program, which will fail the build.

Changelog: [Internal]

Differential Revision: D48312463

fbshipit-source-id: d53dc3f4fe6758a49cdb4759929a36de641d2a8d
huntie added a commit to huntie/react-native that referenced this pull request Aug 14, 2023
Summary:
Pull Request resolved: facebook#38990

This PR adds auto-generation of Typescript definitions from Flow source code for packages using the shared monorepo build setup (facebook#38718).

Today, these are the following Node.js packages:

- `packages/community-cli-plugin`
- `packages/dev-middleware` (⬅️ `emitTypeScriptDefs` enabled)

This also improves emitted Flow definitions (`.js.flow`), by using [`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator) to strip implementations.

**All changes**

- Include `flow-api-translator` and configure this to emit type definitions as part of `yarn build`.
    - Add translation from Flow source to TypeScript definitions (`.d.ts`) adjacent to each built file.
    - Improve emitted Flow definitions (`.js.flow`), by using `flow-api-translator` to strip implementations (previously, source files were copied). The Flow and TS defs now mirror each other.
-  Add `emitFlowDefs` and `emitTypeScriptDefs` options to build config to configure the above.
- Integrate TypeScript compiler to perform program validation on emitted `.d.ts` files.
     - This is based on this guide: https://github.com/microsoft/TypeScript-wiki/blob/main/Using-the-Compiler-API.md#a-minimal-compiler.
- Throw an exception on the `rewritePackageExports` step if a package does not define an `"exports"` field.
- Add minimal `flow-typed` definitions for `typescript` 😄.

**Notes on [`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator)**

This project is experimental but is in a more mature state than when we evaluated it earlier in 2023.
- It's now possible to run this tool on our new Node.js packages, since they are exclusively authored using `import`/`export` syntax (a requirement of the tool).
- As a safety net, we run the TypeScript compiler against the generated program, which will fail the build.

Changelog: [Internal]

Differential Revision: D48312463

fbshipit-source-id: f57bc22ff11d2eb13e8a45f1b8deedc130273420
huntie added a commit to huntie/react-native that referenced this pull request Aug 14, 2023
Summary:
Pull Request resolved: facebook#38990

This PR adds auto-generation of Typescript definitions from Flow source code for packages using the shared monorepo build setup (facebook#38718).

Today, these are the following Node.js packages:

- `packages/community-cli-plugin`
- `packages/dev-middleware` (⬅️ `emitTypeScriptDefs` enabled)

This also improves emitted Flow definitions (`.js.flow`), by using [`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator) to strip implementations.

**All changes**

- Include `flow-api-translator` and configure this to emit type definitions as part of `yarn build`.
    - Add translation from Flow source to TypeScript definitions (`.d.ts`) adjacent to each built file.
    - Improve emitted Flow definitions (`.js.flow`), by using `flow-api-translator` to strip implementations (previously, source files were copied). The Flow and TS defs now mirror each other.
-  Add `emitFlowDefs` and `emitTypeScriptDefs` options to build config to configure the above.
- Integrate TypeScript compiler to perform program validation on emitted `.d.ts` files.
     - This is based on this guide: https://github.com/microsoft/TypeScript-wiki/blob/main/Using-the-Compiler-API.md#a-minimal-compiler.
- Throw an exception on the `rewritePackageExports` step if a package does not define an `"exports"` field.
- Add minimal `flow-typed` definitions for `typescript` 😄.

**Notes on [`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator)**

This project is experimental but is in a more mature state than when we evaluated it earlier in 2023.
- It's now possible to run this tool on our new Node.js packages, since they are exclusively authored using `import`/`export` syntax (a requirement of the tool).
- As a safety net, we run the TypeScript compiler against the generated program, which will fail the build.

Changelog: [Internal]

Differential Revision: D48312463

fbshipit-source-id: 554ac6ed4990f279532524dd3f0ae936c19a6425
huntie added a commit to huntie/react-native that referenced this pull request Aug 14, 2023
Summary:
Pull Request resolved: facebook#38990

This PR adds auto-generation of Typescript definitions from Flow source code for packages using the shared monorepo build setup (facebook#38718).

Today, these are the following Node.js packages:

- `packages/community-cli-plugin`
- `packages/dev-middleware` (⬅️ `emitTypeScriptDefs` enabled)

This also improves emitted Flow definitions (`.js.flow`), by using [`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator) to strip implementations.

**All changes**

- Include `flow-api-translator` and configure this to emit type definitions as part of `yarn build`.
    - Add translation from Flow source to TypeScript definitions (`.d.ts`) adjacent to each built file.
    - Improve emitted Flow definitions (`.js.flow`), by using `flow-api-translator` to strip implementations (previously, source files were copied). The Flow and TS defs now mirror each other.
-  Add `emitFlowDefs` and `emitTypeScriptDefs` options to build config to configure the above.
- Integrate TypeScript compiler to perform program validation on emitted `.d.ts` files.
     - This is based on this guide: https://github.com/microsoft/TypeScript-wiki/blob/main/Using-the-Compiler-API.md#a-minimal-compiler.
- Throw an exception on the `rewritePackageExports` step if a package does not define an `"exports"` field.
- Add minimal `flow-typed` definitions for `typescript` 😄.

**Notes on [`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator)**

This project is experimental but is in a more mature state than when we evaluated it earlier in 2023.
- It's now possible to run this tool on our new Node.js packages, since they are exclusively authored using `import`/`export` syntax (a requirement of the tool).
- As a safety net, we run the TypeScript compiler against the generated program, which will fail the build.

Changelog: [Internal]

Differential Revision: D48312463

fbshipit-source-id: 69fd463ad625145c0455026d9a593d55dac1f1cf
huntie added a commit to huntie/react-native that referenced this pull request Aug 14, 2023
Summary:
Pull Request resolved: facebook#38990

This PR adds auto-generation of Typescript definitions from Flow source code for packages using the shared monorepo build setup (facebook#38718).

Today, these are the following Node.js packages:

- `packages/community-cli-plugin`
- `packages/dev-middleware` (⬅️ `emitTypeScriptDefs` enabled)

This also improves emitted Flow definitions (`.js.flow`), by using [`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator) to strip implementations.

**All changes**

- Include `flow-api-translator` and configure this to emit type definitions as part of `yarn build`.
    - Add translation from Flow source to TypeScript definitions (`.d.ts`) adjacent to each built file.
    - Improve emitted Flow definitions (`.js.flow`), by using `flow-api-translator` to strip implementations (previously, source files were copied). The Flow and TS defs now mirror each other.
-  Add `emitFlowDefs` and `emitTypeScriptDefs` options to build config to configure the above.
- Integrate TypeScript compiler to perform program validation on emitted `.d.ts` files.
     - This is based on this guide: https://github.com/microsoft/TypeScript-wiki/blob/main/Using-the-Compiler-API.md#a-minimal-compiler.
- Throw an exception on the `rewritePackageExports` step if a package does not define an `"exports"` field.
- Add minimal `flow-typed` definitions for `typescript` 😄.

**Notes on [`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator)**

This project is experimental but is in a more mature state than when we evaluated it earlier in 2023.
- It's now possible to run this tool on our new Node.js packages, since they are exclusively authored using `import`/`export` syntax (a requirement of the tool).
- As a safety net, we run the TypeScript compiler against the generated program, which will fail the build.

Changelog: [Internal]

Reviewed By: robhogan

Differential Revision: D48312463

fbshipit-source-id: 74a71615290512f9e830b9723f7cce01e75a7dc2
huntie added a commit to huntie/react-native that referenced this pull request Aug 14, 2023
Summary:
Pull Request resolved: facebook#38990

This PR adds auto-generation of Typescript definitions from Flow source code for packages using the shared monorepo build setup (facebook#38718).

Today, these are the following Node.js packages:

- `packages/community-cli-plugin`
- `packages/dev-middleware` (⬅️ `emitTypeScriptDefs` enabled)

This also improves emitted Flow definitions (`.js.flow`), by using [`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator) to strip implementations.

**All changes**

- Include `flow-api-translator` and configure this to emit type definitions as part of `yarn build`.
    - Add translation from Flow source to TypeScript definitions (`.d.ts`) adjacent to each built file.
    - Improve emitted Flow definitions (`.js.flow`), by using `flow-api-translator` to strip implementations (previously, source files were copied). The Flow and TS defs now mirror each other.
-  Add `emitFlowDefs` and `emitTypeScriptDefs` options to build config to configure the above.
- Integrate TypeScript compiler to perform program validation on emitted `.d.ts` files.
     - This is based on this guide: https://github.com/microsoft/TypeScript-wiki/blob/main/Using-the-Compiler-API.md#a-minimal-compiler.
- Throw an exception on the `rewritePackageExports` step if a package does not define an `"exports"` field.
- Add minimal `flow-typed` definitions for `typescript` 😄.

**Notes on [`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator)**

This project is experimental but is in a more mature state than when we evaluated it earlier in 2023.
- It's now possible to run this tool on our new Node.js packages, since they are exclusively authored using `import`/`export` syntax (a requirement of the tool).
- As a safety net, we run the TypeScript compiler against the generated program, which will fail the build.

Changelog: [Internal]

Reviewed By: robhogan

Differential Revision: D48312463

fbshipit-source-id: 1931654e3448e37463c4105b32f18225b2c9339f
huntie added a commit to huntie/react-native that referenced this pull request Aug 14, 2023
Summary:
Pull Request resolved: facebook#38990

This PR adds auto-generation of Typescript definitions from Flow source code for packages using the shared monorepo build setup (facebook#38718).

Today, these are the following Node.js packages:

- `packages/community-cli-plugin`
- `packages/dev-middleware` (⬅️ `emitTypeScriptDefs` enabled)

This also improves emitted Flow definitions (`.js.flow`), by using [`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator) to strip implementations.

**All changes**

- Include `flow-api-translator` and configure this to emit type definitions as part of `yarn build`.
    - Add translation from Flow source to TypeScript definitions (`.d.ts`) adjacent to each built file.
    - Improve emitted Flow definitions (`.js.flow`), by using `flow-api-translator` to strip implementations (previously, source files were copied). The Flow and TS defs now mirror each other.
-  Add `emitFlowDefs` and `emitTypeScriptDefs` options to build config to configure the above.
- Integrate TypeScript compiler to perform program validation on emitted `.d.ts` files.
     - This is based on this guide: https://github.com/microsoft/TypeScript-wiki/blob/main/Using-the-Compiler-API.md#a-minimal-compiler.
- Throw an exception on the `rewritePackageExports` step if a package does not define an `"exports"` field.
- Add minimal `flow-typed` definitions for `typescript` 😄.

**Notes on [`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator)**

This project is experimental but is in a more mature state than when we evaluated it earlier in 2023.
- It's now possible to run this tool on our new Node.js packages, since they are exclusively authored using `import`/`export` syntax (a requirement of the tool).
- As a safety net, we run the TypeScript compiler against the generated program, which will fail the build.

Changelog: [Internal]

Reviewed By: robhogan

Differential Revision: D48312463

fbshipit-source-id: 5ac8f3b054c313407c37dca060e0c5e77d112e9a
facebook-github-bot pushed a commit that referenced this pull request Aug 14, 2023
Summary:
Pull Request resolved: #38990

This PR adds auto-generation of Typescript definitions from Flow source code for packages using the shared monorepo build setup (#38718).

Today, these are the following Node.js packages:

- `packages/community-cli-plugin`
- `packages/dev-middleware` (⬅️ `emitTypeScriptDefs` enabled)

This also improves emitted Flow definitions (`.js.flow`), by using [`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator) to strip implementations.

**All changes**

- Include `flow-api-translator` and configure this to emit type definitions as part of `yarn build`.
    - Add translation from Flow source to TypeScript definitions (`.d.ts`) adjacent to each built file.
    - Improve emitted Flow definitions (`.js.flow`), by using `flow-api-translator` to strip implementations (previously, source files were copied). The Flow and TS defs now mirror each other.
-  Add `emitFlowDefs` and `emitTypeScriptDefs` options to build config to configure the above.
- Integrate TypeScript compiler to perform program validation on emitted `.d.ts` files.
     - This is based on this guide: https://github.com/microsoft/TypeScript-wiki/blob/main/Using-the-Compiler-API.md#a-minimal-compiler.
- Throw an exception on the `rewritePackageExports` step if a package does not define an `"exports"` field.
- Add minimal `flow-typed` definitions for `typescript` 😄.

**Notes on [`flow-api-translator`](https://www.npmjs.com/package/flow-api-translator)**

This project is experimental but is in a more mature state than when we evaluated it earlier in 2023.
- It's now possible to run this tool on our new Node.js packages, since they are exclusively authored using `import`/`export` syntax (a requirement of the tool).
- As a safety net, we run the TypeScript compiler against the generated program, which will fail the build.

Changelog: [Internal]

Reviewed By: robhogan

Differential Revision: D48312463

fbshipit-source-id: 817edb35f911f52fa987946f2d8fc1a319078c9d
@huntie huntie deleted the export-D47760330 branch August 29, 2023 16:15
huntie added a commit to huntie/react-native that referenced this pull request Sep 13, 2023
Summary:
Fixes running the `build.sh` script for `react-native-codegen` when on [EdenFS](https://github.com/facebook/sapling). This would previously fail due a filesystem "unable to copy extended attributes" error.

NOTE: The change from `mv` to `cp -R` makes this script more expensive, which will make Android builds via Gradle take slightly longer. I have a WIP cleanup planned which will 1/ move `react-native-codegen` to the [shared monorepo build setup](facebook#38718), and 2/ drop this step entirely from the Android Gradle build.

Differential Revision: D49230445
huntie added a commit to huntie/react-native that referenced this pull request Sep 20, 2023
Summary:

Fixes running the `build.sh` script for `react-native-codegen` when on [EdenFS](https://github.com/facebook/sapling). This would previously fail due a filesystem "unable to copy extended attributes" error.

NOTE: The change from `mv` to `cp -R` makes this script more expensive, which will make Android builds via Gradle take slightly longer. I have a WIP cleanup planned which will 1/ move `react-native-codegen` to the [shared monorepo build setup](facebook#38718), and 2/ drop this step entirely from the Android Gradle build.

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D49230445
huntie added a commit to huntie/react-native that referenced this pull request Sep 20, 2023
Summary:

This only affects development within the React Native monorepo. Practically, this equates to a workflow improvement for Meta engineers when creating `RNTester` builds.

Fixes running the `build.sh` script for `react-native-codegen` when on [EdenFS](https://github.com/facebook/sapling). This would previously fail due a filesystem "unable to copy extended attributes" error.

NOTE: The change from `mv` to `cp -R` makes this script more expensive, which will make Android builds via Gradle take slightly longer. I have a WIP cleanup planned which will 1/ move `react-native-codegen` to the [shared monorepo build setup](facebook#38718), and 2/ drop this step entirely from the Android Gradle build.

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D49230445
huntie added a commit to huntie/react-native that referenced this pull request Sep 20, 2023
Summary:
This only affects development within the React Native monorepo. Practically, this equates to a workflow improvement for Meta engineers when creating `RNTester` builds.

Fixes running the `build.sh` script for `react-native-codegen` when on [EdenFS](https://github.com/facebook/sapling). This would previously fail due a filesystem "unable to copy extended attributes" error.

NOTE: The change from `mv` to `cp -R` makes this script more expensive, which will make Android builds via Gradle take slightly longer. I have a WIP cleanup planned which will 1/ move `react-native-codegen` to the [shared monorepo build setup](facebook#38718), and 2/ drop this step entirely from the Android Gradle build.

Changelog: [Internal]

Differential Revision: D49468891
huntie added a commit to huntie/react-native that referenced this pull request Sep 20, 2023
Summary:

Fixes running the `build.sh` script for `react-native-codegen` when on [EdenFS](https://github.com/facebook/sapling). This would previously fail due a filesystem "unable to copy extended attributes" error.

This only affects development within the React Native monorepo. Practically, this equates to a workflow improvement for Meta engineers when creating `RNTester` builds.

NOTE: The change from `mv` to `cp -R` makes this script more expensive, which will make Android builds via Gradle take slightly longer. I have a WIP cleanup planned which will 1/ move `react-native-codegen` to the [shared monorepo build setup](facebook#38718), and 2/ drop this step entirely from the Android Gradle build.

Changelog: [Internal]

Differential Revision: D49468891
huntie added a commit to huntie/react-native that referenced this pull request Sep 21, 2023
Summary:

Fixes running the `build.sh` script for `react-native-codegen` when on [EdenFS](https://github.com/facebook/sapling). This would previously fail due a filesystem "unable to copy extended attributes" error.

This only affects development within the React Native monorepo. Practically, this equates to a workflow improvement for Meta engineers when creating `RNTester` builds.

NOTE: **This is temporary**. The change from `mv` to `cp -R` makes this script more expensive, which will make Android builds via Gradle take slightly longer. I have a WIP cleanup planned which will 1/ move `react-native-codegen` to the [shared monorepo build setup](facebook#38718), and 2/ drop this step entirely from the Android Gradle build.

Changelog: [Internal]

Reviewed By: christophpurrer

Differential Revision: D49468891
huntie added a commit to huntie/react-native that referenced this pull request Sep 21, 2023
Summary:

Fixes running the `build.sh` script for `react-native-codegen` when on [EdenFS](https://github.com/facebook/sapling). This would previously fail due a filesystem "unable to copy extended attributes" error.

This only affects development within the React Native monorepo. Practically, this equates to a workflow improvement for Meta engineers when creating `RNTester` builds.

NOTE: **This is temporary**. The change from `mv` to `cp -R` makes this script more expensive, which will make Android builds via Gradle take slightly longer. I have a WIP cleanup planned which will 1/ move `react-native-codegen` to the [shared monorepo build setup](facebook#38718), and 2/ drop this step entirely from the Android Gradle build.

Changelog: [Internal]

Reviewed By: christophpurrer

Differential Revision: D49468891
huntie added a commit to huntie/react-native that referenced this pull request Sep 21, 2023
Summary:

Fixes running the `build.sh` script for `react-native-codegen` when on [EdenFS](https://github.com/facebook/sapling). This would previously fail due a filesystem "unable to copy extended attributes" error.

This only affects development within the React Native monorepo. Practically, this equates to a workflow improvement for Meta engineers when creating `RNTester` builds.

NOTE: **This is temporary**. The change from `mv` to `cp -R` makes this script more expensive, which will make Android builds via Gradle take slightly longer. I have a WIP cleanup planned which will 1/ move `react-native-codegen` to the [shared monorepo build setup](facebook#38718), and 2/ drop this step entirely from the Android Gradle build.

Changelog: [Internal]

Reviewed By: christophpurrer

Differential Revision: D49468891
huntie added a commit to huntie/react-native that referenced this pull request Sep 21, 2023
Summary:
This only affects development within the React Native monorepo. Practically, this equates to a workflow improvement for Meta engineers when creating `RNTester` builds.

Fixes running the `build.sh` script for `react-native-codegen` when on [EdenFS](https://github.com/facebook/sapling). This would previously fail due a filesystem "unable to copy extended attributes" error.

NOTE: The change from `mv` to `cp -R` makes this script more expensive, which will make Android builds via Gradle take slightly longer. I have a WIP cleanup planned which will 1/ move `react-native-codegen` to the [shared monorepo build setup](facebook#38718), and 2/ drop this step entirely from the Android Gradle build.

Changelog: [Internal]

Differential Revision: D49468891

fbshipit-source-id: 0ce0c1100825ad368bf20bdd317f92c7db15b25d
facebook-github-bot pushed a commit that referenced this pull request Sep 21, 2023
Summary:
Pull Request resolved: #39566

Fixes running the `build.sh` script for `react-native-codegen` when on [EdenFS](https://github.com/facebook/sapling). This would previously fail due a filesystem "unable to copy extended attributes" error.

This only affects development within the React Native monorepo. Practically, this equates to a workflow improvement for Meta engineers when creating `RNTester` builds.

NOTE: **This is temporary**. The change from `mv` to `cp -R` makes this script more expensive, which will make Android builds via Gradle take slightly longer. I have a WIP cleanup planned which will 1/ move `react-native-codegen` to the [shared monorepo build setup](#38718), and 2/ drop this step entirely from the Android Gradle build.

Changelog: [Internal]

Reviewed By: christophpurrer

Differential Revision: D49468891

fbshipit-source-id: 25d5db81798cf8ab150a135174a45f4d4c2cb5a2
ShevO27 pushed a commit to ShevO27/react-native that referenced this pull request Sep 26, 2023
Summary:
Pull Request resolved: facebook#39566

Fixes running the `build.sh` script for `react-native-codegen` when on [EdenFS](https://github.com/facebook/sapling). This would previously fail due a filesystem "unable to copy extended attributes" error.

This only affects development within the React Native monorepo. Practically, this equates to a workflow improvement for Meta engineers when creating `RNTester` builds.

NOTE: **This is temporary**. The change from `mv` to `cp -R` makes this script more expensive, which will make Android builds via Gradle take slightly longer. I have a WIP cleanup planned which will 1/ move `react-native-codegen` to the [shared monorepo build setup](facebook#38718), and 2/ drop this step entirely from the Android Gradle build.

Changelog: [Internal]

Reviewed By: christophpurrer

Differential Revision: D49468891

fbshipit-source-id: 25d5db81798cf8ab150a135174a45f4d4c2cb5a2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants