From a0da91839aec1d53941078eaf0c1338ddbd8054b Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 26 Oct 2021 15:42:10 +0100 Subject: [PATCH] fix(kit): ensure directory exists before writing virtual template (#1473) --- packages/kit/src/module/define.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/kit/src/module/define.ts b/packages/kit/src/module/define.ts index 06738d73b8..8229025156 100644 --- a/packages/kit/src/module/define.ts +++ b/packages/kit/src/module/define.ts @@ -2,6 +2,7 @@ import { promises as fsp } from 'fs' import defu from 'defu' import { applyDefaults } from 'untyped' import consola from 'consola' +import { dirname } from 'pathe' import { useNuxt, nuxtCtx } from '../nuxt' import type { Nuxt, NuxtTemplate } from '../types/nuxt' import type { NuxtModule, LegacyNuxtModule, ModuleOptions } from '../types/module' @@ -89,6 +90,7 @@ export function defineNuxtModule (input: NuxtMod } for await (const template of virtualTemplates) { const contents = await compileTemplate({ ...template, src: '' }, context) + await fsp.mkdir(dirname(template.dst), { recursive: true }) await fsp.writeFile(template.dst, contents) } })