silgi 0.24.15 → 0.24.17

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 (91) hide show
  1. package/dist/cli/build/prepare.mjs +43 -0
  2. package/dist/cli/{dev.mjs → commands/dev.mjs} +4 -43
  3. package/dist/cli/commands/env.mjs +40 -0
  4. package/dist/cli/{install.mjs → commands/install.mjs} +3 -37
  5. package/dist/cli/commands/prepare.mjs +66 -0
  6. package/dist/cli/{prepare.mjs → commands/run.mjs} +9 -82
  7. package/dist/cli/config/defaults.mjs +129 -0
  8. package/dist/cli/config/index.mjs +2 -16
  9. package/dist/cli/config/loader.mjs +97 -0
  10. package/dist/cli/config/resolvers/compatibility.mjs +90 -0
  11. package/dist/cli/config/resolvers/imports.mjs +96 -0
  12. package/dist/cli/config/resolvers/paths.mjs +167 -0
  13. package/dist/cli/config/resolvers/storage.mjs +25 -0
  14. package/dist/cli/config/resolvers/url.mjs +7 -0
  15. package/dist/cli/config/types.mjs +191 -0
  16. package/dist/cli/core/app.mjs +92 -0
  17. package/dist/cli/core/devServer.mjs +8 -0
  18. package/dist/cli/core/env.mjs +76 -0
  19. package/dist/cli/core/installPackage.mjs +31 -0
  20. package/dist/cli/core/prepare.mjs +7 -0
  21. package/dist/cli/core/runtimeConfig.mjs +14 -0
  22. package/dist/cli/core/scan.mjs +39 -0
  23. package/dist/cli/core/silgi.mjs +125 -0
  24. package/dist/cli/core/templates.mjs +31 -0
  25. package/dist/cli/framework/emptyFramework.mjs +9 -0
  26. package/dist/cli/framework/h3.mjs +89 -0
  27. package/dist/cli/framework/index.mjs +8 -0
  28. package/dist/cli/framework/nitro.mjs +106 -0
  29. package/dist/cli/framework/nuxt.mjs +9 -0
  30. package/dist/cli/index.mjs +6 -9
  31. package/dist/cli/module/exportScan.mjs +130 -0
  32. package/dist/cli/module/install.mjs +59 -0
  33. package/dist/cli/module/scan.mjs +227 -0
  34. package/dist/cli/scan/commands.mjs +47 -0
  35. package/dist/cli/scan/prepareConfigs.mjs +46 -0
  36. package/dist/cli/scan/prepareCoreFile.mjs +166 -0
  37. package/dist/cli/scan/prepareFramework.mjs +73 -0
  38. package/dist/cli/scan/prepareSchema.mjs +177 -0
  39. package/dist/cli/scan/prepareServerFiles.mjs +119 -0
  40. package/dist/cli/scan/scanExportFile.mjs +155 -0
  41. package/dist/cli/scan/writeCoreFile.mjs +34 -0
  42. package/dist/cli/scan/writeScanFiles.mjs +30 -0
  43. package/dist/cli/scan/writeTypesAndFiles.mjs +109 -0
  44. package/dist/cli/utils/build-uri-map.mjs +39 -0
  45. package/dist/cli/utils/common.mjs +13 -0
  46. package/dist/cli/{compatibility.mjs → utils/compatibility.mjs} +1 -1
  47. package/dist/cli/utils/generateRouterDTS.mjs +80 -0
  48. package/dist/cli/utils/ignore.mjs +46 -0
  49. package/dist/cli/utils/parser.mjs +168 -0
  50. package/dist/cli/utils/readScanFile.mjs +79 -0
  51. package/dist/cli/utils/storage.mjs +25 -0
  52. package/dist/core/createSilgi.mjs +76 -0
  53. package/dist/core/error.mjs +227 -0
  54. package/dist/core/index.mjs +8 -0
  55. package/dist/core/routeRules.mjs +288 -0
  56. package/dist/core/silgi.mjs +128 -0
  57. package/dist/core/silgiApp.mjs +25 -0
  58. package/dist/core/storage.mjs +15 -0
  59. package/dist/core/unctx.mjs +27 -0
  60. package/dist/core/uris/uri.mjs +33 -0
  61. package/dist/core/uris/utils.mjs +130 -0
  62. package/dist/core/utils/event.mjs +15 -0
  63. package/dist/core/utils/merge.mjs +29 -0
  64. package/dist/core/utils/runtime.mjs +22 -0
  65. package/dist/core/utils/schema.mjs +5 -0
  66. package/dist/core/utils/service.mjs +5 -0
  67. package/dist/core/utils/shared.mjs +5 -0
  68. package/dist/core/utils/storage.mjs +72 -0
  69. package/dist/index.mjs +20 -793
  70. package/dist/kit/errors.mjs +11 -0
  71. package/dist/kit/esm.mjs +14 -0
  72. package/dist/kit/fs.mjs +30 -0
  73. package/dist/kit/gen.mjs +44 -0
  74. package/dist/kit/hash.mjs +8 -0
  75. package/dist/kit/index.mjs +15 -528
  76. package/dist/kit/isFramework.mjs +25 -0
  77. package/dist/kit/logger.mjs +7 -0
  78. package/dist/kit/module.mjs +73 -0
  79. package/dist/kit/parseServices.mjs +57 -0
  80. package/dist/kit/path.mjs +34 -0
  81. package/dist/kit/preset.mjs +6 -0
  82. package/dist/kit/resolve.mjs +80 -0
  83. package/dist/kit/template.mjs +49 -0
  84. package/dist/kit/useRequest.mjs +91 -0
  85. package/dist/kit/utils.mjs +43 -0
  86. package/dist/package.json.mjs +5 -0
  87. package/dist/types/index.d.mts +1 -1
  88. package/package.json +1 -1
  89. package/dist/_chunks/silgiApp.mjs +0 -2682
  90. package/dist/cli/types.mjs +0 -772
  91. /package/dist/cli/{init.mjs → commands/init.mjs} +0 -0
