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