@vite-hub/env 0.4.1 → 0.5.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.
Files changed (43) hide show
  1. package/README.md +3 -3
  2. package/dist/{access-B8lSDip4.js → access-DIErLk3w.js} +2 -3
  3. package/dist/{bridge-Cs9YfQWk.d.ts → bridge-BWwIooe0.d.ts} +0 -12
  4. package/dist/{bridge-error-BhJ77age.js → bridge-error-DEqzARPJ.js} +1 -3
  5. package/dist/bridge.d.ts +1 -1
  6. package/dist/bridge.js +9 -10
  7. package/dist/{cli-BPp7rdcA.d.ts → cli-B-LW6l_J.d.ts} +1 -6
  8. package/dist/cli-CAlHK5nn.js +1354 -0
  9. package/dist/cli.d.ts +3 -6
  10. package/dist/cli.js +1 -2
  11. package/dist/database.d.ts +2 -4
  12. package/dist/database.js +2 -5
  13. package/dist/{declarations-C5XR3aKw.d.ts → declarations-DNjO52_s.d.ts} +1 -21
  14. package/dist/{schema-C_a0WZyd.js → declarations-meg4Rmgd.js} +43 -105
  15. package/dist/{object-C7Jt4ez2.js → error-diagnostics-5BceFRdD.js} +57 -14
  16. package/dist/{error-diagnostics-DsDPsST_.js → error-diagnostics-BFzFaXcH.js} +2 -4
  17. package/dist/index.d.ts +3 -13
  18. package/dist/index.js +8 -12
  19. package/dist/internal/agent.d.ts +2 -4
  20. package/dist/internal/agent.js +3 -4
  21. package/dist/internal/connections.d.ts +2 -4
  22. package/dist/internal/connections.js +3 -4
  23. package/dist/internal/server.d.ts +2 -2
  24. package/dist/internal/server.js +1 -2
  25. package/dist/{operation-definition-nmRu_O3V.d.ts → operation-definition-CqZkx1Rm.d.ts} +8 -6
  26. package/dist/{operations-B1PFpKzy.js → operations-BftegDMd.js} +2 -3
  27. package/dist/operations.d.ts +2 -6
  28. package/dist/operations.js +7 -41
  29. package/dist/runtime/public-env.d.ts +2 -4
  30. package/dist/runtime/public-env.js +2 -3
  31. package/dist/runtime/server-env.d.ts +2 -3
  32. package/dist/runtime/server-env.js +2 -3
  33. package/dist/seal.d.ts +1 -3
  34. package/dist/seal.js +1 -2
  35. package/dist/{secret-DJd-fy5T.js → secret-VhbE53Vm.js} +1 -2
  36. package/dist/{server-CgKAEAE6.d.ts → server-CPEywepM.d.ts} +1 -12
  37. package/dist/{server-B9-8r6MZ.js → server-pTqnkM7n.js} +213 -168
  38. package/dist/server.d.ts +2 -2
  39. package/dist/server.js +1 -2
  40. package/dist/vite.d.ts +5 -17
  41. package/dist/vite.js +20 -37
  42. package/package.json +11 -10
  43. package/dist/cli-C51D6V-M.js +0 -669
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
- import { t as envErrorDiagnostics } from "./error-diagnostics-DsDPsST_.js";
2
- import { a as schemaModuleReference, i as runtimeValueSchema, n as descriptorVariable, r as env, t as parseSchema } from "./schema-C_a0WZyd.js";
3
- import { A as envValueTypeName, E as readViteHubSecret, F as stringValueSchema, I as isEnvSchemaValue, M as parseEnvValue, P as schemaContainsEnum, S as missingRequiredEnv, b as invalidEnvDeclaration, f as invariant, g as runtimeRegistryEntries, h as isRuntimeProviderEntry, m as isRuntimeLiteralEntry, p as isRuntimeEnvEntry, r as describeServerEnv, x as isAbortError, y as envSourceFailed } from "./server-B9-8r6MZ.js";
4
- import { a as VITEHUB_ENV_SERVER, c as createViteHubEnvImportAliases, d as viteHubEnvAmbientTypesPath, f as viteHubEnvDescriptionModulePath, g as viteHubEnvServerModuleTypesPath, h as viteHubEnvServerModulePath, i as VITEHUB_ENV_PUBLIC_ID, l as isServerEnvironment, m as viteHubEnvPublicModuleTypesPath, o as VITEHUB_ENV_SERVER_ID, p as viteHubEnvPublicModulePath, r as loadAllEnv, s as createNoExternalAddition, t as createEnvCliContributor, u as resolveViteHubProjectRoot } from "./cli-C51D6V-M.js";
1
+ import { A as schemaContainsEnum, E as envValueTypeName, F as envSourceFailed, I as invalidEnvDeclaration, L as isAbortError, M as isEnvSchemaValue, N as parseSchema, O as parseEnvValue, R as missingRequiredEnv, S as readViteHubSecret, f as invariant, g as runtimeRegistryEntries, h as isRuntimeProviderEntry, j as stringValueSchema, m as isRuntimeLiteralEntry, p as isRuntimeEnvEntry, r as describeServerEnv } from "./server-pTqnkM7n.js";
2
+ import { a as VITEHUB_ENV_SERVER, c as createViteHubEnvImportAliases, d as viteHubEnvAmbientTypesPath, f as viteHubEnvDescriptionModulePath, g as viteHubEnvServerModuleTypesPath, h as viteHubEnvServerModulePath, i as VITEHUB_ENV_PUBLIC_ID, l as isServerEnvironment, m as viteHubEnvPublicModuleTypesPath, o as VITEHUB_ENV_SERVER_ID, p as viteHubEnvPublicModulePath, r as loadAllEnv, s as createNoExternalAddition, t as createEnvCliContributor, u as resolveViteHubProjectRoot } from "./cli-CAlHK5nn.js";
3
+ import { i as schemaModuleReference, n as env, r as runtimeValueSchema, t as descriptorVariable } from "./declarations-meg4Rmgd.js";
4
+ import { t as envErrorDiagnostics } from "./error-diagnostics-BFzFaXcH.js";
5
5
  import { Diagnostic } from "nostics";
