silgi 0.37.40 → 0.37.42
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/build.mjs +2 -1
- package/dist/cli/build.mjs +13 -8
- package/dist/cli/common.mjs +13 -0
- package/dist/cli/config/index.mjs +2 -1
- package/dist/cli/dev.mjs +1 -1
- package/dist/cli/index.mjs +3 -2
- package/dist/cli/init.mjs +6 -2
- package/dist/cli/install.mjs +4 -2
- package/dist/cli/loader.mjs +588 -0
- package/dist/cli/prepare.mjs +3 -14
- package/dist/cli/reset.mjs +55 -0
- package/dist/cli/types.mjs +6 -587
- package/dist/cli/watch.mjs +4 -2
- package/dist/core/index.mjs +2 -1
- package/dist/types/index.d.mts +5 -3
- package/package.json +1 -1
package/dist/cli/types.mjs
CHANGED
|
@@ -1,590 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { resolveCompatibilityDatesFromEnv, formatDate, resolveCompatibilityDates } from 'compatx';
|
|
3
|
-
import { klona } from 'klona/full';
|
|
4
|
-
import { isTest, isDebug } from 'std-env';
|
|
5
|
-
import consola from 'consola';
|
|
6
|
-
import { colors } from 'consola/utils';
|
|
7
|
-
import { relative, join, resolve, dirname, isAbsolute } from 'pathe';
|
|
8
|
-
import escapeRE from 'escape-string-regexp';
|
|
9
|
-
import { resolveModuleExportNames } from 'mlly';
|
|
10
|
-
import { existsSync, promises, lstatSync } from 'node:fs';
|
|
11
|
-
import { findWorkspaceDir, readPackageJSON } from 'pkg-types';
|
|
12
|
-
import { resolveSilgiPath, relativeWithDot, resolveSilgiModule, isPresents } from 'silgi/kit';
|
|
13
|
-
import { runtimeDir, pkgDir } from 'silgi/runtime/meta';
|
|
14
|
-
import { withLeadingSlash, withTrailingSlash } from 'ufo';
|
|
1
|
+
import { promises, lstatSync } from 'node:fs';
|
|
15
2
|
import { defu } from 'defu';
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
schemaVendor: "zod",
|
|
21
|
-
// timing: isDebug,
|
|
22
|
-
logLevel: isTest ? 1 : 3,
|
|
23
|
-
appConfig: {},
|
|
24
|
-
appConfigFiles: [],
|
|
25
|
-
commandType: "prepare",
|
|
26
|
-
commands: [],
|
|
27
|
-
runtimeConfig: {
|
|
28
|
-
silgi: {}
|
|
29
|
-
},
|
|
30
|
-
storages: [],
|
|
31
|
-
devServer: {
|
|
32
|
-
watch: []
|
|
33
|
-
},
|
|
34
|
-
// Dirs
|
|
35
|
-
scanDirs: [],
|
|
36
|
-
build: {
|
|
37
|
-
dir: ".silgi",
|
|
38
|
-
typesDir: "{{ build.dir }}/types",
|
|
39
|
-
templates: []
|
|
40
|
-
},
|
|
41
|
-
output: {
|
|
42
|
-
dir: "{{ rootDir }}/.output",
|
|
43
|
-
serverDir: "{{ output.dir }}/server",
|
|
44
|
-
publicDir: "{{ output.dir }}/public"
|
|
45
|
-
},
|
|
46
|
-
serverDir: "{{ rootDir }}/server",
|
|
47
|
-
clientDir: "{{ rootDir }}/client",
|
|
48
|
-
migrationDir: "{{ rootDir }}/migration",
|
|
49
|
-
silgi: {
|
|
50
|
-
serverDir: "{{ serverDir }}/silgi",
|
|
51
|
-
clientDir: "{{ clientDir }}/silgi",
|
|
52
|
-
publicDir: "{{ silgi.serverDir }}/public",
|
|
53
|
-
utilsDir: "{{ silgi.serverDir }}/utils",
|
|
54
|
-
vfsDir: "{{ silgi.serverDir }}/vfs",
|
|
55
|
-
typesDir: "{{ silgi.serverDir }}/types"
|
|
56
|
-
},
|
|
57
|
-
// Codegen
|
|
58
|
-
codegen: {
|
|
59
|
-
env: {
|
|
60
|
-
safeList: [
|
|
61
|
-
["silgi", "version"]
|
|
62
|
-
]
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
// Modules
|
|
66
|
-
_modules: [],
|
|
67
|
-
modules: [],
|
|
68
|
-
future: {},
|
|
69
|
-
storage: {},
|
|
70
|
-
devStorage: {},
|
|
71
|
-
stub: false,
|
|
72
|
-
plugins: [],
|
|
73
|
-
imports: {
|
|
74
|
-
exclude: [],
|
|
75
|
-
dirs: [],
|
|
76
|
-
presets: [],
|
|
77
|
-
virtualImports: ["#silgiImports"]
|
|
78
|
-
},
|
|
79
|
-
ignore: [
|
|
80
|
-
"**/*.stories.{js,cts,mts,ts,jsx,tsx}",
|
|
81
|
-
"**/*.{spec,test}.{js,cts,mts,ts,jsx,tsx}",
|
|
82
|
-
"**/*.d.{cts,mts,ts}",
|
|
83
|
-
"**/.{pnpm-store,vercel,netlify,output,git,cache,data}",
|
|
84
|
-
".silgi",
|
|
85
|
-
"**/-*.*"
|
|
86
|
-
],
|
|
87
|
-
// Dev
|
|
88
|
-
dev: false,
|
|
89
|
-
// devServer: { watch: [] },
|
|
90
|
-
watchOptions: {
|
|
91
|
-
ignoreInitial: true,
|
|
92
|
-
ignored: [
|
|
93
|
-
"**/node_modules/**",
|
|
94
|
-
"**/.git/**",
|
|
95
|
-
"**/.silgi/**",
|
|
96
|
-
"**/.output/**",
|
|
97
|
-
"**/.vscode/**",
|
|
98
|
-
"**/.idea/**",
|
|
99
|
-
"**/.nuxt/**",
|
|
100
|
-
"**/.next/**",
|
|
101
|
-
"**/.gitignore",
|
|
102
|
-
"**/.gitattributes",
|
|
103
|
-
"**/assets/**",
|
|
104
|
-
"**/dist/**",
|
|
105
|
-
"**/build/**",
|
|
106
|
-
"**/coverage/**",
|
|
107
|
-
"**/test/**",
|
|
108
|
-
"**/tests/**",
|
|
109
|
-
"**/tmp/**"
|
|
110
|
-
]
|
|
111
|
-
},
|
|
112
|
-
// Advanced
|
|
113
|
-
typescript: {
|
|
114
|
-
strict: false,
|
|
115
|
-
generateTsConfig: true,
|
|
116
|
-
// generateRuntimeConfigTypes: true,
|
|
117
|
-
tsconfigPath: ".silgi/types/silgi.tsconfig.json",
|
|
118
|
-
tsConfig: {},
|
|
119
|
-
customConditions: [],
|
|
120
|
-
generateRuntimeConfigTypes: true,
|
|
121
|
-
removeFileExtension: false
|
|
122
|
-
},
|
|
123
|
-
conditions: [],
|
|
124
|
-
nodeModulesDirs: [],
|
|
125
|
-
hooks: {},
|
|
126
|
-
// Framework
|
|
127
|
-
framework: {
|
|
128
|
-
name: "h3",
|
|
129
|
-
version: ""
|
|
130
|
-
},
|
|
131
|
-
extensions: [".js", ".jsx", ".mjs", ".ts", ".tsx", ".vue"],
|
|
132
|
-
ignoreOptions: void 0,
|
|
133
|
-
// 3. party
|
|
134
|
-
apiFul: {},
|
|
135
|
-
// Kit
|
|
136
|
-
installPackages: {
|
|
137
|
-
dependencies: {},
|
|
138
|
-
devDependencies: {}
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
const fallbackCompatibilityDate = "2025-02-04";
|
|
143
|
-
async function resolveCompatibilityOptions(options) {
|
|
144
|
-
options.compatibilityDate = resolveCompatibilityDatesFromEnv(
|
|
145
|
-
options.compatibilityDate
|
|
146
|
-
);
|
|
147
|
-
if (!options.compatibilityDate.default) {
|
|
148
|
-
options.compatibilityDate.default = await _resolveDefault(options);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
let _fallbackInfoShown = false;
|
|
152
|
-
let _promptedUserToUpdate = false;
|
|
153
|
-
async function _resolveDefault(options) {
|
|
154
|
-
const _todayDate = formatDate(/* @__PURE__ */ new Date());
|
|
155
|
-
const consola$1 = consola.withTag("silgi");
|
|
156
|
-
consola$1.warn(`No valid compatibility date is specified.`);
|
|
157
|
-
const onFallback = () => {
|
|
158
|
-
if (!_fallbackInfoShown) {
|
|
159
|
-
consola$1.info(
|
|
160
|
-
[
|
|
161
|
-
`Using \`${fallbackCompatibilityDate}\` as fallback.`,
|
|
162
|
-
` Please specify compatibility date to avoid unwanted behavior changes:`,
|
|
163
|
-
` - Add \`compatibilityDate: '${_todayDate}'\` to the config file.`,
|
|
164
|
-
` - Or set \`COMPATIBILITY_DATE=${_todayDate}\` environment variable.`,
|
|
165
|
-
``
|
|
166
|
-
].join("\n")
|
|
167
|
-
);
|
|
168
|
-
_fallbackInfoShown = true;
|
|
169
|
-
}
|
|
170
|
-
return fallbackCompatibilityDate;
|
|
171
|
-
};
|
|
172
|
-
const shallUpdate = !_promptedUserToUpdate && await consola$1.prompt(
|
|
173
|
-
`Do you want to auto update config file to set ${colors.cyan(`compatibilityDate: '${_todayDate}'`)}?`,
|
|
174
|
-
{
|
|
175
|
-
type: "confirm",
|
|
176
|
-
default: true
|
|
177
|
-
}
|
|
178
|
-
);
|
|
179
|
-
_promptedUserToUpdate = true;
|
|
180
|
-
if (!shallUpdate) {
|
|
181
|
-
return onFallback();
|
|
182
|
-
}
|
|
183
|
-
const { updateConfig } = await import('c12/update');
|
|
184
|
-
const updateResult = await updateConfig({
|
|
185
|
-
configFile: "silgi.config",
|
|
186
|
-
cwd: options.rootDir,
|
|
187
|
-
async onCreate({ configFile }) {
|
|
188
|
-
const shallCreate = await consola$1.prompt(
|
|
189
|
-
`Do you want to initialize a new config in ${colors.cyan(relative(".", configFile))}?`,
|
|
190
|
-
{
|
|
191
|
-
type: "confirm",
|
|
192
|
-
default: true
|
|
193
|
-
}
|
|
194
|
-
);
|
|
195
|
-
if (shallCreate !== true) {
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
return _getDefaultNitroConfig();
|
|
199
|
-
},
|
|
200
|
-
async onUpdate(config) {
|
|
201
|
-
config.compatibilityDate = _todayDate;
|
|
202
|
-
}
|
|
203
|
-
}).catch((error) => {
|
|
204
|
-
consola$1.error(`Failed to update config: ${error.message}`);
|
|
205
|
-
return null;
|
|
206
|
-
});
|
|
207
|
-
if (updateResult?.configFile) {
|
|
208
|
-
consola$1.success(
|
|
209
|
-
`Compatibility date set to \`${_todayDate}\` in \`${relative(".", updateResult.configFile)}\``
|
|
210
|
-
);
|
|
211
|
-
return _todayDate;
|
|
212
|
-
}
|
|
213
|
-
return onFallback();
|
|
214
|
-
}
|
|
215
|
-
function _getDefaultNitroConfig() {
|
|
216
|
-
return (
|
|
217
|
-
/* js */
|
|
218
|
-
`
|
|
219
|
-
import { defineSilgiConfig } from 'silgi/config'
|
|
220
|
-
|
|
221
|
-
export default defineSilgiConfig({})
|
|
222
|
-
`
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
async function resolveImportsOptions(options) {
|
|
227
|
-
if (options.imports === false) {
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
options.imports.presets ??= [];
|
|
231
|
-
options.imports.presets.push(...getSilgiImportsPreset());
|
|
232
|
-
if (options.preset === "h3") {
|
|
233
|
-
const h3Exports = await resolveModuleExportNames("h3", {
|
|
234
|
-
url: import.meta.url
|
|
235
|
-
});
|
|
236
|
-
options.imports.presets ??= [];
|
|
237
|
-
options.imports.presets.push({
|
|
238
|
-
from: "h3",
|
|
239
|
-
imports: h3Exports.filter((n) => !/^[A-Z]/.test(n) && n !== "use")
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
options.imports.dirs ??= [];
|
|
243
|
-
options.imports.dirs.push(
|
|
244
|
-
...options.scanDirs.map((dir) => join(dir, "utils/**/*"))
|
|
245
|
-
);
|
|
246
|
-
if (Array.isArray(options.imports.exclude) && options.imports.exclude.length === 0) {
|
|
247
|
-
options.imports.exclude.push(/[/\\]\.git[/\\]/);
|
|
248
|
-
options.imports.exclude.push(options.build.dir);
|
|
249
|
-
const scanDirsInNodeModules = options.scanDirs.map((dir) => dir.match(/(?<=\/)node_modules\/(.+)$/)?.[1]).filter(Boolean);
|
|
250
|
-
options.imports.exclude.push(
|
|
251
|
-
scanDirsInNodeModules.length > 0 ? new RegExp(
|
|
252
|
-
`node_modules\\/(?!${scanDirsInNodeModules.map((dir) => escapeRE(dir)).join("|")})`
|
|
253
|
-
) : /[/\\]node_modules[/\\]/
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
function getSilgiImportsPreset() {
|
|
258
|
-
return [
|
|
259
|
-
// TODO: buraya bizim importlarimiz gelecek.
|
|
260
|
-
{
|
|
261
|
-
from: "silgi",
|
|
262
|
-
imports: [
|
|
263
|
-
"createShared",
|
|
264
|
-
"useSilgi",
|
|
265
|
-
"createService",
|
|
266
|
-
"createSchema",
|
|
267
|
-
"createRouter"
|
|
268
|
-
]
|
|
269
|
-
},
|
|
270
|
-
// {
|
|
271
|
-
// from: 'nitropack/runtime',
|
|
272
|
-
// imports: ['useRuntimeConfig', 'useAppConfig'],
|
|
273
|
-
// },
|
|
274
|
-
// {
|
|
275
|
-
// from: 'nitropack/runtime',
|
|
276
|
-
// imports: ['defineNitroPlugin', 'nitroPlugin'],
|
|
277
|
-
// },
|
|
278
|
-
// {
|
|
279
|
-
// from: 'nitropack/runtime/internal/cache',
|
|
280
|
-
// imports: [
|
|
281
|
-
// 'defineCachedFunction',
|
|
282
|
-
// 'defineCachedEventHandler',
|
|
283
|
-
// 'cachedFunction',
|
|
284
|
-
// 'cachedEventHandler',
|
|
285
|
-
// ],
|
|
286
|
-
// },
|
|
287
|
-
{
|
|
288
|
-
from: "silgi",
|
|
289
|
-
imports: ["useSilgiStorage"]
|
|
290
|
-
}
|
|
291
|
-
// {
|
|
292
|
-
// from: 'nitropack/runtime/internal/renderer',
|
|
293
|
-
// imports: ['defineRenderHandler'],
|
|
294
|
-
// },
|
|
295
|
-
// {
|
|
296
|
-
// from: 'nitropack/runtime/internal/meta',
|
|
297
|
-
// imports: ['defineRouteMeta'],
|
|
298
|
-
// },
|
|
299
|
-
// {
|
|
300
|
-
// from: 'nitropack/runtime/internal/route-rules',
|
|
301
|
-
// imports: ['getRouteRules'],
|
|
302
|
-
// },
|
|
303
|
-
// {
|
|
304
|
-
// from: 'nitropack/runtime/internal/context',
|
|
305
|
-
// imports: ['useEvent'],
|
|
306
|
-
// },
|
|
307
|
-
// {
|
|
308
|
-
// from: 'nitropack/runtime/internal/task',
|
|
309
|
-
// imports: ['defineTask', 'runTask'],
|
|
310
|
-
// },
|
|
311
|
-
// {
|
|
312
|
-
// from: 'nitropack/runtime/internal/error/utils',
|
|
313
|
-
// imports: ['defineNitroErrorHandler'],
|
|
314
|
-
// },
|
|
315
|
-
];
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
async function resolvePathOptions(options) {
|
|
319
|
-
options.rootDir = resolve(options.rootDir || ".");
|
|
320
|
-
options.workspaceDir = await findWorkspaceDir(options.rootDir).catch(
|
|
321
|
-
() => options.rootDir
|
|
322
|
-
);
|
|
323
|
-
options.srcDir = resolve(options.srcDir || options.rootDir);
|
|
324
|
-
for (const key of ["srcDir"]) {
|
|
325
|
-
options[key] = resolve(options.rootDir, options[key]);
|
|
326
|
-
}
|
|
327
|
-
options.build.dir = resolve(options.rootDir, options.build.dir);
|
|
328
|
-
options.build.typesDir = resolveSilgiPath(
|
|
329
|
-
options.build.typesDir || SilgiCLIDefaults.build.typesDir,
|
|
330
|
-
options,
|
|
331
|
-
options.rootDir
|
|
332
|
-
);
|
|
333
|
-
if (options.preset === "npm-package") {
|
|
334
|
-
const packageJsonPath = resolve(options.rootDir, "package.json");
|
|
335
|
-
const packageJson = await readPackageJSON(packageJsonPath);
|
|
336
|
-
if (packageJson.name === void 0) {
|
|
337
|
-
throw new Error("Package name is undefined");
|
|
338
|
-
}
|
|
339
|
-
options.alias ||= {};
|
|
340
|
-
options.alias[packageJson.name] = join(options.rootDir, "src/module");
|
|
341
|
-
options.alias[`${packageJson.name}/runtime`] = join(options.rootDir, "src/runtime");
|
|
342
|
-
options.alias[`${packageJson.name}/data`] = join(options.rootDir, "src/data");
|
|
343
|
-
options.alias[`${packageJson.name}/data/*`] = join(options.rootDir, "src/data/*");
|
|
344
|
-
options.alias[`${packageJson.name}/runtime/*`] = join(options.rootDir, "src/runtime/*");
|
|
345
|
-
options.alias[`${packageJson.name}/types`] = join(options.rootDir, "src/types");
|
|
346
|
-
}
|
|
347
|
-
if (options.stub) {
|
|
348
|
-
options.alias = {
|
|
349
|
-
...options.alias,
|
|
350
|
-
"silgi/runtime": join(runtimeDir),
|
|
351
|
-
"silgi/runtime/*": join(runtimeDir, "*")
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
options.alias = {
|
|
355
|
-
...options.alias,
|
|
356
|
-
"~/": join(options.srcDir, "/"),
|
|
357
|
-
"@/": join(options.srcDir, "/"),
|
|
358
|
-
"~~/": join(options.rootDir, "/"),
|
|
359
|
-
"@@/": join(options.rootDir, "/")
|
|
360
|
-
};
|
|
361
|
-
if (options.preset === "npm-package") {
|
|
362
|
-
options.alias = {
|
|
363
|
-
...options.alias
|
|
364
|
-
// '#silgi/app/': join(options.build.dir, '/'),
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
if (options.alias && typeof options.alias === "object") {
|
|
368
|
-
((options.typescript.tsConfig ??= {}).compilerOptions ??= {}).paths ??= {};
|
|
369
|
-
const paths = options.typescript.tsConfig.compilerOptions.paths;
|
|
370
|
-
for (const [key, value] of Object.entries(options.alias)) {
|
|
371
|
-
if (typeof paths === "object") {
|
|
372
|
-
paths[key] = [value];
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
if (options.typescript.tsConfig.compilerOptions?.paths && typeof options.typescript.tsConfig.compilerOptions.paths === "object") {
|
|
377
|
-
((options.typescript.tsConfig ??= {}).compilerOptions ??= {}).paths ??= {};
|
|
378
|
-
const paths = options.typescript.tsConfig.compilerOptions.paths;
|
|
379
|
-
for (const [key, value] of Object.entries(options.alias)) {
|
|
380
|
-
if (typeof paths === "object") {
|
|
381
|
-
paths[key] = [value];
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
options.modulesDir = [resolve(options.rootDir, "node_modules")];
|
|
386
|
-
options.output.dir = resolveSilgiPath(
|
|
387
|
-
options.output.dir || SilgiCLIDefaults.output.dir,
|
|
388
|
-
options,
|
|
389
|
-
options.rootDir
|
|
390
|
-
);
|
|
391
|
-
options.output.publicDir = resolveSilgiPath(
|
|
392
|
-
options.output.publicDir || SilgiCLIDefaults.output.publicDir,
|
|
393
|
-
options,
|
|
394
|
-
options.rootDir
|
|
395
|
-
);
|
|
396
|
-
options.output.serverDir = resolveSilgiPath(
|
|
397
|
-
options.output.serverDir || SilgiCLIDefaults.output.serverDir,
|
|
398
|
-
options,
|
|
399
|
-
options.rootDir
|
|
400
|
-
);
|
|
401
|
-
options.serverDir = resolveSilgiPath(
|
|
402
|
-
options.serverDir || SilgiCLIDefaults.serverDir,
|
|
403
|
-
options,
|
|
404
|
-
options.rootDir
|
|
405
|
-
);
|
|
406
|
-
options.clientDir = resolveSilgiPath(
|
|
407
|
-
options.clientDir || SilgiCLIDefaults.clientDir,
|
|
408
|
-
options,
|
|
409
|
-
options.rootDir
|
|
410
|
-
);
|
|
411
|
-
options.silgi.serverDir = resolveSilgiPath(
|
|
412
|
-
options.silgi.serverDir || SilgiCLIDefaults.silgi.serverDir,
|
|
413
|
-
options,
|
|
414
|
-
options.rootDir
|
|
415
|
-
);
|
|
416
|
-
options.silgi.clientDir = resolveSilgiPath(
|
|
417
|
-
options.silgi.clientDir || SilgiCLIDefaults.silgi.clientDir,
|
|
418
|
-
options,
|
|
419
|
-
options.rootDir
|
|
420
|
-
);
|
|
421
|
-
options.silgi.publicDir = resolveSilgiPath(
|
|
422
|
-
options.silgi.publicDir || SilgiCLIDefaults.silgi.publicDir,
|
|
423
|
-
options,
|
|
424
|
-
options.rootDir
|
|
425
|
-
);
|
|
426
|
-
options.silgi.utilsDir = resolveSilgiPath(
|
|
427
|
-
options.silgi.utilsDir || SilgiCLIDefaults.silgi.utilsDir,
|
|
428
|
-
options,
|
|
429
|
-
options.rootDir
|
|
430
|
-
);
|
|
431
|
-
options.silgi.vfsDir = resolveSilgiPath(
|
|
432
|
-
options.silgi.vfsDir || SilgiCLIDefaults.silgi.vfsDir,
|
|
433
|
-
options,
|
|
434
|
-
options.rootDir
|
|
435
|
-
);
|
|
436
|
-
options.silgi.typesDir = resolveSilgiPath(
|
|
437
|
-
options.silgi.typesDir || SilgiCLIDefaults.silgi.typesDir,
|
|
438
|
-
options,
|
|
439
|
-
options.rootDir
|
|
440
|
-
);
|
|
441
|
-
options.nodeModulesDirs.push(resolve(options.workspaceDir, "node_modules"));
|
|
442
|
-
options.nodeModulesDirs.push(resolve(options.rootDir, "node_modules"));
|
|
443
|
-
options.nodeModulesDirs.push(resolve(pkgDir, "node_modules"));
|
|
444
|
-
options.nodeModulesDirs.push(resolve(pkgDir, ".."));
|
|
445
|
-
options.nodeModulesDirs = [
|
|
446
|
-
...new Set(
|
|
447
|
-
options.nodeModulesDirs.map((dir) => resolve(options.rootDir, dir))
|
|
448
|
-
)
|
|
449
|
-
];
|
|
450
|
-
options.scanDirs.unshift(options.srcDir);
|
|
451
|
-
options.scanDirs = options.scanDirs.map(
|
|
452
|
-
(dir) => resolve(options.srcDir, dir)
|
|
453
|
-
);
|
|
454
|
-
options.scanDirs = [...new Set(options.scanDirs)];
|
|
455
|
-
options.appConfigFiles ??= [];
|
|
456
|
-
options.appConfigFiles = options.appConfigFiles.map((file) => _tryResolve(resolveSilgiPath(file, options))).filter(Boolean);
|
|
457
|
-
for (const dir of options.scanDirs) {
|
|
458
|
-
const configFile = _tryResolve("app.config", dir);
|
|
459
|
-
if (configFile && !options.appConfigFiles.includes(configFile)) {
|
|
460
|
-
options.appConfigFiles.push(configFile);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
function _tryResolve(path, base = ".", extensions = ["", ".js", ".ts", ".mjs", ".cjs", ".json"]) {
|
|
465
|
-
path = resolve(base, path);
|
|
466
|
-
if (existsSync(path)) {
|
|
467
|
-
return path;
|
|
468
|
-
}
|
|
469
|
-
for (const ext of extensions) {
|
|
470
|
-
const p = path + ext;
|
|
471
|
-
if (existsSync(p)) {
|
|
472
|
-
return p;
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
async function resolveStorageOptions(options) {
|
|
478
|
-
const fsMounts = {
|
|
479
|
-
root: resolve(options.rootDir),
|
|
480
|
-
src: resolve(options.srcDir),
|
|
481
|
-
build: resolve(options.build.dir),
|
|
482
|
-
cache: resolve(options.build.dir, "cache")
|
|
483
|
-
};
|
|
484
|
-
for (const p in fsMounts) {
|
|
485
|
-
options.devStorage[p] = options.devStorage[p] || {
|
|
486
|
-
driver: "fs",
|
|
487
|
-
readOnly: p === "root" || p === "src",
|
|
488
|
-
base: fsMounts[p]
|
|
489
|
-
};
|
|
490
|
-
}
|
|
491
|
-
if (options.dev && options.storage.data === void 0 && options.devStorage.data === void 0) {
|
|
492
|
-
options.devStorage.data = {
|
|
493
|
-
driver: "fs",
|
|
494
|
-
base: resolve(options.rootDir, ".data/kv")
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
async function resolveURLOptions(options) {
|
|
500
|
-
options.baseURL = withLeadingSlash(withTrailingSlash(options.baseURL));
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
const configResolvers = [
|
|
504
|
-
resolveCompatibilityOptions,
|
|
505
|
-
resolvePathOptions,
|
|
506
|
-
resolveImportsOptions,
|
|
507
|
-
// resolveRouteRulesOptions,
|
|
508
|
-
// resolveDatabaseOptions,
|
|
509
|
-
// resolveFetchOptions,
|
|
510
|
-
// resolveExportConditionsOptions,
|
|
511
|
-
// resolveRuntimeConfigOptions,
|
|
512
|
-
// resolveOpenAPIOptions,
|
|
513
|
-
resolveURLOptions,
|
|
514
|
-
// resolveAssetsOptions,
|
|
515
|
-
resolveStorageOptions
|
|
516
|
-
// resolveErrorOptions,
|
|
517
|
-
];
|
|
518
|
-
async function loadOptions(configOverrides = {}, opts = {}) {
|
|
519
|
-
const options = await _loadUserConfig(configOverrides, opts);
|
|
520
|
-
for (const resolver of configResolvers) {
|
|
521
|
-
await resolver(options);
|
|
522
|
-
}
|
|
523
|
-
return options;
|
|
524
|
-
}
|
|
525
|
-
async function _loadUserConfig(configOverrides = {}, opts = {}) {
|
|
526
|
-
const presetOverride = configOverrides.preset || process.env.SILGI_PRESET;
|
|
527
|
-
if (configOverrides.dev) ;
|
|
528
|
-
configOverrides = klona(configOverrides);
|
|
529
|
-
globalThis.defineSilgiConfig = globalThis.defineSilgiConfig || ((c) => c);
|
|
530
|
-
let compatibilityDate = configOverrides.compatibilityDate || opts.compatibilityDate || (process.env.SILGI_COMPATIBILITY_DATE || process.env.SERVER_COMPATIBILITY_DATE || process.env.COMPATIBILITY_DATE);
|
|
531
|
-
const { resolvePreset } = await import('silgi/presets');
|
|
532
|
-
const loadedConfig = await (opts.watch ? watchConfig : loadConfig)({
|
|
533
|
-
name: "silgi",
|
|
534
|
-
cwd: configOverrides.rootDir,
|
|
535
|
-
dotenv: configOverrides.dev,
|
|
536
|
-
extend: { extendKey: ["extends", "preset"] },
|
|
537
|
-
overrides: {
|
|
538
|
-
...configOverrides,
|
|
539
|
-
preset: presetOverride
|
|
540
|
-
},
|
|
541
|
-
async defaultConfig({ configs }) {
|
|
542
|
-
const getConf = (key) => configs.main?.[key] ?? configs.rc?.[key] ?? configs.packageJson?.[key];
|
|
543
|
-
if (!compatibilityDate) {
|
|
544
|
-
compatibilityDate = getConf("compatibilityDate");
|
|
545
|
-
}
|
|
546
|
-
return {
|
|
547
|
-
// typescript: {
|
|
548
|
-
// generateRuntimeConfigTypes:
|
|
549
|
-
// !framework?.name || framework.name === 'nitro',
|
|
550
|
-
// },
|
|
551
|
-
preset: presetOverride || (await resolvePreset("", {
|
|
552
|
-
static: getConf("static"),
|
|
553
|
-
compatibilityDate: compatibilityDate || fallbackCompatibilityDate
|
|
554
|
-
}))?._meta?.name
|
|
555
|
-
};
|
|
556
|
-
},
|
|
557
|
-
defaults: SilgiCLIDefaults,
|
|
558
|
-
jitiOptions: {
|
|
559
|
-
alias: {
|
|
560
|
-
"silgi/config": "silgi/config"
|
|
561
|
-
}
|
|
562
|
-
},
|
|
563
|
-
async resolve(id) {
|
|
564
|
-
const preset = await resolvePreset(id, {
|
|
565
|
-
static: configOverrides.static,
|
|
566
|
-
compatibilityDate: compatibilityDate || fallbackCompatibilityDate
|
|
567
|
-
});
|
|
568
|
-
if (preset) {
|
|
569
|
-
return {
|
|
570
|
-
config: klona(preset)
|
|
571
|
-
};
|
|
572
|
-
}
|
|
573
|
-
},
|
|
574
|
-
...opts.c12
|
|
575
|
-
});
|
|
576
|
-
delete globalThis.defineSilgiConfig;
|
|
577
|
-
const options = klona(loadedConfig.config);
|
|
578
|
-
options._config = configOverrides;
|
|
579
|
-
options._c12 = loadedConfig;
|
|
580
|
-
const _presetName = (loadedConfig.layers || []).find((l) => l.config?._meta?.name)?.config?._meta?.name || presetOverride;
|
|
581
|
-
options.preset = _presetName;
|
|
582
|
-
options.compatibilityDate = resolveCompatibilityDates(
|
|
583
|
-
compatibilityDate,
|
|
584
|
-
options.compatibilityDate
|
|
585
|
-
);
|
|
586
|
-
return options;
|
|
587
|
-
}
|
|
3
|
+
import { resolve, dirname, join, isAbsolute, relative } from 'pathe';
|
|
4
|
+
import { readPackageJSON } from 'pkg-types';
|
|
5
|
+
import { relativeWithDot, resolveSilgiModule, isPresents } from 'silgi/kit';
|
|
6
|
+
import { withTrailingSlash } from 'ufo';
|
|
588
7
|
|
|
589
8
|
function getDirectory(p) {
|
|
590
9
|
try {
|
|
@@ -809,4 +228,4 @@ async function silgiGenerateType(silgi) {
|
|
|
809
228
|
};
|
|
810
229
|
}
|
|
811
230
|
|
|
812
|
-
export {
|
|
231
|
+
export { silgiGenerateType as s };
|
package/dist/cli/watch.mjs
CHANGED
|
@@ -2,7 +2,8 @@ import { defineCommand, runCommand } from 'citty';
|
|
|
2
2
|
import consola from 'consola';
|
|
3
3
|
import { version } from 'silgi/meta';
|
|
4
4
|
import { w as watchDev } from './dev.mjs';
|
|
5
|
-
import {
|
|
5
|
+
import { c as commonArgs } from './common.mjs';
|
|
6
|
+
import { a as command$1 } from './prepare.mjs';
|
|
6
7
|
import 'chokidar';
|
|
7
8
|
import 'pathe';
|
|
8
9
|
import 'perfect-debounce';
|
|
@@ -34,7 +35,7 @@ import 'ignore';
|
|
|
34
35
|
import 'klona';
|
|
35
36
|
import 'unstorage';
|
|
36
37
|
import 'scule';
|
|
37
|
-
import './
|
|
38
|
+
import './loader.mjs';
|
|
38
39
|
import 'c12';
|
|
39
40
|
import 'compatx';
|
|
40
41
|
import 'klona/full';
|
|
@@ -45,6 +46,7 @@ import 'pkg-types';
|
|
|
45
46
|
import 'apiful/openapi';
|
|
46
47
|
import 'pathe/utils';
|
|
47
48
|
import 'untyped';
|
|
49
|
+
import './types.mjs';
|
|
48
50
|
import 'node:child_process';
|
|
49
51
|
|
|
50
52
|
const command = defineCommand({
|
package/dist/core/index.mjs
CHANGED
|
@@ -281,7 +281,8 @@ async function createSilgi(config) {
|
|
|
281
281
|
tag: "silgi"
|
|
282
282
|
})).withTag("silgi"),
|
|
283
283
|
captureError: config.captureError ?? (() => {
|
|
284
|
-
})
|
|
284
|
+
}),
|
|
285
|
+
meta: config.meta ?? {}
|
|
285
286
|
};
|
|
286
287
|
sharedRuntimeConfig(silgi.options.runtimeConfig);
|
|
287
288
|
if (!silgi.router) {
|
package/dist/types/index.d.mts
CHANGED
|
@@ -409,7 +409,6 @@ interface SilgiCLI {
|
|
|
409
409
|
unimport?: Unimport;
|
|
410
410
|
logger: ConsolaInstance;
|
|
411
411
|
close: () => Promise<void>;
|
|
412
|
-
updateConfig: (config: SilgiCLIDynamicConfig) => void | Promise<void>;
|
|
413
412
|
scanModules: Array<{
|
|
414
413
|
meta: ModuleMeta;
|
|
415
414
|
module: SilgiModule;
|
|
@@ -421,8 +420,8 @@ interface SilgiCLI {
|
|
|
421
420
|
options: SilgiCLIOptions;
|
|
422
421
|
_requiredModules: Record<string, boolean>;
|
|
423
422
|
adapters: Record<string, Adapter<Record<string, any>, TablesSchema, InferModelTypes<TablesSchema>>>;
|
|
423
|
+
meta: SilgiMeta;
|
|
424
424
|
}
|
|
425
|
-
type SilgiCLIDynamicConfig = Pick<SilgiCLIConfig, 'routeRules'>;
|
|
426
425
|
interface SilgiFrameworkInfo {
|
|
427
426
|
name?: 'silgi' | (string & {});
|
|
428
427
|
version?: string;
|
|
@@ -670,6 +669,8 @@ interface SilgiOptions {
|
|
|
670
669
|
|
|
671
670
|
type StandardHTTPMethod = 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE';
|
|
672
671
|
type HTTPMethod = SilgiRuntimeMethods extends Record<string, any> ? keyof SilgiRuntimeMethods | StandardHTTPMethod : StandardHTTPMethod;
|
|
672
|
+
interface SilgiMeta extends Record<string, unknown> {
|
|
673
|
+
}
|
|
673
674
|
interface SilgiRoute {
|
|
674
675
|
route: string;
|
|
675
676
|
method?: HTTPMethod;
|
|
@@ -698,6 +699,7 @@ interface Silgi {
|
|
|
698
699
|
envOptions: EnvOptions;
|
|
699
700
|
options: SilgiOptions & SilgiRuntimeOptions;
|
|
700
701
|
captureError: CaptureError;
|
|
702
|
+
meta: SilgiMeta;
|
|
701
703
|
}
|
|
702
704
|
interface SilgiConfig extends Partial<Omit<Silgi, 'options'>>, Partial<SilgiRuntimeOptions> {
|
|
703
705
|
options: DeepPartial<SilgiOptions>;
|
|
@@ -1191,4 +1193,4 @@ interface GraphQLJSON {
|
|
|
1191
1193
|
references: any;
|
|
1192
1194
|
}
|
|
1193
1195
|
|
|
1194
|
-
export type { AllPaths, AllPrefixes, AppConfig, Awaitable, BuildSilgi, CaptureError, CapturedErrorContext, CommandType, Commands, CustomRequestInit, DeepPartial, DeepRequired, DefaultHooks, DefineFrameworkOptions, DotenvOptions, EnvOptions, EventHandlerResponse, ExtendContext, ExtendShared, ExtractNamespace, ExtractPathParamKeys, ExtractPathParams, ExtractPrefix, ExtractRoute, GenImport, GenerateAppOptions, GraphQLJSON, HTTPMethod, HookResult, HttpMethod, LoadConfigOptions, MergeAll, MergedSilgiSchema, MethodSchemas, ModuleDefinition, ModuleHookContext, ModuleMeta, ModuleOptionsCustom, ModuleSetupInstallResult, ModuleSetupReturn, NamespacesForPrefix, NitroBuildInfo, RequiredServiceType, ResolvedModuleMeta, ResolvedModuleOptions, ResolvedSchema, ResolvedSchemaDefinition, ResolvedServiceDefinition, ResolvedSilgiTemplate, RouteConfig, RouteConfigService, RouterParams, Routers, RoutesForPrefixAndNamespace, ScanFile, Schema, ServiceHandler, ServiceHandlerInput, ServiceHandlerOutput, ServiceHandlerSource, ServiceMethods, ServiceSetup, Silgi, SilgiAppPlugin, SilgiCLI, SilgiCLIConfig,
|
|
1196
|
+
export type { AllPaths, AllPrefixes, AppConfig, Awaitable, BuildSilgi, CaptureError, CapturedErrorContext, CommandType, Commands, CustomRequestInit, DeepPartial, DeepRequired, DefaultHooks, DefineFrameworkOptions, DotenvOptions, EnvOptions, EventHandlerResponse, ExtendContext, ExtendShared, ExtractNamespace, ExtractPathParamKeys, ExtractPathParams, ExtractPrefix, ExtractRoute, GenImport, GenerateAppOptions, GraphQLJSON, HTTPMethod, HookResult, HttpMethod, LoadConfigOptions, MergeAll, MergedSilgiSchema, MethodSchemas, ModuleDefinition, ModuleHookContext, ModuleMeta, ModuleOptionsCustom, ModuleSetupInstallResult, ModuleSetupReturn, NamespacesForPrefix, NitroBuildInfo, RequiredServiceType, ResolvedModuleMeta, ResolvedModuleOptions, ResolvedSchema, ResolvedSchemaDefinition, ResolvedServiceDefinition, ResolvedSilgiTemplate, RouteConfig, RouteConfigService, RouterParams, Routers, RoutesForPrefixAndNamespace, ScanFile, Schema, ServiceHandler, ServiceHandlerInput, ServiceHandlerOutput, ServiceHandlerSource, ServiceMethods, ServiceSetup, Silgi, SilgiAppPlugin, SilgiCLI, SilgiCLIConfig, SilgiCLIHooks, SilgiCLIOptions, SilgiCommands, SilgiCompatibility, SilgiCompatibilityIssue, SilgiCompatibilityIssues, SilgiConfig, SilgiEvent, SilgiFetchClient, SilgiFetchOptions, SilgiFrameworkInfo, SilgiHooks, SilgiMeta, SilgiModule, SilgiModuleInput, SilgiModuleOptions, SilgiOptions, SilgiPreset, SilgiPresetMeta, SilgiRoute, SilgiRouterTypes, SilgiRuntimeActions, SilgiRuntimeConfig, SilgiRuntimeContext, SilgiRuntimeDefaultConfig, SilgiRuntimeHooks, SilgiRuntimeMethods, SilgiRuntimeOptions, SilgiRuntimeShareds, SilgiRuntimeSharedsExtend, SilgiSchema, SilgiStorageBase, SilgiTemplate, SilgiURL, StandardHTTPMethod, StorageConfig, StorageKeyGenerator, StorageKeyParams, StorageMounts, TSReference, TrimAfterFourSlashes, WithPathParams };
|