seedcord 0.20.0 → 0.21.1
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/dist/cli.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { n as SEEDCORD_CONFIG_FILENAMES, t as version } from "./src-
|
|
2
|
-
import { createRequire } from "node:module";
|
|
1
|
+
import { n as SEEDCORD_CONFIG_FILENAMES, t as version } from "./src-_1ojVhDK.mjs";
|
|
2
|
+
import { createRequire, findPackageJSON } from "node:module";
|
|
3
3
|
import { Command } from "@commander-js/extra-typings";
|
|
4
4
|
import { LEVEL_COLOR, Logger, LoggerChannelRegistry } from "@seedcord/logger";
|
|
5
5
|
import { formatBody, installNodeDefaults } from "@seedcord/logger/node";
|
|
6
6
|
import { Envapter, Environment } from "envapt";
|
|
7
7
|
import { SeedcordErrorCode, isSeedcordError, paint } from "@seedcord/errors";
|
|
8
|
-
import { existsSync, realpathSync } from "node:fs";
|
|
8
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
9
9
|
import { BRAND, SeedcordError, validateDiscordToken } from "@seedcord/errors/internal";
|
|
10
10
|
import { delimiter, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
11
|
+
import { isPlainObject, routeLeavesOf } from "@seedcord/utils/internal";
|
|
11
12
|
import { pathToFileURL } from "node:url";
|
|
12
13
|
import { createJiti } from "jiti";
|
|
13
|
-
import { tsImport } from "tsx/esm/api";
|
|
14
14
|
import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
15
15
|
import { spawn } from "node:child_process";
|
|
16
16
|
import "reflect-metadata";
|
|
@@ -18,7 +18,6 @@ import { isCommandClass, wrapHot } from "@seedcord/core/internal";
|
|
|
18
18
|
import { HostAugmentTarget, HostPluginKeys, HostShutdown, HostStartup, HostVersion, SeedcordBrand } from "@seedcord/types/internal";
|
|
19
19
|
import { isTsOrJsFile } from "@seedcord/utils/node";
|
|
20
20
|
import { ApplicationCommandOptionType, ApplicationCommandType, InteractionContextType, RESTJSONErrorCodes, Routes } from "discord-api-types/v10";
|
|
21
|
-
import { routeLeavesOf } from "@seedcord/utils/internal";
|
|
22
21
|
import { DiscordAPIError, REST } from "@discordjs/rest";
|
|
23
22
|
import { autocompleteMultiselect, cancel, confirm, intro, isCancel, log, multiselect, note, outro, select, spinner } from "@clack/prompts";
|
|
24
23
|
import { createInterface } from "node:readline";
|
|
@@ -66,9 +65,6 @@ function isObjectWithDefault(value) {
|
|
|
66
65
|
|
|
67
66
|
//#endregion
|
|
68
67
|
//#region src/core/config/ConfigLoader.ts
|
|
69
|
-
function isPlainObject(value) {
|
|
70
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
71
|
-
}
|
|
72
68
|
function isOptionalString(value) {
|
|
73
69
|
return value === void 0 || typeof value === "string";
|
|
74
70
|
}
|
|
@@ -221,45 +217,34 @@ const TS_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
221
217
|
".mts",
|
|
222
218
|
".cts"
|
|
223
219
|
]);
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
220
|
+
const EXTENSIONS = [
|
|
221
|
+
...TS_EXTENSIONS,
|
|
222
|
+
".js",
|
|
223
|
+
".mjs",
|
|
224
|
+
".cjs"
|
|
225
|
+
];
|
|
226
|
+
function jitiFor(entryPath) {
|
|
227
|
+
return createJiti(pathToFileURL(entryPath).href, {
|
|
227
228
|
cache: false,
|
|
228
229
|
interopDefault: true,
|
|
229
|
-
extensions:
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
".mts",
|
|
233
|
-
".cts",
|
|
234
|
-
".js",
|
|
235
|
-
".mjs",
|
|
236
|
-
".cjs"
|
|
237
|
-
]
|
|
230
|
+
extensions: EXTENSIONS,
|
|
231
|
+
tsconfigPaths: true,
|
|
232
|
+
jsx: true
|
|
238
233
|
});
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
234
|
+
}
|
|
235
|
+
var RuntimeModuleLoader = class {
|
|
242
236
|
async importModule(entryPath) {
|
|
243
237
|
const normalized = resolve(entryPath);
|
|
244
238
|
if (!existsSync(normalized)) throw new SeedcordError(SeedcordErrorCode.CliEntryNotFound, [normalized]);
|
|
245
|
-
if (
|
|
239
|
+
if (TS_EXTENSIONS.has(extname(normalized).toLowerCase())) return this.importTypeScript(normalized);
|
|
246
240
|
return this.importWithNode(normalized);
|
|
247
241
|
}
|
|
248
|
-
|
|
249
|
-
if (this.options.forceTsx) return true;
|
|
250
|
-
return TS_EXTENSIONS.has(extname(filePath).toLowerCase());
|
|
251
|
-
}
|
|
252
|
-
async importWithTsx(entryPath) {
|
|
253
|
-
const specifier = pathToFileURL(entryPath).href;
|
|
254
|
-
const tsconfig = this.resolveTsconfig(entryPath);
|
|
242
|
+
async importTypeScript(entryPath) {
|
|
255
243
|
try {
|
|
256
|
-
return await
|
|
257
|
-
parentURL: import.meta.url,
|
|
258
|
-
tsconfig
|
|
259
|
-
});
|
|
244
|
+
return await jitiFor(entryPath).import(entryPath);
|
|
260
245
|
} catch (error) {
|
|
261
|
-
const reason = Error.isError(error) ? error.message : "Unknown
|
|
262
|
-
throw new SeedcordError(SeedcordErrorCode.
|
|
246
|
+
const reason = Error.isError(error) ? error.message : "Unknown jiti error";
|
|
247
|
+
throw new SeedcordError(SeedcordErrorCode.CliTsImportFailed, [entryPath, reason]);
|
|
263
248
|
}
|
|
264
249
|
}
|
|
265
250
|
async importWithNode(entryPath) {
|
|
@@ -268,7 +253,7 @@ var RuntimeModuleLoader = class {
|
|
|
268
253
|
return await import(specifier);
|
|
269
254
|
} catch (nativeError) {
|
|
270
255
|
try {
|
|
271
|
-
return await
|
|
256
|
+
return await jitiFor(entryPath).import(entryPath);
|
|
272
257
|
} catch (fallbackError) {
|
|
273
258
|
const nativeReason = Error.isError(nativeError) ? nativeError.message : "Unknown ESM import error";
|
|
274
259
|
const fallbackReason = Error.isError(fallbackError) ? fallbackError.message : "Unknown jiti error";
|
|
@@ -280,17 +265,6 @@ var RuntimeModuleLoader = class {
|
|
|
280
265
|
}
|
|
281
266
|
}
|
|
282
267
|
}
|
|
283
|
-
resolveTsconfig(entryPath) {
|
|
284
|
-
if (this.options.tsconfig !== void 0) return this.options.tsconfig;
|
|
285
|
-
return this.findNearestTsconfig(dirname(entryPath)) ?? false;
|
|
286
|
-
}
|
|
287
|
-
findNearestTsconfig(startDir) {
|
|
288
|
-
const candidate = resolve(startDir, "tsconfig.json");
|
|
289
|
-
if (existsSync(candidate)) return candidate;
|
|
290
|
-
const parent = dirname(startDir);
|
|
291
|
-
if (parent === startDir) return void 0;
|
|
292
|
-
return this.findNearestTsconfig(parent);
|
|
293
|
-
}
|
|
294
268
|
};
|
|
295
269
|
|
|
296
270
|
//#endregion
|
|
@@ -3251,6 +3225,70 @@ var HmrPlugin = class extends TypedEventEmitter {
|
|
|
3251
3225
|
}
|
|
3252
3226
|
};
|
|
3253
3227
|
|
|
3228
|
+
//#endregion
|
|
3229
|
+
//#region src/commands/dev/runtime/seedcordDependents.ts
|
|
3230
|
+
const PROJECT_FIELDS = [
|
|
3231
|
+
"dependencies",
|
|
3232
|
+
"devDependencies",
|
|
3233
|
+
"optionalDependencies"
|
|
3234
|
+
];
|
|
3235
|
+
const PACKAGE_FIELDS = ["dependencies", "peerDependencies"];
|
|
3236
|
+
function dependencyNames(manifestPath, fields) {
|
|
3237
|
+
const manifest = existsSync(manifestPath) ? JSON.parse(readFileSync(manifestPath, "utf8")) : void 0;
|
|
3238
|
+
if (!isPlainObject(manifest)) return [];
|
|
3239
|
+
return fields.flatMap((field) => {
|
|
3240
|
+
const deps = manifest[field];
|
|
3241
|
+
return isPlainObject(deps) ? Object.keys(deps) : [];
|
|
3242
|
+
});
|
|
3243
|
+
}
|
|
3244
|
+
function installedManifest(name, fromManifest) {
|
|
3245
|
+
try {
|
|
3246
|
+
return findPackageJSON(name, pathToFileURL(fromManifest));
|
|
3247
|
+
} catch (error) {
|
|
3248
|
+
if (Error.isError(error) && "code" in error && error.code === "ERR_MODULE_NOT_FOUND") return void 0;
|
|
3249
|
+
throw error;
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3252
|
+
function isSeedcordPackage(name) {
|
|
3253
|
+
return name.startsWith("@seedcord/");
|
|
3254
|
+
}
|
|
3255
|
+
function installedGraph(projectDir) {
|
|
3256
|
+
const edges = /* @__PURE__ */ new Map();
|
|
3257
|
+
const listsSeedcord = /* @__PURE__ */ new Set();
|
|
3258
|
+
const collect = (manifestPath, fields) => {
|
|
3259
|
+
if (edges.has(manifestPath)) return;
|
|
3260
|
+
const children = /* @__PURE__ */ new Map();
|
|
3261
|
+
edges.set(manifestPath, children);
|
|
3262
|
+
for (const name of dependencyNames(manifestPath, fields)) {
|
|
3263
|
+
if (isSeedcordPackage(name)) listsSeedcord.add(manifestPath);
|
|
3264
|
+
const depManifest = installedManifest(name, manifestPath);
|
|
3265
|
+
if (depManifest === void 0) continue;
|
|
3266
|
+
children.set(name, depManifest);
|
|
3267
|
+
collect(depManifest, PACKAGE_FIELDS);
|
|
3268
|
+
}
|
|
3269
|
+
};
|
|
3270
|
+
collect(join(projectDir, "package.json"), PROJECT_FIELDS);
|
|
3271
|
+
return {
|
|
3272
|
+
edges,
|
|
3273
|
+
listsSeedcord
|
|
3274
|
+
};
|
|
3275
|
+
}
|
|
3276
|
+
function seedcordDependents(projectDir) {
|
|
3277
|
+
const { edges, listsSeedcord } = installedGraph(projectDir);
|
|
3278
|
+
const parentsOf = /* @__PURE__ */ new Map();
|
|
3279
|
+
for (const [manifest, children] of edges) for (const depManifest of children.values()) parentsOf.set(depManifest, [...parentsOf.get(depManifest) ?? [], manifest]);
|
|
3280
|
+
const dependsOnSeedcord = new Set(listsSeedcord);
|
|
3281
|
+
const queue = [...listsSeedcord];
|
|
3282
|
+
for (const manifest of queue) for (const parent of parentsOf.get(manifest) ?? []) {
|
|
3283
|
+
if (dependsOnSeedcord.has(parent)) continue;
|
|
3284
|
+
dependsOnSeedcord.add(parent);
|
|
3285
|
+
queue.push(parent);
|
|
3286
|
+
}
|
|
3287
|
+
const found = /* @__PURE__ */ new Set();
|
|
3288
|
+
for (const children of edges.values()) for (const [name, depManifest] of children) if (dependsOnSeedcord.has(depManifest) && !isSeedcordPackage(name)) found.add(name);
|
|
3289
|
+
return [...found];
|
|
3290
|
+
}
|
|
3291
|
+
|
|
3254
3292
|
//#endregion
|
|
3255
3293
|
//#region src/commands/dev/runtime/vite.config.ts
|
|
3256
3294
|
function logsIgnore(root) {
|
|
@@ -3328,11 +3366,14 @@ var ViteDevRuntime = class {
|
|
|
3328
3366
|
});
|
|
3329
3367
|
const hmrPlugin = new HmrPlugin(this.context.config);
|
|
3330
3368
|
this.hmrPlugin = hmrPlugin;
|
|
3331
|
-
const
|
|
3369
|
+
const projectDir = dirname(this.context.config.configFile);
|
|
3370
|
+
const base = structuredClone(vite_config_default);
|
|
3371
|
+
const config = mergeConfig(base, {
|
|
3332
3372
|
root: projectRoot,
|
|
3333
3373
|
configFile: false,
|
|
3334
3374
|
server: { watch: { ignored: [logsIgnore(projectRoot)] } },
|
|
3335
|
-
|
|
3375
|
+
ssr: { noExternal: seedcordDependents(projectDir) },
|
|
3376
|
+
plugins: [tsconfigPaths({ root: projectDir }), hmrPlugin.plugin]
|
|
3336
3377
|
});
|
|
3337
3378
|
this.viteServer = await createServer(config);
|
|
3338
3379
|
this.evaluatedModules = new EvaluatedModules();
|