Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Vite version to v6 #1381

Merged
merged 7 commits into from
Jan 14, 2025
Merged

Update Vite version to v6 #1381

merged 7 commits into from
Jan 14, 2025

Conversation

nmajor25
Copy link
Contributor

@nmajor25 nmajor25 commented Jan 13, 2025

Shortcut Story ID: [sc-57765]

Summary by CodeRabbit

  • Dependencies

    • Updated multiple package versions, including Vite, Cypress, PWA plugin, and Stylelint
    • Added js-yaml dependency
    • Removed @modyfi/vite-plugin-yaml
  • Configuration

    • Introduced a custom YAML plugin for Vite
    • Updated Vite configuration to use the new local YAML plugin
    • Added legacy API option for SCSS preprocessor
  • Styles

    • Removed the overrides stylesheet for form elements, eliminating specific browser adjustments for consistent styling.
    • Removed import statements for the overrides stylesheet in core styles.

…plugin-stylelint npm packages

To support vite 6
…external @modyfi/vite-plugin-yaml npm package

@modyfi/vite-plugin-yaml npm package is no longer being maintained and is blocking us from moving to vite v6
Temporarily setting `css.preprocessorOptions.scss.api: 'legacy'` for vite 6 to work. We will remove that at a later date when we update sass to use the modern js api
@nmajor25 nmajor25 requested a review from paulfalgout January 13, 2025 21:30
Copy link

coderabbitai bot commented Jan 13, 2025

Walkthrough

A custom Vite YAML plugin has been developed to replace an external dependency. The project has upgraded several development dependencies, including Vite and related plugins. A new local YAML transformation plugin is introduced in config/vite-plugin-yaml.js, which uses js-yaml to parse and convert YAML files into JavaScript modules. The Vite configuration has been updated to use this local plugin and modify SCSS preprocessor settings. Additionally, SCSS styles for form elements have been removed to simplify styling across browsers.

Changes

File Change Summary
config/vite-plugin-yaml.js New Vite plugin created to transform YAML files into JavaScript modules using js-yaml.
package.json - Upgraded @cypress/vite-dev-server to ^6.0.0
- Removed @modyfi/vite-plugin-yaml
- Added js-yaml
- Updated Vite and related plugins.
vite.config.js - Switched YAML plugin import to local implementation
- Added api: 'legacy' to SCSS preprocessor options
src/scss/core/_overrides.scss Removed entire SCSS file that contained browser-specific styles for form elements.
src/scss/outreach-core.scss Removed import statement for core/overrides stylesheet.
src/scss/provider-core.scss Removed import statement for core/overrides stylesheet.
config/vite-plugin-handlebars-loader.js Modified error handling in load method to ensure explicit return of null on errors.

Sequence Diagram

sequenceDiagram
    participant V as Vite
    participant P as YAML Plugin
    participant Y as js-yaml
    
    V->>P: Process YAML file
    P->>Y: Parse YAML content
    Y-->>P: Return parsed data
    P-->>V: Provide transformed module
Loading

Poem

🐰 A YAML plugin, fresh and bright,
Transforming configs with rabbit might!
From external to homegrown delight,
Our code now dances with pure insight.
Vite config, leap and take flight! 🚀

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
config/vite-plugin-yaml.js (1)

1-4: Consider using more specific imports.

Instead of importing the entire load function, consider using a more specific import to potentially reduce bundle size.

-import { load } from 'js-yaml';
+import { load as yamlLoad } from 'js-yaml';
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4582fb3 and fb11e80.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • config/vite-plugin-yaml.js (1 hunks)
  • package.json (3 hunks)
  • vite.config.js (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: test-build
🔇 Additional comments (3)
vite.config.js (1)

33-34: Document the technical debt and create a tracking issue.

The comment indicates this is a temporary solution. We should track this technical debt to ensure it's addressed in the future.

Would you like me to create a GitHub issue to track the removal of the legacy SCSS API usage? This will help ensure we don't forget about this technical debt.

package.json (2)

196-196: Verify security of new dependencies.

The new dependencies js-yaml and tosource should be verified for security vulnerabilities.

Also applies to: 208-208

✅ Verification successful

Dependencies js-yaml@^4.1.0 and tosource verified as secure

  • No current vulnerabilities found in either package
  • Both packages are well-maintained and hosted on GitHub
  • js-yaml version ^4.1.0 is well above historical vulnerable versions (last known: 3.13.1)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for known vulnerabilities in new dependencies
npm audit js-yaml tosource

# Check for recent security advisories
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: NPM, package: "js-yaml") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
    }
  }
}'