@@ -0,0 +1,31 @@
1
+ import { addTemplate } from 'silgi/kit';
2
+ import { peerDependencies } from 'silgi/meta';
3
+
4
+ async function installPackages(silgi) {
5
+ const packages = {
6
+ dependencies: {
7
+ "@fastify/deepmerge": peerDependencies["@fastify/deepmerge"],
8
+ "@silgi/ecosystem": peerDependencies["@silgi/ecosystem"],
9
+ ...silgi.options.installPackages?.dependencies
10
+ },
11
+ devDependencies: {
12
+ ...silgi.options.installPackages?.devDependencies
13
+ }
14
+ };
15
+ await silgi.callHook("prepare:installPackages", packages);
16
+ if (silgi.options.preset === "npm-package") {
17
+ packages.devDependencies = {
18
+ ...packages.devDependencies,
19
+ ...packages.dependencies
20
+ };
21
+ packages.dependencies = {};
22
+ }
23
+ addTemplate({
24
+ filename: "install.json",
25
+ where: ".silgi",
26
+ write: true,
27
+ getContents: () => JSON.stringify(packages, null, 2)
28
+ });
29
+ }
30
+
31
+ export { installPackages };
@@ -0,0 +1,7 @@
1
+ import 'node:fs';
2
+ import 'node:fs/promises';
3
+
4
+ async function prepare(_silgi) {
5
+ }
6
+
7
+ export { prepare };
@@ -0,0 +1,14 @@
1
+ import { initRuntimeConfig } from 'silgi/runtime';
2
+
3
+ function useCLIRuntimeConfig(silgi) {
4
+ const safeRuntimeConfig = JSON.parse(JSON.stringify(silgi.options.runtimeConfig));
5
+ silgi.hook("prepare:configs.ts", (data) => {
6
+ data.runtimeConfig = safeRuntimeConfig;
7
+ silgi.options.envOptions = silgi.options.envOptions;
8
+ });
9
+ const _sharedRuntimeConfig = initRuntimeConfig(silgi.options.envOptions, silgi.options.runtimeConfig);
10
+ silgi.options.runtimeConfig = _sharedRuntimeConfig;
11
+ return _sharedRuntimeConfig;
12
+ }
13
+
14
+ export { useCLIRuntimeConfig };
@@ -0,0 +1,39 @@
1
+ import { globby } from 'globby';
2
+ import { join, relative } from 'pathe';
3
+
4
+ const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}";
5
+ async function scanAndSyncOptions(silgi) {
6
+ const scannedModules = await scanModules(silgi);
7
+ silgi.options.modules = silgi.options.modules || [];
8
+ for (const modPath of scannedModules) {
9
+ if (!silgi.options.modules.includes(modPath)) {
10
+ silgi.options.modules.push(modPath);
11
+ }
12
+ }
13
+ }
14
+ async function scanModules(silgi) {
15
+ const files = await scanFiles(silgi, "silgi/modules");
16
+ return files.map((f) => f.fullPath);
17
+ }
18
+ async function scanFiles(silgi, name) {
19
+ const files = await Promise.all(
20
+ silgi.options.scanDirs.map((dir) => scanDir(silgi, dir, name))
21
+ ).then((r) => r.flat());
22
+ return files;
23
+ }
24
+ async function scanDir(silgi, dir, name) {
25
+ const fileNames = await globby(join(name, GLOB_SCAN_PATTERN), {
26
+ cwd: dir,
27
+ dot: true,
28
+ ignore: silgi.options.ignore,
29
+ absolute: true
30
+ });
31
+ return fileNames.map((fullPath) => {
32
+ return {
33
+ fullPath,
34
+ path: relative(join(dir, name), fullPath)
35
+ };
36
+ }).sort((a, b) => a.path.localeCompare(b.path));
37
+ }
38
+
39
+ export { GLOB_SCAN_PATTERN, scanAndSyncOptions, scanModules };
@@ -0,0 +1,125 @@
1
+ import { consola } from 'consola';
2
+ import { createHooks, createDebugger } from 'hookable';
3
+ import { join } from 'pathe';
4
+ import { silgiCLICtx, autoImportTypes } from 'silgi';
5
+ import { resolveSilgiPath } from 'silgi/kit';
6
+ import { runtimeDir } from 'silgi/runtime/meta';
7
+ import { createUnimport } from 'unimport';
8
+ import { createRouteRules } from '../../core/routeRules.mjs';
9
+ import { prepareEnv } from '../commands/env.mjs';
10
+ import { frameworkSetup } from '../framework/index.mjs';
11
+ import { registerModuleExportScan } from '../module/exportScan.mjs';
12
+ import { installModules } from '../module/install.mjs';
13
+ import { scanModules } from '../module/scan.mjs';
14
+ import { commands } from '../scan/commands.mjs';
15
+ import { scanExportFile } from '../scan/scanExportFile.mjs';
16
+ import { writeScanFiles } from '../scan/writeScanFiles.mjs';
17
+ import { createStorageCLI } from '../utils/storage.mjs';
18
+ import { generateApp } from './app.mjs';
19
+ import { installPackages } from './installPackage.mjs';
20
+ import { useCLIRuntimeConfig } from './runtimeConfig.mjs';
21
+ import { scanAndSyncOptions } from './scan.mjs';
22
+ import { loadOptions } from '../config/loader.mjs';
23
+
24
+ async function createSilgiCLI(config = {}, opts = {}) {
25
+ const options = await loadOptions(config, opts);
26
+ const hooks = createHooks();
27
+ const silgi = {
28
+ modulesURIs: {},
29
+ scannedURIs: /* @__PURE__ */ new Map(),
30
+ services: {},
31
+ uris: {},
32
+ shareds: {},
33
+ schemas: {},
34
+ unimport: void 0,
35
+ options,
36
+ hooks,
37
+ errors: [],
38
+ commands: {},
39
+ _requiredModules: {},
40
+ logger: consola.withTag("silgi"),
41
+ close: () => silgi.hooks.callHook("close", silgi),
42
+ storage: void 0,
43
+ scanModules: [],
44
+ templates: [],
45
+ callHook: hooks.callHook,
46
+ addHooks: hooks.addHooks,
47
+ hook: hooks.hook,
48
+ async updateConfig(_config) {
49
+ },
50
+ routeRules: void 0
51
+ };
52
+ await prepareEnv(options);
53
+ const routeRules = createRouteRules();
54
+ routeRules.importRules(options.routeRules ?? {});
55
+ silgi.routeRules = routeRules;
56
+ if (silgiCLICtx.tryUse()) {
57
+ silgiCLICtx.unset();
58
+ silgiCLICtx.set(silgi);
59
+ } else {
60
+ silgiCLICtx.set(silgi);
61
+ silgi.hook("close", () => silgiCLICtx.unset());
62
+ }
63
+ if (silgi.options.debug) {
64
+ createDebugger(silgi.hooks, { tag: "silgi" });
65
+ silgi.options.plugins.push({
66
+ path: join(runtimeDir, "internal/debug"),
67
+ packageImport: "silgi/runtime/internal/debug"
68
+ });
69
+ }
70
+ for (const framework of frameworkSetup) {
71
+ await framework(silgi);
72
+ }
73
+ await scanAndSyncOptions(silgi);
74
+ await scanModules(silgi);
75
+ await scanExportFile(silgi);
76
+ await installModules(silgi, true);
77
+ useCLIRuntimeConfig(silgi);
78
+ await writeScanFiles(silgi);
79
+ silgi.storage = await createStorageCLI(silgi);
80
+ silgi.hooks.hook("close", async () => {
81
+ await silgi.storage.dispose();
82
+ });
83
+ if (silgi.options.logLevel !== void 0) {
84
+ silgi.logger.level = silgi.options.logLevel;
85
+ }
86
+ silgi.hooks.addHooks(silgi.options.hooks);
87
+ await installModules(silgi);
88
+ await silgi.hooks.callHook("scanFiles:done", silgi);
89
+ await commands(silgi);
90
+ await installPackages(silgi);
91
+ await generateApp(silgi);
92
+ if (silgi.options.imports) {
93
+ silgi.options.imports.dirs ??= [];
94
+ silgi.options.imports.dirs = silgi.options.imports.dirs.map((dir) => {
95
+ if (typeof dir === "string") {
96
+ if (dir.startsWith("!")) {
97
+ return `!${resolveSilgiPath(dir.slice(1), options, silgi.options.rootDir)}`;
98
+ }
99
+ return resolveSilgiPath(dir, options, silgi.options.rootDir);
100
+ }
101
+ return dir;
102
+ });
103
+ silgi.options.imports.presets.push({
104
+ from: "silgi/types",
105
+ imports: autoImportTypes.map((type) => type),
106
+ type: true
107
+ });
108
+ silgi.options.imports.presets.push({
109
+ from: "silgi/types",
110
+ imports: autoImportTypes.map((type) => type),
111
+ type: true
112
+ });
113
+ silgi.options.imports.presets.push({
114
+ from: "silgi/runtime/internal/ofetch",
115
+ imports: ["createSilgiFetch", "silgi$fetch"]
116
+ });
117
+ silgi.unimport = createUnimport(silgi.options.imports);
118
+ await silgi.unimport.init();
119
+ }
120
+ await registerModuleExportScan(silgi);
121
+ await writeScanFiles(silgi);
122
+ return silgi;
123
+ }
124
+
125
+ export { createSilgiCLI };
@@ -0,0 +1,31 @@
1
+ const vueShim = {
2
+ filename: "delete/testtest.d.ts",
3
+ where: ".silgi",
4
+ getContents: ({ app }) => {
5
+ if (!app.options.typescript.shim) {
6
+ return "";
7
+ }
8
+ return [
9
+ "declare module '*.vue' {",
10
+ " import { DefineComponent } from 'vue'",
11
+ " const component: DefineComponent<{}, {}, any>",
12
+ " export default component",
13
+ "}"
14
+ ].join("\n");
15
+ }
16
+ };
17
+ const pluginsDeclaration = {
18
+ filename: "delete/testtest1.d.ts",
19
+ where: ".silgi",
20
+ getContents: async () => {
21
+ return `
22
+ declare module 'nuxt' {
23
+ interface NuxtApp {
24
+ $myPlugin: any;
25
+ }
26
+ }
27
+ `;
28
+ }
29
+ };
30
+
31
+ export { pluginsDeclaration, vueShim };
@@ -0,0 +1,9 @@
1
+ async function emptyFramework(silgi) {
2
+ if (silgi.options.preset === "npm-package" || !silgi.options.preset) {
3
+ silgi.hook("after:prepare:schema.ts", (data) => {
4
+ data.unshift("type FrameworkContextExtends = {}");
5
+ });
6
+ }
7
+ }
8
+
9
+ export { emptyFramework };
@@ -0,0 +1,89 @@
1
+ import { resolveModuleExportNames } from 'mlly';
2
+
3
+ async function h3Framework(silgi, skip = false) {
4
+ if (silgi.options.preset !== "h3" && skip === false)
5
+ return;
6
+ if (silgi.options.preset === "h3") {
7
+ silgi.hook("after:prepare:schema.ts", (data) => {
8
+ data.unshift("type FrameworkContextExtends = NitroApp");
9
+ });
10
+ }
11
+ silgi.hook("prepare:schema.ts", (data) => {
12
+ data.importItems.nitropack = {
13
+ import: [
14
+ {
15
+ name: "NitroApp",
16
+ type: true,
17
+ key: "NitroApp"
18
+ }
19
+ ],
20
+ from: "nitropack/types"
21
+ };
22
+ data.importItems.h3 = {
23
+ import: [
24
+ {
25
+ name: "H3Event",
26
+ type: true,
27
+ key: "H3Event"
28
+ }
29
+ ],
30
+ from: "h3"
31
+ };
32
+ data.events.push({
33
+ key: "H3Event",
34
+ value: "H3Event",
35
+ extends: true,
36
+ isSilgiContext: false
37
+ });
38
+ });
39
+ silgi.hook("prepare:createDTSFramework", (data) => {
40
+ data.importItems["silgi/types"] = {
41
+ import: [
42
+ {
43
+ name: "SilgiRuntimeContext",
44
+ type: true,
45
+ key: "SilgiRuntimeContext"
46
+ }
47
+ ],
48
+ from: "silgi/types"
49
+ };
50
+ data.customContent?.push(
51
+ "",
52
+ 'declare module "h3" {',
53
+ " interface H3EventContext extends SilgiRuntimeContext {}",
54
+ "}",
55
+ ""
56
+ );
57
+ });
58
+ silgi.hook("prepare:core.ts", (data) => {
59
+ data._silgiConfigs.push(`captureError: (error, context = {}) => {
60
+ const promise = silgi.hooks
61
+ .callHookParallel('error', error, context)
62
+ .catch((error_) => {
63
+ console.error('Error while capturing another error', error_)
64
+ })
65
+
66
+ if (context.event && isEvent(context.event)) {
67
+ const errors = context.event.context.nitro?.errors
68
+ if (errors) {
69
+ errors.push({ error, context })
70
+ }
71
+ if (context.event.waitUntil) {
72
+ context.event.waitUntil(promise)
73
+ }
74
+ }
75
+ }`);
76
+ });
77
+ if (silgi.options.imports !== false) {
78
+ const h3Exports = await resolveModuleExportNames("h3", {
79
+ url: import.meta.url
80
+ });
81
+ silgi.options.imports.presets ??= [];
82
+ silgi.options.imports.presets.push({
83
+ from: "h3",
84
+ imports: h3Exports.filter((n) => !/^[A-Z]/.test(n) && n !== "use")
85
+ });
86
+ }
87
+ }
88
+
89
+ export { h3Framework };
@@ -0,0 +1,8 @@
1
+ import { emptyFramework } from './emptyFramework.mjs';
2
+ import { h3Framework } from './h3.mjs';
3
+ import { nitroFramework } from './nitro.mjs';
4
+ import { nuxtFramework } from './nuxt.mjs';
5
+
6
+ const frameworkSetup = [emptyFramework, h3Framework, nitroFramework, nuxtFramework];
7
+
8
+ export { frameworkSetup };
@@ -0,0 +1,106 @@
1
+ import { join } from 'pathe';
2
+ import { runtimeDir } from 'silgi/runtime/meta';
3
+ import { h3Framework } from './h3.mjs';
4
+
5
+ async function nitroFramework(silgi, skip = false) {
6
+ if (silgi.options.preset !== "nitro" && skip === false)
7
+ return;
8
+ silgi.hook("prepare:schema.ts", (data) => {
9
+ data.importItems.nitropack = {
10
+ import: [
11
+ {
12
+ name: "NitroApp",
13
+ type: true,
14
+ key: "NitroApp"
15
+ }
16
+ ],
17
+ from: "nitropack/types"
18
+ };
19
+ });
20
+ silgi.hook("after:prepare:schema.ts", (data) => {
21
+ data.unshift("type FrameworkContextExtends = NitroApp");
22
+ });
23
+ silgi.options.plugins.push({
24
+ packageImport: "silgi/runtime/internal/nitro",
25
+ path: join(runtimeDir, "internal/nitro")
26
+ });
27
+ silgi.hook("prepare:createDTSFramework", (data) => {
28
+ data.importItems["nitropack/types"] = {
29
+ import: [
30
+ {
31
+ name: "NitroRuntimeConfig",
32
+ type: true,
33
+ key: "NitroRuntimeConfig"
34
+ }
35
+ ],
36
+ from: "nitropack/types"
37
+ };
38
+ data.customContent?.push(
39
+ "",
40
+ 'declare module "silgi/types" {',
41
+ " interface SilgiRuntimeConfig extends NitroRuntimeConfig {}",
42
+ "}",
43
+ ""
44
+ );
45
+ });
46
+ if (silgi.options.imports !== false) {
47
+ silgi.options.imports.presets ??= [];
48
+ silgi.options.imports.presets.push(...getNitroImportsPreset());
49
+ }
50
+ await h3Framework(silgi, true);
51
+ }
52
+ function getNitroImportsPreset() {
53
+ return [
54
+ {
55
+ from: "nitropack/runtime/internal/app",
56
+ imports: ["useNitroApp"]
57
+ },
58
+ {
59
+ from: "nitropack/runtime/internal/config",
60
+ imports: ["useRuntimeConfig", "useAppConfig"]
61
+ },
62
+ {
63
+ from: "nitropack/runtime/internal/plugin",
64
+ imports: ["defineNitroPlugin", "nitroPlugin"]
65
+ },
66
+ {
67
+ from: "nitropack/runtime/internal/cache",
68
+ imports: [
69
+ "defineCachedFunction",
70
+ "defineCachedEventHandler",
71
+ "cachedFunction",
72
+ "cachedEventHandler"
73
+ ]
74
+ },
75
+ {
76
+ from: "nitropack/runtime/internal/storage",
77
+ imports: ["useStorage"]
78
+ },
79
+ {
80
+ from: "nitropack/runtime/internal/renderer",
81
+ imports: ["defineRenderHandler"]
82
+ },
83
+ {
84
+ from: "nitropack/runtime/internal/meta",
85
+ imports: ["defineRouteMeta"]
86
+ },
87
+ {
88
+ from: "nitropack/runtime/internal/route-rules",
89
+ imports: ["getRouteRules"]
90
+ },
91
+ {
92
+ from: "nitropack/runtime/internal/context",
93
+ imports: ["useEvent"]
94
+ },
95
+ {
96
+ from: "nitropack/runtime/internal/task",
97
+ imports: ["defineTask", "runTask"]
98
+ },
99
+ {
100
+ from: "nitropack/runtime/internal/error/utils",
101
+ imports: ["defineNitroErrorHandler"]
102
+ }
103
+ ];
104
+ }
105
+
106
+ export { nitroFramework };
@@ -0,0 +1,9 @@
1
+ import { nitroFramework } from './nitro.mjs';
2
+
3
+ async function nuxtFramework(silgi, skip = false) {
4
+ if (silgi.options.preset !== "nuxt" && skip === false)
5
+ return;
6
+ await nitroFramework(silgi, true);
7
+ }
8
+
9
+ export { nuxtFramework };
@@ -1,9 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCommand, runMain } from 'citty';
3
-
4
- const version = "0.24.15";
5
- const packageJson = {
6
- version: version};
3
+ import packageJson from '../package.json.mjs';
7
4
 
