silgi 0.23.9 → 0.23.11

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.
@@ -1,4 +1,4 @@
1
- const version = "0.23.9";
1
+ const version = "0.23.11";
2
2
  const peerDependencies = {
3
3
  "@fastify/deepmerge": "^3.0.0",
4
4
  "@nuxt/kit": "^3.15.3",
@@ -1628,7 +1628,6 @@ async function scanDir(silgi, dir, name) {
1628
1628
 
1629
1629
  async function createSilgiCLI(config = {}, opts = {}) {
1630
1630
  const options = await loadOptions(config, opts);
1631
- await prepareEnv(options);
1632
1631
  const hooks = createHooks();
1633
1632
  const silgi = {
1634
1633
  modulesURIs: {},
@@ -1655,6 +1654,7 @@ async function createSilgiCLI(config = {}, opts = {}) {
1655
1654
  },
1656
1655
  routeRules: void 0
1657
1656
  };
1657
+ await prepareEnv(options);
1658
1658
  const routeRules = createRouteRules();
1659
1659
  routeRules.importRules(options.routeRules ?? {});
1660
1660
  silgi.routeRules = routeRules;
@@ -1746,7 +1746,7 @@ async function prepareConfigs(silgi) {
1746
1746
  await silgi.callHook("prepare:configs.ts", _data);
1747
1747
  const importData = [
1748
1748
  "import type { SilgiRuntimeOptions, SilgiRuntimeConfig, SilgiOptions } from 'silgi/types'",
1749
- "import { useSilgiRuntimeConfig } from 'silgi/kit'",
1749
+ "import { useSilgiRuntimeConfig } from 'silgi/runtime/internal/config'",
1750
1750
  "",
1751
1751
  `export const runtimeConfig: Partial<SilgiRuntimeConfig> = ${genObjectFromRawEntries(
1752
1752
  Object.entries(_data.runtimeConfig).map(([key, value]) => [key, genEnsureSafeVar(value)]),
@@ -1,4 +1,4 @@
1
- import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, ServiceParseModule, SilgiPreset, SilgiPresetMeta, EnvOptions, SilgiRuntimeConfig, SilgiEvents, SilgiTemplate, ResolvedSilgiTemplate } from 'silgi/types';
1
+ import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, ServiceParseModule, SilgiPreset, SilgiPresetMeta, SilgiTemplate, ResolvedSilgiTemplate, SilgiEvents } from 'silgi/types';
2
2
  import { Buffer } from 'node:buffer';
3
3
  import * as consola from 'consola';
4
4
  import { ConsolaOptions } from 'consola';
@@ -106,15 +106,6 @@ interface Resolver {
106
106
  declare function createResolver(base: string | URL): Resolver;
107
107
  declare function resolveSilgiModule(base: string, paths: string[]): Promise<string[]>;
108
108
 
109
- /**
110
- * Access 'resolved' Nuxt runtime configuration, with values updated from environment.
111
- *
112
- * This mirrors the runtime behavior of Nitro.
113
- */
114
- declare function useSilgiRuntimeConfig<T extends SilgiRuntimeConfig>(event?: SilgiEvents, inlineRuntimeConfig?: Record<string, any>): SilgiRuntimeConfig;
115
- declare function initRuntimeConfig(envOptions?: EnvOptions, inlineRuntimeConfig?: Record<string, any>): Readonly<Record<string, any>>;
116
- declare function applyEnv(obj: Record<string, any>, opts: EnvOptions, parentKey?: string): Record<string, any>;
117
-
118
109
  /**
119
110
  * Renders given template during build into the virtual file system (and optionally to disk in the project `buildDir`)
120
111
  */
@@ -156,6 +147,6 @@ declare const MODE_RE: RegExp;
156
147
  declare function hasSilgiModule(moduleKey: string, silgi?: SilgiCLI): boolean;
157
148
  declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolean;
158
149
  declare const baseHeaderBannerComment: string[];
159
- declare function addFileExtension(src: string): string;
150
+ declare function processFilePath(src: string): string;
160
151
 
161
- export { MODE_RE, addFileExtension, addTemplate, applyEnv, baseHeaderBannerComment, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, useSilgiRuntimeConfig, writeFile };
152
+ export { MODE_RE, addTemplate, baseHeaderBannerComment, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
@@ -1,4 +1,4 @@
1
- import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, ServiceParseModule, SilgiPreset, SilgiPresetMeta, EnvOptions, SilgiRuntimeConfig, SilgiEvents, SilgiTemplate, ResolvedSilgiTemplate } from 'silgi/types';
1
+ import { SilgiCLI, ModuleOptionsCustom, ModuleDefinition, SilgiModule, ServiceParseModule, SilgiPreset, SilgiPresetMeta, SilgiTemplate, ResolvedSilgiTemplate, SilgiEvents } from 'silgi/types';
2
2
  import { Buffer } from 'node:buffer';
3
3
  import * as consola from 'consola';
4
4
  import { ConsolaOptions } from 'consola';
@@ -106,15 +106,6 @@ interface Resolver {
106
106
  declare function createResolver(base: string | URL): Resolver;
107
107
  declare function resolveSilgiModule(base: string, paths: string[]): Promise<string[]>;
108
108
 
109
- /**
110
- * Access 'resolved' Nuxt runtime configuration, with values updated from environment.
111
- *
112
- * This mirrors the runtime behavior of Nitro.
113
- */
114
- declare function useSilgiRuntimeConfig<T extends SilgiRuntimeConfig>(event?: SilgiEvents, inlineRuntimeConfig?: Record<string, any>): SilgiRuntimeConfig;
115
- declare function initRuntimeConfig(envOptions?: EnvOptions, inlineRuntimeConfig?: Record<string, any>): Readonly<Record<string, any>>;
116
- declare function applyEnv(obj: Record<string, any>, opts: EnvOptions, parentKey?: string): Record<string, any>;
117
-
118
109
  /**
119
110
  * Renders given template during build into the virtual file system (and optionally to disk in the project `buildDir`)
120
111
  */
@@ -156,6 +147,6 @@ declare const MODE_RE: RegExp;
156
147
  declare function hasSilgiModule(moduleKey: string, silgi?: SilgiCLI): boolean;
157
148
  declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolean;
158
149
  declare const baseHeaderBannerComment: string[];
159
- declare function addFileExtension(src: string): string;
150
+ declare function processFilePath(src: string): string;
160
151
 
161
- export { MODE_RE, addFileExtension, addTemplate, applyEnv, baseHeaderBannerComment, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, useSilgiRuntimeConfig, writeFile };
152
+ export { MODE_RE, addTemplate, baseHeaderBannerComment, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
@@ -1,4 +1,4 @@
1
- import { tryUseSilgiCLI, useSilgiCLI, useSilgi, tryUseSilgi } from 'silgi/core';
1
+ import { tryUseSilgiCLI, useSilgiCLI, useSilgi } from 'silgi/core';
2
2
  import { pathToFileURL, fileURLToPath } from 'node:url';
3
3
  import { resolvePath as resolvePath$1 } from 'mlly';
4
4
  import fsp from 'node:fs/promises';
@@ -8,14 +8,12 @@ import { colors } from 'consola/utils';
8
8
  import { getProperty } from 'dot-prop';
9
9
  import { genString, genObjectFromRaw, genObjectFromValues, genObjectFromRawEntries } from 'knitwork';
10
10
  import { hash as hash$1 } from 'ohash';
11
- import { camelCase, snakeCase } from 'scule';
11
+ import { camelCase } from 'scule';
12
12
  import { defu } from 'defu';
13
13
  import { c as checkSilgiCompatibility } from '../cli/compatibility.mjs';
14
14
  import { withLeadingSlash } from 'ufo';
15
15
  import { existsSync, promises } from 'node:fs';
16
16
  import { resolveAlias as resolveAlias$1 } from 'pathe/utils';
17
- import destr from 'destr';
18
- import { klona } from 'klona';
19
17
  import { hash as hash$2 } from 'silgi/kit';
20
18
  import 'semver/functions/satisfies.js';
21
19
  import 'silgi/meta';
@@ -359,105 +357,6 @@ async function resolveSilgiModule(base, paths) {
359
357
  return resolved;
360
358
  }
361
359
 
362
- const silgiRuntimeConfig = process.env.RUNTIME_CONFIG;
363
- const envOptions = {
364
- prefix: "NITRO_",
365
- altPrefix: silgiRuntimeConfig?.nitro.envPrefix ?? process.env.NITRO_ENV_PREFIX ?? "_",
366
- silgiPrefix: "SILGI_",
367
- envExpansion: silgiRuntimeConfig?.nitro.envExpansion ?? process.env.NITRO_ENV_EXPANSION ?? false
368
- };
369
- let _sharedRuntimeConfig = _deepFreeze(
370
- applyEnv(klona(silgiRuntimeConfig ?? {}), envOptions)
371
- );
372
- function useSilgiRuntimeConfig(event, inlineRuntimeConfig = {}) {
373
- const silgi = tryUseSilgi();
374
- if (!silgi) {
375
- if (globalThis.$silgiSharedRuntimeConfig) {
376
- inlineRuntimeConfig = globalThis.$silgiSharedRuntimeConfig;
377
- if (inlineRuntimeConfig && !event) {
378
- return inlineRuntimeConfig;
379
- }
380
- }
381
- if (!silgiRuntimeConfig) {
382
- _sharedRuntimeConfig = initRuntimeConfig(envOptions, inlineRuntimeConfig);
383
- }
384
- if (!event) {
385
- return _sharedRuntimeConfig;
386
- }
387
- const runtimeConfig2 = klona(silgiRuntimeConfig);
388
- applyEnv(runtimeConfig2, envOptions);
389
- return runtimeConfig2;
390
- }
391
- if (!silgiRuntimeConfig) {
392
- _sharedRuntimeConfig = initRuntimeConfig(envOptions, inlineRuntimeConfig);
393
- }
394
- if (!event) {
395
- return _sharedRuntimeConfig;
396
- }
397
- const runtimeConfig = klona(silgiRuntimeConfig);
398
- applyEnv(runtimeConfig, envOptions);
399
- return runtimeConfig;
400
- }
401
- function initRuntimeConfig(envOptions2 = {}, inlineRuntimeConfig = {}) {
402
- const finalEnvOptions = {
403
- prefix: "NITRO_",
404
- altPrefix: inlineRuntimeConfig?.nitro?.envPrefix ?? process.env.NITRO_ENV_PREFIX ?? "_",
405
- silgiPrefix: "SILGI_",
406
- envExpansion: inlineRuntimeConfig?.nitro?.envExpansion ?? process.env.NITRO_ENV_EXPANSION ?? false,
407
- ...envOptions2
408
- };
409
- return _deepFreeze(
410
- applyEnv(klona(inlineRuntimeConfig), finalEnvOptions)
411
- );
412
- }
413
- function getEnv(key, opts, env = process.env) {
414
- const envKey = snakeCase(key).toUpperCase();
415
- return destr(
416
- env[opts.prefix + envKey] ?? env[opts.altPrefix + envKey] ?? env[opts.silgiPrefix + envKey]
417
- );
418
- }
419
- function _isObject(input) {
420
- return typeof input === "object" && !Array.isArray(input);
421
- }
422
- function applyEnv(obj, opts, parentKey = "") {
423
- for (const key in obj) {
424
- const subKey = parentKey ? `${parentKey}_${key}` : key;
425
- const envValue = getEnv(subKey, opts);
426
- if (_isObject(obj[key])) {
427
- if (_isObject(envValue)) {
428
- obj[key] = { ...obj[key], ...envValue };
429
- applyEnv(obj[key], opts, subKey);
430
- } else if (envValue === void 0) {
431
- applyEnv(obj[key], opts, subKey);
432
- } else {
433
- obj[key] = envValue ?? obj[key];
434
- }
435
- } else {
436
- obj[key] = envValue ?? obj[key];
437
- }
438
- if (opts.envExpansion && typeof obj[key] === "string") {
439
- obj[key] = _expandFromEnv(obj[key]);
440
- }
441
- }
442
- return obj;
443
- }
444
- const envExpandRx = /\{\{([^{}]*)\}\}/g;
445
- function _expandFromEnv(value, env = process.env) {
446
- return value.replace(envExpandRx, (match, key) => {
447
- return env[key] || match;
448
- });
449
- }
450
- function _deepFreeze(object) {
451
- const propNames = Object.getOwnPropertyNames(object);
452
- for (const name of propNames) {
453
- const value = object[name];
454
- if (value && typeof value === "object") {
455
- _deepFreeze(value);
456
- }
457
- }
458
- return Object.freeze(object);
459
- }
460
-
461
360
  const RELATIVE_RE = /^([^.])/;
462
361
  function relativeWithDot(from, to) {
463
362
  return relative(from, to).replace(RELATIVE_RE, "./$1") || ".";
@@ -488,7 +387,7 @@ const baseHeaderBannerComment = [
488
387
  "/* prettier-ignore */",
489
388
  "/* tslint:disable */"
490
389
  ];
491
- function addFileExtension(src) {
390
+ function processFilePath(src) {
492
391
  const silgi = useSilgiCLI();
493
392
  if (silgi.options.typescript.removeFileExtension) {
494
393
  src = src.replace(/\.ts$/, "");
@@ -627,4 +526,4 @@ function isValidIp(ip) {
627
526
  return false;
628
527
  }
629
528
 
630
- export { MODE_RE, addFileExtension, addTemplate, applyEnv, baseHeaderBannerComment, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, initRuntimeConfig, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, useSilgiRuntimeConfig, writeFile };
529
+ export { MODE_RE, addTemplate, baseHeaderBannerComment, createResolver, defineSilgiModule, defineSilgiPreset, directoryToURL, filterInPlace, genEnsureSafeVar, getAllEntries, getIpAddress, hasError, hasInstalledModule, hasSilgiModule, hash, ipAddress, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, parseServices, prettyPath, processFilePath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, serviceParseModule, toArray, tryResolveModule, useLogger, useRequest, useResponse, writeFile };
@@ -0,0 +1,10 @@
1
+ import type { EnvOptions, SilgiEvents, SilgiRuntimeConfig } from 'silgi/types';
2
+ /**
3
+ * Access 'resolved' Nuxt runtime configuration, with values updated from environment.
4
+ *
5
+ * This mirrors the runtime behavior of Nitro.
6
+ */
7
+ export declare function useSilgiRuntimeConfig<T extends SilgiRuntimeConfig>(event?: SilgiEvents, inlineRuntimeConfig?: Record<string, any>): SilgiRuntimeConfig;
8
+ export declare function initRuntimeConfig(envOptions?: EnvOptions, inlineRuntimeConfig?: Record<string, any>): Readonly<Record<string, any>>;
9
+ export declare function updateRuntimeConfig(runtimeConfig: Record<string, unknown>): void;
10
+ export declare function applyEnv(obj: Record<string, any>, opts: EnvOptions, parentKey?: string): Record<string, any>;
@@ -0,0 +1,110 @@
1
+ import defu from "defu";
2
+ import destr from "destr";
3
+ import { klona } from "klona";
4
+ import { snakeCase } from "scule";
5
+ import { tryUseSilgi, useSilgi } from "silgi/core";
6
+ const silgiRuntimeConfig = process.env.RUNTIME_CONFIG;
7
+ const envOptions = {
8
+ prefix: "NITRO_",
9
+ altPrefix: silgiRuntimeConfig?.nitro.envPrefix ?? process.env.NITRO_ENV_PREFIX ?? "_",
10
+ silgiPrefix: "SILGI_",
11
+ envExpansion: silgiRuntimeConfig?.nitro.envExpansion ?? process.env.NITRO_ENV_EXPANSION ?? false
12
+ };
13
+ let _sharedRuntimeConfig = _deepFreeze(
14
+ applyEnv(klona(silgiRuntimeConfig ?? {}), envOptions)
15
+ );
16
+ export function useSilgiRuntimeConfig(event, inlineRuntimeConfig = {}) {
17
+ const silgi = tryUseSilgi();
18
+ if (!silgi) {
19
+ if (globalThis.$silgiSharedRuntimeConfig) {
20
+ inlineRuntimeConfig = globalThis.$silgiSharedRuntimeConfig;
21
+ if (inlineRuntimeConfig && !event) {
22
+ return inlineRuntimeConfig;
23
+ }
24
+ }
25
+ if (!silgiRuntimeConfig) {
26
+ _sharedRuntimeConfig = initRuntimeConfig(envOptions, inlineRuntimeConfig);
27
+ }
28
+ if (!event) {
29
+ return _sharedRuntimeConfig;
30
+ }
31
+ const runtimeConfig2 = klona(silgiRuntimeConfig);
32
+ applyEnv(runtimeConfig2, envOptions);
33
+ return runtimeConfig2;
34
+ }
35
+ if (!silgiRuntimeConfig) {
36
+ _sharedRuntimeConfig = initRuntimeConfig(envOptions, inlineRuntimeConfig);
37
+ }
38
+ if (!event) {
39
+ return _sharedRuntimeConfig;
40
+ }
41
+ const runtimeConfig = klona(silgiRuntimeConfig);
42
+ applyEnv(runtimeConfig, envOptions);
43
+ return runtimeConfig;
44
+ }
45
+ export function initRuntimeConfig(envOptions2 = {}, inlineRuntimeConfig = {}) {
46
+ const finalEnvOptions = {
47
+ prefix: "NITRO_",
48
+ altPrefix: inlineRuntimeConfig?.nitro?.envPrefix ?? process.env.NITRO_ENV_PREFIX ?? "_",
49
+ silgiPrefix: "SILGI_",
50
+ envExpansion: inlineRuntimeConfig?.nitro?.envExpansion ?? process.env.NITRO_ENV_EXPANSION ?? false,
51
+ ...envOptions2
52
+ };
53
+ return _deepFreeze(
54
+ applyEnv(klona(inlineRuntimeConfig), finalEnvOptions)
55
+ );
56
+ }
57
+ export function updateRuntimeConfig(runtimeConfig) {
58
+ const nuxt = useSilgi();
59
+ Object.assign(nuxt.options.nitro.runtimeConfig, defu(runtimeConfig, nuxt.options.nitro.runtimeConfig));
60
+ try {
61
+ } catch {
62
+ }
63
+ }
64
+ function getEnv(key, opts, env = process.env) {
65
+ const envKey = snakeCase(key).toUpperCase();
66
+ return destr(
67
+ env[opts.prefix + envKey] ?? env[opts.altPrefix + envKey] ?? env[opts.silgiPrefix + envKey]
68
+ );
69
+ }
70
+ function _isObject(input) {
71
+ return typeof input === "object" && !Array.isArray(input);
72
+ }
73
+ export function applyEnv(obj, opts, parentKey = "") {
74
+ for (const key in obj) {
75
+ const subKey = parentKey ? `${parentKey}_${key}` : key;
76
+ const envValue = getEnv(subKey, opts);
77
+ if (_isObject(obj[key])) {
78
+ if (_isObject(envValue)) {
79
+ obj[key] = { ...obj[key], ...envValue };
80
+ applyEnv(obj[key], opts, subKey);
81
+ } else if (envValue === void 0) {
82
+ applyEnv(obj[key], opts, subKey);
83
+ } else {
84
+ obj[key] = envValue ?? obj[key];
85
+ }
86
+ } else {
87
+ obj[key] = envValue ?? obj[key];
88
+ }
89
+ if (opts.envExpansion && typeof obj[key] === "string") {
90
+ obj[key] = _expandFromEnv(obj[key]);
91
+ }
92
+ }
93
+ return obj;
94
+ }
95
+ const envExpandRx = /\{\{([^{}]*)\}\}/g;
96
+ function _expandFromEnv(value, env = process.env) {
97
+ return value.replace(envExpandRx, (match, key) => {
98
+ return env[key] || match;
99
+ });
100
+ }
101
+ function _deepFreeze(object) {
102
+ const propNames = Object.getOwnPropertyNames(object);
103
+ for (const name of propNames) {
104
+ const value = object[name];
105
+ if (value && typeof value === "object") {
106
+ _deepFreeze(value);
107
+ }
108
+ }
109
+ return Object.freeze(object);
110
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.23.9",
4
+ "version": "0.23.11",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {