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

Support scopes packages in externals when found in a transitive dep #1552 #1569

Merged
merged 3 commits into from
Dec 16, 2024

Conversation

ericallam
Copy link
Member

@ericallam ericallam commented Dec 16, 2024

This fixes #1552. The issue turned out to be marking an external dependency with a scoped name (e.g. @huggingface/transformers), when it was being imported through another package. This was happening because we create a symlink from the trigger build node_modules dir to the actual location of the dependency (in dev), but that was failing because the @huggingface directory didn't exist.

Summary by CodeRabbit

  • Bug Fixes

    • Resolved issues with the handling of scoped packages in the "trigger.dev" configuration.
    • Improved error handling and logging for the creation of symbolic links for scoped packages.
  • New Features

    • Enhanced functionality to automatically create necessary directories for scoped packages within the node_modules path.

Copy link

changeset-bot bot commented Dec 16, 2024

🦋 Changeset detected

Latest commit: 6aecfca

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

This PR includes changesets to release 12 packages
Name Type
trigger.dev Patch
@trigger.dev/build Patch
@trigger.dev/core Patch
@trigger.dev/react-hooks Patch
@trigger.dev/rsc Patch
@trigger.dev/sdk Patch
@trigger.dev/database Patch
@trigger.dev/otlp-importer Patch
@internal/redis-worker Patch
@internal/zod-worker Patch
references-nextjs-realtime Patch
@internal/testcontainers 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 Dec 16, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/cli-v3/src/build/externals.ts

Oops! Something went wrong! :(

ESLint: 8.45.0

ESLint couldn't find the config "custom" to extend from. Please check that the name of the config is correct.

The config "custom" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

Walkthrough

The pull request focuses on improving the handling of scoped packages within the Trigger.dev CLI build process. Specifically, the changes modify the linkExternal function in the externals configuration to better support scoped packages by ensuring that scope directories are correctly created within the node_modules path before creating symbolic links.

Changes

File Change Summary
packages/cli-v3/src/build/externals.ts Enhanced scoped package handling in linkExternal function by adding logic to create scope directories when processing external packages starting with "@"
.changeset/kind-plants-tap.md Patch configuration for Trigger.dev to address external package handling from monorepo

Possibly related PRs

Poem

🐰 In the realm of packages, scoped and bright,
A rabbit's fix brings build paths to light!
Directories dance, symlinks take flight,
No more confusion, everything's right!
CLI magic, with precision so neat 🔧


📜 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 db0abc6 and 6aecfca.

📒 Files selected for processing (2)
  • .changeset/kind-plants-tap.md (1 hunks)
  • packages/cli-v3/src/build/externals.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .changeset/kind-plants-tap.md
  • packages/cli-v3/src/build/externals.ts

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

🧹 Nitpick comments (1)
packages/cli-v3/src/build/externals.ts (1)

48-67: Consider enhancing the scoped package handling implementation

The implementation correctly handles scoped packages by creating the necessary directory structure. However, consider these improvements:

  1. Extract the scope directory logic into a reusable helper function
  2. Add error handling for the mkdir operation
  3. Use a more robust method to extract the scope directory

Consider this refactoring:

+ async function ensureScopeDirectory(packageName: string, destinationPath: string, logger: BuildLogger): Promise<void> {
+   if (!packageName.startsWith('@')) return;
+   
+   const scopeMatch = packageName.match(/^(@[^/]+)/);
+   if (!scopeMatch) {
+     logger.debug("[externals] Invalid scoped package name", { packageName });
+     return;
+   }
+   
+   const scopeDir = scopeMatch[1];
+   const scopePath = join(destinationPath, scopeDir);
+   
+   logger.debug("[externals] Creating scope directory", {
+     scopeDir,
+     scopePath,
+   });
+   
+   try {
+     await mkdir(scopePath, { recursive: true });
+   } catch (error) {
+     logger.debug("[externals] Failed to create scope directory", {
+       error,
+       scopePath,
+     });
+     throw error;
+   }
+ }

 async function linkExternal(external: CollectedExternal, resolveDir: string, logger: BuildLogger) {
   const destinationPath = join(resolveDir, "node_modules");
   await mkdir(destinationPath, { recursive: true });
 
   logger.debug("[externals] Make a symbolic link", {
     fromPath: external.path,
     destinationPath,
     external,
   });

-  // For scoped packages, we need to ensure the scope directory exists
-  if (external.name.startsWith("@")) {
-    // Get the scope part (e.g., '@huggingface')
-    const scopeDir = external.name.split("/")[0];
-
-    if (scopeDir) {
-      const scopePath = join(destinationPath, scopeDir);
-
-      logger.debug("[externals] Ensure scope directory exists", {
-        scopeDir,
-        scopePath,
-      });
-
-      await mkdir(scopePath, { recursive: true });
-    } else {
-      logger.debug("[externals] Unable to get the scope directory", {
-        external,
-      });
-    }
-  }
+  await ensureScopeDirectory(external.name, destinationPath, logger);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f3e4597 and db0abc6.

📒 Files selected for processing (2)
  • .changeset/kind-plants-tap.md (1 hunks)
  • packages/cli-v3/src/build/externals.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changeset/kind-plants-tap.md
🔇 Additional comments (2)
packages/cli-v3/src/build/externals.ts (2)

48-67: Implementation successfully handles scoped packages

The changes effectively solve the issue of supporting scoped packages in externals. The implementation:

  • Correctly identifies scoped packages
  • Creates necessary directory structure
  • Maintains good logging practices

While there are suggestions for improvements, the current implementation is functional and meets the requirements.


48-67: Verify handling of nested scoped packages

While the implementation handles basic scoped packages, we should verify the handling of nested scoped packages (e.g., @scope/namespace/package) and ensure proper resolution in the build process.

✅ Verification successful

Based on the analysis of the package.json files and dependencies across the codebase, I can now provide a final response:

No issues with nested scoped package handling

The current implementation correctly handles scoped packages. While the codebase uses many scoped packages (like @trigger.dev/*, @opentelemetry/*, etc.), there are no nested scoped packages (packages with format @scope/namespace/package) in use. The current directory creation logic is sufficient for the actual package patterns used in the project.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for nested scoped packages in the codebase

# Search for import/require statements with nested scoped packages
rg -g '*.{js,ts,jsx,tsx}' -A 2 'from\s+["'\'']@[^/]+/[^/]+/.+["'\'']|require\(["\']@[^/]+/[^/]+/.+["\']\)'

# Search for nested scoped packages in package.json files
fd 'package.json' -x jq -r '.dependencies + .devDependencies | keys[] | select(test("^@[^/]+/[^/]+/.+"))'

Length of output: 116


Script:

#!/bin/bash
# Let's try a different approach to check for nested scoped packages

# Search for import statements with scoped packages to understand current usage patterns
rg -g '*.{js,ts,jsx,tsx}' "from ['\"](@@[^'\"]+)" --no-line-number || true

# Look for dependencies in package.json files
fd "package.json" -x cat {} \; | grep -A 1 "@.*/" || true

# Check the externals handling implementation to understand the current logic
rg -g '*.{ts,js}' -B 2 -A 2 "external.name.startsWith('@')" || true

Length of output: 19115

Copy link

pkg-pr-new bot commented Dec 16, 2024

@trigger.dev/react-hooks

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/react-hooks@1569

@trigger.dev/build

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/build@1569

@trigger.dev/rsc

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/rsc@1569

trigger.dev

npm i https://pkg.pr.new/triggerdotdev/trigger.dev@1569

@trigger.dev/sdk

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/sdk@1569

@trigger.dev/core

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/core@1569

commit: 6aecfca

@ericallam ericallam merged commit 88a0754 into main Dec 16, 2024
8 checks passed
@ericallam ericallam deleted the ea-branch-4 branch December 16, 2024 17:55
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.

Marking a transitive dependency as external in a monorepo doesn't work
1 participant