silgi 0.7.0 → 0.7.1

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.
Files changed (77) hide show
  1. package/dist/cli/build/framework/h3.mjs +46 -0
  2. package/dist/cli/build/framework/index.mjs +7 -0
  3. package/dist/cli/build/framework/nitro.mjs +28 -0
  4. package/dist/cli/build/framework/nuxt.mjs +9 -0
  5. package/dist/cli/build/prepare.mjs +7 -0
  6. package/dist/cli/build/scanURIs.mjs +27 -0
  7. package/dist/cli/build/template/framework.mjs +91 -0
  8. package/dist/cli/build/template/schema.mjs +115 -0
  9. package/dist/cli/build/template/silgi.mjs +149 -0
  10. package/dist/cli/build/types.mjs +130 -0
  11. package/dist/cli/commands/prepare.mjs +49 -0
  12. package/dist/cli/common.mjs +13 -0
  13. package/dist/cli/core/app.mjs +89 -0
  14. package/dist/cli/core/scan.mjs +40 -0
  15. package/dist/cli/core/silgi.mjs +77 -0
  16. package/dist/cli/core/storage.mjs +11 -0
  17. package/dist/cli/core/templates.mjs +29 -0
  18. package/dist/cli/index.mjs +3 -3
  19. package/dist/cli/module/exportScan.mjs +69 -0
  20. package/dist/cli/module/install.mjs +52 -0
  21. package/dist/cli/module/scan.mjs +141 -0
  22. package/dist/cli/{compatibility.mjs → utils/compatibility.mjs} +1 -1
  23. package/dist/cli/utils/generateRouterDTS.mjs +84 -0
  24. package/dist/cli/utils/ignore.mjs +46 -0
  25. package/dist/cli/utils/readCoreFile.mjs +47 -0
  26. package/dist/cli/utils/scan.mjs +147 -0
  27. package/dist/cli/utils/storage.mjs +21 -0
  28. package/dist/cli/utils/uri.mjs +71 -0
  29. package/dist/core/config/defaults.mjs +96 -0
  30. package/dist/core/config/loader.mjs +98 -0
  31. package/dist/core/config/resolvers/compatibility.mjs +90 -0
  32. package/dist/core/config/resolvers/imports.mjs +96 -0
  33. package/dist/core/config/resolvers/paths.mjs +194 -0
  34. package/dist/core/config/resolvers/storage.mjs +25 -0
  35. package/dist/core/config/resolvers/url.mjs +7 -0
  36. package/dist/core/config/types.mjs +160 -0
  37. package/dist/core/createSilgi.mjs +84 -0
  38. package/dist/core/error.mjs +227 -0
  39. package/dist/core/fetch/ofetch.mjs +35 -0
  40. package/dist/core/index.mjs +16 -1678
  41. package/dist/core/parser.mjs +136 -0
  42. package/dist/core/silgi.mjs +114 -0
  43. package/dist/core/silgiApp.mjs +15 -0
  44. package/dist/core/unctx.mjs +27 -0
  45. package/dist/core/uris/uri.mjs +33 -0
  46. package/dist/core/uris/utils.mjs +127 -0
  47. package/dist/core/utils/event.mjs +5 -0
  48. package/dist/core/utils/global.mjs +12 -0
  49. package/dist/core/utils/merge.mjs +25 -0
  50. package/dist/core/utils/schema.mjs +5 -0
  51. package/dist/core/utils/service.mjs +5 -0
  52. package/dist/core/utils/shared.mjs +5 -0
  53. package/dist/core/utils/storage.mjs +70 -0
  54. package/dist/ecosystem/nitro/index.mjs +1 -62
  55. package/dist/ecosystem/nitro/module.mjs +62 -0
  56. package/dist/kit/esm.mjs +10 -0
  57. package/dist/kit/fs.mjs +25 -0
  58. package/dist/kit/index.mjs +10 -299
  59. package/dist/kit/isFramework.mjs +25 -0
  60. package/dist/kit/logger.mjs +8 -0
  61. package/dist/kit/module.mjs +73 -0
  62. package/dist/kit/path.mjs +34 -0
  63. package/dist/kit/preset.mjs +6 -0
  64. package/dist/kit/resolve.mjs +78 -0
  65. package/dist/kit/template.mjs +47 -0
  66. package/dist/kit/utils.mjs +20 -0
  67. package/dist/meta/index.d.mts +1 -1
  68. package/dist/meta/index.d.ts +1 -1
  69. package/dist/meta/index.mjs +1 -1
  70. package/dist/package.json.mjs +5 -0
  71. package/dist/schema/common.mjs +43 -0
  72. package/dist/schema/index.mjs +9 -0
  73. package/dist/schema/internal.mjs +22 -0
  74. package/package.json +1 -1
  75. package/dist/_chunks/index.mjs +0 -5
  76. package/dist/cli/prepare.mjs +0 -1481
  77. /package/dist/cli/{init.mjs → commands/init.mjs} +0 -0