6
6
  import { isViteHubError } from "@vite-hub/runtime";
7
7
  import { existsSync, readFileSync } from "node:fs";
@@ -9,11 +9,12 @@ import { dirname, isAbsolute, relative, resolve, win32 } from "node:path";
9
9
  import { fileURLToPath } from "node:url";
10
10
  import { chmod, mkdir, open, readFile, rename, stat, unlink, writeFile } from "node:fs/promises";
11
11
  import { createHash, randomBytes } from "node:crypto";
12
+ import MagicString from "magic-string";
12
13
  import { loadEnv } from "vite";
13
14
  import { execFile } from "node:child_process";
14
15
  import { promisify } from "node:util";
15
16
  import { ParsedEnvSpecFunctionCall, ParsedEnvSpecKeyValuePair, ParsedEnvSpecStaticValue, parseEnvSpecDotEnvFile } from "@env-spec/parser";
16
- //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
17
+ // ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
17
18
  const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
18
19
  function normalizeWindowsPath(input = "") {
19
20
  if (!input) return input;
@@ -97,8 +98,7 @@ const dirname$1 = function(p) {
97
98
  if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
98
99
  return segments.join("/") || (isAbsolute$1(p) ? "/" : ".");
99
100
  };
100
- //#endregion
101
- //#region ../internal/src/build/paths.ts
101
+ // ../internal/src/build/paths.ts
102
102
  function resolveRuntimeModule(packageDir, modulePath) {
103
103
  const distFile = resolve$1(packageDir, "dist", `${modulePath}.js`);
104
104
  return existsSync(distFile) ? distFile : resolve$1(packageDir, "src", `${modulePath}.ts`);
@@ -125,16 +125,14 @@ function findPackageDir(file) {
125
125
  function ownModule(importMetaUrl, modulePath) {
126
126
  return resolveRuntimeModule(findPackageDir(fileURLToPath(importMetaUrl)), modulePath);
127
127
  }
128
- //#endregion
129
- //#region ../internal/src/definition-catalog.ts
128
+ // ../internal/src/definition-catalog.ts
130
129
  /** `writeFileIfChangedSync` for async callers. */
131
130
  async function writeFileIfChanged(file, contents) {
132
131
  if (await readFile(file, "utf8").catch(() => void 0) === contents) return;
133
132
  await mkdir(resolve$1(file, ".."), { recursive: true });
134
133
  await writeFile(file, contents, "utf8");
135
134
  }
136
- //#endregion
137
- //#region src/core/diagnostics.ts
135
+ // src/core/diagnostics.ts
138
136
  function shouldTraceDiagnostics(option) {
139
137
  return option === "trace" || process.env.VITEHUB_ENV_TRACE === "true";
140
138
  }
@@ -152,8 +150,7 @@ function formatDiagnostics(entries, option = "summary") {
152
150
  entry.masked ? " value: ********" : void 0
153
151
  ].filter(Boolean))].join("\n");
154
152
  }
155
- //#endregion
156
- //#region src/core/resolve.ts
153
+ // src/core/resolve.ts
157
154
  const execFileAsync = promisify(execFile);
