11/* eslint-disable import/no-commonjs */
22
33const path = require ( 'path' ) ;
4- const { cosmiconfigSync } = require ( 'cosmiconfig' ) ;
5- const { lstatSync } = require ( 'fs' ) ;
6- const { name } = require ( './package.json' ) ;
4+ const { loadConfig } = require ( './lib/utils/loadConfig' ) ;
75
86/**
97 * Get Babel configuration for the example project.
@@ -17,28 +15,18 @@ const { name } = require('./package.json');
1715 * @returns {import('@babel/core').TransformOptions } Babel configuration
1816 */
1917const getConfig = ( defaultConfig , { root, pkg } ) => {
20- const explorer = cosmiconfigSync ( name , {
21- stopDir : root ,
22- searchPlaces : [ 'package.json' , 'bob.config.cjs' , 'bob.config.js' ] ,
23- } ) ;
18+ const result = loadConfig ( root ) ;
2419
25- const result = explorer . search ( ) ;
26- const src = result ? result . config . source : null ;
20+ if ( result == null ) {
21+ throw new Error ( "Couldn't find a valid configuration." ) ;
22+ }
23+
24+ const { source } = result . config ;
2725
28- if ( src == null ) {
29- if (
30- lstatSync ( path . join ( root , 'bob.config.mjs' ) , {
31- throwIfNoEntry : false ,
32- } ) . isFile ( )
33- ) {
34- throw new Error (
35- "Found a 'bob.config.mjs' file. However, ESM syntax is currently not supported for the Babel configuration."
36- ) ;
37- } else {
38- throw new Error (
39- "Couldn't determine the source directory. Does your config specify a 'source' field?"
40- ) ;
41- }
26+ if ( source == null ) {
27+ throw new Error (
28+ "Couldn't determine the source directory. Does your config specify a 'source' field?"
29+ ) ;
4230 }
4331
4432 return {
@@ -60,7 +48,7 @@ const getConfig = (defaultConfig, { root, pkg }) => {
6048 ] ,
6149 } ,
6250 {
63- include : path . join ( root , src ) ,
51+ include : path . join ( root , source ) ,
6452 presets : [
6553 [
6654 require . resolve ( './babel-preset' ) ,
0 commit comments