@fantasticfour/dotenvx-next 0.3.0 → 0.4.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/dist/plugin.cjs +1 -1
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts +5 -0
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts +5 -0
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +1 -1
- package/dist/plugin.mjs.map +1 -1
- package/package.json +1 -1
package/dist/plugin.cjs
CHANGED
|
@@ -44,7 +44,7 @@ async function dotenvxNextConfigFn(nextConfig, options, phase, defaults) {
|
|
|
44
44
|
const isTurbopack = !!(process.env.TURBOPACK || process.env.TURBOPACK_DEV || process.env.TURBOPACK_BUILD || process.env.npm_config_turbopack);
|
|
45
45
|
const { parsed: env = {} } = resolvedFiles.length ? _dotenvx_dotenvx.default.config({
|
|
46
46
|
path: resolvedFiles,
|
|
47
|
-
overload: true,
|
|
47
|
+
overload: options.overload ?? true,
|
|
48
48
|
quiet: true
|
|
49
49
|
}) : { parsed: {} };
|
|
50
50
|
debugLog(`phase=${phase}, isTurbopack=${isTurbopack}, resolvedFiles=${JSON.stringify(resolvedFiles)}, envKeys=${Object.keys(env).join(",")}`);
|
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({
|
|
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,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
CHANGED
|
@@ -11,6 +11,11 @@ interface DotenvxNextOptions {
|
|
|
11
11
|
* Directory where env files live. Defaults to process.cwd().
|
|
12
12
|
*/
|
|
13
13
|
envDir?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Whether to overload (overwrite) existing process.env values with the loaded
|
|
16
|
+
* env files. Defaults to true.
|
|
17
|
+
*/
|
|
18
|
+
overload?: boolean;
|
|
14
19
|
}
|
|
15
20
|
type NextConfigFn = (phase: string, defaults: {
|
|
16
21
|
defaultConfig: NextConfig;
|
package/dist/plugin.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;UAyBiB,kBAAA;
|
|
1
|
+
{"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;UAyBiB,kBAAA;EAqCC;;;;EAhChB,KAAA;EA+B2B;;;EA1B3B,MAAA;EA2BwB;;AAAU;AAwFpC;EA7GE,QAAA;AAAA;AAAA,KAkBG,YAAA,IACH,KAAA,UACA,QAAA;EAAY,aAAA,EAAe,UAAA;AAAA,MACxB,UAAA,GAAa,OAAA,CAAQ,UAAA;AAAA,iBAwFV,WAAA,CACd,UAAA,EAAY,UAAA,GAAa,YAAA,EACzB,OAAA,GAAS,kBAAA,GACR,YAAA"}
|
package/dist/plugin.d.mts
CHANGED
|
@@ -11,6 +11,11 @@ interface DotenvxNextOptions {
|
|
|
11
11
|
* Directory where env files live. Defaults to process.cwd().
|
|
12
12
|
*/
|
|
13
13
|
envDir?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Whether to overload (overwrite) existing process.env values with the loaded
|
|
16
|
+
* env files. Defaults to true.
|
|
17
|
+
*/
|
|
18
|
+
overload?: boolean;
|
|
14
19
|
}
|
|
15
20
|
type NextConfigFn = (phase: string, defaults: {
|
|
16
21
|
defaultConfig: NextConfig;
|
package/dist/plugin.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;UAyBiB,kBAAA;
|
|
1
|
+
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;UAyBiB,kBAAA;EAqCC;;;;EAhChB,KAAA;EA+B2B;;;EA1B3B,MAAA;EA2BwB;;AAAU;AAwFpC;EA7GE,QAAA;AAAA;AAAA,KAkBG,YAAA,IACH,KAAA,UACA,QAAA;EAAY,aAAA,EAAe,UAAA;AAAA,MACxB,UAAA,GAAa,OAAA,CAAQ,UAAA;AAAA,iBAwFV,WAAA,CACd,UAAA,EAAY,UAAA,GAAa,YAAA,EACzB,OAAA,GAAS,kBAAA,GACR,YAAA"}
|
package/dist/plugin.mjs
CHANGED
|
@@ -40,7 +40,7 @@ async function dotenvxNextConfigFn(nextConfig, options, phase, defaults) {
|
|
|
40
40
|
const isTurbopack = !!(process.env.TURBOPACK || process.env.TURBOPACK_DEV || process.env.TURBOPACK_BUILD || process.env.npm_config_turbopack);
|
|
41
41
|
const { parsed: env = {} } = resolvedFiles.length ? dotenvx.config({
|
|
42
42
|
path: resolvedFiles,
|
|
43
|
-
overload: true,
|
|
43
|
+
overload: options.overload ?? true,
|
|
44
44
|
quiet: true
|
|
45
45
|
}) : { parsed: {} };
|
|
46
46
|
debugLog(`phase=${phase}, isTurbopack=${isTurbopack}, resolvedFiles=${JSON.stringify(resolvedFiles)}, envKeys=${Object.keys(env).join(",")}`);
|
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({
|
|
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,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fantasticfour/dotenvx-next",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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": {
|