@fantasticfour/dotenvx-next 0.1.3 → 0.2.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.
Files changed (41) hide show
  1. package/README.md +85 -0
  2. package/dist/next-env-compat.cjs +2 -2
  3. package/dist/next-env-compat.cjs.map +1 -1
  4. package/dist/plugin.cjs +21 -48
  5. package/dist/plugin.cjs.map +1 -1
  6. package/dist/plugin.d.cts +2 -7
  7. package/dist/plugin.d.cts.map +1 -1
  8. package/dist/plugin.d.mts +2 -7
  9. package/dist/plugin.d.mts.map +1 -1
  10. package/dist/plugin.mjs +20 -49
  11. package/dist/plugin.mjs.map +1 -1
  12. package/dist/{turbopack-inject-BgCxanwa.cjs → turbopack-inject-BElH61NN.cjs} +13 -15
  13. package/dist/turbopack-inject-BElH61NN.cjs.map +1 -0
  14. package/dist/turbopack-inject.cjs +1 -1
  15. package/dist/turbopack-inject.d.cts +4 -4
  16. package/dist/turbopack-inject.d.cts.map +1 -1
  17. package/dist/turbopack-inject.d.mts +4 -4
  18. package/dist/turbopack-inject.d.mts.map +1 -1
  19. package/dist/turbopack-inject.mjs +12 -14
  20. package/dist/turbopack-inject.mjs.map +1 -1
  21. package/dist/webpack-plugin-BmC1uBZp.mjs +47 -0
  22. package/dist/webpack-plugin-BmC1uBZp.mjs.map +1 -0
  23. package/dist/webpack-plugin.cjs +3 -11
  24. package/dist/webpack-plugin.cjs.map +1 -1
  25. package/dist/webpack-plugin.d.cts +7 -10
  26. package/dist/webpack-plugin.d.cts.map +1 -1
  27. package/dist/webpack-plugin.d.mts +7 -10
  28. package/dist/webpack-plugin.d.mts.map +1 -1
  29. package/dist/webpack-plugin.mjs +1 -51
  30. package/package.json +17 -19
  31. package/dist/chunk-y_GBKt04.mjs +0 -5
  32. package/dist/init.cjs +0 -16
  33. package/dist/init.cjs.map +0 -1
  34. package/dist/init.d.cts +0 -5
  35. package/dist/init.d.cts.map +0 -1
  36. package/dist/init.d.mts +0 -5
  37. package/dist/init.d.mts.map +0 -1
  38. package/dist/init.mjs +0 -18
  39. package/dist/init.mjs.map +0 -1
  40. package/dist/turbopack-inject-BgCxanwa.cjs.map +0 -1
  41. package/dist/webpack-plugin.mjs.map +0 -1
@@ -3,7 +3,7 @@ import path from "node:path";
3
3
  //#region src/turbopack-inject.ts
4
4
  /**
5
5
  * Turbopack runtime injection — patches fs.writeFile/fs.writeFileSync to intercept
6
- * turbopack's build output and prepend the dotenvx init bundle into runtime files.
6
+ * turbopack's build output and prepend the env inline snippet into runtime files.
7
7
  *
8
8
  * Turbopack writes `[turbopack]_runtime.js` directly (bypassing webpack), so we
9
9
  * can't use the processAssets hook. Instead we intercept fs writes and inject when
@@ -18,10 +18,10 @@ function isInjectedTurbopackRuntime() {
18
18
  return injectedTurbopackRuntime;
19
19
  }
20
20
  /**
21
- * Inject the dotenvx init bundle into turbopack runtime files.
21
+ * Inject the env inline snippet into turbopack runtime files.
22
22
  * Called after export-detail.json is written (turbopack compilation complete).
23
23
  */
