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.
@@ -1,752 +1,17 @@
1
- import { watchConfig, loadConfig } from 'c12';
2
- import { resolveCompatibilityDatesFromEnv, formatDate, resolveCompatibilityDates } from 'compatx';
3
- import { klona } from 'klona/full';
4
- import { isDebug, isTest, isDevelopment } from 'std-env';
5
- import consola, { createConsola } from 'consola';
6
- import { colors } from 'consola/utils';
7
- import { relative, join, resolve, isAbsolute, dirname } from 'pathe';
8
- import escapeRE from 'escape-string-regexp';
9
- import { resolveModuleExportNames, resolvePath as resolvePath$1 } from 'mlly';
10
- import { existsSync, lstatSync, promises, writeFileSync } from 'node:fs';
11
- import { pathToFileURL } from 'node:url';
12
- import { findWorkspaceDir, readPackageJSON } from 'pkg-types';
13
- import { resolveSilgiPath, resolveAlias, resolvePath, relativeWithDot, resolveSilgiModule } from 'silgi/kit';
14
- import { runtimeDir, pkgDir } from 'silgi/runtime/meta';
15
- import { isRelative, withLeadingSlash, withTrailingSlash } from 'ufo';
16
- import defu$1, { defu } from 'defu';
1
+ import { createConsola } from 'consola';
2
+ import defu from 'defu';
17
3
  import { isEvent } from 'h3';
18
4
  import { createHooks } from 'hookable';
19
5
  import { defineUntypedSchema, applyDefaults } from 'untyped';
6
+ import { isDebug, isTest, isDevelopment } from 'std-env';
20
7
  import { getContext } from 'unctx';
21
8
  import { Buffer } from 'node:buffer';
22
- import { klona as klona$1 } from 'klona';
9
+ import { klona } from 'klona';
23
10
  import { createStorage as createStorage$1, builtinDrivers, prefixStorage } from 'unstorage';
24
11
  import memoryDriver from 'unstorage/drivers/memory';
12
+ import { writeFileSync } from 'node:fs';
25
13
  import { parseSync } from '@oxc-parser/wasm';
26
14
 
