@fantasticfour/dotenvx-next 0.4.0 → 0.4.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/dist/next-env-compat.cjs +4 -4
- package/dist/next-env-compat.cjs.map +1 -1
- package/dist/next-env-compat.d.cts +21 -5
- package/dist/next-env-compat.d.cts.map +1 -1
- package/dist/next-env-compat.d.mts +21 -5
- package/dist/next-env-compat.d.mts.map +1 -1
- package/dist/next-env-compat.mjs +1 -2
- package/dist/next-env-compat.mjs.map +1 -1
- package/dist/plugin.cjs +6 -7
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts +19 -6
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts +19 -6
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +4 -5
- package/dist/plugin.mjs.map +1 -1
- package/dist/{rolldown-runtime-D6vf50IK.cjs → rolldown-runtime-CmQyd0Gu.cjs} +2 -3
- package/dist/rolldown-runtime-D3PmRqjj.mjs +4 -0
- package/dist/turbopack-inject.cjs +3 -4
- package/dist/turbopack-inject.cjs.map +1 -1
- package/dist/turbopack-inject.d.cts +3 -6
- package/dist/turbopack-inject.d.cts.map +1 -1
- package/dist/turbopack-inject.d.mts +3 -6
- package/dist/turbopack-inject.d.mts.map +1 -1
- package/dist/turbopack-inject.mjs +1 -2
- package/dist/webpack-plugin.cjs +2 -3
- package/dist/webpack-plugin.cjs.map +1 -1
- package/dist/webpack-plugin.d.cts +3 -5
- package/dist/webpack-plugin.d.cts.map +1 -1
- package/dist/webpack-plugin.d.mts +3 -5
- package/dist/webpack-plugin.d.mts.map +1 -1
- package/dist/webpack-plugin.mjs +3 -4
- package/dist/webpack-plugin.mjs.map +1 -1
- package/package.json +11 -15
- package/dist/rolldown-runtime-BdkLduGY.mjs +0 -5
package/dist/next-env-compat.cjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_rolldown_runtime = require("./rolldown-runtime-
|
|
2
|
+
const require_rolldown_runtime = require("./rolldown-runtime-CmQyd0Gu.cjs");
|
|
3
|
+
let node_module = require("node:module");
|
|
3
4
|
let _dotenvx_dotenvx = require("@dotenvx/dotenvx");
|
|
4
5
|
_dotenvx_dotenvx = require_rolldown_runtime.__toESM(_dotenvx_dotenvx, 1);
|
|
5
|
-
|
|
6
|
+
// src/next-env-compat.ts
|
|
6
7
|
/**
|
|
7
8
|
* Drop-in replacement for @next/env that wraps loadEnvConfig to also call
|
|
8
9
|
* dotenvx.config() so dotenvx-decrypted values are present in process.env
|
|
@@ -22,12 +23,11 @@ _dotenvx_dotenvx = require_rolldown_runtime.__toESM(_dotenvx_dotenvx, 1);
|
|
|
22
23
|
*
|
|
23
24
|
* @next/env is CJS-only, so createRequire is used to load it from ESM.
|
|
24
25
|
*/
|
|
25
|
-
const { loadEnvConfig: originalLoadEnvConfig, initialEnv, updateInitialEnv, processEnv, resetEnv } = (0,
|
|
26
|
+
const { loadEnvConfig: originalLoadEnvConfig, initialEnv, updateInitialEnv, processEnv, resetEnv } = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("@next/env");
|
|
26
27
|
function loadEnvConfig(...args) {
|
|
27
28
|
_dotenvx_dotenvx.default.config({ quiet: true });
|
|
28
29
|
return originalLoadEnvConfig(...args);
|
|
29
30
|
}
|
|
30
|
-
//#endregion
|
|
31
31
|
exports.initialEnv = initialEnv;
|
|
32
32
|
exports.loadEnvConfig = loadEnvConfig;
|
|
33
33
|
exports.processEnv = processEnv;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-env-compat.cjs","names":[],"sources":["../src/next-env-compat.ts"],"sourcesContent":["/**\n * Drop-in replacement for @next/env that wraps loadEnvConfig to also call\n * dotenvx.config() so dotenvx-decrypted values are present in process.env\n * whenever loadEnvConfig is invoked.\n *\n * Two coverage levels:\n *\n * 1. Webpack alias (partial): plugin.ts sets webpack resolve.alias['@next/env']\n * to this module. Intercepts imports of @next/env INSIDE webpack-bundled code\n * (hot-reload handlers, preview mode helpers in the server bundle).\n * Does NOT cover Next.js's own Node.js startup calls to loadEnvConfig, which\n * happen before webpack runs.\n *\n * 2. npm overrides (full): users add \"@next/env\" → \"@fantasticfour/dotenvx-next\"\n * in package.json overrides/resolutions. Node.js resolves require('@next/env')\n * to this package's CJS entry, which re-exports loadEnvConfig, covering startup.\n *\n * @next/env is CJS-only, so createRequire is used to load it from ESM.\n */\n\nimport { createRequire } from 'node:module';\nimport dotenvx from '@dotenvx/dotenvx';\nimport type {\n Env,\n LoadedEnvFiles,\n loadEnvConfig as LoadEnvConfigFn,\n} from '@next/env';\n\nconst require = createRequire(import.meta.url);\n\nconst nextEnv = require('@next/env') as typeof import('@next/env');\n\nconst {\n loadEnvConfig: originalLoadEnvConfig,\n initialEnv,\n updateInitialEnv,\n processEnv,\n resetEnv,\n} = nextEnv;\n\nexport function loadEnvConfig(\n ...args: Parameters<typeof LoadEnvConfigFn>\n): ReturnType<typeof LoadEnvConfigFn> {\n dotenvx.config({ quiet: true });\n return originalLoadEnvConfig(...args);\n}\n\nexport type { Env, LoadedEnvFiles };\nexport { initialEnv, updateInitialEnv, processEnv, resetEnv };\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"next-env-compat.cjs","names":["createRequire","dotenvx"],"sources":["../src/next-env-compat.ts"],"sourcesContent":["/**\n * Drop-in replacement for @next/env that wraps loadEnvConfig to also call\n * dotenvx.config() so dotenvx-decrypted values are present in process.env\n * whenever loadEnvConfig is invoked.\n *\n * Two coverage levels:\n *\n * 1. Webpack alias (partial): plugin.ts sets webpack resolve.alias['@next/env']\n * to this module. Intercepts imports of @next/env INSIDE webpack-bundled code\n * (hot-reload handlers, preview mode helpers in the server bundle).\n * Does NOT cover Next.js's own Node.js startup calls to loadEnvConfig, which\n * happen before webpack runs.\n *\n * 2. npm overrides (full): users add \"@next/env\" → \"@fantasticfour/dotenvx-next\"\n * in package.json overrides/resolutions. Node.js resolves require('@next/env')\n * to this package's CJS entry, which re-exports loadEnvConfig, covering startup.\n *\n * @next/env is CJS-only, so createRequire is used to load it from ESM.\n */\n\nimport { createRequire } from 'node:module';\nimport dotenvx from '@dotenvx/dotenvx';\nimport type {\n Env,\n LoadedEnvFiles,\n loadEnvConfig as LoadEnvConfigFn,\n} from '@next/env';\n\nconst require = createRequire(import.meta.url);\n\nconst nextEnv = require('@next/env') as typeof import('@next/env');\n\nconst {\n loadEnvConfig: originalLoadEnvConfig,\n initialEnv,\n updateInitialEnv,\n processEnv,\n resetEnv,\n} = nextEnv;\n\nexport function loadEnvConfig(\n ...args: Parameters<typeof LoadEnvConfigFn>\n): ReturnType<typeof LoadEnvConfigFn> {\n dotenvx.config({ quiet: true });\n return originalLoadEnvConfig(...args);\n}\n\nexport type { Env, LoadedEnvFiles };\nexport { initialEnv, updateInitialEnv, processEnv, resetEnv };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAM,EACJ,eAAe,uBACf,YACA,kBACA,YACA,cAAA,GATcA,YAAAA,cAAAA,CAAAA,QAAAA,KAAAA,CAAAA,CAAAA,cAAAA,UAAAA,CAAAA,CAAAA,IAEM,CAAC,CAAC,WAQd;AAEV,SAAgB,cACd,GAAG,MACiC;CACpCC,iBAAAA,QAAQ,OAAO,EAAE,OAAO,KAAK,CAAC;CAC9B,OAAO,sBAAsB,GAAG,IAAI;AACtC"}
|
|
@@ -1,8 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drop-in replacement for @next/env that wraps loadEnvConfig to also call
|
|
3
|
+
* dotenvx.config() so dotenvx-decrypted values are present in process.env
|
|
4
|
+
* whenever loadEnvConfig is invoked.
|
|
5
|
+
*
|
|
6
|
+
* Two coverage levels:
|
|
7
|
+
*
|
|
8
|
+
* 1. Webpack alias (partial): plugin.ts sets webpack resolve.alias['@next/env']
|
|
9
|
+
* to this module. Intercepts imports of @next/env INSIDE webpack-bundled code
|
|
10
|
+
* (hot-reload handlers, preview mode helpers in the server bundle).
|
|
11
|
+
* Does NOT cover Next.js's own Node.js startup calls to loadEnvConfig, which
|
|
12
|
+
* happen before webpack runs.
|
|
13
|
+
*
|
|
14
|
+
* 2. npm overrides (full): users add "@next/env" → "@fantasticfour/dotenvx-next"
|
|
15
|
+
* in package.json overrides/resolutions. Node.js resolves require('@next/env')
|
|
16
|
+
* to this package's CJS entry, which re-exports loadEnvConfig, covering startup.
|
|
17
|
+
*
|
|
18
|
+
* @next/env is CJS-only, so createRequire is used to load it from ESM.
|
|
19
|
+
*/
|
|
1
20
|
import { Env, LoadedEnvFiles, loadEnvConfig as loadEnvConfig$1 } from "@next/env";
|
|
2
|
-
|
|
3
|
-
//#region src/next-env-compat.d.ts
|
|
4
21
|
declare const initialEnv: Env | undefined, updateInitialEnv: typeof import("@next/env").updateInitialEnv, processEnv: typeof import("@next/env").processEnv, resetEnv: typeof import("@next/env").resetEnv;
|
|
5
|
-
declare function loadEnvConfig(...args: Parameters<typeof loadEnvConfig$1>): ReturnType<typeof loadEnvConfig$1>;
|
|
6
|
-
|
|
7
|
-
export { type Env, type LoadedEnvFiles, initialEnv, loadEnvConfig, processEnv, resetEnv, updateInitialEnv };
|
|
22
|
+
export declare function loadEnvConfig(...args: Parameters<typeof loadEnvConfig$1>): ReturnType<typeof loadEnvConfig$1>;
|
|
23
|
+
export { type Env, type LoadedEnvFiles, initialEnv, processEnv, resetEnv, updateInitialEnv };
|
|
8
24
|
//# sourceMappingURL=next-env-compat.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-env-compat.d.cts","names":[],"sources":["../src/next-env-compat.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"next-env-compat.d.cts","names":["LoadEnvConfigFn"],"sources":["../src/next-env-compat.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;cAkCE,YAAU,iBACV,6CAAgB,kBAChB,uCAAU,YACV,qCAAQ;wBAGM,iBACX,MAAM,kBAAkBA,mBAC1B,kBAAkBA"}
|
|
@@ -1,8 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drop-in replacement for @next/env that wraps loadEnvConfig to also call
|
|
3
|
+
* dotenvx.config() so dotenvx-decrypted values are present in process.env
|
|
4
|
+
* whenever loadEnvConfig is invoked.
|
|
5
|
+
*
|
|
6
|
+
* Two coverage levels:
|
|
7
|
+
*
|
|
8
|
+
* 1. Webpack alias (partial): plugin.ts sets webpack resolve.alias['@next/env']
|
|
9
|
+
* to this module. Intercepts imports of @next/env INSIDE webpack-bundled code
|
|
10
|
+
* (hot-reload handlers, preview mode helpers in the server bundle).
|
|
11
|
+
* Does NOT cover Next.js's own Node.js startup calls to loadEnvConfig, which
|
|
12
|
+
* happen before webpack runs.
|
|
13
|
+
*
|
|
14
|
+
* 2. npm overrides (full): users add "@next/env" → "@fantasticfour/dotenvx-next"
|
|
15
|
+
* in package.json overrides/resolutions. Node.js resolves require('@next/env')
|
|
16
|
+
* to this package's CJS entry, which re-exports loadEnvConfig, covering startup.
|
|
17
|
+
*
|
|
18
|
+
* @next/env is CJS-only, so createRequire is used to load it from ESM.
|
|
19
|
+
*/
|
|
1
20
|
import { Env, LoadedEnvFiles, loadEnvConfig as loadEnvConfig$1 } from "@next/env";
|
|
2
|
-
|
|
3
|
-
//#region src/next-env-compat.d.ts
|
|
4
21
|
declare const initialEnv: Env | undefined, updateInitialEnv: typeof import("@next/env").updateInitialEnv, processEnv: typeof import("@next/env").processEnv, resetEnv: typeof import("@next/env").resetEnv;
|
|
5
|
-
declare function loadEnvConfig(...args: Parameters<typeof loadEnvConfig$1>): ReturnType<typeof loadEnvConfig$1>;
|
|
6
|
-
|
|
7
|
-
export { type Env, type LoadedEnvFiles, initialEnv, loadEnvConfig, processEnv, resetEnv, updateInitialEnv };
|
|
22
|
+
export declare function loadEnvConfig(...args: Parameters<typeof loadEnvConfig$1>): ReturnType<typeof loadEnvConfig$1>;
|
|
23
|
+
export { type Env, type LoadedEnvFiles, initialEnv, processEnv, resetEnv, updateInitialEnv };
|
|
8
24
|
//# sourceMappingURL=next-env-compat.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-env-compat.d.mts","names":[],"sources":["../src/next-env-compat.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"next-env-compat.d.mts","names":["LoadEnvConfigFn"],"sources":["../src/next-env-compat.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;cAkCE,YAAU,iBACV,6CAAgB,kBAChB,uCAAU,YACV,qCAAQ;wBAGM,iBACX,MAAM,kBAAkBA,mBAC1B,kBAAkBA"}
|
package/dist/next-env-compat.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import dotenvx from "@dotenvx/dotenvx";
|
|
3
|
-
|
|
3
|
+
// src/next-env-compat.ts
|
|
4
4
|
/**
|
|
5
5
|
* Drop-in replacement for @next/env that wraps loadEnvConfig to also call
|
|
6
6
|
* dotenvx.config() so dotenvx-decrypted values are present in process.env
|
|
@@ -25,7 +25,6 @@ function loadEnvConfig(...args) {
|
|
|
25
25
|
dotenvx.config({ quiet: true });
|
|
26
26
|
return originalLoadEnvConfig(...args);
|
|
27
27
|
}
|
|
28
|
-
//#endregion
|
|
29
28
|
export { initialEnv, loadEnvConfig, processEnv, resetEnv, updateInitialEnv };
|
|
30
29
|
|
|
31
30
|
//# sourceMappingURL=next-env-compat.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-env-compat.mjs","names":[],"sources":["../src/next-env-compat.ts"],"sourcesContent":["/**\n * Drop-in replacement for @next/env that wraps loadEnvConfig to also call\n * dotenvx.config() so dotenvx-decrypted values are present in process.env\n * whenever loadEnvConfig is invoked.\n *\n * Two coverage levels:\n *\n * 1. Webpack alias (partial): plugin.ts sets webpack resolve.alias['@next/env']\n * to this module. Intercepts imports of @next/env INSIDE webpack-bundled code\n * (hot-reload handlers, preview mode helpers in the server bundle).\n * Does NOT cover Next.js's own Node.js startup calls to loadEnvConfig, which\n * happen before webpack runs.\n *\n * 2. npm overrides (full): users add \"@next/env\" → \"@fantasticfour/dotenvx-next\"\n * in package.json overrides/resolutions. Node.js resolves require('@next/env')\n * to this package's CJS entry, which re-exports loadEnvConfig, covering startup.\n *\n * @next/env is CJS-only, so createRequire is used to load it from ESM.\n */\n\nimport { createRequire } from 'node:module';\nimport dotenvx from '@dotenvx/dotenvx';\nimport type {\n Env,\n LoadedEnvFiles,\n loadEnvConfig as LoadEnvConfigFn,\n} from '@next/env';\n\nconst require = createRequire(import.meta.url);\n\nconst nextEnv = require('@next/env') as typeof import('@next/env');\n\nconst {\n loadEnvConfig: originalLoadEnvConfig,\n initialEnv,\n updateInitialEnv,\n processEnv,\n resetEnv,\n} = nextEnv;\n\nexport function loadEnvConfig(\n ...args: Parameters<typeof LoadEnvConfigFn>\n): ReturnType<typeof LoadEnvConfigFn> {\n dotenvx.config({ quiet: true });\n return originalLoadEnvConfig(...args);\n}\n\nexport type { Env, LoadedEnvFiles };\nexport { initialEnv, updateInitialEnv, processEnv, resetEnv };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAM,EACJ,eAAe,uBACf,YACA,kBACA,YACA,aATc,cAAc,
|
|
1
|
+
{"version":3,"file":"next-env-compat.mjs","names":[],"sources":["../src/next-env-compat.ts"],"sourcesContent":["/**\n * Drop-in replacement for @next/env that wraps loadEnvConfig to also call\n * dotenvx.config() so dotenvx-decrypted values are present in process.env\n * whenever loadEnvConfig is invoked.\n *\n * Two coverage levels:\n *\n * 1. Webpack alias (partial): plugin.ts sets webpack resolve.alias['@next/env']\n * to this module. Intercepts imports of @next/env INSIDE webpack-bundled code\n * (hot-reload handlers, preview mode helpers in the server bundle).\n * Does NOT cover Next.js's own Node.js startup calls to loadEnvConfig, which\n * happen before webpack runs.\n *\n * 2. npm overrides (full): users add \"@next/env\" → \"@fantasticfour/dotenvx-next\"\n * in package.json overrides/resolutions. Node.js resolves require('@next/env')\n * to this package's CJS entry, which re-exports loadEnvConfig, covering startup.\n *\n * @next/env is CJS-only, so createRequire is used to load it from ESM.\n */\n\nimport { createRequire } from 'node:module';\nimport dotenvx from '@dotenvx/dotenvx';\nimport type {\n Env,\n LoadedEnvFiles,\n loadEnvConfig as LoadEnvConfigFn,\n} from '@next/env';\n\nconst require = createRequire(import.meta.url);\n\nconst nextEnv = require('@next/env') as typeof import('@next/env');\n\nconst {\n loadEnvConfig: originalLoadEnvConfig,\n initialEnv,\n updateInitialEnv,\n processEnv,\n resetEnv,\n} = nextEnv;\n\nexport function loadEnvConfig(\n ...args: Parameters<typeof LoadEnvConfigFn>\n): ReturnType<typeof LoadEnvConfigFn> {\n dotenvx.config({ quiet: true });\n return originalLoadEnvConfig(...args);\n}\n\nexport type { Env, LoadedEnvFiles };\nexport { initialEnv, updateInitialEnv, processEnv, resetEnv };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAM,EACJ,eAAe,uBACf,YACA,kBACA,YACA,aATc,cAAc,YAAY,GAEpB,CAAC,CAAC,WAQd;AAEV,SAAgB,cACd,GAAG,MACiC;CACpC,QAAQ,OAAO,EAAE,OAAO,KAAK,CAAC;CAC9B,OAAO,sBAAsB,GAAG,IAAI;AACtC"}
|
package/dist/plugin.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_rolldown_runtime = require("./rolldown-runtime-
|
|
3
|
-
const require_webpack_plugin = require("./webpack-plugin.cjs");
|
|
4
|
-
const require_turbopack_inject = require("./turbopack-inject.cjs");
|
|
2
|
+
const require_rolldown_runtime = require("./rolldown-runtime-CmQyd0Gu.cjs");
|
|
5
3
|
let node_fs = require("node:fs");
|
|
6
|
-
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
7
4
|
let node_path = require("node:path");
|
|
8
|
-
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
9
5
|
let node_url = require("node:url");
|
|
10
6
|
let _dotenvx_dotenvx = require("@dotenvx/dotenvx");
|
|
7
|
+
const require_webpack_plugin = require("./webpack-plugin.cjs");
|
|
8
|
+
const require_turbopack_inject = require("./turbopack-inject.cjs");
|
|
9
|
+
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
10
|
+
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
11
11
|
_dotenvx_dotenvx = require_rolldown_runtime.__toESM(_dotenvx_dotenvx, 1);
|
|
12
|
-
|
|
12
|
+
// src/plugin.ts
|
|
13
13
|
/**
|
|
14
14
|
* withDotenvx() — Next.js config wrapper that loads dotenvx secrets at build time
|
|
15
15
|
* and inlines them into the webpack/turbopack runtime so they are available before
|
|
@@ -68,7 +68,6 @@ async function dotenvxNextConfigFn(nextConfig, options, phase, defaults) {
|
|
|
68
68
|
function withDotenvx(nextConfig, options = {}) {
|
|
69
69
|
return (phase, defaults) => dotenvxNextConfigFn(nextConfig, options, phase, defaults);
|
|
70
70
|
}
|
|
71
|
-
//#endregion
|
|
72
71
|
exports.withDotenvx = withDotenvx;
|
|
73
72
|
|
|
74
73
|
//# sourceMappingURL=plugin.cjs.map
|
package/dist/plugin.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs","names":["path","fs","dotenvx","DotenvxWebpackPlugin"],"sources":["../src/plugin.ts"],"sourcesContent":["/**\n * withDotenvx() — Next.js config wrapper that loads dotenvx secrets at build time\n * and inlines them into the webpack/turbopack runtime so they are available before\n * any user code evaluates (Prisma Pool, etc.) at module-load time.\n *\n * Strategy:\n * - At build time, call dotenvx.config() to decrypt env files and capture the\n * resolved key-value pairs.\n * - Webpack builds: prepend Object.assign(process.env, {...}) into webpack-runtime.js\n * via DotenvxWebpackPlugin (processAssets hook at PROCESS_ASSETS_STAGE_ADDITIONS).\n * - Turbopack builds: patch fs.writeFile to detect compilation completion and inject\n * the same snippet into [turbopack]_runtime.js files.\n * - Webpack alias: aliases @next/env inside webpack-bundled code only (hot-reload,\n * preview mode). Does NOT cover Next.js's pre-webpack startup calls — use npm\n * overrides for full coverage. See README.\n */\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { NextConfig } from 'next';\nimport dotenvx from '@dotenvx/dotenvx';\nimport { DotenvxWebpackPlugin } from './webpack-plugin.js';\nimport { activateTurbopackInjection } from './turbopack-inject.js';\n\nexport interface DotenvxNextOptions {\n /**\n * Env files to load. Defaults to ['.env'], filtered to files that actually\n * exist in envDir.\n */\n files?: string[];\n\n /**\n * Directory where env files live. Defaults to process.cwd().\n */\n envDir?: string;\n\n /**\n * Whether to overload (overwrite) existing process.env values with the loaded\n * env files. Defaults to true.\n */\n overload?: boolean;\n}\n\nconst DEFAULT_ENV_FILES = ['.env'];\n\nconst PLUGIN_DEBUG = !!process.env.DEBUG_DOTENVX_NEXT;\n\nfunction debugLog(...args: unknown[]): void {\n if (!PLUGIN_DEBUG) return;\n console.log('[dotenvx-next]', ...args);\n}\n\nfunction resolveExistingFiles(files: string[], envDir: string): string[] {\n return files\n .map((f) => path.resolve(envDir, f))\n .filter((absPath) => fs.existsSync(absPath));\n}\n\ntype NextConfigFn = (\n phase: string,\n defaults: { defaultConfig: NextConfig }\n) => NextConfig | Promise<NextConfig>;\n\nasync function dotenvxNextConfigFn(\n nextConfig: NextConfig | NextConfigFn,\n options: DotenvxNextOptions,\n phase: string,\n defaults: { defaultConfig: NextConfig }\n): Promise<NextConfig> {\n let resolvedNextConfig: NextConfig;\n\n if (typeof nextConfig === 'function') {\n resolvedNextConfig = {\n ...(await (nextConfig as NextConfigFn)(phase, defaults)),\n };\n } else {\n // Shallow-copy so we never mutate the frozen original config object\n resolvedNextConfig = { ...nextConfig };\n }\n\n const envDir = options.envDir ?? process.cwd();\n const fileNames = options.files ?? DEFAULT_ENV_FILES;\n const resolvedFiles = resolveExistingFiles(fileNames, envDir);\n\n // Detect turbopack (Next 16+ uses it by default in dev)\n const isTurbopack = !!(\n process.env.TURBOPACK ||\n process.env.TURBOPACK_DEV ||\n process.env.TURBOPACK_BUILD ||\n process.env.npm_config_turbopack\n );\n\n // Decrypt and resolve env values at build time.\n // parsed contains only the keys from the specified files (not all of process.env).\n const { parsed: env = {} } = resolvedFiles.length\n ? dotenvx.config({\n path: resolvedFiles,\n overload: options.overload ?? true,\n quiet: true,\n })\n : { parsed: {} };\n\n debugLog(\n `phase=${phase}, isTurbopack=${isTurbopack}, resolvedFiles=${JSON.stringify(resolvedFiles)}, envKeys=${Object.keys(env).join(',')}`\n );\n\n if (isTurbopack) {\n activateTurbopackInjection(env);\n }\n\n // Extend webpack config (used for non-turbopack builds and edge runtime)\n const prevWebpack = resolvedNextConfig.webpack;\n\n resolvedNextConfig.webpack = (webpackConfig, webpackOptions) => {\n // Apply user's existing webpack customizations first\n const config = prevWebpack\n ? prevWebpack(webpackConfig, webpackOptions)\n : webpackConfig;\n\n // Register the webpack plugin to inject the env snippet into runtime files\n if (!isTurbopack) {\n (config.plugins as unknown[]).push(new DotenvxWebpackPlugin({ env }));\n }\n\n // Alias @next/env → compat shim for webpack-bundled code paths (hot-reload, etc.).\n // Does NOT cover Next.js startup calls before webpack. See README for npm overrides.\n config.resolve ??= {};\n (config.resolve as Record<string, unknown>).alias ??= {};\n const alias = (config.resolve as Record<string, unknown>).alias as Record<\n string,\n string\n >;\n try {\n alias['@next/env'] = require.resolve(\n '@fantasticfour/dotenvx-next/next-env'\n );\n } catch {\n // Local dev: package not installed under that name — resolve relative to this file\n alias['@next/env'] = fileURLToPath(\n new URL('./next-env-compat.js', import.meta.url)\n );\n }\n\n return config;\n };\n\n return resolvedNextConfig;\n}\n\nexport function withDotenvx(\n nextConfig: NextConfig | NextConfigFn,\n options: DotenvxNextOptions = {}\n): NextConfigFn {\n return (phase: string, defaults: { defaultConfig: NextConfig }) =>\n dotenvxNextConfigFn(nextConfig, options, phase, defaults);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAM,oBAAoB,CAAC,MAAM;AAEjC,MAAM,eAAe,CAAC,CAAC,QAAQ,IAAI;AAEnC,SAAS,SAAS,GAAG,MAAuB;CAC1C,IAAI,CAAC,cAAc;CACnB,QAAQ,IAAI,kBAAkB,GAAG,IAAI;AACvC;AAEA,SAAS,qBAAqB,OAAiB,QAA0B;CACvE,OAAO,MACJ,KAAK,MAAMA,UAAAA,QAAK,QAAQ,QAAQ,CAAC,CAAC,CAAC,CACnC,QAAQ,YAAYC,QAAAA,QAAG,WAAW,OAAO,CAAC;AAC/C;AAOA,eAAe,oBACb,YACA,SACA,OACA,UACqB;CACrB,IAAI;CAEJ,IAAI,OAAO,eAAe,YACxB,qBAAqB,EACnB,GAAI,MAAO,WAA4B,OAAO,QAAQ,EACxD;MAGA,qBAAqB,EAAE,GAAG,WAAW;CAGvC,MAAM,SAAS,QAAQ,UAAU,QAAQ,IAAI;CAE7C,MAAM,gBAAgB,qBADJ,QAAQ,SAAS,mBACmB,MAAM;CAG5D,MAAM,cAAc,CAAC,EACnB,QAAQ,IAAI,aACZ,QAAQ,IAAI,iBACZ,QAAQ,IAAI,mBACZ,QAAQ,IAAI;CAKd,MAAM,EAAE,QAAQ,MAAM,CAAC,MAAM,cAAc,SACvCC,iBAAAA,QAAQ,OAAO;EACb,MAAM;EACN,UAAU,QAAQ,YAAY;EAC9B,OAAO;CACT,CAAC,IACD,EAAE,QAAQ,CAAC,EAAE;CAEjB,SACE,SAAS,MAAM,gBAAgB,YAAY,kBAAkB,KAAK,UAAU,aAAa,EAAE,YAAY,OAAO,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG,GAClI;CAEA,IAAI,
|
|
1
|
+
{"version":3,"file":"plugin.cjs","names":["path","fs","dotenvx","activateTurbopackInjection","DotenvxWebpackPlugin","fileURLToPath"],"sources":["../src/plugin.ts"],"sourcesContent":["/**\n * withDotenvx() — Next.js config wrapper that loads dotenvx secrets at build time\n * and inlines them into the webpack/turbopack runtime so they are available before\n * any user code evaluates (Prisma Pool, etc.) at module-load time.\n *\n * Strategy:\n * - At build time, call dotenvx.config() to decrypt env files and capture the\n * resolved key-value pairs.\n * - Webpack builds: prepend Object.assign(process.env, {...}) into webpack-runtime.js\n * via DotenvxWebpackPlugin (processAssets hook at PROCESS_ASSETS_STAGE_ADDITIONS).\n * - Turbopack builds: patch fs.writeFile to detect compilation completion and inject\n * the same snippet into [turbopack]_runtime.js files.\n * - Webpack alias: aliases @next/env inside webpack-bundled code only (hot-reload,\n * preview mode). Does NOT cover Next.js's pre-webpack startup calls — use npm\n * overrides for full coverage. See README.\n */\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { NextConfig } from 'next';\nimport dotenvx from '@dotenvx/dotenvx';\nimport { DotenvxWebpackPlugin } from './webpack-plugin.js';\nimport { activateTurbopackInjection } from './turbopack-inject.js';\n\nexport interface DotenvxNextOptions {\n /**\n * Env files to load. Defaults to ['.env'], filtered to files that actually\n * exist in envDir.\n */\n files?: string[];\n\n /**\n * Directory where env files live. Defaults to process.cwd().\n */\n envDir?: string;\n\n /**\n * Whether to overload (overwrite) existing process.env values with the loaded\n * env files. Defaults to true.\n */\n overload?: boolean;\n}\n\nconst DEFAULT_ENV_FILES = ['.env'];\n\nconst PLUGIN_DEBUG = !!process.env.DEBUG_DOTENVX_NEXT;\n\nfunction debugLog(...args: unknown[]): void {\n if (!PLUGIN_DEBUG) return;\n console.log('[dotenvx-next]', ...args);\n}\n\nfunction resolveExistingFiles(files: string[], envDir: string): string[] {\n return files\n .map((f) => path.resolve(envDir, f))\n .filter((absPath) => fs.existsSync(absPath));\n}\n\ntype NextConfigFn = (\n phase: string,\n defaults: { defaultConfig: NextConfig }\n) => NextConfig | Promise<NextConfig>;\n\nasync function dotenvxNextConfigFn(\n nextConfig: NextConfig | NextConfigFn,\n options: DotenvxNextOptions,\n phase: string,\n defaults: { defaultConfig: NextConfig }\n): Promise<NextConfig> {\n let resolvedNextConfig: NextConfig;\n\n if (typeof nextConfig === 'function') {\n resolvedNextConfig = {\n ...(await (nextConfig as NextConfigFn)(phase, defaults)),\n };\n } else {\n // Shallow-copy so we never mutate the frozen original config object\n resolvedNextConfig = { ...nextConfig };\n }\n\n const envDir = options.envDir ?? process.cwd();\n const fileNames = options.files ?? DEFAULT_ENV_FILES;\n const resolvedFiles = resolveExistingFiles(fileNames, envDir);\n\n // Detect turbopack (Next 16+ uses it by default in dev)\n const isTurbopack = !!(\n process.env.TURBOPACK ||\n process.env.TURBOPACK_DEV ||\n process.env.TURBOPACK_BUILD ||\n process.env.npm_config_turbopack\n );\n\n // Decrypt and resolve env values at build time.\n // parsed contains only the keys from the specified files (not all of process.env).\n const { parsed: env = {} } = resolvedFiles.length\n ? dotenvx.config({\n path: resolvedFiles,\n overload: options.overload ?? true,\n quiet: true,\n })\n : { parsed: {} };\n\n debugLog(\n `phase=${phase}, isTurbopack=${isTurbopack}, resolvedFiles=${JSON.stringify(resolvedFiles)}, envKeys=${Object.keys(env).join(',')}`\n );\n\n if (isTurbopack) {\n activateTurbopackInjection(env);\n }\n\n // Extend webpack config (used for non-turbopack builds and edge runtime)\n const prevWebpack = resolvedNextConfig.webpack;\n\n resolvedNextConfig.webpack = (webpackConfig, webpackOptions) => {\n // Apply user's existing webpack customizations first\n const config = prevWebpack\n ? prevWebpack(webpackConfig, webpackOptions)\n : webpackConfig;\n\n // Register the webpack plugin to inject the env snippet into runtime files\n if (!isTurbopack) {\n (config.plugins as unknown[]).push(new DotenvxWebpackPlugin({ env }));\n }\n\n // Alias @next/env → compat shim for webpack-bundled code paths (hot-reload, etc.).\n // Does NOT cover Next.js startup calls before webpack. See README for npm overrides.\n config.resolve ??= {};\n (config.resolve as Record<string, unknown>).alias ??= {};\n const alias = (config.resolve as Record<string, unknown>).alias as Record<\n string,\n string\n >;\n try {\n alias['@next/env'] = require.resolve(\n '@fantasticfour/dotenvx-next/next-env'\n );\n } catch {\n // Local dev: package not installed under that name — resolve relative to this file\n alias['@next/env'] = fileURLToPath(\n new URL('./next-env-compat.js', import.meta.url)\n );\n }\n\n return config;\n };\n\n return resolvedNextConfig;\n}\n\nexport function withDotenvx(\n nextConfig: NextConfig | NextConfigFn,\n options: DotenvxNextOptions = {}\n): NextConfigFn {\n return (phase: string, defaults: { defaultConfig: NextConfig }) =>\n dotenvxNextConfigFn(nextConfig, options, phase, defaults);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAM,oBAAoB,CAAC,MAAM;AAEjC,MAAM,eAAe,CAAC,CAAC,QAAQ,IAAI;AAEnC,SAAS,SAAS,GAAG,MAAuB;CAC1C,IAAI,CAAC,cAAc;CACnB,QAAQ,IAAI,kBAAkB,GAAG,IAAI;AACvC;AAEA,SAAS,qBAAqB,OAAiB,QAA0B;CACvE,OAAO,MACJ,KAAK,MAAMA,UAAAA,QAAK,QAAQ,QAAQ,CAAC,CAAC,CAAC,CACnC,QAAQ,YAAYC,QAAAA,QAAG,WAAW,OAAO,CAAC;AAC/C;AAOA,eAAe,oBACb,YACA,SACA,OACA,UACqB;CACrB,IAAI;CAEJ,IAAI,OAAO,eAAe,YACxB,qBAAqB,EACnB,GAAI,MAAO,WAA4B,OAAO,QAAQ,EACxD;MAGA,qBAAqB,EAAE,GAAG,WAAW;CAGvC,MAAM,SAAS,QAAQ,UAAU,QAAQ,IAAI;CAE7C,MAAM,gBAAgB,qBADJ,QAAQ,SAAS,mBACmB,MAAM;CAG5D,MAAM,cAAc,CAAC,EACnB,QAAQ,IAAI,aACZ,QAAQ,IAAI,iBACZ,QAAQ,IAAI,mBACZ,QAAQ,IAAI;CAKd,MAAM,EAAE,QAAQ,MAAM,CAAC,MAAM,cAAc,SACvCC,iBAAAA,QAAQ,OAAO;EACb,MAAM;EACN,UAAU,QAAQ,YAAY;EAC9B,OAAO;CACT,CAAC,IACD,EAAE,QAAQ,CAAC,EAAE;CAEjB,SACE,SAAS,MAAM,gBAAgB,YAAY,kBAAkB,KAAK,UAAU,aAAa,EAAE,YAAY,OAAO,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG,GAClI;CAEA,IAAI,aACFC,yBAAAA,2BAA2B,GAAG;CAIhC,MAAM,cAAc,mBAAmB;CAEvC,mBAAmB,WAAW,eAAe,mBAAmB;EAE9D,MAAM,SAAS,cACX,YAAY,eAAe,cAAc,IACzC;EAGJ,IAAI,CAAC,aACF,OAAO,QAAsB,KAAK,IAAIC,uBAAAA,qBAAqB,EAAE,IAAI,CAAC,CAAC;EAKtE,OAAO,YAAY,CAAC;EACnB,OAAO,QAAoC,UAAU,CAAC;EACvD,MAAM,QAAS,OAAO,QAAoC;EAI1D,IAAI;GACF,MAAM,eAAe,QAAQ,QAC3B,sCACF;EACF,QAAQ;GAEN,MAAM,gBAAA,GAAeC,SAAAA,cAAAA,CACnB,IAAI,IAAI,wBAAA,QAAA,KAAA,CAAA,CAAA,cAAA,UAAA,CAAA,CAAA,IAAuC,CACjD;EACF;EAEA,OAAO;CACT;CAEA,OAAO;AACT;AAEA,SAAgB,YACd,YACA,UAA8B,CAAC,GACjB;CACd,QAAQ,OAAe,aACrB,oBAAoB,YAAY,SAAS,OAAO,QAAQ;AAC5D"}
|
package/dist/plugin.d.cts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* withDotenvx() — Next.js config wrapper that loads dotenvx secrets at build time
|
|
3
|
+
* and inlines them into the webpack/turbopack runtime so they are available before
|
|
4
|
+
* any user code evaluates (Prisma Pool, etc.) at module-load time.
|
|
5
|
+
*
|
|
6
|
+
* Strategy:
|
|
7
|
+
* - At build time, call dotenvx.config() to decrypt env files and capture the
|
|
8
|
+
* resolved key-value pairs.
|
|
9
|
+
* - Webpack builds: prepend Object.assign(process.env, {...}) into webpack-runtime.js
|
|
10
|
+
* via DotenvxWebpackPlugin (processAssets hook at PROCESS_ASSETS_STAGE_ADDITIONS).
|
|
11
|
+
* - Turbopack builds: patch fs.writeFile to detect compilation completion and inject
|
|
12
|
+
* the same snippet into [turbopack]_runtime.js files.
|
|
13
|
+
* - Webpack alias: aliases @next/env inside webpack-bundled code only (hot-reload,
|
|
14
|
+
* preview mode). Does NOT cover Next.js's pre-webpack startup calls — use npm
|
|
15
|
+
* overrides for full coverage. See README.
|
|
16
|
+
*/
|
|
1
17
|
import { NextConfig } from "next";
|
|
2
|
-
|
|
3
|
-
//#region src/plugin.d.ts
|
|
4
|
-
interface DotenvxNextOptions {
|
|
18
|
+
export interface DotenvxNextOptions {
|
|
5
19
|
/**
|
|
6
20
|
* Env files to load. Defaults to ['.env'], filtered to files that actually
|
|
7
21
|
* exist in envDir.
|
|
@@ -20,7 +34,6 @@ interface DotenvxNextOptions {
|
|
|
20
34
|
type NextConfigFn = (phase: string, defaults: {
|
|
21
35
|
defaultConfig: NextConfig;
|
|
22
36
|
}) => NextConfig | Promise<NextConfig>;
|
|
23
|
-
declare function withDotenvx(nextConfig: NextConfig | NextConfigFn, options?: DotenvxNextOptions): NextConfigFn;
|
|
24
|
-
|
|
25
|
-
export { DotenvxNextOptions, withDotenvx };
|
|
37
|
+
export declare function withDotenvx(nextConfig: NextConfig | NextConfigFn, options?: DotenvxNextOptions): NextConfigFn;
|
|
38
|
+
export {};
|
|
26
39
|
//# sourceMappingURL=plugin.d.cts.map
|
package/dist/plugin.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/plugin.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;;;;;;;;;;;;;;iBAyBiB;;;;;EAKf;;;;EAKA;;;;;EAMA;;KAkBG,gBACH,eACA;EAAY,eAAe;MACxB,aAAa,QAAQ;wBAwFV,YACd,YAAY,aAAa,cACzB,UAAS,qBACR"}
|
package/dist/plugin.d.mts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* withDotenvx() — Next.js config wrapper that loads dotenvx secrets at build time
|
|
3
|
+
* and inlines them into the webpack/turbopack runtime so they are available before
|
|
4
|
+
* any user code evaluates (Prisma Pool, etc.) at module-load time.
|
|
5
|
+
*
|
|
6
|
+
* Strategy:
|
|
7
|
+
* - At build time, call dotenvx.config() to decrypt env files and capture the
|
|
8
|
+
* resolved key-value pairs.
|
|
9
|
+
* - Webpack builds: prepend Object.assign(process.env, {...}) into webpack-runtime.js
|
|
10
|
+
* via DotenvxWebpackPlugin (processAssets hook at PROCESS_ASSETS_STAGE_ADDITIONS).
|
|
11
|
+
* - Turbopack builds: patch fs.writeFile to detect compilation completion and inject
|
|
12
|
+
* the same snippet into [turbopack]_runtime.js files.
|
|
13
|
+
* - Webpack alias: aliases @next/env inside webpack-bundled code only (hot-reload,
|
|
14
|
+
* preview mode). Does NOT cover Next.js's pre-webpack startup calls — use npm
|
|
15
|
+
* overrides for full coverage. See README.
|
|
16
|
+
*/
|
|
1
17
|
import { NextConfig } from "next";
|
|
2
|
-
|
|
3
|
-
//#region src/plugin.d.ts
|
|
4
|
-
interface DotenvxNextOptions {
|
|
18
|
+
export interface DotenvxNextOptions {
|
|
5
19
|
/**
|
|
6
20
|
* Env files to load. Defaults to ['.env'], filtered to files that actually
|
|
7
21
|
* exist in envDir.
|
|
@@ -20,7 +34,6 @@ interface DotenvxNextOptions {
|
|
|
20
34
|
type NextConfigFn = (phase: string, defaults: {
|
|
21
35
|
defaultConfig: NextConfig;
|
|
22
36
|
}) => NextConfig | Promise<NextConfig>;
|
|
23
|
-
declare function withDotenvx(nextConfig: NextConfig | NextConfigFn, options?: DotenvxNextOptions): NextConfigFn;
|
|
24
|
-
|
|
25
|
-
export { DotenvxNextOptions, withDotenvx };
|
|
37
|
+
export declare function withDotenvx(nextConfig: NextConfig | NextConfigFn, options?: DotenvxNextOptions): NextConfigFn;
|
|
38
|
+
export {};
|
|
26
39
|
//# sourceMappingURL=plugin.d.mts.map
|
package/dist/plugin.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;;;;;;;;;;;;;;iBAyBiB;;;;;EAKf;;;;EAKA;;;;;EAMA;;KAkBG,gBACH,eACA;EAAY,eAAe;MACxB,aAAa,QAAQ;wBAwFV,YACd,YAAY,aAAa,cACzB,UAAS,qBACR"}
|
package/dist/plugin.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { t as __require } from "./rolldown-runtime-
|
|
2
|
-
import { DotenvxWebpackPlugin } from "./webpack-plugin.mjs";
|
|
3
|
-
import { activateTurbopackInjection } from "./turbopack-inject.mjs";
|
|
1
|
+
import { t as __require } from "./rolldown-runtime-D3PmRqjj.mjs";
|
|
4
2
|
import fs from "node:fs";
|
|
5
3
|
import path from "node:path";
|
|
6
4
|
import { fileURLToPath } from "node:url";
|
|
7
5
|
import dotenvx from "@dotenvx/dotenvx";
|
|
8
|
-
|
|
6
|
+
import { DotenvxWebpackPlugin } from "./webpack-plugin.mjs";
|
|
7
|
+
import { activateTurbopackInjection } from "./turbopack-inject.mjs";
|
|
8
|
+
// src/plugin.ts
|
|
9
9
|
/**
|
|
10
10
|
* withDotenvx() — Next.js config wrapper that loads dotenvx secrets at build time
|
|
11
11
|
* and inlines them into the webpack/turbopack runtime so they are available before
|
|
@@ -64,7 +64,6 @@ async function dotenvxNextConfigFn(nextConfig, options, phase, defaults) {
|
|
|
64
64
|
function withDotenvx(nextConfig, options = {}) {
|
|
65
65
|
return (phase, defaults) => dotenvxNextConfigFn(nextConfig, options, phase, defaults);
|
|
66
66
|
}
|
|
67
|
-
//#endregion
|
|
68
67
|
export { withDotenvx };
|
|
69
68
|
|
|
70
69
|
//# sourceMappingURL=plugin.mjs.map
|
package/dist/plugin.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["/**\n * withDotenvx() — Next.js config wrapper that loads dotenvx secrets at build time\n * and inlines them into the webpack/turbopack runtime so they are available before\n * any user code evaluates (Prisma Pool, etc.) at module-load time.\n *\n * Strategy:\n * - At build time, call dotenvx.config() to decrypt env files and capture the\n * resolved key-value pairs.\n * - Webpack builds: prepend Object.assign(process.env, {...}) into webpack-runtime.js\n * via DotenvxWebpackPlugin (processAssets hook at PROCESS_ASSETS_STAGE_ADDITIONS).\n * - Turbopack builds: patch fs.writeFile to detect compilation completion and inject\n * the same snippet into [turbopack]_runtime.js files.\n * - Webpack alias: aliases @next/env inside webpack-bundled code only (hot-reload,\n * preview mode). Does NOT cover Next.js's pre-webpack startup calls — use npm\n * overrides for full coverage. See README.\n */\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { NextConfig } from 'next';\nimport dotenvx from '@dotenvx/dotenvx';\nimport { DotenvxWebpackPlugin } from './webpack-plugin.js';\nimport { activateTurbopackInjection } from './turbopack-inject.js';\n\nexport interface DotenvxNextOptions {\n /**\n * Env files to load. Defaults to ['.env'], filtered to files that actually\n * exist in envDir.\n */\n files?: string[];\n\n /**\n * Directory where env files live. Defaults to process.cwd().\n */\n envDir?: string;\n\n /**\n * Whether to overload (overwrite) existing process.env values with the loaded\n * env files. Defaults to true.\n */\n overload?: boolean;\n}\n\nconst DEFAULT_ENV_FILES = ['.env'];\n\nconst PLUGIN_DEBUG = !!process.env.DEBUG_DOTENVX_NEXT;\n\nfunction debugLog(...args: unknown[]): void {\n if (!PLUGIN_DEBUG) return;\n console.log('[dotenvx-next]', ...args);\n}\n\nfunction resolveExistingFiles(files: string[], envDir: string): string[] {\n return files\n .map((f) => path.resolve(envDir, f))\n .filter((absPath) => fs.existsSync(absPath));\n}\n\ntype NextConfigFn = (\n phase: string,\n defaults: { defaultConfig: NextConfig }\n) => NextConfig | Promise<NextConfig>;\n\nasync function dotenvxNextConfigFn(\n nextConfig: NextConfig | NextConfigFn,\n options: DotenvxNextOptions,\n phase: string,\n defaults: { defaultConfig: NextConfig }\n): Promise<NextConfig> {\n let resolvedNextConfig: NextConfig;\n\n if (typeof nextConfig === 'function') {\n resolvedNextConfig = {\n ...(await (nextConfig as NextConfigFn)(phase, defaults)),\n };\n } else {\n // Shallow-copy so we never mutate the frozen original config object\n resolvedNextConfig = { ...nextConfig };\n }\n\n const envDir = options.envDir ?? process.cwd();\n const fileNames = options.files ?? DEFAULT_ENV_FILES;\n const resolvedFiles = resolveExistingFiles(fileNames, envDir);\n\n // Detect turbopack (Next 16+ uses it by default in dev)\n const isTurbopack = !!(\n process.env.TURBOPACK ||\n process.env.TURBOPACK_DEV ||\n process.env.TURBOPACK_BUILD ||\n process.env.npm_config_turbopack\n );\n\n // Decrypt and resolve env values at build time.\n // parsed contains only the keys from the specified files (not all of process.env).\n const { parsed: env = {} } = resolvedFiles.length\n ? dotenvx.config({\n path: resolvedFiles,\n overload: options.overload ?? true,\n quiet: true,\n })\n : { parsed: {} };\n\n debugLog(\n `phase=${phase}, isTurbopack=${isTurbopack}, resolvedFiles=${JSON.stringify(resolvedFiles)}, envKeys=${Object.keys(env).join(',')}`\n );\n\n if (isTurbopack) {\n activateTurbopackInjection(env);\n }\n\n // Extend webpack config (used for non-turbopack builds and edge runtime)\n const prevWebpack = resolvedNextConfig.webpack;\n\n resolvedNextConfig.webpack = (webpackConfig, webpackOptions) => {\n // Apply user's existing webpack customizations first\n const config = prevWebpack\n ? prevWebpack(webpackConfig, webpackOptions)\n : webpackConfig;\n\n // Register the webpack plugin to inject the env snippet into runtime files\n if (!isTurbopack) {\n (config.plugins as unknown[]).push(new DotenvxWebpackPlugin({ env }));\n }\n\n // Alias @next/env → compat shim for webpack-bundled code paths (hot-reload, etc.).\n // Does NOT cover Next.js startup calls before webpack. See README for npm overrides.\n config.resolve ??= {};\n (config.resolve as Record<string, unknown>).alias ??= {};\n const alias = (config.resolve as Record<string, unknown>).alias as Record<\n string,\n string\n >;\n try {\n alias['@next/env'] = require.resolve(\n '@fantasticfour/dotenvx-next/next-env'\n );\n } catch {\n // Local dev: package not installed under that name — resolve relative to this file\n alias['@next/env'] = fileURLToPath(\n new URL('./next-env-compat.js', import.meta.url)\n );\n }\n\n return config;\n };\n\n return resolvedNextConfig;\n}\n\nexport function withDotenvx(\n nextConfig: NextConfig | NextConfigFn,\n options: DotenvxNextOptions = {}\n): NextConfigFn {\n return (phase: string, defaults: { defaultConfig: NextConfig }) =>\n dotenvxNextConfigFn(nextConfig, options, phase, defaults);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAM,oBAAoB,CAAC,MAAM;AAEjC,MAAM,eAAe,CAAC,CAAC,QAAQ,IAAI;AAEnC,SAAS,SAAS,GAAG,MAAuB;CAC1C,IAAI,CAAC,cAAc;CACnB,QAAQ,IAAI,kBAAkB,GAAG,IAAI;AACvC;AAEA,SAAS,qBAAqB,OAAiB,QAA0B;CACvE,OAAO,MACJ,KAAK,MAAM,KAAK,QAAQ,QAAQ,CAAC,CAAC,CAAC,CACnC,QAAQ,YAAY,GAAG,WAAW,OAAO,CAAC;AAC/C;AAOA,eAAe,oBACb,YACA,SACA,OACA,UACqB;CACrB,IAAI;CAEJ,IAAI,OAAO,eAAe,YACxB,qBAAqB,EACnB,GAAI,MAAO,WAA4B,OAAO,QAAQ,EACxD;MAGA,qBAAqB,EAAE,GAAG,WAAW;CAGvC,MAAM,SAAS,QAAQ,UAAU,QAAQ,IAAI;CAE7C,MAAM,gBAAgB,qBADJ,QAAQ,SAAS,mBACmB,MAAM;CAG5D,MAAM,cAAc,CAAC,EACnB,QAAQ,IAAI,aACZ,QAAQ,IAAI,iBACZ,QAAQ,IAAI,mBACZ,QAAQ,IAAI;CAKd,MAAM,EAAE,QAAQ,MAAM,CAAC,MAAM,cAAc,SACvC,QAAQ,OAAO;EACb,MAAM;EACN,UAAU,QAAQ,YAAY;EAC9B,OAAO;CACT,CAAC,IACD,EAAE,QAAQ,CAAC,EAAE;CAEjB,SACE,SAAS,MAAM,gBAAgB,YAAY,kBAAkB,KAAK,UAAU,aAAa,EAAE,YAAY,OAAO,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG,GAClI;CAEA,IAAI,aACF,2BAA2B,GAAG;CAIhC,MAAM,cAAc,mBAAmB;CAEvC,mBAAmB,WAAW,eAAe,mBAAmB;EAE9D,MAAM,SAAS,cACX,YAAY,eAAe,cAAc,IACzC;EAGJ,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["/**\n * withDotenvx() — Next.js config wrapper that loads dotenvx secrets at build time\n * and inlines them into the webpack/turbopack runtime so they are available before\n * any user code evaluates (Prisma Pool, etc.) at module-load time.\n *\n * Strategy:\n * - At build time, call dotenvx.config() to decrypt env files and capture the\n * resolved key-value pairs.\n * - Webpack builds: prepend Object.assign(process.env, {...}) into webpack-runtime.js\n * via DotenvxWebpackPlugin (processAssets hook at PROCESS_ASSETS_STAGE_ADDITIONS).\n * - Turbopack builds: patch fs.writeFile to detect compilation completion and inject\n * the same snippet into [turbopack]_runtime.js files.\n * - Webpack alias: aliases @next/env inside webpack-bundled code only (hot-reload,\n * preview mode). Does NOT cover Next.js's pre-webpack startup calls — use npm\n * overrides for full coverage. See README.\n */\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { NextConfig } from 'next';\nimport dotenvx from '@dotenvx/dotenvx';\nimport { DotenvxWebpackPlugin } from './webpack-plugin.js';\nimport { activateTurbopackInjection } from './turbopack-inject.js';\n\nexport interface DotenvxNextOptions {\n /**\n * Env files to load. Defaults to ['.env'], filtered to files that actually\n * exist in envDir.\n */\n files?: string[];\n\n /**\n * Directory where env files live. Defaults to process.cwd().\n */\n envDir?: string;\n\n /**\n * Whether to overload (overwrite) existing process.env values with the loaded\n * env files. Defaults to true.\n */\n overload?: boolean;\n}\n\nconst DEFAULT_ENV_FILES = ['.env'];\n\nconst PLUGIN_DEBUG = !!process.env.DEBUG_DOTENVX_NEXT;\n\nfunction debugLog(...args: unknown[]): void {\n if (!PLUGIN_DEBUG) return;\n console.log('[dotenvx-next]', ...args);\n}\n\nfunction resolveExistingFiles(files: string[], envDir: string): string[] {\n return files\n .map((f) => path.resolve(envDir, f))\n .filter((absPath) => fs.existsSync(absPath));\n}\n\ntype NextConfigFn = (\n phase: string,\n defaults: { defaultConfig: NextConfig }\n) => NextConfig | Promise<NextConfig>;\n\nasync function dotenvxNextConfigFn(\n nextConfig: NextConfig | NextConfigFn,\n options: DotenvxNextOptions,\n phase: string,\n defaults: { defaultConfig: NextConfig }\n): Promise<NextConfig> {\n let resolvedNextConfig: NextConfig;\n\n if (typeof nextConfig === 'function') {\n resolvedNextConfig = {\n ...(await (nextConfig as NextConfigFn)(phase, defaults)),\n };\n } else {\n // Shallow-copy so we never mutate the frozen original config object\n resolvedNextConfig = { ...nextConfig };\n }\n\n const envDir = options.envDir ?? process.cwd();\n const fileNames = options.files ?? DEFAULT_ENV_FILES;\n const resolvedFiles = resolveExistingFiles(fileNames, envDir);\n\n // Detect turbopack (Next 16+ uses it by default in dev)\n const isTurbopack = !!(\n process.env.TURBOPACK ||\n process.env.TURBOPACK_DEV ||\n process.env.TURBOPACK_BUILD ||\n process.env.npm_config_turbopack\n );\n\n // Decrypt and resolve env values at build time.\n // parsed contains only the keys from the specified files (not all of process.env).\n const { parsed: env = {} } = resolvedFiles.length\n ? dotenvx.config({\n path: resolvedFiles,\n overload: options.overload ?? true,\n quiet: true,\n })\n : { parsed: {} };\n\n debugLog(\n `phase=${phase}, isTurbopack=${isTurbopack}, resolvedFiles=${JSON.stringify(resolvedFiles)}, envKeys=${Object.keys(env).join(',')}`\n );\n\n if (isTurbopack) {\n activateTurbopackInjection(env);\n }\n\n // Extend webpack config (used for non-turbopack builds and edge runtime)\n const prevWebpack = resolvedNextConfig.webpack;\n\n resolvedNextConfig.webpack = (webpackConfig, webpackOptions) => {\n // Apply user's existing webpack customizations first\n const config = prevWebpack\n ? prevWebpack(webpackConfig, webpackOptions)\n : webpackConfig;\n\n // Register the webpack plugin to inject the env snippet into runtime files\n if (!isTurbopack) {\n (config.plugins as unknown[]).push(new DotenvxWebpackPlugin({ env }));\n }\n\n // Alias @next/env → compat shim for webpack-bundled code paths (hot-reload, etc.).\n // Does NOT cover Next.js startup calls before webpack. See README for npm overrides.\n config.resolve ??= {};\n (config.resolve as Record<string, unknown>).alias ??= {};\n const alias = (config.resolve as Record<string, unknown>).alias as Record<\n string,\n string\n >;\n try {\n alias['@next/env'] = require.resolve(\n '@fantasticfour/dotenvx-next/next-env'\n );\n } catch {\n // Local dev: package not installed under that name — resolve relative to this file\n alias['@next/env'] = fileURLToPath(\n new URL('./next-env-compat.js', import.meta.url)\n );\n }\n\n return config;\n };\n\n return resolvedNextConfig;\n}\n\nexport function withDotenvx(\n nextConfig: NextConfig | NextConfigFn,\n options: DotenvxNextOptions = {}\n): NextConfigFn {\n return (phase: string, defaults: { defaultConfig: NextConfig }) =>\n dotenvxNextConfigFn(nextConfig, options, phase, defaults);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAM,oBAAoB,CAAC,MAAM;AAEjC,MAAM,eAAe,CAAC,CAAC,QAAQ,IAAI;AAEnC,SAAS,SAAS,GAAG,MAAuB;CAC1C,IAAI,CAAC,cAAc;CACnB,QAAQ,IAAI,kBAAkB,GAAG,IAAI;AACvC;AAEA,SAAS,qBAAqB,OAAiB,QAA0B;CACvE,OAAO,MACJ,KAAK,MAAM,KAAK,QAAQ,QAAQ,CAAC,CAAC,CAAC,CACnC,QAAQ,YAAY,GAAG,WAAW,OAAO,CAAC;AAC/C;AAOA,eAAe,oBACb,YACA,SACA,OACA,UACqB;CACrB,IAAI;CAEJ,IAAI,OAAO,eAAe,YACxB,qBAAqB,EACnB,GAAI,MAAO,WAA4B,OAAO,QAAQ,EACxD;MAGA,qBAAqB,EAAE,GAAG,WAAW;CAGvC,MAAM,SAAS,QAAQ,UAAU,QAAQ,IAAI;CAE7C,MAAM,gBAAgB,qBADJ,QAAQ,SAAS,mBACmB,MAAM;CAG5D,MAAM,cAAc,CAAC,EACnB,QAAQ,IAAI,aACZ,QAAQ,IAAI,iBACZ,QAAQ,IAAI,mBACZ,QAAQ,IAAI;CAKd,MAAM,EAAE,QAAQ,MAAM,CAAC,MAAM,cAAc,SACvC,QAAQ,OAAO;EACb,MAAM;EACN,UAAU,QAAQ,YAAY;EAC9B,OAAO;CACT,CAAC,IACD,EAAE,QAAQ,CAAC,EAAE;CAEjB,SACE,SAAS,MAAM,gBAAgB,YAAY,kBAAkB,KAAK,UAAU,aAAa,EAAE,YAAY,OAAO,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG,GAClI;CAEA,IAAI,aACF,2BAA2B,GAAG;CAIhC,MAAM,cAAc,mBAAmB;CAEvC,mBAAmB,WAAW,eAAe,mBAAmB;EAE9D,MAAM,SAAS,cACX,YAAY,eAAe,cAAc,IACzC;EAGJ,IAAI,CAAC,aACF,OAAO,QAAsB,KAAK,IAAI,qBAAqB,EAAE,IAAI,CAAC,CAAC;EAKtE,OAAO,YAAY,CAAC;EACnB,OAAO,QAAoC,UAAU,CAAC;EACvD,MAAM,QAAS,OAAO,QAAoC;EAI1D,IAAI;GACF,MAAM,eAAA,UAAuB,QAC3B,sCACF;EACF,QAAQ;GAEN,MAAM,eAAe,cACnB,IAAI,IAAI,wBAAwB,YAAY,GAAG,CACjD;EACF;EAEA,OAAO;CACT;CAEA,OAAO;AACT;AAEA,SAAgB,YACd,YACA,UAA8B,CAAC,GACjB;CACd,QAAQ,OAAe,aACrB,oBAAoB,YAAY,SAAS,OAAO,QAAQ;AAC5D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -15,11 +15,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
}
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
19
19
|
value: mod,
|
|
20
20
|
enumerable: true
|
|
21
21
|
}) : target, mod));
|
|
22
|
-
//#endregion
|
|
23
22
|
Object.defineProperty(exports, "__toESM", {
|
|
24
23
|
enumerable: true,
|
|
25
24
|
get: function() {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_rolldown_runtime = require("./rolldown-runtime-
|
|
2
|
+
const require_rolldown_runtime = require("./rolldown-runtime-CmQyd0Gu.cjs");
|
|
3
3
|
let node_fs = require("node:fs");
|
|
4
|
-
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
5
4
|
let node_path = require("node:path");
|
|
5
|
+
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
6
6
|
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
7
|
-
|
|
7
|
+
// src/turbopack-inject.ts
|
|
8
8
|
/**
|
|
9
9
|
* Turbopack runtime injection — patches fs.writeFile/fs.writeFileSync to intercept
|
|
10
10
|
* turbopack's build output and prepend the env inline snippet into runtime files.
|
|
@@ -88,7 +88,6 @@ function activateTurbopackInjection(env) {
|
|
|
88
88
|
origWriteFileSyncFn.apply(node_fs.default, args);
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
-
//#endregion
|
|
92
91
|
exports.activateTurbopackInjection = activateTurbopackInjection;
|
|
93
92
|
exports.injectDotenvxInitIntoTurbopackRuntime = injectDotenvxInitIntoTurbopackRuntime;
|
|
94
93
|
exports.isInjectedTurbopackRuntime = isInjectedTurbopackRuntime;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turbopack-inject.cjs","names":["fs","path"],"sources":["../src/turbopack-inject.ts"],"sourcesContent":["/**\n * Turbopack runtime injection — patches fs.writeFile/fs.writeFileSync to intercept\n * turbopack's build output and prepend the env inline snippet into runtime files.\n *\n * Turbopack writes `[turbopack]_runtime.js` directly (bypassing webpack), so we\n * can't use the processAssets hook. Instead we intercept fs writes and inject when\n * export-detail.json is written (signals compilation is complete).\n */\n\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nfunction debugLog(...args: unknown[]): void {\n if (!process.env.DEBUG_DOTENVX_NEXT) return;\n console.log('[dotenvx-next]', ...args);\n}\n\nlet injectedTurbopackRuntime = false;\n\nexport function isInjectedTurbopackRuntime(): boolean {\n return injectedTurbopackRuntime;\n}\n\n/**\n * Inject the env inline snippet into turbopack runtime files.\n * Called after export-detail.json is written (turbopack compilation complete).\n */\nexport function injectDotenvxInitIntoTurbopackRuntime(\n nextDirPath: string,\n env: Record<string, string>\n): void {\n if (injectedTurbopackRuntime) return;\n\n const serverRuntimeFiles: string[] = [];\n const edgeWrapperFiles: string[] = [];\n\n const walkDir = (dir: string): void => {\n if (!fs.existsSync(dir)) return;\n for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {\n if (entry.isDirectory()) {\n walkDir(path.join(dir, entry.name));\n } else if (entry.name === '[turbopack]_runtime.js') {\n serverRuntimeFiles.push(path.join(dir, entry.name));\n } else if (\n entry.name.includes('edge-wrapper') &&\n entry.name.endsWith('.js')\n ) {\n edgeWrapperFiles.push(path.join(dir, entry.name));\n }\n }\n };\n\n walkDir(nextDirPath);\n\n debugLog(\n `turbopack runtime injection: found ${serverRuntimeFiles.length} server runtime files,`,\n `${edgeWrapperFiles.length} edge wrapper files`\n );\n\n if (!serverRuntimeFiles.length) {\n // Runtime files may not exist yet — turbopack (Rust) writes them directly.\n // We'll retry on subsequent fs writes until they appear.\n return;\n }\n\n // Mark as done so we don't retry\n injectedTurbopackRuntime = true;\n\n // Inline snippet: assign build-time-resolved values into process.env at runtime.\n const inlineSnippet = `(function(){if(typeof process!=='undefined'){Object.assign(process.env,${JSON.stringify(env)});}})();`;\n\n /**\n * Insert inlineSnippet into source respecting ESM constraints.\n * ESM files require all top-level `import` declarations to appear before any\n * other statements, so we must insert after the last import line rather than\n * prepending to the file.\n */\n const insertIntoSource = (origSource: string): string => {\n const lines = origSource.split('\\n');\n // Find the last line that starts with 'import ' (top-level import declaration)\n let lastImportIdx = -1;\n for (let i = 0; i < lines.length; i++) {\n if (/^import\\s/.test(lines[i])) {\n lastImportIdx = i;\n }\n }\n if (lastImportIdx >= 0) {\n // Insert after the last import line\n lines.splice(lastImportIdx + 1, 0, inlineSnippet);\n return lines.join('\\n');\n }\n // CJS or no imports — prepend\n return [inlineSnippet, origSource].join('\\n');\n };\n\n for (const runtimeFile of serverRuntimeFiles) {\n const origSource = fs.readFileSync(runtimeFile, 'utf8');\n fs.writeFileSync(runtimeFile, insertIntoSource(origSource));\n debugLog(`injected env into turbopack server runtime: ${runtimeFile}`);\n }\n\n for (const wrapperFile of edgeWrapperFiles) {\n const origSource = fs.readFileSync(wrapperFile, 'utf8');\n fs.writeFileSync(wrapperFile, insertIntoSource(origSource));\n debugLog(`injected env into turbopack edge wrapper: ${wrapperFile}`);\n }\n}\n\n/**\n * Patch global fs methods to detect when turbopack compilation completes,\n * then trigger runtime injection.\n */\nexport function activateTurbopackInjection(env: Record<string, string>): void {\n debugLog('activating turbopack fs intercept');\n\n const origWriteFileFn = fs.promises.writeFile;\n fs.promises.writeFile = async function dotenvxPatchedWriteFile(\n ...args: Parameters<typeof fs.promises.writeFile>\n ): ReturnType<typeof fs.promises.writeFile> {\n const filePath = args[0].toString();\n debugLog('fs.promises.writeFile:', filePath);\n\n if (\n !injectedTurbopackRuntime &&\n filePath.endsWith('/.next/export-detail.json')\n ) {\n const nextDirPath = filePath.substring(0, filePath.lastIndexOf('/'));\n injectDotenvxInitIntoTurbopackRuntime(nextDirPath, env);\n }\n\n return origWriteFileFn.apply(fs.promises, args);\n };\n\n const origWriteFileSyncFn = fs.writeFileSync;\n fs.writeFileSync = function dotenvxPatchedWriteFileSync(\n ...args: Parameters<typeof fs.writeFileSync>\n ): void {\n const filePath = args[0].toString();\n debugLog('fs.writeFileSync:', filePath);\n\n if (\n !injectedTurbopackRuntime &&\n filePath.endsWith('/.next/export-detail.json')\n ) {\n const nextDirPath = filePath.substring(0, filePath.lastIndexOf('/'));\n injectDotenvxInitIntoTurbopackRuntime(nextDirPath, env);\n }\n\n origWriteFileSyncFn.apply(fs, args);\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAYA,SAAS,SAAS,GAAG,MAAuB;CAC1C,IAAI,CAAC,QAAQ,IAAI,oBAAoB;CACrC,QAAQ,IAAI,kBAAkB,GAAG,IAAI;AACvC;AAEA,IAAI,2BAA2B;AAE/B,SAAgB,6BAAsC;CACpD,OAAO;AACT;;;;;AAMA,SAAgB,sCACd,aACA,KACM;CACN,IAAI,0BAA0B;CAE9B,MAAM,qBAA+B,CAAC;CACtC,MAAM,mBAA6B,CAAC;CAEpC,MAAM,WAAW,QAAsB;EACrC,IAAI,CAACA,QAAAA,QAAG,WAAW,GAAG,GAAG;EACzB,KAAK,MAAM,SAASA,QAAAA,QAAG,YAAY,KAAK,EAAE,eAAe,KAAK,CAAC,GAC7D,IAAI,MAAM,YAAY,GACpB,QAAQC,UAAAA,QAAK,KAAK,KAAK,MAAM,IAAI,CAAC;OAC7B,IAAI,MAAM,SAAS,0BACxB,mBAAmB,KAAKA,UAAAA,QAAK,KAAK,KAAK,MAAM,IAAI,CAAC;OAC7C,IACL,MAAM,KAAK,SAAS,cAAc,KAClC,MAAM,KAAK,SAAS,KAAK,GAEzB,iBAAiB,KAAKA,UAAAA,QAAK,KAAK,KAAK,MAAM,IAAI,CAAC;CAGtD;CAEA,QAAQ,WAAW;CAEnB,SACE,sCAAsC,mBAAmB,OAAO,yBAChE,GAAG,iBAAiB,OAAO,oBAC7B;CAEA,IAAI,CAAC,mBAAmB,QAGtB;CAIF,2BAA2B;CAG3B,MAAM,gBAAgB,0EAA0E,KAAK,UAAU,GAAG,EAAE;;;;;;;CAQpH,MAAM,oBAAoB,eAA+B;EACvD,MAAM,QAAQ,WAAW,MAAM,IAAI;EAEnC,IAAI,gBAAgB;EACpB,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAChC,IAAI,YAAY,KAAK,MAAM,EAAE,GAC3B,gBAAgB;EAGpB,IAAI,iBAAiB,GAAG;GAEtB,MAAM,OAAO,gBAAgB,GAAG,GAAG,aAAa;GAChD,OAAO,MAAM,KAAK,IAAI;EACxB;EAEA,OAAO,CAAC,eAAe,UAAU,CAAC,CAAC,KAAK,IAAI;CAC9C;CAEA,KAAK,MAAM,eAAe,oBAAoB;EAC5C,MAAM,aAAaD,QAAAA,QAAG,aAAa,aAAa,MAAM;
|
|
1
|
+
{"version":3,"file":"turbopack-inject.cjs","names":["fs","path"],"sources":["../src/turbopack-inject.ts"],"sourcesContent":["/**\n * Turbopack runtime injection — patches fs.writeFile/fs.writeFileSync to intercept\n * turbopack's build output and prepend the env inline snippet into runtime files.\n *\n * Turbopack writes `[turbopack]_runtime.js` directly (bypassing webpack), so we\n * can't use the processAssets hook. Instead we intercept fs writes and inject when\n * export-detail.json is written (signals compilation is complete).\n */\n\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nfunction debugLog(...args: unknown[]): void {\n if (!process.env.DEBUG_DOTENVX_NEXT) return;\n console.log('[dotenvx-next]', ...args);\n}\n\nlet injectedTurbopackRuntime = false;\n\nexport function isInjectedTurbopackRuntime(): boolean {\n return injectedTurbopackRuntime;\n}\n\n/**\n * Inject the env inline snippet into turbopack runtime files.\n * Called after export-detail.json is written (turbopack compilation complete).\n */\nexport function injectDotenvxInitIntoTurbopackRuntime(\n nextDirPath: string,\n env: Record<string, string>\n): void {\n if (injectedTurbopackRuntime) return;\n\n const serverRuntimeFiles: string[] = [];\n const edgeWrapperFiles: string[] = [];\n\n const walkDir = (dir: string): void => {\n if (!fs.existsSync(dir)) return;\n for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {\n if (entry.isDirectory()) {\n walkDir(path.join(dir, entry.name));\n } else if (entry.name === '[turbopack]_runtime.js') {\n serverRuntimeFiles.push(path.join(dir, entry.name));\n } else if (\n entry.name.includes('edge-wrapper') &&\n entry.name.endsWith('.js')\n ) {\n edgeWrapperFiles.push(path.join(dir, entry.name));\n }\n }\n };\n\n walkDir(nextDirPath);\n\n debugLog(\n `turbopack runtime injection: found ${serverRuntimeFiles.length} server runtime files,`,\n `${edgeWrapperFiles.length} edge wrapper files`\n );\n\n if (!serverRuntimeFiles.length) {\n // Runtime files may not exist yet — turbopack (Rust) writes them directly.\n // We'll retry on subsequent fs writes until they appear.\n return;\n }\n\n // Mark as done so we don't retry\n injectedTurbopackRuntime = true;\n\n // Inline snippet: assign build-time-resolved values into process.env at runtime.\n const inlineSnippet = `(function(){if(typeof process!=='undefined'){Object.assign(process.env,${JSON.stringify(env)});}})();`;\n\n /**\n * Insert inlineSnippet into source respecting ESM constraints.\n * ESM files require all top-level `import` declarations to appear before any\n * other statements, so we must insert after the last import line rather than\n * prepending to the file.\n */\n const insertIntoSource = (origSource: string): string => {\n const lines = origSource.split('\\n');\n // Find the last line that starts with 'import ' (top-level import declaration)\n let lastImportIdx = -1;\n for (let i = 0; i < lines.length; i++) {\n if (/^import\\s/.test(lines[i])) {\n lastImportIdx = i;\n }\n }\n if (lastImportIdx >= 0) {\n // Insert after the last import line\n lines.splice(lastImportIdx + 1, 0, inlineSnippet);\n return lines.join('\\n');\n }\n // CJS or no imports — prepend\n return [inlineSnippet, origSource].join('\\n');\n };\n\n for (const runtimeFile of serverRuntimeFiles) {\n const origSource = fs.readFileSync(runtimeFile, 'utf8');\n fs.writeFileSync(runtimeFile, insertIntoSource(origSource));\n debugLog(`injected env into turbopack server runtime: ${runtimeFile}`);\n }\n\n for (const wrapperFile of edgeWrapperFiles) {\n const origSource = fs.readFileSync(wrapperFile, 'utf8');\n fs.writeFileSync(wrapperFile, insertIntoSource(origSource));\n debugLog(`injected env into turbopack edge wrapper: ${wrapperFile}`);\n }\n}\n\n/**\n * Patch global fs methods to detect when turbopack compilation completes,\n * then trigger runtime injection.\n */\nexport function activateTurbopackInjection(env: Record<string, string>): void {\n debugLog('activating turbopack fs intercept');\n\n const origWriteFileFn = fs.promises.writeFile;\n fs.promises.writeFile = async function dotenvxPatchedWriteFile(\n ...args: Parameters<typeof fs.promises.writeFile>\n ): ReturnType<typeof fs.promises.writeFile> {\n const filePath = args[0].toString();\n debugLog('fs.promises.writeFile:', filePath);\n\n if (\n !injectedTurbopackRuntime &&\n filePath.endsWith('/.next/export-detail.json')\n ) {\n const nextDirPath = filePath.substring(0, filePath.lastIndexOf('/'));\n injectDotenvxInitIntoTurbopackRuntime(nextDirPath, env);\n }\n\n return origWriteFileFn.apply(fs.promises, args);\n };\n\n const origWriteFileSyncFn = fs.writeFileSync;\n fs.writeFileSync = function dotenvxPatchedWriteFileSync(\n ...args: Parameters<typeof fs.writeFileSync>\n ): void {\n const filePath = args[0].toString();\n debugLog('fs.writeFileSync:', filePath);\n\n if (\n !injectedTurbopackRuntime &&\n filePath.endsWith('/.next/export-detail.json')\n ) {\n const nextDirPath = filePath.substring(0, filePath.lastIndexOf('/'));\n injectDotenvxInitIntoTurbopackRuntime(nextDirPath, env);\n }\n\n origWriteFileSyncFn.apply(fs, args);\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAYA,SAAS,SAAS,GAAG,MAAuB;CAC1C,IAAI,CAAC,QAAQ,IAAI,oBAAoB;CACrC,QAAQ,IAAI,kBAAkB,GAAG,IAAI;AACvC;AAEA,IAAI,2BAA2B;AAE/B,SAAgB,6BAAsC;CACpD,OAAO;AACT;;;;;AAMA,SAAgB,sCACd,aACA,KACM;CACN,IAAI,0BAA0B;CAE9B,MAAM,qBAA+B,CAAC;CACtC,MAAM,mBAA6B,CAAC;CAEpC,MAAM,WAAW,QAAsB;EACrC,IAAI,CAACA,QAAAA,QAAG,WAAW,GAAG,GAAG;EACzB,KAAK,MAAM,SAASA,QAAAA,QAAG,YAAY,KAAK,EAAE,eAAe,KAAK,CAAC,GAC7D,IAAI,MAAM,YAAY,GACpB,QAAQC,UAAAA,QAAK,KAAK,KAAK,MAAM,IAAI,CAAC;OAC7B,IAAI,MAAM,SAAS,0BACxB,mBAAmB,KAAKA,UAAAA,QAAK,KAAK,KAAK,MAAM,IAAI,CAAC;OAC7C,IACL,MAAM,KAAK,SAAS,cAAc,KAClC,MAAM,KAAK,SAAS,KAAK,GAEzB,iBAAiB,KAAKA,UAAAA,QAAK,KAAK,KAAK,MAAM,IAAI,CAAC;CAGtD;CAEA,QAAQ,WAAW;CAEnB,SACE,sCAAsC,mBAAmB,OAAO,yBAChE,GAAG,iBAAiB,OAAO,oBAC7B;CAEA,IAAI,CAAC,mBAAmB,QAGtB;CAIF,2BAA2B;CAG3B,MAAM,gBAAgB,0EAA0E,KAAK,UAAU,GAAG,EAAE;;;;;;;CAQpH,MAAM,oBAAoB,eAA+B;EACvD,MAAM,QAAQ,WAAW,MAAM,IAAI;EAEnC,IAAI,gBAAgB;EACpB,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAChC,IAAI,YAAY,KAAK,MAAM,EAAE,GAC3B,gBAAgB;EAGpB,IAAI,iBAAiB,GAAG;GAEtB,MAAM,OAAO,gBAAgB,GAAG,GAAG,aAAa;GAChD,OAAO,MAAM,KAAK,IAAI;EACxB;EAEA,OAAO,CAAC,eAAe,UAAU,CAAC,CAAC,KAAK,IAAI;CAC9C;CAEA,KAAK,MAAM,eAAe,oBAAoB;EAC5C,MAAM,aAAaD,QAAAA,QAAG,aAAa,aAAa,MAAM;EACtDA,QAAAA,QAAG,cAAc,aAAa,iBAAiB,UAAU,CAAC;EAC1D,SAAS,+CAA+C,aAAa;CACvE;CAEA,KAAK,MAAM,eAAe,kBAAkB;EAC1C,MAAM,aAAaA,QAAAA,QAAG,aAAa,aAAa,MAAM;EACtDA,QAAAA,QAAG,cAAc,aAAa,iBAAiB,UAAU,CAAC;EAC1D,SAAS,6CAA6C,aAAa;CACrE;AACF;;;;;AAMA,SAAgB,2BAA2B,KAAmC;CAC5E,SAAS,mCAAmC;CAE5C,MAAM,kBAAkBA,QAAAA,QAAG,SAAS;CACpCA,QAAAA,QAAG,SAAS,YAAY,eAAe,wBACrC,GAAG,MACuC;EAC1C,MAAM,WAAW,KAAK,EAAE,CAAC,SAAS;EAClC,SAAS,0BAA0B,QAAQ;EAE3C,IACE,CAAC,4BACD,SAAS,SAAS,2BAA2B,GAG7C,sCADoB,SAAS,UAAU,GAAG,SAAS,YAAY,GAAG,CAClB,GAAG,GAAG;EAGxD,OAAO,gBAAgB,MAAMA,QAAAA,QAAG,UAAU,IAAI;CAChD;CAEA,MAAM,sBAAsBA,QAAAA,QAAG;CAC/B,QAAA,QAAA,gBAAmB,SAAS,4BAC1B,GAAG,MACG;EACN,MAAM,WAAW,KAAK,EAAE,CAAC,SAAS;EAClC,SAAS,qBAAqB,QAAQ;EAEtC,IACE,CAAC,4BACD,SAAS,SAAS,2BAA2B,GAG7C,sCADoB,SAAS,UAAU,GAAG,SAAS,YAAY,GAAG,CAClB,GAAG,GAAG;EAGxD,oBAAoB,MAAMA,QAAAA,SAAI,IAAI;CACpC;AACF"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/turbopack-inject.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Turbopack runtime injection — patches fs.writeFile/fs.writeFileSync to intercept
|
|
4
3
|
* turbopack's build output and prepend the env inline snippet into runtime files.
|
|
@@ -7,17 +6,15 @@
|
|
|
7
6
|
* can't use the processAssets hook. Instead we intercept fs writes and inject when
|
|
8
7
|
* export-detail.json is written (signals compilation is complete).
|
|
9
8
|
*/
|
|
10
|
-
declare function isInjectedTurbopackRuntime(): boolean;
|
|
9
|
+
export declare function isInjectedTurbopackRuntime(): boolean;
|
|
11
10
|
/**
|
|
12
11
|
* Inject the env inline snippet into turbopack runtime files.
|
|
13
12
|
* Called after export-detail.json is written (turbopack compilation complete).
|
|
14
13
|
*/
|
|
15
|
-
declare function injectDotenvxInitIntoTurbopackRuntime(nextDirPath: string, env: Record<string, string>): void;
|
|
14
|
+
export declare function injectDotenvxInitIntoTurbopackRuntime(nextDirPath: string, env: Record<string, string>): void;
|
|
16
15
|
/**
|
|
17
16
|
* Patch global fs methods to detect when turbopack compilation completes,
|
|
18
17
|
* then trigger runtime injection.
|
|
19
18
|
*/
|
|
20
|
-
declare function activateTurbopackInjection(env: Record<string, string>): void;
|
|
21
|
-
//#endregion
|
|
22
|
-
export { activateTurbopackInjection, injectDotenvxInitIntoTurbopackRuntime, isInjectedTurbopackRuntime };
|
|
19
|
+
export declare function activateTurbopackInjection(env: Record<string, string>): void;
|
|
23
20
|
//# sourceMappingURL=turbopack-inject.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turbopack-inject.d.cts","names":[],"sources":["../src/turbopack-inject.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"turbopack-inject.d.cts","names":[],"sources":["../src/turbopack-inject.ts"],"mappings":";;;;;;;;wBAmBgB;;;;;wBAQA,sCACd,qBACA,KAAK;;;;;wBAmFS,2BAA2B,KAAK"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/turbopack-inject.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Turbopack runtime injection — patches fs.writeFile/fs.writeFileSync to intercept
|
|
4
3
|
* turbopack's build output and prepend the env inline snippet into runtime files.
|
|
@@ -7,17 +6,15 @@
|
|
|
7
6
|
* can't use the processAssets hook. Instead we intercept fs writes and inject when
|
|
8
7
|
* export-detail.json is written (signals compilation is complete).
|
|
9
8
|
*/
|
|
10
|
-
declare function isInjectedTurbopackRuntime(): boolean;
|
|
9
|
+
export declare function isInjectedTurbopackRuntime(): boolean;
|
|
11
10
|
/**
|
|
12
11
|
* Inject the env inline snippet into turbopack runtime files.
|
|
13
12
|
* Called after export-detail.json is written (turbopack compilation complete).
|
|
14
13
|
*/
|
|
15
|
-
declare function injectDotenvxInitIntoTurbopackRuntime(nextDirPath: string, env: Record<string, string>): void;
|
|
14
|
+
export declare function injectDotenvxInitIntoTurbopackRuntime(nextDirPath: string, env: Record<string, string>): void;
|
|
16
15
|
/**
|
|
17
16
|
* Patch global fs methods to detect when turbopack compilation completes,
|
|
18
17
|
* then trigger runtime injection.
|
|
19
18
|
*/
|
|
20
|
-
declare function activateTurbopackInjection(env: Record<string, string>): void;
|
|
21
|
-
//#endregion
|
|
22
|
-
export { activateTurbopackInjection, injectDotenvxInitIntoTurbopackRuntime, isInjectedTurbopackRuntime };
|
|
19
|
+
export declare function activateTurbopackInjection(env: Record<string, string>): void;
|
|
23
20
|
//# sourceMappingURL=turbopack-inject.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turbopack-inject.d.mts","names":[],"sources":["../src/turbopack-inject.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"turbopack-inject.d.mts","names":[],"sources":["../src/turbopack-inject.ts"],"mappings":";;;;;;;;wBAmBgB;;;;;wBAQA,sCACd,qBACA,KAAK;;;;;wBAmFS,2BAA2B,KAAK"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
|
|
3
|
+
// src/turbopack-inject.ts
|
|
4
4
|
/**
|
|
5
5
|
* Turbopack runtime injection — patches fs.writeFile/fs.writeFileSync to intercept
|
|
6
6
|
* turbopack's build output and prepend the env inline snippet into runtime files.
|
|
@@ -84,7 +84,6 @@ function activateTurbopackInjection(env) {
|
|
|
84
84
|
origWriteFileSyncFn.apply(fs, args);
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
//#endregion
|
|
88
87
|
export { activateTurbopackInjection, injectDotenvxInitIntoTurbopackRuntime, isInjectedTurbopackRuntime };
|
|
89
88
|
|
|
90
89
|
//# sourceMappingURL=turbopack-inject.mjs.map
|
package/dist/webpack-plugin.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
// src/webpack-plugin.ts
|
|
3
3
|
const PLUGIN_NAME = "DotenvxNextWebpackPlugin";
|
|
4
4
|
const SERVER_RUNTIME_ASSETS = [
|
|
5
5
|
"webpack-runtime.js",
|
|
@@ -25,7 +25,7 @@ var DotenvxWebpackPlugin = class {
|
|
|
25
25
|
name: PLUGIN_NAME,
|
|
26
26
|
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
|
|
27
27
|
}, () => {
|
|
28
|
-
const runtimeNames = new Set([...SERVER_RUNTIME_ASSETS, ...EDGE_RUNTIME_ASSETS]);
|
|
28
|
+
const runtimeNames = /* @__PURE__ */ new Set([...SERVER_RUNTIME_ASSETS, ...EDGE_RUNTIME_ASSETS]);
|
|
29
29
|
for (const assetName of runtimeNames) {
|
|
30
30
|
if (!compilation.getAsset(assetName)) continue;
|
|
31
31
|
compilation.updateAsset(assetName, (origSource) => {
|
|
@@ -37,7 +37,6 @@ var DotenvxWebpackPlugin = class {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
-
//#endregion
|
|
41
40
|
exports.DotenvxWebpackPlugin = DotenvxWebpackPlugin;
|
|
42
41
|
|
|
43
42
|
//# sourceMappingURL=webpack-plugin.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpack-plugin.cjs","names":[],"sources":["../src/webpack-plugin.ts"],"sourcesContent":["/**\n * DotenvxWebpackPlugin — injects resolved env vars into webpack runtime files.\n *\n * At build time, dotenvx has already decrypted the env files and provided the\n * key-value pairs. We serialize them into a compact Object.assign(process.env, {...})\n * snippet and prepend it to the webpack runtime so every value is available before\n * any user module code runs (before Prisma Pool, etc. can evaluate at import time).\n */\n\n// webpack types come bundled with next — do not add webpack as a separate dep\ntype WebpackCompiler = import('webpack').Compiler;\ntype WebpackCompilation = import('webpack').Compilation;\n\nconst PLUGIN_NAME = 'DotenvxNextWebpackPlugin';\n\n// These are the webpack runtime asset names where we inject\nconst SERVER_RUNTIME_ASSETS = [\n 'webpack-runtime.js',\n '../webpack-runtime.js',\n 'webpack-api-runtime.js',\n '../webpack-api-runtime.js',\n];\n\nconst EDGE_RUNTIME_ASSETS = [\n 'edge-runtime-webpack.js',\n 'webpack-runtime.js',\n '../webpack-runtime.js',\n];\n\nexport interface DotenvxWebpackPluginOptions {\n /** Resolved env key-value pairs from dotenvx.config() at build time */\n env: Record<string, string>;\n}\n\nexport class DotenvxWebpackPlugin {\n private readonly options: DotenvxWebpackPluginOptions;\n\n constructor(options: DotenvxWebpackPluginOptions) {\n this.options = options;\n }\n\n apply(compiler: WebpackCompiler): void {\n const { env } = this.options;\n\n // Inline snippet: assign build-time-resolved values into process.env at runtime.\n // Wrapped in an IIFE to avoid any variable leakage into the runtime scope.\n const inlineSnippet = `(function(){if(typeof process!=='undefined'){Object.assign(process.env,${JSON.stringify(env)});}})();`;\n\n // Use webpack from the compiler's context — same instance Next.js uses\n const webpack = require('webpack') as typeof import('webpack');\n\n compiler.hooks.thisCompilation.tap(\n PLUGIN_NAME,\n (compilation: WebpackCompilation) => {\n compilation.hooks.processAssets.tap(\n {\n name: PLUGIN_NAME,\n stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n },\n () => {\n // Inject into whichever runtime asset this compilation emits\n // (server or edge). compiler.options.target can't tell them apart\n // — the edge compilation isn't tagged \"webworker\" — so we try every\n // known runtime asset and let the getAsset guard below skip those\n // (e.g. client) that this compilation didn't emit.\n const runtimeNames = new Set([\n ...SERVER_RUNTIME_ASSETS,\n ...EDGE_RUNTIME_ASSETS,\n ]);\n\n for (const assetName of runtimeNames) {\n if (!compilation.getAsset(assetName)) continue;\n\n compilation.updateAsset(assetName, (origSource) => {\n const updatedSourceStr = [\n inlineSnippet,\n origSource.source().toString(),\n ].join('\\n');\n return new webpack.sources.RawSource(updatedSourceStr);\n });\n }\n }\n );\n }\n );\n }\n}\n"],"mappings":";;AAaA,MAAM,cAAc;AAGpB,MAAM,wBAAwB;CAC5B;CACA;CACA;CACA;AACF;AAEA,MAAM,sBAAsB;CAC1B;CACA;CACA;AACF;AAOA,IAAa,uBAAb,MAAkC;CAGhC,YAAY,SAAsC;EAChD,KAAK,UAAU;CACjB;CAEA,MAAM,UAAiC;EACrC,MAAM,EAAE,QAAQ,KAAK;EAIrB,MAAM,gBAAgB,0EAA0E,KAAK,UAAU,GAAG,EAAE;EAGpH,MAAM,UAAU,QAAQ,SAAS;EAEjC,SAAS,MAAM,gBAAgB,IAC7B,cACC,gBAAoC;GACnC,YAAY,MAAM,cAAc,IAC9B;IACE,MAAM;IACN,OAAO,QAAQ,YAAY;GAC7B,SACM;IAMJ,MAAM,
|
|
1
|
+
{"version":3,"file":"webpack-plugin.cjs","names":[],"sources":["../src/webpack-plugin.ts"],"sourcesContent":["/**\n * DotenvxWebpackPlugin — injects resolved env vars into webpack runtime files.\n *\n * At build time, dotenvx has already decrypted the env files and provided the\n * key-value pairs. We serialize them into a compact Object.assign(process.env, {...})\n * snippet and prepend it to the webpack runtime so every value is available before\n * any user module code runs (before Prisma Pool, etc. can evaluate at import time).\n */\n\n// webpack types come bundled with next — do not add webpack as a separate dep\ntype WebpackCompiler = import('webpack').Compiler;\ntype WebpackCompilation = import('webpack').Compilation;\n\nconst PLUGIN_NAME = 'DotenvxNextWebpackPlugin';\n\n// These are the webpack runtime asset names where we inject\nconst SERVER_RUNTIME_ASSETS = [\n 'webpack-runtime.js',\n '../webpack-runtime.js',\n 'webpack-api-runtime.js',\n '../webpack-api-runtime.js',\n];\n\nconst EDGE_RUNTIME_ASSETS = [\n 'edge-runtime-webpack.js',\n 'webpack-runtime.js',\n '../webpack-runtime.js',\n];\n\nexport interface DotenvxWebpackPluginOptions {\n /** Resolved env key-value pairs from dotenvx.config() at build time */\n env: Record<string, string>;\n}\n\nexport class DotenvxWebpackPlugin {\n private readonly options: DotenvxWebpackPluginOptions;\n\n constructor(options: DotenvxWebpackPluginOptions) {\n this.options = options;\n }\n\n apply(compiler: WebpackCompiler): void {\n const { env } = this.options;\n\n // Inline snippet: assign build-time-resolved values into process.env at runtime.\n // Wrapped in an IIFE to avoid any variable leakage into the runtime scope.\n const inlineSnippet = `(function(){if(typeof process!=='undefined'){Object.assign(process.env,${JSON.stringify(env)});}})();`;\n\n // Use webpack from the compiler's context — same instance Next.js uses\n const webpack = require('webpack') as typeof import('webpack');\n\n compiler.hooks.thisCompilation.tap(\n PLUGIN_NAME,\n (compilation: WebpackCompilation) => {\n compilation.hooks.processAssets.tap(\n {\n name: PLUGIN_NAME,\n stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n },\n () => {\n // Inject into whichever runtime asset this compilation emits\n // (server or edge). compiler.options.target can't tell them apart\n // — the edge compilation isn't tagged \"webworker\" — so we try every\n // known runtime asset and let the getAsset guard below skip those\n // (e.g. client) that this compilation didn't emit.\n const runtimeNames = new Set([\n ...SERVER_RUNTIME_ASSETS,\n ...EDGE_RUNTIME_ASSETS,\n ]);\n\n for (const assetName of runtimeNames) {\n if (!compilation.getAsset(assetName)) continue;\n\n compilation.updateAsset(assetName, (origSource) => {\n const updatedSourceStr = [\n inlineSnippet,\n origSource.source().toString(),\n ].join('\\n');\n return new webpack.sources.RawSource(updatedSourceStr);\n });\n }\n }\n );\n }\n );\n }\n}\n"],"mappings":";;AAaA,MAAM,cAAc;AAGpB,MAAM,wBAAwB;CAC5B;CACA;CACA;CACA;AACF;AAEA,MAAM,sBAAsB;CAC1B;CACA;CACA;AACF;AAOA,IAAa,uBAAb,MAAkC;CAGhC,YAAY,SAAsC;EAChD,KAAK,UAAU;CACjB;CAEA,MAAM,UAAiC;EACrC,MAAM,EAAE,QAAQ,KAAK;EAIrB,MAAM,gBAAgB,0EAA0E,KAAK,UAAU,GAAG,EAAE;EAGpH,MAAM,UAAU,QAAQ,SAAS;EAEjC,SAAS,MAAM,gBAAgB,IAC7B,cACC,gBAAoC;GACnC,YAAY,MAAM,cAAc,IAC9B;IACE,MAAM;IACN,OAAO,QAAQ,YAAY;GAC7B,SACM;IAMJ,MAAM,+BAAe,IAAI,IAAI,CAC3B,GAAG,uBACH,GAAG,mBACL,CAAC;IAED,KAAK,MAAM,aAAa,cAAc;KACpC,IAAI,CAAC,YAAY,SAAS,SAAS,GAAG;KAEtC,YAAY,YAAY,YAAY,eAAe;MACjD,MAAM,mBAAmB,CACvB,eACA,WAAW,OAAO,CAAC,CAAC,SAAS,CAC/B,CAAC,CAAC,KAAK,IAAI;MACX,OAAO,IAAI,QAAQ,QAAQ,UAAU,gBAAgB;KACvD,CAAC;IACH;GACF,CACF;EACF,CACF;CACF;AACF"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/webpack-plugin.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* DotenvxWebpackPlugin — injects resolved env vars into webpack runtime files.
|
|
4
3
|
*
|
|
@@ -8,15 +7,14 @@
|
|
|
8
7
|
* any user module code runs (before Prisma Pool, etc. can evaluate at import time).
|
|
9
8
|
*/
|
|
10
9
|
type WebpackCompiler = import('webpack').Compiler;
|
|
11
|
-
interface DotenvxWebpackPluginOptions {
|
|
10
|
+
export interface DotenvxWebpackPluginOptions {
|
|
12
11
|
/** Resolved env key-value pairs from dotenvx.config() at build time */
|
|
13
12
|
env: Record<string, string>;
|
|
14
13
|
}
|
|
15
|
-
declare class DotenvxWebpackPlugin {
|
|
14
|
+
export declare class DotenvxWebpackPlugin {
|
|
16
15
|
private readonly options;
|
|
17
16
|
constructor(options: DotenvxWebpackPluginOptions);
|
|
18
17
|
apply(compiler: WebpackCompiler): void;
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
export { DotenvxWebpackPlugin, DotenvxWebpackPluginOptions };
|
|
19
|
+
export {};
|
|
22
20
|
//# sourceMappingURL=webpack-plugin.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpack-plugin.d.cts","names":[],"sources":["../src/webpack-plugin.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"webpack-plugin.d.cts","names":[],"sources":["../src/webpack-plugin.ts"],"mappings":";;;;;;;;KAUK,oCAAoC;iBAmBxB;;EAEf,KAAK;;qBAGM;mBACM;EAEjB,YAAY,SAAS;EAIrB,MAAM,UAAU"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/webpack-plugin.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* DotenvxWebpackPlugin — injects resolved env vars into webpack runtime files.
|
|
4
3
|
*
|
|
@@ -8,15 +7,14 @@
|
|
|
8
7
|
* any user module code runs (before Prisma Pool, etc. can evaluate at import time).
|
|
9
8
|
*/
|
|
10
9
|
type WebpackCompiler = import('webpack').Compiler;
|
|
11
|
-
interface DotenvxWebpackPluginOptions {
|
|
10
|
+
export interface DotenvxWebpackPluginOptions {
|
|
12
11
|
/** Resolved env key-value pairs from dotenvx.config() at build time */
|
|
13
12
|
env: Record<string, string>;
|
|
14
13
|
}
|
|
15
|
-
declare class DotenvxWebpackPlugin {
|
|
14
|
+
export declare class DotenvxWebpackPlugin {
|
|
16
15
|
private readonly options;
|
|
17
16
|
constructor(options: DotenvxWebpackPluginOptions);
|
|
18
17
|
apply(compiler: WebpackCompiler): void;
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
export { DotenvxWebpackPlugin, DotenvxWebpackPluginOptions };
|
|
19
|
+
export {};
|
|
22
20
|
//# sourceMappingURL=webpack-plugin.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpack-plugin.d.mts","names":[],"sources":["../src/webpack-plugin.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"webpack-plugin.d.mts","names":[],"sources":["../src/webpack-plugin.ts"],"mappings":";;;;;;;;KAUK,oCAAoC;iBAmBxB;;EAEf,KAAK;;qBAGM;mBACM;EAEjB,YAAY,SAAS;EAIrB,MAAM,UAAU"}
|
package/dist/webpack-plugin.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as __require } from "./rolldown-runtime-
|
|
2
|
-
|
|
1
|
+
import { t as __require } from "./rolldown-runtime-D3PmRqjj.mjs";
|
|
2
|
+
// src/webpack-plugin.ts
|
|
3
3
|
const PLUGIN_NAME = "DotenvxNextWebpackPlugin";
|
|
4
4
|
const SERVER_RUNTIME_ASSETS = [
|
|
5
5
|
"webpack-runtime.js",
|
|
@@ -25,7 +25,7 @@ var DotenvxWebpackPlugin = class {
|
|
|
25
25
|
name: PLUGIN_NAME,
|
|
26
26
|
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
|
|
27
27
|
}, () => {
|
|
28
|
-
const runtimeNames = new Set([...SERVER_RUNTIME_ASSETS, ...EDGE_RUNTIME_ASSETS]);
|
|
28
|
+
const runtimeNames = /* @__PURE__ */ new Set([...SERVER_RUNTIME_ASSETS, ...EDGE_RUNTIME_ASSETS]);
|
|
29
29
|
for (const assetName of runtimeNames) {
|
|
30
30
|
if (!compilation.getAsset(assetName)) continue;
|
|
31
31
|
compilation.updateAsset(assetName, (origSource) => {
|
|
@@ -37,7 +37,6 @@ var DotenvxWebpackPlugin = class {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
-
//#endregion
|
|
41
40
|
export { DotenvxWebpackPlugin };
|
|
42
41
|
|
|
43
42
|
//# sourceMappingURL=webpack-plugin.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpack-plugin.mjs","names":[],"sources":["../src/webpack-plugin.ts"],"sourcesContent":["/**\n * DotenvxWebpackPlugin — injects resolved env vars into webpack runtime files.\n *\n * At build time, dotenvx has already decrypted the env files and provided the\n * key-value pairs. We serialize them into a compact Object.assign(process.env, {...})\n * snippet and prepend it to the webpack runtime so every value is available before\n * any user module code runs (before Prisma Pool, etc. can evaluate at import time).\n */\n\n// webpack types come bundled with next — do not add webpack as a separate dep\ntype WebpackCompiler = import('webpack').Compiler;\ntype WebpackCompilation = import('webpack').Compilation;\n\nconst PLUGIN_NAME = 'DotenvxNextWebpackPlugin';\n\n// These are the webpack runtime asset names where we inject\nconst SERVER_RUNTIME_ASSETS = [\n 'webpack-runtime.js',\n '../webpack-runtime.js',\n 'webpack-api-runtime.js',\n '../webpack-api-runtime.js',\n];\n\nconst EDGE_RUNTIME_ASSETS = [\n 'edge-runtime-webpack.js',\n 'webpack-runtime.js',\n '../webpack-runtime.js',\n];\n\nexport interface DotenvxWebpackPluginOptions {\n /** Resolved env key-value pairs from dotenvx.config() at build time */\n env: Record<string, string>;\n}\n\nexport class DotenvxWebpackPlugin {\n private readonly options: DotenvxWebpackPluginOptions;\n\n constructor(options: DotenvxWebpackPluginOptions) {\n this.options = options;\n }\n\n apply(compiler: WebpackCompiler): void {\n const { env } = this.options;\n\n // Inline snippet: assign build-time-resolved values into process.env at runtime.\n // Wrapped in an IIFE to avoid any variable leakage into the runtime scope.\n const inlineSnippet = `(function(){if(typeof process!=='undefined'){Object.assign(process.env,${JSON.stringify(env)});}})();`;\n\n // Use webpack from the compiler's context — same instance Next.js uses\n const webpack = require('webpack') as typeof import('webpack');\n\n compiler.hooks.thisCompilation.tap(\n PLUGIN_NAME,\n (compilation: WebpackCompilation) => {\n compilation.hooks.processAssets.tap(\n {\n name: PLUGIN_NAME,\n stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n },\n () => {\n // Inject into whichever runtime asset this compilation emits\n // (server or edge). compiler.options.target can't tell them apart\n // — the edge compilation isn't tagged \"webworker\" — so we try every\n // known runtime asset and let the getAsset guard below skip those\n // (e.g. client) that this compilation didn't emit.\n const runtimeNames = new Set([\n ...SERVER_RUNTIME_ASSETS,\n ...EDGE_RUNTIME_ASSETS,\n ]);\n\n for (const assetName of runtimeNames) {\n if (!compilation.getAsset(assetName)) continue;\n\n compilation.updateAsset(assetName, (origSource) => {\n const updatedSourceStr = [\n inlineSnippet,\n origSource.source().toString(),\n ].join('\\n');\n return new webpack.sources.RawSource(updatedSourceStr);\n });\n }\n }\n );\n }\n );\n }\n}\n"],"mappings":";;AAaA,MAAM,cAAc;AAGpB,MAAM,wBAAwB;CAC5B;CACA;CACA;CACA;AACF;AAEA,MAAM,sBAAsB;CAC1B;CACA;CACA;AACF;AAOA,IAAa,uBAAb,MAAkC;CAGhC,YAAY,SAAsC;EAChD,KAAK,UAAU;CACjB;CAEA,MAAM,UAAiC;EACrC,MAAM,EAAE,QAAQ,KAAK;EAIrB,MAAM,gBAAgB,0EAA0E,KAAK,UAAU,GAAG,EAAE;EAGpH,MAAM,UAAA,UAAkB,SAAS;EAEjC,SAAS,MAAM,gBAAgB,IAC7B,cACC,gBAAoC;GACnC,YAAY,MAAM,cAAc,IAC9B;IACE,MAAM;IACN,OAAO,QAAQ,YAAY;GAC7B,SACM;IAMJ,MAAM,
|
|
1
|
+
{"version":3,"file":"webpack-plugin.mjs","names":[],"sources":["../src/webpack-plugin.ts"],"sourcesContent":["/**\n * DotenvxWebpackPlugin — injects resolved env vars into webpack runtime files.\n *\n * At build time, dotenvx has already decrypted the env files and provided the\n * key-value pairs. We serialize them into a compact Object.assign(process.env, {...})\n * snippet and prepend it to the webpack runtime so every value is available before\n * any user module code runs (before Prisma Pool, etc. can evaluate at import time).\n */\n\n// webpack types come bundled with next — do not add webpack as a separate dep\ntype WebpackCompiler = import('webpack').Compiler;\ntype WebpackCompilation = import('webpack').Compilation;\n\nconst PLUGIN_NAME = 'DotenvxNextWebpackPlugin';\n\n// These are the webpack runtime asset names where we inject\nconst SERVER_RUNTIME_ASSETS = [\n 'webpack-runtime.js',\n '../webpack-runtime.js',\n 'webpack-api-runtime.js',\n '../webpack-api-runtime.js',\n];\n\nconst EDGE_RUNTIME_ASSETS = [\n 'edge-runtime-webpack.js',\n 'webpack-runtime.js',\n '../webpack-runtime.js',\n];\n\nexport interface DotenvxWebpackPluginOptions {\n /** Resolved env key-value pairs from dotenvx.config() at build time */\n env: Record<string, string>;\n}\n\nexport class DotenvxWebpackPlugin {\n private readonly options: DotenvxWebpackPluginOptions;\n\n constructor(options: DotenvxWebpackPluginOptions) {\n this.options = options;\n }\n\n apply(compiler: WebpackCompiler): void {\n const { env } = this.options;\n\n // Inline snippet: assign build-time-resolved values into process.env at runtime.\n // Wrapped in an IIFE to avoid any variable leakage into the runtime scope.\n const inlineSnippet = `(function(){if(typeof process!=='undefined'){Object.assign(process.env,${JSON.stringify(env)});}})();`;\n\n // Use webpack from the compiler's context — same instance Next.js uses\n const webpack = require('webpack') as typeof import('webpack');\n\n compiler.hooks.thisCompilation.tap(\n PLUGIN_NAME,\n (compilation: WebpackCompilation) => {\n compilation.hooks.processAssets.tap(\n {\n name: PLUGIN_NAME,\n stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n },\n () => {\n // Inject into whichever runtime asset this compilation emits\n // (server or edge). compiler.options.target can't tell them apart\n // — the edge compilation isn't tagged \"webworker\" — so we try every\n // known runtime asset and let the getAsset guard below skip those\n // (e.g. client) that this compilation didn't emit.\n const runtimeNames = new Set([\n ...SERVER_RUNTIME_ASSETS,\n ...EDGE_RUNTIME_ASSETS,\n ]);\n\n for (const assetName of runtimeNames) {\n if (!compilation.getAsset(assetName)) continue;\n\n compilation.updateAsset(assetName, (origSource) => {\n const updatedSourceStr = [\n inlineSnippet,\n origSource.source().toString(),\n ].join('\\n');\n return new webpack.sources.RawSource(updatedSourceStr);\n });\n }\n }\n );\n }\n );\n }\n}\n"],"mappings":";;AAaA,MAAM,cAAc;AAGpB,MAAM,wBAAwB;CAC5B;CACA;CACA;CACA;AACF;AAEA,MAAM,sBAAsB;CAC1B;CACA;CACA;AACF;AAOA,IAAa,uBAAb,MAAkC;CAGhC,YAAY,SAAsC;EAChD,KAAK,UAAU;CACjB;CAEA,MAAM,UAAiC;EACrC,MAAM,EAAE,QAAQ,KAAK;EAIrB,MAAM,gBAAgB,0EAA0E,KAAK,UAAU,GAAG,EAAE;EAGpH,MAAM,UAAA,UAAkB,SAAS;EAEjC,SAAS,MAAM,gBAAgB,IAC7B,cACC,gBAAoC;GACnC,YAAY,MAAM,cAAc,IAC9B;IACE,MAAM;IACN,OAAO,QAAQ,YAAY;GAC7B,SACM;IAMJ,MAAM,+BAAe,IAAI,IAAI,CAC3B,GAAG,uBACH,GAAG,mBACL,CAAC;IAED,KAAK,MAAM,aAAa,cAAc;KACpC,IAAI,CAAC,YAAY,SAAS,SAAS,GAAG;KAEtC,YAAY,YAAY,YAAY,eAAe;MACjD,MAAM,mBAAmB,CACvB,eACA,WAAW,OAAO,CAAC,CAAC,SAAS,CAC/B,CAAC,CAAC,KAAK,IAAI;MACX,OAAO,IAAI,QAAQ,QAAQ,UAAU,gBAAgB;KACvD,CAAC;IACH;GACF,CACF;EACF,CACF;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fantasticfour/dotenvx-next",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Next.js plugin that loads dotenvx secrets early — before any user code evaluates — by injecting an init bundle into webpack/turbopack runtime files at build time.",
|
|
6
6
|
"repository": {
|
|
@@ -33,25 +33,21 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@biomejs/biome": "^2.
|
|
37
|
-
"@changesets/cli": "^
|
|
38
|
-
"@types/node": "^
|
|
39
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
40
|
-
"@vitest/coverage-v8": "^
|
|
41
|
-
"next": "^16.
|
|
42
|
-
"tsdown": "^0.
|
|
43
|
-
"typescript": "^
|
|
44
|
-
"vitest": "^
|
|
45
|
-
"webpack": "^5.
|
|
36
|
+
"@biomejs/biome": "^2.6.9",
|
|
37
|
+
"@changesets/cli": "^3.0.3",
|
|
38
|
+
"@types/node": "^26.6.11",
|
|
39
|
+
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
40
|
+
"@vitest/coverage-v8": "^5.1.2",
|
|
41
|
+
"next": "^16.5.0",
|
|
42
|
+
"tsdown": "^0.23.7",
|
|
43
|
+
"typescript": "^7.0.2",
|
|
44
|
+
"vitest": "^5.1.2",
|
|
45
|
+
"webpack": "^5.113.0"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": ">=18",
|
|
49
49
|
"pnpm": ">=11.0.0"
|
|
50
50
|
},
|
|
51
|
-
"volta": {
|
|
52
|
-
"node": "24.15.0",
|
|
53
|
-
"pnpm": "11.0.6"
|
|
54
|
-
},
|
|
55
51
|
"license": "MIT",
|
|
56
52
|
"author": "Vincent Taverna <vinnymac@gmail.com> (https://github.com/vinnymac)",
|
|
57
53
|
"homepage": "https://github.com/vinnymac/dotenvx-next#readme",
|