Skip to content

Commit 21c354b

Browse files
committed
mod: change to commonjs
1 parent b16b59c commit 21c354b

File tree

7 files changed

+5556
-1411
lines changed

7 files changed

+5556
-1411
lines changed

babel-plugin-code-push/index.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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");
44

55
const OPTIONS_TO_BUNDLE = [
66
"bundleHost",
@@ -9,11 +9,11 @@ const OPTIONS_TO_BUNDLE = [
99
"updateChecker",
1010
];
1111

12-
export default async function (babel) {
12+
module.exports = function (babel) {
1313
const { types: t } = babel;
1414

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();
1717

1818
// Helper to serialize config values to AST nodes
1919
function serializeConfigToNode(value) {
@@ -58,15 +58,15 @@ export default async function (babel) {
5858
throw new Error(`Unsupported config value type: ${typeof value}`);
5959
}
6060

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");
6363
if (!fs.existsSync(configPath)) {
6464
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."
6666
);
6767
}
6868

69-
const configModule = await import(configPath);
69+
const configModule = require(configPath);
7070

7171
const configCode = fs.readFileSync(configPath, "utf8");
7272
const ast = parse(configCode, {
@@ -103,10 +103,10 @@ export default async function (babel) {
103103
},
104104
});
105105

106-
// Add missing imports from codepush.config.mjs to the input file
106+
// Add missing imports from codepush.config.js to the input file
107107
configImports.forEach((importNode) => {
108108
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
110110
path.node.body.unshift(t.cloneNode(importNode));
111111
}
112112
});
@@ -147,4 +147,4 @@ export default async function (babel) {
147147
},
148148
},
149149
};
150-
}
150+
};

0 commit comments

Comments
 (0)