Skip to content

Commit

Permalink
fix: read source directory from bob config
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Jul 27, 2024
1 parent be426bb commit 77df6cd
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions packages/react-native-builder-bob/babel-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* eslint-disable import/no-commonjs */

const path = require('path');
const { cosmiconfigSync } = require('cosmiconfig');
const { lstatSync } = require('fs');
const { name } = require('./package.json');

/**
* Get Babel configuration for the example project.
Expand All @@ -14,22 +17,28 @@ const path = require('path');
* @returns {import('@babel/core').TransformOptions} Babel configuration
*/
const getConfig = (defaultConfig, { root, pkg }) => {
let src;
const explorer = cosmiconfigSync(name, {
stopDir: root,
searchPlaces: ['package.json', 'bob.config.cjs', 'bob.config.js'],
});

if (pkg.source.includes('/')) {
const segments = pkg.source.split('/');

if (segments[0] === '.') {
segments.shift();
}

src = segments[0];
}
const result = explorer.search();
const src = result ? result.config.source : null;

if (src == null) {
throw new Error(
"Couldn't determine the source directory. Does the 'source' field in your 'package.json' point to a file within a directory?"
);
if (
lstatSync(path.join(root, 'bob.config.mjs'), {
throwIfNoEntry: false,
}).isFile()
) {
throw new Error(
"Found a 'bob.config.mjs' file. However, ESM syntax is currently not supported for the Babel configuration."
);
} else {
throw new Error(
"Couldn't determine the source directory. Does your config specify a 'source' field?"
);
}
}

return {
Expand Down

0 comments on commit 77df6cd

Please sign in to comment.