Length of output: 795


Script:

#!/bin/bash
# Check security advisories for tosource
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: NPM, package: "tosource") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
    }
  }
}'

# Check package details
npm view tosource time.modified repository.url

Length of output: 442


Line range hint 177-213: Verify compatibility with Vite v6 breaking changes.

The update to Vite v6 may introduce breaking changes. Please ensure all the following are verified:

  1. The new minimum Node.js version requirement is met
  2. All plugins are compatible with Vite v6
  3. The build output and development server work as expected
✅ Verification successful

Vite v6 upgrade is compatible with current setup

The verification shows that:

  • Node.js v22.9.0 meets Vite 6's requirements
  • All actively used Vite plugins are compatible with v6
  • Configuration structure in vite.config.js follows Vite 6 standards
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check Node.js version compatibility
node -v

# Verify all Vite-related packages are using compatible versions
npm ls vite @cypress/vite-dev-server vite-plugin-pwa vite-plugin-stylelint vite-plugin-babel vite-plugin-eslint

# Check for any reported issues with these versions
gh api graphql -f query='
{
  repository(owner: "vitejs", name: "vite") {
    issues(first: 5, states: OPEN, labels: ["bug"], orderBy: {field: CREATED_AT, direction: DESC}) {
      nodes {
        title
        url
        labels(first: 5) {
          nodes {
            name
          }
        }
      }
    }
  }
}'

Length of output: 614


Script:

#!/bin/bash
# Search for plugin usage in configuration files
echo "=== Searching for Vite plugin usage ==="
rg -l "vite-plugin|@cypress/vite" --type js --type ts

# Check if these plugins are mentioned in any configuration files
echo -e "\n=== Checking specific configuration files ==="
for file in $(fd -e js -e ts -e json -e yaml "vite|cypress" -t f); do
  echo "=== Content of $file ==="
  cat "$file"
done

Length of output: 6043