158
155
  const envOptionKeys = /* @__PURE__ */ new Set([
159
156
  "define",
@@ -458,12 +455,7 @@ function parseRuntimeDefault(schema, value, path) {
458
455
  if (!result.success) throw envErrorDiagnostics.ENV_R0023({ message: `[vitehub] Invalid default for ${path}: ${result.message}` });
459
456
  return schema.kind === "json" ? value : result.data;
460
457
  }
461
- /** The default prefix of canonical variable names. */
462
458
  const defaultEnvPrefix = "VITEHUB_";
463
- /**
464
- * The canonical variable name of a declaration path: the prefix plus the path in upper snake case.
465
- * `env.server.cliproxy.apiKey` becomes `VITEHUB_CLIPROXY_API_KEY`. `false` disables canonical names.
466
- */
467
459
  function canonicalEnvName(path, prefix = defaultEnvPrefix) {
468
460
  return prefix === false ? void 0 : `${prefix}${pathToEnvName(path)}`;
469
461
  }
@@ -643,8 +635,7 @@ function readPath(value, path) {
643
635
  return current[segment];
644
636
  }, value);
645
637
  }
646
- //#endregion
647
- //#region src/env-schema/profile.ts
638
+ // src/env-schema/profile.ts
648
639
  function fail$1(context, reason) {
649
640
  throw envErrorDiagnostics.ENV_B0006({ message: `${context.file}:${context.line}${context.key ? ` (${context.key})` : ""}: ${reason}` });
650
641
  }
@@ -936,8 +927,7 @@ function parseEnvSchema(source, filename) {
936
927
  return field;
937
928
  });
938
929
  }
939
- //#endregion
940
- //#region src/env-schema/importer.ts
930
+ // src/env-schema/importer.ts
941
931
  function fail(field, reason) {
942
932
  const path = field ? `${field.source.file}:${field.source.line} (${field.key})` : "envSchema";
943
933
  throw invalidEnvDeclaration(path, `${path}: ${reason}`);
@@ -1057,8 +1047,7 @@ function envSchema(file, options = {}) {
1057
1047
  server: serverConfig(server)
1058
1048
  };
1059
1049
  }
1060
- //#endregion
1061
- //#region src/vite.ts
1050
+ // src/vite.ts
1062
1051
  const ENV_VITE_PLUGIN_NAME = "@vite-hub/env/vite";
1063
1052
  const envNoExternal = createNoExternalAddition("@vite-hub/env");
1064
1053
  const ENV_PUBLIC_ID = VITEHUB_ENV_PUBLIC_ID;
@@ -1345,7 +1334,13 @@ function hubEnv(options = {}) {
1345
1334
  filter: { code: "/* @vitehub-env */" },
1346
1335
  handler(code) {
1347
1336
  if (!code.includes("/* @vitehub-env */") || !code.includes(ENV_SERVER_ID)) return;
1348
- return code.replace(/\/\* @vite-ignore \*\/\s*\/\* @vitehub-env \*\/\s*[\w$]+/g, JSON.stringify(ENV_SERVER_ID));
1337
+ const output = new MagicString(code);
1338
+ output.replaceAll(/\/\* @vite-ignore \*\/\s*\/\* @vitehub-env \*\/\s*[\w$]+/g, JSON.stringify(ENV_SERVER_ID));
1339
+ if (!output.hasChanged()) return;
1340
+ return {
1341
+ code: output.toString(),
1342
+ map: output.generateMap({ hires: "boundary" })
1343
+ };
1349
1344
  }
1350
1345
  }
1351
1346
  };
