silgi 0.9.1 → 0.9.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/prepare.mjs +176 -176
- package/dist/meta/index.d.mts +1 -1
- package/dist/meta/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/_chunks/index.mjs
CHANGED
package/dist/cli/prepare.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { defineCommand } from 'citty';
|
|
2
2
|
import consola, { consola as consola$1 } from 'consola';
|
|
3
|
-
import {
|
|
3
|
+
import { resolve, isAbsolute, relative, join, dirname, basename, extname } from 'pathe';
|
|
4
4
|
import { devDependencies, version } from 'silgi/meta';
|
|
5
|
-
import { resolveModuleExportNames, resolvePath, parseNodeModulePath, lookupNodeModuleSubpath, resolve as resolve$1 } from 'mlly';
|
|
6
|
-
import { runtimeDir } from 'silgi/runtime/meta';
|
|
7
5
|
import { promises, existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
8
6
|
import { readdir } from 'node:fs/promises';
|
|
7
|
+
import { resolvePath, parseNodeModulePath, lookupNodeModuleSubpath, resolveModuleExportNames, resolve as resolve$1 } from 'mlly';
|
|
9
8
|
import { resolveAlias } from 'pathe/utils';
|
|
10
9
|
import { relativeWithDot, isDirectory, writeFile, resolveAlias as resolveAlias$1, resolvePath as resolvePath$1, normalizeTemplate, useLogger, addTemplate } from 'silgi/kit';
|
|
10
|
+
import { runtimeDir } from 'silgi/runtime/meta';
|
|
11
11
|
import { toExports, scanExports, createUnimport } from 'unimport';
|
|
12
12
|
import { execSync } from 'node:child_process';
|
|
13
13
|
import { createJiti } from 'dev-jiti';
|
|
@@ -36,176 +36,6 @@ import 'std-env';
|
|
|
36
36
|
import 'consola/utils';
|
|
37
37
|
import 'escape-string-regexp';
|
|
38
38
|
|
|
39
|
-
async function emptyFramework(silgi) {
|
|
40
|
-
if (silgi.options.preset === "npm-package" || !silgi.options.preset) {
|
|
41
|
-
silgi.hook("after:prepare:schema.ts", (data) => {
|
|
42
|
-
data.unshift("type FrameworkContextExtends = {}");
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async function h3Framework(silgi, skip = false) {
|
|
48
|
-
if (silgi.options.preset !== "h3" && skip === false)
|
|
49
|
-
return;
|
|
50
|
-
if (silgi.options.preset === "h3") {
|
|
51
|
-
silgi.hook("after:prepare:schema.ts", (data) => {
|
|
52
|
-
data.unshift("type FrameworkContextExtends = NitroApp");
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
silgi.hook("prepare:schema.ts", (data) => {
|
|
56
|
-
data.importItems.nitropack = {
|
|
57
|
-
import: [
|
|
58
|
-
{ name: "NitroApp", type: true }
|
|
59
|
-
],
|
|
60
|
-
from: "nitropack/types"
|
|
61
|
-
};
|
|
62
|
-
data.importItems.h3 = {
|
|
63
|
-
import: [
|
|
64
|
-
{ name: "H3Event", type: true }
|
|
65
|
-
],
|
|
66
|
-
from: "h3"
|
|
67
|
-
};
|
|
68
|
-
data.events.push({
|
|
69
|
-
key: "H3Event",
|
|
70
|
-
value: "H3Event",
|
|
71
|
-
extends: true,
|
|
72
|
-
isSilgiContext: false
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
silgi.hook("prepare:createDTSFramework", (data) => {
|
|
76
|
-
data.importItems["silgi/types"] = {
|
|
77
|
-
import: [
|
|
78
|
-
{ name: "SilgiRuntimeContext", type: true }
|
|
79
|
-
],
|
|
80
|
-
from: "silgi/types"
|
|
81
|
-
};
|
|
82
|
-
data.customContent?.push(
|
|
83
|
-
"",
|
|
84
|
-
'declare module "h3" {',
|
|
85
|
-
" interface H3EventContext extends SilgiRuntimeContext {}",
|
|
86
|
-
"}",
|
|
87
|
-
""
|
|
88
|
-
);
|
|
89
|
-
});
|
|
90
|
-
silgi.hook("prepare:core.ts", (data) => {
|
|
91
|
-
data._silgiConfigs.push(`captureError: (error, context = {}) => {
|
|
92
|
-
const promise = silgi.hooks
|
|
93
|
-
.callHookParallel('error', error, context)
|
|
94
|
-
.catch((error_) => {
|
|
95
|
-
console.error('Error while capturing another error', error_)
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
if (context.event && isEvent(context.event)) {
|
|
99
|
-
const errors = context.event.context.nitro?.errors
|
|
100
|
-
if (errors) {
|
|
101
|
-
errors.push({ error, context })
|
|
102
|
-
}
|
|
103
|
-
if (context.event.waitUntil) {
|
|
104
|
-
context.event.waitUntil(promise)
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}`);
|
|
108
|
-
});
|
|
109
|
-
if (silgi.options.imports !== false) {
|
|
110
|
-
const h3Exports = await resolveModuleExportNames("h3", {
|
|
111
|
-
url: import.meta.url
|
|
112
|
-
});
|
|
113
|
-
silgi.options.imports.presets ??= [];
|
|
114
|
-
silgi.options.imports.presets.push({
|
|
115
|
-
from: "h3",
|
|
116
|
-
imports: h3Exports.filter((n) => !/^[A-Z]/.test(n) && n !== "use")
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async function nitroFramework(silgi, skip = false) {
|
|
122
|
-
if (silgi.options.preset !== "nitro" && skip === false)
|
|
123
|
-
return;
|
|
124
|
-
silgi.hook("prepare:schema.ts", (data) => {
|
|
125
|
-
data.importItems.nitropack = {
|
|
126
|
-
import: [
|
|
127
|
-
{ name: "NitroApp", type: true }
|
|
128
|
-
],
|
|
129
|
-
from: "nitropack/types"
|
|
130
|
-
};
|
|
131
|
-
});
|
|
132
|
-
silgi.hook("after:prepare:schema.ts", (data) => {
|
|
133
|
-
data.unshift("type FrameworkContextExtends = NitroApp");
|
|
134
|
-
});
|
|
135
|
-
silgi.options.plugins.push({
|
|
136
|
-
packageImport: "silgi/runtime/internal/nitro",
|
|
137
|
-
path: join(runtimeDir, "internal/nitro")
|
|
138
|
-
});
|
|
139
|
-
silgi.hook("prepare:core.ts", (_data) => {
|
|
140
|
-
if (silgi.options.imports !== false) {
|
|
141
|
-
silgi.options.imports.presets ??= [];
|
|
142
|
-
silgi.options.imports.presets.push(...getNitroImportsPreset());
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
await h3Framework(silgi, true);
|
|
146
|
-
}
|
|
147
|
-
function getNitroImportsPreset() {
|
|
148
|
-
return [
|
|
149
|
-
{
|
|
150
|
-
from: "nitropack/runtime/internal/app",
|
|
151
|
-
imports: ["useNitroApp"]
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
from: "nitropack/runtime/internal/config",
|
|
155
|
-
imports: ["useRuntimeConfig", "useAppConfig"]
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
from: "nitropack/runtime/internal/plugin",
|
|
159
|
-
imports: ["defineNitroPlugin", "nitroPlugin"]
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
from: "nitropack/runtime/internal/cache",
|
|
163
|
-
imports: [
|
|
164
|
-
"defineCachedFunction",
|
|
165
|
-
"defineCachedEventHandler",
|
|
166
|
-
"cachedFunction",
|
|
167
|
-
"cachedEventHandler"
|
|
168
|
-
]
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
from: "nitropack/runtime/internal/storage",
|
|
172
|
-
imports: ["useStorage"]
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
from: "nitropack/runtime/internal/renderer",
|
|
176
|
-
imports: ["defineRenderHandler"]
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
from: "nitropack/runtime/internal/meta",
|
|
180
|
-
imports: ["defineRouteMeta"]
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
from: "nitropack/runtime/internal/route-rules",
|
|
184
|
-
imports: ["getRouteRules"]
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
from: "nitropack/runtime/internal/context",
|
|
188
|
-
imports: ["useEvent"]
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
from: "nitropack/runtime/internal/task",
|
|
192
|
-
imports: ["defineTask", "runTask"]
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
from: "nitropack/runtime/internal/error/utils",
|
|
196
|
-
imports: ["defineNitroErrorHandler"]
|
|
197
|
-
}
|
|
198
|
-
];
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
async function nuxtFramework(silgi, skip = false) {
|
|
202
|
-
if (silgi.options.preset !== "nuxt" && skip === false)
|
|
203
|
-
return;
|
|
204
|
-
await nitroFramework(silgi, true);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const frameworkSetup = [emptyFramework, h3Framework, nitroFramework, nuxtFramework];
|
|
208
|
-
|
|
209
39
|
async function prepare$1(_silgi) {
|
|
210
40
|
}
|
|
211
41
|
|
|
@@ -940,6 +770,176 @@ async function writeTypesAndFiles(silgi) {
|
|
|
940
770
|
await silgi.hooks.callHook("finish:types", readCore);
|
|
941
771
|
}
|
|
942
772
|
|
|
773
|
+
async function emptyFramework(silgi) {
|
|
774
|
+
if (silgi.options.preset === "npm-package" || !silgi.options.preset) {
|
|
775
|
+
silgi.hook("after:prepare:schema.ts", (data) => {
|
|
776
|
+
data.unshift("type FrameworkContextExtends = {}");
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
async function h3Framework(silgi, skip = false) {
|
|
782
|
+
if (silgi.options.preset !== "h3" && skip === false)
|
|
783
|
+
return;
|
|
784
|
+
if (silgi.options.preset === "h3") {
|
|
785
|
+
silgi.hook("after:prepare:schema.ts", (data) => {
|
|
786
|
+
data.unshift("type FrameworkContextExtends = NitroApp");
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
silgi.hook("prepare:schema.ts", (data) => {
|
|
790
|
+
data.importItems.nitropack = {
|
|
791
|
+
import: [
|
|
792
|
+
{ name: "NitroApp", type: true }
|
|
793
|
+
],
|
|
794
|
+
from: "nitropack/types"
|
|
795
|
+
};
|
|
796
|
+
data.importItems.h3 = {
|
|
797
|
+
import: [
|
|
798
|
+
{ name: "H3Event", type: true }
|
|
799
|
+
],
|
|
800
|
+
from: "h3"
|
|
801
|
+
};
|
|
802
|
+
data.events.push({
|
|
803
|
+
key: "H3Event",
|
|
804
|
+
value: "H3Event",
|
|
805
|
+
extends: true,
|
|
806
|
+
isSilgiContext: false
|
|
807
|
+
});
|
|
808
|
+
});
|
|
809
|
+
silgi.hook("prepare:createDTSFramework", (data) => {
|
|
810
|
+
data.importItems["silgi/types"] = {
|
|
811
|
+
import: [
|
|
812
|
+
{ name: "SilgiRuntimeContext", type: true }
|
|
813
|
+
],
|
|
814
|
+
from: "silgi/types"
|
|
815
|
+
};
|
|
816
|
+
data.customContent?.push(
|
|
817
|
+
"",
|
|
818
|
+
'declare module "h3" {',
|
|
819
|
+
" interface H3EventContext extends SilgiRuntimeContext {}",
|
|
820
|
+
"}",
|
|
821
|
+
""
|
|
822
|
+
);
|
|
823
|
+
});
|
|
824
|
+
silgi.hook("prepare:core.ts", (data) => {
|
|
825
|
+
data._silgiConfigs.push(`captureError: (error, context = {}) => {
|
|
826
|
+
const promise = silgi.hooks
|
|
827
|
+
.callHookParallel('error', error, context)
|
|
828
|
+
.catch((error_) => {
|
|
829
|
+
console.error('Error while capturing another error', error_)
|
|
830
|
+
})
|
|
831
|
+
|
|
832
|
+
if (context.event && isEvent(context.event)) {
|
|
833
|
+
const errors = context.event.context.nitro?.errors
|
|
834
|
+
if (errors) {
|
|
835
|
+
errors.push({ error, context })
|
|
836
|
+
}
|
|
837
|
+
if (context.event.waitUntil) {
|
|
838
|
+
context.event.waitUntil(promise)
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}`);
|
|
842
|
+
});
|
|
843
|
+
if (silgi.options.imports !== false) {
|
|
844
|
+
const h3Exports = await resolveModuleExportNames("h3", {
|
|
845
|
+
url: import.meta.url
|
|
846
|
+
});
|
|
847
|
+
silgi.options.imports.presets ??= [];
|
|
848
|
+
silgi.options.imports.presets.push({
|
|
849
|
+
from: "h3",
|
|
850
|
+
imports: h3Exports.filter((n) => !/^[A-Z]/.test(n) && n !== "use")
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
async function nitroFramework(silgi, skip = false) {
|
|
856
|
+
if (silgi.options.preset !== "nitro" && skip === false)
|
|
857
|
+
return;
|
|
858
|
+
silgi.hook("prepare:schema.ts", (data) => {
|
|
859
|
+
data.importItems.nitropack = {
|
|
860
|
+
import: [
|
|
861
|
+
{ name: "NitroApp", type: true }
|
|
862
|
+
],
|
|
863
|
+
from: "nitropack/types"
|
|
864
|
+
};
|
|
865
|
+
});
|
|
866
|
+
silgi.hook("after:prepare:schema.ts", (data) => {
|
|
867
|
+
data.unshift("type FrameworkContextExtends = NitroApp");
|
|
868
|
+
});
|
|
869
|
+
silgi.options.plugins.push({
|
|
870
|
+
packageImport: "silgi/runtime/internal/nitro",
|
|
871
|
+
path: join(runtimeDir, "internal/nitro")
|
|
872
|
+
});
|
|
873
|
+
silgi.hook("prepare:core.ts", (_data) => {
|
|
874
|
+
if (silgi.options.imports !== false) {
|
|
875
|
+
silgi.options.imports.presets ??= [];
|
|
876
|
+
silgi.options.imports.presets.push(...getNitroImportsPreset());
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
await h3Framework(silgi, true);
|
|
880
|
+
}
|
|
881
|
+
function getNitroImportsPreset() {
|
|
882
|
+
return [
|
|
883
|
+
{
|
|
884
|
+
from: "nitropack/runtime/internal/app",
|
|
885
|
+
imports: ["useNitroApp"]
|
|
886
|
+
},
|
|
887
|
+
{
|
|
888
|
+
from: "nitropack/runtime/internal/config",
|
|
889
|
+
imports: ["useRuntimeConfig", "useAppConfig"]
|
|
890
|
+
},
|
|
891
|
+
{
|
|
892
|
+
from: "nitropack/runtime/internal/plugin",
|
|
893
|
+
imports: ["defineNitroPlugin", "nitroPlugin"]
|
|
894
|
+
},
|
|
895
|
+
{
|
|
896
|
+
from: "nitropack/runtime/internal/cache",
|
|
897
|
+
imports: [
|
|
898
|
+
"defineCachedFunction",
|
|
899
|
+
"defineCachedEventHandler",
|
|
900
|
+
"cachedFunction",
|
|
901
|
+
"cachedEventHandler"
|
|
902
|
+
]
|
|
903
|
+
},
|
|
904
|
+
{
|
|
905
|
+
from: "nitropack/runtime/internal/storage",
|
|
906
|
+
imports: ["useStorage"]
|
|
907
|
+
},
|
|
908
|
+
{
|
|
909
|
+
from: "nitropack/runtime/internal/renderer",
|
|
910
|
+
imports: ["defineRenderHandler"]
|
|
911
|
+
},
|
|
912
|
+
{
|
|
913
|
+
from: "nitropack/runtime/internal/meta",
|
|
914
|
+
imports: ["defineRouteMeta"]
|
|
915
|
+
},
|
|
916
|
+
{
|
|
917
|
+
from: "nitropack/runtime/internal/route-rules",
|
|
918
|
+
imports: ["getRouteRules"]
|
|
919
|
+
},
|
|
920
|
+
{
|
|
921
|
+
from: "nitropack/runtime/internal/context",
|
|
922
|
+
imports: ["useEvent"]
|
|
923
|
+
},
|
|
924
|
+
{
|
|
925
|
+
from: "nitropack/runtime/internal/task",
|
|
926
|
+
imports: ["defineTask", "runTask"]
|
|
927
|
+
},
|
|
928
|
+
{
|
|
929
|
+
from: "nitropack/runtime/internal/error/utils",
|
|
930
|
+
imports: ["defineNitroErrorHandler"]
|
|
931
|
+
}
|
|
932
|
+
];
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
async function nuxtFramework(silgi, skip = false) {
|
|
936
|
+
if (silgi.options.preset !== "nuxt" && skip === false)
|
|
937
|
+
return;
|
|
938
|
+
await nitroFramework(silgi, true);
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
const frameworkSetup = [emptyFramework, h3Framework, nitroFramework, nuxtFramework];
|
|
942
|
+
|
|
943
943
|
async function registerModuleExportScan(silgi) {
|
|
944
944
|
silgi.hook("prepare:schema.ts", async (options) => {
|
|
945
945
|
for (const module of silgi.scanModules) {
|
|
@@ -1844,6 +1844,9 @@ async function createSilgiCLI(config = {}, opts = {}) {
|
|
|
1844
1844
|
packageImport: "silgi/runtime/internal/debug"
|
|
1845
1845
|
});
|
|
1846
1846
|
}
|
|
1847
|
+
for (const framework of frameworkSetup) {
|
|
1848
|
+
await framework(silgi);
|
|
1849
|
+
}
|
|
1847
1850
|
await scanAndSyncOptions(silgi);
|
|
1848
1851
|
await scanModules$1(silgi);
|
|
1849
1852
|
await scanFiles$1(silgi);
|
|
@@ -1895,9 +1898,6 @@ const prepare = defineCommand({
|
|
|
1895
1898
|
preset: args.preset
|
|
1896
1899
|
});
|
|
1897
1900
|
await prepare$1();
|
|
1898
|
-
for (const framework of frameworkSetup) {
|
|
1899
|
-
await framework(silgi);
|
|
1900
|
-
}
|
|
1901
1901
|
await writeTypesAndFiles(silgi);
|
|
1902
1902
|
await silgi.callHook("read:core.ts", async () => {
|
|
1903
1903
|
const data = await readCoreFile(silgi);
|
package/dist/meta/index.d.mts
CHANGED
package/dist/meta/index.d.ts
CHANGED