Comment on lines 9 to 19
async transform(code, id) {
if (yamlExtension.test(id)) {
const yamlData = load(code, {
filename: id,
});

return {
code: `const data = ${ toSource(yamlData) };\nexport default data;`,
map: { mappings: '' },
};
}
Copy link

@coderabbitai coderabbitai bot Jan 13, 2025

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for YAML parsing.

The current implementation doesn't handle YAML parsing errors gracefully. Consider wrapping the load call in a try-catch block to provide better error messages.

 async transform(code, id) {
   if (yamlExtension.test(id)) {
+    try {
       const yamlData = load(code, {
         filename: id,
       });
 
       return {
         code: `const data = ${ toSource(yamlData) };\nexport default data;`,
         map: { mappings: '' },
       };
+    } catch (error) {
+      const errorMessage = `Failed to parse YAML file ${id}: ${error.message}`;
+      this.error(errorMessage);
+      return null;
+    }
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async transform(code, id) {
if (yamlExtension.test(id)) {
const yamlData = load(code, {
filename: id,
});
return {
code: `const data = ${ toSource(yamlData) };\nexport default data;`,
map: { mappings: '' },
};
}
async transform(code, id) {
if (yamlExtension.test(id)) {
try {
const yamlData = load(code, {
filename: id,
});
return {
code: `const data = ${ toSource(yamlData) };\nexport default data;`,
map: { mappings: '' },
};
} catch (error) {
const errorMessage = `Failed to parse YAML file ${id}: ${error.message}`;
this.error(errorMessage);
return null;
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, this is probably a good idea 👍 we have similar try...catch error handling for our handlebars vite plugin.

Copy link

Choose a reason for hiding this comment

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

@nmajor25 Great! Thanks for confirming. Looking forward to the improved error handling.


✏️ Learnings added
Learnt from: nmajor25
PR: RoundingWell/care-ops-frontend#1381
File: config/vite-plugin-yaml.js:9-19
Timestamp: 2025-01-13T21:56:19.310Z
Learning: Vite plugins in the project should include try-catch error handling, similar to the implementation in the handlebars plugin, to provide better error messages when processing fails.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

Copy link

cypress bot commented Jan 13, 2025

RoundingWell Care Ops Frontend    Run #7169

Run Properties:  status check passed Passed #7169  •  git commit e3d501f8c5: Add `return null;`s to our vite plugins
Project RoundingWell Care Ops Frontend
Branch Review vite-v6
Run status status check passed Passed #7169
Run duration 02m 51s
Commit git commit e3d501f8c5: Add `return null;`s to our vite plugins
Committer Nick Major
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 1
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 245
View all changes introduced in this branch ↗︎

@@ -56,7 +56,7 @@ select {
// -------------------------------------

// remove bg image on selects from Firefox
@-moz-document url-prefix('') {
@document url-prefix('') {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something is updating this automatically now in my ide. I think it's the new version of vite-plugin-stylelint? I'm not entirely sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The mdn web doc for this rule seems to indicate that @document should be used. Which is only compatible with firefox: https://developer.mozilla.org/en-US/docs/Web/CSS/@document#browser_compatibility.

But I don't understand the context around this css. Looks like y'all added it back in the day on the initial build of the app.

Copy link
Member

Choose a reason for hiding this comment

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

this might not be used at all anymore.. I think it was related to an old dropdown plugin, but I'm not sure.

Copy link
Member

Choose a reason for hiding this comment

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

I actually believe we can safely remove this entire file. Had chatgpt analyze it along side our browserlist and it seems like it's all obsolete.

@coveralls
Copy link

coveralls commented Jan 13, 2025

Pull Request Test Coverage Report for Build e6d57dca-4f1c-4253-86ef-1fb5cf1e714f

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 89 unchanged lines in 17 files lost coverage.
  • Overall coverage decreased (-1.8%) to 98.188%

Files with Coverage Reduction New Missed Lines %
src/js/utils/formatting/words.js 1 71.43%
src/js/utils/formatting/trim.js 1 66.67%
src/js/components/optionlist/index.js 1 94.44%
src/js/components/datepicker/datepicker_views.js 1 91.67%
src/js/components/droplist/index.js 1 97.56%
src/js/utils/handle-errors.js 1 66.67%
src/js/app.js 1 98.28%
src/js/behaviors/key-listener.js 2 76.92%
src/js/services/alert.js 4 80.0%
src/js/utils/sorting.js 4 80.0%
Totals Coverage Status
Change from base Build 47b04e92-a6eb-4322-a3cf-6fcb0cf52e1a: -1.8%
Covered Lines: 5991
Relevant Lines: 6080

💛 - Coveralls

@@ -0,0 +1,24 @@
import { load } from 'js-yaml';
import toSource from 'tosource';
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove toSource and just use JSON.stringify

@@ -56,7 +56,7 @@ select {
// -------------------------------------

// remove bg image on selects from Firefox
@-moz-document url-prefix('') {
@document url-prefix('') {
Copy link
Member

Choose a reason for hiding this comment

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

I actually believe we can safely remove this entire file. Had chatgpt analyze it along side our browserlist and it seems like it's all obsolete.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
config/vite-plugin-yaml.js (1)

5-8: Consider adding plugin options for configurability.

The factory function pattern is good, but consider adding configuration options for flexibility, such as:

  • Custom file extensions
  • YAML load options
  • Output format customization

Example enhancement:

-export default function() {
+export default function(options = {}) {
+  const {
+    extensions = /\.ya?ml$/,
+    loadOptions = {},
+  } = options;
   return {
     name: 'vite-plugin-yaml',
     async transform(code, id) {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9bdce19 and 495ed5c.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • config/vite-plugin-yaml.js (1 hunks)
  • package.json (3 hunks)
  • src/scss/core/_overrides.scss (0 hunks)
  • src/scss/outreach-core.scss (0 hunks)
  • src/scss/provider-core.scss (0 hunks)
💤 Files with no reviewable changes (3)
  • src/scss/outreach-core.scss
  • src/scss/provider-core.scss
  • src/scss/core/_overrides.scss
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
🧰 Additional context used
📓 Learnings (1)
config/vite-plugin-yaml.js (1)
Learnt from: nmajor25
PR: RoundingWell/care-ops-frontend#1381
File: config/vite-plugin-yaml.js:9-19
Timestamp: 2025-01-13T21:56:19.458Z
Learning: Vite plugins in the project should include try-catch error handling, similar to the implementation in the handlebars plugin, to provide better error messages when processing fails.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (4)
config/vite-plugin-yaml.js (4)

1-3: LGTM! Clean import and accurate file extension matching.

The implementation uses a specific import and a correct regex pattern for YAML extensions.


15-18: LGTM! Clean transformation implementation.

The code correctly uses JSON.stringify and provides appropriate source map information.


19-22: 🛠️ Refactor suggestion

Improve error handling to match project patterns.

Based on the project's established patterns, we should use Vite's error reporting mechanism instead of console.error.

Apply this change to align with the project's error handling patterns:

         } catch (exception) {
-          console.error(`${ id } errored during yaml processing: `, exception);
-          return null;
+          this.error({
+            id,
+            message: `Failed to process YAML file: ${exception.message}`,
+            stack: exception.stack
+          });
         }

Likely invalid or redundant comment.


5-26: Verify Vite v6 plugin API compatibility.

Since this PR updates to Vite v6, we should verify that the plugin implementation follows the latest plugin API specifications.

✅ Verification successful

Plugin implementation is compatible with Vite v6

The YAML plugin follows the standard Vite plugin API structure with correct hook signatures, return values, and error handling. No changes are required for Vite v6 compatibility.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check package.json for Vite version and related dependencies
echo "Checking Vite version and dependencies..."
rg '"vite":|"@vitejs/' package.json

# Look for any breaking changes in plugin API
echo "Checking for Vite plugin API usage..."
rg 'transform.*\(.*\).*{' config/

Length of output: 377


Script:

#!/bin/bash
# Search for other plugin implementations
echo "Checking other plugin implementations..."
fd -e js -e ts --full-path ./config/ --exec grep -l "transform.*(" {} \;

# Look for plugin-related documentation
echo -e "\nChecking for plugin documentation..."
fd -e md -e txt | xargs grep -l -i "vite.*plugin" || true

# Search for specific plugin patterns
echo -e "\nChecking plugin patterns..."
rg "name: ['\"](vite-plugin|rollup-plugin)" --type js --type ts

# Check transform hook implementations
echo -e "\nChecking transform implementations..."
ast-grep --pattern 'transform(code, id) { $$$ }'

Length of output: 683

}

return null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need this return null; if (yamlExtension.test(id)) is false? I think we are good without it. The handlebars vite plugin doesn't have it: https://github.com/RoundingWell/care-ops-frontend/blob/develop/config/vite-plugin-handlebars-loader.js

Copy link
Member

Choose a reason for hiding this comment

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

ooh.. I think it does need it.. we should add that to the handlebars one too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added 👍

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
config/vite-plugin-handlebars-loader.js (1)

Line range hint 1-1: Consider tracking the TODO as a separate task.

Since this PR involves Vite plugin management, it might be worth creating a tracking issue for extracting this into a standalone Vite plugin package.

Would you like me to create a GitHub issue to track the extraction of this Handlebars loader into a separate Vite plugin package?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 495ed5c and e3d501f.

📒 Files selected for processing (2)
  • config/vite-plugin-handlebars-loader.js (2 hunks)
  • config/vite-plugin-yaml.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • config/vite-plugin-yaml.js
🔇 Additional comments (3)
config/vite-plugin-handlebars-loader.js (3)

20-20: LGTM! Explicit error handling improvement.

The explicit return null properly signals to Vite that this loader should be skipped when file reading fails.


30-30: LGTM! Consistent error handling.

The explicit return null maintains consistency with other error cases and properly handles Handlebars compilation failures.


33-34: LGTM! Explicit default case handling.

The explicit default return null improves clarity and maintains consistent behavior when processing non-Handlebars files.

@nmajor25 nmajor25 requested a review from paulfalgout January 14, 2025 16:59
@paulfalgout paulfalgout merged commit 1d3a741 into develop Jan 14, 2025
6 checks passed
@paulfalgout paulfalgout deleted the vite-v6 branch January 14, 2025 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants