@dotenvage/node 0.1.5
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 +337 -0
- package/bin/dotenvage-next.js +18 -0
- package/bin/dotenvage.js +265 -0
- package/dotenvage-napi.darwin-arm64.node +0 -0
- package/dotenvage-napi.darwin-x64.node +0 -0
- package/dotenvage-napi.linux-arm64-musl.node +0 -0
- package/examples/app-config.ts +129 -0
- package/examples/auto-encrypt.ts +132 -0
- package/examples/basic.js +127 -0
- package/examples/encrypt-decrypt.ts +56 -0
- package/examples/load-env.ts +51 -0
- package/examples/nextjs-config.ts +132 -0
- package/examples/tsconfig.json +22 -0
- package/index.d.ts +57 -0
- package/index.js +582 -0
- package/nextjs/README.md +271 -0
- package/nextjs/config.d.ts +32 -0
- package/nextjs/config.mjs +59 -0
- package/nextjs/loader.d.ts +22 -0
- package/nextjs/loader.mjs +117 -0
- package/nextjs/preinit.d.ts +13 -0
- package/nextjs/preinit.mjs +106 -0
- package/nextjs/wrapper.mjs +87 -0
- package/package.json +91 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Wrapper script for Next.js that loads encrypted environment variables
|
|
4
|
+
* before Next.js starts.
|
|
5
|
+
*
|
|
6
|
+
* IMPORTANT: This works because @next/env does NOT overwrite existing process.env values.
|
|
7
|
+
* Flow:
|
|
8
|
+
* 1. This script loads encrypted .env files and decrypts them into process.env
|
|
9
|
+
* 2. Next.js starts and @next/env runs to load .env files
|
|
10
|
+
* 3. @next/env sees existing values in process.env and preserves them (doesn't overwrite)
|
|
11
|
+
* 4. Result: Decrypted values from dotenvage are used, not encrypted values from .env files
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* node @dotenvage/node/nextjs/wrapper.mjs dev
|
|
15
|
+
* node @dotenvage/node/nextjs/wrapper.mjs build
|
|
16
|
+
*
|
|
17
|
+
* Or via package.json scripts:
|
|
18
|
+
* "dev": "node @dotenvage/node/nextjs/wrapper.mjs dev"
|
|
19
|
+
* "build": "node @dotenvage/node/nextjs/wrapper.mjs build"
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
// Load encrypted environment variables BEFORE Next.js starts
|
|
23
|
+
try {
|
|
24
|
+
// Load env vars first (synchronously via side-effect)
|
|
25
|
+
await import("./preinit.mjs");
|
|
26
|
+
|
|
27
|
+
// Now import Node.js modules
|
|
28
|
+
const childProcess = await import("child_process");
|
|
29
|
+
const fsModule = await import("fs/promises");
|
|
30
|
+
const pathModule = await import("path");
|
|
31
|
+
|
|
32
|
+
// Detect package manager by checking for lock files
|
|
33
|
+
const cwd = process.cwd();
|
|
34
|
+
const packageManager = await (async () => {
|
|
35
|
+
try {
|
|
36
|
+
const pnpmLock = await fsModule
|
|
37
|
+
.access(pathModule.join(cwd, "pnpm-lock.yaml"))
|
|
38
|
+
.then(() => true)
|
|
39
|
+
.catch(() => false);
|
|
40
|
+
if (pnpmLock) return "pnpm";
|
|
41
|
+
|
|
42
|
+
const yarnLock = await fsModule
|
|
43
|
+
.access(pathModule.join(cwd, "yarn.lock"))
|
|
44
|
+
.then(() => true)
|
|
45
|
+
.catch(() => false);
|
|
46
|
+
if (yarnLock) return "yarn";
|
|
47
|
+
|
|
48
|
+
const packageLock = await fsModule
|
|
49
|
+
.access(pathModule.join(cwd, "package-lock.json"))
|
|
50
|
+
.then(() => true)
|
|
51
|
+
.catch(() => false);
|
|
52
|
+
if (packageLock) return "npm";
|
|
53
|
+
|
|
54
|
+
// Default to npm if no lock file found
|
|
55
|
+
return "npm";
|
|
56
|
+
} catch {
|
|
57
|
+
return "npm";
|
|
58
|
+
}
|
|
59
|
+
})();
|
|
60
|
+
|
|
61
|
+
// Forward all command-line arguments to Next.js
|
|
62
|
+
const args = process.argv.slice(2);
|
|
63
|
+
|
|
64
|
+
// Use package manager exec to ensure we use the correct Next.js binary
|
|
65
|
+
// This works with all package managers and handles path resolution automatically
|
|
66
|
+
const child = childProcess.spawn(
|
|
67
|
+
packageManager,
|
|
68
|
+
["exec", "next", ...args],
|
|
69
|
+
{
|
|
70
|
+
stdio: "inherit",
|
|
71
|
+
cwd: cwd,
|
|
72
|
+
env: process.env, // Pass through all environment variables (including decrypted ones)
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
child.on("exit", (code) => {
|
|
77
|
+
process.exit(code || 0);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
child.on("error", (error) => {
|
|
81
|
+
console.error("Failed to start Next.js:", error);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
});
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.error("Failed to load environment variables:", error);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dotenvage/node",
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"description": "Node.js bindings for dotenvage - Dotenv with age encryption",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"dotenvage": "./bin/dotenvage.js",
|
|
9
|
+
"dotenvage-next": "./bin/dotenvage-next.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"index.js",
|
|
13
|
+
"index.d.ts",
|
|
14
|
+
"bin/",
|
|
15
|
+
"*.node",
|
|
16
|
+
"README.md",
|
|
17
|
+
"examples/",
|
|
18
|
+
"nextjs/"
|
|
19
|
+
],
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./index.d.ts",
|
|
23
|
+
"default": "./index.js"
|
|
24
|
+
},
|
|
25
|
+
"./nextjs": {
|
|
26
|
+
"types": "./nextjs/loader.d.ts",
|
|
27
|
+
"default": "./nextjs/loader.mjs"
|
|
28
|
+
},
|
|
29
|
+
"./nextjs/preinit": {
|
|
30
|
+
"types": "./nextjs/preinit.d.ts",
|
|
31
|
+
"default": "./nextjs/preinit.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./nextjs/config": {
|
|
34
|
+
"types": "./nextjs/config.d.ts",
|
|
35
|
+
"default": "./nextjs/config.mjs"
|
|
36
|
+
},
|
|
37
|
+
"./package.json": "./package.json"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"dotenv",
|
|
41
|
+
"age",
|
|
42
|
+
"encryption",
|
|
43
|
+
"secrets",
|
|
44
|
+
"environment",
|
|
45
|
+
"env",
|
|
46
|
+
"napi",
|
|
47
|
+
"nodejs"
|
|
48
|
+
],
|
|
49
|
+
"author": "Jacobus Geluk <jacobus@dataroad.com>",
|
|
50
|
+
"license": "CC-BY-SA-4.0",
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "https://github.com/dataroadinc/dotenvage.git",
|
|
54
|
+
"directory": "npm"
|
|
55
|
+
},
|
|
56
|
+
"homepage": "https://github.com/dataroadinc/dotenvage#readme",
|
|
57
|
+
"bugs": {
|
|
58
|
+
"url": "https://github.com/dataroadinc/dotenvage/issues"
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": ">=18.0.0"
|
|
62
|
+
},
|
|
63
|
+
"napi": {
|
|
64
|
+
"binaryName": "dotenvage-napi",
|
|
65
|
+
"targets": [
|
|
66
|
+
"x86_64-unknown-linux-gnu",
|
|
67
|
+
"x86_64-unknown-linux-musl",
|
|
68
|
+
"aarch64-unknown-linux-gnu",
|
|
69
|
+
"aarch64-unknown-linux-musl",
|
|
70
|
+
"x86_64-apple-darwin",
|
|
71
|
+
"aarch64-apple-darwin",
|
|
72
|
+
"x86_64-pc-windows-msvc",
|
|
73
|
+
"aarch64-pc-windows-msvc",
|
|
74
|
+
"i686-pc-windows-msvc"
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
"devDependencies": {
|
|
78
|
+
"@napi-rs/cli": "^3.5.1",
|
|
79
|
+
"@types/node": "^20.0.0",
|
|
80
|
+
"typescript": "^5.0.0"
|
|
81
|
+
},
|
|
82
|
+
"scripts": {
|
|
83
|
+
"build": "napi build --manifest-path ./dotenvage-napi/Cargo.toml --output-dir . --platform --release --target $(./scripts/get-current-target.sh)",
|
|
84
|
+
"build:debug": "napi build --manifest-path ./dotenvage-napi/Cargo.toml --output-dir . --platform --target $(./scripts/get-current-target.sh)",
|
|
85
|
+
"build:all": "./scripts/build-all.sh",
|
|
86
|
+
"test": "node --test __tests__/*.test.js",
|
|
87
|
+
"test:unit": "node --test __tests__/basic.test.js __tests__/secret-manager.test.js __tests__/env-loader.test.js",
|
|
88
|
+
"test:integration": "node --test __tests__/integration.test.js",
|
|
89
|
+
"test:all": "npm run test"
|
|
90
|
+
}
|
|
91
|
+
}
|