Skip to content

Feat: Extension puppeteer #1323

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

Merged
merged 4 commits into from
Sep 19, 2024

Conversation

ThibautCuchet
Copy link
Contributor

@ThibautCuchet ThibautCuchet commented Sep 19, 2024

Discord thread

✅ Checklist

  • I have followed every step in the contributing guide
  • The PR title follows the convention.
  • I ran and tested the code works

Testing

  • Started the web app
  • Created an organization
  • Created the project v3-catalog
  • Built and ran the CLI
  • Created a task "puppeteerTask" in v3-catalog:
    • Opened a browser
    • Navigated to "https://google.com"
    • Took a screenshot
    • Good to know: In production, the property machine.preset needs to be set to "large-1x" for it to work. I did not test for all values.
  • Ran the "puppeteerTask" in dev mode
  • New file "screenshot.png" was successfully created

Changelog

Added a new "puppeteer" extension to enable browser usage in puppeteer tasks.


Screenshots

[Screenshots]

💯

Summary by CodeRabbit

  • New Features

    • Introduced a Puppeteer extension for enhanced browser automation and testing capabilities.
    • Added a new task for automated web interactions, including taking screenshots of web pages.
  • Bug Fixes

    • Reorganized dependencies for better management, ensuring stability and functionality.
  • Documentation

    • Updated configuration files to integrate the new Puppeteer functionalities into the build process.

Copy link

changeset-bot bot commented Sep 19, 2024

🦋 Changeset detected

Latest commit: 25cac44

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@trigger.dev/build Patch
trigger.dev Patch
@trigger.dev/core Patch
@trigger.dev/sdk Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

coderabbitai bot commented Sep 19, 2024

Walkthrough

The pull request introduces a new Puppeteer extension to the package, enhancing its functionality for browser automation and testing. It includes modifications to the package.json to support Puppeteer, the creation of a PuppeteerExtension class, and a new task that takes a screenshot of a webpage. Additionally, the configuration file is updated to integrate the Puppeteer extension into the build process, allowing for automated web interactions.

Changes

File Change Summary
packages/build/package.json Added Puppeteer extension with import/require paths and updated sourceDialects and types.
packages/build/src/extensions/puppeteer.ts Introduced PuppeteerExtension class implementing BuildExtension, with onBuildComplete method for build context.
references/v3-catalog/package.json Removed and re-added fluent-ffmpeg, added puppeteer and @types/fluent-ffmpeg dependencies.
references/v3-catalog/src/trigger/puppeteerTask.ts Created a new task for Puppeteer that takes a screenshot of the Google homepage.
references/v3-catalog/trigger.config.ts Added puppeteer() to the exported configuration for build integration.

Possibly related PRs

🐇 Hopping with glee, oh what a sight,
Puppeteer joins in, bringing delight!
With screenshots and builds, all in a row,
Our tasks now dance, with a vibrant glow.
A leap into code, where magic unfolds,
In the world of automation, our story is told! 🐾


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 375c170 and 25cac44.

Files selected for processing (1)
  • .changeset/little-donkeys-protect.md (1 hunks)
Additional comments not posted (1)
.changeset/little-donkeys-protect.md (1)

1-5: LGTM!

The changeset file follows the expected format and provides a clear description of the new feature. The addition of a "puppeteer build extension" could significantly improve the developer experience when working with Puppeteer in conjunction with the @trigger.dev/build framework.

To complete the review, please ensure that the actual implementation of this feature in the relevant source code files adheres to best practices, maintains code quality, and includes appropriate tests and documentation.


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.

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: 0

Outside diff range and nitpick comments (1)
references/v3-catalog/src/trigger/puppeteerTask.ts (1)

1-16: LGTM! The Puppeteer task is implemented correctly.

The task uses the Trigger.dev SDK and Puppeteer library to launch a browser, navigate to a URL, take a screenshot, and close the browser. The implementation looks good and follows the expected pattern.

A few suggestions for future enhancements:

  1. Consider parameterizing the URL and screenshot path to make the task more reusable across different scenarios.
  2. Review the machine preset choice (large-1x) based on the specific use case and resource requirements. Ensure that the selected preset provides optimal performance and cost-efficiency for the task.
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b3a6f4e and 375c170.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (5)
  • packages/build/package.json (3 hunks)
  • packages/build/src/extensions/puppeteer.ts (1 hunks)
  • references/v3-catalog/package.json (2 hunks)
  • references/v3-catalog/src/trigger/puppeteerTask.ts (1 hunks)
  • references/v3-catalog/trigger.config.ts (2 hunks)
Additional comments not posted (10)
packages/build/src/extensions/puppeteer.ts (2)

4-6: LGTM!

The puppeteer factory function is implemented correctly. It creates and returns a new instance of PuppeteerExtension.


8-34: Excellent work!

The PuppeteerExtension class is implemented correctly and follows best practices:

  • It implements the BuildExtension interface correctly.
  • The name property is set to a descriptive value.
  • The onBuildComplete method adds a new layer to the build context when the target is not "dev".
  • The added layer includes instructions for installing Google Chrome, which is required for Puppeteer.
  • The instructions follow best practices for reducing image size by cleaning up package lists.

The implementation is clean, well-structured, and follows the project's conventions.

