silgi 0.19.10 → 0.19.11
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/common.mjs +2208 -3
- package/dist/cli/config/index.mjs +1 -2
- package/dist/cli/dev.mjs +4 -6
- package/dist/cli/index.mjs +2 -2
- package/dist/cli/install.mjs +6 -9
- package/dist/cli/prepare.mjs +166 -47
- package/dist/cli/types.mjs +567 -6
- package/dist/meta/index.d.mts +1 -1
- package/dist/meta/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cli/loader.mjs +0 -568
- package/dist/cli/run.mjs +0 -121
- package/dist/cli/writeTypesAndFiles.mjs +0 -2211
package/dist/cli/types.mjs
CHANGED
|
@@ -1,9 +1,570 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { watchConfig, loadConfig } from 'c12';
|
|
2
|
+
import { resolveCompatibilityDatesFromEnv, formatDate, resolveCompatibilityDates } from 'compatx';
|
|
3
|
+
import { klona } from 'klona/full';
|
|
4
|
+
import { isDebug, isTest } 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 } from 'silgi/kit';
|
|
13
|
+
import { runtimeDir, pkgDir } from 'silgi/runtime/meta';
|
|
14
|
+
import { withLeadingSlash, withTrailingSlash } from 'ufo';
|
|
2
15
|
import { defu } from 'defu';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
16
|
+
|
|
17
|
+
const SilgiCLIDefaults = {
|
|
18
|
+
// General
|
|
19
|
+
debug: isDebug,
|
|
20
|
+
// timing: isDebug,
|
|
21
|
+
logLevel: isTest ? 1 : 3,
|
|
22
|
+
// runtimeConfig: { app: {}, silgi: {} },
|
|
23
|
+
appConfig: {},
|
|
24
|
+
appConfigFiles: [],
|
|
25
|
+
commandType: "prepare",
|
|
26
|
+
runtimeConfig: {
|
|
27
|
+
silgi: {
|
|
28
|
+
version: "0.0.1"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
serviceParseModules: [],
|
|
32
|
+
storages: [],
|
|
33
|
+
devServer: {
|
|
34
|
+
watch: []
|
|
35
|
+
},
|
|
36
|
+
// Dirs
|
|
37
|
+
scanDirs: [],
|
|
38
|
+
build: {
|
|
39
|
+
dir: ".silgi",
|
|
40
|
+
typesDir: "{{ build.dir }}/types",
|
|
41
|
+
templates: []
|
|
42
|
+
},
|
|
43
|
+
output: {
|
|
44
|
+
dir: "{{ rootDir }}/.output",
|
|
45
|
+
serverDir: "{{ output.dir }}/server",
|
|
46
|
+
publicDir: "{{ output.dir }}/public"
|
|
47
|
+
},
|
|
48
|
+
serverDir: "{{ rootDir }}/server",
|
|
49
|
+
clientDir: "{{ rootDir }}/client",
|
|
50
|
+
silgi: {
|
|
51
|
+
serverDir: "{{ serverDir }}/silgi",
|
|
52
|
+
clientDir: "{{ clientDir }}/silgi",
|
|
53
|
+
publicDir: "{{ silgi.serverDir }}/public",
|
|
54
|
+
utilsDir: "{{ silgi.serverDir }}/utils",
|
|
55
|
+
vfsDir: "{{ silgi.serverDir }}/vfs",
|
|
56
|
+
typesDir: "{{ silgi.serverDir }}/types"
|
|
57
|
+
},
|
|
58
|
+
// Modules
|
|
59
|
+
_modules: [],
|
|
60
|
+
modules: [],
|
|
61
|
+
routeRules: {},
|
|
62
|
+
// Features
|
|
63
|
+
// experimental: {},
|
|
64
|
+
future: {},
|
|
65
|
+
storage: {},
|
|
66
|
+
devStorage: {},
|
|
67
|
+
stub: false,
|
|
68
|
+
// bundledStorage: [],
|
|
69
|
+
// publicAssets: [],
|
|
70
|
+
// serverAssets: [],
|
|
71
|
+
plugins: [],
|
|
72
|
+
// tasks: {},
|
|
73
|
+
// scheduledTasks: {},
|
|
74
|
+
imports: {
|
|
75
|
+
exclude: [],
|
|
76
|
+
dirs: [],
|
|
77
|
+
presets: [],
|
|
78
|
+
virtualImports: ["#silgiImports"]
|
|
79
|
+
},
|
|
80
|
+
// virtual: {},
|
|
81
|
+
// compressPublicAssets: false,
|
|
82
|
+
ignore: [],
|
|
83
|
+
// Dev
|
|
84
|
+
dev: false,
|
|
85
|
+
// devServer: { watch: [] },
|
|
86
|
+
watchOptions: { ignoreInitial: true },
|
|
87
|
+
// devProxy: {},
|
|
88
|
+
// Logging
|
|
89
|
+
// logging: {
|
|
90
|
+
// compressedSizes: true,
|
|
91
|
+
// buildSuccess: true,
|
|
92
|
+
// },
|
|
93
|
+
// Routing
|
|
94
|
+
// baseURL: process.env.NITRO_APP_BASE_URL || '/',
|
|
95
|
+
// handlers: [],
|
|
96
|
+
// devHandlers: [],
|
|
97
|
+
// errorHandler: undefined,
|
|
98
|
+
// Advanced
|
|
99
|
+
typescript: {
|
|
100
|
+
strict: false,
|
|
101
|
+
generateTsConfig: true,
|
|
102
|
+
// generateRuntimeConfigTypes: true,
|
|
103
|
+
tsconfigPath: ".silgi/types/silgi.tsconfig.json",
|
|
104
|
+
tsConfig: {},
|
|
105
|
+
customConditions: [],
|
|
106
|
+
generateRuntimeConfigTypes: true,
|
|
107
|
+
removeFileExtension: false
|
|
108
|
+
},
|
|
109
|
+
conditions: [],
|
|
110
|
+
nodeModulesDirs: [],
|
|
111
|
+
// hooks: {},
|
|
112
|
+
commands: {},
|
|
113
|
+
// Framework
|
|
114
|
+
framework: {
|
|
115
|
+
name: "h3",
|
|
116
|
+
version: ""
|
|
117
|
+
},
|
|
118
|
+
extensions: [".js", ".jsx", ".mjs", ".ts", ".tsx", ".vue"],
|
|
119
|
+
ignoreOptions: void 0
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const fallbackCompatibilityDate = "2025-02-04";
|
|
123
|
+
async function resolveCompatibilityOptions(options) {
|
|
124
|
+
options.compatibilityDate = resolveCompatibilityDatesFromEnv(
|
|
125
|
+
options.compatibilityDate
|
|
126
|
+
);
|
|
127
|
+
if (!options.compatibilityDate.default) {
|
|
128
|
+
options.compatibilityDate.default = await _resolveDefault(options);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
let _fallbackInfoShown = false;
|
|
132
|
+
let _promptedUserToUpdate = false;
|
|
133
|
+
async function _resolveDefault(options) {
|
|
134
|
+
const _todayDate = formatDate(/* @__PURE__ */ new Date());
|
|
135
|
+
const consola$1 = consola.withTag("silgi");
|
|
136
|
+
consola$1.warn(`No valid compatibility date is specified.`);
|
|
137
|
+
const onFallback = () => {
|
|
138
|
+
if (!_fallbackInfoShown) {
|
|
139
|
+
consola$1.info(
|
|
140
|
+
[
|
|
141
|
+
`Using \`${fallbackCompatibilityDate}\` as fallback.`,
|
|
142
|
+
` Please specify compatibility date to avoid unwanted behavior changes:`,
|
|
143
|
+
` - Add \`compatibilityDate: '${_todayDate}'\` to the config file.`,
|
|
144
|
+
` - Or set \`COMPATIBILITY_DATE=${_todayDate}\` environment variable.`,
|
|
145
|
+
``
|
|
146
|
+
].join("\n")
|
|
147
|
+
);
|
|
148
|
+
_fallbackInfoShown = true;
|
|
149
|
+
}
|
|
150
|
+
return fallbackCompatibilityDate;
|
|
151
|
+
};
|
|
152
|
+
const shallUpdate = !_promptedUserToUpdate && await consola$1.prompt(
|
|
153
|
+
`Do you want to auto update config file to set ${colors.cyan(`compatibilityDate: '${_todayDate}'`)}?`,
|
|
154
|
+
{
|
|
155
|
+
type: "confirm",
|
|
156
|
+
default: true
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
_promptedUserToUpdate = true;
|
|
160
|
+
if (!shallUpdate) {
|
|
161
|
+
return onFallback();
|
|
162
|
+
}
|
|
163
|
+
const { updateConfig } = await import('c12/update');
|
|
164
|
+
const updateResult = await updateConfig({
|
|
165
|
+
configFile: "silgi.config",
|
|
166
|
+
cwd: options.rootDir,
|
|
167
|
+
async onCreate({ configFile }) {
|
|
168
|
+
const shallCreate = await consola$1.prompt(
|
|
169
|
+
`Do you want to initialize a new config in ${colors.cyan(relative(".", configFile))}?`,
|
|
170
|
+
{
|
|
171
|
+
type: "confirm",
|
|
172
|
+
default: true
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
if (shallCreate !== true) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
return _getDefaultNitroConfig();
|
|
179
|
+
},
|
|
180
|
+
async onUpdate(config) {
|
|
181
|
+
config.compatibilityDate = _todayDate;
|
|
182
|
+
}
|
|
183
|
+
}).catch((error) => {
|
|
184
|
+
consola$1.error(`Failed to update config: ${error.message}`);
|
|
185
|
+
return null;
|
|
186
|
+
});
|
|
187
|
+
if (updateResult?.configFile) {
|
|
188
|
+
consola$1.success(
|
|
189
|
+
`Compatibility date set to \`${_todayDate}\` in \`${relative(".", updateResult.configFile)}\``
|
|
190
|
+
);
|
|
191
|
+
return _todayDate;
|
|
192
|
+
}
|
|
193
|
+
return onFallback();
|
|
194
|
+
}
|
|
195
|
+
function _getDefaultNitroConfig() {
|
|
196
|
+
return (
|
|
197
|
+
/* js */
|
|
198
|
+
`
|
|
199
|
+
import { defineSilgiConfig } from 'silgi/config'
|
|
200
|
+
|
|
201
|
+
export default defineSilgiConfig({})
|
|
202
|
+
`
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async function resolveImportsOptions(options) {
|
|
207
|
+
if (options.imports === false) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
options.imports.presets ??= [];
|
|
211
|
+
options.imports.presets.push(...getSilgiImportsPreset());
|
|
212
|
+
if (options.preset === "h3") {
|
|
213
|
+
const h3Exports = await resolveModuleExportNames("h3", {
|
|
214
|
+
url: import.meta.url
|
|
215
|
+
});
|
|
216
|
+
options.imports.presets ??= [];
|
|
217
|
+
options.imports.presets.push({
|
|
218
|
+
from: "h3",
|
|
219
|
+
imports: h3Exports.filter((n) => !/^[A-Z]/.test(n) && n !== "use")
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
options.imports.dirs ??= [];
|
|
223
|
+
options.imports.dirs.push(
|
|
224
|
+
...options.scanDirs.map((dir) => join(dir, "utils/**/*"))
|
|
225
|
+
);
|
|
226
|
+
if (Array.isArray(options.imports.exclude) && options.imports.exclude.length === 0) {
|
|
227
|
+
options.imports.exclude.push(/[/\\]\.git[/\\]/);
|
|
228
|
+
options.imports.exclude.push(options.build.dir);
|
|
229
|
+
const scanDirsInNodeModules = options.scanDirs.map((dir) => dir.match(/(?<=\/)node_modules\/(.+)$/)?.[1]).filter(Boolean);
|
|
230
|
+
options.imports.exclude.push(
|
|
231
|
+
scanDirsInNodeModules.length > 0 ? new RegExp(
|
|
232
|
+
`node_modules\\/(?!${scanDirsInNodeModules.map((dir) => escapeRE(dir)).join("|")})`
|
|
233
|
+
) : /[/\\]node_modules[/\\]/
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function getSilgiImportsPreset() {
|
|
238
|
+
return [
|
|
239
|
+
// TODO: buraya bizim importlarimiz gelecek.
|
|
240
|
+
{
|
|
241
|
+
from: "silgi",
|
|
242
|
+
imports: [
|
|
243
|
+
"createShared",
|
|
244
|
+
"useSilgi",
|
|
245
|
+
"createService",
|
|
246
|
+
"createSchema"
|
|
247
|
+
]
|
|
248
|
+
},
|
|
249
|
+
// {
|
|
250
|
+
// from: 'nitropack/runtime',
|
|
251
|
+
// imports: ['useRuntimeConfig', 'useAppConfig'],
|
|
252
|
+
// },
|
|
253
|
+
// {
|
|
254
|
+
// from: 'nitropack/runtime',
|
|
255
|
+
// imports: ['defineNitroPlugin', 'nitroPlugin'],
|
|
256
|
+
// },
|
|
257
|
+
// {
|
|
258
|
+
// from: 'nitropack/runtime/internal/cache',
|
|
259
|
+
// imports: [
|
|
260
|
+
// 'defineCachedFunction',
|
|
261
|
+
// 'defineCachedEventHandler',
|
|
262
|
+
// 'cachedFunction',
|
|
263
|
+
// 'cachedEventHandler',
|
|
264
|
+
// ],
|
|
265
|
+
// },
|
|
266
|
+
{
|
|
267
|
+
from: "silgi/core",
|
|
268
|
+
imports: ["useSilgiStorage"]
|
|
269
|
+
}
|
|
270
|
+
// {
|
|
271
|
+
// from: 'nitropack/runtime/internal/renderer',
|
|
272
|
+
// imports: ['defineRenderHandler'],
|
|
273
|
+
// },
|
|
274
|
+
// {
|
|
275
|
+
// from: 'nitropack/runtime/internal/meta',
|
|
276
|
+
// imports: ['defineRouteMeta'],
|
|
277
|
+
// },
|
|
278
|
+
// {
|
|
279
|
+
// from: 'nitropack/runtime/internal/route-rules',
|
|
280
|
+
// imports: ['getRouteRules'],
|
|
281
|
+
// },
|
|
282
|
+
// {
|
|
283
|
+
// from: 'nitropack/runtime/internal/context',
|
|
284
|
+
// imports: ['useEvent'],
|
|
285
|
+
// },
|
|
286
|
+
// {
|
|
287
|
+
// from: 'nitropack/runtime/internal/task',
|
|
288
|
+
// imports: ['defineTask', 'runTask'],
|
|
289
|
+
// },
|
|
290
|
+
// {
|
|
291
|
+
// from: 'nitropack/runtime/internal/error/utils',
|
|
292
|
+
// imports: ['defineNitroErrorHandler'],
|
|
293
|
+
// },
|
|
294
|
+
];
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
async function resolvePathOptions(options) {
|
|
298
|
+
options.rootDir = resolve(options.rootDir || ".");
|
|
299
|
+
options.workspaceDir = await findWorkspaceDir(options.rootDir).catch(
|
|
300
|
+
() => options.rootDir
|
|
301
|
+
);
|
|
302
|
+
options.srcDir = resolve(options.srcDir || options.rootDir);
|
|
303
|
+
for (const key of ["srcDir"]) {
|
|
304
|
+
options[key] = resolve(options.rootDir, options[key]);
|
|
305
|
+
}
|
|
306
|
+
options.build.dir = resolve(options.rootDir, options.build.dir);
|
|
307
|
+
options.build.typesDir = resolveSilgiPath(
|
|
308
|
+
options.build.typesDir || SilgiCLIDefaults.build.typesDir,
|
|
309
|
+
options,
|
|
310
|
+
options.rootDir
|
|
311
|
+
);
|
|
312
|
+
if (options.preset === "npm-package") {
|
|
313
|
+
const packageJsonPath = resolve(options.rootDir, "package.json");
|
|
314
|
+
const packageJson = await readPackageJSON(packageJsonPath);
|
|
315
|
+
if (packageJson.name === void 0) {
|
|
316
|
+
throw new Error("Package name is undefined");
|
|
317
|
+
}
|
|
318
|
+
options.alias ||= {};
|
|
319
|
+
options.alias[packageJson.name] = join(options.rootDir, "src/module");
|
|
320
|
+
options.alias[`${packageJson.name}/runtime/`] = join(options.rootDir, "src/runtime");
|
|
321
|
+
options.alias[`${packageJson.name}/runtime/*`] = join(options.rootDir, "src/runtime/*");
|
|
322
|
+
options.alias[`${packageJson.name}/types`] = join(options.rootDir, "src/types");
|
|
323
|
+
}
|
|
324
|
+
if (options.stub) {
|
|
325
|
+
options.alias = {
|
|
326
|
+
...options.alias,
|
|
327
|
+
"silgi/runtime": join(runtimeDir),
|
|
328
|
+
"#internal/silgi": join(runtimeDir),
|
|
329
|
+
"silgi/runtime/*": join(runtimeDir, "*"),
|
|
330
|
+
"#internal/silgi/*": join(runtimeDir, "*")
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
options.alias = {
|
|
334
|
+
...options.alias,
|
|
335
|
+
"~/": join(options.srcDir, "/"),
|
|
336
|
+
"@/": join(options.srcDir, "/"),
|
|
337
|
+
"~~/": join(options.rootDir, "/"),
|
|
338
|
+
"@@/": join(options.rootDir, "/")
|
|
339
|
+
};
|
|
340
|
+
if (options.preset === "npm-package") {
|
|
341
|
+
options.alias = {
|
|
342
|
+
...options.alias,
|
|
343
|
+
"#silgi/app/": join(options.build.dir, "/")
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
if (options.alias && typeof options.alias === "object") {
|
|
347
|
+
((options.typescript.tsConfig ??= {}).compilerOptions ??= {}).paths ??= {};
|
|
348
|
+
const paths = options.typescript.tsConfig.compilerOptions.paths;
|
|
349
|
+
for (const [key, value] of Object.entries(options.alias)) {
|
|
350
|
+
if (typeof paths === "object") {
|
|
351
|
+
paths[key] = [value];
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
if (options.typescript.tsConfig.compilerOptions?.paths && typeof options.typescript.tsConfig.compilerOptions.paths === "object") {
|
|
356
|
+
((options.typescript.tsConfig ??= {}).compilerOptions ??= {}).paths ??= {};
|
|
357
|
+
const paths = options.typescript.tsConfig.compilerOptions.paths;
|
|
358
|
+
for (const [key, value] of Object.entries(options.alias)) {
|
|
359
|
+
if (typeof paths === "object") {
|
|
360
|
+
paths[key] = [value];
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
options.modulesDir = [resolve(options.rootDir, "node_modules")];
|
|
365
|
+
options.output.dir = resolveSilgiPath(
|
|
366
|
+
options.output.dir || SilgiCLIDefaults.output.dir,
|
|
367
|
+
options,
|
|
368
|
+
options.rootDir
|
|
369
|
+
);
|
|
370
|
+
options.output.publicDir = resolveSilgiPath(
|
|
371
|
+
options.output.publicDir || SilgiCLIDefaults.output.publicDir,
|
|
372
|
+
options,
|
|
373
|
+
options.rootDir
|
|
374
|
+
);
|
|
375
|
+
options.output.serverDir = resolveSilgiPath(
|
|
376
|
+
options.output.serverDir || SilgiCLIDefaults.output.serverDir,
|
|
377
|
+
options,
|
|
378
|
+
options.rootDir
|
|
379
|
+
);
|
|
380
|
+
options.serverDir = resolveSilgiPath(
|
|
381
|
+
options.serverDir || SilgiCLIDefaults.serverDir,
|
|
382
|
+
options,
|
|
383
|
+
options.rootDir
|
|
384
|
+
);
|
|
385
|
+
options.clientDir = resolveSilgiPath(
|
|
386
|
+
options.clientDir || SilgiCLIDefaults.clientDir,
|
|
387
|
+
options,
|
|
388
|
+
options.rootDir
|
|
389
|
+
);
|
|
390
|
+
options.silgi.serverDir = resolveSilgiPath(
|
|
391
|
+
options.silgi.serverDir || SilgiCLIDefaults.silgi.serverDir,
|
|
392
|
+
options,
|
|
393
|
+
options.rootDir
|
|
394
|
+
);
|
|
395
|
+
options.silgi.clientDir = resolveSilgiPath(
|
|
396
|
+
options.silgi.clientDir || SilgiCLIDefaults.silgi.clientDir,
|
|
397
|
+
options,
|
|
398
|
+
options.rootDir
|
|
399
|
+
);
|
|
400
|
+
options.silgi.publicDir = resolveSilgiPath(
|
|
401
|
+
options.silgi.publicDir || SilgiCLIDefaults.silgi.publicDir,
|
|
402
|
+
options,
|
|
403
|
+
options.rootDir
|
|
404
|
+
);
|
|
405
|
+
options.silgi.utilsDir = resolveSilgiPath(
|
|
406
|
+
options.silgi.utilsDir || SilgiCLIDefaults.silgi.utilsDir,
|
|
407
|
+
options,
|
|
408
|
+
options.rootDir
|
|
409
|
+
);
|
|
410
|
+
options.silgi.vfsDir = resolveSilgiPath(
|
|
411
|
+
options.silgi.vfsDir || SilgiCLIDefaults.silgi.vfsDir,
|
|
412
|
+
options,
|
|
413
|
+
options.rootDir
|
|
414
|
+
);
|
|
415
|
+
options.silgi.typesDir = resolveSilgiPath(
|
|
416
|
+
options.silgi.typesDir || SilgiCLIDefaults.silgi.typesDir,
|
|
417
|
+
options,
|
|
418
|
+
options.rootDir
|
|
419
|
+
);
|
|
420
|
+
options.nodeModulesDirs.push(resolve(options.workspaceDir, "node_modules"));
|
|
421
|
+
options.nodeModulesDirs.push(resolve(options.rootDir, "node_modules"));
|
|
422
|
+
options.nodeModulesDirs.push(resolve(pkgDir, "node_modules"));
|
|
423
|
+
options.nodeModulesDirs.push(resolve(pkgDir, ".."));
|
|
424
|
+
options.nodeModulesDirs = [
|
|
425
|
+
...new Set(
|
|
426
|
+
options.nodeModulesDirs.map((dir) => resolve(options.rootDir, dir))
|
|
427
|
+
)
|
|
428
|
+
];
|
|
429
|
+
options.scanDirs.unshift(options.srcDir);
|
|
430
|
+
options.scanDirs = options.scanDirs.map(
|
|
431
|
+
(dir) => resolve(options.srcDir, dir)
|
|
432
|
+
);
|
|
433
|
+
options.scanDirs = [...new Set(options.scanDirs)];
|
|
434
|
+
options.appConfigFiles ??= [];
|
|
435
|
+
options.appConfigFiles = options.appConfigFiles.map((file) => _tryResolve(resolveSilgiPath(file, options))).filter(Boolean);
|
|
436
|
+
for (const dir of options.scanDirs) {
|
|
437
|
+
const configFile = _tryResolve("app.config", dir);
|
|
438
|
+
if (configFile && !options.appConfigFiles.includes(configFile)) {
|
|
439
|
+
options.appConfigFiles.push(configFile);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
function _tryResolve(path, base = ".", extensions = ["", ".js", ".ts", ".mjs", ".cjs", ".json"]) {
|
|
444
|
+
path = resolve(base, path);
|
|
445
|
+
if (existsSync(path)) {
|
|
446
|
+
return path;
|
|
447
|
+
}
|
|
448
|
+
for (const ext of extensions) {
|
|
449
|
+
const p = path + ext;
|
|
450
|
+
if (existsSync(p)) {
|
|
451
|
+
return p;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
async function resolveStorageOptions(options) {
|
|
457
|
+
const fsMounts = {
|
|
458
|
+
root: resolve(options.rootDir),
|
|
459
|
+
src: resolve(options.srcDir),
|
|
460
|
+
build: resolve(options.build.dir),
|
|
461
|
+
cache: resolve(options.build.dir, "cache")
|
|
462
|
+
};
|
|
463
|
+
for (const p in fsMounts) {
|
|
464
|
+
options.devStorage[p] = options.devStorage[p] || {
|
|
465
|
+
driver: "fs",
|
|
466
|
+
readOnly: p === "root" || p === "src",
|
|
467
|
+
base: fsMounts[p]
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
if (options.dev && options.storage.data === void 0 && options.devStorage.data === void 0) {
|
|
471
|
+
options.devStorage.data = {
|
|
472
|
+
driver: "fs",
|
|
473
|
+
base: resolve(options.rootDir, ".data/kv")
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
async function resolveURLOptions(options) {
|
|
479
|
+
options.baseURL = withLeadingSlash(withTrailingSlash(options.baseURL));
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
const configResolvers = [
|
|
483
|
+
resolveCompatibilityOptions,
|
|
484
|
+
resolvePathOptions,
|
|
485
|
+
resolveImportsOptions,
|
|
486
|
+
// resolveRouteRulesOptions,
|
|
487
|
+
// resolveDatabaseOptions,
|
|
488
|
+
// resolveFetchOptions,
|
|
489
|
+
// resolveExportConditionsOptions,
|
|
490
|
+
// resolveRuntimeConfigOptions,
|
|
491
|
+
// resolveOpenAPIOptions,
|
|
492
|
+
resolveURLOptions,
|
|
493
|
+
// resolveAssetsOptions,
|
|
494
|
+
resolveStorageOptions
|
|
495
|
+
// resolveErrorOptions,
|
|
496
|
+
];
|
|
497
|
+
async function loadOptions(configOverrides = {}, opts = {}) {
|
|
498
|
+
const options = await _loadUserConfig(configOverrides, opts);
|
|
499
|
+
for (const resolver of configResolvers) {
|
|
500
|
+
await resolver(options);
|
|
501
|
+
}
|
|
502
|
+
return options;
|
|
503
|
+
}
|
|
504
|
+
async function _loadUserConfig(configOverrides = {}, opts = {}) {
|
|
505
|
+
const presetOverride = configOverrides.preset || process.env.SILGI_PRESET;
|
|
506
|
+
if (configOverrides.dev) ;
|
|
507
|
+
configOverrides = klona(configOverrides);
|
|
508
|
+
globalThis.defineSilgiConfig = globalThis.defineSilgiConfig || ((c) => c);
|
|
509
|
+
let compatibilityDate = configOverrides.compatibilityDate || opts.compatibilityDate || (process.env.SILGI_COMPATIBILITY_DATE || process.env.SERVER_COMPATIBILITY_DATE || process.env.COMPATIBILITY_DATE);
|
|
510
|
+
const { resolvePreset } = await import('silgi/presets');
|
|
511
|
+
const loadedConfig = await (opts.watch ? watchConfig : loadConfig)({
|
|
512
|
+
name: "silgi",
|
|
513
|
+
cwd: configOverrides.rootDir,
|
|
514
|
+
dotenv: configOverrides.dev,
|
|
515
|
+
extend: { extendKey: ["extends", "preset"] },
|
|
516
|
+
overrides: {
|
|
517
|
+
...configOverrides,
|
|
518
|
+
preset: presetOverride
|
|
519
|
+
},
|
|
520
|
+
async defaultConfig({ configs }) {
|
|
521
|
+
const getConf = (key) => configs.main?.[key] ?? configs.rc?.[key] ?? configs.packageJson?.[key];
|
|
522
|
+
if (!compatibilityDate) {
|
|
523
|
+
compatibilityDate = getConf("compatibilityDate");
|
|
524
|
+
}
|
|
525
|
+
return {
|
|
526
|
+
// typescript: {
|
|
527
|
+
// generateRuntimeConfigTypes:
|
|
528
|
+
// !framework?.name || framework.name === 'nitro',
|
|
529
|
+
// },
|
|
530
|
+
preset: presetOverride || (await resolvePreset("", {
|
|
531
|
+
static: getConf("static"),
|
|
532
|
+
compatibilityDate: compatibilityDate || fallbackCompatibilityDate
|
|
533
|
+
}))?._meta?.name
|
|
534
|
+
};
|
|
535
|
+
},
|
|
536
|
+
defaults: SilgiCLIDefaults,
|
|
537
|
+
jitiOptions: {
|
|
538
|
+
alias: {
|
|
539
|
+
"silgi": "silgi/config",
|
|
540
|
+
"silgi/config": "silgi/config"
|
|
541
|
+
}
|
|
542
|
+
},
|
|
543
|
+
async resolve(id) {
|
|
544
|
+
const preset = await resolvePreset(id, {
|
|
545
|
+
static: configOverrides.static,
|
|
546
|
+
compatibilityDate: compatibilityDate || fallbackCompatibilityDate
|
|
547
|
+
});
|
|
548
|
+
if (preset) {
|
|
549
|
+
return {
|
|
550
|
+
config: klona(preset)
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
},
|
|
554
|
+
...opts.c12
|
|
555
|
+
});
|
|
556
|
+
delete globalThis.defineSilgiConfig;
|
|
557
|
+
const options = klona(loadedConfig.config);
|
|
558
|
+
options._config = configOverrides;
|
|
559
|
+
options._c12 = loadedConfig;
|
|
560
|
+
const _presetName = (loadedConfig.layers || []).find((l) => l.config?._meta?.name)?.config?._meta?.name || presetOverride;
|
|
561
|
+
options.preset = _presetName;
|
|
562
|
+
options.compatibilityDate = resolveCompatibilityDates(
|
|
563
|
+
compatibilityDate,
|
|
564
|
+
options.compatibilityDate
|
|
565
|
+
);
|
|
566
|
+
return options;
|
|
567
|
+
}
|
|
7
568
|
|
|
8
569
|
function getDirectory(p) {
|
|
9
570
|
try {
|
|
@@ -193,4 +754,4 @@ async function silgiGenerateType(silgi) {
|
|
|
193
754
|
};
|
|
194
755
|
}
|
|
195
756
|
|
|
196
|
-
export { silgiGenerateType as s };
|
|
757
|
+
export { loadOptions as l, silgiGenerateType as s };
|
package/dist/meta/index.d.mts
CHANGED
package/dist/meta/index.d.ts
CHANGED