@suronai/cli 0.1.42 → 0.1.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands.js +24 -3
package/package.json
CHANGED
package/src/commands.js
CHANGED
|
@@ -105,10 +105,21 @@ function installSdk(cwd) {
|
|
|
105
105
|
// ── Entry-point patching ──────────────────────────────────────────────────────
|
|
106
106
|
|
|
107
107
|
async function patchEntryPoint(cwd, isEsm) {
|
|
108
|
+
// Check package.json "main" first, then fall back to common names
|
|
109
|
+
let mainFromPkg = null;
|
|
110
|
+
try {
|
|
111
|
+
const pkg = JSON.parse(readFileSync(join(cwd, "package.json"), "utf-8"));
|
|
112
|
+
if (pkg.main) mainFromPkg = pkg.main;
|
|
113
|
+
} catch {}
|
|
114
|
+
|
|
108
115
|
const candidates = isEsm
|
|
109
116
|
? ["index.js", "index.mjs", "src/index.js", "src/index.mjs"]
|
|
110
117
|
: ["index.js", "index.cjs", "src/index.js", "src/index.cjs"];
|
|
111
118
|
|
|
119
|
+
if (mainFromPkg && !candidates.includes(mainFromPkg)) {
|
|
120
|
+
candidates.unshift(mainFromPkg);
|
|
121
|
+
}
|
|
122
|
+
|
|
112
123
|
let entryPath = null;
|
|
113
124
|
for (const rel of candidates) {
|
|
114
125
|
const abs = join(cwd, rel);
|
|
@@ -137,7 +148,18 @@ async function patchEntryPoint(cwd, isEsm) {
|
|
|
137
148
|
}
|
|
138
149
|
} else {
|
|
139
150
|
if (trimmed.includes("require")) {
|
|
140
|
-
|
|
151
|
+
// Handle: require("dotenv").config() → require("@suronai/sdk").config()
|
|
152
|
+
// Handle: require("dotenv/config") → require("@suronai/sdk").config()
|
|
153
|
+
// Handle: const x = require("dotenv") → const { config } = require("@suronai/sdk")\nawait config()
|
|
154
|
+
if (/require\(['"]dotenv['"]\)\.config/.test(trimmed)) {
|
|
155
|
+
replacement = indent + trimmed.replace(/require\(['"]dotenv['"]\)/, 'require("@suronai/sdk")');
|
|
156
|
+
// wrap the whole statement to be async-aware
|
|
157
|
+
replacement = indent + `await require("@suronai/sdk").config();`;
|
|
158
|
+
} else if (/require\(['"]dotenv\/config['"]\)/.test(trimmed)) {
|
|
159
|
+
replacement = indent + `await require("@suronai/sdk").config();`;
|
|
160
|
+
} else {
|
|
161
|
+
replacement = indent + `const { config: suronConfig } = require("@suronai/sdk");\n` + indent + `await suronConfig();`;
|
|
162
|
+
}
|
|
141
163
|
}
|
|
142
164
|
}
|
|
143
165
|
toReplace.push({ index: i, content: lines[i], replacement });
|
|
@@ -218,8 +240,7 @@ function printSnippet(isEsm) {
|
|
|
218
240
|
console.log(ui.INDENT + " " + ui.amber('import { config } from "@suronai/sdk"'));
|
|
219
241
|
console.log(ui.INDENT + " " + ui.amber("await config()"));
|
|
220
242
|
} else {
|
|
221
|
-
console.log(ui.INDENT + " " + ui.amber('
|
|
222
|
-
console.log(ui.INDENT + " " + ui.amber("await config()"));
|
|
243
|
+
console.log(ui.INDENT + " " + ui.amber('await require("@suronai/sdk").config()'));
|
|
223
244
|
}
|
|
224
245
|
console.log(ui.blank());
|
|
225
246
|
console.log(ui.hr());
|