silgi 0.9.0 → 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 -109
- 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 { runtimeDir } from 'silgi/runtime/meta';
|
|
6
5
|
import { promises, existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
7
6
|
import { readdir } from 'node:fs/promises';
|
|
8
|
-
import { resolvePath, parseNodeModulePath, lookupNodeModuleSubpath, resolve as resolve$1 } from 'mlly';
|
|
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,109 +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
|
-
}
|
|
110
|
-
|
|
111
|
-
async function nitroFramework(silgi, skip = false) {
|
|
112
|
-
if (silgi.options.preset !== "nitro" && skip === false)
|
|
113
|
-
return;
|
|
114
|
-
silgi.hook("prepare:schema.ts", (data) => {
|
|
115
|
-
data.importItems.nitropack = {
|
|
116
|
-
import: [
|
|
117
|
-
{ name: "NitroApp", type: true }
|
|
118
|
-
],
|
|
119
|
-
from: "nitropack/types"
|
|
120
|
-
};
|
|
121
|
-
});
|
|
122
|
-
silgi.hook("after:prepare:schema.ts", (data) => {
|
|
123
|
-
data.unshift("type FrameworkContextExtends = NitroApp");
|
|
124
|
-
});
|
|
125
|
-
silgi.options.plugins.push({
|
|
126
|
-
packageImport: "silgi/runtime/internal/nitro",
|
|
127
|
-
path: join(runtimeDir, "internal/nitro")
|
|
128
|
-
});
|
|
129
|
-
silgi.hook("prepare:core.ts", (_data) => {
|
|
130
|
-
});
|
|
131
|
-
await h3Framework(silgi, true);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
async function nuxtFramework(silgi, skip = false) {
|
|
135
|
-
if (silgi.options.preset !== "nuxt" && skip === false)
|
|
136
|
-
return;
|
|
137
|
-
await nitroFramework(silgi, true);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const frameworkSetup = [emptyFramework, h3Framework, nitroFramework, nuxtFramework];
|
|
141
|
-
|
|
142
39
|
async function prepare$1(_silgi) {
|
|
143
40
|
}
|
|
144
41
|
|
|
@@ -873,6 +770,176 @@ async function writeTypesAndFiles(silgi) {
|
|
|
873
770
|
await silgi.hooks.callHook("finish:types", readCore);
|
|
874
771
|
}
|
|
875
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
|
+
|
|
876
943
|
async function registerModuleExportScan(silgi) {
|
|
877
944
|
silgi.hook("prepare:schema.ts", async (options) => {
|
|
878
945
|
for (const module of silgi.scanModules) {
|
|
@@ -1777,6 +1844,9 @@ async function createSilgiCLI(config = {}, opts = {}) {
|
|
|
1777
1844
|
packageImport: "silgi/runtime/internal/debug"
|
|
1778
1845
|
});
|
|
1779
1846
|
}
|
|
1847
|
+
for (const framework of frameworkSetup) {
|
|
1848
|
+
await framework(silgi);
|
|
1849
|
+
}
|
|
1780
1850
|
await scanAndSyncOptions(silgi);
|
|
1781
1851
|
await scanModules$1(silgi);
|
|
1782
1852
|
await scanFiles$1(silgi);
|
|
@@ -1828,9 +1898,6 @@ const prepare = defineCommand({
|
|
|
1828
1898
|
preset: args.preset
|
|
1829
1899
|
});
|
|
1830
1900
|
await prepare$1();
|
|
1831
|
-
for (const framework of frameworkSetup) {
|
|
1832
|
-
await framework(silgi);
|
|
1833
|
-
}
|
|
1834
1901
|
await writeTypesAndFiles(silgi);
|
|
1835
1902
|
await silgi.callHook("read:core.ts", async () => {
|
|
1836
1903
|
const data = await readCoreFile(silgi);
|
package/dist/meta/index.d.mts
CHANGED
package/dist/meta/index.d.ts
CHANGED