You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Move JavaScript exports rewrites to publishConfig/prepack (#54857)
Summary:
### Motivation
Updates the shared JavaScript build setup to use the modern `publishConfig` convention.
This:
- Simplifies the build script.
- Makes the production values for `"exports"` more understandable in place (especially by separating from exports conditions).
- Prevents us from creating a dirty file state when running `yarn build`.
### Changes
- Add `publishConfig` to each `package.json` listing production `"exports"` targets.
- Add `scripts/build/prepack.js` script to action `publishConfig` (now on `npm pack`, `npm publish` exclusively).
- Remove `"exports"` rewriting (and un-rewriting safeguards) from build script.
**Note on `"prepack"`**
Slightly unfortunately, `publishConfig` doesn't work consistently between package managers currently, including npm — so this does not work implicitly (but may in future).
We're instead following `publishConfig` as a convention, and explicitly implementing a full copy (theoretically forking us towards pnpm and Yarn v4's approach).
However, I believe this is:
- Worthwhile, for the motivations above — and in particular being able to understand the final shape of `"exports"` (independent from the dimension of conditional exports, which may come into play later).
- Completely inspectable/maintainable as an explicit implementation (`scripts/build/prepack.js`).
Changelog: [Internal]
Pull Request resolved: #54857
Test Plan:
### CI
✅ GitHub Actions
### End-to-end release test script
(Note: Rebased on `0.83-stable` when tested)
```
yarn test-release-local -t "RNTestProject" -p "iOS" -c $GITHUB_TOKEN
```
{F1984106139}
✅ Test script runs `npm publish` on packages to a local proxy.
{F1984106146}
✅ Installed packages have `publishConfig` `"exports"` values applied
NOTE: ⬆️ This is **exactly** the same output as before.
{F1984106148}
✅ `/tmp/RNTestProject` runs using built + proxy-published + proxy-installed packages
Reviewed By: cipolleschi
Differential Revision: D88963450
Pulled By: huntie
fbshipit-source-id: f328252cf93a1f1039b79d7f369d1e6e7e5b4b52
Copy file name to clipboardExpand all lines: scripts/build/README.md
+3-14Lines changed: 3 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,14 +17,6 @@ These scripts form the modern build setup for JavaScript ([Flow](https://flow.or
17
17
-**When does the build run?**
18
18
- Packages are built in CI workflows — both for integration/E2E tests, and before publishing to npm.
19
19
20
-
#### Limitations/quirks
21
-
22
-
> [!Note]
23
-
> **🚧 Work in progress!** This is not the final state for our monorepo build tooling. Unfortunately, our solution options are narrow due to integration requirements with Meta's codebase.
24
-
25
-
- Running `yarn build` will mutate `package.json` files in place, resulting in a dirty Git working copy.
26
-
- We make use of "wrapper files" (`.js` → `.js.flow`) for each package entry point, to enable running from source with zero config. To validate these, package entry points must be explicitly defined via `"exports"`.
27
-
28
20
## Usage
29
21
30
22
**💡 Reminder**: 99% of the time, there is no need to use `yarn build`, as all packages will run from source during development.
@@ -44,9 +36,6 @@ yarn clean
44
36
45
37
Once built, developing in the monorepo should continue to work — now using the compiled version of each package.
46
38
47
-
> [!Warning]
48
-
> **Build changes should not be committed**. Currently, `yarn build` will make changes to each `package.json` file, which should not be committed. This is validated in CI.
49
-
50
39
## Configuration
51
40
52
41
Monorepo packages must be opted in for build, configured in `config.js` (where build options are also documented).
@@ -77,6 +66,7 @@ packages/
77
66
78
67
Notes:
79
68
69
+
- We make use of "wrapper files" (`.js` → `.js.flow`) for each package entry point, to enable running from source with zero config. To validate these, package entry points must be explicitly defined via `"exports"`.
80
70
- To minimize complexity, prefer only a single entry of `{".":"src/index.js"}` in `"exports"` for new packages.
81
71
82
72
## Build behavior
@@ -85,8 +75,7 @@ Running `yarn build` will compile each package following the below steps, depend
85
75
86
76
- Create a `dist/` directory, replicating each source file under `src/`:
87
77
- For every `@flow` file, strip Flow annotations using [flow-api-extractor](https://www.npmjs.com/package/flow-api-translator).
88
-
- For every entry point in `"exports"`, remove the `.js` wrapper file and compile from the `.flow.js` source.
89
-
- Rewrite each package `"exports"` target to map to the `dist/` directory location.
78
+
- For each entry point in `"exports"`, remove the `.js` wrapper file and compile from the `.flow.js` source.
90
79
- If configured, emit a Flow (`.js.flow`) or TypeScript (`.d.ts`) type definition file per source file, using [flow-api-extractor](https://www.npmjs.com/package/flow-api-translator).
0 commit comments