Skip to content

Commit

Permalink
fix: warn when copyFlow is specified without flow-bin in devDependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Jul 19, 2023
1 parent 1902e5f commit a63a9ee
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/react-native-builder-bob/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ yargs
output,
targets: targets.map((t: string) => {
if (t === target && flow) {
return [t, { flow }];
return [t, { copyFlow: true }];
}

return t;
Expand Down
10 changes: 5 additions & 5 deletions packages/react-native-builder-bob/src/targets/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ export default async function build({
`Wrote definition files to ${kleur.blue(path.relative(root, output))}`
);

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

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

const typesPath = path.join(root, packageJson.types);
const typesPath = path.join(root, pkg.types);

if (!(await fs.pathExists(typesPath))) {
report.error(
`The ${kleur.blue('types')} field in ${kleur.blue(
'package.json'
)} points to a non-existent file: ${kleur.blue(
packageJson.types
pkg.types
)}.\nVerify the path points to the correct file under ${kleur.blue(
path.relative(root, output)
)}.`
Expand Down
34 changes: 27 additions & 7 deletions packages/react-native-builder-bob/src/utils/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,30 @@ export default async function compile({
)} with ${kleur.blue('babel')}`
);

const pkg = JSON.parse(
await fs.readFile(path.join(root, 'package.json'), 'utf-8')
);

if (copyFlow) {
if (!Object.keys(pkg.devDependencies || {}).includes('flow-bin')) {
report.warn(
`The ${kleur.blue(
'copyFlow'
)} option was specified, but couldn't find ${kleur.blue(
'flow-bin'
)} in ${kleur.blue(
'package.json'
)}.\nIf the project is using ${kleur.blue(
'flow'
)}, then make sure you have added ${kleur.blue(
'flow-bin'
)} to your ${kleur.blue(
'devDependencies'
)}, otherwise remove the ${kleur.blue('copyFlow')} option.`
);
}
}

await Promise.all(
files.map(async (filepath) => {
const outputFilename = path
Expand Down Expand Up @@ -123,13 +147,9 @@ export default async function compile({

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

const packageJson = JSON.parse(
await fs.readFile(path.join(root, 'package.json'), 'utf-8')
);

if (field in packageJson) {
if (field in pkg) {
try {
require.resolve(path.join(root, packageJson[field]));
require.resolve(path.join(root, pkg[field]));
} catch (e: unknown) {
if (
e != null &&
Expand All @@ -141,7 +161,7 @@ export default async function compile({
`The ${kleur.blue(field)} field in ${kleur.blue(
'package.json'
)} points to a non-existent file: ${kleur.blue(
packageJson[field]
pkg[field]
)}.\nVerify the path points to the correct file under ${kleur.blue(
path.relative(root, output)
)}.`
Expand Down

0 comments on commit a63a9ee

Please sign in to comment.