@fantasticfour/dotenvx-next 0.2.0 → 0.2.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.
- package/README.md +75 -3
- package/dist/chunk-CKQMccvm.cjs +28 -0
- package/dist/index.cjs +6 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +2 -1
- package/dist/next-env-compat.cjs +29 -11858
- package/dist/next-env-compat.cjs.map +1 -1
- package/dist/next-env-compat.d.cts +9 -1
- package/dist/next-env-compat.d.cts.map +1 -0
- package/dist/next-env-compat.d.mts +9 -0
- package/dist/next-env-compat.d.mts.map +1 -0
- package/dist/next-env-compat.mjs +31 -0
- package/dist/next-env-compat.mjs.map +1 -0
- package/dist/plugin.cjs +11 -8
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +6 -4
- package/dist/plugin.mjs.map +1 -1
- package/dist/turbopack-inject.cjs +95 -4
- package/dist/turbopack-inject.cjs.map +1 -0
- package/package.json +2 -1
- package/dist/turbopack-inject-BElH61NN.cjs +0 -137
- package/dist/turbopack-inject-BElH61NN.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ export async function register() {
|
|
|
23
23
|
const pool = new Pool({ connectionString: process.env.DATABASE_URL }); // undefined ✗
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
This plugin
|
|
26
|
+
This plugin decrypts env files at build time and inlines the resolved values directly into the webpack and turbopack runtime, so they are available before any user module is imported.
|
|
27
27
|
|
|
28
28
|
## Install
|
|
29
29
|
|
|
@@ -46,7 +46,77 @@ export default withDotenvx({
|
|
|
46
46
|
});
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
By default it loads `.env` from your project root.
|
|
49
|
+
By default it loads `.env` from your project root. Because values are inlined at build time, no encrypted env files need to be present in the deployed serverless bundle, and you do not need `dotenvx run` in your dev or build scripts.
|
|
50
|
+
|
|
51
|
+
### Full `@next/env` coverage with package overrides
|
|
52
|
+
|
|
53
|
+
The plugin calls `dotenvx.config()` at build time (during `next.config.ts`
|
|
54
|
+
evaluation) and inlines the resolved values into the webpack/turbopack runtime.
|
|
55
|
+
This covers the common case — module-scope `process.env` reads at import time.
|
|
56
|
+
|
|
57
|
+
However, Next.js also calls `loadEnvConfig` from `@next/env` during its own
|
|
58
|
+
**Node.js startup**, before webpack runs. The webpack `resolve.alias` set by
|
|
59
|
+
this plugin only intercepts imports inside webpack-compiled code, so those
|
|
60
|
+
startup calls are not covered by the alias alone.
|
|
61
|
+
|
|
62
|
+
To get full coverage at the Node.js package-resolution level, add an override
|
|
63
|
+
so that `require('@next/env')` resolves to this package instead:
|
|
64
|
+
|
|
65
|
+
**npm** (`package.json`):
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"overrides": {
|
|
70
|
+
"@next/env": "@fantasticfour/dotenvx-next"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**pnpm** (`package.json`):
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"pnpm": {
|
|
80
|
+
"overrides": {
|
|
81
|
+
"@next/env": "@fantasticfour/dotenvx-next"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Yarn** (`package.json`):
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"resolutions": {
|
|
92
|
+
"@next/env": "@fantasticfour/dotenvx-next"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
With this override, `require('@next/env').loadEnvConfig` returns the wrapped
|
|
98
|
+
version that calls `dotenvx.config()` first — at all call sites, including
|
|
99
|
+
Next.js's own startup code.
|
|
100
|
+
|
|
101
|
+
### Multiple environments
|
|
102
|
+
|
|
103
|
+
The `files` option accepts any list of env files. Because the plugin resolves them at build time, you are responsible for selecting the right files for the current environment. On Vercel, `VERCEL_ENV` is set during the build:
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
// next.config.ts
|
|
107
|
+
const vercelEnv = process.env.VERCEL_ENV;
|
|
108
|
+
|
|
109
|
+
export default withDotenvx(config, {
|
|
110
|
+
files:
|
|
111
|
+
vercelEnv === 'production'
|
|
112
|
+
? ['.env.base', '.env.production']
|
|
113
|
+
: vercelEnv === 'preview'
|
|
114
|
+
? ['.env.base', '.env.preview']
|
|
115
|
+
: ['.env'], // local dev
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Passing an empty array (`files: []`) skips decryption entirely for that build, which is useful if you want to handle local dev with `dotenvx run` separately rather than baking values into the dev server runtime.
|
|
50
120
|
|
|
51
121
|
### Options
|
|
52
122
|
|
|
@@ -78,7 +148,9 @@ At build time, `dotenvx.config()` decrypts the specified env files and the resol
|
|
|
78
148
|
|
|
79
149
|
**Turbopack builds:** Since turbopack bypasses webpack's plugin API, the plugin patches `fs.writeFile` to detect when compilation completes (signaled by `export-detail.json` being written), then prepends the same snippet into `[turbopack]_runtime.js`.
|
|
80
150
|
|
|
81
|
-
|
|
151
|
+
**`@next/env` webpack alias:** The plugin sets `webpack resolve.alias['@next/env']` to a compat shim that wraps `loadEnvConfig` to run `dotenvx.config()` first. This covers any import of `@next/env` inside webpack-compiled server bundles (hot-reload handlers, preview mode helpers). It does not cover Next.js's own pre-webpack startup calls — use the [npm overrides pattern](#full-nextenv-coverage-with-package-overrides) for full coverage.
|
|
152
|
+
|
|
153
|
+
**Edge runtime:** The webpack plugin detects edge runtime compilations via `compiler.options.target` and injects into `edge-runtime-webpack.js` rather than `webpack-runtime.js`. The inline snippet uses a `typeof process !== 'undefined'` guard, so it is safe in edge runtimes where `process` may be absent.
|
|
82
154
|
|
|
83
155
|
## Debugging
|
|
84
156
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
Object.defineProperty(exports, "__toESM", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function() {
|
|
26
|
+
return __toESM;
|
|
27
|
+
}
|
|
28
|
+
});
|
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_plugin = require("./plugin.cjs");
|
|
3
|
+
const require_next_env_compat = require("./next-env-compat.cjs");
|
|
4
|
+
exports.initialEnv = require_next_env_compat.initialEnv;
|
|
5
|
+
exports.loadEnvConfig = require_next_env_compat.loadEnvConfig;
|
|
6
|
+
exports.processEnv = require_next_env_compat.processEnv;
|
|
7
|
+
exports.resetEnv = require_next_env_compat.resetEnv;
|
|
8
|
+
exports.updateInitialEnv = require_next_env_compat.updateInitialEnv;
|
|
3
9
|
exports.withDotenvx = require_plugin.withDotenvx;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { DotenvxNextOptions, withDotenvx } from "./plugin.cjs";
|
|
2
|
-
|
|
2
|
+
import { Env, LoadedEnvFiles, initialEnv, loadEnvConfig, processEnv, resetEnv, updateInitialEnv } from "./next-env-compat.cjs";
|
|
3
|
+
export { type DotenvxNextOptions, type Env, type LoadedEnvFiles, initialEnv, loadEnvConfig, processEnv, resetEnv, updateInitialEnv, withDotenvx };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { DotenvxNextOptions, withDotenvx } from "./plugin.mjs";
|
|
2
|
-
|
|
2
|
+
import { Env, LoadedEnvFiles, initialEnv, loadEnvConfig, processEnv, resetEnv, updateInitialEnv } from "./next-env-compat.mjs";
|
|
3
|
+
export { type DotenvxNextOptions, type Env, type LoadedEnvFiles, initialEnv, loadEnvConfig, processEnv, resetEnv, updateInitialEnv, withDotenvx };
|
package/dist/index.mjs
CHANGED