@@ -15,12 +15,13 @@ pub fn from_javascript_path(file_path: &Path) -> Result<Rcfile, RcfileError> {
1515 let nodejs_script = format ! (
1616 r#"
1717 import('{escaped_file_path_for_nodejs}')
18- .then((mod) => mod.default )
18+ .then(findConfig )
1919 .then((value) => {{
2020 if (isNonEmptyObject(value)) {{
2121 console.log(JSON.stringify({{
2222 _tag: 'Ok',
23- value,
23+ value: JSON.stringify(value),
24+ source: 'import',
2425 }}));
2526 }} else {{
2627 tryRequire('Config expected at default export');
@@ -33,12 +34,13 @@ pub fn from_javascript_path(file_path: &Path) -> Result<Rcfile, RcfileError> {
3334 function tryRequire(importError) {{
3435 Promise.resolve(null)
3536 .then(() => require('{escaped_file_path_for_nodejs}'))
36- .then((mod) => mod.default || mod )
37+ .then(findConfig )
3738 .then((value) => {{
3839 if (isNonEmptyObject(value)) {{
3940 console.log(JSON.stringify({{
4041 _tag: 'Ok',
41- value,
42+ value: JSON.stringify(value),
43+ source: 'require',
4244 }}));
4345 }} else {{
4446 console.log(JSON.stringify({{
@@ -60,6 +62,10 @@ pub fn from_javascript_path(file_path: &Path) -> Result<Rcfile, RcfileError> {
6062 function isNonEmptyObject(value) {{
6163 return value && typeof value === 'object' && value.constructor === Object && Object.keys(value).length > 0;
6264 }}
65+
66+ function findConfig(mod) {{
67+ return mod.default && mod.default.default ? mod.default.default : mod.default;
68+ }}
6369 "#
6470 ) ;
6571
@@ -83,7 +89,7 @@ pub fn from_javascript_path(file_path: &Path) -> Result<Rcfile, RcfileError> {
8389 } )
8490 . and_then ( |json_str| serde_json:: from_str :: < NodeJsResult > ( & json_str) . map_err ( RcfileError :: JsonParseFailed ) )
8591 . and_then ( |response| match response {
86- NodeJsResult :: Success { value } => serde_json:: from_value ( value) . map_err ( RcfileError :: InvalidConfig ) ,
92+ NodeJsResult :: Success { value } => serde_json:: from_str :: < Rcfile > ( & value) . map_err ( RcfileError :: InvalidConfig ) ,
8793 NodeJsResult :: Error {
8894 import_error,
8995 require_error,
0 commit comments