@fantasticfour/dotenvx-next 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +13 -1
- package/dist/next-env-compat.cjs +2 -2
- package/dist/next-env-compat.cjs.map +1 -1
- package/dist/next-env-compat.d.cts +1 -2
- package/dist/next-env-compat.d.cts.map +1 -1
- package/dist/next-env-compat.d.mts +1 -2
- package/dist/next-env-compat.d.mts.map +1 -1
- package/dist/next-env-compat.mjs.map +1 -1
- package/dist/plugin.cjs +4 -4
- 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 +2 -1
- package/dist/plugin.mjs.map +1 -1
- package/dist/rolldown-runtime-BdkLduGY.mjs +5 -0
- package/dist/turbopack-inject.cjs +3 -3
- package/dist/turbopack-inject.cjs.map +1 -1
- package/dist/turbopack-inject.d.cts.map +1 -1
- package/dist/turbopack-inject.d.mts.map +1 -1
- package/dist/turbopack-inject.mjs.map +1 -1
- package/dist/webpack-plugin.cjs +1 -2
- package/dist/webpack-plugin.cjs.map +1 -1
- package/dist/webpack-plugin.d.cts +1 -3
- package/dist/webpack-plugin.d.cts.map +1 -1
- package/dist/webpack-plugin.d.mts +1 -3
- package/dist/webpack-plugin.d.mts.map +1 -1
- package/dist/webpack-plugin.mjs +42 -1
- package/dist/webpack-plugin.mjs.map +1 -0
- package/package.json +31 -12
- package/dist/webpack-plugin-BmC1uBZp.mjs +0 -47
- package/dist/webpack-plugin-BmC1uBZp.mjs.map +0 -1
- /package/dist/{chunk-CKQMccvm.cjs → rolldown-runtime-D6vf50IK.cjs} +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vincent Taverna
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
# @fantasticfour/dotenvx-next
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://npmx.dev/package/@fantasticfour/dotenvx-next" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/npm/v/@fantasticfour/dotenvx-next.svg" alt="npm package"></a>
|
|
5
|
+
<a href="/LICENSE"><img src="https://img.shields.io/npm/l/@fantasticfour/dotenvx-next.svg" alt="license"></a>
|
|
6
|
+
<a href="https://nodejs.org/en/about/previous-releases"><img src="https://img.shields.io/node/v/@fantasticfour/dotenvx-next.svg" alt="node compatibility"></a>
|
|
7
|
+
<a href="https://github.com/vinnymac/dotenvx-next/actions/workflows/tests.yml"><img src="https://img.shields.io/github/actions/workflow/status/vinnymac/dotenvx-next/tests.yml?style=flat&logo=github&label=CI" alt="CI status"></a>
|
|
8
|
+
<a href="https://socket.dev/npm/package/@fantasticfour/dotenvx-next" target="_blank" rel="noopener noreferrer"><img src="https://badge.socket.dev/npm/package/@fantasticfour/dotenvx-next" alt="socket.dev score"></a>
|
|
9
|
+
</p>
|
|
10
|
+
<br/>
|
|
11
|
+
|
|
12
|
+
## dotenvx-next
|
|
13
|
+
> Decrypt [dotenvx](https://dotenvx.com) secrets before any Next.js module initializes.
|
|
14
|
+
|
|
15
|
+
A Next.js plugin that loads dotenvx secrets before any user code evaluates at runtime. It solves the timing problem where encrypted env vars need to be decrypted before modules like Prisma initialize their connection pools.
|
|
4
16
|
|
|
5
17
|
## The problem
|
|
6
18
|
|
package/dist/next-env-compat.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_rolldown_runtime = require("./rolldown-runtime-D6vf50IK.cjs");
|
|
3
3
|
let _dotenvx_dotenvx = require("@dotenvx/dotenvx");
|
|
4
|
-
_dotenvx_dotenvx =
|
|
4
|
+
_dotenvx_dotenvx = require_rolldown_runtime.__toESM(_dotenvx_dotenvx, 1);
|
|
5
5
|
//#region src/next-env-compat.ts
|
|
6
6
|
/**
|
|
7
7
|
* Drop-in replacement for @next/env that wraps loadEnvConfig to also call
|
|
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAM,EACJ,eAAe,uBACf,YACA,kBACA,YACA,cAAA,
|
|
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":";;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAM,EACJ,eAAe,uBACf,YACA,kBACA,YACA,cAAA,wBAAA,CAAA,CAAA,cAAA,CAAA,QAAA,KAAA,CAAA,CAAA,cAAA,UAAA,CAAA,CAAA,IAPoB,CAAC,CAAC,WAQd;AAEV,SAAgB,cACd,GAAG,MACiC;CACpC,iBAAA,QAAQ,OAAO,EAAE,OAAO,KAAK,CAAC;CAC9B,OAAO,sBAAsB,GAAG,IAAI;AACtC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import * as _$_next_env0 from "@next/env";
|
|
2
1
|
import { Env, LoadedEnvFiles, loadEnvConfig as loadEnvConfig$1 } from "@next/env";
|
|
3
2
|
|
|
4
3
|
//#region src/next-env-compat.d.ts
|
|
5
|
-
declare const initialEnv: Env | undefined, updateInitialEnv: typeof
|
|
4
|
+
declare const initialEnv: Env | undefined, updateInitialEnv: typeof import("@next/env").updateInitialEnv, processEnv: typeof import("@next/env").processEnv, resetEnv: typeof import("@next/env").resetEnv;
|
|
6
5
|
declare function loadEnvConfig(...args: Parameters<typeof loadEnvConfig$1>): ReturnType<typeof loadEnvConfig$1>;
|
|
7
6
|
//#endregion
|
|
8
7
|
export { type Env, type LoadedEnvFiles, initialEnv, loadEnvConfig, processEnv, resetEnv, updateInitialEnv };
|
|
@@ -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":[],"sources":["../src/next-env-compat.ts"],"mappings":";;;cAkCE,UAAA,EAAU,GAAA,cACV,gBAAA,6BAAgB,gBAAA,EAChB,UAAA,6BAAU,UAAA,EACV,QAAA,6BAAQ,QAAA;AAAA,iBAGM,aAAA,IACX,IAAA,EAAM,UAAA,QAAkB,eAAA,IAC1B,UAAA,QAAkB,eAAA"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import * as _$_next_env0 from "@next/env";
|
|
2
1
|
import { Env, LoadedEnvFiles, loadEnvConfig as loadEnvConfig$1 } from "@next/env";
|
|
3
2
|
|
|
4
3
|
//#region src/next-env-compat.d.ts
|
|
5
|
-
declare const initialEnv: Env | undefined, updateInitialEnv: typeof
|
|
4
|
+
declare const initialEnv: Env | undefined, updateInitialEnv: typeof import("@next/env").updateInitialEnv, processEnv: typeof import("@next/env").processEnv, resetEnv: typeof import("@next/env").resetEnv;
|
|
6
5
|
declare function loadEnvConfig(...args: Parameters<typeof loadEnvConfig$1>): ReturnType<typeof loadEnvConfig$1>;
|
|
7
6
|
//#endregion
|
|
8
7
|
export { type Env, type LoadedEnvFiles, initialEnv, loadEnvConfig, processEnv, resetEnv, updateInitialEnv };
|
|
@@ -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":[],"sources":["../src/next-env-compat.ts"],"mappings":";;;cAkCE,UAAA,EAAU,GAAA,cACV,gBAAA,6BAAgB,gBAAA,EAChB,UAAA,6BAAU,UAAA,EACV,QAAA,6BAAQ,QAAA;AAAA,iBAGM,aAAA,IACX,IAAA,EAAM,UAAA,QAAkB,eAAA,IAC1B,UAAA,QAAkB,eAAA"}
|
|
@@ -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,OAAO,KAAK,
|
|
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,OAAO,KAAK,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,14 +1,14 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_rolldown_runtime = require("./rolldown-runtime-D6vf50IK.cjs");
|
|
3
3
|
const require_webpack_plugin = require("./webpack-plugin.cjs");
|
|
4
4
|
const require_turbopack_inject = require("./turbopack-inject.cjs");
|
|
5
5
|
let node_fs = require("node:fs");
|
|
6
|
-
node_fs =
|
|
6
|
+
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
7
7
|
let node_path = require("node:path");
|
|
8
|
-
node_path =
|
|
8
|
+
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
9
9
|
let node_url = require("node:url");
|
|
10
10
|
let _dotenvx_dotenvx = require("@dotenvx/dotenvx");
|
|
11
|
-
_dotenvx_dotenvx =
|
|
11
|
+
_dotenvx_dotenvx = require_rolldown_runtime.__toESM(_dotenvx_dotenvx, 1);
|
|
12
12
|
//#region src/plugin.ts
|
|
13
13
|
/**
|
|
14
14
|
* withDotenvx() — Next.js config wrapper that loads dotenvx secrets at build time
|
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\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({ path: resolvedFiles, overload: true, quiet: true })\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
|
|
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\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({ path: resolvedFiles, overload: true, quiet: true })\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,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;EAAE,MAAM;EAAe,UAAU;EAAM,OAAO;CAAK,CAAC,IACnE,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,yBAAA,2BAA2B,GAAG;CAIhC,MAAM,cAAc,mBAAmB;CAEvC,mBAAmB,WAAW,eAAe,mBAAmB;EAE9D,MAAM,SAAS,cACX,YAAY,eAAe,cAAc,IACzC;EAGJ,IAAI,CAAC,aACH,OAAQ,QAAsB,KAAK,IAAIC,uBAAAA,qBAAqB,EAAE,IAAI,CAAC,CAAC;EAKtE,OAAO,YAAY,CAAC;EACpB,OAAQ,QAAoC,UAAU,CAAC;EACvD,MAAM,QAAS,OAAO,QAAoC;EAI1D,IAAI;GACF,MAAM,eAAe,QAAQ,QAC3B,sCACF;EACF,QAAQ;GAEN,MAAM,gBAAA,GAAA,SAAA,cAAA,CACJ,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.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;UAyBiB,kBAAA;EA8BH;;;;EAzBZ,KAAA;EA0BwB
|
|
1
|
+
{"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;UAyBiB,kBAAA;EA8BH;;;;EAzBZ,KAAA;EA0BwB;;AAAU;EArBlC,MAAM;AAAA;AAAA,KAkBH,YAAA,IACH,KAAA,UACA,QAAA;EAAY,aAAA,EAAe,UAAA;AAAA,MACxB,UAAA,GAAa,OAAA,CAAQ,UAAA;AAAA,iBAoFV,WAAA,CACd,UAAA,EAAY,UAAA,GAAa,YAAA,EACzB,OAAA,GAAS,kBAAA,GACR,YAAA"}
|
package/dist/plugin.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;UAyBiB,kBAAA;EA8BH;;;;EAzBZ,KAAA;EA0BwB
|
|
1
|
+
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;UAyBiB,kBAAA;EA8BH;;;;EAzBZ,KAAA;EA0BwB;;AAAU;EArBlC,MAAM;AAAA;AAAA,KAkBH,YAAA,IACH,KAAA,UACA,QAAA;EAAY,aAAA,EAAe,UAAA;AAAA,MACxB,UAAA,GAAa,OAAA,CAAQ,UAAA;AAAA,iBAoFV,WAAA,CACd,UAAA,EAAY,UAAA,GAAa,YAAA,EACzB,OAAA,GAAS,kBAAA,GACR,YAAA"}
|
package/dist/plugin.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as __require } from "./rolldown-runtime-BdkLduGY.mjs";
|
|
2
|
+
import { DotenvxWebpackPlugin } from "./webpack-plugin.mjs";
|
|
2
3
|
import { activateTurbopackInjection } from "./turbopack-inject.mjs";
|
|
3
4
|
import fs from "node:fs";
|
|
4
5
|
import path from "node:path";
|
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\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({ path: resolvedFiles, overload: true, quiet: true })\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
|
|
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\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({ path: resolvedFiles, overload: true, quiet: true })\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":";;;;;;;;;;;;;;;;;;;;;;;;AAsCA,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;EAAE,MAAM;EAAe,UAAU;EAAM,OAAO;CAAK,CAAC,IACnE,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,aACH,OAAQ,QAAsB,KAAK,IAAI,qBAAqB,EAAE,IAAI,CAAC,CAAC;EAKtE,OAAO,YAAY,CAAC;EACpB,OAAQ,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,OAAO,KAAK,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,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_rolldown_runtime = require("./rolldown-runtime-D6vf50IK.cjs");
|
|
3
3
|
let node_fs = require("node:fs");
|
|
4
|
-
node_fs =
|
|
4
|
+
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
5
5
|
let node_path = require("node:path");
|
|
6
|
-
node_path =
|
|
6
|
+
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
7
7
|
//#region src/turbopack-inject.ts
|
|
8
8
|
/**
|
|
9
9
|
* Turbopack runtime injection — patches fs.writeFile/fs.writeFileSync to intercept
|
|
@@ -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;
|
|
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;EACtD,QAAA,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;EACtD,QAAA,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;CACpC,QAAA,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turbopack-inject.d.cts","names":[],"sources":["../src/turbopack-inject.ts"],"mappings":";;AAmBA
|
|
1
|
+
{"version":3,"file":"turbopack-inject.d.cts","names":[],"sources":["../src/turbopack-inject.ts"],"mappings":";;AAmBA;;;;AAA0C;AAQ1C;;iBARgB,0BAAA;;;;;iBAQA,qCAAA,CACd,WAAA,UACA,GAAA,EAAK,MAAM;AAAgB;AAmF7B;;;AAnF6B,iBAmFb,0BAAA,CAA2B,GAA2B,EAAtB,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turbopack-inject.d.mts","names":[],"sources":["../src/turbopack-inject.ts"],"mappings":";;AAmBA
|
|
1
|
+
{"version":3,"file":"turbopack-inject.d.mts","names":[],"sources":["../src/turbopack-inject.ts"],"mappings":";;AAmBA;;;;AAA0C;AAQ1C;;iBARgB,0BAAA;;;;;iBAQA,qCAAA,CACd,WAAA,UACA,GAAA,EAAK,MAAM;AAAgB;AAmF7B;;;AAnF6B,iBAmFb,0BAAA,CAA2B,GAA2B,EAAtB,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turbopack-inject.mjs","names":[],"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;
|
|
1
|
+
{"version":3,"file":"turbopack-inject.mjs","names":[],"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,CAAC,GAAG,WAAW,GAAG,GAAG;EACzB,KAAK,MAAM,SAAS,GAAG,YAAY,KAAK,EAAE,eAAe,KAAK,CAAC,GAC7D,IAAI,MAAM,YAAY,GACpB,QAAQ,KAAK,KAAK,KAAK,MAAM,IAAI,CAAC;OAC7B,IAAI,MAAM,SAAS,0BACxB,mBAAmB,KAAK,KAAK,KAAK,KAAK,MAAM,IAAI,CAAC;OAC7C,IACL,MAAM,KAAK,SAAS,cAAc,KAClC,MAAM,KAAK,SAAS,KAAK,GAEzB,iBAAiB,KAAK,KAAK,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,aAAa,GAAG,aAAa,aAAa,MAAM;EACtD,GAAG,cAAc,aAAa,iBAAiB,UAAU,CAAC;EAC1D,SAAS,+CAA+C,aAAa;CACvE;CAEA,KAAK,MAAM,eAAe,kBAAkB;EAC1C,MAAM,aAAa,GAAG,aAAa,aAAa,MAAM;EACtD,GAAG,cAAc,aAAa,iBAAiB,UAAU,CAAC;EAC1D,SAAS,6CAA6C,aAAa;CACrE;AACF;;;;;AAMA,SAAgB,2BAA2B,KAAmC;CAC5E,SAAS,mCAAmC;CAE5C,MAAM,kBAAkB,GAAG,SAAS;CACpC,GAAG,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,MAAM,GAAG,UAAU,IAAI;CAChD;CAEA,MAAM,sBAAsB,GAAG;CAC/B,GAAG,gBAAgB,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,MAAM,IAAI,IAAI;CACpC;AACF"}
|
package/dist/webpack-plugin.cjs
CHANGED
|
@@ -25,8 +25,7 @@ var DotenvxWebpackPlugin = class {
|
|
|
25
25
|
name: PLUGIN_NAME,
|
|
26
26
|
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
|
|
27
27
|
}, () => {
|
|
28
|
-
const
|
|
29
|
-
const runtimeNames = (Array.isArray(target) ? target.some((t) => typeof t === "string" && t.includes("webworker")) : typeof target === "string" && target.includes("webworker")) ? EDGE_RUNTIME_ASSETS : SERVER_RUNTIME_ASSETS;
|
|
28
|
+
const runtimeNames = new Set([...SERVER_RUNTIME_ASSETS, ...EDGE_RUNTIME_ASSETS]);
|
|
30
29
|
for (const assetName of runtimeNames) {
|
|
31
30
|
if (!compilation.getAsset(assetName)) continue;
|
|
32
31
|
compilation.updateAsset(assetName, (origSource) => {
|
|
@@ -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
|
|
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,eAAe,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,5 +1,3 @@
|
|
|
1
|
-
import * as _$webpack from "webpack";
|
|
2
|
-
|
|
3
1
|
//#region src/webpack-plugin.d.ts
|
|
4
2
|
/**
|
|
5
3
|
* DotenvxWebpackPlugin — injects resolved env vars into webpack runtime files.
|
|
@@ -9,7 +7,7 @@ import * as _$webpack from "webpack";
|
|
|
9
7
|
* snippet and prepend it to the webpack runtime so every value is available before
|
|
10
8
|
* any user module code runs (before Prisma Pool, etc. can evaluate at import time).
|
|
11
9
|
*/
|
|
12
|
-
type WebpackCompiler =
|
|
10
|
+
type WebpackCompiler = import('webpack').Compiler;
|
|
13
11
|
interface DotenvxWebpackPluginOptions {
|
|
14
12
|
/** Resolved env key-value pairs from dotenvx.config() at build time */
|
|
15
13
|
env: Record<string, string>;
|
|
@@ -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":";;;;;;AAUiD;AAmBjD;;KAnBK,eAAA,qBAAoC,QAAQ;AAAA,UAmBhC,2BAAA;EAEJ;EAAX,GAAA,EAAK,MAAM;AAAA;AAAA,cAGA,oBAAA;EAAA,iBACM,OAAA;cAEL,OAAA,EAAS,2BAAA;EAIrB,KAAA,CAAM,QAAA,EAAU,eAAe;AAAA"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import * as _$webpack from "webpack";
|
|
2
|
-
|
|
3
1
|
//#region src/webpack-plugin.d.ts
|
|
4
2
|
/**
|
|
5
3
|
* DotenvxWebpackPlugin — injects resolved env vars into webpack runtime files.
|
|
@@ -9,7 +7,7 @@ import * as _$webpack from "webpack";
|
|
|
9
7
|
* snippet and prepend it to the webpack runtime so every value is available before
|
|
10
8
|
* any user module code runs (before Prisma Pool, etc. can evaluate at import time).
|
|
11
9
|
*/
|
|
12
|
-
type WebpackCompiler =
|
|
10
|
+
type WebpackCompiler = import('webpack').Compiler;
|
|
13
11
|
interface DotenvxWebpackPluginOptions {
|
|
14
12
|
/** Resolved env key-value pairs from dotenvx.config() at build time */
|
|
15
13
|
env: Record<string, string>;
|
|
@@ -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":";;;;;;AAUiD;AAmBjD;;KAnBK,eAAA,qBAAoC,QAAQ;AAAA,UAmBhC,2BAAA;EAEJ;EAAX,GAAA,EAAK,MAAM;AAAA;AAAA,cAGA,oBAAA;EAAA,iBACM,OAAA;cAEL,OAAA,EAAS,2BAAA;EAIrB,KAAA,CAAM,QAAA,EAAU,eAAe;AAAA"}
|
package/dist/webpack-plugin.mjs
CHANGED
|
@@ -1,2 +1,43 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as __require } from "./rolldown-runtime-BdkLduGY.mjs";
|
|
2
|
+
//#region src/webpack-plugin.ts
|
|
3
|
+
const PLUGIN_NAME = "DotenvxNextWebpackPlugin";
|
|
4
|
+
const SERVER_RUNTIME_ASSETS = [
|
|
5
|
+
"webpack-runtime.js",
|
|
6
|
+
"../webpack-runtime.js",
|
|
7
|
+
"webpack-api-runtime.js",
|
|
8
|
+
"../webpack-api-runtime.js"
|
|
9
|
+
];
|
|
10
|
+
const EDGE_RUNTIME_ASSETS = [
|
|
11
|
+
"edge-runtime-webpack.js",
|
|
12
|
+
"webpack-runtime.js",
|
|
13
|
+
"../webpack-runtime.js"
|
|
14
|
+
];
|
|
15
|
+
var DotenvxWebpackPlugin = class {
|
|
16
|
+
constructor(options) {
|
|
17
|
+
this.options = options;
|
|
18
|
+
}
|
|
19
|
+
apply(compiler) {
|
|
20
|
+
const { env } = this.options;
|
|
21
|
+
const inlineSnippet = `(function(){if(typeof process!=='undefined'){Object.assign(process.env,${JSON.stringify(env)});}})();`;
|
|
22
|
+
const webpack = __require("webpack");
|
|
23
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
24
|
+
compilation.hooks.processAssets.tap({
|
|
25
|
+
name: PLUGIN_NAME,
|
|
26
|
+
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
|
|
27
|
+
}, () => {
|
|
28
|
+
const runtimeNames = new Set([...SERVER_RUNTIME_ASSETS, ...EDGE_RUNTIME_ASSETS]);
|
|
29
|
+
for (const assetName of runtimeNames) {
|
|
30
|
+
if (!compilation.getAsset(assetName)) continue;
|
|
31
|
+
compilation.updateAsset(assetName, (origSource) => {
|
|
32
|
+
const updatedSourceStr = [inlineSnippet, origSource.source().toString()].join("\n");
|
|
33
|
+
return new webpack.sources.RawSource(updatedSourceStr);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
2
41
|
export { DotenvxWebpackPlugin };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=webpack-plugin.mjs.map
|
|
@@ -0,0 +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,eAAe,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.
|
|
3
|
+
"version": "0.3.0",
|
|
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": {
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"
|
|
28
|
-
"
|
|
27
|
+
"@dotenvx/dotenvx": "^1.0.0",
|
|
28
|
+
"next": ">=14"
|
|
29
29
|
},
|
|
30
30
|
"peerDependenciesMeta": {
|
|
31
31
|
"@dotenvx/dotenvx": {
|
|
@@ -33,31 +33,50 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@biomejs/biome": "^2.
|
|
36
|
+
"@biomejs/biome": "^2.5.0",
|
|
37
37
|
"@changesets/cli": "^2.31.0",
|
|
38
|
-
"@types/node": "^25.
|
|
39
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
40
|
-
"
|
|
38
|
+
"@types/node": "^25.9.0",
|
|
39
|
+
"@typescript/native-preview": "7.0.0-dev.20260615.1",
|
|
40
|
+
"@vitest/coverage-v8": "^4.1.9",
|
|
41
|
+
"next": "^16.2.9",
|
|
42
|
+
"tsdown": "^0.22.0",
|
|
41
43
|
"typescript": "^6.0.3",
|
|
42
|
-
"vitest": "^4.1.
|
|
43
|
-
"webpack": "^5.
|
|
44
|
+
"vitest": "^4.1.9",
|
|
45
|
+
"webpack": "^5.107.2"
|
|
44
46
|
},
|
|
45
47
|
"engines": {
|
|
46
48
|
"node": ">=18",
|
|
47
|
-
"pnpm": ">=
|
|
49
|
+
"pnpm": ">=11.0.0"
|
|
48
50
|
},
|
|
49
51
|
"volta": {
|
|
50
52
|
"node": "24.15.0",
|
|
51
|
-
"pnpm": "
|
|
53
|
+
"pnpm": "11.0.6"
|
|
52
54
|
},
|
|
53
55
|
"license": "MIT",
|
|
56
|
+
"author": "Vincent Taverna <vinnymac@gmail.com> (https://github.com/vinnymac)",
|
|
57
|
+
"homepage": "https://github.com/vinnymac/dotenvx-next#readme",
|
|
58
|
+
"bugs": {
|
|
59
|
+
"url": "https://github.com/vinnymac/dotenvx-next/issues"
|
|
60
|
+
},
|
|
61
|
+
"keywords": [
|
|
62
|
+
"dotenvx",
|
|
63
|
+
"next.js",
|
|
64
|
+
"nextjs",
|
|
65
|
+
"env",
|
|
66
|
+
"secrets",
|
|
67
|
+
"encryption",
|
|
68
|
+
"webpack",
|
|
69
|
+
"turbopack",
|
|
70
|
+
"plugin"
|
|
71
|
+
],
|
|
54
72
|
"scripts": {
|
|
55
73
|
"build": "tsdown",
|
|
56
74
|
"dev": "tsdown --watch",
|
|
57
|
-
"typecheck": "tsgo --noEmit",
|
|
75
|
+
"typecheck": "tsgo --noEmit && tsc --noEmit -p tsconfig.test.json",
|
|
58
76
|
"lint": "biome lint .",
|
|
59
77
|
"format": "biome format --write .",
|
|
60
78
|
"test": "vitest run",
|
|
79
|
+
"test:coverage": "vitest run --coverage",
|
|
61
80
|
"changeset": "changeset",
|
|
62
81
|
"ci:version": "changeset version",
|
|
63
82
|
"ci:publish": "changeset publish"
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
//#region \0rolldown/runtime.js
|
|
3
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
4
|
-
//#endregion
|
|
5
|
-
//#region src/webpack-plugin.ts
|
|
6
|
-
const PLUGIN_NAME = "DotenvxNextWebpackPlugin";
|
|
7
|
-
const SERVER_RUNTIME_ASSETS = [
|
|
8
|
-
"webpack-runtime.js",
|
|
9
|
-
"../webpack-runtime.js",
|
|
10
|
-
"webpack-api-runtime.js",
|
|
11
|
-
"../webpack-api-runtime.js"
|
|
12
|
-
];
|
|
13
|
-
const EDGE_RUNTIME_ASSETS = [
|
|
14
|
-
"edge-runtime-webpack.js",
|
|
15
|
-
"webpack-runtime.js",
|
|
16
|
-
"../webpack-runtime.js"
|
|
17
|
-
];
|
|
18
|
-
var DotenvxWebpackPlugin = class {
|
|
19
|
-
constructor(options) {
|
|
20
|
-
this.options = options;
|
|
21
|
-
}
|
|
22
|
-
apply(compiler) {
|
|
23
|
-
const { env } = this.options;
|
|
24
|
-
const inlineSnippet = `(function(){if(typeof process!=='undefined'){Object.assign(process.env,${JSON.stringify(env)});}})();`;
|
|
25
|
-
const webpack = __require("webpack");
|
|
26
|
-
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
27
|
-
compilation.hooks.processAssets.tap({
|
|
28
|
-
name: PLUGIN_NAME,
|
|
29
|
-
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
|
|
30
|
-
}, () => {
|
|
31
|
-
const target = compiler.options.target;
|
|
32
|
-
const runtimeNames = (Array.isArray(target) ? target.some((t) => typeof t === "string" && t.includes("webworker")) : typeof target === "string" && target.includes("webworker")) ? EDGE_RUNTIME_ASSETS : SERVER_RUNTIME_ASSETS;
|
|
33
|
-
for (const assetName of runtimeNames) {
|
|
34
|
-
if (!compilation.getAsset(assetName)) continue;
|
|
35
|
-
compilation.updateAsset(assetName, (origSource) => {
|
|
36
|
-
const updatedSourceStr = [inlineSnippet, origSource.source().toString()].join("\n");
|
|
37
|
-
return new webpack.sources.RawSource(updatedSourceStr);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
//#endregion
|
|
45
|
-
export { __require as n, DotenvxWebpackPlugin as t };
|
|
46
|
-
|
|
47
|
-
//# sourceMappingURL=webpack-plugin-BmC1uBZp.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"webpack-plugin-BmC1uBZp.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 // eslint-disable-next-line @typescript-eslint/no-require-imports\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 // Determine compilation target from compiler options\n const target = compiler.options.target;\n const isEdge = Array.isArray(target)\n ? target.some(\n (t) => typeof t === 'string' && t.includes('webworker')\n )\n : typeof target === 'string' && target.includes('webworker');\n\n // Only inject into server-side compilations (not client bundles)\n const runtimeNames = isEdge\n ? EDGE_RUNTIME_ASSETS\n : SERVER_RUNTIME_ASSETS;\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;CACD;AAED,MAAM,sBAAsB;CAC1B;CACA;CACA;CACD;AAOD,IAAa,uBAAb,MAAkC;CAGhC,YAAY,SAAsC;AAChD,OAAK,UAAU;;CAGjB,MAAM,UAAiC;EACrC,MAAM,EAAE,QAAQ,KAAK;EAIrB,MAAM,gBAAgB,0EAA0E,KAAK,UAAU,IAAI,CAAC;EAIpH,MAAM,UAAA,UAAkB,UAAU;AAElC,WAAS,MAAM,gBAAgB,IAC7B,cACC,gBAAoC;AACnC,eAAY,MAAM,cAAc,IAC9B;IACE,MAAM;IACN,OAAO,QAAQ,YAAY;IAC5B,QACK;IAEJ,MAAM,SAAS,SAAS,QAAQ;IAQhC,MAAM,gBAPS,MAAM,QAAQ,OAAO,GAChC,OAAO,MACJ,MAAM,OAAO,MAAM,YAAY,EAAE,SAAS,YAAY,CACxD,GACD,OAAO,WAAW,YAAY,OAAO,SAAS,YAAY,IAI1D,sBACA;AAEJ,SAAK,MAAM,aAAa,cAAc;AACpC,SAAI,CAAC,YAAY,SAAS,UAAU,CAAE;AAEtC,iBAAY,YAAY,YAAY,eAAe;MACjD,MAAM,mBAAmB,CACvB,eACA,WAAW,QAAQ,CAAC,UAAU,CAC/B,CAAC,KAAK,KAAK;AACZ,aAAO,IAAI,QAAQ,QAAQ,UAAU,iBAAiB;OACtD;;KAGP;IAEJ"}
|
|
File without changes
|