Skip to content

Conversation

@danielroe
Copy link
Member

🔗 Linked issue

closes #32229

📚 Description

remake of #32229 as I could not push changes.

Copilot AI review requested due to automatic review settings June 2, 2025 00:20
@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses the caching layer in Nuxt by adjusting the way the working directory and file matching patterns are determined for hashing. The changes include updating the cwd fallback to use layer.config.srcDir if available and reworking the file pattern matching logic.

  • Use layer.config.srcDir as the primary cwd with a fallback to layer.cwd.
  • Adjust and simplify the file matching patterns for computing the hash.
Comments suppressed due to low confidence (1)

packages/nuxt/src/core/cache.ts:23

  • Replacing join(relative(layer.cwd, layer.config.srcDir), '') with simply '' changes the file matching scope. Please confirm that matching all files in the current working directory (which may now be layer.config.srcDir) is the intended behavior, particularly when layer.config.srcDir differs from layer.cwd.
        '**',

@danielroe danielroe changed the title Fix/build cache layer cwd fix(nuxt): use correct cwd for layers in buildCache handling Jun 2, 2025
@github-actions github-actions bot added the 3.x label Jun 2, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jun 2, 2025

Walkthrough

The update revises the logic in the getVueHash function for determining the current working directory (cwd) and the file matching patterns used in the getHashes call. The new implementation sets cwd to layer.config.srcDir if available, otherwise defaults to layer.cwd. The file inclusion pattern is simplified to include all files ('**'), and exclusion patterns for server and public directories are now calculated relative to the resolved srcDir instead of layer.cwd. The exclusion patterns for node_modules and nuxt.config.* remain unchanged. No changes were made to exported or public entity declarations.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e26059c and ca8d784.

📒 Files selected for processing (1)
  • packages/nuxt/src/core/cache.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: codeql (actions)
  • GitHub Check: build
  • GitHub Check: code
  • GitHub Check: lint-docs
🔇 Additional comments (2)
packages/nuxt/src/core/cache.ts (2)

19-19: LGTM: Improved consistency in working directory determination.

The fallback logic layer.config.srcDir || layer.cwd provides a more predictable way to determine the working directory, which should help address the cache layer cwd issues mentioned in the PR.


20-29:

Details

✅ Verification successful

Verify exclusion patterns work correctly with relative paths.

The refactored patterns function improves consistency by calculating exclusions relative to srcDir. However, there's a potential issue when srcDir is a subdirectory of layer.cwd and server/public directories are in layer.cwd.

In such cases, relative(srcDir, serverDir) might return paths like ../server, resulting in exclusion patterns like !../server/**. Some glob implementations may not handle .. in exclusion patterns correctly.

Please verify this works correctly with various directory structures:


🏁 Script executed:

#!/bin/bash
# Description: Test glob patterns with relative paths that go up directories
# Expected: Verify that exclusion patterns with '..' work correctly

# Create test directory structure
mkdir -p test-structure/src test-structure/server test-structure/public
echo "test file" > test-structure/src/test.js
echo "server file" > test-structure/server/index.js
echo "public file" > test-structure/public/style.css

# Test glob pattern from src directory with exclusion going up
cd test-structure/src
echo "Testing glob patterns from src directory:"
node -e "
const { glob } = require('tinyglobby');
const path = require('path');
const patterns = [
  '**',
  '!../server/**',
  '!../public/**'
];
glob(patterns, { cwd: process.cwd() }).then(files => {
  console.log('Matched files:', files);
  console.log('Should only include files in src directory');
});
"

# Cleanup
cd ../..
rm -rf test-structure

Length of output: 1515


No changes needed for relative exclusion patterns

Relative exclusion patterns like !../server/** won’t cause any glob errors because the glob run-time is rooted at srcDir and glob implementations (e.g. fast-glob/globby) do not traverse outside their cwd. Any “..” segments simply won’t match files and have no adverse effect. You can safely keep the current implementation.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jun 2, 2025

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@32260

nuxt

npm i https://pkg.pr.new/nuxt@32260

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@32260

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@32260

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@32260

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@32260

commit: ca8d784

@codspeed-hq
Copy link

codspeed-hq bot commented Jun 2, 2025

CodSpeed Performance Report

Merging #32260 will not alter performance

Comparing fix/build-cache-layer-cwd (ca8d784) with main (e26059c)

Summary

✅ 10 untouched benchmarks

@danielroe danielroe changed the title fix(nuxt): use correct cwd for layers in buildCache handling fix(nuxt): make patterns relative to srcDir in buildCache Jun 2, 2025
@danielroe danielroe merged commit b4269eb into main Jun 2, 2025
86 of 88 checks passed
@danielroe danielroe deleted the fix/build-cache-layer-cwd branch June 2, 2025 06:07
@github-actions github-actions bot mentioned this pull request Jun 2, 2025
@github-actions github-actions bot mentioned this pull request Jun 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants