Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
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
33 changes: 33 additions & 0 deletions test/prepare.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { fileURLToPath } from 'node:url'
import { cp, mkdir, readFile, rm } from 'node:fs/promises'
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 },

Check failure on line 18 in test/prepare.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 6 spaces but found 4
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}, 120 * 1000)

it('includes module runtime in generated server tsconfig', async () => {
const serverTsconfig = await readFile(join(prepareRootDir, '.nuxt/tsconfig.server.json'), 'utf-8')
const parsed = JSON.parse(serverTsconfig) as { include?: unknown }
const include = Array.isArray(parsed.include) ? parsed.include : []

expect(
include.some(

Check failure on line 28 in test/prepare.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 6 spaces but found 4
value => typeof value === 'string' && value.includes('../src/runtime'),
),

Check failure on line 30 in test/prepare.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 6 spaces but found 4
).toBe(true)
})
})
Loading