references/v3-catalog/trigger.config.ts (2)

7-7: LGTM!

The import statement for the puppeteer extension is syntactically correct and aligns with the stated PR objective.


83-83: Looks good! Remember to set machine.preset for production use.

The addition of the puppeteer() extension to the build configuration is syntactically correct and aligns with the stated PR objective of enabling browser usage in puppeteer tasks.

As you mentioned in the PR description, for production use, the machine.preset property should be set to large-1x to ensure sufficient resources for running puppeteer tasks. Please ensure this is done before deploying to production.

references/v3-catalog/package.json (2)

40-40: LGTM!

The addition of the puppeteer dependency aligns with the PR objectives to introduce a new "puppeteer" extension. The version specified is the latest major version, which is appropriate.


69-69: LGTM!

The addition of the @types/fluent-ffmpeg dependency provides TypeScript type definitions for the fluent-ffmpeg package, which improves the development experience. The version specified matches the version of the fluent-ffmpeg package, which is appropriate.

packages/build/package.json (4)

30-31: LGTM!

The new entry for the puppeteer extension is added correctly in the exports section, following the same format as other extension entries. The import path points to the correct location of the TypeScript source file for the extension.


53-55: LGTM!

The new entry for the puppeteer extension is added correctly in the typesVersions section, following the same format as other extension entries. The path points to the correct location of the TypeScript declaration file for the CommonJS build of the extension.


152-162: LGTM!

The new entry for the puppeteer extension is added correctly in the exports section, following the same format as other extension entries. The import and require paths point to the correct locations of the respective files for the extension, including the TypeScript source file, TypeScript declaration files, and JavaScript files for both ESM and CommonJS builds. This ensures compatibility with different module systems.


Line range hint 1-169: Overall assessment: The changes look good!

The introduction of the new puppeteer extension in the package.json file is a valuable addition to the @trigger.dev/build package. It enhances the functionality of the package by providing support for browser automation using Puppeteer.

The necessary entries for the puppeteer extension are added correctly in the exports and typesVersions sections, following the existing structure and conventions of the file. The paths to the respective files for the extension, including the TypeScript source file, TypeScript declaration files, and JavaScript files for both ESM and CommonJS builds, are specified accurately. This ensures compatibility with different module systems.

Overall, the changes are well-structured, consistent with the existing codebase, and contribute positively to the package's capabilities.

Copy link
Member

@ericallam ericallam left a comment

Choose a reason for hiding this comment

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

This looks good to me 👍

Copy link

pkg-pr-new bot commented Sep 19, 2024

pnpm add https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/build@1323
pnpm add https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/core@1323
pnpm add https://pkg.pr.new/triggerdotdev/trigger.dev@1323
pnpm add https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/sdk@1323

commit: 25cac44

@ericallam ericallam merged commit c65d482 into triggerdotdev:main Sep 19, 2024
9 checks passed
samejr added a commit that referenced this pull request Sep 19, 2024
commit 64862db
Author: Niels <info@flydev.nl>
Date:   Thu Sep 19 16:25:17 2024 +0200

    Update dotEnv.ts to ignore OTEL_EXPORTER_OTLP_ENDPOINT as well (#1307)

    * Update dotEnv.ts

    * Create four-buttons-run.md

    ---------

    Co-authored-by: Eric Allam <eallam@icloud.com>

commit c65d482
Author: Thibaut Cuchet <thibautcuchet@gmail.com>
Date:   Thu Sep 19 16:22:57 2024 +0200

    Feat: Extension puppeteer (#1323)

    * feat: add puppeteer extension

    * chore: update package and config

    * feat: add puppeteer task

    * Create little-donkeys-protect.md

    ---------

    Co-authored-by: Eric Allam <eallam@icloud.com>

commit b4be736
Author: Eric Allam <eallam@icloud.com>
Date:   Thu Sep 19 15:21:03 2024 +0100

    prismaExtension fixes for #1325 and #1327
@coderabbitai coderabbitai bot mentioned this pull request Sep 19, 2024
samejr added a commit that referenced this pull request Sep 19, 2024
* Added pdf-to-image example

* Copy tweak

* Squashed commit of the following:

commit 64862db
Author: Niels <info@flydev.nl>
Date:   Thu Sep 19 16:25:17 2024 +0200

    Update dotEnv.ts to ignore OTEL_EXPORTER_OTLP_ENDPOINT as well (#1307)

    * Update dotEnv.ts

    * Create four-buttons-run.md

    ---------

    Co-authored-by: Eric Allam <eallam@icloud.com>

commit c65d482
Author: Thibaut Cuchet <thibautcuchet@gmail.com>
Date:   Thu Sep 19 16:22:57 2024 +0200

    Feat: Extension puppeteer (#1323)

    * feat: add puppeteer extension

    * chore: update package and config

    * feat: add puppeteer task

    * Create little-donkeys-protect.md

    ---------

    Co-authored-by: Eric Allam <eallam@icloud.com>

commit b4be736
Author: Eric Allam <eallam@icloud.com>
Date:   Thu Sep 19 15:21:03 2024 +0100

    prismaExtension fixes for #1325 and #1327

* Copy tweak
@ThibautCuchet ThibautCuchet deleted the extension-puppeteer branch September 19, 2024 17:25
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