Skip to content

Commit 141e021

Browse files
huntiemeta-codesync[bot]
authored andcommitted
Add --prepack flag to build script (#55415)
Summary: Pull Request resolved: #55415 Add optional flag to JS build setup that includes running the `"prepack"` script step after build — allowing the net behaviour before #54857 to be conveninently switched to if needed. This is motivated by fixing our internal CI action for `xplat/js/react-native-github/scripts/debugger-shell/build-binary.js` — which depends on a locally built + package.json-written package state (the latter of which no longer happened for `yarn build` by default). Changelog: [Internal] Reviewed By: vzaidman Differential Revision: D92395174 fbshipit-source-id: 28806b3f3872306f2529d4bb5870acde584caf10
1 parent 2e12cbd commit 141e021

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

scripts/build/build.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const {
1818
getTypeScriptCompilerOptions,
1919
} = require('./config');
2020
const babel = require('@babel/core');
21+
const {spawn} = require('child_process');
2122
const translate = require('flow-api-translator');
2223
const {promises: fs} = require('fs');
2324
const micromatch = require('micromatch');
@@ -35,6 +36,7 @@ const IGNORE_PATTERN = '**/__{tests,mocks,fixtures}__/**';
3536
const config = {
3637
allowPositionals: true,
3738
options: {
39+
prepack: {type: 'boolean'},
3840
validate: {type: 'boolean'},
3941
help: {type: 'boolean'},
4042
},
@@ -43,7 +45,7 @@ const config = {
4345
async function build() {
4446
const {
4547
positionals: packageNames,
46-
values: {validate, help},
48+
values: {prepack, validate, help},
4749
/* $FlowFixMe[incompatible-type] Natural Inference rollout. See
4850
* https://fburl.com/workplace/6291gfvu */
4951
} = parseArgs(config);
@@ -58,6 +60,9 @@ async function build() {
5860
a package list is provided, builds only those specified.
5961
6062
Options:
63+
--prepack Run the ./prepack.js script after building, applying
64+
package.json "publishConfig" changes to the working copy.
65+
This is usually run before npm publish.
6166
--validate Validate that no build artifacts have been accidentally
6267
committed.
6368
`);
@@ -80,7 +85,7 @@ async function build() {
8085
if (validate) {
8186
ok &&= await checkPackage(packageName);
8287
} else {
83-
await buildPackage(packageName);
88+
await buildPackage(packageName, prepack);
8489
}
8590
}
8691

@@ -98,7 +103,7 @@ async function checkPackage(packageName /*: string */) /*: Promise<boolean> */ {
98103
return true;
99104
}
100105

101-
async function buildPackage(packageName /*: string */) {
106+
async function buildPackage(packageName /*: string */, prepack /*: boolean */) {
102107
try {
103108
const {emitTypeScriptDefs} = getBuildOptions(packageName);
104109
const entryPoints = await getEntryPoints(packageName);
@@ -136,6 +141,24 @@ async function buildPackage(packageName /*: string */) {
136141
validateTypeScriptDefs(packageName);
137142
}
138143

144+
// Run prepack script if configured
145+
if (prepack) {
146+
await new Promise((resolve, reject) => {
147+
const child = spawn('npm', ['run', 'prepack'], {
148+
cwd: path.resolve(PACKAGES_DIR, packageName),
149+
stdio: ['ignore', 'ignore', 'inherit'],
150+
});
151+
child.on('close', code => {
152+
if (code !== 0) {
153+
reject(new Error(`prepack script exited with code ${code}`));
154+
} else {
155+
resolve();
156+
}
157+
});
158+
child.on('error', reject);
159+
});
160+
}
161+
139162
process.stdout.write(
140163
styleText(['reset', 'inverse', 'bold', 'green'], ' DONE '),
141164
);

0 commit comments

Comments
 (0)