1
- import path from "path" ;
2
- import fs from "fs" ;
3
- import { parseExpression , parse } from "@babel/parser" ;
1
+ const path = require ( "path" ) ;
2
+ const fs = require ( "fs" ) ;
3
+ const { parseExpression, parse } = require ( "@babel/parser" ) ;
4
4
5
5
const OPTIONS_TO_BUNDLE = [
6
6
"bundleHost" ,
@@ -9,11 +9,11 @@ const OPTIONS_TO_BUNDLE = [
9
9
"updateChecker" ,
10
10
] ;
11
11
12
- export default async function ( babel ) {
12
+ module . exports = function ( babel ) {
13
13
const { types : t } = babel ;
14
14
15
- // Load config and imports from `codepush.config.mjs `
16
- const { config, configImports, importedIdentifiers } = await loadConfig ( ) ;
15
+ // Load config and imports from `codepush.config.js `
16
+ const { config, configImports, importedIdentifiers } = loadConfig ( ) ;
17
17
18
18
// Helper to serialize config values to AST nodes
19
19
function serializeConfigToNode ( value ) {
@@ -58,15 +58,15 @@ export default async function (babel) {
58
58
throw new Error ( `Unsupported config value type: ${ typeof value } ` ) ;
59
59
}
60
60
61
- async function loadConfig ( ) {
62
- const configPath = path . resolve ( process . cwd ( ) , "codepush.config.mjs " ) ;
61
+ function loadConfig ( ) {
62
+ const configPath = path . resolve ( process . cwd ( ) , "codepush.config.js " ) ;
63
63
if ( ! fs . existsSync ( configPath ) ) {
64
64
throw new Error (
65
- "codepush.config.mjs not found. Please ensure it exists in the root directory."
65
+ "codepush.config.js not found. Please ensure it exists in the root directory."
66
66
) ;
67
67
}
68
68
69
- const configModule = await import ( configPath ) ;
69
+ const configModule = require ( configPath ) ;
70
70
71
71
const configCode = fs . readFileSync ( configPath , "utf8" ) ;
72
72
const ast = parse ( configCode , {
@@ -103,10 +103,10 @@ export default async function (babel) {
103
103
} ,
104
104
} ) ;
105
105
106
- // Add missing imports from codepush.config.mjs to the input file
106
+ // Add missing imports from codepush.config.js to the input file
107
107
configImports . forEach ( ( importNode ) => {
108
108
if ( ! existingImports . has ( importNode . source . value ) ) {
109
- // Clone the import node from codepush.config.mjs and add it to the input file
109
+ // Clone the import node from codepush.config.js and add it to the input file
110
110
path . node . body . unshift ( t . cloneNode ( importNode ) ) ;
111
111
}
112
112
} ) ;
@@ -147,4 +147,4 @@ export default async function (babel) {
147
147
} ,
148
148
} ,
149
149
} ;
150
- }
150
+ } ;
0 commit comments