silgi 0.7.2 → 0.7.4
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/config/index.mjs +7 -167
- package/dist/cli/prepare.mjs +138 -4
- package/dist/cli/{loader.mjs → types.mjs} +163 -4
- package/dist/core/index.d.mts +1 -28
- package/dist/core/index.d.ts +1 -28
- package/dist/core/index.mjs +1 -135
- package/dist/meta/index.d.mts +1 -1
- package/dist/meta/index.d.ts +1 -1
- package/dist/presets/_resolve.d.ts +1 -1
- package/dist/runtime/internal/nuxt.d.ts +1 -1
- package/package.json +1 -1
package/dist/_chunks/index.mjs
CHANGED
|
@@ -1,177 +1,17 @@
|
|
|
1
|
-
export { l as loadOptions } from '../
|
|
2
|
-
import { promises, lstatSync } from 'node:fs';
|
|
3
|
-
import { defu } from 'defu';
|
|
4
|
-
import { resolve, dirname, join, isAbsolute, relative } from 'pathe';
|
|
5
|
-
import { readPackageJSON } from 'pkg-types';
|
|
6
|
-
import { relativeWithDot, resolveSilgiModule } from 'silgi/kit';
|
|
7
|
-
import { withTrailingSlash } from 'ufo';
|
|
1
|
+
export { l as loadOptions, s as silgiGenerateType } from '../types.mjs';
|
|
8
2
|
import 'c12';
|
|
9
3
|
import 'compatx';
|
|
10
4
|
import 'klona/full';
|
|
11
5
|
import 'std-env';
|
|
12
6
|
import 'consola';
|
|
13
7
|
import 'consola/utils';
|
|
8
|
+
import 'pathe';
|
|
14
9
|
import 'escape-string-regexp';
|
|
15
10
|
import 'mlly';
|
|
11
|
+
import 'node:fs';
|
|
16
12
|
import 'node:url';
|
|
13
|
+
import 'pkg-types';
|
|
14
|
+
import 'silgi/kit';
|
|
17
15
|
import 'silgi/runtime/meta';
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
return isAbsolute(p) && lstatSync(p).isFile() ? dirname(p) : p;
|
|
22
|
-
} catch {
|
|
23
|
-
}
|
|
24
|
-
return p;
|
|
25
|
-
}
|
|
26
|
-
function renderAttrs(obj) {
|
|
27
|
-
const attrs = [];
|
|
28
|
-
for (const key in obj) {
|
|
29
|
-
attrs.push(renderAttr(key, obj[key]));
|
|
30
|
-
}
|
|
31
|
-
return attrs.join(" ");
|
|
32
|
-
}
|
|
33
|
-
function renderAttr(key, value) {
|
|
34
|
-
return value ? `${key}="${value}"` : "";
|
|
35
|
-
}
|
|
36
|
-
async function silgiGenerateType(silgi) {
|
|
37
|
-
const rootDirWithSlash = withTrailingSlash(silgi.options.rootDir);
|
|
38
|
-
const tsConfigPath = resolve(
|
|
39
|
-
silgi.options.rootDir,
|
|
40
|
-
silgi.options.typescript.tsconfigPath
|
|
41
|
-
);
|
|
42
|
-
const tsconfigDir = dirname(tsConfigPath);
|
|
43
|
-
const include = /* @__PURE__ */ new Set([
|
|
44
|
-
relativeWithDot(tsconfigDir, join(silgi.options.build.typesDir, "silgi.d.ts")).replace(
|
|
45
|
-
/^(?=[^.])/,
|
|
46
|
-
"./"
|
|
47
|
-
),
|
|
48
|
-
join(relativeWithDot(tsconfigDir, silgi.options.rootDir), "**/*"),
|
|
49
|
-
...silgi.options.srcDir === silgi.options.rootDir ? [] : [join(relativeWithDot(tsconfigDir, silgi.options.srcDir), "**/*")]
|
|
50
|
-
]);
|
|
51
|
-
const exclude = /* @__PURE__ */ new Set([
|
|
52
|
-
// nitro generate output: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nitro.ts#L186
|
|
53
|
-
relativeWithDot(silgi.options.build.dir, resolve(silgi.options.rootDir, "dist"))
|
|
54
|
-
]);
|
|
55
|
-
for (const dir of silgi.options.modulesDir) {
|
|
56
|
-
exclude.add(relativeWithDot(silgi.options.build.dir, dir));
|
|
57
|
-
}
|
|
58
|
-
const moduleEntryPaths = [];
|
|
59
|
-
for (const m of silgi.scanModules) {
|
|
60
|
-
if (m.entryPath) {
|
|
61
|
-
moduleEntryPaths.push(getDirectory(m.entryPath));
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const modulePaths = await resolveSilgiModule(rootDirWithSlash, moduleEntryPaths);
|
|
65
|
-
for (const path of modulePaths) {
|
|
66
|
-
const relative2 = relativeWithDot(silgi.options.build.dir, path);
|
|
67
|
-
include.add(join(relative2, "runtime"));
|
|
68
|
-
exclude.add(join(relative2, "runtime/server"));
|
|
69
|
-
include.add(join(relative2, "dist/runtime"));
|
|
70
|
-
exclude.add(join(relative2, "dist/runtime/server"));
|
|
71
|
-
}
|
|
72
|
-
const tsConfig = defu(silgi.options.typescript?.tsConfig, {
|
|
73
|
-
compilerOptions: {
|
|
74
|
-
forceConsistentCasingInFileNames: true,
|
|
75
|
-
strict: silgi.options.typescript.strict,
|
|
76
|
-
noEmit: true,
|
|
77
|
-
target: "ESNext",
|
|
78
|
-
module: "ESNext",
|
|
79
|
-
moduleResolution: "Bundler",
|
|
80
|
-
allowJs: true,
|
|
81
|
-
resolveJsonModule: true,
|
|
82
|
-
jsx: "preserve",
|
|
83
|
-
allowSyntheticDefaultImports: true,
|
|
84
|
-
jsxFactory: "h",
|
|
85
|
-
jsxFragmentFactory: "Fragment",
|
|
86
|
-
allowImportingTsExtensions: true,
|
|
87
|
-
...silgi.options.typescript.customConditions ? { customConditions: ["silgiTypes"] } : {},
|
|
88
|
-
paths: {
|
|
89
|
-
"#silgiImports": [
|
|
90
|
-
relativeWithDot(tsconfigDir, join(silgi.options.build.typesDir, "silgi-imports"))
|
|
91
|
-
],
|
|
92
|
-
...silgi.scanModules.reduce((acc, m) => {
|
|
93
|
-
if (m.entryPath) {
|
|
94
|
-
acc[m.meta.name] = [relativeWithDot(tsconfigDir, m.entryPath)];
|
|
95
|
-
}
|
|
96
|
-
return acc;
|
|
97
|
-
}, {}),
|
|
98
|
-
...silgi.scanModules.reduce((acc, m) => {
|
|
99
|
-
if (m.entryPath) {
|
|
100
|
-
const directory = getDirectory(m.entryPath);
|
|
101
|
-
acc[`${m.meta.name}/*`] = [`${relativeWithDot(tsconfigDir, directory)}/*`];
|
|
102
|
-
}
|
|
103
|
-
return acc;
|
|
104
|
-
}, {})
|
|
105
|
-
// ...(silgi.options.typescript?.internalPaths
|
|
106
|
-
// ? {
|
|
107
|
-
// 'silgi/runtime': [
|
|
108
|
-
// relativeWithDot(tsconfigDir, join(runtimeDir, 'index')),
|
|
109
|
-
// ],
|
|
110
|
-
// '#internal/silgi': [
|
|
111
|
-
// relativeWithDot(tsconfigDir, join(runtimeDir, 'index')),
|
|
112
|
-
// ],
|
|
113
|
-
// 'silgi/runtime/*': [
|
|
114
|
-
// relativeWithDot(tsconfigDir, join(runtimeDir, '*')),
|
|
115
|
-
// ],
|
|
116
|
-
// '#internal/silgi/*': [
|
|
117
|
-
// relativeWithDot(tsconfigDir, join(runtimeDir, '*')),
|
|
118
|
-
// ],
|
|
119
|
-
// }
|
|
120
|
-
// : {}),
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
include: [...include],
|
|
124
|
-
exclude: [...exclude]
|
|
125
|
-
});
|
|
126
|
-
tsConfig.compilerOptions ||= {};
|
|
127
|
-
tsConfig.compilerOptions.paths ||= {};
|
|
128
|
-
tsConfig.include ||= [];
|
|
129
|
-
for (const alias in tsConfig.compilerOptions.paths) {
|
|
130
|
-
const paths = tsConfig.compilerOptions.paths[alias];
|
|
131
|
-
tsConfig.compilerOptions.paths[alias] = await Promise.all(
|
|
132
|
-
paths.map(async (path) => {
|
|
133
|
-
if (!isAbsolute(path)) {
|
|
134
|
-
return path;
|
|
135
|
-
}
|
|
136
|
-
const stats = await promises.stat(path).catch(
|
|
137
|
-
() => null
|
|
138
|
-
/* file does not exist */
|
|
139
|
-
);
|
|
140
|
-
return relativeWithDot(
|
|
141
|
-
tsconfigDir,
|
|
142
|
-
stats?.isFile() ? path.replace(/\b\.\w+$/g, "") : path
|
|
143
|
-
);
|
|
144
|
-
})
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
const references = [];
|
|
148
|
-
await Promise.all([...silgi.options.modules, ...silgi.options._modules].map(async (id) => {
|
|
149
|
-
if (typeof id !== "string") {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
const pkg = await readPackageJSON(id, { url: silgi.options.modulesDir }).catch(() => null);
|
|
153
|
-
references.push({ types: pkg?.name || id });
|
|
154
|
-
}));
|
|
155
|
-
const declarations = [];
|
|
156
|
-
await silgi.callHook("prepare:types", { references, declarations, tsConfig });
|
|
157
|
-
tsConfig.include = [...new Set(tsConfig.include.map((p) => isAbsolute(p) ? relativeWithDot(silgi.options.build.dir, p) : p))];
|
|
158
|
-
tsConfig.exclude = [...new Set(tsConfig.exclude.map((p) => isAbsolute(p) ? relativeWithDot(silgi.options.build.dir, p) : p))];
|
|
159
|
-
const _declarations = [
|
|
160
|
-
...references.map((ref) => {
|
|
161
|
-
if ("path" in ref && isAbsolute(ref.path)) {
|
|
162
|
-
ref.path = relative(silgi.options.build.dir, ref.path);
|
|
163
|
-
}
|
|
164
|
-
return `/// <reference ${renderAttrs(ref)} />`;
|
|
165
|
-
}),
|
|
166
|
-
...declarations,
|
|
167
|
-
"",
|
|
168
|
-
"export {}",
|
|
169
|
-
""
|
|
170
|
-
];
|
|
171
|
-
return {
|
|
172
|
-
declarations: _declarations,
|
|
173
|
-
tsConfig
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export { silgiGenerateType };
|
|
16
|
+
import 'ufo';
|
|
17
|
+
import 'defu';
|
package/dist/cli/prepare.mjs
CHANGED
|
@@ -2,34 +2,36 @@ import { defineCommand } from 'citty';
|
|
|
2
2
|
import { join, resolve, isAbsolute, relative, dirname, basename, extname } from 'pathe';
|
|
3
3
|
import { version } from 'silgi/meta';
|
|
4
4
|
import { runtimeDir } from 'silgi/runtime/meta';
|
|
5
|
-
import { promises, existsSync, readFileSync,
|
|
5
|
+
import { promises, existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
6
6
|
import { readdir } from 'node:fs/promises';
|
|
7
7
|
import { resolvePath, parseNodeModulePath, lookupNodeModuleSubpath, resolve as resolve$1 } from 'mlly';
|
|
8
8
|
import { resolveAlias } from 'pathe/utils';
|
|
9
|
-
import { silgiGenerateType, useSilgiCLI, SchemaParser, silgiCLICtx } from 'silgi/core';
|
|
10
9
|
import { relativeWithDot, isDirectory, writeFile, resolveAlias as resolveAlias$1, resolvePath as resolvePath$1, normalizeTemplate, useLogger } from 'silgi/kit';
|
|
11
10
|
import { toExports, scanExports, createUnimport } from 'unimport';
|
|
12
11
|
import { createJiti } from 'dev-jiti';
|
|
13
12
|
import { readPackageJSON } from 'pkg-types';
|
|
14
13
|
import { hash } from 'ohash';
|
|
14
|
+
import { s as silgiGenerateType, l as loadOptions } from './types.mjs';
|
|
15
15
|
import { consola } from 'consola';
|
|
16
16
|
import { createHooks, createDebugger } from 'hookable';
|
|
17
|
+
import { useSilgiCLI, silgiCLICtx } from 'silgi/core';
|
|
17
18
|
import { pascalCase } from 'scule';
|
|
18
19
|
import { h as hasInstalledModule } from './compatibility.mjs';
|
|
19
20
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
20
21
|
import { isRelative, withTrailingSlash } from 'ufo';
|
|
21
22
|
import { globby } from 'globby';
|
|
22
23
|
import ignore from 'ignore';
|
|
24
|
+
import { parseSync } from '@oxc-parser/wasm';
|
|
23
25
|
import { klona } from 'klona';
|
|
24
26
|
import { createStorage, builtinDrivers } from 'unstorage';
|
|
25
|
-
import { l as loadOptions } from './loader.mjs';
|
|
26
|
-
import 'semver/functions/satisfies.js';
|
|
27
27
|
import 'c12';
|
|
28
28
|
import 'compatx';
|
|
29
29
|
import 'klona/full';
|
|
30
30
|
import 'std-env';
|
|
31
31
|
import 'consola/utils';
|
|
32
32
|
import 'escape-string-regexp';
|
|
33
|
+
import 'defu';
|
|
34
|
+
import 'semver/functions/satisfies.js';
|
|
33
35
|
|
|
34
36
|
async function h3Framework(silgi, skip = false) {
|
|
35
37
|
if (silgi.options.preset !== "h3" && skip === false)
|
|
@@ -1081,6 +1083,138 @@ function resolveGroupSyntax(group) {
|
|
|
1081
1083
|
return groups;
|
|
1082
1084
|
}
|
|
1083
1085
|
|
|
1086
|
+
class SchemaParser {
|
|
1087
|
+
options = {
|
|
1088
|
+
debug: false
|
|
1089
|
+
};
|
|
1090
|
+
/**
|
|
1091
|
+
*
|
|
1092
|
+
*/
|
|
1093
|
+
constructor(options) {
|
|
1094
|
+
this.options = {
|
|
1095
|
+
...this.options,
|
|
1096
|
+
...options
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
parseExports(content, filePath) {
|
|
1100
|
+
const ast = parseSync(content, { sourceType: "module", sourceFilename: filePath });
|
|
1101
|
+
if (this.options.debug)
|
|
1102
|
+
writeFileSync(`${filePath}.ast.json`, JSON.stringify(ast.program, null, 2));
|
|
1103
|
+
return {
|
|
1104
|
+
exportVariables: (search, path) => this.parseTypeDeclarations(ast, search, path),
|
|
1105
|
+
parseInterfaceDeclarations: (search, path) => this.parseInterfaceDeclarations(ast, search, path)
|
|
1106
|
+
// parsePlugin: (path: string) => this.parsePlugin(ast, path),
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1109
|
+
parseVariableDeclaration(ast) {
|
|
1110
|
+
return ast.program.body.filter((i) => i.type === "ExportNamedDeclaration").filter((i) => i.declaration?.type === "VariableDeclaration");
|
|
1111
|
+
}
|
|
1112
|
+
parseTSInterfaceDeclaration(ast) {
|
|
1113
|
+
return ast.program.body.filter((i) => i.type === "ExportNamedDeclaration").filter((i) => i.declaration?.type === "TSInterfaceDeclaration");
|
|
1114
|
+
}
|
|
1115
|
+
parseTypeDeclarations(ast, find = "", path = "") {
|
|
1116
|
+
const data = [];
|
|
1117
|
+
for (const item of this.parseVariableDeclaration(ast)) {
|
|
1118
|
+
for (const declaration of item.declaration.declarations) {
|
|
1119
|
+
if (declaration.init?.callee?.name === find) {
|
|
1120
|
+
const options = {};
|
|
1121
|
+
if (declaration.init.arguments) {
|
|
1122
|
+
for (const argument of declaration.init.arguments) {
|
|
1123
|
+
for (const propertie of argument.properties) {
|
|
1124
|
+
if (propertie.key.name === "name")
|
|
1125
|
+
options.pluginName = propertie.value.value;
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
for (const key in declaration.init.properties) {
|
|
1130
|
+
const property = declaration.init.properties[key];
|
|
1131
|
+
if (property.type === "ObjectProperty") {
|
|
1132
|
+
if (property.key.name === "options") {
|
|
1133
|
+
for (const key2 in property.value.properties) {
|
|
1134
|
+
const option = property.value.properties[key2];
|
|
1135
|
+
if (option.type === "ObjectProperty") {
|
|
1136
|
+
options[option.key.name] = option.value.value;
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
options.type = false;
|
|
1143
|
+
data.push({
|
|
1144
|
+
exportName: declaration.id.name,
|
|
1145
|
+
options,
|
|
1146
|
+
// object: declaration.init,
|
|
1147
|
+
path
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
return data;
|
|
1153
|
+
}
|
|
1154
|
+
parseInterfaceDeclarations(ast, find = "", path = "") {
|
|
1155
|
+
const data = [];
|
|
1156
|
+
for (const item of this.parseTSInterfaceDeclaration(ast)) {
|
|
1157
|
+
if (!item?.declaration?.extends)
|
|
1158
|
+
continue;
|
|
1159
|
+
for (const declaration of item?.declaration?.extends) {
|
|
1160
|
+
if (declaration.expression.name === find) {
|
|
1161
|
+
const options = {};
|
|
1162
|
+
options.type = true;
|
|
1163
|
+
data.push({
|
|
1164
|
+
exportName: item.declaration.id.name,
|
|
1165
|
+
options,
|
|
1166
|
+
// object: declaration.init,
|
|
1167
|
+
path
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
return data;
|
|
1173
|
+
}
|
|
1174
|
+
// private parsePlugin(ast: any, path: string = '') {
|
|
1175
|
+
// const data = {
|
|
1176
|
+
// export: [],
|
|
1177
|
+
// name: '',
|
|
1178
|
+
// path: '',
|
|
1179
|
+
// } as DataTypePlugin
|
|
1180
|
+
// for (const item of this.parseVariableDeclaration(ast)) {
|
|
1181
|
+
// for (const declaration of item.declaration.declarations) {
|
|
1182
|
+
// if (declaration.init.callee?.name === 'defineSilgiModule') {
|
|
1183
|
+
// if (declaration.init.arguments) {
|
|
1184
|
+
// for (const argument of declaration.init.arguments) {
|
|
1185
|
+
// for (const propertie of argument.properties) {
|
|
1186
|
+
// if (propertie.key.name === 'name')
|
|
1187
|
+
// data.name = propertie.value.value
|
|
1188
|
+
// }
|
|
1189
|
+
// }
|
|
1190
|
+
// }
|
|
1191
|
+
// data.export.push({
|
|
1192
|
+
// name: data.name,
|
|
1193
|
+
// as: camelCase(`${data.name}DefineSilgiModule`),
|
|
1194
|
+
// type: false,
|
|
1195
|
+
// })
|
|
1196
|
+
// }
|
|
1197
|
+
// }
|
|
1198
|
+
// }
|
|
1199
|
+
// for (const item of this.parseTSInterfaceDeclaration(ast)) {
|
|
1200
|
+
// if (!item?.declaration?.extends)
|
|
1201
|
+
// continue
|
|
1202
|
+
// for (const declaration of item?.declaration?.extends) {
|
|
1203
|
+
// if (declaration.expression.name === 'ModuleOptions') {
|
|
1204
|
+
// data.export.push({
|
|
1205
|
+
// name: item.declaration.id.name,
|
|
1206
|
+
// as: camelCase(`${data.name}ModuleOptions`),
|
|
1207
|
+
// type: true,
|
|
1208
|
+
// })
|
|
1209
|
+
// }
|
|
1210
|
+
// // TODO add other plugins
|
|
1211
|
+
// }
|
|
1212
|
+
// }
|
|
1213
|
+
// data.path = path
|
|
1214
|
+
// return data
|
|
1215
|
+
// }
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1084
1218
|
async function scanFiles$1(silgi) {
|
|
1085
1219
|
const filePaths = /* @__PURE__ */ new Set();
|
|
1086
1220
|
const scannedPaths = [];
|
|
@@ -4,15 +4,16 @@ import { klona } from 'klona/full';
|
|
|
4
4
|
import { isDebug, isTest } from 'std-env';
|
|
5
5
|
import consola from 'consola';
|
|
6
6
|
import { colors } from 'consola/utils';
|
|
7
|
-
import { relative, join, resolve, isAbsolute } from 'pathe';
|
|
7
|
+
import { relative, join, resolve, isAbsolute, dirname } from 'pathe';
|
|
8
8
|
import escapeRE from 'escape-string-regexp';
|
|
9
9
|
import { resolveModuleExportNames, resolvePath as resolvePath$1 } from 'mlly';
|
|
10
|
-
import { existsSync } from 'node:fs';
|
|
10
|
+
import { existsSync, promises, lstatSync } from 'node:fs';
|
|
11
11
|
import { pathToFileURL } from 'node:url';
|
|
12
12
|
import { findWorkspaceDir, readPackageJSON } from 'pkg-types';
|
|
13
|
-
import { resolveSilgiPath, resolveAlias, resolvePath } from 'silgi/kit';
|
|
13
|
+
import { resolveSilgiPath, resolveAlias, resolvePath, relativeWithDot, resolveSilgiModule } from 'silgi/kit';
|
|
14
14
|
import { runtimeDir, pkgDir } from 'silgi/runtime/meta';
|
|
15
15
|
import { isRelative, withLeadingSlash, withTrailingSlash } from 'ufo';
|
|
16
|
+
import { defu } from 'defu';
|
|
16
17
|
|
|
17
18
|
const SilgiCLIDefaults = {
|
|
18
19
|
// General
|
|
@@ -578,4 +579,162 @@ async function _loadUserConfig(configOverrides = {}, opts = {}) {
|
|
|
578
579
|
return options;
|
|
579
580
|
}
|
|
580
581
|
|
|
581
|
-
|
|
582
|
+
function getDirectory(p) {
|
|
583
|
+
try {
|
|
584
|
+
return isAbsolute(p) && lstatSync(p).isFile() ? dirname(p) : p;
|
|
585
|
+
} catch {
|
|
586
|
+
}
|
|
587
|
+
return p;
|
|
588
|
+
}
|
|
589
|
+
function renderAttrs(obj) {
|
|
590
|
+
const attrs = [];
|
|
591
|
+
for (const key in obj) {
|
|
592
|
+
attrs.push(renderAttr(key, obj[key]));
|
|
593
|
+
}
|
|
594
|
+
return attrs.join(" ");
|
|
595
|
+
}
|
|
596
|
+
function renderAttr(key, value) {
|
|
597
|
+
return value ? `${key}="${value}"` : "";
|
|
598
|
+
}
|
|
599
|
+
async function silgiGenerateType(silgi) {
|
|
600
|
+
const rootDirWithSlash = withTrailingSlash(silgi.options.rootDir);
|
|
601
|
+
const tsConfigPath = resolve(
|
|
602
|
+
silgi.options.rootDir,
|
|
603
|
+
silgi.options.typescript.tsconfigPath
|
|
604
|
+
);
|
|
605
|
+
const tsconfigDir = dirname(tsConfigPath);
|
|
606
|
+
const include = /* @__PURE__ */ new Set([
|
|
607
|
+
relativeWithDot(tsconfigDir, join(silgi.options.build.typesDir, "silgi.d.ts")).replace(
|
|
608
|
+
/^(?=[^.])/,
|
|
609
|
+
"./"
|
|
610
|
+
),
|
|
611
|
+
join(relativeWithDot(tsconfigDir, silgi.options.rootDir), "**/*"),
|
|
612
|
+
...silgi.options.srcDir === silgi.options.rootDir ? [] : [join(relativeWithDot(tsconfigDir, silgi.options.srcDir), "**/*")]
|
|
613
|
+
]);
|
|
614
|
+
const exclude = /* @__PURE__ */ new Set([
|
|
615
|
+
// nitro generate output: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nitro.ts#L186
|
|
616
|
+
relativeWithDot(silgi.options.build.dir, resolve(silgi.options.rootDir, "dist"))
|
|
617
|
+
]);
|
|
618
|
+
for (const dir of silgi.options.modulesDir) {
|
|
619
|
+
exclude.add(relativeWithDot(silgi.options.build.dir, dir));
|
|
620
|
+
}
|
|
621
|
+
const moduleEntryPaths = [];
|
|
622
|
+
for (const m of silgi.scanModules) {
|
|
623
|
+
if (m.entryPath) {
|
|
624
|
+
moduleEntryPaths.push(getDirectory(m.entryPath));
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
const modulePaths = await resolveSilgiModule(rootDirWithSlash, moduleEntryPaths);
|
|
628
|
+
for (const path of modulePaths) {
|
|
629
|
+
const relative2 = relativeWithDot(silgi.options.build.dir, path);
|
|
630
|
+
include.add(join(relative2, "runtime"));
|
|
631
|
+
exclude.add(join(relative2, "runtime/server"));
|
|
632
|
+
include.add(join(relative2, "dist/runtime"));
|
|
633
|
+
exclude.add(join(relative2, "dist/runtime/server"));
|
|
634
|
+
}
|
|
635
|
+
const tsConfig = defu(silgi.options.typescript?.tsConfig, {
|
|
636
|
+
compilerOptions: {
|
|
637
|
+
forceConsistentCasingInFileNames: true,
|
|
638
|
+
strict: silgi.options.typescript.strict,
|
|
639
|
+
noEmit: true,
|
|
640
|
+
target: "ESNext",
|
|
641
|
+
module: "ESNext",
|
|
642
|
+
moduleResolution: "Bundler",
|
|
643
|
+
allowJs: true,
|
|
644
|
+
resolveJsonModule: true,
|
|
645
|
+
jsx: "preserve",
|
|
646
|
+
allowSyntheticDefaultImports: true,
|
|
647
|
+
jsxFactory: "h",
|
|
648
|
+
jsxFragmentFactory: "Fragment",
|
|
649
|
+
allowImportingTsExtensions: true,
|
|
650
|
+
...silgi.options.typescript.customConditions ? { customConditions: ["silgiTypes"] } : {},
|
|
651
|
+
paths: {
|
|
652
|
+
"#silgiImports": [
|
|
653
|
+
relativeWithDot(tsconfigDir, join(silgi.options.build.typesDir, "silgi-imports"))
|
|
654
|
+
],
|
|
655
|
+
...silgi.scanModules.reduce((acc, m) => {
|
|
656
|
+
if (m.entryPath) {
|
|
657
|
+
acc[m.meta.name] = [relativeWithDot(tsconfigDir, m.entryPath)];
|
|
658
|
+
}
|
|
659
|
+
return acc;
|
|
660
|
+
}, {}),
|
|
661
|
+
...silgi.scanModules.reduce((acc, m) => {
|
|
662
|
+
if (m.entryPath) {
|
|
663
|
+
const directory = getDirectory(m.entryPath);
|
|
664
|
+
acc[`${m.meta.name}/*`] = [`${relativeWithDot(tsconfigDir, directory)}/*`];
|
|
665
|
+
}
|
|
666
|
+
return acc;
|
|
667
|
+
}, {})
|
|
668
|
+
// ...(silgi.options.typescript?.internalPaths
|
|
669
|
+
// ? {
|
|
670
|
+
// 'silgi/runtime': [
|
|
671
|
+
// relativeWithDot(tsconfigDir, join(runtimeDir, 'index')),
|
|
672
|
+
// ],
|
|
673
|
+
// '#internal/silgi': [
|
|
674
|
+
// relativeWithDot(tsconfigDir, join(runtimeDir, 'index')),
|
|
675
|
+
// ],
|
|
676
|
+
// 'silgi/runtime/*': [
|
|
677
|
+
// relativeWithDot(tsconfigDir, join(runtimeDir, '*')),
|
|
678
|
+
// ],
|
|
679
|
+
// '#internal/silgi/*': [
|
|
680
|
+
// relativeWithDot(tsconfigDir, join(runtimeDir, '*')),
|
|
681
|
+
// ],
|
|
682
|
+
// }
|
|
683
|
+
// : {}),
|
|
684
|
+
}
|
|
685
|
+
},
|
|
686
|
+
include: [...include],
|
|
687
|
+
exclude: [...exclude]
|
|
688
|
+
});
|
|
689
|
+
tsConfig.compilerOptions ||= {};
|
|
690
|
+
tsConfig.compilerOptions.paths ||= {};
|
|
691
|
+
tsConfig.include ||= [];
|
|
692
|
+
for (const alias in tsConfig.compilerOptions.paths) {
|
|
693
|
+
const paths = tsConfig.compilerOptions.paths[alias];
|
|
694
|
+
tsConfig.compilerOptions.paths[alias] = await Promise.all(
|
|
695
|
+
paths.map(async (path) => {
|
|
696
|
+
if (!isAbsolute(path)) {
|
|
697
|
+
return path;
|
|
698
|
+
}
|
|
699
|
+
const stats = await promises.stat(path).catch(
|
|
700
|
+
() => null
|
|
701
|
+
/* file does not exist */
|
|
702
|
+
);
|
|
703
|
+
return relativeWithDot(
|
|
704
|
+
tsconfigDir,
|
|
705
|
+
stats?.isFile() ? path.replace(/\b\.\w+$/g, "") : path
|
|
706
|
+
);
|
|
707
|
+
})
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
const references = [];
|
|
711
|
+
await Promise.all([...silgi.options.modules, ...silgi.options._modules].map(async (id) => {
|
|
712
|
+
if (typeof id !== "string") {
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
const pkg = await readPackageJSON(id, { url: silgi.options.modulesDir }).catch(() => null);
|
|
716
|
+
references.push({ types: pkg?.name || id });
|
|
717
|
+
}));
|
|
718
|
+
const declarations = [];
|
|
719
|
+
await silgi.callHook("prepare:types", { references, declarations, tsConfig });
|
|
720
|
+
tsConfig.include = [...new Set(tsConfig.include.map((p) => isAbsolute(p) ? relativeWithDot(silgi.options.build.dir, p) : p))];
|
|
721
|
+
tsConfig.exclude = [...new Set(tsConfig.exclude.map((p) => isAbsolute(p) ? relativeWithDot(silgi.options.build.dir, p) : p))];
|
|
722
|
+
const _declarations = [
|
|
723
|
+
...references.map((ref) => {
|
|
724
|
+
if ("path" in ref && isAbsolute(ref.path)) {
|
|
725
|
+
ref.path = relative(silgi.options.build.dir, ref.path);
|
|
726
|
+
}
|
|
727
|
+
return `/// <reference ${renderAttrs(ref)} />`;
|
|
728
|
+
}),
|
|
729
|
+
...declarations,
|
|
730
|
+
"",
|
|
731
|
+
"export {}",
|
|
732
|
+
""
|
|
733
|
+
];
|
|
734
|
+
return {
|
|
735
|
+
declarations: _declarations,
|
|
736
|
+
tsConfig
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
export { loadOptions as l, silgiGenerateType as s };
|
package/dist/core/index.d.mts
CHANGED
|
@@ -37,33 +37,6 @@ type SilgiFetchOptions<R extends ValidRoute, M extends Method<R>> = {
|
|
|
37
37
|
type SilgiFetchClient = <R extends ValidRoute, M extends Method<R> = 'get' extends Method<R> ? 'get' : Method<R>>(url: R, options: SilgiFetchOptions<R, M>) => Promise<FetchResponseData<R, M>>;
|
|
38
38
|
declare function createSilgiFetch(options: FetchOptions | ((options: FetchOptions) => FetchOptions), localFetch?: typeof globalThis.$fetch): SilgiFetchClient;
|
|
39
39
|
|
|
40
|
-
interface Options {
|
|
41
|
-
debug?: boolean;
|
|
42
|
-
}
|
|
43
|
-
interface DataType {
|
|
44
|
-
exportName: string;
|
|
45
|
-
options: {
|
|
46
|
-
type: boolean;
|
|
47
|
-
pluginName?: string;
|
|
48
|
-
};
|
|
49
|
-
path: string;
|
|
50
|
-
}
|
|
51
|
-
declare class SchemaParser {
|
|
52
|
-
options: Options;
|
|
53
|
-
/**
|
|
54
|
-
*
|
|
55
|
-
*/
|
|
56
|
-
constructor(options?: Options);
|
|
57
|
-
parseExports(content: string, filePath: string): {
|
|
58
|
-
exportVariables: (search: string, path: string) => DataType[];
|
|
59
|
-
parseInterfaceDeclarations: (search: string, path: string) => DataType[];
|
|
60
|
-
};
|
|
61
|
-
private parseVariableDeclaration;
|
|
62
|
-
private parseTSInterfaceDeclaration;
|
|
63
|
-
private parseTypeDeclarations;
|
|
64
|
-
private parseInterfaceDeclarations;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
40
|
interface RouteTemplateValidator {
|
|
68
41
|
(value: string): boolean;
|
|
69
42
|
}
|
|
@@ -311,4 +284,4 @@ declare function useSilgiCLI(): SilgiCLI;
|
|
|
311
284
|
*/
|
|
312
285
|
declare function tryUseSilgiCLI(): SilgiCLI | null;
|
|
313
286
|
|
|
314
|
-
export { type BaseError, ErrorCategory, ErrorFactory, type ErrorMetadata, ErrorSeverity, HttpStatus,
|
|
287
|
+
export { type BaseError, ErrorCategory, ErrorFactory, type ErrorMetadata, ErrorSeverity, HttpStatus, SilgiError, createSchema, createService, createShared, createSilgi, createSilgiFetch, getEvent, isBaseError, mergeSchemas, mergeServices, mergeShared, parseURI, silgiCLICtx, silgiCtx, tryUseSilgi, tryUseSilgiCLI, useSilgi, useSilgiCLI };
|
package/dist/core/index.d.ts
CHANGED
|
@@ -37,33 +37,6 @@ type SilgiFetchOptions<R extends ValidRoute, M extends Method<R>> = {
|
|
|
37
37
|
type SilgiFetchClient = <R extends ValidRoute, M extends Method<R> = 'get' extends Method<R> ? 'get' : Method<R>>(url: R, options: SilgiFetchOptions<R, M>) => Promise<FetchResponseData<R, M>>;
|
|
38
38
|
declare function createSilgiFetch(options: FetchOptions | ((options: FetchOptions) => FetchOptions), localFetch?: typeof globalThis.$fetch): SilgiFetchClient;
|
|
39
39
|
|
|
40
|
-
interface Options {
|
|
41
|
-
debug?: boolean;
|
|
42
|
-
}
|
|
43
|
-
interface DataType {
|
|
44
|
-
exportName: string;
|
|
45
|
-
options: {
|
|
46
|
-
type: boolean;
|
|
47
|
-
pluginName?: string;
|
|
48
|
-
};
|
|
49
|
-
path: string;
|
|
50
|
-
}
|
|
51
|
-
declare class SchemaParser {
|
|
52
|
-
options: Options;
|
|
53
|
-
/**
|
|
54
|
-
*
|
|
55
|
-
*/
|
|
56
|
-
constructor(options?: Options);
|
|
57
|
-
parseExports(content: string, filePath: string): {
|
|
58
|
-
exportVariables: (search: string, path: string) => DataType[];
|
|
59
|
-
parseInterfaceDeclarations: (search: string, path: string) => DataType[];
|
|
60
|
-
};
|
|
61
|
-
private parseVariableDeclaration;
|
|
62
|
-
private parseTSInterfaceDeclaration;
|
|
63
|
-
private parseTypeDeclarations;
|
|
64
|
-
private parseInterfaceDeclarations;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
40
|
interface RouteTemplateValidator {
|
|
68
41
|
(value: string): boolean;
|
|
69
42
|
}
|
|
@@ -311,4 +284,4 @@ declare function useSilgiCLI(): SilgiCLI;
|
|
|
311
284
|
*/
|
|
312
285
|
declare function tryUseSilgiCLI(): SilgiCLI | null;
|
|
313
286
|
|
|
314
|
-
export { type BaseError, ErrorCategory, ErrorFactory, type ErrorMetadata, ErrorSeverity, HttpStatus,
|
|
287
|
+
export { type BaseError, ErrorCategory, ErrorFactory, type ErrorMetadata, ErrorSeverity, HttpStatus, SilgiError, createSchema, createService, createShared, createSilgi, createSilgiFetch, getEvent, isBaseError, mergeSchemas, mergeServices, mergeShared, parseURI, silgiCLICtx, silgiCtx, tryUseSilgi, tryUseSilgiCLI, useSilgi, useSilgiCLI };
|
package/dist/core/index.mjs
CHANGED
|
@@ -9,8 +9,6 @@ import { Buffer } from 'node:buffer';
|
|
|
9
9
|
import { klona } from 'klona';
|
|
10
10
|
import { createStorage as createStorage$1, builtinDrivers, prefixStorage } from 'unstorage';
|
|
11
11
|
import memoryDriver from 'unstorage/drivers/memory';
|
|
12
|
-
import { writeFileSync } from 'node:fs';
|
|
13
|
-
import { parseSync } from '@oxc-parser/wasm';
|
|
14
12
|
|
|
15
13
|
const common = defineUntypedSchema({
|
|
16
14
|
/**
|
|
@@ -648,138 +646,6 @@ function fillPath(path, params) {
|
|
|
648
646
|
return result;
|
|
649
647
|
}
|
|
650
648
|
|
|
651
|
-
class SchemaParser {
|
|
652
|
-
options = {
|
|
653
|
-
debug: false
|
|
654
|
-
};
|
|
655
|
-
/**
|
|
656
|
-
*
|
|
657
|
-
*/
|
|
658
|
-
constructor(options) {
|
|
659
|
-
this.options = {
|
|
660
|
-
...this.options,
|
|
661
|
-
...options
|
|
662
|
-
};
|
|
663
|
-
}
|
|
664
|
-
parseExports(content, filePath) {
|
|
665
|
-
const ast = parseSync(content, { sourceType: "module", sourceFilename: filePath });
|
|
666
|
-
if (this.options.debug)
|
|
667
|
-
writeFileSync(`${filePath}.ast.json`, JSON.stringify(ast.program, null, 2));
|
|
668
|
-
return {
|
|
669
|
-
exportVariables: (search, path) => this.parseTypeDeclarations(ast, search, path),
|
|
670
|
-
parseInterfaceDeclarations: (search, path) => this.parseInterfaceDeclarations(ast, search, path)
|
|
671
|
-
// parsePlugin: (path: string) => this.parsePlugin(ast, path),
|
|
672
|
-
};
|
|
673
|
-
}
|
|
674
|
-
parseVariableDeclaration(ast) {
|
|
675
|
-
return ast.program.body.filter((i) => i.type === "ExportNamedDeclaration").filter((i) => i.declaration?.type === "VariableDeclaration");
|
|
676
|
-
}
|
|
677
|
-
parseTSInterfaceDeclaration(ast) {
|
|
678
|
-
return ast.program.body.filter((i) => i.type === "ExportNamedDeclaration").filter((i) => i.declaration?.type === "TSInterfaceDeclaration");
|
|
679
|
-
}
|
|
680
|
-
parseTypeDeclarations(ast, find = "", path = "") {
|
|
681
|
-
const data = [];
|
|
682
|
-
for (const item of this.parseVariableDeclaration(ast)) {
|
|
683
|
-
for (const declaration of item.declaration.declarations) {
|
|
684
|
-
if (declaration.init?.callee?.name === find) {
|
|
685
|
-
const options = {};
|
|
686
|
-
if (declaration.init.arguments) {
|
|
687
|
-
for (const argument of declaration.init.arguments) {
|
|
688
|
-
for (const propertie of argument.properties) {
|
|
689
|
-
if (propertie.key.name === "name")
|
|
690
|
-
options.pluginName = propertie.value.value;
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
for (const key in declaration.init.properties) {
|
|
695
|
-
const property = declaration.init.properties[key];
|
|
696
|
-
if (property.type === "ObjectProperty") {
|
|
697
|
-
if (property.key.name === "options") {
|
|
698
|
-
for (const key2 in property.value.properties) {
|
|
699
|
-
const option = property.value.properties[key2];
|
|
700
|
-
if (option.type === "ObjectProperty") {
|
|
701
|
-
options[option.key.name] = option.value.value;
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
options.type = false;
|
|
708
|
-
data.push({
|
|
709
|
-
exportName: declaration.id.name,
|
|
710
|
-
options,
|
|
711
|
-
// object: declaration.init,
|
|
712
|
-
path
|
|
713
|
-
});
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
return data;
|
|
718
|
-
}
|
|
719
|
-
parseInterfaceDeclarations(ast, find = "", path = "") {
|
|
720
|
-
const data = [];
|
|
721
|
-
for (const item of this.parseTSInterfaceDeclaration(ast)) {
|
|
722
|
-
if (!item?.declaration?.extends)
|
|
723
|
-
continue;
|
|
724
|
-
for (const declaration of item?.declaration?.extends) {
|
|
725
|
-
if (declaration.expression.name === find) {
|
|
726
|
-
const options = {};
|
|
727
|
-
options.type = true;
|
|
728
|
-
data.push({
|
|
729
|
-
exportName: item.declaration.id.name,
|
|
730
|
-
options,
|
|
731
|
-
// object: declaration.init,
|
|
732
|
-
path
|
|
733
|
-
});
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
return data;
|
|
738
|
-
}
|
|
739
|
-
// private parsePlugin(ast: any, path: string = '') {
|
|
740
|
-
// const data = {
|
|
741
|
-
// export: [],
|
|
742
|
-
// name: '',
|
|
743
|
-
// path: '',
|
|
744
|
-
// } as DataTypePlugin
|
|
745
|
-
// for (const item of this.parseVariableDeclaration(ast)) {
|
|
746
|
-
// for (const declaration of item.declaration.declarations) {
|
|
747
|
-
// if (declaration.init.callee?.name === 'defineSilgiModule') {
|
|
748
|
-
// if (declaration.init.arguments) {
|
|
749
|
-
// for (const argument of declaration.init.arguments) {
|
|
750
|
-
// for (const propertie of argument.properties) {
|
|
751
|
-
// if (propertie.key.name === 'name')
|
|
752
|
-
// data.name = propertie.value.value
|
|
753
|
-
// }
|
|
754
|
-
// }
|
|
755
|
-
// }
|
|
756
|
-
// data.export.push({
|
|
757
|
-
// name: data.name,
|
|
758
|
-
// as: camelCase(`${data.name}DefineSilgiModule`),
|
|
759
|
-
// type: false,
|
|
760
|
-
// })
|
|
761
|
-
// }
|
|
762
|
-
// }
|
|
763
|
-
// }
|
|
764
|
-
// for (const item of this.parseTSInterfaceDeclaration(ast)) {
|
|
765
|
-
// if (!item?.declaration?.extends)
|
|
766
|
-
// continue
|
|
767
|
-
// for (const declaration of item?.declaration?.extends) {
|
|
768
|
-
// if (declaration.expression.name === 'ModuleOptions') {
|
|
769
|
-
// data.export.push({
|
|
770
|
-
// name: item.declaration.id.name,
|
|
771
|
-
// as: camelCase(`${data.name}ModuleOptions`),
|
|
772
|
-
// type: true,
|
|
773
|
-
// })
|
|
774
|
-
// }
|
|
775
|
-
// // TODO add other plugins
|
|
776
|
-
// }
|
|
777
|
-
// }
|
|
778
|
-
// data.path = path
|
|
779
|
-
// return data
|
|
780
|
-
// }
|
|
781
|
-
}
|
|
782
|
-
|
|
783
649
|
function silgi(event) {
|
|
784
650
|
return {
|
|
785
651
|
execute: (uriString, input) => {
|
|
@@ -940,4 +806,4 @@ function tryUseSilgiCLI() {
|
|
|
940
806
|
return silgiCLICtx.tryUse();
|
|
941
807
|
}
|
|
942
808
|
|
|
943
|
-
export { ErrorCategory, ErrorFactory, ErrorSeverity, HttpStatus,
|
|
809
|
+
export { ErrorCategory, ErrorFactory, ErrorSeverity, HttpStatus, SilgiError, createSchema, createService, createShared, createSilgi, createSilgiFetch, createStorage, getEvent, isBaseError, mergeSchemas, mergeServices, mergeShared, parseURI, silgi, silgiCLICtx, silgiCtx, tryUseSilgi, tryUseSilgiCLI, useSilgi, useSilgiCLI, useSilgiStorage };
|
package/dist/meta/index.d.mts
CHANGED
package/dist/meta/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { CompatibilityDateSpec } from 'compatx';
|
|
1
2
|
import type { SilgiPreset, SilgiPresetMeta } from 'silgi/types';
|
|
2
|
-
import { type CompatibilityDateSpec } from 'compatx';
|
|
3
3
|
export declare function resolvePreset(name: string, opts: {
|
|
4
4
|
static?: boolean;
|
|
5
5
|
compatibilityDate?: false | CompatibilityDateSpec;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { AsyncData, UseFetchOptions } from 'nuxt/app';
|
|
1
2
|
import type { FetchError } from 'ofetch';
|
|
2
3
|
import type { SilgiRouterTypes } from 'silgi/types';
|
|
3
|
-
import { type AsyncData, type UseFetchOptions } from 'nuxt/app';
|
|
4
4
|
type TrimAfterFourSlashes<T extends string> = T extends `/${infer S1}/${infer S2}/${infer S3}/${infer S4}/${infer _}` ? `/${S1}/${S2}/${S3}/${S4}` : T;
|
|
5
5
|
type AllPaths = SilgiRouterTypes extends {
|
|
6
6
|
keys: infer U;
|