silgi 0.11.4 → 0.12.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.
- package/dist/_chunks/index.mjs +1 -1
- package/dist/cli/dev.mjs +1 -0
- package/dist/cli/loader.mjs +2 -1
- package/dist/cli/prepare.mjs +1 -0
- package/dist/cli/writeTypesAndFiles.mjs +101 -41
- package/dist/kit/index.d.mts +4 -3
- package/dist/kit/index.d.ts +4 -3
- package/dist/kit/index.mjs +38 -21
- package/dist/meta/index.d.mts +1 -1
- package/dist/meta/index.d.ts +1 -1
- package/dist/types/index.d.mts +12 -4
- package/dist/types/index.d.ts +12 -4
- package/package.json +1 -1
package/dist/_chunks/index.mjs
CHANGED
package/dist/cli/dev.mjs
CHANGED
package/dist/cli/loader.mjs
CHANGED
|
@@ -97,7 +97,8 @@ const SilgiCLIDefaults = {
|
|
|
97
97
|
// generateRuntimeConfigTypes: true,
|
|
98
98
|
tsconfigPath: ".silgi/types/silgi.tsconfig.json",
|
|
99
99
|
tsConfig: {},
|
|
100
|
-
customConditions: []
|
|
100
|
+
customConditions: [],
|
|
101
|
+
generateRuntimeConfigTypes: true
|
|
101
102
|
},
|
|
102
103
|
conditions: [],
|
|
103
104
|
nodeModulesDirs: [],
|
package/dist/cli/prepare.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import consola$1, { consola } from 'consola';
|
|
|
4
4
|
import { createHooks, createDebugger } from 'hookable';
|
|
5
5
|
import { join, resolve, isAbsolute, relative, dirname, basename, extname } from 'pathe';
|
|
6
6
|
import { useSilgiCLI, silgiCLICtx } from 'silgi/core';
|
|
7
|
-
import { relativeWithDot, hash, resolveAlias, resolvePath, writeFile, normalizeTemplate, useLogger, addTemplate,
|
|
7
|
+
import { relativeWithDot, hash, resolveAlias, resolvePath, writeFile, normalizeTemplate, useLogger, addTemplate, initRuntimeConfig, hasError as hasError$1, isDirectory } from 'silgi/kit';
|
|
8
8
|
import { runtimeDir } from 'silgi/runtime/meta';
|
|
9
9
|
import { autoImportTypes } from 'silgi/types';
|
|
10
10
|
import { scanExports, createUnimport, toExports } from 'unimport';
|
|
@@ -23,6 +23,7 @@ import { createStorage, builtinDrivers } from 'unstorage';
|
|
|
23
23
|
import { peerDependencies } from 'silgi/meta';
|
|
24
24
|
import { l as loadOptions } from './loader.mjs';
|
|
25
25
|
import { resolveAlias as resolveAlias$1 } from 'pathe/utils';
|
|
26
|
+
import { generateTypes, resolveSchema } from 'untyped';
|
|
26
27
|
import { s as silgiGenerateType } from './types.mjs';
|
|
27
28
|
|
|
28
29
|
async function prepare(_silgi) {
|
|
@@ -146,7 +147,7 @@ async function nitroFramework(silgi, skip = false) {
|
|
|
146
147
|
data.customContent?.push(
|
|
147
148
|
"",
|
|
148
149
|
'declare module "silgi/types" {',
|
|
149
|
-
" interface
|
|
150
|
+
" interface SilgiRuntimeConfig extends NitroRuntimeConfig {}",
|
|
150
151
|
"}",
|
|
151
152
|
""
|
|
152
153
|
);
|
|
@@ -1382,32 +1383,14 @@ async function installPackages(silgi) {
|
|
|
1382
1383
|
});
|
|
1383
1384
|
}
|
|
1384
1385
|
|
|
1385
|
-
function _deepFreeze(object) {
|
|
1386
|
-
const propNames = Object.getOwnPropertyNames(object);
|
|
1387
|
-
for (const name of propNames) {
|
|
1388
|
-
const value = object[name];
|
|
1389
|
-
if (value && typeof value === "object") {
|
|
1390
|
-
_deepFreeze(value);
|
|
1391
|
-
}
|
|
1392
|
-
}
|
|
1393
|
-
return Object.freeze(object);
|
|
1394
|
-
}
|
|
1395
1386
|
function useCLIRuntimeConfig(silgi) {
|
|
1396
|
-
const
|
|
1397
|
-
|
|
1398
|
-
prefix: "NITRO_",
|
|
1399
|
-
altPrefix: process.env.NITRO_ENV_PREFIX ?? process.env.SILGI_ENV_PREFIX ?? "_",
|
|
1400
|
-
silgiPrefix: "SILGI_",
|
|
1401
|
-
envExpansion: process.env.NITRO_ENV_EXPANSION ?? process.env.SILGI_ENV_EXPANSION ?? false,
|
|
1402
|
-
...silgi.options.envOptions
|
|
1403
|
-
};
|
|
1387
|
+
const _sharedRuntimeConfig = initRuntimeConfig(silgi.options.envOptions, silgi.options.runtimeConfig);
|
|
1388
|
+
silgi.options.runtimeConfig = _sharedRuntimeConfig;
|
|
1404
1389
|
silgi.hook("prepare:configs.ts", (data) => {
|
|
1405
|
-
data.
|
|
1390
|
+
data.storage = silgi.options.storage;
|
|
1391
|
+
data.runtimeConfig = _sharedRuntimeConfig;
|
|
1392
|
+
silgi.options.envOptions = silgi.options.envOptions;
|
|
1406
1393
|
});
|
|
1407
|
-
const _sharedRuntimeConfig = _deepFreeze(
|
|
1408
|
-
applyEnv(klona(_inlineRuntimeConfig), envOptions)
|
|
1409
|
-
);
|
|
1410
|
-
silgi.options.runtimeConfig = _sharedRuntimeConfig;
|
|
1411
1394
|
return _sharedRuntimeConfig;
|
|
1412
1395
|
}
|
|
1413
1396
|
|
|
@@ -1540,18 +1523,47 @@ async function createSilgiCLI(config = {}, opts = {}) {
|
|
|
1540
1523
|
return silgi;
|
|
1541
1524
|
}
|
|
1542
1525
|
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1526
|
+
function serializeToJs(obj, indent = 2, level = 0) {
|
|
1527
|
+
if (obj === null || obj === void 0) {
|
|
1528
|
+
return String(obj);
|
|
1529
|
+
}
|
|
1530
|
+
if (typeof obj === "function") {
|
|
1531
|
+
return obj.toString();
|
|
1532
|
+
}
|
|
1533
|
+
if (typeof obj !== "object") {
|
|
1534
|
+
if (typeof obj === "string") {
|
|
1535
|
+
if (obj.startsWith("runtime.")) {
|
|
1536
|
+
return obj;
|
|
1548
1537
|
}
|
|
1538
|
+
return `'${obj.replace(/'/g, "\\'")}'`;
|
|
1549
1539
|
}
|
|
1550
|
-
|
|
1540
|
+
return String(obj);
|
|
1541
|
+
}
|
|
1542
|
+
if (Array.isArray(obj)) {
|
|
1543
|
+
if (obj.length === 0)
|
|
1544
|
+
return "[]";
|
|
1545
|
+
const items = obj.map((item) => serializeToJs(item, indent, level + 1)).join(`,
|
|
1546
|
+
${" ".repeat((level + 1) * indent)}`);
|
|
1547
|
+
return `[
|
|
1548
|
+
${" ".repeat((level + 1) * indent)}${items}
|
|
1549
|
+
${" ".repeat(level * indent)}]`;
|
|
1550
|
+
}
|
|
1551
|
+
const entries = Object.entries(obj);
|
|
1552
|
+
if (entries.length === 0)
|
|
1553
|
+
return "{}";
|
|
1554
|
+
const props = entries.map(([key, value]) => {
|
|
1555
|
+
const keyStr = /^[a-z_$][\w$]*$/i.test(key) ? key : `'${key}'`;
|
|
1556
|
+
return `${keyStr}: ${serializeToJs(value, indent, level + 1)}`;
|
|
1557
|
+
}).join(`,
|
|
1558
|
+
${" ".repeat((level + 1) * indent)}`);
|
|
1559
|
+
return `{
|
|
1560
|
+
${" ".repeat((level + 1) * indent)}${props}
|
|
1561
|
+
${" ".repeat(level * indent)}}`;
|
|
1551
1562
|
}
|
|
1552
|
-
|
|
1553
1563
|
async function prepareConfigs(silgi) {
|
|
1554
|
-
const _data = {
|
|
1564
|
+
const _data = {
|
|
1565
|
+
runtimeConfig: {}
|
|
1566
|
+
};
|
|
1555
1567
|
for (const module of silgi.scanModules) {
|
|
1556
1568
|
if (module.meta.cliToRuntimeOptionsKeys && module.meta.cliToRuntimeOptionsKeys?.length > 0) {
|
|
1557
1569
|
for (const key of module.meta.cliToRuntimeOptionsKeys) {
|
|
@@ -1565,10 +1577,20 @@ async function prepareConfigs(silgi) {
|
|
|
1565
1577
|
}
|
|
1566
1578
|
}
|
|
1567
1579
|
await silgi.callHook("prepare:configs.ts", _data);
|
|
1580
|
+
const runtimeConfig = JSON.parse(JSON.stringify(_data.runtimeConfig || {}));
|
|
1581
|
+
delete _data.runtimeConfig;
|
|
1568
1582
|
const importData = [
|
|
1569
|
-
"import type { SilgiRuntimeOptions } from 'silgi/types'",
|
|
1583
|
+
"import type { SilgiRuntimeOptions, SilgiRuntimeConfig } from 'silgi/types'",
|
|
1584
|
+
"import { useSilgiRuntimeConfig } from 'silgi/kit'",
|
|
1585
|
+
"",
|
|
1586
|
+
`export const runtimeConfig: Partial<SilgiRuntimeConfig> = ${serializeToJs(runtimeConfig)}`,
|
|
1587
|
+
"",
|
|
1588
|
+
"const runtime = useSilgiRuntimeConfig(undefined, runtimeConfig)",
|
|
1570
1589
|
"",
|
|
1571
|
-
|
|
1590
|
+
"export const cliConfigs: Partial<SilgiRuntimeOptions> = {",
|
|
1591
|
+
" runtimeConfig: runtime,",
|
|
1592
|
+
` ${serializeToJs(_data).replace(/^\{/, "").replace(/\}$/, "")}`,
|
|
1593
|
+
"}",
|
|
1572
1594
|
""
|
|
1573
1595
|
];
|
|
1574
1596
|
return importData;
|
|
@@ -1790,7 +1812,6 @@ async function createDTSFramework(silgi) {
|
|
|
1790
1812
|
|
|
1791
1813
|
async function writeCoreFile(silgi) {
|
|
1792
1814
|
const data = await prepareFramework(silgi);
|
|
1793
|
-
await generateSilgiStorageBaseType(silgi);
|
|
1794
1815
|
const coreContent = await prepareCoreFile({
|
|
1795
1816
|
_importItems: data?.importItems ?? {},
|
|
1796
1817
|
_customImports: data?.customImports ?? []
|
|
@@ -1897,9 +1918,21 @@ async function prepareSchema(silgi) {
|
|
|
1897
1918
|
const importItems = {
|
|
1898
1919
|
"silgi/types": {
|
|
1899
1920
|
import: [
|
|
1900
|
-
{
|
|
1901
|
-
|
|
1902
|
-
|
|
1921
|
+
{
|
|
1922
|
+
name: "URIsTypes",
|
|
1923
|
+
type: true,
|
|
1924
|
+
key: "URIsTypes"
|
|
1925
|
+
},
|
|
1926
|
+
{
|
|
1927
|
+
name: "Namespaces",
|
|
1928
|
+
type: true,
|
|
1929
|
+
key: "Namespaces"
|
|
1930
|
+
},
|
|
1931
|
+
{
|
|
1932
|
+
name: "SilgiRuntimeContext",
|
|
1933
|
+
type: true,
|
|
1934
|
+
key: "SilgiRuntimeContext"
|
|
1935
|
+
}
|
|
1903
1936
|
],
|
|
1904
1937
|
from: "silgi/types"
|
|
1905
1938
|
}
|
|
@@ -1918,7 +1951,6 @@ async function prepareSchema(silgi) {
|
|
|
1918
1951
|
runtimeOptions: [],
|
|
1919
1952
|
methods: []
|
|
1920
1953
|
};
|
|
1921
|
-
const storeBase = [];
|
|
1922
1954
|
await silgi.callHook("prepare:schema.ts", data);
|
|
1923
1955
|
relativeWithDot(silgi.options.build.typesDir, `${silgi.options.silgi.serverDir}/core.ts`);
|
|
1924
1956
|
const silgiScanTS = relativeWithDot(silgi.options.build.typesDir, `${silgi.options.silgi.serverDir}/scan.ts`);
|
|
@@ -1962,8 +1994,24 @@ async function prepareSchema(silgi) {
|
|
|
1962
1994
|
"",
|
|
1963
1995
|
`type SilgiRuntimeOptionExtends = ${data.runtimeOptions?.length ? data.runtimeOptions.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
|
|
1964
1996
|
"",
|
|
1997
|
+
silgi.options.typescript.generateRuntimeConfigTypes ? generateTypes(
|
|
1998
|
+
await resolveSchema(
|
|
1999
|
+
Object.fromEntries(
|
|
2000
|
+
Object.entries(silgi.options.runtimeConfig).filter(
|
|
2001
|
+
([key]) => !["app", "nitro", "nuxt"].includes(key)
|
|
2002
|
+
)
|
|
2003
|
+
)
|
|
2004
|
+
),
|
|
2005
|
+
{
|
|
2006
|
+
interfaceName: "SilgiRuntimeConfigExtends",
|
|
2007
|
+
addExport: false,
|
|
2008
|
+
addDefaults: false,
|
|
2009
|
+
allowExtraKeys: false,
|
|
2010
|
+
indentation: 0
|
|
2011
|
+
}
|
|
2012
|
+
) : "",
|
|
1965
2013
|
"interface SilgiStorageBaseExtends {",
|
|
1966
|
-
...(storeBase || []).map((value) => ` ${value}: ''`),
|
|
2014
|
+
...(data.storeBase || []).map((value) => ` ${value}: ''`),
|
|
1967
2015
|
"}",
|
|
1968
2016
|
"",
|
|
1969
2017
|
`type ModuleHooksExtend = ${data.hooks?.length ? data.hooks.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
|
|
@@ -1983,6 +2031,7 @@ async function prepareSchema(silgi) {
|
|
|
1983
2031
|
" interface SilgiModuleOptions extends SilgiModuleOptionExtend {}",
|
|
1984
2032
|
" interface SilgiRuntimeOptions extends SilgiRuntimeOptionExtends {}",
|
|
1985
2033
|
" interface SilgiRuntimeHooks extends SilgiRuntimeHooksExtends {}",
|
|
2034
|
+
" interface SilgiRuntimeConfig extends SilgiRuntimeConfigExtends {}",
|
|
1986
2035
|
" interface SilgiHooks extends ModuleHooksExtend {}",
|
|
1987
2036
|
" interface SilgiRuntimeMethods extends RuntimeMethodExtends {}",
|
|
1988
2037
|
"}",
|
|
@@ -1994,8 +2043,19 @@ async function prepareSchema(silgi) {
|
|
|
1994
2043
|
return importData;
|
|
1995
2044
|
}
|
|
1996
2045
|
|
|
2046
|
+
async function prepareStore(silgi) {
|
|
2047
|
+
silgi.hook("prepare:schema.ts", async (options) => {
|
|
2048
|
+
if (silgi.options.storage) {
|
|
2049
|
+
for (const [key, _value] of Object.entries(silgi.options.storage)) {
|
|
2050
|
+
options.storeBase.push(key);
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
});
|
|
2054
|
+
}
|
|
2055
|
+
|
|
1997
2056
|
async function writeTypesAndFiles(silgi) {
|
|
1998
2057
|
const routerDTS = await generateRouterDTS(silgi);
|
|
2058
|
+
await prepareStore(silgi);
|
|
1999
2059
|
silgi.hook("prepare:types", (opts) => {
|
|
2000
2060
|
opts.references.push({ path: "./schema.d.ts" });
|
|
2001
2061
|
opts.references.push({ path: "./silgi-routes.d.ts" });
|
package/dist/kit/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, SilgiPreset, SilgiPresetMeta, EnvOptions, SilgiEvents, SilgiTemplate, ResolvedSilgiTemplate } from 'silgi/types';
|
|
1
|
+
import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, SilgiPreset, SilgiPresetMeta, EnvOptions, SilgiRuntimeConfig, SilgiEvents, SilgiTemplate, ResolvedSilgiTemplate } from 'silgi/types';
|
|
2
2
|
import { Buffer } from 'node:buffer';
|
|
3
3
|
import * as consola from 'consola';
|
|
4
4
|
import { ConsolaOptions } from 'consola';
|
|
@@ -80,7 +80,8 @@ declare function resolveSilgiModule(base: string, paths: string[]): Promise<stri
|
|
|
80
80
|
*
|
|
81
81
|
* This mirrors the runtime behavior of Nitro.
|
|
82
82
|
*/
|
|
83
|
-
declare function useSilgiRuntimeConfig(event?: SilgiEvents):
|
|
83
|
+
declare function useSilgiRuntimeConfig<T extends SilgiRuntimeConfig>(event?: SilgiEvents, inlineRuntimeConfig?: Record<string, any>): SilgiRuntimeConfig;
|
|
84
|
+
declare function initRuntimeConfig(envOptions?: EnvOptions, inlineRuntimeConfig?: Record<string, any>): Readonly<Record<string, any>>;
|
|
84
85
|
declare function applyEnv(obj: Record<string, any>, opts: EnvOptions, parentKey?: string): Record<string, any>;
|
|
85
86
|
|
|
86
87
|
/**
|
|
@@ -112,4 +113,4 @@ declare const MODE_RE: RegExp;
|
|
|
112
113
|
declare function hasSilgiModule(moduleKey: string, silgi?: SilgiCLI): boolean;
|
|
113
114
|
declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolean;
|
|
114
115
|
|
|
115
|
-
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, hasError, hasInstalledModule, hasSilgiModule, hash, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useSilgiRuntimeConfig, writeFile };
|
|
116
|
+
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useSilgiRuntimeConfig, writeFile };
|
package/dist/kit/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, SilgiPreset, SilgiPresetMeta, EnvOptions, SilgiEvents, SilgiTemplate, ResolvedSilgiTemplate } from 'silgi/types';
|
|
1
|
+
import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, SilgiPreset, SilgiPresetMeta, EnvOptions, SilgiRuntimeConfig, SilgiEvents, SilgiTemplate, ResolvedSilgiTemplate } from 'silgi/types';
|
|
2
2
|
import { Buffer } from 'node:buffer';
|
|
3
3
|
import * as consola from 'consola';
|
|
4
4
|
import { ConsolaOptions } from 'consola';
|
|
@@ -80,7 +80,8 @@ declare function resolveSilgiModule(base: string, paths: string[]): Promise<stri
|
|
|
80
80
|
*
|
|
81
81
|
* This mirrors the runtime behavior of Nitro.
|
|
82
82
|
*/
|
|
83
|
-
declare function useSilgiRuntimeConfig(event?: SilgiEvents):
|
|
83
|
+
declare function useSilgiRuntimeConfig<T extends SilgiRuntimeConfig>(event?: SilgiEvents, inlineRuntimeConfig?: Record<string, any>): SilgiRuntimeConfig;
|
|
84
|
+
declare function initRuntimeConfig(envOptions?: EnvOptions, inlineRuntimeConfig?: Record<string, any>): Readonly<Record<string, any>>;
|
|
84
85
|
declare function applyEnv(obj: Record<string, any>, opts: EnvOptions, parentKey?: string): Record<string, any>;
|
|
85
86
|
|
|
86
87
|
/**
|
|
@@ -112,4 +113,4 @@ declare const MODE_RE: RegExp;
|
|
|
112
113
|
declare function hasSilgiModule(moduleKey: string, silgi?: SilgiCLI): boolean;
|
|
113
114
|
declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolean;
|
|
114
115
|
|
|
115
|
-
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, hasError, hasInstalledModule, hasSilgiModule, hash, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useSilgiRuntimeConfig, writeFile };
|
|
116
|
+
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useSilgiRuntimeConfig, writeFile };
|
package/dist/kit/index.mjs
CHANGED
|
@@ -248,39 +248,56 @@ async function resolveSilgiModule(base, paths) {
|
|
|
248
248
|
return resolved;
|
|
249
249
|
}
|
|
250
250
|
|
|
251
|
-
const
|
|
252
|
-
/** */
|
|
253
|
-
process.env.RUNTIME_CONFIG
|
|
254
|
-
);
|
|
251
|
+
const silgiRuntimeConfig = process.env.RUNTIME_CONFIG;
|
|
255
252
|
const envOptions = {
|
|
256
253
|
prefix: "NITRO_",
|
|
257
|
-
altPrefix:
|
|
258
|
-
|
|
254
|
+
altPrefix: silgiRuntimeConfig?.nitro.envPrefix ?? process.env.NITRO_ENV_PREFIX ?? "_",
|
|
255
|
+
silgiPrefix: "SILGI_",
|
|
256
|
+
envExpansion: silgiRuntimeConfig?.nitro.envExpansion ?? process.env.NITRO_ENV_EXPANSION ?? false
|
|
259
257
|
};
|
|
260
|
-
|
|
261
|
-
applyEnv(klona(
|
|
258
|
+
let _sharedRuntimeConfig = _deepFreeze(
|
|
259
|
+
applyEnv(klona(silgiRuntimeConfig ?? {}), envOptions)
|
|
262
260
|
);
|
|
263
|
-
function useSilgiRuntimeConfig(event) {
|
|
261
|
+
function useSilgiRuntimeConfig(event, inlineRuntimeConfig = {}) {
|
|
264
262
|
const silgi = tryUseSilgi();
|
|
265
263
|
if (!silgi) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
264
|
+
if (globalThis.$silgiSharedRuntimeConfig) {
|
|
265
|
+
inlineRuntimeConfig = globalThis.$silgiSharedRuntimeConfig;
|
|
266
|
+
if (inlineRuntimeConfig && !event) {
|
|
267
|
+
return inlineRuntimeConfig;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (!silgiRuntimeConfig) {
|
|
271
|
+
_sharedRuntimeConfig = initRuntimeConfig(envOptions, inlineRuntimeConfig);
|
|
269
272
|
}
|
|
270
273
|
if (!event) {
|
|
271
274
|
return _sharedRuntimeConfig;
|
|
272
275
|
}
|
|
273
|
-
const
|
|
274
|
-
applyEnv(
|
|
275
|
-
return
|
|
276
|
+
const runtimeConfig2 = klona(silgiRuntimeConfig);
|
|
277
|
+
applyEnv(runtimeConfig2, envOptions);
|
|
278
|
+
return runtimeConfig2;
|
|
279
|
+
}
|
|
280
|
+
if (!silgiRuntimeConfig) {
|
|
281
|
+
_sharedRuntimeConfig = initRuntimeConfig(envOptions, inlineRuntimeConfig);
|
|
282
|
+
}
|
|
283
|
+
if (!event) {
|
|
284
|
+
return _sharedRuntimeConfig;
|
|
276
285
|
}
|
|
277
|
-
|
|
286
|
+
const runtimeConfig = klona(silgiRuntimeConfig);
|
|
287
|
+
applyEnv(runtimeConfig, envOptions);
|
|
288
|
+
return runtimeConfig;
|
|
289
|
+
}
|
|
290
|
+
function initRuntimeConfig(envOptions2 = {}, inlineRuntimeConfig = {}) {
|
|
291
|
+
const finalEnvOptions = {
|
|
278
292
|
prefix: "NITRO_",
|
|
279
|
-
altPrefix: "
|
|
293
|
+
altPrefix: inlineRuntimeConfig?.nitro?.envPrefix ?? process.env.NITRO_ENV_PREFIX ?? "_",
|
|
280
294
|
silgiPrefix: "SILGI_",
|
|
281
|
-
envExpansion:
|
|
282
|
-
...
|
|
283
|
-
}
|
|
295
|
+
envExpansion: inlineRuntimeConfig?.nitro?.envExpansion ?? process.env.NITRO_ENV_EXPANSION ?? false,
|
|
296
|
+
...envOptions2
|
|
297
|
+
};
|
|
298
|
+
return _deepFreeze(
|
|
299
|
+
applyEnv(klona(inlineRuntimeConfig), finalEnvOptions)
|
|
300
|
+
);
|
|
284
301
|
}
|
|
285
302
|
function getEnv(key, opts, env = process.env) {
|
|
286
303
|
const envKey = snakeCase(key).toUpperCase();
|
|
@@ -396,4 +413,4 @@ function normalizeTemplate(template, buildDir) {
|
|
|
396
413
|
return template;
|
|
397
414
|
}
|
|
398
415
|
|
|
399
|
-
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, hasInstalledModule, hasSilgiModule, hash, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useSilgiRuntimeConfig, writeFile };
|
|
416
|
+
export { MODE_RE, addTemplate, applyEnv, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useSilgiRuntimeConfig, writeFile };
|
package/dist/meta/index.d.mts
CHANGED
package/dist/meta/index.d.ts
CHANGED
package/dist/types/index.d.mts
CHANGED
|
@@ -6,7 +6,7 @@ import { Hookable, NestedHooks } from 'hookable';
|
|
|
6
6
|
import { Ignore, Options } from 'ignore';
|
|
7
7
|
import { TSConfig } from 'pkg-types';
|
|
8
8
|
import { PresetName, PresetOptions, PresetNameInput } from 'silgi/presets';
|
|
9
|
-
import { ResolvedServiceType as ResolvedServiceType$1, SilgiRuntimeShareds as SilgiRuntimeShareds$1, SilgiRuntimeOptions as SilgiRuntimeOptions$1, ModuleMeta as ModuleMeta$1, DotenvOptions as DotenvOptions$1, EnvOptions as EnvOptions$1, SilgiCLIHooks as SilgiCLIHooks$1, StorageMounts as StorageMounts$1, SilgiTemplate as SilgiTemplate$1, SilgiFrameworkInfo as SilgiFrameworkInfo$1 } from 'silgi/types';
|
|
9
|
+
import { ResolvedServiceType as ResolvedServiceType$1, SilgiRuntimeShareds as SilgiRuntimeShareds$1, SilgiRuntimeOptions as SilgiRuntimeOptions$1, ModuleMeta as ModuleMeta$1, DotenvOptions as DotenvOptions$1, EnvOptions as EnvOptions$1, SilgiRuntimeConfig as SilgiRuntimeConfig$1, SilgiCLIHooks as SilgiCLIHooks$1, StorageMounts as StorageMounts$1, SilgiTemplate as SilgiTemplate$1, SilgiFrameworkInfo as SilgiFrameworkInfo$1 } from 'silgi/types';
|
|
10
10
|
import { UnimportPluginOptions } from 'unimport/unplugin';
|
|
11
11
|
import { Defu } from 'defu';
|
|
12
12
|
import { Unimport } from 'unimport';
|
|
@@ -566,7 +566,7 @@ interface SilgiCLIOptions extends PresetOptions {
|
|
|
566
566
|
environments: DotenvOptions$1[];
|
|
567
567
|
activeEnvironment: string;
|
|
568
568
|
envOptions: EnvOptions$1;
|
|
569
|
-
runtimeConfig:
|
|
569
|
+
runtimeConfig: SilgiRuntimeConfig$1 & {
|
|
570
570
|
[key: string]: any;
|
|
571
571
|
};
|
|
572
572
|
namespaces: string[];
|
|
@@ -742,6 +742,12 @@ interface SilgiCLIOptions extends PresetOptions {
|
|
|
742
742
|
* @default ['silgiTypes']
|
|
743
743
|
*/
|
|
744
744
|
customConditions: string[];
|
|
745
|
+
/**
|
|
746
|
+
* Enable generating runtime configuration types.
|
|
747
|
+
*
|
|
748
|
+
* @default true
|
|
749
|
+
*/
|
|
750
|
+
generateRuntimeConfigTypes: boolean;
|
|
745
751
|
};
|
|
746
752
|
alias: Record<string, string>;
|
|
747
753
|
/**
|
|
@@ -976,6 +982,8 @@ interface SilgiRuntimeHooks {
|
|
|
976
982
|
'error': CaptureError;
|
|
977
983
|
}
|
|
978
984
|
|
|
985
|
+
interface SilgiRuntimeConfig {
|
|
986
|
+
}
|
|
979
987
|
interface SilgiOptions {
|
|
980
988
|
consolaOptions?: Partial<ConsolaOptions>;
|
|
981
989
|
present: PresetNameInput;
|
|
@@ -990,7 +998,7 @@ interface SilgiOptions {
|
|
|
990
998
|
debug: boolean;
|
|
991
999
|
storage: StorageMounts;
|
|
992
1000
|
putStorage?: Storage<StorageValue>;
|
|
993
|
-
runtimeConfig:
|
|
1001
|
+
runtimeConfig: SilgiRuntimeConfig & {
|
|
994
1002
|
[key: string]: any;
|
|
995
1003
|
};
|
|
996
1004
|
captureError: CaptureError;
|
|
@@ -1047,4 +1055,4 @@ type Namespaces<T extends BaseNamespaceType> = {
|
|
|
1047
1055
|
|
|
1048
1056
|
declare const autoImportTypes: string[];
|
|
1049
1057
|
|
|
1050
|
-
export { type AppConfig, type Awaitable, type BaseNamespaceType, type BaseSchemaType, type BaseSilgiMethodType, type CaptureError, type CapturedErrorContext, type CommandType, type CreateScope, type DeepPartial, type DefaultHooks, type DefaultNamespaces, type DotenvOptions, type EnvOptions, type EventHandlerResponse, type ExtendContext, type ExtendShared, type ExtractInputFromURI, type ExtractOutputFromURI, type ExtractPathParamsFromURI, type ExtractQueryParamsFromURI, type ExtractSourceFromURI, type FrameworkContext, type GenerateAppOptions, type GraphQLJSON, type HookResult, type ImportItem, type LoadConfigOptions, type MergedSilgiSchema, type MethodHandlerType, type ModuleDefinition, type ModuleHookContext, type ModuleMeta, type ModuleOptionsCustom, type ModuleSetupInstallResult, type ModuleSetupReturn, type Namespaces, type NitroBuildInfo, type PrepareCore, type RequiredServiceType, type ResolvedMethodHandlerType, type ResolvedModuleMeta, type ResolvedModuleOptions, type ResolvedServiceType, type ResolvedSilgiTemplate, type ScanFile, type SchemaPreparationOptions, type ServiceType, type Silgi, type SilgiAppPlugin, type SilgiCLI, type SilgiCLIConfig, type SilgiCLIDynamicConfig, type SilgiCLIHooks, type SilgiCLIOptions, type SilgiCompatibility, type SilgiCompatibilityIssue, type SilgiCompatibilityIssues, type SilgiConfig, type SilgiEvents, type SilgiFrameworkInfo, type SilgiFunction, type SilgiHooks, type SilgiModule, type SilgiModuleInput, type SilgiModuleOptions, type SilgiNamespaces, type SilgiOperation, type SilgiOptions, type SilgiPreset, type SilgiPresetMeta, type SilgiRouterTypes, type SilgiRuntimeActions, type SilgiRuntimeContext, type SilgiRuntimeHooks, type SilgiRuntimeMethods, type SilgiRuntimeOptions, type SilgiRuntimeSharedExtends, type SilgiRuntimeShareds, type SilgiSchema, type SilgiServiceInterface, type SilgiStorageBase, type SilgiTemplate, type SilgiURIs, type StorageConfig, type StorageKeyGenerator, type StorageKeyParams, type StorageMounts, type TSReference, type URIsTypes, autoImportTypes };
|
|
1058
|
+
export { type AppConfig, type Awaitable, type BaseNamespaceType, type BaseSchemaType, type BaseSilgiMethodType, type CaptureError, type CapturedErrorContext, type CommandType, type CreateScope, type DeepPartial, type DefaultHooks, type DefaultNamespaces, type DotenvOptions, type EnvOptions, type EventHandlerResponse, type ExtendContext, type ExtendShared, type ExtractInputFromURI, type ExtractOutputFromURI, type ExtractPathParamsFromURI, type ExtractQueryParamsFromURI, type ExtractSourceFromURI, type FrameworkContext, type GenerateAppOptions, type GraphQLJSON, type HookResult, type ImportItem, type LoadConfigOptions, type MergedSilgiSchema, type MethodHandlerType, type ModuleDefinition, type ModuleHookContext, type ModuleMeta, type ModuleOptionsCustom, type ModuleSetupInstallResult, type ModuleSetupReturn, type Namespaces, type NitroBuildInfo, type PrepareCore, type RequiredServiceType, type ResolvedMethodHandlerType, type ResolvedModuleMeta, type ResolvedModuleOptions, type ResolvedServiceType, type ResolvedSilgiTemplate, type ScanFile, type SchemaPreparationOptions, type ServiceType, type Silgi, type SilgiAppPlugin, type SilgiCLI, type SilgiCLIConfig, type SilgiCLIDynamicConfig, type SilgiCLIHooks, type SilgiCLIOptions, type SilgiCompatibility, type SilgiCompatibilityIssue, type SilgiCompatibilityIssues, type SilgiConfig, type SilgiEvents, type SilgiFrameworkInfo, type SilgiFunction, type SilgiHooks, type SilgiModule, type SilgiModuleInput, type SilgiModuleOptions, type SilgiNamespaces, type SilgiOperation, type SilgiOptions, type SilgiPreset, type SilgiPresetMeta, type SilgiRouterTypes, type SilgiRuntimeActions, type SilgiRuntimeConfig, type SilgiRuntimeContext, type SilgiRuntimeHooks, type SilgiRuntimeMethods, type SilgiRuntimeOptions, type SilgiRuntimeSharedExtends, type SilgiRuntimeShareds, type SilgiSchema, type SilgiServiceInterface, type SilgiStorageBase, type SilgiTemplate, type SilgiURIs, type StorageConfig, type StorageKeyGenerator, type StorageKeyParams, type StorageMounts, type TSReference, type URIsTypes, autoImportTypes };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { Hookable, NestedHooks } from 'hookable';
|
|
|
6
6
|
import { Ignore, Options } from 'ignore';
|
|
7
7
|
import { TSConfig } from 'pkg-types';
|
|
8
8
|
import { PresetName, PresetOptions, PresetNameInput } from 'silgi/presets';
|
|
9
|
-
import { ResolvedServiceType as ResolvedServiceType$1, SilgiRuntimeShareds as SilgiRuntimeShareds$1, SilgiRuntimeOptions as SilgiRuntimeOptions$1, ModuleMeta as ModuleMeta$1, DotenvOptions as DotenvOptions$1, EnvOptions as EnvOptions$1, SilgiCLIHooks as SilgiCLIHooks$1, StorageMounts as StorageMounts$1, SilgiTemplate as SilgiTemplate$1, SilgiFrameworkInfo as SilgiFrameworkInfo$1 } from 'silgi/types';
|
|
9
|
+
import { ResolvedServiceType as ResolvedServiceType$1, SilgiRuntimeShareds as SilgiRuntimeShareds$1, SilgiRuntimeOptions as SilgiRuntimeOptions$1, ModuleMeta as ModuleMeta$1, DotenvOptions as DotenvOptions$1, EnvOptions as EnvOptions$1, SilgiRuntimeConfig as SilgiRuntimeConfig$1, SilgiCLIHooks as SilgiCLIHooks$1, StorageMounts as StorageMounts$1, SilgiTemplate as SilgiTemplate$1, SilgiFrameworkInfo as SilgiFrameworkInfo$1 } from 'silgi/types';
|
|
10
10
|
import { UnimportPluginOptions } from 'unimport/unplugin';
|
|
11
11
|
import { Defu } from 'defu';
|
|
12
12
|
import { Unimport } from 'unimport';
|
|
@@ -566,7 +566,7 @@ interface SilgiCLIOptions extends PresetOptions {
|
|
|
566
566
|
environments: DotenvOptions$1[];
|
|
567
567
|
activeEnvironment: string;
|
|
568
568
|
envOptions: EnvOptions$1;
|
|
569
|
-
runtimeConfig:
|
|
569
|
+
runtimeConfig: SilgiRuntimeConfig$1 & {
|
|
570
570
|
[key: string]: any;
|
|
571
571
|
};
|
|
572
572
|
namespaces: string[];
|
|
@@ -742,6 +742,12 @@ interface SilgiCLIOptions extends PresetOptions {
|
|
|
742
742
|
* @default ['silgiTypes']
|
|
743
743
|
*/
|
|
744
744
|
customConditions: string[];
|
|
745
|
+
/**
|
|
746
|
+
* Enable generating runtime configuration types.
|
|
747
|
+
*
|
|
748
|
+
* @default true
|
|
749
|
+
*/
|
|
750
|
+
generateRuntimeConfigTypes: boolean;
|
|
745
751
|
};
|
|
746
752
|
alias: Record<string, string>;
|
|
747
753
|
/**
|
|
@@ -976,6 +982,8 @@ interface SilgiRuntimeHooks {
|
|
|
976
982
|
'error': CaptureError;
|
|
977
983
|
}
|
|
978
984
|
|
|
985
|
+
interface SilgiRuntimeConfig {
|
|
986
|
+
}
|
|
979
987
|
interface SilgiOptions {
|
|
980
988
|
consolaOptions?: Partial<ConsolaOptions>;
|
|
981
989
|
present: PresetNameInput;
|
|
@@ -990,7 +998,7 @@ interface SilgiOptions {
|
|
|
990
998
|
debug: boolean;
|
|
991
999
|
storage: StorageMounts;
|
|
992
1000
|
putStorage?: Storage<StorageValue>;
|
|
993
|
-
runtimeConfig:
|
|
1001
|
+
runtimeConfig: SilgiRuntimeConfig & {
|
|
994
1002
|
[key: string]: any;
|
|
995
1003
|
};
|
|
996
1004
|
captureError: CaptureError;
|
|
@@ -1047,4 +1055,4 @@ type Namespaces<T extends BaseNamespaceType> = {
|
|
|
1047
1055
|
|
|
1048
1056
|
declare const autoImportTypes: string[];
|
|
1049
1057
|
|
|
1050
|
-
export { type AppConfig, type Awaitable, type BaseNamespaceType, type BaseSchemaType, type BaseSilgiMethodType, type CaptureError, type CapturedErrorContext, type CommandType, type CreateScope, type DeepPartial, type DefaultHooks, type DefaultNamespaces, type DotenvOptions, type EnvOptions, type EventHandlerResponse, type ExtendContext, type ExtendShared, type ExtractInputFromURI, type ExtractOutputFromURI, type ExtractPathParamsFromURI, type ExtractQueryParamsFromURI, type ExtractSourceFromURI, type FrameworkContext, type GenerateAppOptions, type GraphQLJSON, type HookResult, type ImportItem, type LoadConfigOptions, type MergedSilgiSchema, type MethodHandlerType, type ModuleDefinition, type ModuleHookContext, type ModuleMeta, type ModuleOptionsCustom, type ModuleSetupInstallResult, type ModuleSetupReturn, type Namespaces, type NitroBuildInfo, type PrepareCore, type RequiredServiceType, type ResolvedMethodHandlerType, type ResolvedModuleMeta, type ResolvedModuleOptions, type ResolvedServiceType, type ResolvedSilgiTemplate, type ScanFile, type SchemaPreparationOptions, type ServiceType, type Silgi, type SilgiAppPlugin, type SilgiCLI, type SilgiCLIConfig, type SilgiCLIDynamicConfig, type SilgiCLIHooks, type SilgiCLIOptions, type SilgiCompatibility, type SilgiCompatibilityIssue, type SilgiCompatibilityIssues, type SilgiConfig, type SilgiEvents, type SilgiFrameworkInfo, type SilgiFunction, type SilgiHooks, type SilgiModule, type SilgiModuleInput, type SilgiModuleOptions, type SilgiNamespaces, type SilgiOperation, type SilgiOptions, type SilgiPreset, type SilgiPresetMeta, type SilgiRouterTypes, type SilgiRuntimeActions, type SilgiRuntimeContext, type SilgiRuntimeHooks, type SilgiRuntimeMethods, type SilgiRuntimeOptions, type SilgiRuntimeSharedExtends, type SilgiRuntimeShareds, type SilgiSchema, type SilgiServiceInterface, type SilgiStorageBase, type SilgiTemplate, type SilgiURIs, type StorageConfig, type StorageKeyGenerator, type StorageKeyParams, type StorageMounts, type TSReference, type URIsTypes, autoImportTypes };
|
|
1058
|
+
export { type AppConfig, type Awaitable, type BaseNamespaceType, type BaseSchemaType, type BaseSilgiMethodType, type CaptureError, type CapturedErrorContext, type CommandType, type CreateScope, type DeepPartial, type DefaultHooks, type DefaultNamespaces, type DotenvOptions, type EnvOptions, type EventHandlerResponse, type ExtendContext, type ExtendShared, type ExtractInputFromURI, type ExtractOutputFromURI, type ExtractPathParamsFromURI, type ExtractQueryParamsFromURI, type ExtractSourceFromURI, type FrameworkContext, type GenerateAppOptions, type GraphQLJSON, type HookResult, type ImportItem, type LoadConfigOptions, type MergedSilgiSchema, type MethodHandlerType, type ModuleDefinition, type ModuleHookContext, type ModuleMeta, type ModuleOptionsCustom, type ModuleSetupInstallResult, type ModuleSetupReturn, type Namespaces, type NitroBuildInfo, type PrepareCore, type RequiredServiceType, type ResolvedMethodHandlerType, type ResolvedModuleMeta, type ResolvedModuleOptions, type ResolvedServiceType, type ResolvedSilgiTemplate, type ScanFile, type SchemaPreparationOptions, type ServiceType, type Silgi, type SilgiAppPlugin, type SilgiCLI, type SilgiCLIConfig, type SilgiCLIDynamicConfig, type SilgiCLIHooks, type SilgiCLIOptions, type SilgiCompatibility, type SilgiCompatibilityIssue, type SilgiCompatibilityIssues, type SilgiConfig, type SilgiEvents, type SilgiFrameworkInfo, type SilgiFunction, type SilgiHooks, type SilgiModule, type SilgiModuleInput, type SilgiModuleOptions, type SilgiNamespaces, type SilgiOperation, type SilgiOptions, type SilgiPreset, type SilgiPresetMeta, type SilgiRouterTypes, type SilgiRuntimeActions, type SilgiRuntimeConfig, type SilgiRuntimeContext, type SilgiRuntimeHooks, type SilgiRuntimeMethods, type SilgiRuntimeOptions, type SilgiRuntimeSharedExtends, type SilgiRuntimeShareds, type SilgiSchema, type SilgiServiceInterface, type SilgiStorageBase, type SilgiTemplate, type SilgiURIs, type StorageConfig, type StorageKeyGenerator, type StorageKeyParams, type StorageMounts, type TSReference, type URIsTypes, autoImportTypes };
|