8
5
  const main = defineCommand({
9
6
  meta: {
@@ -18,11 +15,11 @@ const main = defineCommand({
18
15
  }
19
16
  },
20
17
  subCommands: {
21
- prepare: () => import('./prepare.mjs').then(function (n) { return n.a; }).then((m) => m.default),
22
- init: () => import('./init.mjs').then((m) => m.default),
23
- run: () => import('./prepare.mjs').then(function (n) { return n.r; }).then((m) => m.default),
24
- install: () => import('./install.mjs').then((m) => m.default),
25
- dev: () => import('./dev.mjs').then((m) => m.default)
18
+ prepare: () => import('./commands/prepare.mjs').then((m) => m.default),
19
+ init: () => import('./commands/init.mjs').then((m) => m.default),
20
+ run: () => import('./commands/run.mjs').then((m) => m.default),
21
+ install: () => import('./commands/install.mjs').then((m) => m.default),
22
+ dev: () => import('./commands/dev.mjs').then((m) => m.default)
26
23
  },
27
24
  run({ args }) {
28
25
  if (args.version)
@@ -0,0 +1,130 @@
1
+ import { promises } from 'node:fs';
2
+ import { findTypeExports, findExports } from 'mlly';
3
+ import { relativeWithDot, hash } from 'silgi/kit';
4
+
5
+ async function registerModuleExportScan(silgi) {
6
+ silgi.hook("prepare:schema.ts", async (options) => {
7
+ for (const module of silgi.scanModules) {
8
+ const moduleReExports = [];
9
+ if (!module.entryPath) {
10
+ continue;
11
+ }
12
+ const moduleTypes = await promises.readFile(module.entryPath.replace(/\.mjs$/, "Types.d.ts"), "utf8").catch(() => "");
13
+ const normalisedModuleTypes = moduleTypes.replace(/export\s*\{.*?\}/gs, (match) => match.replace(/\b(type|interface)\b/g, ""));
14
+ for (const e of findTypeExports(normalisedModuleTypes)) {
15
+ moduleReExports.push(e);
16
+ }
17
+ for (const e of findExports(normalisedModuleTypes)) {
18
+ moduleReExports.push(e);
19
+ }
20
+ const hasTypeExport = (name) => moduleReExports.find((exp) => exp.names?.includes(name));
21
+ const configKey = module.meta.configKey;
22
+ const moduleName = module.meta.name || module.meta._packageName;
23
+ options.importItems[configKey] = {
24
+ import: [],
25
+ from: module.meta._packageName ? moduleName : relativeWithDot(silgi.options.build.typesDir, module.entryPath)
26
+ };
27
+ if (hasTypeExport("ModuleOptions")) {
28
+ const importName = `_${hash(`${configKey}ModuleOptions`)}`;
29
+ options.importItems[configKey].import.push({
30
+ name: `ModuleOptions as ${importName}`,
31
+ type: true,
32
+ key: importName
33
+ });
34
+ options.options.push({ key: configKey, value: importName });
35
+ }
36
+ if (hasTypeExport("ModuleRuntimeOptions")) {
37
+ const importName = `_${hash(`${configKey}ModuleRuntimeOptions`)}`;
38
+ options.importItems[configKey].import.push({
39
+ name: `ModuleRuntimeOptions as ${importName}`,
40
+ type: true,
41
+ key: importName
42
+ });
43
+ options.runtimeOptions.push({ key: configKey, value: importName });
44
+ }
45
+ if (hasTypeExport("ModuleRuntimeShareds")) {
46
+ const importName = `_${hash(`${configKey}ModuleRuntimeShareds`)}`;
47
+ options.importItems[configKey].import.push({
48
+ name: `ModuleRuntimeShareds as ${importName}`,
49
+ type: true,
50
+ key: importName
51
+ });
52
+ options.shareds.push({ key: configKey, value: importName });
53
+ }
54
+ if (hasTypeExport("ModuleEvents")) {
55
+ const importName = `_${hash(`${configKey}ModuleEvents`)}`;
56
+ options.importItems[configKey].import.push({
57
+ name: `ModuleEvents as ${importName}`,
58
+ type: true,
59
+ key: importName
60
+ });
61
+ options.events.push({ key: configKey, value: importName });
62
+ }
63
+ if (hasTypeExport("ModuleRuntimeContexts")) {
64
+ const importName = `_${hash(`${configKey}ModuleRuntimeContexts`)}`;
65
+ options.importItems[configKey].import.push({
66
+ name: `ModuleRuntimeContexts as ${importName}`,
67
+ type: true,
68
+ key: importName
69
+ });
70
+ options.contexts.push({ key: configKey, value: importName });
71
+ }
72
+ if (hasTypeExport("ModuleHooks")) {
73
+ const importName = `_${hash(`${configKey}ModuleHooks`)}`;
74
+ options.importItems[configKey].import.push({
75
+ name: `ModuleHooks as ${importName}`,
76
+ type: true,
77
+ key: importName
78
+ });
79
+ options.hooks.push({ key: configKey, value: importName });
80
+ }
81
+ if (hasTypeExport("ModuleRuntimeHooks")) {
82
+ const importName = `_${hash(`${configKey}RuntimeHooks`)}`;
83
+ options.importItems[configKey].import.push({
84
+ name: `ModuleRuntimeHooks as ${importName}`,
85
+ type: true,
86
+ key: importName
87
+ });
88
+ options.runtimeHooks.push({ key: configKey, value: importName });
89
+ }
90
+ if (hasTypeExport("ModuleRuntimeActions")) {
91
+ const importName = `_${hash(`${configKey}ModuleRuntimeActions`)}`;
92
+ options.importItems[configKey].import.push({
93
+ name: `ModuleRuntimeActions as ${importName}`,
94
+ type: true,
95
+ key: importName
96
+ });
97
+ options.actions.push({ key: configKey, value: importName });
98
+ }
99
+ if (hasTypeExport("ModuleRuntimeMethods")) {
100
+ const importName = `_${hash(`${configKey}ModuleRuntimeMethods`)}`;
101
+ options.importItems[configKey].import.push({
102
+ name: `ModuleRuntimeMethods as ${importName}`,
103
+ type: true,
104
+ key: importName
105
+ });
106
+ options.methods.push({ key: configKey, value: importName });
107
+ }
108
+ if (hasTypeExport("ModuleRuntimeRouteRules")) {
109
+ const importName = `_${hash(`${configKey}ModuleRuntimeRouteRules`)}`;
110
+ options.importItems[configKey].import.push({
111
+ name: `ModuleRuntimeRouteRules as ${importName}`,
112
+ type: true,
113
+ key: importName
114
+ });
115
+ options.routeRules.push({ key: configKey, value: importName });
116
+ }
117
+ if (hasTypeExport("ModuleRuntimeRouteRulesConfig")) {
118
+ const importName = `_${hash(`${configKey}ModuleRuntimeRouteRulesConfig`)}`;
119
+ options.importItems[configKey].import.push({
120
+ name: `ModuleRuntimeRouteRulesConfig as ${importName}`,
121
+ type: true,
122
+ key: importName
123
+ });
124
+ options.routeRulesConfig.push({ key: configKey, value: importName });
125
+ }
126
+ }
127
+ });
128
+ }
129
+
130
+ export { registerModuleExportScan };