@@ -1391,7 +1386,6 @@ function resolveProviderModules(providers, root) {
1391
1386
  function assertConfiguredProviders(registry, providers) {
1392
1387
  for (const { entry, path } of runtimeRegistryEntries(registry)) if (isRuntimeProviderEntry(entry) && !Object.hasOwn(providers, entry.source.provider)) throw envErrorDiagnostics.ENV_B0005({ message: `[vitehub] ${path} references Env provider ${JSON.stringify(entry.source.provider)}, but hubEnv({ providers }) does not configure it.` });
1393
1388
  }
1394
- /** Map each `env.schemaFrom()` specifier to the module the server build imports. Relative specifiers resolve from the project root. */
1395
1389
  function resolveSchemaModules(registry, root) {
1396
1390
  const output = {};
1397
1391
  for (const { entry } of runtimeRegistryEntries(registry)) {
@@ -1401,7 +1395,6 @@ function resolveSchemaModules(registry, root) {
1401
1395
  }
1402
1396
  return output;
1403
1397
  }
1404
- /** A type-only import specifier for a schema module, relative to the generated declaration file. */
1405
1398
  function schemaModuleTypeSpecifier(specifier, outputPath) {
1406
1399
  const typed = specifier.replace(/\.([cm]?)tsx?$/, ".$1js");
1407
1400
  if (!isAbsolute(typed)) return typed;
@@ -1409,10 +1402,6 @@ function schemaModuleTypeSpecifier(specifier, outputPath) {
1409
1402
  return target.startsWith(".") ? target : `./${target}`;
1410
1403
  }
1411
1404
  const generatedSecretPattern = /^[0-9a-f]{64}$/;
1412
- /**
1413
- * Give the development server a root secret when none is configured, so `deriveSecret()` works without setup.
1414
- * The secret is kept in `.vitehub/env/secret` with mode 0600 and survives restarts. Builds never generate one.
1415
- */
1416
1405
  async function resolveDevelopmentSecret(projectRoot, loadedEnv) {
1417
1406
  const existing = developmentSecretLocks.get(projectRoot);
1418
1407
  if (existing) return existing;
@@ -1630,10 +1619,6 @@ function createServerEnvModuleTypes(serverRegistry, runtimeImports, schemaModule
1630
1619
  function envAccessorTypesPath(root) {
1631
1620
  return resolve(root, ".vitehub", "types", "env-accessors.d.ts");
1632
1621
  }
1633
- /**
1634
- * Types `useServerEnv()` and `usePublicEnv()` of the Env root with the declared fields. The file is a module, so its
1635
- * `declare module` blocks augment the package instead of replacing it.
1636
- */
1637
1622
  function createEnvAccessorTypes(publicTypes, serverRegistry, runtimeImports, schemaModules, outputPath) {
1638
1623
  const schemaTypes = {
1639
1624
  modules: schemaModules,
@@ -1753,7 +1738,6 @@ function serverTypeFor(value, indent, schemaTypes, secretType) {
1753
1738
  const prefix = " ".repeat(indent);
1754
1739
  return `{\n${fields.join("\n")}\n${prefix}}`;
1755
1740
  }
1756
- /** Infer the output from optional Standard Schema type metadata, falling back to unknown when it is absent. */
1757
1741
  function schemaOutputType(specifier, exportName, schemaTypes) {
1758
1742
  const module = schemaModuleTypeSpecifier(schemaTypes.modules[specifier] ?? specifier, schemaTypes.outputPath);
1759
1743
  return `typeof import(${JSON.stringify(module)})[${JSON.stringify(exportName)}] extends { readonly "~standard": { readonly types?: { readonly output: infer Output } | undefined } } ? Output : unknown`;
@@ -1771,5 +1755,4 @@ function literalType(value) {
1771
1755
  default: return "unknown";
1772
1756
  }
1773
1757
  }
1774
- //#endregion
1775
1758
  export { ENV_PUBLIC_ID, ENV_SERVER_ID, ENV_VITE_PLUGIN_NAME, createEnvImportAliases, createEnvTypeScriptPaths, createEnvTypes, createRuntimeRegistry as createRuntimeEnvRegistry, env, envSchema, hubEnv };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-hub/env",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "Safe build and runtime environment variables for ViteHub.",
5
5
  "keywords": [
6
6
  "env",
@@ -96,29 +96,30 @@
96
96
  "./package.json": "./package.json"
97
97
  },
98
98
  "dependencies": {
99
- "@env-spec/parser": "0.6.2",
100
- "@vite-hub/runtime": "0.4.1",
99
+ "@env-spec/parser": "0.6.3",
100
+ "@vite-hub/runtime": "0.5.1",
101
+ "magic-string": "^1.4.5",
101
102
  "nostics": "1.4.0",
102
103
  "valibot": "^1.5.0"
103
104
  },
104
105
  "devDependencies": {
105
- "@types/node": "^24.19.1",
106
+ "@types/node": "^24.19.2",
106
107
  "zod": "^4.6.7",
107
108
  "@vite-hub/internal": "0.0.1",
108
109
  "publint": "^0.3.25",
109
110
  "typescript": "^6.0.3",
110
- "vite": "^8.2.2",
111
- "vite-plus": "^0.3.3",
112
- "vitest": "^4.1.11",
113
- "drizzle-orm": "1.0.0-rc.5",
111
+ "vite": "^8.3.8",
112
+ "vite-plus": "^1.7.0",
113
+ "vitest": "5.1.0",
114
+ "drizzle-orm": "1.0.0-rc.6",
114
115
  "@libsql/client": "^0.18.0",
115
116
  "miniflare": "4.20260730.0",
116
117
  "nitro": "^3.0.261103-rc"
117
118
  },
118
119
  "peerDependencies": {
119
120
  "vite": ">=8.0.0",
120
- "drizzle-orm": "1.0.0-rc.5 || ^1.0.0",
121
- "@vite-hub/agent": "0.4.1",
121
+ "drizzle-orm": "1.0.0-rc.5 || 1.0.0-rc.6 || ^1.0.0",
122
+ "@vite-hub/agent": "0.5.1",
122
123
  "nitro": "3.0.261102-rc || ^3.0.261103-rc"
123
124
  },
124
125
  "peerDependenciesMeta": {