Skip to content

fix: adding packages for vite plugins#3688

Merged
mattinannt merged 3 commits intomainfrom
fix/plugins
Oct 14, 2024
Merged

fix: adding packages for vite plugins#3688
mattinannt merged 3 commits intomainfrom
fix/plugins

Conversation

@pandeymangg
Copy link
Contributor

@pandeymangg pandeymangg commented Oct 14, 2024

What does this PR do?

Adds a new package under packages/vite-plugins for being consistent with our coding conventions regarding the vite plugins as well, right now, the copy compiled assets plugin is defined inside it.

Fixes # (issue)

How should this be tested?

  • run pnpm go or pnpm build
  • binaries and other assets should be copied to apps/web/public/js directory

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read How we Code at Formbricks
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand bits
  • Ran pnpm build
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues
  • First PR at Formbricks? Please sign the CLA! Without it we wont be able to merge it 🙏

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Formbricks Docs if changes were necessary

Summary by CodeRabbit

  • New Features

    • Updated video source paths in the AppTab and WebsiteTab components for improved clarity.
    • Introduced a new copyCompiledAssetsPlugin for efficient asset management during the build process.
    • Added new configuration files for ESLint and TypeScript in the Vite plugins directory.
  • Bug Fixes

    • Simplified video source declarations to enhance component functionality.
  • Chores

    • Restructured project directory paths for plugin imports.

@vercel
Copy link

vercel bot commented Oct 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
formbricks-cloud 🛑 Canceled (Inspect) Oct 14, 2024 9:25am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
formbricks-docs ⬜️ Ignored (Inspect) Visit Preview Oct 14, 2024 9:25am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 14, 2024

Walkthrough

The changes in this pull request involve modifications to several components and configuration files across the project. Specifically, the AppTab and WebsiteTab components had their video source paths updated from imported variables to direct string paths. Additionally, the import paths for the copyCompiledAssetsPlugin were modified in the vite.config.ts files of the js-core and surveys packages, reflecting a directory restructuring. New configuration files and implementations were introduced in the vite-plugins directory, including the addition of a new plugin for copying compiled assets.

Changes

File Change Summary
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/shareEmbedModal/AppTab.tsx
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/shareEmbedModal/WebsiteTab.tsx
Updated video source paths from imported variables to direct string paths.
packages/js-core/vite.config.ts
packages/surveys/vite.config.ts
Modified import paths for copyCompiledAssetsPlugin due to directory restructuring.
packages/copyCompiledAssetsPlugin/vite.config.ts Deleted file containing original plugin implementation.
packages/vite-plugins/.eslintrc.cjs Added ESLint configuration extending from @formbricks/eslint-config/library.js.
packages/vite-plugins/copy-compiled-assets/index.ts Introduced copyCompiledAssetsPlugin function and CopyCompiledAssetsPluginOptions interface.
packages/vite-plugins/package.json Specified metadata for the new @formbricks/vite-plugins package.
packages/vite-plugins/tsconfig.json Added TypeScript configuration extending from @formbricks/config-typescript/js-library.json.

Possibly related PRs

Suggested labels

bug, 🙋🏻‍♂️help wanted, 🕹️ oss.gg

🐰 In a world of code and screens,
The rabbits hop with joyful gleans.
With paths now clear, the videos play,
In tabs of apps, they brighten the day.
New plugins sprout, like carrots in rows,
A garden of changes, where innovation grows! 🌱✨


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 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.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 14, 2024

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Member

@mattinannt mattinannt left a comment

Choose a reason for hiding this comment

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

@pandeymangg Thank you for the fix :-) 🚀

Copy link
Contributor

@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: 4

🧹 Outside diff range and nitpick comments (4)
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/shareEmbedModal/AppTab.tsx (1)

88-88: LGTM! Consider using a constant for the video path.

The change to use a direct string path for the video source is consistent with the PR objectives and simplifies the code. However, for better maintainability and flexibility, consider defining the video path as a constant at the top of the file or in a separate constants file.

Here's a suggestion to improve flexibility:

const CHANGE_SURVEY_TYPE_VIDEO_PATH = "/video/tooltips/change-survey-type-app.mp4";

