Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/src/runtime/server/plugins/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default defineNitroPlugin(() => {})
2 changes: 1 addition & 1 deletion src/commands/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
30 changes: 30 additions & 0 deletions test/prepare.spec.ts
Original file line number Diff line number Diff line change
@@ -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')
Comment on lines +10 to +11

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Derive the temp workspace from the parent directory, not a string replace.

exampleDir.replace('example', '.temp-example-prepare') rewrites the first example anywhere in the absolute path. On a checkout path like /tmp/example-repos/module-builder/example, this points to /tmp/.temp-example-prepare-repos/module-builder/example, so the test copies and prepares the wrong directory. Build the sibling path from dirname(exampleDir) instead.

Proposed fix
 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')
+const prepareRootDir = join(dirname(exampleDir), '.temp-example-prepare')
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/prepare.spec.ts` around lines 9 - 10, The prepareRootDir calculation is
using string replace on exampleDir which can alter unrelated parts of the path;
change it to derive the temp workspace from the parent directory instead:
compute the parent dir (e.g. via path.dirname(exampleDir) or new URL('../',
exampleDir) semantics) and then build prepareRootDir by joining that parent with
'.temp-example-prepare' (referencing the existing exampleDir and prepareRootDir
identifiers so you replace the replace(...) expression with a dirname +
path.join/URL-based sibling path).


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 },
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}, 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)
})
})
Loading