From 2dab9b34f8df50ec60056bceb12c68d0a39484d0 Mon Sep 17 00:00:00 2001 From: Chris Marsh Date: Fri, 27 Sep 2024 10:13:57 +0100 Subject: [PATCH 1/2] feat(index.js): use runtimeConfig to set options Nuxt allows you to use environment variables through useRuntimeConfig. This is preferable when you want different settings in different environments, and want to use secrets (e.g. SMTP username and password) without exposing them in nuxt.config.ts. This change adds `runtimeConfig.mail` options to the options object. fix #120 --- src/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 467fd27..1c2946b 100644 --- a/src/index.js +++ b/src/index.js @@ -22,7 +22,14 @@ const moduleName = parsePackagejsonName(packageConfig.name).fullName; export default function (moduleOptions, nuxt) { nuxt = nuxt || this; - const options = { ...nuxt.options.mail, ...moduleOptions }; + + const runtimeConfig = useRuntimeConfig(); + + const options = { + ...runtimeConfig.mail, + ...nuxt.options.mail, + ...moduleOptions, + }; if (!options.smtp) { throw new Error('SMTP config is missing.'); From 2f6f53c9bff37d15d27e6c08cd6b7c70a61222c1 Mon Sep 17 00:00:00 2001 From: Chris Marsh Date: Mon, 30 Sep 2024 11:48:24 +0100 Subject: [PATCH 2/2] fix: use useRuntimeConfig() for Nuxt 3 --- src/index.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/index.js b/src/index.js index 1c2946b..961728b 100644 --- a/src/index.js +++ b/src/index.js @@ -5,6 +5,7 @@ import { addTemplate, createResolver, isNuxt3 as isNuxt3Try, + useRuntimeConfig, } from '@nuxt/kit'; import express from 'express'; import fs from 'fs-extra'; @@ -22,8 +23,17 @@ const moduleName = parsePackagejsonName(packageConfig.name).fullName; export default function (moduleOptions, nuxt) { nuxt = nuxt || this; + let isNuxt3 = true; + + try { + isNuxt3 = isNuxt3Try(); + } catch { + isNuxt3 = false; + } - const runtimeConfig = useRuntimeConfig(); + const runtimeConfig = isNuxt3 + ? useRuntimeConfig() + : nuxt.options.privateRuntimeConfig; const options = { ...runtimeConfig.mail, @@ -50,14 +60,6 @@ export default function (moduleOptions, nuxt) { throw new Error('You have to provide to/cc/bcc in all configs.'); } - let isNuxt3 = true; - - try { - isNuxt3 = isNuxt3Try(); - } catch { - isNuxt3 = false; - } - if (isNuxt3) { addTemplate({ filename: P.join(moduleName, 'options.mjs'),