@@ -0,0 +1,194 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { pathToFileURL } from 'node:url';
3
+ import { resolvePath as resolvePath$1 } from 'mlly';
4
+ import { resolve, join, isAbsolute } from 'pathe';
5
+ import { findWorkspaceDir, readPackageJSON } from 'pkg-types';
6
+ import { resolveSilgiPath, resolveAlias, resolvePath } from 'silgi/kit';
7
+ import { runtimeDir, pkgDir } from 'silgi/runtime/meta';
8
+ import { isRelative } from 'ufo';
9
+ import { SilgiCLIDefaults } from '../defaults.mjs';
10
+
11
+ async function resolvePathOptions(options) {
12
+ options.rootDir = resolve(options.rootDir || ".");
13
+ options.workspaceDir = await findWorkspaceDir(options.rootDir).catch(
14
+ () => options.rootDir
15
+ );
16
+ options.srcDir = resolve(options.srcDir || options.rootDir);
17
+ for (const key of ["srcDir"]) {
18
+ options[key] = resolve(options.rootDir, options[key]);
19
+ }
20
+ options.build.dir = resolve(options.rootDir, options.build.dir);
21
+ options.build.typesDir = resolveSilgiPath(
22
+ options.build.typesDir || SilgiCLIDefaults.build.typesDir,
23
+ options,
24
+ options.rootDir
25
+ );
26
+ if (options.preset === "npm-package") {
27
+ const packageJsonPath = resolve(options.rootDir, "package.json");
28
+ const packageJson = await readPackageJSON(packageJsonPath);
29
+ if (packageJson.name === void 0) {
30
+ throw new Error("Package name is undefined");
31
+ }
32
+ options.alias ||= {};
33
+ options.alias[packageJson.name] = join(options.rootDir, "src/module.ts");
34
+ options.alias[`${packageJson.name}/runtime/`] = join(options.rootDir, "src/runtime/");
35
+ }
36
+ if (options.typescript?.internalPaths || options.stub) {
37
+ options.alias = {
38
+ ...options.alias,
39
+ "silgi/runtime": join(runtimeDir),
40
+ "#internal/silgi": join(runtimeDir),
41
+ "silgi/runtime/*": join(runtimeDir, "*"),
42
+ "#internal/silgi/*": join(runtimeDir, "*")
43
+ };
44
+ options.typescript.customConditions = [
45
+ ...options.typescript.customConditions,
46
+ "silgiTypes"
47
+ ];
48
+ options.conditions ||= [];
49
+ options.conditions.push("silgi");
50
+ }
51
+ options.alias = {
52
+ ...options.alias,
53
+ "~/": join(options.srcDir, "/"),
54
+ "@/": join(options.srcDir, "/"),
55
+ "~~/": join(options.rootDir, "/"),
56
+ "@@/": join(options.rootDir, "/")
57
+ };
58
+ if (options.preset === "npm-package") {
59
+ options.alias = {
60
+ ...options.alias,
61
+ "#silgi/app/": join(options.build.dir, "/")
62
+ };
63
+ }
64
+ if (options.alias && typeof options.alias === "object") {
65
+ ((options.typescript.tsConfig ??= {}).compilerOptions ??= {}).paths ??= {};
66
+ const paths = options.typescript.tsConfig.compilerOptions.paths;
67
+ for (const [key, value] of Object.entries(options.alias)) {
68
+ if (typeof paths === "object") {
69
+ paths[key] = [value];
70
+ }
71
+ }
72
+ }
73
+ if (options.typescript.tsConfig.compilerOptions?.paths && typeof options.typescript.tsConfig.compilerOptions.paths === "object") {
74
+ ((options.typescript.tsConfig ??= {}).compilerOptions ??= {}).paths ??= {};
75
+ const paths = options.typescript.tsConfig.compilerOptions.paths;
76
+ for (const [key, value] of Object.entries(options.alias)) {
77
+ if (typeof paths === "object") {
78
+ paths[key] = [value];
79
+ }
80
+ }
81
+ }
82
+ options.modulesDir = [resolve(options.rootDir, "node_modules")];
83
+ options.output.dir = resolveSilgiPath(
84
+ options.output.dir || SilgiCLIDefaults.output.dir,
85
+ options,
86
+ options.rootDir
87
+ );
88
+ options.output.publicDir = resolveSilgiPath(
89
+ options.output.publicDir || SilgiCLIDefaults.output.publicDir,
90
+ options,
91
+ options.rootDir
92
+ );
93
+ options.output.serverDir = resolveSilgiPath(
94
+ options.output.serverDir || SilgiCLIDefaults.output.serverDir,
95
+ options,
96
+ options.rootDir
97
+ );
98
+ options.serverDir = resolveSilgiPath(
99
+ options.serverDir || SilgiCLIDefaults.serverDir,
100
+ options,
101
+ options.rootDir
102
+ );
103
+ options.clientDir = resolveSilgiPath(
104
+ options.clientDir || SilgiCLIDefaults.clientDir,
105
+ options,
106
+ options.rootDir
107
+ );
108
+ options.silgi.serverDir = resolveSilgiPath(
109
+ options.silgi.serverDir || SilgiCLIDefaults.silgi.serverDir,
110
+ options,
111
+ options.rootDir
112
+ );
113
+ options.silgi.clientDir = resolveSilgiPath(
114
+ options.silgi.clientDir || SilgiCLIDefaults.silgi.clientDir,
115
+ options,
116
+ options.rootDir
117
+ );
118
+ options.silgi.publicDir = resolveSilgiPath(
119
+ options.silgi.publicDir || SilgiCLIDefaults.silgi.publicDir,
120
+ options,
121
+ options.rootDir
122
+ );
123
+ options.silgi.utilsDir = resolveSilgiPath(
124
+ options.silgi.utilsDir || SilgiCLIDefaults.silgi.utilsDir,
125
+ options,
126
+ options.rootDir
127
+ );
128
+ options.silgi.vfsDir = resolveSilgiPath(
129
+ options.silgi.vfsDir || SilgiCLIDefaults.silgi.vfsDir,
130
+ options,
131
+ options.rootDir
132
+ );
133
+ options.silgi.typesDir = resolveSilgiPath(
134
+ options.silgi.typesDir || SilgiCLIDefaults.silgi.typesDir,
135
+ options,
136
+ options.rootDir
137
+ );
138
+ options.nodeModulesDirs.push(resolve(options.workspaceDir, "node_modules"));
139
+ options.nodeModulesDirs.push(resolve(options.rootDir, "node_modules"));
140
+ options.nodeModulesDirs.push(resolve(pkgDir, "node_modules"));
141
+ options.nodeModulesDirs.push(resolve(pkgDir, ".."));
142
+ options.nodeModulesDirs = [
143
+ ...new Set(
144
+ options.nodeModulesDirs.map((dir) => resolve(options.rootDir, dir))
145
+ )
146
+ ];
147
+ options.scanDirs.unshift(options.srcDir);
148
+ options.scanDirs = options.scanDirs.map(
149
+ (dir) => resolve(options.srcDir, dir)
150
+ );
151
+ options.scanDirs = [...new Set(options.scanDirs)];
152
+ options.appConfigFiles ??= [];
153
+ options.appConfigFiles = options.appConfigFiles.map((file) => _tryResolve(resolveSilgiPath(file, options))).filter(Boolean);
154
+ for (const dir of options.scanDirs) {
155
+ const configFile = _tryResolve("app.config", dir);
156
+ if (configFile && !options.appConfigFiles.includes(configFile)) {
157
+ options.appConfigFiles.push(configFile);
158
+ }
159
+ }
160
+ const modulesRuntimePaths = {};
161
+ if (options.typescript?.internalPaths) {
162
+ for (let i of options.modules) {
163
+ if (typeof i === "string") {
164
+ i = resolveAlias(i, options.alias);
165
+ if (isRelative(i)) {
166
+ i = resolve(options.rootDir, i);
167
+ }
168
+ 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 });
169
+ const cleanPath = src.replace(/(\/(?:src|dist)(?:\/runtime)?(?:\/.*)?$)/, "");
170
+ modulesRuntimePaths[`${i}/runtime`] = `${cleanPath}/src/runtime`;
171
+ }
172
+ }
173
+ for (const [key, value] of Object.entries(modulesRuntimePaths)) {
174
+ options.alias = {
175
+ ...options.alias,
176
+ [`${key}`]: value
177
+ };
178
+ }
179
+ }
180
+ }
181
+ function _tryResolve(path, base = ".", extensions = ["", ".js", ".ts", ".mjs", ".cjs", ".json"]) {
182
+ path = resolve(base, path);
183
+ if (existsSync(path)) {
184
+ return path;
185
+ }
186
+ for (const ext of extensions) {
187
+ const p = path + ext;
188
+ if (existsSync(p)) {
189
+ return p;
190
+ }
191
+ }
192
+ }
193
+
194
+ export { resolvePathOptions };
@@ -0,0 +1,25 @@
1
+ import { resolve } from 'pathe';
2
+
3
+ async function resolveStorageOptions(options) {
4
+ const fsMounts = {
5
+ root: resolve(options.rootDir),
6
+ src: resolve(options.srcDir),
7
+ build: resolve(options.build.dir),
8
+ cache: resolve(options.build.dir, "cache")
9
+ };
10
+ for (const p in fsMounts) {
11
+ options.devStorage[p] = options.devStorage[p] || {
12
+ driver: "fs",
13
+ readOnly: p === "root" || p === "src",
14
+ base: fsMounts[p]
15
+ };
16
+ }
17
+ if (options.dev && options.storage.data === void 0 && options.devStorage.data === void 0) {
18
+ options.devStorage.data = {
19
+ driver: "fs",
20
+ base: resolve(options.rootDir, ".data/kv")
21
+ };
22
+ }
23
+ }
24
+
25
+ export { resolveStorageOptions };
@@ -0,0 +1,7 @@
1
+ import { withLeadingSlash, withTrailingSlash } from 'ufo';
2
+
3
+ async function resolveURLOptions(options) {
4
+ options.baseURL = withLeadingSlash(withTrailingSlash(options.baseURL));
5
+ }
6
+
7
+ export { resolveURLOptions };
@@ -0,0 +1,160 @@
1
+ import { promises } from 'node:fs';
2
+ import { defu } from 'defu';
3
+ import { resolve, dirname, join, isAbsolute, relative } from 'pathe';
4
+ import { readPackageJSON } from 'pkg-types';
5
+ import { relativeWithDot, resolveSilgiModule } from 'silgi/kit';
6
+ import { withTrailingSlash } from 'ufo';
7
+ import { getDirectory } from '../utils/global.mjs';
8
+
9
+ function renderAttrs(obj) {
10
+ const attrs = [];
11
+ for (const key in obj) {
12
+ attrs.push(renderAttr(key, obj[key]));
13
+ }
14
+ return attrs.join(" ");
15
+ }
16
+ function renderAttr(key, value) {
17
+ return value ? `${key}="${value}"` : "";
18
+ }
19
+ async function silgiGenerateType(silgi) {
20
+ const rootDirWithSlash = withTrailingSlash(silgi.options.rootDir);
21
+ const tsConfigPath = resolve(
22
+ silgi.options.rootDir,
23
+ silgi.options.typescript.tsconfigPath
24
+ );
25
+ const tsconfigDir = dirname(tsConfigPath);
26
+ const include = /* @__PURE__ */ new Set([
27
+ relativeWithDot(tsconfigDir, join(silgi.options.build.typesDir, "silgi.d.ts")).replace(
28
+ /^(?=[^.])/,
29
+ "./"
30
+ ),
31
+ join(relativeWithDot(tsconfigDir, silgi.options.rootDir), "**/*"),
32
+ ...silgi.options.srcDir === silgi.options.rootDir ? [] : [join(relativeWithDot(tsconfigDir, silgi.options.srcDir), "**/*")]
33
+ ]);
34
+ const exclude = /* @__PURE__ */ new Set([
35
+ // nitro generate output: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nitro.ts#L186
36
+ relativeWithDot(silgi.options.build.dir, resolve(silgi.options.rootDir, "dist"))
37
+ ]);
38
+ for (const dir of silgi.options.modulesDir) {
39
+ exclude.add(relativeWithDot(silgi.options.build.dir, dir));
40
+ }
41
+ const moduleEntryPaths = [];
42
+ for (const m of silgi.scanModules) {
43
+ if (m.entryPath) {
44
+ moduleEntryPaths.push(getDirectory(m.entryPath));
45
+ }
46
+ }
47
+ const modulePaths = await resolveSilgiModule(rootDirWithSlash, moduleEntryPaths);
48
+ for (const path of modulePaths) {
49
+ const relative2 = relativeWithDot(silgi.options.build.dir, path);
50
+ include.add(join(relative2, "runtime"));
51
+ exclude.add(join(relative2, "runtime/server"));
52
+ include.add(join(relative2, "dist/runtime"));
53
+ exclude.add(join(relative2, "dist/runtime/server"));
54
+ }
55
+ const tsConfig = defu(silgi.options.typescript?.tsConfig, {
56
+ compilerOptions: {
57
+ forceConsistentCasingInFileNames: true,
58
+ strict: silgi.options.typescript.strict,
59
+ noEmit: true,
60
+ target: "ESNext",
61
+ module: "ESNext",
62
+ moduleResolution: "Bundler",
63
+ allowJs: true,
64
+ resolveJsonModule: true,
65
+ jsx: "preserve",
66
+ allowSyntheticDefaultImports: true,
67
+ jsxFactory: "h",
68
+ jsxFragmentFactory: "Fragment",
69
+ allowImportingTsExtensions: true,
70
+ ...silgi.options.typescript.customConditions ? { customConditions: ["silgiTypes"] } : {},
71
+ paths: {
72
+ "#silgiImports": [
73
+ relativeWithDot(tsconfigDir, join(silgi.options.build.typesDir, "silgi-imports"))
74
+ ],
75
+ ...silgi.scanModules.reduce((acc, m) => {
76
+ if (m.entryPath) {
77
+ acc[m.meta.name] = [relativeWithDot(tsconfigDir, m.entryPath)];
78
+ }
79
+ return acc;
80
+ }, {}),
81
+ ...silgi.scanModules.reduce((acc, m) => {
82
+ if (m.entryPath) {
83
+ const directory = getDirectory(m.entryPath);
84
+ acc[`${m.meta.name}/*`] = [`${relativeWithDot(tsconfigDir, directory)}/*`];
85
+ }
86
+ return acc;
87
+ }, {})
88
+ // ...(silgi.options.typescript?.internalPaths
89
+ // ? {
90
+ // 'silgi/runtime': [
91
+ // relativeWithDot(tsconfigDir, join(runtimeDir, 'index')),
92
+ // ],
93
+ // '#internal/silgi': [
94
+ // relativeWithDot(tsconfigDir, join(runtimeDir, 'index')),
95
+ // ],
96
+ // 'silgi/runtime/*': [
97
+ // relativeWithDot(tsconfigDir, join(runtimeDir, '*')),
98
+ // ],
99
+ // '#internal/silgi/*': [
100
+ // relativeWithDot(tsconfigDir, join(runtimeDir, '*')),
101
+ // ],
102
+ // }
103
+ // : {}),
104
+ }
105
+ },
106
+ include: [...include],
107
+ exclude: [...exclude]
108
+ });
109
+ tsConfig.compilerOptions ||= {};
110
+ tsConfig.compilerOptions.paths ||= {};
111
+ tsConfig.include ||= [];
112
+ for (const alias in tsConfig.compilerOptions.paths) {
113
+ const paths = tsConfig.compilerOptions.paths[alias];
114
+ tsConfig.compilerOptions.paths[alias] = await Promise.all(
115
+ paths.map(async (path) => {
116
+ if (!isAbsolute(path)) {
117
+ return path;
118
+ }
119
+ const stats = await promises.stat(path).catch(
120
+ () => null
121
+ /* file does not exist */
122
+ );
123
+ return relativeWithDot(
124
+ tsconfigDir,
125
+ stats?.isFile() ? path.replace(/\b\.\w+$/g, "") : path
126
+ );
127
+ })
128
+ );
129
+ }
130
+ const references = [];
131
+ await Promise.all([...silgi.options.modules, ...silgi.options._modules].map(async (id) => {
132
+ if (typeof id !== "string") {
133
+ return;
134
+ }
135
+ const pkg = await readPackageJSON(id, { url: silgi.options.modulesDir }).catch(() => null);
136
+ references.push({ types: pkg?.name || id });
137
+ }));
138
+ const declarations = [];
139
+ await silgi.callHook("prepare:types", { references, declarations, tsConfig });
140
+ tsConfig.include = [...new Set(tsConfig.include.map((p) => isAbsolute(p) ? relativeWithDot(silgi.options.build.dir, p) : p))];
141
+ tsConfig.exclude = [...new Set(tsConfig.exclude.map((p) => isAbsolute(p) ? relativeWithDot(silgi.options.build.dir, p) : p))];
142
+ const _declarations = [
143
+ ...references.map((ref) => {
144
+ if ("path" in ref && isAbsolute(ref.path)) {
145
+ ref.path = relative(silgi.options.build.dir, ref.path);
146
+ }
147
+ return `/// <reference ${renderAttrs(ref)} />`;
148
+ }),
149
+ ...declarations,
150
+ "",
151
+ "export {}",
152
+ ""
153
+ ];
154
+ return {
155
+ declarations: _declarations,
156
+ tsConfig
157
+ };
158
+ }
159
+
160
+ export { silgiGenerateType };
@@ -0,0 +1,84 @@
1
+ import { createConsola } from 'consola';
2
+ import defu from 'defu';
3
+ import { isEvent } from 'h3';
4
+ import { createHooks } from 'hookable';
5
+ import { applyDefaults } from 'untyped';
6
+ import { SilgiConfigSchema } from '../schema/index.mjs';
7
+ import { silgiCtx } from './unctx.mjs';
8
+ import { scanAction } from './uris/uri.mjs';
9
+ import { createStorage, useSilgiStorage } from './utils/storage.mjs';
10
+
11
+ async function runSilgiPlugins(silgi) {
12
+ for (const plugin of silgi.plugins) {
13
+ try {
14
+ await plugin(silgi);
15
+ } catch (error) {
16
+ silgi.captureError(error, { tags: ["plugin"] });
17
+ throw error;
18
+ }
19
+ }
20
+ }
21
+ async function createSilgi(config) {
22
+ const hooks = createHooks();
23
+ await applyDefaults(SilgiConfigSchema, config.options);
24
+ const silgi = {
25
+ schemas: config.schemas,
26
+ services: config.services ?? {},
27
+ shared: config.shared ?? void 0,
28
+ uris: config.uris ?? {},
29
+ modulesURIs: config.modulesURIs ?? {},
30
+ scannedHandlers: /* @__PURE__ */ new Map(),
31
+ plugins: config.plugins ?? [],
32
+ framework: config.framework ?? void 0,
33
+ storage: config.storage ?? void 0,
34
+ options: config.options,
35
+ hooks,
36
+ callHook: hooks.callHook,
37
+ addHooks: hooks.addHooks,
38
+ hook: hooks.hook,
39
+ ready: () => {
40
+ return hooks.callHook("ready", silgi);
41
+ },
42
+ close: () => hooks.callHook("close", silgi),
43
+ logger: createConsola(defu(config.options.consolaOptions, {
44
+ tag: "silgi"
45
+ })).withTag("silgi"),
46
+ captureError: (error, context = {}) => {
47
+ const promise = hooks.callHookParallel("error", error, context).catch((error_) => {
48
+ console.error("Error while capturing another error", error_);
49
+ });
50
+ if (context.event && isEvent(context.event)) {
51
+ const errors = context.event.context.nitro?.errors;
52
+ if (errors) {
53
+ errors.push({ error, context });
54
+ }
55
+ if (context.event.waitUntil) {
56
+ context.event.waitUntil(promise);
57
+ }
58
+ }
59
+ }
60
+ };
61
+ await runSilgiPlugins(silgi);
62
+ await scanAction(silgi);
63
+ if (!silgi.storage) {
64
+ silgi.storage = await createStorage(silgi);
65
+ }
66
+ silgi.shared.storage = (...data) => {
67
+ return useSilgiStorage(...data);
68
+ };
69
+ if (silgiCtx.tryUse()) {
70
+ silgiCtx.unset();
71
+ silgiCtx.set(silgi);
72
+ } else {
73
+ silgiCtx.set(silgi);
74
+ silgi.hook("close", () => silgiCtx.unset());
75
+ }
76
+ silgi.logger.info("Silgi installed");
77
+ hooks.hookOnce("close", async () => {
78
+ hooks.removeAllHooks();
79
+ await silgi.storage.dispose();
80
+ });
81
+ return silgi;
82
+ }
83
+
84
+ export { createSilgi };