silgi 0.7.3 → 0.7.5
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/config/index.mjs +7 -167
- package/dist/cli/prepare.mjs +89 -79
- package/dist/cli/{loader.mjs → types.mjs} +163 -4
- package/dist/core/index.d.mts +3 -3
- package/dist/core/index.d.ts +3 -3
- package/dist/ecosystem/nuxt/module.d.mts +3 -3
- package/dist/ecosystem/nuxt/module.d.ts +3 -3
- package/dist/meta/index.d.mts +1 -1
- package/dist/meta/index.d.ts +1 -1
- package/dist/presets/_resolve.d.ts +1 -1
- package/dist/runtime/internal/nuxt.d.ts +1 -1
- package/dist/shared/{silgi.BFbL2aof.d.mts → silgi.BuspmWeq.d.mts} +2 -2
- package/dist/shared/{silgi.BFbL2aof.d.ts → silgi.BuspmWeq.d.ts} +2 -2
- package/dist/types/index.d.mts +38 -39
- package/dist/types/index.d.ts +38 -39
- package/package.json +4 -3
package/dist/_chunks/index.mjs
CHANGED
|
@@ -1,177 +1,17 @@
|
|
|
1
|
-
export { l as loadOptions } from '../
|
|
2
|
-
import { promises, lstatSync } from 'node:fs';
|
|
3
|
-
import { defu } from 'defu';
|
|
4
|
-
import { resolve, dirname, join, isAbsolute, relative } from 'pathe';
|
|
5
|
-
import { readPackageJSON } from 'pkg-types';
|
|
6
|
-
import { relativeWithDot, resolveSilgiModule } from 'silgi/kit';
|
|
7
|
-
import { withTrailingSlash } from 'ufo';
|
|
1
|
+
export { l as loadOptions, s as silgiGenerateType } from '../types.mjs';
|
|
8
2
|
import 'c12';
|
|
9
3
|
import 'compatx';
|
|
10
4
|
import 'klona/full';
|
|
11
5
|
import 'std-env';
|
|
12
6
|
import 'consola';
|
|
13
7
|
import 'consola/utils';
|
|
8
|
+
import 'pathe';
|
|
14
9
|
import 'escape-string-regexp';
|
|
15
10
|
import 'mlly';
|
|
11
|
+
import 'node:fs';
|
|
16
12
|
import 'node:url';
|
|
13
|
+
import 'pkg-types';
|
|
14
|
+
import 'silgi/kit';
|
|
17
15
|
import 'silgi/runtime/meta';
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
return isAbsolute(p) && lstatSync(p).isFile() ? dirname(p) : p;
|
|
22
|
-
} catch {
|
|
23
|
-
}
|
|
24
|
-
return p;
|
|
25
|
-
}
|
|
26
|
-
function renderAttrs(obj) {
|
|
27
|
-
const attrs = [];
|
|
28
|
-
for (const key in obj) {
|
|
29
|
-
attrs.push(renderAttr(key, obj[key]));
|
|
30
|
-
}
|
|
31
|
-
return attrs.join(" ");
|
|
32
|
-
}
|
|
33
|
-
function renderAttr(key, value) {
|
|
34
|
-
return value ? `${key}="${value}"` : "";
|
|
35
|
-
}
|
|
36
|
-
async function silgiGenerateType(silgi) {
|
|
37
|
-
const rootDirWithSlash = withTrailingSlash(silgi.options.rootDir);
|
|
38
|
-
const tsConfigPath = resolve(
|
|
39
|
-
silgi.options.rootDir,
|
|
40
|
-
silgi.options.typescript.tsconfigPath
|
|
41
|
-
);
|
|
42
|
-
const tsconfigDir = dirname(tsConfigPath);
|
|
43
|
-
const include = /* @__PURE__ */ new Set([
|
|
44
|
-
relativeWithDot(tsconfigDir, join(silgi.options.build.typesDir, "silgi.d.ts")).replace(
|
|
45
|
-
/^(?=[^.])/,
|
|
46
|
-
"./"
|
|
47
|
-
),
|
|
48
|
-
join(relativeWithDot(tsconfigDir, silgi.options.rootDir), "**/*"),
|
|
49
|
-
...silgi.options.srcDir === silgi.options.rootDir ? [] : [join(relativeWithDot(tsconfigDir, silgi.options.srcDir), "**/*")]
|
|
50
|
-
]);
|
|
51
|
-
const exclude = /* @__PURE__ */ new Set([
|
|
52
|
-
// nitro generate output: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nitro.ts#L186
|
|
53
|
-
relativeWithDot(silgi.options.build.dir, resolve(silgi.options.rootDir, "dist"))
|
|
54
|
-
]);
|
|
55
|
-
for (const dir of silgi.options.modulesDir) {
|
|
56
|
-
exclude.add(relativeWithDot(silgi.options.build.dir, dir));
|
|
57
|
-
}
|
|
58
|
-
const moduleEntryPaths = [];
|
|
59
|
-
for (const m of silgi.scanModules) {
|
|
60
|
-
if (m.entryPath) {
|
|
61
|
-
moduleEntryPaths.push(getDirectory(m.entryPath));
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const modulePaths = await resolveSilgiModule(rootDirWithSlash, moduleEntryPaths);
|
|
65
|
-
for (const path of modulePaths) {
|
|
66
|
-
const relative2 = relativeWithDot(silgi.options.build.dir, path);
|
|
67
|
-
include.add(join(relative2, "runtime"));
|
|
68
|
-
exclude.add(join(relative2, "runtime/server"));
|
|
69
|
-
include.add(join(relative2, "dist/runtime"));
|
|
70
|
-
exclude.add(join(relative2, "dist/runtime/server"));
|
|
71
|
-
}
|
|
72
|
-
const tsConfig = defu(silgi.options.typescript?.tsConfig, {
|
|
73
|
-
compilerOptions: {
|
|
74
|
-
forceConsistentCasingInFileNames: true,
|
|
75
|
-
strict: silgi.options.typescript.strict,
|
|
76
|
-
noEmit: true,
|
|
77
|
-
target: "ESNext",
|
|
78
|
-
module: "ESNext",
|
|
79
|
-
moduleResolution: "Bundler",
|
|
80
|
-
allowJs: true,
|
|
81
|
-
resolveJsonModule: true,
|
|
82
|
-
jsx: "preserve",
|
|
83
|
-
allowSyntheticDefaultImports: true,
|
|
84
|
-
jsxFactory: "h",
|
|
85
|
-
jsxFragmentFactory: "Fragment",
|
|
86
|
-
allowImportingTsExtensions: true,
|
|
87
|
-
...silgi.options.typescript.customConditions ? { customConditions: ["silgiTypes"] } : {},
|
|
88
|
-
paths: {
|
|
89
|
-
"#silgiImports": [
|
|
90
|
-
relativeWithDot(tsconfigDir, join(silgi.options.build.typesDir, "silgi-imports"))
|
|
91
|
-
],
|
|
92
|
-
...silgi.scanModules.reduce((acc, m) => {
|
|
93
|
-
if (m.entryPath) {
|
|
94
|
-
acc[m.meta.name] = [relativeWithDot(tsconfigDir, m.entryPath)];
|
|
95
|
-
}
|
|
96
|
-
return acc;
|
|
97
|
-
}, {}),
|
|
98
|
-
...silgi.scanModules.reduce((acc, m) => {
|
|
99
|
-
if (m.entryPath) {
|
|
100
|
-
const directory = getDirectory(m.entryPath);
|
|
101
|
-
acc[`${m.meta.name}/*`] = [`${relativeWithDot(tsconfigDir, directory)}/*`];
|
|
102
|
-
}
|
|
103
|
-
return acc;
|
|
104
|
-
}, {})
|
|
105
|
-
// ...(silgi.options.typescript?.internalPaths
|
|
106
|
-
// ? {
|
|
107
|
-
// 'silgi/runtime': [
|
|
108
|
-
// relativeWithDot(tsconfigDir, join(runtimeDir, 'index')),
|
|
109
|
-
// ],
|
|
110
|
-
// '#internal/silgi': [
|
|
111
|
-
// relativeWithDot(tsconfigDir, join(runtimeDir, 'index')),
|
|
112
|
-
// ],
|
|
113
|
-
// 'silgi/runtime/*': [
|
|
114
|
-
// relativeWithDot(tsconfigDir, join(runtimeDir, '*')),
|
|
115
|
-
// ],
|
|
116
|
-
// '#internal/silgi/*': [
|
|
117
|
-
// relativeWithDot(tsconfigDir, join(runtimeDir, '*')),
|
|
118
|
-
// ],
|
|
119
|
-
// }
|
|
120
|
-
// : {}),
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
include: [...include],
|
|
124
|
-
exclude: [...exclude]
|
|
125
|
-
});
|
|
126
|
-
tsConfig.compilerOptions ||= {};
|
|
127
|
-
tsConfig.compilerOptions.paths ||= {};
|
|
128
|
-
tsConfig.include ||= [];
|
|
129
|
-
for (const alias in tsConfig.compilerOptions.paths) {
|
|
130
|
-
const paths = tsConfig.compilerOptions.paths[alias];
|
|
131
|
-
tsConfig.compilerOptions.paths[alias] = await Promise.all(
|
|
132
|
-
paths.map(async (path) => {
|
|
133
|
-
if (!isAbsolute(path)) {
|
|
134
|
-
return path;
|
|
135
|
-
}
|
|
136
|
-
const stats = await promises.stat(path).catch(
|
|
137
|
-
() => null
|
|
138
|
-
/* file does not exist */
|
|
139
|
-
);
|
|
140
|
-
return relativeWithDot(
|
|
141
|
-
tsconfigDir,
|
|
142
|
-
stats?.isFile() ? path.replace(/\b\.\w+$/g, "") : path
|
|
143
|
-
);
|
|
144
|
-
})
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
const references = [];
|
|
148
|
-
await Promise.all([...silgi.options.modules, ...silgi.options._modules].map(async (id) => {
|
|
149
|
-
if (typeof id !== "string") {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
const pkg = await readPackageJSON(id, { url: silgi.options.modulesDir }).catch(() => null);
|
|
153
|
-
references.push({ types: pkg?.name || id });
|
|
154
|
-
}));
|
|
155
|
-
const declarations = [];
|
|
156
|
-
await silgi.callHook("prepare:types", { references, declarations, tsConfig });
|
|
157
|
-
tsConfig.include = [...new Set(tsConfig.include.map((p) => isAbsolute(p) ? relativeWithDot(silgi.options.build.dir, p) : p))];
|
|
158
|
-
tsConfig.exclude = [...new Set(tsConfig.exclude.map((p) => isAbsolute(p) ? relativeWithDot(silgi.options.build.dir, p) : p))];
|
|
159
|
-
const _declarations = [
|
|
160
|
-
...references.map((ref) => {
|
|
161
|
-
if ("path" in ref && isAbsolute(ref.path)) {
|
|
162
|
-
ref.path = relative(silgi.options.build.dir, ref.path);
|
|
163
|
-
}
|
|
164
|
-
return `/// <reference ${renderAttrs(ref)} />`;
|
|
165
|
-
}),
|
|
166
|
-
...declarations,
|
|
167
|
-
"",
|
|
168
|
-
"export {}",
|
|
169
|
-
""
|
|
170
|
-
];
|
|
171
|
-
return {
|
|
172
|
-
declarations: _declarations,
|
|
173
|
-
tsConfig
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export { silgiGenerateType };
|
|
16
|
+
import 'ufo';
|
|
17
|
+
import 'defu';
|
package/dist/cli/prepare.mjs
CHANGED
|
@@ -6,14 +6,15 @@ import { promises, existsSync, readFileSync, writeFileSync, mkdirSync } from 'no
|
|
|
6
6
|
import { readdir } from 'node:fs/promises';
|
|
7
7
|
import { resolvePath, parseNodeModulePath, lookupNodeModuleSubpath, resolve as resolve$1 } from 'mlly';
|
|
8
8
|
import { resolveAlias } from 'pathe/utils';
|
|
9
|
-
import { silgiGenerateType, useSilgiCLI, silgiCLICtx } from 'silgi/core';
|
|
10
9
|
import { relativeWithDot, isDirectory, writeFile, resolveAlias as resolveAlias$1, resolvePath as resolvePath$1, normalizeTemplate, useLogger } from 'silgi/kit';
|
|
11
10
|
import { toExports, scanExports, createUnimport } from 'unimport';
|
|
12
11
|
import { createJiti } from 'dev-jiti';
|
|
13
12
|
import { readPackageJSON } from 'pkg-types';
|
|
14
13
|
import { hash } from 'ohash';
|
|
14
|
+
import { s as silgiGenerateType, l as loadOptions } from './types.mjs';
|
|
15
15
|
import { consola } from 'consola';
|
|
16
16
|
import { createHooks, createDebugger } from 'hookable';
|
|
17
|
+
import { useSilgiCLI, silgiCLICtx } from 'silgi/core';
|
|
17
18
|
import { pascalCase } from 'scule';
|
|
18
19
|
import { h as hasInstalledModule } from './compatibility.mjs';
|
|
19
20
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
@@ -23,14 +24,14 @@ import ignore from 'ignore';
|
|
|
23
24
|
import { parseSync } from '@oxc-parser/wasm';
|
|
24
25
|
import { klona } from 'klona';
|
|
25
26
|
import { createStorage, builtinDrivers } from 'unstorage';
|
|
26
|
-
import { l as loadOptions } from './loader.mjs';
|
|
27
|
-
import 'semver/functions/satisfies.js';
|
|
28
27
|
import 'c12';
|
|
29
28
|
import 'compatx';
|
|
30
29
|
import 'klona/full';
|
|
31
30
|
import 'std-env';
|
|
32
31
|
import 'consola/utils';
|
|
33
32
|
import 'escape-string-regexp';
|
|
33
|
+
import 'defu';
|
|
34
|
+
import 'semver/functions/satisfies.js';
|
|
34
35
|
|
|
35
36
|
async function h3Framework(silgi, skip = false) {
|
|
36
37
|
if (silgi.options.preset !== "h3" && skip === false)
|
|
@@ -63,14 +64,14 @@ async function h3Framework(silgi, skip = false) {
|
|
|
63
64
|
silgi.hook("prepare:createDTSFramework", (data) => {
|
|
64
65
|
data.importItems["silgi/types"] = {
|
|
65
66
|
import: [
|
|
66
|
-
{ name: "
|
|
67
|
+
{ name: "SilgiRuntimeContext", type: true }
|
|
67
68
|
],
|
|
68
69
|
from: "silgi/types"
|
|
69
70
|
};
|
|
70
71
|
data.customContent?.push(
|
|
71
72
|
"",
|
|
72
73
|
'declare module "h3" {',
|
|
73
|
-
" interface H3EventContext extends
|
|
74
|
+
" interface H3EventContext extends SilgiRuntimeContext {}",
|
|
74
75
|
"}",
|
|
75
76
|
""
|
|
76
77
|
);
|
|
@@ -342,7 +343,7 @@ async function createCoreFramework(silgi) {
|
|
|
342
343
|
const importItems = {
|
|
343
344
|
"silgi/types": {
|
|
344
345
|
import: [
|
|
345
|
-
{ name: "
|
|
346
|
+
{ name: "SilgiRuntimeContext", type: true }
|
|
346
347
|
],
|
|
347
348
|
from: "silgi/types"
|
|
348
349
|
}
|
|
@@ -380,7 +381,7 @@ async function createDTSFramework(silgi) {
|
|
|
380
381
|
const importItems = {
|
|
381
382
|
"silgi/types": {
|
|
382
383
|
import: [
|
|
383
|
-
{ name: "
|
|
384
|
+
{ name: "SilgiRuntimeContext", type: true }
|
|
384
385
|
],
|
|
385
386
|
from: "silgi/types"
|
|
386
387
|
}
|
|
@@ -428,7 +429,7 @@ async function schemaTemplate(silgi) {
|
|
|
428
429
|
import: [
|
|
429
430
|
{ name: "URIsTypes", type: true },
|
|
430
431
|
{ name: "Namespaces", type: true },
|
|
431
|
-
{ name: "
|
|
432
|
+
{ name: "SilgiRuntimeContext", type: true }
|
|
432
433
|
],
|
|
433
434
|
from: "silgi/types"
|
|
434
435
|
}
|
|
@@ -448,14 +449,15 @@ async function schemaTemplate(silgi) {
|
|
|
448
449
|
const data = {
|
|
449
450
|
importItems,
|
|
450
451
|
customImports: [],
|
|
451
|
-
|
|
452
|
+
options: [],
|
|
452
453
|
contexts: [],
|
|
453
|
-
|
|
454
|
+
actions: [],
|
|
454
455
|
shareds: [],
|
|
455
456
|
events: [],
|
|
456
457
|
storeBase: [],
|
|
457
458
|
hooks: [],
|
|
458
|
-
runtimeHooks: []
|
|
459
|
+
runtimeHooks: [],
|
|
460
|
+
runtimeOptions: []
|
|
459
461
|
};
|
|
460
462
|
const storeBase = [];
|
|
461
463
|
await silgi.callHook("prepare:schema.ts", data);
|
|
@@ -486,19 +488,17 @@ async function schemaTemplate(silgi) {
|
|
|
486
488
|
if (item.isSilgiContext) {
|
|
487
489
|
addSilgiContext = true;
|
|
488
490
|
}
|
|
489
|
-
return !item.extends && !addSilgiContext ? ` ${item.key}: ${item.value}` : item.isSilgiContext ? " context:
|
|
491
|
+
return !item.extends && !addSilgiContext ? ` ${item.key}: ${item.value}` : item.isSilgiContext ? " context: SilgiRuntimeContext" : "";
|
|
490
492
|
}).join(",\n")}
|
|
491
493
|
}` : "interface SilgiModuleEventsExtends {}",
|
|
492
494
|
"",
|
|
493
|
-
|
|
495
|
+
`type RuntimeActionExtends = ${data.actions?.length ? data.actions.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
|
|
494
496
|
"",
|
|
495
|
-
"
|
|
496
|
-
...(data.methods || []).map(({ key, value }) => ` ${key}: ${value},`),
|
|
497
|
-
"}",
|
|
497
|
+
`type SilgiModuleSharedExtends = ${data.shareds.length ? data.shareds.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
|
|
498
498
|
"",
|
|
499
|
-
"
|
|
500
|
-
|
|
501
|
-
"}"
|
|
499
|
+
`type SilgiModuleOptionExtend = ${data.options?.length ? data.options.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
|
|
500
|
+
"",
|
|
501
|
+
`type SilgiRuntimeOptionExtends = ${data.runtimeOptions?.length ? data.runtimeOptions.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
|
|
502
502
|
"",
|
|
503
503
|
"interface SilgiStorageBaseExtends {",
|
|
504
504
|
...(storeBase || []).map((value) => ` ${value}: ''`),
|
|
@@ -513,15 +513,15 @@ async function schemaTemplate(silgi) {
|
|
|
513
513
|
" interface SilgiSchema extends SchemaExtends {}",
|
|
514
514
|
" interface SilgiNamespaces extends InferredNamespaces {}",
|
|
515
515
|
" interface SilgiStorageBase extends SilgiStorageBaseExtends {}",
|
|
516
|
-
" interface SilgiModules extends SilgiModuleOptionsExtends {}",
|
|
517
516
|
" interface SilgiURIs extends SilgiURIsMerge {}",
|
|
518
|
-
" interface
|
|
519
|
-
" interface
|
|
520
|
-
" interface
|
|
521
|
-
" interface
|
|
522
|
-
" interface
|
|
523
|
-
" interface
|
|
524
|
-
" interface
|
|
517
|
+
" interface SilgiRuntimeContext extends SilgiModuleContextExtends {}",
|
|
518
|
+
" interface SilgiEvents extends SilgiModuleEventsExtends {}",
|
|
519
|
+
" interface SilgiShareds extends SilgiModuleSharedExtends {}",
|
|
520
|
+
" interface SilgiRuntimeActions extends RuntimeActionExtends {}",
|
|
521
|
+
" interface SilgiModuleOptions extends SilgiModuleOptionExtend {}",
|
|
522
|
+
" interface SilgiRuntimeOptions extends SilgiRuntimeOptionExtends {}",
|
|
523
|
+
" interface SilgiRuntimeHooks extends SilgiRuntimeHooksExtends {}",
|
|
524
|
+
" interface SilgiHooks extends ModuleHooksExtend {}",
|
|
525
525
|
"}",
|
|
526
526
|
"",
|
|
527
527
|
"export {}"
|
|
@@ -542,7 +542,7 @@ async function silgiCoreFile(data, frameworkContext, silgi) {
|
|
|
542
542
|
},
|
|
543
543
|
"silgi/types": {
|
|
544
544
|
import: [
|
|
545
|
-
{ name: "
|
|
545
|
+
{ name: "SilgiRuntimeOptions", type: true },
|
|
546
546
|
{ name: "SilgiOptions", type: true },
|
|
547
547
|
{ name: "FrameworkContext", type: true },
|
|
548
548
|
{ name: "DeepPartial", type: true },
|
|
@@ -641,9 +641,9 @@ async function silgiCoreFile(data, frameworkContext, silgi) {
|
|
|
641
641
|
}),
|
|
642
642
|
shareds.length > 0 ? "])" : "}",
|
|
643
643
|
"",
|
|
644
|
-
`export const _silgiOptions: DeepPartial<
|
|
644
|
+
`export const _silgiOptions: DeepPartial<SilgiRuntimeOptions> = ${JSON.stringify(_silgiOptions, null, 2)}`,
|
|
645
645
|
"",
|
|
646
|
-
"export async function buildSilgi(framework: FrameworkContext, moduleOptions?: Partial<
|
|
646
|
+
"export async function buildSilgi(framework: FrameworkContext, moduleOptions?: Partial<SilgiRuntimeOptions>,buildOptions?: Partial<BuildConfig>, ) {",
|
|
647
647
|
" const silgi = await createSilgi({",
|
|
648
648
|
" framework,",
|
|
649
649
|
" shared: shareds as any,",
|
|
@@ -812,53 +812,63 @@ async function registerModuleExportScan(silgi) {
|
|
|
812
812
|
from: module.meta._packageName ? moduleName : relativeWithDot(silgi.options.build.typesDir, module.entryPath)
|
|
813
813
|
};
|
|
814
814
|
const exportedTypes = exports.filter((exp) => exp.type).map((exp) => exp.name);
|
|
815
|
-
if (
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
815
|
+
if (!module.meta._packageName) {
|
|
816
|
+
if (exportedTypes.includes("ModuleOptions")) {
|
|
817
|
+
const importName = pascalCase(`${configKey}Config`);
|
|
818
|
+
options.importItems[configKey].import.push({
|
|
819
|
+
name: `ModuleOptions as ${importName}`,
|
|
820
|
+
type: true
|
|
821
|
+
});
|
|
822
|
+
options.options.push({ key: configKey, value: importName });
|
|
823
|
+
}
|
|
824
|
+
if (exportedTypes.includes("SilgiRuntimeOptions")) {
|
|
825
|
+
const importName = pascalCase(`${configKey}RuntimeConfig`);
|
|
826
|
+
options.importItems[configKey].import.push({
|
|
827
|
+
name: `SilgiRuntimeOptions as ${importName}`,
|
|
828
|
+
type: true
|
|
829
|
+
});
|
|
830
|
+
options.runtimeOptions.push({ key: configKey, value: importName });
|
|
831
|
+
}
|
|
832
|
+
if (exportedTypes.includes("ModuleRuntimeContext")) {
|
|
833
|
+
const importName = pascalCase(`${configKey}RuntimeContext`);
|
|
834
|
+
options.importItems[configKey].import.push({
|
|
835
|
+
name: `ModuleRuntimeContext as ${importName}`,
|
|
836
|
+
type: true
|
|
837
|
+
});
|
|
838
|
+
options.contexts.push({ key: configKey, value: importName });
|
|
839
|
+
}
|
|
840
|
+
if (exportedTypes.includes("ModuleRuntimeAction")) {
|
|
841
|
+
const importName = pascalCase(`${configKey}Action`);
|
|
842
|
+
options.importItems[configKey].import.push({
|
|
843
|
+
name: `ModuleRuntimeAction as ${importName}`,
|
|
844
|
+
type: true
|
|
845
|
+
});
|
|
846
|
+
options.actions.push({ key: configKey, value: importName });
|
|
847
|
+
}
|
|
848
|
+
if (exportedTypes.includes("ModuleRuntimeShared")) {
|
|
849
|
+
const importName = pascalCase(`${configKey}Shared`);
|
|
850
|
+
options.importItems[configKey].import.push({
|
|
851
|
+
name: `ModuleRuntimeShared as ${importName}`,
|
|
852
|
+
type: true
|
|
853
|
+
});
|
|
854
|
+
options.shareds.push({ key: configKey, value: importName });
|
|
855
|
+
}
|
|
856
|
+
if (exportedTypes.includes("ModuleHooks")) {
|
|
857
|
+
const importName = pascalCase(`${configKey}Hooks`);
|
|
858
|
+
options.importItems[configKey].import.push({
|
|
859
|
+
name: `ModuleHooks as ${importName}`,
|
|
860
|
+
type: true
|
|
861
|
+
});
|
|
862
|
+
options.hooks.push({ key: configKey, value: importName });
|
|
863
|
+
}
|
|
864
|
+
if (exportedTypes.includes("ModuleRuntimeHooks")) {
|
|
865
|
+
const importName = pascalCase(`${configKey}RuntimeHooks`);
|
|
866
|
+
options.importItems[configKey].import.push({
|
|
867
|
+
name: `ModuleRuntimeHooks as ${importName}`,
|
|
868
|
+
type: true
|
|
869
|
+
});
|
|
870
|
+
options.runtimeHooks.push({ key: configKey, value: importName });
|
|
871
|
+
}
|
|
862
872
|
}
|
|
863
873
|
}
|
|
864
874
|
});
|
|
@@ -1199,10 +1209,10 @@ class SchemaParser {
|
|
|
1199
1209
|
// if (!item?.declaration?.extends)
|
|
1200
1210
|
// continue
|
|
1201
1211
|
// for (const declaration of item?.declaration?.extends) {
|
|
1202
|
-
// if (declaration.expression.name === '
|
|
1212
|
+
// if (declaration.expression.name === 'SilgiModuleOptions') {
|
|
1203
1213
|
// data.export.push({
|
|
1204
1214
|
// name: item.declaration.id.name,
|
|
1205
|
-
// as: camelCase(`${data.name}
|
|
1215
|
+
// as: camelCase(`${data.name}SilgiModuleOptions`),
|
|
1206
1216
|
// type: true,
|
|
1207
1217
|
// })
|
|
1208
1218
|
// }
|
|
@@ -4,15 +4,16 @@ import { klona } from 'klona/full';
|
|
|
4
4
|
import { isDebug, isTest } from 'std-env';
|
|
5
5
|
import consola from 'consola';
|
|
6
6
|
import { colors } from 'consola/utils';
|
|
7
|
-
import { relative, join, resolve, isAbsolute } from 'pathe';
|
|
7
|
+
import { relative, join, resolve, isAbsolute, dirname } from 'pathe';
|
|
8
8
|
import escapeRE from 'escape-string-regexp';
|
|
9
9
|
import { resolveModuleExportNames, resolvePath as resolvePath$1 } from 'mlly';
|
|
10
|
-
import { existsSync } from 'node:fs';
|
|
10
|
+
import { existsSync, promises, lstatSync } from 'node:fs';
|
|
11
11
|
import { pathToFileURL } from 'node:url';
|
|
12
12
|
import { findWorkspaceDir, readPackageJSON } from 'pkg-types';
|
|
13
|
-
import { resolveSilgiPath, resolveAlias, resolvePath } from 'silgi/kit';
|
|
13
|
+
import { resolveSilgiPath, resolveAlias, resolvePath, relativeWithDot, resolveSilgiModule } from 'silgi/kit';
|
|
14
14
|
import { runtimeDir, pkgDir } from 'silgi/runtime/meta';
|
|
15
15
|
import { isRelative, withLeadingSlash, withTrailingSlash } from 'ufo';
|
|
16
|
+
import { defu } from 'defu';
|
|
16
17
|
|
|
17
18
|
const SilgiCLIDefaults = {
|
|
18
19
|
// General
|
|
@@ -578,4 +579,162 @@ async function _loadUserConfig(configOverrides = {}, opts = {}) {
|
|
|
578
579
|
return options;
|
|
579
580
|
}
|
|
580
581
|
|
|
581
|
-
|
|
582
|
+
function getDirectory(p) {
|
|
583
|
+
try {
|
|
584
|
+
return isAbsolute(p) && lstatSync(p).isFile() ? dirname(p) : p;
|
|
585
|
+
} catch {
|
|
586
|
+
}
|
|
587
|
+
return p;
|
|
588
|
+
}
|
|
589
|
+
function renderAttrs(obj) {
|
|
590
|
+
const attrs = [];
|
|
591
|
+
for (const key in obj) {
|
|
592
|
+
attrs.push(renderAttr(key, obj[key]));
|
|
593
|
+
}
|
|
594
|
+
return attrs.join(" ");
|
|
595
|
+
}
|
|
596
|
+
function renderAttr(key, value) {
|
|
597
|
+
return value ? `${key}="${value}"` : "";
|
|
598
|
+
}
|
|
599
|
+
async function silgiGenerateType(silgi) {
|
|
600
|
+
const rootDirWithSlash = withTrailingSlash(silgi.options.rootDir);
|
|
601
|
+
const tsConfigPath = resolve(
|
|
602
|
+
silgi.options.rootDir,
|
|
603
|
+
silgi.options.typescript.tsconfigPath
|
|
604
|
+
);
|
|
605
|
+
const tsconfigDir = dirname(tsConfigPath);
|
|
606
|
+
const include = /* @__PURE__ */ new Set([
|
|
607
|
+
relativeWithDot(tsconfigDir, join(silgi.options.build.typesDir, "silgi.d.ts")).replace(
|
|
608
|
+
/^(?=[^.])/,
|
|
609
|
+
"./"
|
|
610
|
+
),
|
|
611
|
+
join(relativeWithDot(tsconfigDir, silgi.options.rootDir), "**/*"),
|
|
612
|
+
...silgi.options.srcDir === silgi.options.rootDir ? [] : [join(relativeWithDot(tsconfigDir, silgi.options.srcDir), "**/*")]
|
|
613
|
+
]);
|
|
614
|
+
const exclude = /* @__PURE__ */ new Set([
|
|
615
|
+
// nitro generate output: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nitro.ts#L186
|
|
616
|
+
relativeWithDot(silgi.options.build.dir, resolve(silgi.options.rootDir, "dist"))
|
|
617
|
+
]);
|
|
618
|
+
for (const dir of silgi.options.modulesDir) {
|
|
619
|
+
exclude.add(relativeWithDot(silgi.options.build.dir, dir));
|
|
620
|
+
}
|
|
621
|
+
const moduleEntryPaths = [];
|
|
622
|
+
for (const m of silgi.scanModules) {
|
|
623
|
+
if (m.entryPath) {
|
|
624
|
+
moduleEntryPaths.push(getDirectory(m.entryPath));
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
const modulePaths = await resolveSilgiModule(rootDirWithSlash, moduleEntryPaths);
|
|
628
|
+
for (const path of modulePaths) {
|
|
629
|
+
const relative2 = relativeWithDot(silgi.options.build.dir, path);
|
|
630
|
+
include.add(join(relative2, "runtime"));
|
|
631
|
+
exclude.add(join(relative2, "runtime/server"));
|
|
632
|
+
include.add(join(relative2, "dist/runtime"));
|
|
633
|
+
exclude.add(join(relative2, "dist/runtime/server"));
|
|
634
|
+
}
|
|
635
|
+
const tsConfig = defu(silgi.options.typescript?.tsConfig, {
|
|
636
|
+
compilerOptions: {
|
|
637
|
+
forceConsistentCasingInFileNames: true,
|
|
638
|
+
strict: silgi.options.typescript.strict,
|
|
639
|
+
noEmit: true,
|
|
640
|
+
target: "ESNext",
|
|
641
|
+
module: "ESNext",
|
|
642
|
+
moduleResolution: "Bundler",
|
|
643
|
+
allowJs: true,
|
|
644
|
+
resolveJsonModule: true,
|
|
645
|
+
jsx: "preserve",
|
|
646
|
+
allowSyntheticDefaultImports: true,
|
|
647
|
+
jsxFactory: "h",
|
|
648
|
+
jsxFragmentFactory: "Fragment",
|
|
649
|
+
allowImportingTsExtensions: true,
|
|
650
|
+
...silgi.options.typescript.customConditions ? { customConditions: ["silgiTypes"] } : {},
|
|
651
|
+
paths: {
|
|
652
|
+
"#silgiImports": [
|
|
653
|
+
relativeWithDot(tsconfigDir, join(silgi.options.build.typesDir, "silgi-imports"))
|
|
654
|
+
],
|
|
655
|
+
...silgi.scanModules.reduce((acc, m) => {
|
|
656
|
+
if (m.entryPath) {
|
|
657
|
+
acc[m.meta.name] = [relativeWithDot(tsconfigDir, m.entryPath)];
|
|
658
|
+
}
|
|
659
|
+
return acc;
|
|
660
|
+
}, {}),
|
|
661
|
+
...silgi.scanModules.reduce((acc, m) => {
|
|
662
|
+
if (m.entryPath) {
|
|
663
|
+
const directory = getDirectory(m.entryPath);
|
|
664
|
+
acc[`${m.meta.name}/*`] = [`${relativeWithDot(tsconfigDir, directory)}/*`];
|
|
665
|
+
}
|
|
666
|
+
return acc;
|
|
667
|
+
}, {})
|
|
668
|
+
// ...(silgi.options.typescript?.internalPaths
|
|
669
|
+
// ? {
|
|
670
|
+
// 'silgi/runtime': [
|
|
671
|
+
// relativeWithDot(tsconfigDir, join(runtimeDir, 'index')),
|
|
672
|
+
// ],
|
|
673
|
+
// '#internal/silgi': [
|
|
674
|
+
// relativeWithDot(tsconfigDir, join(runtimeDir, 'index')),
|
|
675
|
+
// ],
|
|
676
|
+
// 'silgi/runtime/*': [
|
|
677
|
+
// relativeWithDot(tsconfigDir, join(runtimeDir, '*')),
|
|
678
|
+
// ],
|
|
679
|
+
// '#internal/silgi/*': [
|
|
680
|
+
// relativeWithDot(tsconfigDir, join(runtimeDir, '*')),
|
|
681
|
+
// ],
|
|
682
|
+
// }
|
|
683
|
+
// : {}),
|
|
684
|
+
}
|
|
685
|
+
},
|
|
686
|
+
include: [...include],
|
|
687
|
+
exclude: [...exclude]
|
|
688
|
+
});
|
|
689
|
+
tsConfig.compilerOptions ||= {};
|
|
690
|
+
tsConfig.compilerOptions.paths ||= {};
|
|
691
|
+
tsConfig.include ||= [];
|
|
692
|
+
for (const alias in tsConfig.compilerOptions.paths) {
|
|
693
|
+
const paths = tsConfig.compilerOptions.paths[alias];
|
|
694
|
+
tsConfig.compilerOptions.paths[alias] = await Promise.all(
|
|
695
|
+
paths.map(async (path) => {
|
|
696
|
+
if (!isAbsolute(path)) {
|
|
697
|
+
return path;
|
|
698
|
+
}
|
|
699
|
+
const stats = await promises.stat(path).catch(
|
|
700
|
+
() => null
|
|
701
|
+
/* file does not exist */
|
|
702
|
+
);
|
|
703
|
+
return relativeWithDot(
|
|
704
|
+
tsconfigDir,
|
|
705
|
+
stats?.isFile() ? path.replace(/\b\.\w+$/g, "") : path
|
|
706
|
+
);
|
|
707
|
+
})
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
const references = [];
|
|
711
|
+
await Promise.all([...silgi.options.modules, ...silgi.options._modules].map(async (id) => {
|
|
712
|
+
if (typeof id !== "string") {
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
const pkg = await readPackageJSON(id, { url: silgi.options.modulesDir }).catch(() => null);
|
|
716
|
+
references.push({ types: pkg?.name || id });
|
|
717
|
+
}));
|
|
718
|
+
const declarations = [];
|
|
719
|
+
await silgi.callHook("prepare:types", { references, declarations, tsConfig });
|
|
720
|
+
tsConfig.include = [...new Set(tsConfig.include.map((p) => isAbsolute(p) ? relativeWithDot(silgi.options.build.dir, p) : p))];
|
|
721
|
+
tsConfig.exclude = [...new Set(tsConfig.exclude.map((p) => isAbsolute(p) ? relativeWithDot(silgi.options.build.dir, p) : p))];
|
|
722
|
+
const _declarations = [
|
|
723
|
+
...references.map((ref) => {
|
|
724
|
+
if ("path" in ref && isAbsolute(ref.path)) {
|
|
725
|
+
ref.path = relative(silgi.options.build.dir, ref.path);
|
|
726
|
+
}
|
|
727
|
+
return `/// <reference ${renderAttrs(ref)} />`;
|
|
728
|
+
}),
|
|
729
|
+
...declarations,
|
|
730
|
+
"",
|
|
731
|
+
"export {}",
|
|
732
|
+
""
|
|
733
|
+
];
|
|
734
|
+
return {
|
|
735
|
+
declarations: _declarations,
|
|
736
|
+
tsConfig
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
export { loadOptions as l, silgiGenerateType as s };
|