@swift-rust/env 0.2.0

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/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # @swift-rust/env
2
+
3
+ Loads `.env*` files into `process.env` at server startup and provides helpers for the `SWIFT_RUST_PUBLIC_*` convention used to expose safe-to-inline values to client code.
4
+
5
+ ## Usage
6
+
7
+ ```ts
8
+ import { loadPublicEnv, publicEnvKey } from "@swift-rust/env";
9
+
10
+ loadPublicEnv();
11
+ // or
12
+ import { loadEnvFiles } from "@swift-rust/env/load";
13
+ loadEnvFiles();
14
+ ```
@@ -0,0 +1,5 @@
1
+ export type PublicEnv = Record<string, string | undefined>;
2
+ export declare const PUBLIC_PREFIX = "SWIFT_RUST_PUBLIC_";
3
+ export declare function loadPublicEnv(source?: PublicEnv): PublicEnv;
4
+ export declare function publicEnvKey(name: string): string;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAE3D,eAAO,MAAM,aAAa,uBAAuB,CAAC;AAElD,wBAAgB,aAAa,CAAC,MAAM,GAAE,SAAuB,GAAG,SAAS,CAQxE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjD"}
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ export const PUBLIC_PREFIX = "SWIFT_RUST_PUBLIC_";
2
+ export function loadPublicEnv(source = process.env) {
3
+ const out = {};
4
+ for (const [k, v] of Object.entries(source)) {
5
+ if (k.startsWith(PUBLIC_PREFIX)) {
6
+ out[stripPrefix(k)] = v;
7
+ }
8
+ }
9
+ return out;
10
+ }
11
+ export function publicEnvKey(name) {
12
+ return `${PUBLIC_PREFIX}${name.toUpperCase()}`;
13
+ }
14
+ function stripPrefix(name) {
15
+ return name.startsWith(PUBLIC_PREFIX) ? name.slice(PUBLIC_PREFIX.length) : name;
16
+ }
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAG,oBAAoB,CAAC;AAElD,MAAM,UAAU,aAAa,CAAC,SAAoB,OAAO,CAAC,GAAG;IAC3D,MAAM,GAAG,GAAc,EAAE,CAAC;IAC1B,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5C,IAAI,CAAC,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;YAChC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,GAAG,aAAa,GAAG,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;AACjD,CAAC;AAED,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAO,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAClF,CAAC"}
package/dist/load.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function loadEnvFiles(cwd?: string): void;
2
+ //# sourceMappingURL=load.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AAMA,wBAAgB,YAAY,CAAC,GAAG,GAAE,MAAsB,GAAG,IAAI,CAO9D"}
package/dist/load.js ADDED
@@ -0,0 +1,15 @@
1
+ import { existsSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { config as dotenvx } from "@dotenvx/dotenvx";
4
+ const ENV_FILES = [".env.development.local", ".env.local", ".env.development", ".env"];
5
+ export function loadEnvFiles(cwd = process.cwd()) {
6
+ for (const file of ENV_FILES) {
7
+ const path = join(cwd, file);
8
+ if (!existsSync(path))
9
+ continue;
10
+ if (process.env.NODE_ENV === "production" && file.includes(".development"))
11
+ continue;
12
+ dotenvx({ path, quiet: true });
13
+ }
14
+ }
15
+ //# sourceMappingURL=load.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load.js","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAErD,MAAM,SAAS,GAAG,CAAC,wBAAwB,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,CAAC,CAAC;AAEvF,MAAM,UAAU,YAAY,CAAC,MAAc,OAAO,CAAC,GAAG,EAAE;IACtD,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC7B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,SAAS;QAChC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,IAAI,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC;YAAE,SAAS;QACrF,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACjC,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=smoke.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smoke.test.d.ts","sourceRoot":"","sources":["../src/smoke.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import { expect, test } from "bun:test";
2
+ import * as mod from "./index";
3
+ test("package exports a default or named module", () => {
4
+ expect(mod).toBeDefined();
5
+ });
6
+ //# sourceMappingURL=smoke.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smoke.test.js","sourceRoot":"","sources":["../src/smoke.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,KAAK,GAAG,MAAM,SAAS,CAAC;AAE/B,IAAI,CAAC,2CAA2C,EAAE,GAAG,EAAE;IACrD,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;AAC5B,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@swift-rust/env",
3
+ "version": "0.2.0",
4
+ "description": "Loads .env files and exposes validated environment variables.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./load": {
15
+ "types": "./dist/load.d.ts",
16
+ "import": "./dist/load.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "scripts": {
23
+ "build": "tsc -p tsconfig.json",
24
+ "dev": "tsc -p tsconfig.json --watch",
25
+ "lint": "biome check --no-errors-on-unmatched $(pwd)/src",
26
+ "test": "bun test",
27
+ "typecheck": "tsc --noEmit",
28
+ "clean": "rm -rf dist .turbo"
29
+ },
30
+ "dependencies": {
31
+ "@dotenvx/dotenvx": "^1.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "typescript": "^6.0.0"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/swift-rust/swift-rust.git",
42
+ "directory": "packages/env"
43
+ },
44
+ "bugs": {
45
+ "url": "https://github.com/swift-rust/swift-rust/issues"
46
+ },
47
+ "homepage": "https://swift-rust.dev"
48
+ }