silgi 0.9.6 → 0.9.8

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.9.6";
1
+ const version = "0.9.8";
2
2
  const devDependencies = {
3
3
  "@antfu/eslint-config": "^4.3.0",
4
4
  "@nuxt/kit": "^3.15.4",
@@ -859,7 +859,20 @@ async function nitroFramework(silgi, skip = false) {
859
859
  packageImport: "silgi/runtime/internal/nitro",
860
860
  path: join(runtimeDir, "internal/nitro")
861
861
  });
862
- silgi.hook("prepare:core.ts", (_data) => {
862
+ silgi.hook("prepare:createDTSFramework", (data) => {
863
+ data.importItems["silgi/types"] = {
864
+ import: [
865
+ { name: "NitroRuntimeConfig", type: true }
866
+ ],
867
+ from: "nitropack/types"
868
+ };
869
+ data.customContent?.push(
870
+ "",
871
+ 'declare module "silgi/types" {',
872
+ " interface SilgiRuntimeOptions extends NitroRuntimeConfig {}",
873
+ "}",
874
+ ""
875
+ );
863
876
  });
864
877
  if (silgi.options.imports !== false) {
865
878
  silgi.options.imports.presets ??= [];
@@ -71,6 +71,13 @@ interface Resolver {
71
71
  declare function createResolver(base: string | URL): Resolver;
72
72
  declare function resolveSilgiModule(base: string, paths: string[]): Promise<string[]>;
73
73
 
74
+ /**
75
+ * Access 'resolved' Nuxt runtime configuration, with values updated from environment.
76
+ *
77
+ * This mirrors the runtime behavior of Nitro.
78
+ */
79
+ declare function useSilgiRuntimeConfig(): Record<string, any>;
80
+
74
81
  /**
75
82
  * Renders given template during build into the virtual file system (and optionally to disk in the project `buildDir`)
76
83
  */
@@ -100,4 +107,4 @@ declare const MODE_RE: RegExp;
100
107
  declare function hasSilgiModule(moduleKey: string, silgi?: SilgiCLI): boolean;
101
108
  declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolean;
102
109
 
103
- export { MODE_RE, addTemplate, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, hasInstalledModule, hasSilgiModule, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, writeFile };
110
+ export { MODE_RE, addTemplate, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, hasInstalledModule, hasSilgiModule, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useSilgiRuntimeConfig, writeFile };
@@ -71,6 +71,13 @@ interface Resolver {
71
71
  declare function createResolver(base: string | URL): Resolver;
72
72
  declare function resolveSilgiModule(base: string, paths: string[]): Promise<string[]>;
73
73
 
74
+ /**
75
+ * Access 'resolved' Nuxt runtime configuration, with values updated from environment.
76
+ *
77
+ * This mirrors the runtime behavior of Nitro.
78
+ */
79
+ declare function useSilgiRuntimeConfig(): Record<string, any>;
80
+
74
81
  /**
75
82
  * Renders given template during build into the virtual file system (and optionally to disk in the project `buildDir`)
76
83
  */
@@ -100,4 +107,4 @@ declare const MODE_RE: RegExp;
100
107
  declare function hasSilgiModule(moduleKey: string, silgi?: SilgiCLI): boolean;
101
108
  declare function hasInstalledModule(moduleKey: string, silgi?: SilgiCLI): boolean;
102
109
 
103
- export { MODE_RE, addTemplate, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, hasInstalledModule, hasSilgiModule, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, writeFile };
110
+ export { MODE_RE, addTemplate, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, hasInstalledModule, hasSilgiModule, isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useSilgiRuntimeConfig, writeFile };
@@ -4,12 +4,16 @@ import consola, { consola as consola$1 } from 'consola';
4
4
  import { relative, resolve, dirname, normalize, isAbsolute, join, parse, basename } from 'pathe';
5
5
  import { colors } from 'consola/utils';
6
6
  import { getProperty } from 'dot-prop';
7
- import { useSilgi, tryUseSilgiCLI, useSilgiCLI } from 'silgi/core';
7
+ import { useSilgi, tryUseSilgiCLI, useSilgiCLI, tryUseSilgi } from 'silgi/core';
8
8
  import { defu } from 'defu';
9
9
  import { c as checkSilgiCompatibility } from '../cli/compatibility.mjs';
10
10
  import { existsSync, promises } from 'node:fs';
11
11
  import { fileURLToPath } from 'node:url';
12
12
  import { resolveAlias as resolveAlias$1 } from 'pathe/utils';
13
+ import process$1 from 'node:process';
14
+ import destr from 'destr';
15
+ import { klona } from 'klona';
16
+ import { snakeCase } from 'scule';
13
17
  import { hash } from 'ohash';
14
18
  import 'semver/functions/satisfies.js';
15
19
  import 'silgi/meta';
@@ -239,6 +243,57 @@ async function resolveSilgiModule(base, paths) {
239
243
  return resolved;
240
244
  }
241
245
 
246
+ function useSilgiRuntimeConfig() {
247
+ const silgi = tryUseSilgi();
248
+ if (!silgi) {
249
+ return {};
250
+ }
251
+ return applyEnv(klona(silgi.options.runtimeConfig), {
252
+ prefix: "NITRO_",
253
+ altPrefix: "NUXT_",
254
+ silgiPrefix: "SILGI_",
255
+ // TODO: add more prefixes ecosystem-wide
256
+ envExpansion: silgi.options.experimental?.envExpansion ?? !!process$1.env.NITRO_ENV_EXPANSION
257
+ });
258
+ }
259
+ function getEnv(key, opts, env = process$1.env) {
260
+ const envKey = snakeCase(key).toUpperCase();
261
+ return destr(
262
+ env[opts.prefix + envKey] ?? env[opts.altPrefix + envKey] ?? env[opts.silgiPrefix + envKey]
263
+ );
264
+ }
265
+ function _isObject(input) {
266
+ return typeof input === "object" && !Array.isArray(input);
267
+ }
268
+ function applyEnv(obj, opts, parentKey = "") {
269
+ for (const key in obj) {
270
+ const subKey = parentKey ? `${parentKey}_${key}` : key;
271
+ const envValue = getEnv(subKey, opts);
272
+ if (_isObject(obj[key])) {
273
+ if (_isObject(envValue)) {
274
+ obj[key] = { ...obj[key], ...envValue };
275
+ applyEnv(obj[key], opts, subKey);
276
+ } else if (envValue === void 0) {
277
+ applyEnv(obj[key], opts, subKey);
278
+ } else {
279
+ obj[key] = envValue ?? obj[key];
280
+ }
281
+ } else {
282
+ obj[key] = envValue ?? obj[key];
283
+ }
284
+ if (opts.envExpansion && typeof obj[key] === "string") {
285
+ obj[key] = _expandFromEnv(obj[key]);
286
+ }
287
+ }
288
+ return obj;
289
+ }
290
+ const envExpandRx = /\{\{([^{}]*)\}\}/g;
291
+ function _expandFromEnv(value, env = process$1.env) {
292
+ return value.replace(envExpandRx, (match, key) => {
293
+ return env[key] || match;
294
+ });
295
+ }
296
+
242
297
  const RELATIVE_RE = /^([^.])/;
243
298
  function relativeWithDot(from, to) {
244
299
  return relative(from, to).replace(RELATIVE_RE, "./$1") || ".";
@@ -305,4 +360,4 @@ function normalizeTemplate(template, buildDir) {
305
360
  return template;
306
361
  }
307
362
 
308
- export { MODE_RE, addTemplate, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, hasInstalledModule, hasSilgiModule, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, writeFile };
363
+ export { MODE_RE, addTemplate, createResolver, defineSilgiModule, defineSilgiPreset, filterInPlace, hasInstalledModule, hasSilgiModule, isDirectory$1 as isDirectory, isH3, isNitro, isNuxt, normalizeTemplate, prettyPath, relativeWithDot, resolveAlias, resolvePath, resolveSilgiModule, resolveSilgiPath, toArray, tryResolveModule, useLogger, useSilgiRuntimeConfig, writeFile };
@@ -1,4 +1,4 @@
1
- const version = "0.9.6";
1
+ const version = "0.9.8";
2
2
  const devDependencies = {
3
3
  "@antfu/eslint-config": "^4.3.0",
4
4
  "@nuxt/kit": "^3.15.4",
@@ -1,4 +1,4 @@
1
- const version = "0.9.6";
1
+ const version = "0.9.8";
2
2
  const devDependencies = {
3
3
  "@antfu/eslint-config": "^4.3.0",
4
4
  "@nuxt/kit": "^3.15.4",
@@ -944,6 +944,9 @@ type CaptureError = (error: Error, context: CapturedErrorContext) => void;
944
944
  interface SilgiOptions {
945
945
  consolaOptions?: Partial<ConsolaOptions>;
946
946
  present: PresetNameInput;
947
+ runtimeConfig: SilgiRuntimeOptions & {
948
+ [key: string]: any;
949
+ };
947
950
  /**
948
951
  * Set to `true` to enable debug mode.
949
952
  *
@@ -944,6 +944,9 @@ type CaptureError = (error: Error, context: CapturedErrorContext) => void;
944
944
  interface SilgiOptions {
945
945
  consolaOptions?: Partial<ConsolaOptions>;
946
946
  present: PresetNameInput;
947
+ runtimeConfig: SilgiRuntimeOptions & {
948
+ [key: string]: any;
949
+ };
947
950
  /**
948
951
  * Set to `true` to enable debug mode.
949
952
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.9.6",
4
+ "version": "0.9.8",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {
@@ -120,6 +120,7 @@
120
120
  "compatx": "^0.1.8",
121
121
  "consola": "^3.4.0",
122
122
  "defu": "^6.1.4",
123
+ "destr": "^2.0.3",
123
124
  "dev-jiti": "^2.4.2",
124
125
  "dot-prop": "^9.0.0",
125
126
  "dotenv": "^16.4.7",
@@ -1 +0,0 @@
1
- export { useSilgiNitroRuntimeConfig } from './useRuntimeConfig';
@@ -1 +0,0 @@
1
- export { useSilgiNitroRuntimeConfig } from "./useRuntimeConfig.mjs";
@@ -1 +0,0 @@
1
- export declare function useSilgiNitroRuntimeConfig(): any;
@@ -1,7 +0,0 @@
1
- import { useRuntimeConfig } from "nitropack/runtime/internal/config";
2
- export function useSilgiNitroRuntimeConfig() {
3
- if (globalThis.$silgiStatus === "prepare" || globalThis.$silgiStatus === "install" || globalThis.$silgiStatus === "run") {
4
- return;
5
- }
6
- return useRuntimeConfig();
7
- }