Skip to content

Commit a63a9ee

Browse files
committed
fix: warn when copyFlow is specified without flow-bin in devDependencies
1 parent 1902e5f commit a63a9ee

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

packages/react-native-builder-bob/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ yargs
285285
output,
286286
targets: targets.map((t: string) => {
287287
if (t === target && flow) {
288-
return [t, { flow }];
288+
return [t, { copyFlow: true }];
289289
}
290290

291291
return t;

packages/react-native-builder-bob/src/targets/typescript.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ export default async function build({
194194
`Wrote definition files to ${kleur.blue(path.relative(root, output))}`
195195
);
196196

197-
const packageJson = JSON.parse(
197+
const pkg = JSON.parse(
198198
await fs.readFile(path.join(root, 'package.json'), 'utf-8')
199199
);
200200

201-
if ('types' in packageJson) {
202-
if (!packageJson.types.endsWith('.d.ts')) {
201+
if ('types' in pkg) {
202+
if (!pkg.types.endsWith('.d.ts')) {
203203
report.error(
204204
`The ${kleur.blue('types')} field in ${kleur.blue(
205205
'package.json'
@@ -211,14 +211,14 @@ export default async function build({
211211
throw new Error("Found incorrect path in 'types' field.");
212212
}
213213

214-
const typesPath = path.join(root, packageJson.types);
214+
const typesPath = path.join(root, pkg.types);
215215

216216
if (!(await fs.pathExists(typesPath))) {
217217
report.error(
218218
`The ${kleur.blue('types')} field in ${kleur.blue(
219219
'package.json'
220220
)} points to a non-existent file: ${kleur.blue(
221-
packageJson.types
221+
pkg.types
222222
)}.\nVerify the path points to the correct file under ${kleur.blue(
223223
path.relative(root, output)
224224
)}.`

packages/react-native-builder-bob/src/utils/compile.ts

+27-7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,30 @@ export default async function compile({
4040
)} with ${kleur.blue('babel')}`
4141
);
4242

43+
const pkg = JSON.parse(
44+
await fs.readFile(path.join(root, 'package.json'), 'utf-8')
45+
);
46+
47+
if (copyFlow) {
48+
if (!Object.keys(pkg.devDependencies || {}).includes('flow-bin')) {
49+
report.warn(
50+
`The ${kleur.blue(
51+
'copyFlow'
52+
)} option was specified, but couldn't find ${kleur.blue(
53+
'flow-bin'
54+
)} in ${kleur.blue(
55+
'package.json'
56+
)}.\nIf the project is using ${kleur.blue(
57+
'flow'
58+
)}, then make sure you have added ${kleur.blue(
59+
'flow-bin'
60+
)} to your ${kleur.blue(
61+
'devDependencies'
62+
)}, otherwise remove the ${kleur.blue('copyFlow')} option.`
63+
);
64+
}
65+
}
66+
4367
await Promise.all(
4468
files.map(async (filepath) => {
4569
const outputFilename = path
@@ -123,13 +147,9 @@ export default async function compile({
123147

124148
report.success(`Wrote files to ${kleur.blue(path.relative(root, output))}`);
125149

126-
const packageJson = JSON.parse(
127-
await fs.readFile(path.join(root, 'package.json'), 'utf-8')
128-
);
129-
130-
if (field in packageJson) {
150+
if (field in pkg) {
131151
try {
132-
require.resolve(path.join(root, packageJson[field]));
152+
require.resolve(path.join(root, pkg[field]));
133153
} catch (e: unknown) {
134154
if (
135155
e != null &&
@@ -141,7 +161,7 @@ export default async function compile({
141161
`The ${kleur.blue(field)} field in ${kleur.blue(
142162
'package.json'
143163
)} points to a non-existent file: ${kleur.blue(
144-
packageJson[field]
164+
pkg[field]
145165
)}.\nVerify the path points to the correct file under ${kleur.blue(
146166
path.relative(root, output)
147167
)}.`

0 commit comments

Comments
 (0)