24
- function injectDotenvxInitIntoTurbopackRuntime(nextDirPath, initSource) {
24
+ function injectDotenvxInitIntoTurbopackRuntime(nextDirPath, env) {
25
25
  if (injectedTurbopackRuntime) return;
26
26
  const serverRuntimeFiles = [];
27
27
  const edgeWrapperFiles = [];
@@ -35,11 +35,9 @@ function injectDotenvxInitIntoTurbopackRuntime(nextDirPath, initSource) {
35
35
  debugLog(`turbopack runtime injection: found ${serverRuntimeFiles.length} server runtime files,`, `${edgeWrapperFiles.length} edge wrapper files`);
36
36
  if (!serverRuntimeFiles.length) return;
37
37
  injectedTurbopackRuntime = true;
38
- const strippedSource = initSource.replace(/\s*\/\/# sourceMappingURL=\S+\s*$/m, "");
39
- const iifeWrap = (src) => `(function(exports,module){${src}\n})({},{exports:{}});`;
40
- const wrappedInit = iifeWrap(strippedSource);
38
+ const inlineSnippet = `(function(){if(typeof process!=='undefined'){Object.assign(process.env,${JSON.stringify(env)});}})();`;
41
39
  /**
42
- * Insert wrappedInit into source respecting ESM constraints.
40
+ * Insert inlineSnippet into source respecting ESM constraints.
43
41
  * ESM files require all top-level `import` declarations to appear before any
44
42
  * other statements, so we must insert after the last import line rather than
45
43
  * prepending to the file.
@@ -49,40 +47,40 @@ function injectDotenvxInitIntoTurbopackRuntime(nextDirPath, initSource) {
49
47
  let lastImportIdx = -1;
50
48
  for (let i = 0; i < lines.length; i++) if (/^import\s/.test(lines[i])) lastImportIdx = i;
51
49
  if (lastImportIdx >= 0) {
52
- lines.splice(lastImportIdx + 1, 0, wrappedInit);
50
+ lines.splice(lastImportIdx + 1, 0, inlineSnippet);
53
51
  return lines.join("\n");
54
52
  }
55
- return [wrappedInit, origSource].join("\n");
53
+ return [inlineSnippet, origSource].join("\n");
56
54
  };
57
55
  for (const runtimeFile of serverRuntimeFiles) {
58
56
  const origSource = fs.readFileSync(runtimeFile, "utf8");
59
57
  fs.writeFileSync(runtimeFile, insertIntoSource(origSource));
60
- debugLog(`injected dotenvx init into turbopack server runtime: ${runtimeFile}`);
58
+ debugLog(`injected env into turbopack server runtime: ${runtimeFile}`);
61
59
  }
62
60
  for (const wrapperFile of edgeWrapperFiles) {
63
61
  const origSource = fs.readFileSync(wrapperFile, "utf8");
64
62
  fs.writeFileSync(wrapperFile, insertIntoSource(origSource));
65
- debugLog(`injected dotenvx init into turbopack edge wrapper: ${wrapperFile}`);
63
+ debugLog(`injected env into turbopack edge wrapper: ${wrapperFile}`);
66
64
  }
67
65
  }
68
66
  /**
69
67
  * Patch global fs methods to detect when turbopack compilation completes,
70
68
  * then trigger runtime injection.
71
69
  */
72
- function activateTurbopackInjection(initSource) {
70
+ function activateTurbopackInjection(env) {
73
71
  debugLog("activating turbopack fs intercept");
74
72
  const origWriteFileFn = fs.promises.writeFile;
75
73
  fs.promises.writeFile = async function dotenvxPatchedWriteFile(...args) {
76
74
  const filePath = args[0].toString();
77
75
  debugLog("fs.promises.writeFile:", filePath);
78
- if (!injectedTurbopackRuntime && filePath.endsWith("/.next/export-detail.json")) injectDotenvxInitIntoTurbopackRuntime(filePath.substring(0, filePath.lastIndexOf("/")), initSource);
76
+ if (!injectedTurbopackRuntime && filePath.endsWith("/.next/export-detail.json")) injectDotenvxInitIntoTurbopackRuntime(filePath.substring(0, filePath.lastIndexOf("/")), env);
79
77
  return origWriteFileFn.apply(fs.promises, args);
80
78
  };
81
79
  const origWriteFileSyncFn = fs.writeFileSync;
82
80
  fs.writeFileSync = function dotenvxPatchedWriteFileSync(...args) {
83
81
  const filePath = args[0].toString();
84
82
  debugLog("fs.writeFileSync:", filePath);
85
- if (!injectedTurbopackRuntime && filePath.endsWith("/.next/export-detail.json")) injectDotenvxInitIntoTurbopackRuntime(filePath.substring(0, filePath.lastIndexOf("/")), initSource);
83
+ if (!injectedTurbopackRuntime && filePath.endsWith("/.next/export-detail.json")) injectDotenvxInitIntoTurbopackRuntime(filePath.substring(0, filePath.lastIndexOf("/")), env);
86
84
  origWriteFileSyncFn.apply(fs, args);
87
85
  };
88
86
  }
@@ -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 dotenvx init bundle 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 dotenvx init bundle into turbopack runtime files.\n * Called after export-detail.json is written (turbopack compilation complete).\n */\nexport function injectDotenvxInitIntoTurbopackRuntime(\n nextDirPath: string,\n initSource: 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 // Strip sourcemap comment — if it appears on the last line before the closing\n // `})({},{exports:{}});`, it would comment out the IIFE closer and cause\n // \"Unexpected end of input\" at parse time.\n const strippedSource = initSource.replace(\n /\\s*\\/\\/# sourceMappingURL=\\S+\\s*$/m,\n ''\n );\n\n // Wrap in IIFE to avoid symbol collisions (CJS bundle uses exports.X = ...)\n const iifeWrap = (src: string): string =>\n `(function(exports,module){${src}\\n})({},{exports:{}});`;\n\n const wrappedInit = iifeWrap(strippedSource);\n\n /**\n * Insert wrappedInit 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, wrappedInit);\n return lines.join('\\n');\n }\n // CJS or no imports — prepend as before\n return [wrappedInit, 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(\n `injected dotenvx init into turbopack server runtime: ${runtimeFile}`\n );\n }\n\n for (const wrapperFile of edgeWrapperFiles) {\n const origSource = fs.readFileSync(wrapperFile, 'utf8');\n fs.writeFileSync(wrapperFile, insertIntoSource(origSource));\n debugLog(\n `injected dotenvx init into turbopack edge wrapper: ${wrapperFile}`\n );\n }\n}\n\n/**\n * Patch global fs methods to detect when turbopack compilation completes,\n * then trigger runtime injection.\n */\nexport function activateTurbopackInjection(initSource: 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, initSource);\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, initSource);\n }\n\n origWriteFileSyncFn.apply(fs, args);\n };\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAS,SAAS,GAAG,MAAuB;AAC1C,KAAI,CAAC,QAAQ,IAAI,mBAAoB;AACrC,SAAQ,IAAI,kBAAkB,GAAG,KAAK;;AAGxC,IAAI,2BAA2B;AAE/B,SAAgB,6BAAsC;AACpD,QAAO;;;;;;AAOT,SAAgB,sCACd,aACA,YACM;AACN,KAAI,yBAA0B;CAE9B,MAAM,qBAA+B,EAAE;CACvC,MAAM,mBAA6B,EAAE;CAErC,MAAM,WAAW,QAAsB;AACrC,MAAI,CAAC,GAAG,WAAW,IAAI,CAAE;AACzB,OAAK,MAAM,SAAS,GAAG,YAAY,KAAK,EAAE,eAAe,MAAM,CAAC,CAC9D,KAAI,MAAM,aAAa,CACrB,SAAQ,KAAK,KAAK,KAAK,MAAM,KAAK,CAAC;WAC1B,MAAM,SAAS,yBACxB,oBAAmB,KAAK,KAAK,KAAK,KAAK,MAAM,KAAK,CAAC;WAEnD,MAAM,KAAK,SAAS,eAAe,IACnC,MAAM,KAAK,SAAS,MAAM,CAE1B,kBAAiB,KAAK,KAAK,KAAK,KAAK,MAAM,KAAK,CAAC;;AAKvD,SAAQ,YAAY;AAEpB,UACE,sCAAsC,mBAAmB,OAAO,yBAChE,GAAG,iBAAiB,OAAO,qBAC5B;AAED,KAAI,CAAC,mBAAmB,OAGtB;AAIF,4BAA2B;CAK3B,MAAM,iBAAiB,WAAW,QAChC,sCACA,GACD;CAGD,MAAM,YAAY,QAChB,6BAA6B,IAAI;CAEnC,MAAM,cAAc,SAAS,eAAe;;;;;;;CAQ5C,MAAM,oBAAoB,eAA+B;EACvD,MAAM,QAAQ,WAAW,MAAM,KAAK;EAEpC,IAAI,gBAAgB;AACpB,OAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,IAChC,KAAI,YAAY,KAAK,MAAM,GAAG,CAC5B,iBAAgB;AAGpB,MAAI,iBAAiB,GAAG;AAEtB,SAAM,OAAO,gBAAgB,GAAG,GAAG,YAAY;AAC/C,UAAO,MAAM,KAAK,KAAK;;AAGzB,SAAO,CAAC,aAAa,WAAW,CAAC,KAAK,KAAK;;AAG7C,MAAK,MAAM,eAAe,oBAAoB;EAC5C,MAAM,aAAa,GAAG,aAAa,aAAa,OAAO;AACvD,KAAG,cAAc,aAAa,iBAAiB,WAAW,CAAC;AAC3D,WACE,wDAAwD,cACzD;;AAGH,MAAK,MAAM,eAAe,kBAAkB;EAC1C,MAAM,aAAa,GAAG,aAAa,aAAa,OAAO;AACvD,KAAG,cAAc,aAAa,iBAAiB,WAAW,CAAC;AAC3D,WACE,sDAAsD,cACvD;;;;;;;AAQL,SAAgB,2BAA2B,YAA0B;AACnE,UAAS,oCAAoC;CAE7C,MAAM,kBAAkB,GAAG,SAAS;AACpC,IAAG,SAAS,YAAY,eAAe,wBACrC,GAAG,MACuC;EAC1C,MAAM,WAAW,KAAK,GAAG,UAAU;AACnC,WAAS,0BAA0B,SAAS;AAE5C,MACE,CAAC,4BACD,SAAS,SAAS,4BAA4B,CAG9C,uCADoB,SAAS,UAAU,GAAG,SAAS,YAAY,IAAI,CAClB,EAAE,WAAW;AAGhE,SAAO,gBAAgB,MAAM,GAAG,UAAU,KAAK;;CAGjD,MAAM,sBAAsB,GAAG;AAC/B,IAAG,gBAAgB,SAAS,4BAC1B,GAAG,MACG;EACN,MAAM,WAAW,KAAK,GAAG,UAAU;AACnC,WAAS,qBAAqB,SAAS;AAEvC,MACE,CAAC,4BACD,SAAS,SAAS,4BAA4B,CAG9C,uCADoB,SAAS,UAAU,GAAG,SAAS,YAAY,IAAI,CAClB,EAAE,WAAW;AAGhE,sBAAoB,MAAM,IAAI,KAAK"}
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;AAC1C,KAAI,CAAC,QAAQ,IAAI,mBAAoB;AACrC,SAAQ,IAAI,kBAAkB,GAAG,KAAK;;AAGxC,IAAI,2BAA2B;AAE/B,SAAgB,6BAAsC;AACpD,QAAO;;;;;;AAOT,SAAgB,sCACd,aACA,KACM;AACN,KAAI,yBAA0B;CAE9B,MAAM,qBAA+B,EAAE;CACvC,MAAM,mBAA6B,EAAE;CAErC,MAAM,WAAW,QAAsB;AACrC,MAAI,CAAC,GAAG,WAAW,IAAI,CAAE;AACzB,OAAK,MAAM,SAAS,GAAG,YAAY,KAAK,EAAE,eAAe,MAAM,CAAC,CAC9D,KAAI,MAAM,aAAa,CACrB,SAAQ,KAAK,KAAK,KAAK,MAAM,KAAK,CAAC;WAC1B,MAAM,SAAS,yBACxB,oBAAmB,KAAK,KAAK,KAAK,KAAK,MAAM,KAAK,CAAC;WAEnD,MAAM,KAAK,SAAS,eAAe,IACnC,MAAM,KAAK,SAAS,MAAM,CAE1B,kBAAiB,KAAK,KAAK,KAAK,KAAK,MAAM,KAAK,CAAC;;AAKvD,SAAQ,YAAY;AAEpB,UACE,sCAAsC,mBAAmB,OAAO,yBAChE,GAAG,iBAAiB,OAAO,qBAC5B;AAED,KAAI,CAAC,mBAAmB,OAGtB;AAIF,4BAA2B;CAG3B,MAAM,gBAAgB,0EAA0E,KAAK,UAAU,IAAI,CAAC;;;;;;;CAQpH,MAAM,oBAAoB,eAA+B;EACvD,MAAM,QAAQ,WAAW,MAAM,KAAK;EAEpC,IAAI,gBAAgB;AACpB,OAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,IAChC,KAAI,YAAY,KAAK,MAAM,GAAG,CAC5B,iBAAgB;AAGpB,MAAI,iBAAiB,GAAG;AAEtB,SAAM,OAAO,gBAAgB,GAAG,GAAG,cAAc;AACjD,UAAO,MAAM,KAAK,KAAK;;AAGzB,SAAO,CAAC,eAAe,WAAW,CAAC,KAAK,KAAK;;AAG/C,MAAK,MAAM,eAAe,oBAAoB;EAC5C,MAAM,aAAa,GAAG,aAAa,aAAa,OAAO;AACvD,KAAG,cAAc,aAAa,iBAAiB,WAAW,CAAC;AAC3D,WAAS,+CAA+C,cAAc;;AAGxE,MAAK,MAAM,eAAe,kBAAkB;EAC1C,MAAM,aAAa,GAAG,aAAa,aAAa,OAAO;AACvD,KAAG,cAAc,aAAa,iBAAiB,WAAW,CAAC;AAC3D,WAAS,6CAA6C,cAAc;;;;;;;AAQxE,SAAgB,2BAA2B,KAAmC;AAC5E,UAAS,oCAAoC;CAE7C,MAAM,kBAAkB,GAAG,SAAS;AACpC,IAAG,SAAS,YAAY,eAAe,wBACrC,GAAG,MACuC;EAC1C,MAAM,WAAW,KAAK,GAAG,UAAU;AACnC,WAAS,0BAA0B,SAAS;AAE5C,MACE,CAAC,4BACD,SAAS,SAAS,4BAA4B,CAG9C,uCADoB,SAAS,UAAU,GAAG,SAAS,YAAY,IAAI,CAClB,EAAE,IAAI;AAGzD,SAAO,gBAAgB,MAAM,GAAG,UAAU,KAAK;;CAGjD,MAAM,sBAAsB,GAAG;AAC/B,IAAG,gBAAgB,SAAS,4BAC1B,GAAG,MACG;EACN,MAAM,WAAW,KAAK,GAAG,UAAU;AACnC,WAAS,qBAAqB,SAAS;AAEvC,MACE,CAAC,4BACD,SAAS,SAAS,4BAA4B,CAG9C,uCADoB,SAAS,UAAU,GAAG,SAAS,YAAY,IAAI,CAClB,EAAE,IAAI;AAGzD,sBAAoB,MAAM,IAAI,KAAK"}
@@ -0,0 +1,47 @@
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
@@ -0,0 +1 @@
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"}
@@ -12,21 +12,13 @@ const EDGE_RUNTIME_ASSETS = [
12
12
  "webpack-runtime.js",
13
13
  "../webpack-runtime.js"
14
14
  ];
15
- /**
16
- * Replace the __DOTENVX_FILES__ placeholder in the init bundle with the actual
17
- * file list. The placeholder is a string literal in the source that gets swapped
18
- * with a JSON-encoded array string, so JSON.parse() in the init code yields string[].
19
- */
20
- function substituteFiles(initSource, files) {
21
- return initSource.replace(/'__DOTENVX_FILES__'/g, JSON.stringify(JSON.stringify(files)));
22
- }
23
15
  var DotenvxWebpackPlugin = class {
24
16
  constructor(options) {
25
17
  this.options = options;
26
18
  }
27
19
  apply(compiler) {
28
- const { files, initSource } = this.options;
29
- const wrappedInit = `(function(exports,module){${substituteFiles(initSource, files)}})({},{exports:{}});`;
20
+ const { env } = this.options;
21
+ const inlineSnippet = `(function(){if(typeof process!=='undefined'){Object.assign(process.env,${JSON.stringify(env)});}})();`;
30
22
  const webpack = require("webpack");
31
23
  compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
32
24
  compilation.hooks.processAssets.tap({
@@ -38,7 +30,7 @@ var DotenvxWebpackPlugin = class {
38
30
  for (const assetName of runtimeNames) {
39
31
  if (!compilation.getAsset(assetName)) continue;
40
32
  compilation.updateAsset(assetName, (origSource) => {
41
- const updatedSourceStr = [wrappedInit, origSource.source().toString()].join("\n");
33
+ const updatedSourceStr = [inlineSnippet, origSource.source().toString()].join("\n");
42
34
  return new webpack.sources.RawSource(updatedSourceStr);
43
35
  });
44
36
  }
@@ -1 +1 @@
1
- {"version":3,"file":"webpack-plugin.cjs","names":[],"sources":["../src/webpack-plugin.ts"],"sourcesContent":["/**\n * DotenvxWebpackPlugin — injects the dotenvx init bundle into webpack runtime files.\n *\n * We prepend the self-contained init bundle as raw JS so it runs before any\n * module code (before Prisma Pool, etc. can evaluate at import time).\n *\n * The __DOTENVX_FILES__ placeholder in the init source is replaced via direct\n * string substitution before injection — no DefinePlugin needed.\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 list of env file paths to pass to dotenvx at runtime */\n files: string[];\n /** Pre-compiled init bundle source (CJS) to prepend into runtime */\n initSource: string;\n}\n\n/**\n * Replace the __DOTENVX_FILES__ placeholder in the init bundle with the actual\n * file list. The placeholder is a string literal in the source that gets swapped\n * with a JSON-encoded array string, so JSON.parse() in the init code yields string[].\n */\nfunction substituteFiles(initSource: string, files: string[]): string {\n // The init source contains: const filesJson: string = '__DOTENVX_FILES__';\n // We replace the placeholder string literal with the actual JSON value.\n return initSource.replace(\n /'__DOTENVX_FILES__'/g,\n JSON.stringify(JSON.stringify(files)),\n );\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 { files, initSource } = this.options;\n\n // Substitute the file list into the init bundle once, before any hooks run\n const patchedInitSource = substituteFiles(initSource, files);\n\n // Wrap in IIFE to avoid symbol collisions (CJS bundle uses exports.X = ...)\n const wrappedInit = `(function(exports,module){${patchedInitSource}})({},{exports:{}});`;\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(PLUGIN_NAME, (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((t) => typeof t === 'string' && t.includes('webworker'))\n : typeof target === 'string' && target.includes('webworker');\n\n // Only inject into server-side compilations (not client bundles)\n const runtimeNames = isEdge ? EDGE_RUNTIME_ASSETS : SERVER_RUNTIME_ASSETS;\n\n for (const assetName of runtimeNames) {\n if (!compilation.getAsset(assetName)) continue;\n\n compilation.updateAsset(assetName, (origSource) => {\n const origSourceStr = origSource.source().toString();\n const updatedSourceStr = [wrappedInit, origSourceStr].join('\\n');\n return new webpack.sources.RawSource(updatedSourceStr);\n });\n }\n },\n );\n });\n }\n}\n"],"mappings":";;AAcA,MAAM,cAAc;AAGpB,MAAM,wBAAwB;CAC5B;CACA;CACA;CACA;CACD;AAED,MAAM,sBAAsB;CAC1B;CACA;CACA;CACD;;;;;;AAcD,SAAS,gBAAgB,YAAoB,OAAyB;AAGpE,QAAO,WAAW,QAChB,wBACA,KAAK,UAAU,KAAK,UAAU,MAAM,CAAC,CACtC;;AAGH,IAAa,uBAAb,MAAkC;CAGhC,YAAY,SAAsC;AAChD,OAAK,UAAU;;CAGjB,MAAM,UAAiC;EACrC,MAAM,EAAE,OAAO,eAAe,KAAK;EAMnC,MAAM,cAAc,6BAHM,gBAAgB,YAAY,MAGY,CAAC;EAInE,MAAM,UAAU,QAAQ,UAAU;AAElC,WAAS,MAAM,gBAAgB,IAAI,cAAc,gBAAoC;AACnF,eAAY,MAAM,cAAc,IAC9B;IACE,MAAM;IACN,OAAO,QAAQ,YAAY;IAC5B,QACK;IAEJ,MAAM,SAAS,SAAS,QAAQ;IAMhC,MAAM,gBALS,MAAM,QAAQ,OAAO,GAChC,OAAO,MAAM,MAAM,OAAO,MAAM,YAAY,EAAE,SAAS,YAAY,CAAC,GACpE,OAAO,WAAW,YAAY,OAAO,SAAS,YAAY,IAGhC,sBAAsB;AAEpD,SAAK,MAAM,aAAa,cAAc;AACpC,SAAI,CAAC,YAAY,SAAS,UAAU,CAAE;AAEtC,iBAAY,YAAY,YAAY,eAAe;MAEjD,MAAM,mBAAmB,CAAC,aADJ,WAAW,QAAQ,CAAC,UACU,CAAC,CAAC,KAAK,KAAK;AAChE,aAAO,IAAI,QAAQ,QAAQ,UAAU,iBAAiB;OACtD;;KAGP;IACD"}
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 // 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,UAAU,QAAQ,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"}
@@ -2,20 +2,17 @@ import * as _$webpack from "webpack";
2
2
 
3
3
  //#region src/webpack-plugin.d.ts
4
4
  /**
5
- * DotenvxWebpackPlugin — injects the dotenvx init bundle into webpack runtime files.
5
+ * DotenvxWebpackPlugin — injects resolved env vars into webpack runtime files.
6
6
  *
7
- * We prepend the self-contained init bundle as raw JS so it runs before any
8
- * module code (before Prisma Pool, etc. can evaluate at import time).
9
- *
10
- * The __DOTENVX_FILES__ placeholder in the init source is replaced via direct
11
- * string substitution before injection — no DefinePlugin needed.
7
+ * At build time, dotenvx has already decrypted the env files and provided the
8
+ * key-value pairs. We serialize them into a compact Object.assign(process.env, {...})
9
+ * snippet and prepend it to the webpack runtime so every value is available before
10
+ * any user module code runs (before Prisma Pool, etc. can evaluate at import time).
12
11
  */
13
12
  type WebpackCompiler = _$webpack.Compiler;
14
13
  interface DotenvxWebpackPluginOptions {
15
- /** Resolved list of env file paths to pass to dotenvx at runtime */
16
- files: string[];
17
- /** Pre-compiled init bundle source (CJS) to prepend into runtime */
18
- initSource: string;
14
+ /** Resolved env key-value pairs from dotenvx.config() at build time */
15
+ env: Record<string, string>;
19
16
  }
20
17
  declare class DotenvxWebpackPlugin {
21
18
  private readonly options;
@@ -1 +1 @@
1
- {"version":3,"file":"webpack-plugin.d.cts","names":[],"sources":["../src/webpack-plugin.ts"],"mappings":";;;;;;AAWuC;;;;;AAmBvC;KAnBK,eAAA,GAAe,SAAA,CAAqB,QAAA;AAAA,UAmBxB,2BAAA;EAEf;EAAA,KAAA;EAmBW;EAjBX,UAAA;AAAA;AAAA,cAiBW,oBAAA;EAAA,iBACM,OAAA;cAEL,OAAA,EAAS,2BAAA;EAIrB,KAAA,CAAM,QAAA,EAAU,eAAA;AAAA"}
1
+ {"version":3,"file":"webpack-plugin.d.cts","names":[],"sources":["../src/webpack-plugin.ts"],"mappings":";;;;;;AAUuC;;;;;KAAlC,eAAA,GAAe,SAAA,CAAqB,QAAA;AAAA,UAmBxB,2BAAA;;EAEf,GAAA,EAAK,MAAA;AAAA;AAAA,cAGM,oBAAA;EAAA,iBACM,OAAA;cAEL,OAAA,EAAS,2BAAA;EAIrB,KAAA,CAAM,QAAA,EAAU,eAAA;AAAA"}
@@ -2,20 +2,17 @@ import * as _$webpack from "webpack";
2
2
 
3
3
  //#region src/webpack-plugin.d.ts
4
4
  /**
5
- * DotenvxWebpackPlugin — injects the dotenvx init bundle into webpack runtime files.
5
+ * DotenvxWebpackPlugin — injects resolved env vars into webpack runtime files.
6
6
  *
7
- * We prepend the self-contained init bundle as raw JS so it runs before any
8
- * module code (before Prisma Pool, etc. can evaluate at import time).
9
- *
10
- * The __DOTENVX_FILES__ placeholder in the init source is replaced via direct
11
- * string substitution before injection — no DefinePlugin needed.
7
+ * At build time, dotenvx has already decrypted the env files and provided the
8
+ * key-value pairs. We serialize them into a compact Object.assign(process.env, {...})
9
+ * snippet and prepend it to the webpack runtime so every value is available before
10
+ * any user module code runs (before Prisma Pool, etc. can evaluate at import time).
12
11
  */
13
12
  type WebpackCompiler = _$webpack.Compiler;
14
13
  interface DotenvxWebpackPluginOptions {
15
- /** Resolved list of env file paths to pass to dotenvx at runtime */
16
- files: string[];
17
- /** Pre-compiled init bundle source (CJS) to prepend into runtime */
18
- initSource: string;
14
+ /** Resolved env key-value pairs from dotenvx.config() at build time */
15
+ env: Record<string, string>;
19
16
  }
20
17
  declare class DotenvxWebpackPlugin {
21
18
  private readonly options;
@@ -1 +1 @@
1
- {"version":3,"file":"webpack-plugin.d.mts","names":[],"sources":["../src/webpack-plugin.ts"],"mappings":";;;;;;AAWuC;;;;;AAmBvC;KAnBK,eAAA,GAAe,SAAA,CAAqB,QAAA;AAAA,UAmBxB,2BAAA;EAEf;EAAA,KAAA;EAmBW;EAjBX,UAAA;AAAA;AAAA,cAiBW,oBAAA;EAAA,iBACM,OAAA;cAEL,OAAA,EAAS,2BAAA;EAIrB,KAAA,CAAM,QAAA,EAAU,eAAA;AAAA"}
1
+ {"version":3,"file":"webpack-plugin.d.mts","names":[],"sources":["../src/webpack-plugin.ts"],"mappings":";;;;;;AAUuC;;;;;KAAlC,eAAA,GAAe,SAAA,CAAqB,QAAA;AAAA,UAmBxB,2BAAA;;EAEf,GAAA,EAAK,MAAA;AAAA;AAAA,cAGM,oBAAA;EAAA,iBACM,OAAA;cAEL,OAAA,EAAS,2BAAA;EAIrB,KAAA,CAAM,QAAA,EAAU,eAAA;AAAA"}
@@ -1,52 +1,2 @@
1
- import { t as __require } from "./chunk-y_GBKt04.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
- /**
16
- * Replace the __DOTENVX_FILES__ placeholder in the init bundle with the actual
17
- * file list. The placeholder is a string literal in the source that gets swapped
18
- * with a JSON-encoded array string, so JSON.parse() in the init code yields string[].
19
- */
20
- function substituteFiles(initSource, files) {
21
- return initSource.replace(/'__DOTENVX_FILES__'/g, JSON.stringify(JSON.stringify(files)));
22
- }
23
- var DotenvxWebpackPlugin = class {
24
- constructor(options) {
25
- this.options = options;
26
- }
27
- apply(compiler) {
28
- const { files, initSource } = this.options;
29
- const wrappedInit = `(function(exports,module){${substituteFiles(initSource, files)}})({},{exports:{}});`;
30
- const webpack = __require("webpack");
31
- compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
32
- compilation.hooks.processAssets.tap({
33
- name: PLUGIN_NAME,
34
- stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
35
- }, () => {
36
- const target = compiler.options.target;
37
- 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;
38
- for (const assetName of runtimeNames) {
39
- if (!compilation.getAsset(assetName)) continue;
40
- compilation.updateAsset(assetName, (origSource) => {
41
- const updatedSourceStr = [wrappedInit, origSource.source().toString()].join("\n");
42
- return new webpack.sources.RawSource(updatedSourceStr);
43
- });
44
- }
45
- });
46
- });
47
- }
48
- };
49
- //#endregion
1
+ import { t as DotenvxWebpackPlugin } from "./webpack-plugin-BmC1uBZp.mjs";
50
2
  export { DotenvxWebpackPlugin };
51
-
52
- //# sourceMappingURL=webpack-plugin.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fantasticfour/dotenvx-next",
3
- "version": "0.1.3",
3
+ "version": "0.2.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": {
@@ -8,11 +8,11 @@
8
8
  "url": "https://github.com/vinnymac/dotenvx-next.git"
9
9
  },
10
10
  "main": "dist/index.cjs",
11
- "module": "dist/index.js",
12
- "types": "dist/index.d.ts",
11
+ "module": "dist/index.mjs",
12
+ "types": "dist/index.d.mts",
13
13
  "exports": {
14
14
  ".": {
15
- "import": "./dist/index.js",
15
+ "import": "./dist/index.mjs",
16
16
  "require": "./dist/index.cjs"
17
17
  },
18
18
  "./next-env": {
@@ -22,18 +22,6 @@
22
22
  "files": [
23
23
  "dist"
24
24
  ],
25
- "scripts": {
26
- "build": "tsdown",
27
- "dev": "tsdown --watch",
28
- "typecheck": "tsgo --noEmit",
29
- "lint": "biome lint .",
30
- "format": "biome format --write .",
31
- "test": "vitest run",
32
- "changeset": "changeset",
33
- "ci:version": "changeset version",
34
- "ci:publish": "changeset publish",
35
- "prepare": "husky"
36
- },
37
25
  "peerDependencies": {
38
26
  "next": ">=14"
39
27
  },
@@ -59,10 +47,20 @@
59
47
  "node": ">=18",
60
48
  "pnpm": ">=10.0.0"
61
49
  },
62
- "packageManager": "pnpm@10.13.1",
63
50
  "volta": {
64
51
  "node": "24.15.0",
65
52
  "pnpm": "10.13.1"
66
53
  },
67
- "license": "MIT"
68
- }
54
+ "license": "MIT",
55
+ "scripts": {
56
+ "build": "tsdown",
57
+ "dev": "tsdown --watch",
58
+ "typecheck": "tsgo --noEmit",
59
+ "lint": "biome lint .",
60
+ "format": "biome format --write .",
61
+ "test": "vitest run",
62
+ "changeset": "changeset",
63
+ "ci:version": "changeset version",
64
+ "ci:publish": "changeset publish"
65
+ }
66
+ }
@@ -1,5 +0,0 @@
1
- import { createRequire } from "node:module";
2
- //#region \0rolldown/runtime.js
3
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
4
- //#endregion
5
- export { __require as t };
package/dist/init.cjs DELETED
@@ -1,16 +0,0 @@
1
- //#region src/init.ts
2
- if (typeof process !== "undefined" && !globalThis.__dotenvxNextInit) {
3
- globalThis.__dotenvxNextInit = true;
4
- const vercelEnv = process.env.VERCEL_ENV;
5
- if (vercelEnv === "production" || vercelEnv === "preview") {
6
- const files = JSON.parse("__DOTENVX_FILES__");
7
- require("@dotenvx/dotenvx").config({
8
- path: files,
9
- overload: true,
10
- quiet: true
11
- });
12
- }
13
- }
14
- //#endregion
15
-
16
- //# sourceMappingURL=init.cjs.map
package/dist/init.cjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"init.cjs","names":[],"sources":["../src/init.ts"],"sourcesContent":["/**\n * Runtime init bundle — injected into webpack/turbopack runtime before any user code runs.\n * This is a self-contained CJS-compatible snippet that runs in the webpack runtime context.\n *\n * The string '__DOTENVX_FILES__' is replaced by DotenvxWebpackPlugin via string substitution\n * with a JSON-encoded array of env file paths before this source is prepended to the runtime.\n *\n * Guard against double-init (worker processes, HMR) via a globalThis flag.\n */\n\n// Augment global type to include our guard flag\n// export {} makes this a module so `declare global` is valid\nexport {};\ndeclare global {\n var __dotenvxNextInit: boolean | undefined;\n}\n\nif (typeof process !== 'undefined' && !globalThis.__dotenvxNextInit) {\n globalThis.__dotenvxNextInit = true;\n\n const vercelEnv = process.env.VERCEL_ENV;\n\n if (vercelEnv === 'production' || vercelEnv === 'preview') {\n // '__DOTENVX_FILES__' is replaced at injection time with the actual JSON-encoded file list\n const files = JSON.parse('__DOTENVX_FILES__') as string[];\n\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n (require('@dotenvx/dotenvx') as typeof import('@dotenvx/dotenvx')).config({\n path: files,\n overload: true,\n quiet: true,\n });\n }\n}\n"],"mappings":";AAiBA,IAAI,OAAO,YAAY,eAAe,CAAC,WAAW,mBAAmB;AACnE,YAAW,oBAAoB;CAE/B,MAAM,YAAY,QAAQ,IAAI;AAE9B,KAAI,cAAc,gBAAgB,cAAc,WAAW;EAEzD,MAAM,QAAQ,KAAK,MAAM,oBAAoB;AAG5C,UAAQ,mBAAmB,CAAuC,OAAO;GACxE,MAAM;GACN,UAAU;GACV,OAAO;GACR,CAAC"}
package/dist/init.d.cts DELETED
@@ -1,5 +0,0 @@
1
- //#region src/init.d.ts
2
- declare global {
3
- var __dotenvxNextInit: boolean | undefined;
4
- } //# sourceMappingURL=init.d.ts.map
5
- //# sourceMappingURL=init.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"init.d.cts","names":[],"sources":["../src/init.ts"],"mappings":";QAaQ,MAAA;EAAA,IACF,iBAAA;AAAA"}
package/dist/init.d.mts DELETED
@@ -1,5 +0,0 @@
1
- //#region src/init.d.ts
2
- declare global {
3
- var __dotenvxNextInit: boolean | undefined;
4
- } //# sourceMappingURL=init.d.ts.map
5
- //# sourceMappingURL=init.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"init.d.mts","names":[],"sources":["../src/init.ts"],"mappings":";QAaQ,MAAA;EAAA,IACF,iBAAA;AAAA"}
package/dist/init.mjs DELETED
@@ -1,18 +0,0 @@
1
- import { t as __require } from "./chunk-y_GBKt04.mjs";
2
- //#region src/init.ts
3
- if (typeof process !== "undefined" && !globalThis.__dotenvxNextInit) {
4
- globalThis.__dotenvxNextInit = true;
5
- const vercelEnv = process.env.VERCEL_ENV;
6
- if (vercelEnv === "production" || vercelEnv === "preview") {
7
- const files = JSON.parse("__DOTENVX_FILES__");
8
- __require("@dotenvx/dotenvx").config({
9
- path: files,
10
- overload: true,
11
- quiet: true
12
- });
13
- }
14
- }
15
- //#endregion
16
- export {};
17
-
18
- //# sourceMappingURL=init.mjs.map
package/dist/init.mjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"init.mjs","names":[],"sources":["../src/init.ts"],"sourcesContent":["/**\n * Runtime init bundle — injected into webpack/turbopack runtime before any user code runs.\n * This is a self-contained CJS-compatible snippet that runs in the webpack runtime context.\n *\n * The string '__DOTENVX_FILES__' is replaced by DotenvxWebpackPlugin via string substitution\n * with a JSON-encoded array of env file paths before this source is prepended to the runtime.\n *\n * Guard against double-init (worker processes, HMR) via a globalThis flag.\n */\n\n// Augment global type to include our guard flag\n// export {} makes this a module so `declare global` is valid\nexport {};\ndeclare global {\n var __dotenvxNextInit: boolean | undefined;\n}\n\nif (typeof process !== 'undefined' && !globalThis.__dotenvxNextInit) {\n globalThis.__dotenvxNextInit = true;\n\n const vercelEnv = process.env.VERCEL_ENV;\n\n if (vercelEnv === 'production' || vercelEnv === 'preview') {\n // '__DOTENVX_FILES__' is replaced at injection time with the actual JSON-encoded file list\n const files = JSON.parse('__DOTENVX_FILES__') as string[];\n\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n (require('@dotenvx/dotenvx') as typeof import('@dotenvx/dotenvx')).config({\n path: files,\n overload: true,\n quiet: true,\n });\n }\n}\n"],"mappings":";;AAiBA,IAAI,OAAO,YAAY,eAAe,CAAC,WAAW,mBAAmB;AACnE,YAAW,oBAAoB;CAE/B,MAAM,YAAY,QAAQ,IAAI;AAE9B,KAAI,cAAc,gBAAgB,cAAc,WAAW;EAEzD,MAAM,QAAQ,KAAK,MAAM,oBAAoB;AAG7C,YAAS,mBAAmB,CAAuC,OAAO;GACxE,MAAM;GACN,UAAU;GACV,OAAO;GACR,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"turbopack-inject-BgCxanwa.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 dotenvx init bundle 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 dotenvx init bundle into turbopack runtime files.\n * Called after export-detail.json is written (turbopack compilation complete).\n */\nexport function injectDotenvxInitIntoTurbopackRuntime(\n nextDirPath: string,\n initSource: 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 // Strip sourcemap comment — if it appears on the last line before the closing\n // `})({},{exports:{}});`, it would comment out the IIFE closer and cause\n // \"Unexpected end of input\" at parse time.\n const strippedSource = initSource.replace(\n /\\s*\\/\\/# sourceMappingURL=\\S+\\s*$/m,\n ''\n );\n\n // Wrap in IIFE to avoid symbol collisions (CJS bundle uses exports.X = ...)\n const iifeWrap = (src: string): string =>\n `(function(exports,module){${src}\\n})({},{exports:{}});`;\n\n const wrappedInit = iifeWrap(strippedSource);\n\n /**\n * Insert wrappedInit 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, wrappedInit);\n return lines.join('\\n');\n }\n // CJS or no imports — prepend as before\n return [wrappedInit, 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(\n `injected dotenvx init into turbopack server runtime: ${runtimeFile}`\n );\n }\n\n for (const wrapperFile of edgeWrapperFiles) {\n const origSource = fs.readFileSync(wrapperFile, 'utf8');\n fs.writeFileSync(wrapperFile, insertIntoSource(origSource));\n debugLog(\n `injected dotenvx init into turbopack edge wrapper: ${wrapperFile}`\n );\n }\n}\n\n/**\n * Patch global fs methods to detect when turbopack compilation completes,\n * then trigger runtime injection.\n */\nexport function activateTurbopackInjection(initSource: 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, initSource);\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, initSource);\n }\n\n origWriteFileSyncFn.apply(fs, args);\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,SAAS,SAAS,GAAG,MAAuB;AAC1C,KAAI,CAAC,QAAQ,IAAI,mBAAoB;AACrC,SAAQ,IAAI,kBAAkB,GAAG,KAAK;;AAGxC,IAAI,2BAA2B;AAE/B,SAAgB,6BAAsC;AACpD,QAAO;;;;;;AAOT,SAAgB,sCACd,aACA,YACM;AACN,KAAI,yBAA0B;CAE9B,MAAM,qBAA+B,EAAE;CACvC,MAAM,mBAA6B,EAAE;CAErC,MAAM,WAAW,QAAsB;AACrC,MAAI,CAACA,QAAAA,QAAG,WAAW,IAAI,CAAE;AACzB,OAAK,MAAM,SAASA,QAAAA,QAAG,YAAY,KAAK,EAAE,eAAe,MAAM,CAAC,CAC9D,KAAI,MAAM,aAAa,CACrB,SAAQC,UAAAA,QAAK,KAAK,KAAK,MAAM,KAAK,CAAC;WAC1B,MAAM,SAAS,yBACxB,oBAAmB,KAAKA,UAAAA,QAAK,KAAK,KAAK,MAAM,KAAK,CAAC;WAEnD,MAAM,KAAK,SAAS,eAAe,IACnC,MAAM,KAAK,SAAS,MAAM,CAE1B,kBAAiB,KAAKA,UAAAA,QAAK,KAAK,KAAK,MAAM,KAAK,CAAC;;AAKvD,SAAQ,YAAY;AAEpB,UACE,sCAAsC,mBAAmB,OAAO,yBAChE,GAAG,iBAAiB,OAAO,qBAC5B;AAED,KAAI,CAAC,mBAAmB,OAGtB;AAIF,4BAA2B;CAK3B,MAAM,iBAAiB,WAAW,QAChC,sCACA,GACD;CAGD,MAAM,YAAY,QAChB,6BAA6B,IAAI;CAEnC,MAAM,cAAc,SAAS,eAAe;;;;;;;CAQ5C,MAAM,oBAAoB,eAA+B;EACvD,MAAM,QAAQ,WAAW,MAAM,KAAK;EAEpC,IAAI,gBAAgB;AACpB,OAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,IAChC,KAAI,YAAY,KAAK,MAAM,GAAG,CAC5B,iBAAgB;AAGpB,MAAI,iBAAiB,GAAG;AAEtB,SAAM,OAAO,gBAAgB,GAAG,GAAG,YAAY;AAC/C,UAAO,MAAM,KAAK,KAAK;;AAGzB,SAAO,CAAC,aAAa,WAAW,CAAC,KAAK,KAAK;;AAG7C,MAAK,MAAM,eAAe,oBAAoB;EAC5C,MAAM,aAAaD,QAAAA,QAAG,aAAa,aAAa,OAAO;AACvD,UAAA,QAAG,cAAc,aAAa,iBAAiB,WAAW,CAAC;AAC3D,WACE,wDAAwD,cACzD;;AAGH,MAAK,MAAM,eAAe,kBAAkB;EAC1C,MAAM,aAAaA,QAAAA,QAAG,aAAa,aAAa,OAAO;AACvD,UAAA,QAAG,cAAc,aAAa,iBAAiB,WAAW,CAAC;AAC3D,WACE,sDAAsD,cACvD;;;;;;;AAQL,SAAgB,2BAA2B,YAA0B;AACnE,UAAS,oCAAoC;CAE7C,MAAM,kBAAkBA,QAAAA,QAAG,SAAS;AACpC,SAAA,QAAG,SAAS,YAAY,eAAe,wBACrC,GAAG,MACuC;EAC1C,MAAM,WAAW,KAAK,GAAG,UAAU;AACnC,WAAS,0BAA0B,SAAS;AAE5C,MACE,CAAC,4BACD,SAAS,SAAS,4BAA4B,CAG9C,uCADoB,SAAS,UAAU,GAAG,SAAS,YAAY,IAAI,CAClB,EAAE,WAAW;AAGhE,SAAO,gBAAgB,MAAMA,QAAAA,QAAG,UAAU,KAAK;;CAGjD,MAAM,sBAAsBA,QAAAA,QAAG;AAC/B,SAAA,QAAA,gBAAmB,SAAS,4BAC1B,GAAG,MACG;EACN,MAAM,WAAW,KAAK,GAAG,UAAU;AACnC,WAAS,qBAAqB,SAAS;AAEvC,MACE,CAAC,4BACD,SAAS,SAAS,4BAA4B,CAG9C,uCADoB,SAAS,UAAU,GAAG,SAAS,YAAY,IAAI,CAClB,EAAE,WAAW;AAGhE,sBAAoB,MAAMA,QAAAA,SAAI,KAAK"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"webpack-plugin.mjs","names":[],"sources":["../src/webpack-plugin.ts"],"sourcesContent":["/**\n * DotenvxWebpackPlugin — injects the dotenvx init bundle into webpack runtime files.\n *\n * We prepend the self-contained init bundle as raw JS so it runs before any\n * module code (before Prisma Pool, etc. can evaluate at import time).\n *\n * The __DOTENVX_FILES__ placeholder in the init source is replaced via direct\n * string substitution before injection — no DefinePlugin needed.\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 list of env file paths to pass to dotenvx at runtime */\n files: string[];\n /** Pre-compiled init bundle source (CJS) to prepend into runtime */\n initSource: string;\n}\n\n/**\n * Replace the __DOTENVX_FILES__ placeholder in the init bundle with the actual\n * file list. The placeholder is a string literal in the source that gets swapped\n * with a JSON-encoded array string, so JSON.parse() in the init code yields string[].\n */\nfunction substituteFiles(initSource: string, files: string[]): string {\n // The init source contains: const filesJson: string = '__DOTENVX_FILES__';\n // We replace the placeholder string literal with the actual JSON value.\n return initSource.replace(\n /'__DOTENVX_FILES__'/g,\n JSON.stringify(JSON.stringify(files)),\n );\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 { files, initSource } = this.options;\n\n // Substitute the file list into the init bundle once, before any hooks run\n const patchedInitSource = substituteFiles(initSource, files);\n\n // Wrap in IIFE to avoid symbol collisions (CJS bundle uses exports.X = ...)\n const wrappedInit = `(function(exports,module){${patchedInitSource}})({},{exports:{}});`;\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(PLUGIN_NAME, (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((t) => typeof t === 'string' && t.includes('webworker'))\n : typeof target === 'string' && target.includes('webworker');\n\n // Only inject into server-side compilations (not client bundles)\n const runtimeNames = isEdge ? EDGE_RUNTIME_ASSETS : SERVER_RUNTIME_ASSETS;\n\n for (const assetName of runtimeNames) {\n if (!compilation.getAsset(assetName)) continue;\n\n compilation.updateAsset(assetName, (origSource) => {\n const origSourceStr = origSource.source().toString();\n const updatedSourceStr = [wrappedInit, origSourceStr].join('\\n');\n return new webpack.sources.RawSource(updatedSourceStr);\n });\n }\n },\n );\n });\n }\n}\n"],"mappings":";;AAcA,MAAM,cAAc;AAGpB,MAAM,wBAAwB;CAC5B;CACA;CACA;CACA;CACD;AAED,MAAM,sBAAsB;CAC1B;CACA;CACA;CACD;;;;;;AAcD,SAAS,gBAAgB,YAAoB,OAAyB;AAGpE,QAAO,WAAW,QAChB,wBACA,KAAK,UAAU,KAAK,UAAU,MAAM,CAAC,CACtC;;AAGH,IAAa,uBAAb,MAAkC;CAGhC,YAAY,SAAsC;AAChD,OAAK,UAAU;;CAGjB,MAAM,UAAiC;EACrC,MAAM,EAAE,OAAO,eAAe,KAAK;EAMnC,MAAM,cAAc,6BAHM,gBAAgB,YAAY,MAGY,CAAC;EAInE,MAAM,UAAA,UAAkB,UAAU;AAElC,WAAS,MAAM,gBAAgB,IAAI,cAAc,gBAAoC;AACnF,eAAY,MAAM,cAAc,IAC9B;IACE,MAAM;IACN,OAAO,QAAQ,YAAY;IAC5B,QACK;IAEJ,MAAM,SAAS,SAAS,QAAQ;IAMhC,MAAM,gBALS,MAAM,QAAQ,OAAO,GAChC,OAAO,MAAM,MAAM,OAAO,MAAM,YAAY,EAAE,SAAS,YAAY,CAAC,GACpE,OAAO,WAAW,YAAY,OAAO,SAAS,YAAY,IAGhC,sBAAsB;AAEpD,SAAK,MAAM,aAAa,cAAc;AACpC,SAAI,CAAC,YAAY,SAAS,UAAU,CAAE;AAEtC,iBAAY,YAAY,YAAY,eAAe;MAEjD,MAAM,mBAAmB,CAAC,aADJ,WAAW,QAAQ,CAAC,UACU,CAAC,CAAC,KAAK,KAAK;AAChE,aAAO,IAAI,QAAQ,QAAQ,UAAU,iBAAiB;OACtD;;KAGP;IACD"}