diff --git a/example/src/runtime/server/plugins/plugin.ts b/example/src/runtime/server/plugins/plugin.ts new file mode 100644 index 00000000..9dbec430 --- /dev/null +++ b/example/src/runtime/server/plugins/plugin.ts @@ -0,0 +1 @@ +export default defineNitroPlugin(() => {}) diff --git a/src/commands/prepare.ts b/src/commands/prepare.ts index 50a227ad..d6135b4c 100644 --- a/src/commands/prepare.ts +++ b/src/commands/prepare.ts @@ -26,7 +26,7 @@ export default defineCommand({ autoImport: false, }, modules: [ - resolve(cwd, './src/module'), + resolve(cwd, './src'), function (_options, nuxt) { nuxt.hooks.hook('app:templates', (app) => { for (const template of app.templates) { diff --git a/test/prepare.spec.ts b/test/prepare.spec.ts new file mode 100644 index 00000000..527961a3 --- /dev/null +++ b/test/prepare.spec.ts @@ -0,0 +1,30 @@ +import { fileURLToPath } from 'node:url' +import { cp, mkdir, rm } from 'node:fs/promises' +import ts from 'typescript' +import { beforeAll, describe, expect, it } from 'vitest' +import { exec } from 'tinyexec' +import { dirname, join } from 'pathe' + +describe('module builder', () => { + const workspaceDir = fileURLToPath(new URL('..', import.meta.url)) + const exampleDir = fileURLToPath(new URL('../example', import.meta.url)) + const prepareRootDir = exampleDir.replace('example', '.temp-example-prepare') + + beforeAll(async () => { + await mkdir(dirname(prepareRootDir), { recursive: true }) + await rm(prepareRootDir, { force: true, recursive: true }) + await cp(exampleDir, prepareRootDir, { recursive: true }) + + await exec('pnpm', ['nuxt-module-build', 'prepare', prepareRootDir], { + nodeOptions: { cwd: workspaceDir }, + }) + }, 120 * 1000) + + it('includes runtime server plugin in resolved tsconfig files', async () => { + const serverTsconfigPath = join(prepareRootDir, '.nuxt/tsconfig.server.json') + const sourceFile = ts.readJsonConfigFile(serverTsconfigPath, ts.sys.readFile) + const parsed = ts.parseJsonSourceFileConfigFileContent(sourceFile, ts.sys, dirname(serverTsconfigPath)) + const expectedPluginPath = join(prepareRootDir, 'src/runtime/server/plugins/plugin.ts') + expect(parsed.fileNames).toContain(expectedPluginPath) + }) +})