27
- const SilgiCLIDefaults = {
28
- // General
29
- debug: isDebug,
30
- // timing: isDebug,
31
- logLevel: isTest ? 1 : 3,
32
- // runtimeConfig: { app: {}, silgi: {} },
33
- appConfig: {},
34
- appConfigFiles: [],
35
- // Dirs
36
- scanDirs: [],
37
- build: {
38
- dir: ".silgi",
39
- typesDir: "{{ build.dir }}/types",
40
- templates: []
41
- },
42
- output: {
43
- dir: "{{ rootDir }}/.output",
44
- serverDir: "{{ output.dir }}/server",
45
- publicDir: "{{ output.dir }}/public"
46
- },
47
- serverDir: "{{ rootDir }}/server",
48
- clientDir: "{{ rootDir }}/client",
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
- // Modules
58
- _modules: [],
59
- modules: [],
60
- // Features
61
- // experimental: {},
62
- future: {},
63
- storage: {},
64
- devStorage: {},
65
- stub: false,
66
- // bundledStorage: [],
67
- // publicAssets: [],
68
- // serverAssets: [],
69
- plugins: [],
70
- // tasks: {},
71
- // scheduledTasks: {},
72
- imports: {
73
- exclude: [],
74
- dirs: [],
75
- presets: [],
76
- virtualImports: ["#silgiImports"]
77
- },
78
- // virtual: {},
79
- // compressPublicAssets: false,
80
- ignore: [],
81
- // Dev
82
- dev: false,
83
- // devServer: { watch: [] },
84
- watchOptions: { ignoreInitial: true },
85
- // devProxy: {},
86
- // Logging
87
- // logging: {
88
- // compressedSizes: true,
89
- // buildSuccess: true,
90
- // },
91
- // Routing
92
- // baseURL: process.env.NITRO_APP_BASE_URL || '/',
93
- // handlers: [],
94
- // devHandlers: [],
95
- // errorHandler: undefined,
96
- // routeRules: {},
97
- // Advanced
98
- typescript: {
99
- strict: false,
100
- generateTsConfig: true,
101
- // generateRuntimeConfigTypes: true,
102
- tsconfigPath: "types/silgi.tsconfig.json",
103
- internalPaths: false,
104
- tsConfig: {},
105
- customConditions: []
106
- },
107
- conditions: [],
108
- nodeModulesDirs: [],
109
- // hooks: {},
110
- commands: {},
111
- // Framework
112
- framework: {
113
- name: "h3",
114
- version: ""
115
- },
116
- extensions: [".js", ".jsx", ".mjs", ".ts", ".tsx", ".vue"],
117
- ignoreOptions: void 0
118
- };
119
-
120
- const fallbackCompatibilityDate = "2025-02-04";
121
- async function resolveCompatibilityOptions(options) {
122
- options.compatibilityDate = resolveCompatibilityDatesFromEnv(
123
- options.compatibilityDate
124
- );
125
- if (!options.compatibilityDate.default) {
126
- options.compatibilityDate.default = await _resolveDefault(options);
127
- }
128
- }
129
- let _fallbackInfoShown = false;
130
- let _promptedUserToUpdate = false;
131
- async function _resolveDefault(options) {
132
- const _todayDate = formatDate(/* @__PURE__ */ new Date());
133
- const consola$1 = consola.withTag("silgi");
134
- consola$1.warn(`No valid compatibility date is specified.`);
135
- const onFallback = () => {
136
- if (!_fallbackInfoShown) {
137
- consola$1.info(
138
- [
139
- `Using \`${fallbackCompatibilityDate}\` as fallback.`,
140
- ` Please specify compatibility date to avoid unwanted behavior changes:`,
141
- ` - Add \`compatibilityDate: '${_todayDate}'\` to the config file.`,
142
- ` - Or set \`COMPATIBILITY_DATE=${_todayDate}\` environment variable.`,
143
- ``
144
- ].join("\n")
145
- );
146
- _fallbackInfoShown = true;
147
- }
148
- return fallbackCompatibilityDate;
149
- };
150
- const shallUpdate = !_promptedUserToUpdate && await consola$1.prompt(
151
- `Do you want to auto update config file to set ${colors.cyan(`compatibilityDate: '${_todayDate}'`)}?`,
152
- {
153
- type: "confirm",
154
- default: true
155
- }
156
- );
157
- _promptedUserToUpdate = true;
158
- if (!shallUpdate) {
159
- return onFallback();
160
- }
161
- const { updateConfig } = await import('c12/update');
162
- const updateResult = await updateConfig({
163
- configFile: "silgi.config",
164
- cwd: options.rootDir,
165
- async onCreate({ configFile }) {
166
- const shallCreate = await consola$1.prompt(
167
- `Do you want to initialize a new config in ${colors.cyan(relative(".", configFile))}?`,
168
- {
169
- type: "confirm",
170
- default: true
171
- }
172
- );
173
- if (shallCreate !== true) {
174
- return false;
175
- }
176
- return _getDefaultNitroConfig();
177
- },
178
- async onUpdate(config) {
179
- config.compatibilityDate = _todayDate;
180
- }
181
- }).catch((error) => {
182
- consola$1.error(`Failed to update config: ${error.message}`);
183
- return null;
184
- });
185
- if (updateResult?.configFile) {
186
- consola$1.success(
187
- `Compatibility date set to \`${_todayDate}\` in \`${relative(".", updateResult.configFile)}\``
188
- );
189
- return _todayDate;
190
- }
191
- return onFallback();
192
- }
193
- function _getDefaultNitroConfig() {
194
- return (
195
- /* js */
196
- `
197
- import { defineSilgiConfig } from 'silgi/config'
198
-
199
- export default defineSilgiConfig({})
200
- `
201
- );
202
- }
203
-
204
- async function resolveImportsOptions(options) {
205
- if (options.imports === false) {
206
- return;
207
- }
208
- options.imports.presets ??= [];
209
- options.imports.presets.push(...getSilgiImportsPreset());
210
- if (options.preset === "h3") {
211
- const h3Exports = await resolveModuleExportNames("h3", {
212
- url: import.meta.url
213
- });
214
- options.imports.presets ??= [];
215
- options.imports.presets.push({
216
- from: "h3",
217
- imports: h3Exports.filter((n) => !/^[A-Z]/.test(n) && n !== "use")
218
- });
219
- }
220
- options.imports.dirs ??= [];
221
- options.imports.dirs.push(
222
- ...options.scanDirs.map((dir) => join(dir, "utils/**/*"))
223
- );
224
- if (Array.isArray(options.imports.exclude) && options.imports.exclude.length === 0) {
225
- options.imports.exclude.push(/[/\\]\.git[/\\]/);
226
- options.imports.exclude.push(options.build.dir);
227
- const scanDirsInNodeModules = options.scanDirs.map((dir) => dir.match(/(?<=\/)node_modules\/(.+)$/)?.[1]).filter(Boolean);
228
- options.imports.exclude.push(
229
- scanDirsInNodeModules.length > 0 ? new RegExp(
230
- `node_modules\\/(?!${scanDirsInNodeModules.map((dir) => escapeRE(dir)).join("|")})`
231
- ) : /[/\\]node_modules[/\\]/
232
- );
233
- }
234
- }
235
- function getSilgiImportsPreset() {
236
- return [
237
- // TODO: buraya bizim importlarimiz gelecek.
238
- {
239
- from: "silgi",
240
- imports: [
241
- "createShared",
242
- "useSilgi",
243
- "createService",
244
- "createSchema"
245
- ]
246
- },
247
- // {
248
- // from: 'nitropack/runtime',
249
- // imports: ['useRuntimeConfig', 'useAppConfig'],
250
- // },
251
- // {
252
- // from: 'nitropack/runtime',
253
- // imports: ['defineNitroPlugin', 'nitroPlugin'],
254
- // },
255
- // {
256
- // from: 'nitropack/runtime/internal/cache',
257
- // imports: [
258
- // 'defineCachedFunction',
259
- // 'defineCachedEventHandler',
260
- // 'cachedFunction',
261
- // 'cachedEventHandler',
262
- // ],
263
- // },
264
- {
265
- from: "silgi/core",
266
- imports: ["useSilgiStorage"]
267
- }
268
- // {
269
- // from: 'nitropack/runtime/internal/renderer',
270
- // imports: ['defineRenderHandler'],
271
- // },
272
- // {
273
- // from: 'nitropack/runtime/internal/meta',
274
- // imports: ['defineRouteMeta'],
275
- // },
276
- // {
277
- // from: 'nitropack/runtime/internal/route-rules',
278
- // imports: ['getRouteRules'],
279
- // },
280
- // {
281
- // from: 'nitropack/runtime/internal/context',
282
- // imports: ['useEvent'],
283
- // },
284
- // {
285
- // from: 'nitropack/runtime/internal/task',
286
- // imports: ['defineTask', 'runTask'],
287
- // },
288
- // {
289
- // from: 'nitropack/runtime/internal/error/utils',
290
- // imports: ['defineNitroErrorHandler'],
291
- // },
292
- ];
293
- }
294
-
295
- async function resolvePathOptions(options) {
296
- options.rootDir = resolve(options.rootDir || ".");
297
- options.workspaceDir = await findWorkspaceDir(options.rootDir).catch(
298
- () => options.rootDir
299
- );
300
- options.srcDir = resolve(options.srcDir || options.rootDir);
301
- for (const key of ["srcDir"]) {
302
- options[key] = resolve(options.rootDir, options[key]);
303
- }
304
- options.build.dir = resolve(options.rootDir, options.build.dir);
305
- options.build.typesDir = resolveSilgiPath(
306
- options.build.typesDir || SilgiCLIDefaults.build.typesDir,
307
- options,
308
- options.rootDir
309
- );
310
- if (options.preset === "npm-package") {
311
- const packageJsonPath = resolve(options.rootDir, "package.json");
312
- const packageJson = await readPackageJSON(packageJsonPath);
313
- if (packageJson.name === void 0) {
314
- throw new Error("Package name is undefined");
315
- }
316
- options.alias ||= {};
317
- options.alias[packageJson.name] = join(options.rootDir, "src/module.ts");
318
- options.alias[`${packageJson.name}/runtime/`] = join(options.rootDir, "src/runtime/");
319
- }
320
- if (options.typescript?.internalPaths || options.stub) {
321
- options.alias = {
322
- ...options.alias,
323
- "silgi/runtime": join(runtimeDir),
324
- "#internal/silgi": join(runtimeDir),
325
- "silgi/runtime/*": join(runtimeDir, "*"),
326
- "#internal/silgi/*": join(runtimeDir, "*")
327
- };
328
- options.typescript.customConditions = [
329
- ...options.typescript.customConditions,
330
- "silgiTypes"
331
- ];
332
- options.conditions ||= [];
333
- options.conditions.push("silgi");
334
- }
335
- options.alias = {
336
- ...options.alias,
337
- "~/": join(options.srcDir, "/"),
338
- "@/": join(options.srcDir, "/"),
339
- "~~/": join(options.rootDir, "/"),
340
- "@@/": join(options.rootDir, "/")
341
- };
342
- if (options.preset === "npm-package") {
343
- options.alias = {
344
- ...options.alias,
345
- "#silgi/app/": join(options.build.dir, "/")
346
- };
347
- }
348
- if (options.alias && typeof options.alias === "object") {
349
- ((options.typescript.tsConfig ??= {}).compilerOptions ??= {}).paths ??= {};
350
- const paths = options.typescript.tsConfig.compilerOptions.paths;
351
- for (const [key, value] of Object.entries(options.alias)) {
352
- if (typeof paths === "object") {
353
- paths[key] = [value];
354
- }
355
- }
356
- }
357
- if (options.typescript.tsConfig.compilerOptions?.paths && typeof options.typescript.tsConfig.compilerOptions.paths === "object") {
358
- ((options.typescript.tsConfig ??= {}).compilerOptions ??= {}).paths ??= {};
359
- const paths = options.typescript.tsConfig.compilerOptions.paths;
360
- for (const [key, value] of Object.entries(options.alias)) {
361
- if (typeof paths === "object") {
362
- paths[key] = [value];
363
- }
364
- }
365
- }
366
- options.modulesDir = [resolve(options.rootDir, "node_modules")];
367
- options.output.dir = resolveSilgiPath(
368
- options.output.dir || SilgiCLIDefaults.output.dir,
369
- options,
370
- options.rootDir
371
- );
372
- options.output.publicDir = resolveSilgiPath(
373
- options.output.publicDir || SilgiCLIDefaults.output.publicDir,
374
- options,
375
- options.rootDir
376
- );
377
- options.output.serverDir = resolveSilgiPath(
378
- options.output.serverDir || SilgiCLIDefaults.output.serverDir,
379
- options,
380
- options.rootDir
381
- );
382
- options.serverDir = resolveSilgiPath(
383
- options.serverDir || SilgiCLIDefaults.serverDir,
384
- options,
385
- options.rootDir
386
- );
387
- options.clientDir = resolveSilgiPath(
388
- options.clientDir || SilgiCLIDefaults.clientDir,
389
- options,
390
- options.rootDir
391
- );
392
- options.silgi.serverDir = resolveSilgiPath(
393
- options.silgi.serverDir || SilgiCLIDefaults.silgi.serverDir,
394
- options,
395
- options.rootDir
396
- );
397
- options.silgi.clientDir = resolveSilgiPath(
398
- options.silgi.clientDir || SilgiCLIDefaults.silgi.clientDir,
399
- options,
400
- options.rootDir
401
- );
402
- options.silgi.publicDir = resolveSilgiPath(
403
- options.silgi.publicDir || SilgiCLIDefaults.silgi.publicDir,
404
- options,
405
- options.rootDir
406
- );
407
- options.silgi.utilsDir = resolveSilgiPath(
408
- options.silgi.utilsDir || SilgiCLIDefaults.silgi.utilsDir,
409
- options,
410
- options.rootDir
411
- );
412
- options.silgi.vfsDir = resolveSilgiPath(
413
- options.silgi.vfsDir || SilgiCLIDefaults.silgi.vfsDir,
414
- options,
415
- options.rootDir
416
- );
417
- options.silgi.typesDir = resolveSilgiPath(
418
- options.silgi.typesDir || SilgiCLIDefaults.silgi.typesDir,
419
- options,
420
- options.rootDir
421
- );
422
- options.nodeModulesDirs.push(resolve(options.workspaceDir, "node_modules"));
423
- options.nodeModulesDirs.push(resolve(options.rootDir, "node_modules"));
424
- options.nodeModulesDirs.push(resolve(pkgDir, "node_modules"));
425
- options.nodeModulesDirs.push(resolve(pkgDir, ".."));
426
- options.nodeModulesDirs = [
427
- ...new Set(
428
- options.nodeModulesDirs.map((dir) => resolve(options.rootDir, dir))
429
- )
430
- ];
431
- options.scanDirs.unshift(options.srcDir);
432
- options.scanDirs = options.scanDirs.map(
433
- (dir) => resolve(options.srcDir, dir)
434
- );
435
- options.scanDirs = [...new Set(options.scanDirs)];
436
- options.appConfigFiles ??= [];
437
- options.appConfigFiles = options.appConfigFiles.map((file) => _tryResolve(resolveSilgiPath(file, options))).filter(Boolean);
438
- for (const dir of options.scanDirs) {
439
- const configFile = _tryResolve("app.config", dir);
440
- if (configFile && !options.appConfigFiles.includes(configFile)) {
441
- options.appConfigFiles.push(configFile);
442
- }
443
- }
444
- const modulesRuntimePaths = {};
445
- if (options.typescript?.internalPaths) {
446
- for (let i of options.modules) {
447
- if (typeof i === "string") {
448
- i = resolveAlias(i, options.alias);
449
- if (isRelative(i)) {
450
- i = resolve(options.rootDir, i);
451
- }
452
- 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 });
453
- const cleanPath = src.replace(/(\/(?:src|dist)(?:\/runtime)?(?:\/.*)?$)/, "");
454
- modulesRuntimePaths[`${i}/runtime`] = `${cleanPath}/src/runtime`;
455
- }
456
- }
457
- for (const [key, value] of Object.entries(modulesRuntimePaths)) {
458
- options.alias = {
459
- ...options.alias,
460
- [`${key}`]: value
461
- };
462
- }
463
- }
464
- }
465
- function _tryResolve(path, base = ".", extensions = ["", ".js", ".ts", ".mjs", ".cjs", ".json"]) {
466
- path = resolve(base, path);
467
- if (existsSync(path)) {
468
- return path;
469
- }
470
- for (const ext of extensions) {
471
- const p = path + ext;
472
- if (existsSync(p)) {
473
- return p;
474
- }
475
- }
476
- }
477
-
478
- async function resolveStorageOptions(options) {
479
- const fsMounts = {
480
- root: resolve(options.rootDir),
481
- src: resolve(options.srcDir),
482
- build: resolve(options.build.dir),
483
- cache: resolve(options.build.dir, "cache")
484
- };
485
- for (const p in fsMounts) {
486
- options.devStorage[p] = options.devStorage[p] || {
487
- driver: "fs",
488
- readOnly: p === "root" || p === "src",
489
- base: fsMounts[p]
490
- };
491
- }
492
- if (options.dev && options.storage.data === void 0 && options.devStorage.data === void 0) {
493
- options.devStorage.data = {
494
- driver: "fs",
495
- base: resolve(options.rootDir, ".data/kv")
496
- };
497
- }
498
- }
499
-
500
- async function resolveURLOptions(options) {
501
- options.baseURL = withLeadingSlash(withTrailingSlash(options.baseURL));
502
- }
503
-
504
- const configResolvers = [
505
- resolveCompatibilityOptions,
506
- resolvePathOptions,
507
- resolveImportsOptions,
508
- // resolveRouteRulesOptions,
509
- // resolveDatabaseOptions,
510
- // resolveFetchOptions,
511
- // resolveExportConditionsOptions,
512
- // resolveRuntimeConfigOptions,
513
- // resolveOpenAPIOptions,
514
- resolveURLOptions,
515
- // resolveAssetsOptions,
516
- resolveStorageOptions
517
- // resolveErrorOptions,
518
- ];
519
- async function loadOptions(configOverrides = {}, opts = {}) {
520
- const options = await _loadUserConfig(configOverrides, opts);
521
- for (const resolver of configResolvers) {
522
- await resolver(options);
523
- }
524
- return options;
525
- }
526
- async function _loadUserConfig(configOverrides = {}, opts = {}) {
527
- const presetOverride = configOverrides.preset || process.env.SILGI_PRESET;
528
- if (configOverrides.dev) ;
529
- configOverrides = klona(configOverrides);
530
- globalThis.defineSilgiConfig = globalThis.defineSilgiConfig || ((c) => c);
531
- let compatibilityDate = configOverrides.compatibilityDate || opts.compatibilityDate || (process.env.SILGI_COMPATIBILITY_DATE || process.env.SERVER_COMPATIBILITY_DATE || process.env.COMPATIBILITY_DATE);
532
- const { resolvePreset } = await import('silgi/presets');
533
- const loadedConfig = await (opts.watch ? watchConfig : loadConfig)({
534
- name: "silgi",
535
- cwd: configOverrides.rootDir,
536
- dotenv: configOverrides.dev,
537
- extend: { extendKey: ["extends", "preset"] },
538
- overrides: {
539
- ...configOverrides,
540
- preset: presetOverride
541
- },
542
- async defaultConfig({ configs }) {
543
- const getConf = (key) => configs.main?.[key] ?? configs.rc?.[key] ?? configs.packageJson?.[key];
544
- if (!compatibilityDate) {
545
- compatibilityDate = getConf("compatibilityDate");
546
- }
547
- return {
548
- // typescript: {
549
- // generateRuntimeConfigTypes:
550
- // !framework?.name || framework.name === 'nitro',
551
- // },
552
- preset: presetOverride || (await resolvePreset("", {
553
- static: getConf("static"),
554
- compatibilityDate: compatibilityDate || fallbackCompatibilityDate
555
- }))?._meta?.name
556
- };
557
- },
558
- defaults: SilgiCLIDefaults,
559
- jitiOptions: {
560
- alias: {
561
- "silgi": "silgi/config",
562
- "silgi/config": "silgi/config"
563
- }
564
- },
565
- async resolve(id) {
566
- const preset = await resolvePreset(id, {
567
- static: configOverrides.static,
568
- compatibilityDate: compatibilityDate || fallbackCompatibilityDate
569
- });
570
- if (preset) {
571
- return {
572
- config: klona(preset)
573
- };
574
- }
575
- },
576
- ...opts.c12
577
- });
578
- delete globalThis.defineSilgiConfig;
579
- const options = klona(loadedConfig.config);
580
- options._config = configOverrides;
581
- options._c12 = loadedConfig;
582
- const _presetName = (loadedConfig.layers || []).find((l) => l.config?._meta?.name)?.config?._meta?.name || presetOverride;
583
- options.preset = _presetName;
584
- options.compatibilityDate = resolveCompatibilityDates(
585
- compatibilityDate,
586
- options.compatibilityDate
587
- );
588
- return options;
589
- }
590
-
591
- function getDirectory(p) {
592
- try {
593
- return isAbsolute(p) && lstatSync(p).isFile() ? dirname(p) : p;
594
- } catch {
595
- }
596
- return p;
597
- }
598
-
599
- function renderAttrs(obj) {
600
- const attrs = [];
601
- for (const key in obj) {
602
- attrs.push(renderAttr(key, obj[key]));
603
- }
604
- return attrs.join(" ");
605
- }
606
- function renderAttr(key, value) {
607
- return value ? `${key}="${value}"` : "";
608
- }
609
- async function silgiGenerateType(silgi) {
610
- const rootDirWithSlash = withTrailingSlash(silgi.options.rootDir);
611
- const tsConfigPath = resolve(
612
- silgi.options.rootDir,
613
- silgi.options.typescript.tsconfigPath
614
- );
615
- const tsconfigDir = dirname(tsConfigPath);
616
- const include = /* @__PURE__ */ new Set([
617
- relativeWithDot(tsconfigDir, join(silgi.options.build.typesDir, "silgi.d.ts")).replace(
618
- /^(?=[^.])/,
619
- "./"
620
- ),
621
- join(relativeWithDot(tsconfigDir, silgi.options.rootDir), "**/*"),
622
- ...silgi.options.srcDir === silgi.options.rootDir ? [] : [join(relativeWithDot(tsconfigDir, silgi.options.srcDir), "**/*")]
623
- ]);
624
- const exclude = /* @__PURE__ */ new Set([
625
- // nitro generate output: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nitro.ts#L186
626
- relativeWithDot(silgi.options.build.dir, resolve(silgi.options.rootDir, "dist"))
627
- ]);
628
- for (const dir of silgi.options.modulesDir) {
629
- exclude.add(relativeWithDot(silgi.options.build.dir, dir));
630
- }
631
- const moduleEntryPaths = [];
632
- for (const m of silgi.scanModules) {
633
- if (m.entryPath) {
634
- moduleEntryPaths.push(getDirectory(m.entryPath));
635
- }
636
- }
637
- const modulePaths = await resolveSilgiModule(rootDirWithSlash, moduleEntryPaths);
638
- for (const path of modulePaths) {
639
- const relative2 = relativeWithDot(silgi.options.build.dir, path);
640
- include.add(join(relative2, "runtime"));
641
- exclude.add(join(relative2, "runtime/server"));
642
- include.add(join(relative2, "dist/runtime"));
643
- exclude.add(join(relative2, "dist/runtime/server"));
644
- }
645
- const tsConfig = defu(silgi.options.typescript?.tsConfig, {
646
- compilerOptions: {
647
- forceConsistentCasingInFileNames: true,
648
- strict: silgi.options.typescript.strict,
649
- noEmit: true,
650
- target: "ESNext",
651
- module: "ESNext",
652
- moduleResolution: "Bundler",
653
- allowJs: true,
654
- resolveJsonModule: true,
655
- jsx: "preserve",
656
- allowSyntheticDefaultImports: true,
657
- jsxFactory: "h",
658
- jsxFragmentFactory: "Fragment",
659
- allowImportingTsExtensions: true,
660
- ...silgi.options.typescript.customConditions ? { customConditions: ["silgiTypes"] } : {},
661
- paths: {
662
- "#silgiImports": [
663
- relativeWithDot(tsconfigDir, join(silgi.options.build.typesDir, "silgi-imports"))
664
- ],
665
- ...silgi.scanModules.reduce((acc, m) => {
666
- if (m.entryPath) {
667
- acc[m.meta.name] = [relativeWithDot(tsconfigDir, m.entryPath)];
668
- }
669
- return acc;
670
- }, {}),
671
- ...silgi.scanModules.reduce((acc, m) => {
672
- if (m.entryPath) {
673
- const directory = getDirectory(m.entryPath);
674
- acc[`${m.meta.name}/*`] = [`${relativeWithDot(tsconfigDir, directory)}/*`];
675
- }
676
- return acc;
677
- }, {})
678
- // ...(silgi.options.typescript?.internalPaths
679
- // ? {
680
- // 'silgi/runtime': [
681
- // relativeWithDot(tsconfigDir, join(runtimeDir, 'index')),
682
- // ],
683
- // '#internal/silgi': [
684
- // relativeWithDot(tsconfigDir, join(runtimeDir, 'index')),
685
- // ],
686
- // 'silgi/runtime/*': [
687
- // relativeWithDot(tsconfigDir, join(runtimeDir, '*')),
688
- // ],
689
- // '#internal/silgi/*': [
690
- // relativeWithDot(tsconfigDir, join(runtimeDir, '*')),
691
- // ],
692
- // }
693
- // : {}),
694
- }
695
- },
696
- include: [...include],
697
- exclude: [...exclude]
698
- });
699
- tsConfig.compilerOptions ||= {};
700
- tsConfig.compilerOptions.paths ||= {};
701
- tsConfig.include ||= [];
702
- for (const alias in tsConfig.compilerOptions.paths) {
703
- const paths = tsConfig.compilerOptions.paths[alias];
704
- tsConfig.compilerOptions.paths[alias] = await Promise.all(
705
- paths.map(async (path) => {
706
- if (!isAbsolute(path)) {
707
- return path;
708
- }
709
- const stats = await promises.stat(path).catch(
710
- () => null
711
- /* file does not exist */
712
- );
713
- return relativeWithDot(
714
- tsconfigDir,
715
- stats?.isFile() ? path.replace(/\b\.\w+$/g, "") : path
716
- );
717
- })
718
- );
719
- }
720
- const references = [];
721
- await Promise.all([...silgi.options.modules, ...silgi.options._modules].map(async (id) => {
722
- if (typeof id !== "string") {
723
- return;
724
- }
725
- const pkg = await readPackageJSON(id, { url: silgi.options.modulesDir }).catch(() => null);
726
- references.push({ types: pkg?.name || id });
727
- }));
728
- const declarations = [];
729
- await silgi.callHook("prepare:types", { references, declarations, tsConfig });
730
- tsConfig.include = [...new Set(tsConfig.include.map((p) => isAbsolute(p) ? relativeWithDot(silgi.options.build.dir, p) : p))];
731
- tsConfig.exclude = [...new Set(tsConfig.exclude.map((p) => isAbsolute(p) ? relativeWithDot(silgi.options.build.dir, p) : p))];
732
- const _declarations = [
733
- ...references.map((ref) => {
734
- if ("path" in ref && isAbsolute(ref.path)) {
735
- ref.path = relative(silgi.options.build.dir, ref.path);
736
- }
737
- return `/// <reference ${renderAttrs(ref)} />`;
738
- }),
739
- ...declarations,
740
- "",
741
- "export {}",
742
- ""
743
- ];
744
- return {
745
- declarations: _declarations,
746
- tsConfig
747
- };
748
- }
749
-
750
15
  const common = defineUntypedSchema({
751
16
  /**
752
17
  * Environment to use.
@@ -1216,7 +481,7 @@ async function scanAction(silgi) {
1216
481
 
1217
482
  async function createStorage(silgi) {
1218
483
  const storage = createStorage$1();
1219
- const mounts = klona$1({
484
+ const mounts = klona({
1220
485
  ...silgi.options.storage,
1221
486
  ...silgi.options.devStorage
1222
487
  });
@@ -1308,7 +573,7 @@ async function createSilgi(config) {
1308
573
  return hooks.callHook("ready", silgi);
1309
574
  },
1310
575
  close: () => hooks.callHook("close", silgi),
1311
- logger: createConsola(defu$1(config.options.consolaOptions, {
576
+ logger: createConsola(defu(config.options.consolaOptions, {
1312
577
  tag: "silgi"
1313
578
  })).withTag("silgi"),
1314
579
  captureError: (error, context = {}) => {
@@ -1675,4 +940,4 @@ function tryUseSilgiCLI() {
1675
940
  return silgiCLICtx.tryUse();
1676
941
  }
1677
942
 
1678
- export { ErrorCategory, ErrorFactory, ErrorSeverity, HttpStatus, SchemaParser, SilgiError, createSchema, createService, createShared, createSilgi, createSilgiFetch, createStorage, getEvent, isBaseError, loadOptions, mergeSchemas, mergeServices, mergeShared, parseURI, silgi, silgiCLICtx, silgiCtx, silgiGenerateType, tryUseSilgi, tryUseSilgiCLI, useSilgi, useSilgiCLI, useSilgiStorage };
943
+ export { ErrorCategory, ErrorFactory, ErrorSeverity, HttpStatus, SchemaParser, SilgiError, createSchema, createService, createShared, createSilgi, createSilgiFetch, createStorage, getEvent, isBaseError, mergeSchemas, mergeServices, mergeShared, parseURI, silgi, silgiCLICtx, silgiCtx, tryUseSilgi, tryUseSilgiCLI, useSilgi, useSilgiCLI, useSilgiStorage };