silgi 0.22.0 → 0.22.2
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/_chunks/index.mjs +1 -1
- package/dist/cli/compatibility.mjs +2 -10
- package/dist/cli/dev.mjs +1 -0
- package/dist/cli/prepare.mjs +264 -263
- package/dist/kit/index.mjs +11 -4
- package/dist/meta/index.d.mts +1 -1
- package/dist/meta/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/_chunks/index.mjs
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import { tryUseSilgiCLI, useSilgiCLI } from 'silgi/core';
|
|
2
1
|
import satisfies from 'semver/functions/satisfies.js';
|
|
2
|
+
import { useSilgiCLI } from 'silgi/core';
|
|
3
3
|
import { version } from 'silgi/meta';
|
|
4
4
|
|
|
5
|
-
function hasError(type, silgi) {
|
|
6
|
-
silgi = silgi ?? tryUseSilgiCLI() ?? void 0;
|
|
7
|
-
if (silgi && silgi.errors.some((error) => error.type === type)) {
|
|
8
|
-
return true;
|
|
9
|
-
}
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
5
|
const SEMANTIC_VERSION_RE = /-\d+\.[0-9a-f]+/;
|
|
14
6
|
function normalizeSemanticVersion(version) {
|
|
15
7
|
return version.replace(SEMANTIC_VERSION_RE, "");
|
|
@@ -35,4 +27,4 @@ function hasInstalledModule(moduleKey, silgi = useSilgiCLI()) {
|
|
|
35
27
|
return find?.installed ?? false;
|
|
36
28
|
}
|
|
37
29
|
|
|
38
|
-
export {
|
|
30
|
+
export { checkSilgiCompatibility as c, hasInstalledModule as h };
|
package/dist/cli/dev.mjs
CHANGED
|
@@ -89,6 +89,7 @@ const dev = defineCommand({
|
|
|
89
89
|
const watchReloadEvents = /* @__PURE__ */ new Set(["add", "addDir", "unlink", "unlinkDir", "change"]);
|
|
90
90
|
let watcher;
|
|
91
91
|
if (silgi.options.devServer.watch.length > 0) {
|
|
92
|
+
silgi.options.devServer.watch = [...new Set(silgi.options.devServer.watch)];
|
|
92
93
|
watcher = watch(silgi.options.devServer.watch, silgi.options.watchOptions);
|
|
93
94
|
watcher.on("all", async (event, path, stats) => {
|
|
94
95
|
if (!watchReloadEvents.has(event)) {
|
package/dist/cli/prepare.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { defineCommand, runCommand } from 'citty';
|
|
2
2
|
import { join, resolve, relative, dirname, basename, extname, isAbsolute } from 'pathe';
|
|
3
3
|
import { peerDependencies, version } from 'silgi/meta';
|
|
4
|
-
import { writeFile, relativeWithDot, hash, resolveAlias, directoryToURL, addTemplate, parseServices, normalizeTemplate, useLogger, initRuntimeConfig, resolveSilgiPath, isDirectory } from 'silgi/kit';
|
|
4
|
+
import { writeFile, relativeWithDot, hash, resolveAlias, directoryToURL, addTemplate, hasError, parseServices, normalizeTemplate, useLogger, initRuntimeConfig, resolveSilgiPath, isDirectory } from 'silgi/kit';
|
|
5
5
|
import { existsSync, promises, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
6
6
|
import { readdir, readFile } from 'node:fs/promises';
|
|
7
|
-
import consola
|
|
7
|
+
import consola, { consola as consola$1 } from 'consola';
|
|
8
8
|
import { createHooks, createDebugger } from 'hookable';
|
|
9
9
|
import { useSilgiCLI, silgiCLICtx } from 'silgi/core';
|
|
10
10
|
import { runtimeDir } from 'silgi/runtime/meta';
|
|
@@ -15,7 +15,7 @@ import * as p from '@clack/prompts';
|
|
|
15
15
|
import * as dotenv from 'dotenv';
|
|
16
16
|
import { resolveModuleExportNames, findTypeExports, findExports, resolvePath, parseNodeModulePath, lookupNodeModuleSubpath } from 'mlly';
|
|
17
17
|
import { createJiti } from 'dev-jiti';
|
|
18
|
-
import {
|
|
18
|
+
import { h as hasInstalledModule } from './compatibility.mjs';
|
|
19
19
|
import { fileURLToPath } from 'node:url';
|
|
20
20
|
import defu, { defu as defu$1 } from 'defu';
|
|
21
21
|
import { resolveModuleURL } from 'exsolve';
|
|
@@ -868,252 +868,6 @@ async function commands(silgi) {
|
|
|
868
868
|
});
|
|
869
869
|
}
|
|
870
870
|
|
|
871
|
-
function buildUriMap(silgi, currentPath = []) {
|
|
872
|
-
const uriMap = /* @__PURE__ */ new Map();
|
|
873
|
-
function traverse(node, path = []) {
|
|
874
|
-
if (!node || typeof node !== "object")
|
|
875
|
-
return;
|
|
876
|
-
if (path.length === 4) {
|
|
877
|
-
const basePath = path.join("/");
|
|
878
|
-
let pathString = "";
|
|
879
|
-
if (node.pathParams) {
|
|
880
|
-
let paths = null;
|
|
881
|
-
if (node.pathParams?._def?.typeName !== void 0) {
|
|
882
|
-
try {
|
|
883
|
-
const shape = node.pathParams?.shape;
|
|
884
|
-
paths = shape ? Object.keys(shape) : null;
|
|
885
|
-
} catch {
|
|
886
|
-
paths = null;
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
if (paths?.length) {
|
|
890
|
-
pathString = paths.map((p) => `:${p}`).join("/");
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
uriMap.set(basePath, pathString);
|
|
894
|
-
return;
|
|
895
|
-
}
|
|
896
|
-
for (const key in node) {
|
|
897
|
-
if (!["_type", "fields"].includes(key)) {
|
|
898
|
-
traverse(node[key], [...path, key]);
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
traverse(silgi.schemas, currentPath);
|
|
903
|
-
silgi.uris = defu$1(silgi.uris, Object.fromEntries(uriMap));
|
|
904
|
-
return uriMap;
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
async function readScanFile(silgi) {
|
|
908
|
-
const path = resolve(silgi.options.silgi.serverDir, "scan.ts");
|
|
909
|
-
const context = await promises.readFile(path, { encoding: "utf-8" });
|
|
910
|
-
silgi.unimport = createUnimport(silgi.options.imports || {});
|
|
911
|
-
await silgi.unimport.init();
|
|
912
|
-
const injectedResult = await silgi.unimport.injectImports(context, path);
|
|
913
|
-
if (!injectedResult) {
|
|
914
|
-
throw new Error("Failed to inject imports");
|
|
915
|
-
}
|
|
916
|
-
const jiti = createJiti(silgi.options.rootDir, {
|
|
917
|
-
fsCache: true,
|
|
918
|
-
moduleCache: false,
|
|
919
|
-
debug: silgi.options.debug,
|
|
920
|
-
alias: silgi.options.alias
|
|
921
|
-
});
|
|
922
|
-
try {
|
|
923
|
-
if (silgi.options.commandType === "prepare") {
|
|
924
|
-
globalThis.$silgiSharedRuntimeConfig = silgi.options.runtimeConfig;
|
|
925
|
-
injectedResult.code = `globalThis.$silgiSharedRuntimeConfig = ${JSON.stringify(silgi.options.runtimeConfig)};
|
|
926
|
-
${injectedResult.code}`;
|
|
927
|
-
injectedResult.code = injectedResult.code.replace(/runtimeConfig: \{\}/, `runtimeConfig: ${JSON.stringify(silgi.options.runtimeConfig)}`);
|
|
928
|
-
}
|
|
929
|
-
const scanFile = await jiti.evalModule(
|
|
930
|
-
injectedResult.code,
|
|
931
|
-
{
|
|
932
|
-
filename: path,
|
|
933
|
-
async: true,
|
|
934
|
-
conditions: silgi.options.conditions
|
|
935
|
-
},
|
|
936
|
-
async (data, name) => {
|
|
937
|
-
return (await silgi.unimport.injectImports(data, name)).code;
|
|
938
|
-
}
|
|
939
|
-
);
|
|
940
|
-
silgi.uris = defu$1(silgi.uris, scanFile.uris) || {};
|
|
941
|
-
silgi.schemas = defu$1(scanFile.schemas, scanFile.uris) || {};
|
|
942
|
-
silgi.services = defu$1(scanFile.services, scanFile.uris) || {};
|
|
943
|
-
silgi.shareds = defu$1(scanFile.shareds, scanFile.shareds) || {};
|
|
944
|
-
silgi.modulesURIs = defu$1(scanFile.modulesURIs, scanFile.modulesURIs) || {};
|
|
945
|
-
return {
|
|
946
|
-
context,
|
|
947
|
-
object: {
|
|
948
|
-
schemas: scanFile.schemas,
|
|
949
|
-
uris: scanFile.uris,
|
|
950
|
-
services: scanFile.services,
|
|
951
|
-
shareds: scanFile.shareds,
|
|
952
|
-
modulesURIs: scanFile.modulesURIs
|
|
953
|
-
},
|
|
954
|
-
path
|
|
955
|
-
};
|
|
956
|
-
} catch (error) {
|
|
957
|
-
if (silgi.options.debug) {
|
|
958
|
-
console.error("Failed to read scan.ts file:", error);
|
|
959
|
-
} else {
|
|
960
|
-
if (error instanceof Error) {
|
|
961
|
-
consola.withTag("silgi").info(error.message);
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
return {
|
|
965
|
-
context,
|
|
966
|
-
object: {
|
|
967
|
-
schemas: {},
|
|
968
|
-
uris: {},
|
|
969
|
-
services: {},
|
|
970
|
-
shareds: {},
|
|
971
|
-
modulesURIs: {}
|
|
972
|
-
},
|
|
973
|
-
path
|
|
974
|
-
};
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
async function prepareServerFiles(silgi) {
|
|
979
|
-
const importItems = {
|
|
980
|
-
"silgi": {
|
|
981
|
-
import: [
|
|
982
|
-
{ name: "createSilgi", key: "createSilgi" },
|
|
983
|
-
{ name: "createShared", key: "createShared" }
|
|
984
|
-
],
|
|
985
|
-
from: "silgi"
|
|
986
|
-
},
|
|
987
|
-
"silgi/types": {
|
|
988
|
-
import: [
|
|
989
|
-
{ name: "SilgiRuntimeOptions", type: true, key: "SilgiRuntimeOptions" },
|
|
990
|
-
{ name: "FrameworkContext", type: true, key: "FrameworkContext" }
|
|
991
|
-
],
|
|
992
|
-
from: "silgi/types"
|
|
993
|
-
},
|
|
994
|
-
"#silgi/vfs": {
|
|
995
|
-
import: [],
|
|
996
|
-
from: "./vfs"
|
|
997
|
-
},
|
|
998
|
-
"configs.ts": {
|
|
999
|
-
import: [
|
|
1000
|
-
{
|
|
1001
|
-
name: "cliConfigs",
|
|
1002
|
-
type: false,
|
|
1003
|
-
key: "cliConfigs"
|
|
1004
|
-
}
|
|
1005
|
-
],
|
|
1006
|
-
from: "./configs.ts"
|
|
1007
|
-
}
|
|
1008
|
-
};
|
|
1009
|
-
const scanned = {
|
|
1010
|
-
uris: {},
|
|
1011
|
-
services: [],
|
|
1012
|
-
shareds: [
|
|
1013
|
-
`createShared({
|
|
1014
|
-
modulesURIs,
|
|
1015
|
-
})`
|
|
1016
|
-
],
|
|
1017
|
-
schemas: [],
|
|
1018
|
-
modulesURIs: {},
|
|
1019
|
-
customImports: [],
|
|
1020
|
-
importItems
|
|
1021
|
-
};
|
|
1022
|
-
if (silgi.uris) {
|
|
1023
|
-
defu$1(scanned.uris, silgi.uris);
|
|
1024
|
-
}
|
|
1025
|
-
if (silgi.modulesURIs) {
|
|
1026
|
-
defu$1(scanned.modulesURIs, silgi.modulesURIs);
|
|
1027
|
-
}
|
|
1028
|
-
await silgi.callHook("prepare:scan.ts", scanned);
|
|
1029
|
-
if (importItems["#silgi/vfs"].import.length === 0) {
|
|
1030
|
-
delete importItems["#silgi/vfs"];
|
|
1031
|
-
}
|
|
1032
|
-
if (scanned.services.length > 0) {
|
|
1033
|
-
importItems.silgi.import.push({ name: "mergeServices", key: "mergeServices" });
|
|
1034
|
-
}
|
|
1035
|
-
if (scanned.shareds.length > 0) {
|
|
1036
|
-
importItems.silgi.import.push({ name: "mergeShared", key: "mergeShared" });
|
|
1037
|
-
}
|
|
1038
|
-
if (scanned.schemas.length > 0) {
|
|
1039
|
-
importItems.silgi.import.push({ name: "mergeSchemas", key: "mergeSchemas" });
|
|
1040
|
-
}
|
|
1041
|
-
for (const key in importItems) {
|
|
1042
|
-
importItems[key].import = deduplicateImportsByKey(importItems[key].import);
|
|
1043
|
-
}
|
|
1044
|
-
const importsContent = [
|
|
1045
|
-
...Object.entries(importItems).map(([_name, { from, import: imports }]) => {
|
|
1046
|
-
if (silgi.options.typescript.removeFileExtension) {
|
|
1047
|
-
from = from.replace(/\.(js|ts|mjs|cjs|jsx|tsx)$/, "");
|
|
1048
|
-
}
|
|
1049
|
-
return `import { ${imports.map(({ type, name }) => type ? `type ${name}` : name).join(", ")} } from '${from}'`;
|
|
1050
|
-
}),
|
|
1051
|
-
"",
|
|
1052
|
-
...scanned.customImports,
|
|
1053
|
-
""
|
|
1054
|
-
];
|
|
1055
|
-
const importData = [
|
|
1056
|
-
`export const uris = ${JSON.stringify(scanned.uris, null, 2)}`,
|
|
1057
|
-
"",
|
|
1058
|
-
`export const modulesURIs = ${JSON.stringify(scanned.modulesURIs, null, 2)}`,
|
|
1059
|
-
"",
|
|
1060
|
-
scanned.schemas.length > 0 ? "export const schemas = mergeSchemas([" : "export const schemas = {",
|
|
1061
|
-
...scanned.schemas.map((name) => {
|
|
1062
|
-
return ` ${name},`;
|
|
1063
|
-
}),
|
|
1064
|
-
scanned.schemas.length > 0 ? "])" : "}",
|
|
1065
|
-
"",
|
|
1066
|
-
scanned.services.length > 0 ? "export const services = mergeServices([" : "export const services = {",
|
|
1067
|
-
...scanned.services.map((name) => {
|
|
1068
|
-
return ` ${name},`;
|
|
1069
|
-
}),
|
|
1070
|
-
scanned.services.length > 0 ? "])" : "}",
|
|
1071
|
-
"",
|
|
1072
|
-
scanned.shareds.length > 0 ? "export const shareds = mergeShared([" : "export const shareds = {",
|
|
1073
|
-
...scanned.shareds.map((name) => {
|
|
1074
|
-
return ` ${name},`;
|
|
1075
|
-
}),
|
|
1076
|
-
scanned.shareds.length > 0 ? "])" : "}",
|
|
1077
|
-
""
|
|
1078
|
-
];
|
|
1079
|
-
await silgi.callHook("after:prepare:scan.ts", importData);
|
|
1080
|
-
importData.unshift(...importsContent);
|
|
1081
|
-
return importData;
|
|
1082
|
-
}
|
|
1083
|
-
function deduplicateImportsByKey(imports) {
|
|
1084
|
-
const seenKeys = /* @__PURE__ */ new Map();
|
|
1085
|
-
return imports.filter((item) => {
|
|
1086
|
-
if (seenKeys.has(item.key)) {
|
|
1087
|
-
return false;
|
|
1088
|
-
}
|
|
1089
|
-
seenKeys.set(item.key, true);
|
|
1090
|
-
return true;
|
|
1091
|
-
});
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
|
-
async function writeScanFiles(silgi) {
|
|
1095
|
-
const data = await prepareServerFiles(silgi);
|
|
1096
|
-
if (!silgi.errors.length) {
|
|
1097
|
-
await writeFile(
|
|
1098
|
-
resolve(silgi.options.silgi.serverDir, "scan.ts"),
|
|
1099
|
-
data.join("\n")
|
|
1100
|
-
);
|
|
1101
|
-
}
|
|
1102
|
-
await readScanFile(silgi);
|
|
1103
|
-
buildUriMap(silgi);
|
|
1104
|
-
parseServices(silgi);
|
|
1105
|
-
silgi.hook("prepare:scan.ts", (file) => {
|
|
1106
|
-
file.uris = {
|
|
1107
|
-
...file.uris,
|
|
1108
|
-
...silgi.uris
|
|
1109
|
-
};
|
|
1110
|
-
file.modulesURIs = {
|
|
1111
|
-
...file.modulesURIs,
|
|
1112
|
-
...silgi.modulesURIs
|
|
1113
|
-
};
|
|
1114
|
-
});
|
|
1115
|
-
}
|
|
1116
|
-
|
|
1117
871
|
function resolveIgnorePatterns(silgi, relativePath) {
|
|
1118
872
|
if (!silgi) {
|
|
1119
873
|
return [];
|
|
@@ -1185,7 +939,7 @@ class SchemaParser {
|
|
|
1185
939
|
type: "Parser",
|
|
1186
940
|
path
|
|
1187
941
|
});
|
|
1188
|
-
consola
|
|
942
|
+
consola.warn("This file has a problem:", path);
|
|
1189
943
|
}
|
|
1190
944
|
const variableDeclarations = ast.program.body.filter((i) => i.type === "ExportNamedDeclaration").filter((i) => i.declaration?.type === "VariableDeclaration");
|
|
1191
945
|
return variableDeclarations;
|
|
@@ -1197,7 +951,7 @@ class SchemaParser {
|
|
|
1197
951
|
type: "Parser",
|
|
1198
952
|
path
|
|
1199
953
|
});
|
|
1200
|
-
consola
|
|
954
|
+
consola.warn("This file has a problem:", path);
|
|
1201
955
|
}
|
|
1202
956
|
const interfaceDeclarations = ast.program.body.filter((i) => i.type === "ExportNamedDeclaration").filter((i) => i.declaration?.type === "TSInterfaceDeclaration");
|
|
1203
957
|
return interfaceDeclarations;
|
|
@@ -1306,7 +1060,7 @@ class SchemaParser {
|
|
|
1306
1060
|
// }
|
|
1307
1061
|
}
|
|
1308
1062
|
|
|
1309
|
-
async function
|
|
1063
|
+
async function scanExportFile(silgi) {
|
|
1310
1064
|
const filePaths = /* @__PURE__ */ new Set();
|
|
1311
1065
|
const scannedPaths = [];
|
|
1312
1066
|
const dir = silgi.options.serverDir;
|
|
@@ -1320,7 +1074,7 @@ async function scanFiles$1(silgi, watchFiles) {
|
|
|
1320
1074
|
if (caseCorrected) {
|
|
1321
1075
|
const original = relative(silgi.options.serverDir, dir);
|
|
1322
1076
|
const corrected = relative(silgi.options.serverDir, join(dirname(dir), caseCorrected));
|
|
1323
|
-
consola.warn(`Components not scanned from \`~/${corrected}\`. Did you mean to name the directory \`~/${original}\` instead?`);
|
|
1077
|
+
consola$1.warn(`Components not scanned from \`~/${corrected}\`. Did you mean to name the directory \`~/${original}\` instead?`);
|
|
1324
1078
|
}
|
|
1325
1079
|
}
|
|
1326
1080
|
}
|
|
@@ -1347,7 +1101,6 @@ async function scanFiles$1(silgi, watchFiles) {
|
|
|
1347
1101
|
const schemaTS = [];
|
|
1348
1102
|
if (createServices.length > 0) {
|
|
1349
1103
|
scanTS.push(...createServices.map(({ exportName, path }) => {
|
|
1350
|
-
silgi.options.devServer.watch.push(path);
|
|
1351
1104
|
const randomString = hash(basename(path) + exportName);
|
|
1352
1105
|
const _name = `_v${randomString}`;
|
|
1353
1106
|
return { exportName, path, _name, type: "service" };
|
|
@@ -1359,7 +1112,6 @@ async function scanFiles$1(silgi, watchFiles) {
|
|
|
1359
1112
|
}
|
|
1360
1113
|
if (createSchemas.length > 0) {
|
|
1361
1114
|
scanTS.push(...createSchemas.map(({ exportName, path }) => {
|
|
1362
|
-
silgi.options.devServer.watch.push(path);
|
|
1363
1115
|
const randomString = hash(basename(path) + exportName);
|
|
1364
1116
|
const _name = `_v${randomString}`;
|
|
1365
1117
|
return { exportName, path, _name, type: "schema" };
|
|
@@ -1371,7 +1123,6 @@ async function scanFiles$1(silgi, watchFiles) {
|
|
|
1371
1123
|
}
|
|
1372
1124
|
if (createShareds.length > 0) {
|
|
1373
1125
|
scanTS.push(...createShareds.map(({ exportName, path }) => {
|
|
1374
|
-
silgi.options.devServer.watch.push(path);
|
|
1375
1126
|
const randomString = hash(basename(path) + exportName);
|
|
1376
1127
|
const _name = `_v${randomString}`;
|
|
1377
1128
|
return { exportName, path, _name, type: "shared" };
|
|
@@ -1383,7 +1134,6 @@ async function scanFiles$1(silgi, watchFiles) {
|
|
|
1383
1134
|
}
|
|
1384
1135
|
if (sharedsTypes.length > 0) {
|
|
1385
1136
|
schemaTS.push(...sharedsTypes.map(({ exportName, path }) => {
|
|
1386
|
-
silgi.options.devServer.watch.push(path);
|
|
1387
1137
|
const randomString = hash(basename(path) + exportName);
|
|
1388
1138
|
const _name = `_v${randomString}`;
|
|
1389
1139
|
return { exportName, path, _name, type: "shared" };
|
|
@@ -1395,7 +1145,6 @@ async function scanFiles$1(silgi, watchFiles) {
|
|
|
1395
1145
|
}
|
|
1396
1146
|
if (contextTypes.length > 0) {
|
|
1397
1147
|
schemaTS.push(...contextTypes.map(({ exportName, path }) => {
|
|
1398
|
-
silgi.options.devServer.watch.push(path);
|
|
1399
1148
|
const randomString = hash(basename(path) + exportName);
|
|
1400
1149
|
const _name = `_v${randomString}`;
|
|
1401
1150
|
return { exportName, path, _name, type: "context" };
|
|
@@ -1403,6 +1152,9 @@ async function scanFiles$1(silgi, watchFiles) {
|
|
|
1403
1152
|
}
|
|
1404
1153
|
silgi.hook("prepare:scan.ts", (options) => {
|
|
1405
1154
|
for (const { exportName, path, _name, type } of scanTS) {
|
|
1155
|
+
if (!path.includes("vfs")) {
|
|
1156
|
+
silgi.options.devServer.watch.push(path);
|
|
1157
|
+
}
|
|
1406
1158
|
if (type === "service") {
|
|
1407
1159
|
options.services.push(_name);
|
|
1408
1160
|
}
|
|
@@ -1424,6 +1176,9 @@ async function scanFiles$1(silgi, watchFiles) {
|
|
|
1424
1176
|
});
|
|
1425
1177
|
silgi.hook("prepare:schema.ts", (options) => {
|
|
1426
1178
|
for (const { exportName, path, _name, type } of schemaTS) {
|
|
1179
|
+
if (!path.includes("vfs")) {
|
|
1180
|
+
silgi.options.devServer.watch.push(path);
|
|
1181
|
+
}
|
|
1427
1182
|
if (type === "shared") {
|
|
1428
1183
|
options.shareds.push({
|
|
1429
1184
|
key: _name,
|
|
@@ -1450,6 +1205,252 @@ async function scanFiles$1(silgi, watchFiles) {
|
|
|
1450
1205
|
}
|
|
1451
1206
|
}
|
|
1452
1207
|
|
|
1208
|
+
function buildUriMap(silgi, currentPath = []) {
|
|
1209
|
+
const uriMap = /* @__PURE__ */ new Map();
|
|
1210
|
+
function traverse(node, path = []) {
|
|
1211
|
+
if (!node || typeof node !== "object")
|
|
1212
|
+
return;
|
|
1213
|
+
if (path.length === 4) {
|
|
1214
|
+
const basePath = path.join("/");
|
|
1215
|
+
let pathString = "";
|
|
1216
|
+
if (node.pathParams) {
|
|
1217
|
+
let paths = null;
|
|
1218
|
+
if (node.pathParams?._def?.typeName !== void 0) {
|
|
1219
|
+
try {
|
|
1220
|
+
const shape = node.pathParams?.shape;
|
|
1221
|
+
paths = shape ? Object.keys(shape) : null;
|
|
1222
|
+
} catch {
|
|
1223
|
+
paths = null;
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
if (paths?.length) {
|
|
1227
|
+
pathString = paths.map((p) => `:${p}`).join("/");
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
uriMap.set(basePath, pathString);
|
|
1231
|
+
return;
|
|
1232
|
+
}
|
|
1233
|
+
for (const key in node) {
|
|
1234
|
+
if (!["_type", "fields"].includes(key)) {
|
|
1235
|
+
traverse(node[key], [...path, key]);
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
traverse(silgi.schemas, currentPath);
|
|
1240
|
+
silgi.uris = defu$1(silgi.uris, Object.fromEntries(uriMap));
|
|
1241
|
+
return uriMap;
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
async function readScanFile(silgi) {
|
|
1245
|
+
const path = resolve(silgi.options.silgi.serverDir, "scan.ts");
|
|
1246
|
+
const context = await promises.readFile(path, { encoding: "utf-8" });
|
|
1247
|
+
silgi.unimport = createUnimport(silgi.options.imports || {});
|
|
1248
|
+
await silgi.unimport.init();
|
|
1249
|
+
const injectedResult = await silgi.unimport.injectImports(context, path);
|
|
1250
|
+
if (!injectedResult) {
|
|
1251
|
+
throw new Error("Failed to inject imports");
|
|
1252
|
+
}
|
|
1253
|
+
const jiti = createJiti(silgi.options.rootDir, {
|
|
1254
|
+
fsCache: true,
|
|
1255
|
+
moduleCache: false,
|
|
1256
|
+
debug: silgi.options.debug,
|
|
1257
|
+
alias: silgi.options.alias
|
|
1258
|
+
});
|
|
1259
|
+
try {
|
|
1260
|
+
if (silgi.options.commandType === "prepare") {
|
|
1261
|
+
globalThis.$silgiSharedRuntimeConfig = silgi.options.runtimeConfig;
|
|
1262
|
+
injectedResult.code = `globalThis.$silgiSharedRuntimeConfig = ${JSON.stringify(silgi.options.runtimeConfig)};
|
|
1263
|
+
${injectedResult.code}`;
|
|
1264
|
+
injectedResult.code = injectedResult.code.replace(/runtimeConfig: \{\}/, `runtimeConfig: ${JSON.stringify(silgi.options.runtimeConfig)}`);
|
|
1265
|
+
}
|
|
1266
|
+
const scanFile = await jiti.evalModule(
|
|
1267
|
+
injectedResult.code,
|
|
1268
|
+
{
|
|
1269
|
+
filename: path,
|
|
1270
|
+
async: true,
|
|
1271
|
+
conditions: silgi.options.conditions
|
|
1272
|
+
},
|
|
1273
|
+
async (data, name) => {
|
|
1274
|
+
return (await silgi.unimport.injectImports(data, name)).code;
|
|
1275
|
+
}
|
|
1276
|
+
);
|
|
1277
|
+
silgi.uris = defu$1(silgi.uris, scanFile.uris) || {};
|
|
1278
|
+
silgi.schemas = defu$1(scanFile.schemas, scanFile.uris) || {};
|
|
1279
|
+
silgi.services = defu$1(scanFile.services, scanFile.uris) || {};
|
|
1280
|
+
silgi.shareds = defu$1(scanFile.shareds, scanFile.shareds) || {};
|
|
1281
|
+
silgi.modulesURIs = defu$1(scanFile.modulesURIs, scanFile.modulesURIs) || {};
|
|
1282
|
+
return {
|
|
1283
|
+
context,
|
|
1284
|
+
object: {
|
|
1285
|
+
schemas: scanFile.schemas,
|
|
1286
|
+
uris: scanFile.uris,
|
|
1287
|
+
services: scanFile.services,
|
|
1288
|
+
shareds: scanFile.shareds,
|
|
1289
|
+
modulesURIs: scanFile.modulesURIs
|
|
1290
|
+
},
|
|
1291
|
+
path
|
|
1292
|
+
};
|
|
1293
|
+
} catch (error) {
|
|
1294
|
+
if (silgi.options.debug) {
|
|
1295
|
+
console.error("Failed to read scan.ts file:", error);
|
|
1296
|
+
} else {
|
|
1297
|
+
if (error instanceof Error) {
|
|
1298
|
+
consola$1.withTag("silgi").info(error.message);
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
return {
|
|
1302
|
+
context,
|
|
1303
|
+
object: {
|
|
1304
|
+
schemas: {},
|
|
1305
|
+
uris: {},
|
|
1306
|
+
services: {},
|
|
1307
|
+
shareds: {},
|
|
1308
|
+
modulesURIs: {}
|
|
1309
|
+
},
|
|
1310
|
+
path
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
async function prepareServerFiles(silgi) {
|
|
1316
|
+
const importItems = {
|
|
1317
|
+
"silgi": {
|
|
1318
|
+
import: [
|
|
1319
|
+
{ name: "createSilgi", key: "createSilgi" },
|
|
1320
|
+
{ name: "createShared", key: "createShared" }
|
|
1321
|
+
],
|
|
1322
|
+
from: "silgi"
|
|
1323
|
+
},
|
|
1324
|
+
"silgi/types": {
|
|
1325
|
+
import: [
|
|
1326
|
+
{ name: "SilgiRuntimeOptions", type: true, key: "SilgiRuntimeOptions" },
|
|
1327
|
+
{ name: "FrameworkContext", type: true, key: "FrameworkContext" }
|
|
1328
|
+
],
|
|
1329
|
+
from: "silgi/types"
|
|
1330
|
+
},
|
|
1331
|
+
"#silgi/vfs": {
|
|
1332
|
+
import: [],
|
|
1333
|
+
from: "./vfs"
|
|
1334
|
+
},
|
|
1335
|
+
"configs.ts": {
|
|
1336
|
+
import: [
|
|
1337
|
+
{
|
|
1338
|
+
name: "cliConfigs",
|
|
1339
|
+
type: false,
|
|
1340
|
+
key: "cliConfigs"
|
|
1341
|
+
}
|
|
1342
|
+
],
|
|
1343
|
+
from: "./configs.ts"
|
|
1344
|
+
}
|
|
1345
|
+
};
|
|
1346
|
+
const scanned = {
|
|
1347
|
+
uris: {},
|
|
1348
|
+
services: [],
|
|
1349
|
+
shareds: [
|
|
1350
|
+
`createShared({
|
|
1351
|
+
modulesURIs,
|
|
1352
|
+
})`
|
|
1353
|
+
],
|
|
1354
|
+
schemas: [],
|
|
1355
|
+
modulesURIs: {},
|
|
1356
|
+
customImports: [],
|
|
1357
|
+
importItems
|
|
1358
|
+
};
|
|
1359
|
+
if (silgi.uris) {
|
|
1360
|
+
defu$1(scanned.uris, silgi.uris);
|
|
1361
|
+
}
|
|
1362
|
+
if (silgi.modulesURIs) {
|
|
1363
|
+
defu$1(scanned.modulesURIs, silgi.modulesURIs);
|
|
1364
|
+
}
|
|
1365
|
+
await silgi.callHook("prepare:scan.ts", scanned);
|
|
1366
|
+
if (importItems["#silgi/vfs"].import.length === 0) {
|
|
1367
|
+
delete importItems["#silgi/vfs"];
|
|
1368
|
+
}
|
|
1369
|
+
if (scanned.services.length > 0) {
|
|
1370
|
+
importItems.silgi.import.push({ name: "mergeServices", key: "mergeServices" });
|
|
1371
|
+
}
|
|
1372
|
+
if (scanned.shareds.length > 0) {
|
|
1373
|
+
importItems.silgi.import.push({ name: "mergeShared", key: "mergeShared" });
|
|
1374
|
+
}
|
|
1375
|
+
if (scanned.schemas.length > 0) {
|
|
1376
|
+
importItems.silgi.import.push({ name: "mergeSchemas", key: "mergeSchemas" });
|
|
1377
|
+
}
|
|
1378
|
+
for (const key in importItems) {
|
|
1379
|
+
importItems[key].import = deduplicateImportsByKey(importItems[key].import);
|
|
1380
|
+
}
|
|
1381
|
+
const importsContent = [
|
|
1382
|
+
...Object.entries(importItems).map(([_name, { from, import: imports }]) => {
|
|
1383
|
+
if (silgi.options.typescript.removeFileExtension) {
|
|
1384
|
+
from = from.replace(/\.(js|ts|mjs|cjs|jsx|tsx)$/, "");
|
|
1385
|
+
}
|
|
1386
|
+
return `import { ${imports.map(({ type, name }) => type ? `type ${name}` : name).join(", ")} } from '${from}'`;
|
|
1387
|
+
}),
|
|
1388
|
+
"",
|
|
1389
|
+
...scanned.customImports,
|
|
1390
|
+
""
|
|
1391
|
+
];
|
|
1392
|
+
const importData = [
|
|
1393
|
+
`export const uris = ${JSON.stringify(scanned.uris, null, 2)}`,
|
|
1394
|
+
"",
|
|
1395
|
+
`export const modulesURIs = ${JSON.stringify(scanned.modulesURIs, null, 2)}`,
|
|
1396
|
+
"",
|
|
1397
|
+
scanned.schemas.length > 0 ? "export const schemas = mergeSchemas([" : "export const schemas = {",
|
|
1398
|
+
...scanned.schemas.map((name) => {
|
|
1399
|
+
return ` ${name},`;
|
|
1400
|
+
}),
|
|
1401
|
+
scanned.schemas.length > 0 ? "])" : "}",
|
|
1402
|
+
"",
|
|
1403
|
+
scanned.services.length > 0 ? "export const services = mergeServices([" : "export const services = {",
|
|
1404
|
+
...scanned.services.map((name) => {
|
|
1405
|
+
return ` ${name},`;
|
|
1406
|
+
}),
|
|
1407
|
+
scanned.services.length > 0 ? "])" : "}",
|
|
1408
|
+
"",
|
|
1409
|
+
scanned.shareds.length > 0 ? "export const shareds = mergeShared([" : "export const shareds = {",
|
|
1410
|
+
...scanned.shareds.map((name) => {
|
|
1411
|
+
return ` ${name},`;
|
|
1412
|
+
}),
|
|
1413
|
+
scanned.shareds.length > 0 ? "])" : "}",
|
|
1414
|
+
""
|
|
1415
|
+
];
|
|
1416
|
+
await silgi.callHook("after:prepare:scan.ts", importData);
|
|
1417
|
+
importData.unshift(...importsContent);
|
|
1418
|
+
return importData;
|
|
1419
|
+
}
|
|
1420
|
+
function deduplicateImportsByKey(imports) {
|
|
1421
|
+
const seenKeys = /* @__PURE__ */ new Map();
|
|
1422
|
+
return imports.filter((item) => {
|
|
1423
|
+
if (seenKeys.has(item.key)) {
|
|
1424
|
+
return false;
|
|
1425
|
+
}
|
|
1426
|
+
seenKeys.set(item.key, true);
|
|
1427
|
+
return true;
|
|
1428
|
+
});
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
async function writeScanFiles(silgi) {
|
|
1432
|
+
const data = await prepareServerFiles(silgi);
|
|
1433
|
+
if (!silgi.errors.length) {
|
|
1434
|
+
await writeFile(
|
|
1435
|
+
resolve(silgi.options.silgi.serverDir, "scan.ts"),
|
|
1436
|
+
data.join("\n")
|
|
1437
|
+
);
|
|
1438
|
+
}
|
|
1439
|
+
await readScanFile(silgi);
|
|
1440
|
+
buildUriMap(silgi);
|
|
1441
|
+
parseServices(silgi);
|
|
1442
|
+
silgi.hook("prepare:scan.ts", (file) => {
|
|
1443
|
+
file.uris = {
|
|
1444
|
+
...file.uris,
|
|
1445
|
+
...silgi.uris
|
|
1446
|
+
};
|
|
1447
|
+
file.modulesURIs = {
|
|
1448
|
+
...file.modulesURIs,
|
|
1449
|
+
...silgi.modulesURIs
|
|
1450
|
+
};
|
|
1451
|
+
});
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1453
1454
|
async function createStorageCLI(silgi) {
|
|
1454
1455
|
const storage = createStorage();
|
|
1455
1456
|
const mounts = klona({
|
|
@@ -1674,7 +1675,7 @@ async function createSilgiCLI(config = {}, opts = {}) {
|
|
|
1674
1675
|
errors: [],
|
|
1675
1676
|
commands: {},
|
|
1676
1677
|
_requiredModules: {},
|
|
1677
|
-
logger: consola.withTag("silgi"),
|
|
1678
|
+
logger: consola$1.withTag("silgi"),
|
|
1678
1679
|
close: () => silgi.hooks.callHook("close", silgi),
|
|
1679
1680
|
storage: void 0,
|
|
1680
1681
|
scanModules: [],
|
|
@@ -1709,7 +1710,7 @@ async function createSilgiCLI(config = {}, opts = {}) {
|
|
|
1709
1710
|
}
|
|
1710
1711
|
await scanAndSyncOptions(silgi);
|
|
1711
1712
|
await scanModules$1(silgi);
|
|
1712
|
-
await
|
|
1713
|
+
await scanExportFile(silgi);
|
|
1713
1714
|
await installModules(silgi, true);
|
|
1714
1715
|
await writeScanFiles(silgi);
|
|
1715
1716
|
silgi.storage = await createStorageCLI(silgi);
|
|
@@ -2490,7 +2491,7 @@ const run = defineCommand({
|
|
|
2490
2491
|
rawArgs: ["--commands", "run"]
|
|
2491
2492
|
}) : void 0;
|
|
2492
2493
|
if (!data?.result?.silgi && args.active) {
|
|
2493
|
-
consola.error("Silgi not found");
|
|
2494
|
+
consola$1.error("Silgi not found");
|
|
2494
2495
|
return;
|
|
2495
2496
|
}
|
|
2496
2497
|
const silgi = useSilgiCLI();
|
|
@@ -2521,11 +2522,11 @@ const run = defineCommand({
|
|
|
2521
2522
|
}
|
|
2522
2523
|
} else {
|
|
2523
2524
|
if (!silgi) {
|
|
2524
|
-
consola.error("Silgi not found");
|
|
2525
|
+
consola$1.error("Silgi not found");
|
|
2525
2526
|
return;
|
|
2526
2527
|
}
|
|
2527
2528
|
if (Object.keys(cliJson).length === 0) {
|
|
2528
|
-
consola.warn("No commands found in cli.json");
|
|
2529
|
+
consola$1.warn("No commands found in cli.json");
|
|
2529
2530
|
return;
|
|
2530
2531
|
}
|
|
2531
2532
|
const allTags = Object.values(silgi.commands).reduce((acc, commandGroup) => {
|
package/dist/kit/index.mjs
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { h as hasError } from '../cli/compatibility.mjs';
|
|
1
|
+
import { tryUseSilgiCLI, useSilgiCLI, useSilgi, tryUseSilgi } from 'silgi/core';
|
|
3
2
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
4
3
|
import { resolvePath as resolvePath$1 } from 'mlly';
|
|
5
4
|
import fsp from 'node:fs/promises';
|
|
6
5
|
import consola, { consola as consola$1 } from 'consola';
|
|
7
6
|
import { relative, resolve, dirname, normalize, isAbsolute, join, parse, basename } from 'pathe';
|
|
8
|
-
import { useSilgiCLI, useSilgi, tryUseSilgiCLI, tryUseSilgi } from 'silgi/core';
|
|
9
7
|
import { colors } from 'consola/utils';
|
|
10
8
|
import { getProperty } from 'dot-prop';
|
|
11
9
|
import { hash as hash$1 } from 'ohash';
|
|
12
10
|
import { camelCase, snakeCase } from 'scule';
|
|
13
11
|
import { defu } from 'defu';
|
|
12
|
+
import { c as checkSilgiCompatibility } from '../cli/compatibility.mjs';
|
|
14
13
|
import { withLeadingSlash } from 'ufo';
|
|
15
14
|
import { existsSync, promises } from 'node:fs';
|
|
16
15
|
import { resolveAlias as resolveAlias$1 } from 'pathe/utils';
|
|
@@ -20,6 +19,14 @@ import { hash as hash$2 } from 'silgi/kit';
|
|
|
20
19
|
import 'semver/functions/satisfies.js';
|
|
21
20
|
import 'silgi/meta';
|
|
22
21
|
|
|
22
|
+
function hasError(type, silgi) {
|
|
23
|
+
silgi = silgi ?? tryUseSilgiCLI() ?? void 0;
|
|
24
|
+
if (silgi && silgi.errors.some((error) => error.type === type)) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
23
30
|
function directoryToURL(dir) {
|
|
24
31
|
return pathToFileURL(`${dir}/`);
|
|
25
32
|
}
|
|
@@ -563,4 +570,4 @@ function isValidIp(ip) {
|
|
|
563
570
|
return false;
|
|
564
571
|
}
|
|
565
572
|
|
|
566
|
-
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, getIpAddress, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, useSilgiRuntimeConfig, writeFile };
|
|
573
|
+
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, useSilgiRuntimeConfig, writeFile };
|
package/dist/meta/index.d.mts
CHANGED
package/dist/meta/index.d.ts
CHANGED