// Then in the video source:
<source src={CHANGE_SURVEY_TYPE_VIDEO_PATH} type="video/mp4" />

This approach maintains the simplicity while allowing for easier updates if the path changes in the future.

packages/vite-plugins/copy-compiled-assets/index.ts (3)

1-1: Correct the typo in the comment

There's a typo in the comment on line 1: "plguins" should be "plugins".


39-39: Remove commented-out code for cleanliness

The commented-out line // fs.ensureDirSync(outputDir); appears to be leftover code. Removing it will clean up the codebase and avoid confusion.


58-58: Log the actual number of files copied

The current log message uses filesToCopy.length, which includes all entries from distDir, even those skipped. To reflect the actual number of files copied, count the files during the copy process.

Adjust the code as follows:

+ let filesCopied = 0;

 for (const file of filesToCopy) {
   // ...
   await copyFile(srcFile, destFile);
+  filesCopied++;
 }

 console.log(
-  `Copied ${filesToCopy.length.toString()} files to ${outputDir} (${options.filename})`
+  `Copied ${filesCopied} files to ${outputDir} (${options.filename})`
 );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 49f7867 and 8dc4a9f.

⛔ Files ignored due to path filters (3)
  • apps/web/public/video/tooltips/change-survey-type-app.mp4 is excluded by !**/*.mp4
  • apps/web/public/video/tooltips/change-survey-type.mp4 is excluded by !**/*.mp4
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (9)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/shareEmbedModal/AppTab.tsx (1 hunks)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/shareEmbedModal/WebsiteTab.tsx (1 hunks)
  • packages/copyCompiledAssetsPlugin/vite.config.ts (0 hunks)
  • packages/js-core/vite.config.ts (1 hunks)
  • packages/surveys/vite.config.ts (1 hunks)
  • packages/vite-plugins/.eslintrc.cjs (1 hunks)
  • packages/vite-plugins/copy-compiled-assets/index.ts (1 hunks)
  • packages/vite-plugins/package.json (1 hunks)
  • packages/vite-plugins/tsconfig.json (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/copyCompiledAssetsPlugin/vite.config.ts
✅ Files skipped from review due to trivial changes (4)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/shareEmbedModal/WebsiteTab.tsx
  • packages/vite-plugins/.eslintrc.cjs
  • packages/vite-plugins/package.json
  • packages/vite-plugins/tsconfig.json
🧰 Additional context used
🔇 Additional comments (1)
packages/js-core/vite.config.ts (1)

5-5: LGTM! Verify the new import path.

The import statement has been correctly updated to reflect the new package structure mentioned in the PR objectives. This change maintains consistency with the new location of Vite plugins.

To ensure the new import path is correct and the plugin is properly implemented, please run the following script:

import dts from "vite-plugin-dts";
import tsconfigPaths from "vite-tsconfig-paths";
import { copyCompiledAssetsPlugin } from "../copyCompiledAssetsPlugin/vite.config";
import { copyCompiledAssetsPlugin } from "../vite-plugins/copy-compiled-assets";
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Import Path Issue for copyCompiledAssetsPlugin

The new import path points to packages/vite-plugins/copy-compiled-assets.ts, but the file does not exist. Please verify the location of copyCompiledAssetsPlugin or ensure the file is added to packages/vite-plugins.

🔗 Analysis chain

Verify the new import path for copyCompiledAssetsPlugin

The import path for copyCompiledAssetsPlugin has been updated to reflect the new package structure mentioned in the PR objectives. This change aligns with the goal of introducing a new package under packages/vite-plugins for Vite plugins.

However, to ensure this change is correct and doesn't introduce any issues:

  1. Confirm that the file copy-compiled-assets.ts (or copy-compiled-assets/index.ts) exists in the packages/vite-plugins directory.
  2. Verify that the copyCompiledAssetsPlugin is correctly exported from this new location.
  3. Check if similar changes have been made in other files that might be using this plugin (e.g., other vite.config.ts files in the project).

Run the following script to verify the new structure and usage:

If all checks pass, this change is likely correct and consistent with the PR objectives.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new structure and usage of copyCompiledAssetsPlugin

# Test 1: Check if the new file exists
echo "Checking if the new file exists:"
fd --type f --full-path "packages/vite-plugins/copy-compiled-assets.(ts|js|tsx|jsx)"

# Test 2: Verify the export of copyCompiledAssetsPlugin
echo "Verifying the export of copyCompiledAssetsPlugin:"
rg --type typescript "export.*copyCompiledAssetsPlugin" "packages/vite-plugins"

# Test 3: Check for other usages of copyCompiledAssetsPlugin
echo "Checking for other usages of copyCompiledAssetsPlugin:"
rg --type typescript "import.*copyCompiledAssetsPlugin" -g "!packages/surveys/vite.config.ts"

Length of output: 635


Script:

#!/bin/bash
# Description: Verify the new structure and usage of copyCompiledAssetsPlugin

# Test 1: Check if the new file exists
echo "Checking if the new file exists:"
fd --type f --full-path 'packages/vite-plugins/copy-compiled-assets.ts' packages/vite-plugins

# Test 2: Verify the export of copyCompiledAssetsPlugin
echo "Verifying the export of copyCompiledAssetsPlugin:"
rg "export\s+const\s+copyCompiledAssetsPlugin" packages/vite-plugins/copy-compiled-assets.ts

# Test 3: Check for other usages of copyCompiledAssetsPlugin
echo "Checking for other usages of copyCompiledAssetsPlugin:"
rg "import\s+.*copyCompiledAssetsPlugin" --glob '!packages/surveys/vite.config.ts' packages/

Length of output: 785

try {
await access(dirPath);
} catch (error) {
if ((error as { code: string }).code === "ENOENT") {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Use proper error typing for better type safety

In line 15, to safely access the code property, consider casting the error to NodeJS.ErrnoException. This ensures proper typing and better type safety.

Apply this diff to fix the typing:

- if ((error as { code: string }).code === "ENOENT") {
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") {
📝 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
if ((error as { code: string }).code === "ENOENT") {
if ((error as NodeJS.ErrnoException).code === "ENOENT") {


for (const file of filesToCopy) {
const srcFile = path.resolve(distDir, file);
const destFile = path.resolve(outputDir, file.replace("index", options.filename));
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure accurate filename replacement when copying files

The replacement of "index" in filenames on line 48 might unintentionally affect files that have "index" elsewhere in their names. This could lead to incorrect file names after copying.

Consider using a more precise condition:

 const destFile = path.resolve(
   outputDir,
-  file.replace("index", options.filename)
+  file === "index.js" ? `${options.filename}.js` : file
 );

This change ensures that only files exactly named "index.js" are replaced with the desired filename.

📝 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
const destFile = path.resolve(outputDir, file.replace("index", options.filename));
const destFile = path.resolve(
outputDir,
file === "index.js" ? `${options.filename}.js` : file
);

},

async writeBundle() {
const outputDir = path.resolve(config.root, "../../apps/web/public/js");
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Make the output directory configurable

Currently, the outputDir is hardcoded in line 35. Consider making it a configurable option to enhance flexibility and reusability of the plugin.

Modify the CopyCompiledAssetsPluginOptions interface and adjust the code accordingly:

 interface CopyCompiledAssetsPluginOptions {
   filename: string;
   distDir: string;
+  outputDir: string;
 }

 export function copyCompiledAssetsPlugin(options: CopyCompiledAssetsPluginOptions): Plugin {
   let config: ResolvedConfig;

   return {
     // ...
     async writeBundle() {
-      const outputDir = path.resolve(config.root, "../../apps/web/public/js");
+      const outputDir = path.resolve(config.root, options.outputDir);
       const distDir = path.resolve(config.root, options.distDir);
       // ...
     },
   };
 }

Committable suggestion was skipped due to low confidence.

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 14, 2024
@mattinannt mattinannt added this pull request to the merge queue Oct 14, 2024
Merged via the queue into main with commit b40ed54 Oct 14, 2024
@mattinannt mattinannt deleted the fix/plugins branch October 14, 2024 09:46
@coderabbitai coderabbitai bot mentioned this pull request Feb 28, 2025
12 tasks
@coderabbitai coderabbitai bot mentioned this pull request Apr 22, 2025
12 tasks
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.

2 participants