Skip to content

Conversation

@kingston
Copy link
Collaborator

@kingston kingston commented Jan 6, 2025

Summary by CodeRabbit

Release Notes

  • New Features

    • Added graph visualization of generator steps using Cytoscape.js.
    • Introduced optional return values for the generator run function.
    • Added WebSocket subscription support in the Yoga plugin.
    • New functionality to generate HTML for visualizing graph data.
  • Improvements

    • Enhanced generator step tracking and metadata handling.
    • Updated build and temporary directory paths.
    • Improved flexibility in task configuration and dependency management.
  • Changes

    • Modified Vite server file watching configuration.
    • Updated .gitignore exclusions for Baseplate build artifacts.

@linear
Copy link

linear bot commented Jan 6, 2025

ENG-529 Create visualizer for generator tasks / dependencies

Allows us to better refactor the generator by understanding the dependency structure

@changeset-bot
Copy link

changeset-bot bot commented Jan 6, 2025

🦋 Changeset detected

Latest commit: 1d30997

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

This PR includes changesets to release 12 packages
Name Type
@halfdomelabs/project-builder-server Patch
@halfdomelabs/sync Patch
@halfdomelabs/core-generators Patch
@halfdomelabs/project-builder-cli Patch
@halfdomelabs/project-builder-common Patch
@halfdomelabs/project-builder-test Patch
@halfdomelabs/project-builder-web Patch
@halfdomelabs/cli Patch
@halfdomelabs/fastify-generators Patch
@halfdomelabs/project-builder-lib Patch
@halfdomelabs/react-generators Patch
@halfdomelabs/baseplate-plugin-storage 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

@coderabbitai
Copy link

coderabbitai bot commented Jan 6, 2025

Walkthrough

The pull request introduces several enhancements across multiple packages, focusing on improving generator functionality, metadata handling, and visualization. Key changes include adding graph visualization for generator steps using Cytoscape.js, refactoring the run function to support optional returns, updating file paths and build artifact handling, and introducing new metadata tracking for generator steps. The modifications span packages like core-generators, fastify-generators, project-builder-server, react-generators, and sync, with a focus on improving flexibility, type safety, and developer experience.

Changes

File Change Summary
.changeset/rotten-rocks-report.md Added graph visualization of generator steps using Cytoscape.js
.changeset/small-ghosts-smash.md Refactored run function to support optional returns
packages/core-generators/src/generators/node/node-git-ignore/index.ts Updated .gitignore exclusions from temporary files to build artifacts
packages/fastify-generators/src/generators/auth0/auth0-module/index.ts Removed return statements from task configurations
packages/fastify-generators/src/generators/yoga/yoga-plugin/index.ts Added server-websocket task, modified subscription task with optional auth dependency
packages/project-builder-server/src/service/environment-flags.ts Introduced environmentFlags constant with BASEPLATE_WRITE_GENERATOR_STEPS_HTML
packages/project-builder-server/src/sync/generator-steps-html-writer.ts Added new function to generate HTML visualization of generator steps
packages/project-builder-server/src/sync/index.ts Updated build result and temporary directory paths, added conditional HTML generation
packages/react-generators/src/generators/core/react/index.ts Modified Vite server's ignored files pattern
packages/sync/src/core/engine/dependency-sort.ts Enhanced getSortedRunSteps to return metadata
packages/sync/src/core/engine/generator-runner.ts Updated executeGeneratorEntry to handle new metadata
packages/sync/src/core/generator-output.ts Added GeneratorOutputMetadata interface
packages/sync/src/utils/create-generator-with-tasks.ts Updated task configuration interfaces for more flexible typing

Sequence Diagram

sequenceDiagram
    participant Generator
    participant DependencySort
    participant GeneratorRunner
    participant HTMLWriter

    Generator->>DependencySort: Get sorted run steps
    DependencySort-->>Generator: Return steps with metadata
    Generator->>GeneratorRunner: Execute generator entry
    GeneratorRunner->>GeneratorRunner: Build output with metadata
    alt BASEPLATE_WRITE_GENERATOR_STEPS_HTML is true
        GeneratorRunner->>HTMLWriter: Write generator steps HTML
        HTMLWriter-->>GeneratorRunner: HTML file generated
    end
Loading

The sequence diagram illustrates the new workflow for generator step processing, including metadata generation and optional HTML visualization.


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

@kingston kingston changed the title Kingston/eng-529-create-visualizer-for-generator-tasks-dependencies feat: Create visualizer for generator steps using cytoscape Jan 6, 2025
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 (8)
packages/project-builder-server/src/sync/generator-steps-html-writer.ts (2)

6-75: Consider allowing external script versions to be configurable or pinned.
Embedding Cytoscape from a CDN is convenient, but pinning a more specific version or utilizing Subresource Integrity (SRI) can help maintain reliability and security.


86-112: Add error handling or logging for file writes.
While writeGeneratorStepsHtml is concise, you could consider wrapping fs.writeFile in a try/catch block to make errors more explicit. Also, verifying outputDirectory before writing might be beneficial in complex scenarios.

packages/sync/src/core/engine/generator-runner.ts (1)

120-129: Optional labeling of nodes and edges may aid debugging.
Currently, each node's label is not populated. If this is intentional, it’s fine; otherwise, consider adding a descriptive label property for improved clarity in visualizations.

packages/sync/src/core/engine/dependency-sort.ts (2)

169-174: Consider removing duplicates in fullSteps.

You’re aggregating steps from different sources (entries plus interdependentNodes). If there’s any overlap, calling toposort.array() might produce errors. Ensure duplicates won't exist or deduplicate before calling toposort.


175-181: Potential fallback for empty graphs.

When fullSteps or fullEdges is empty, toposort might return an empty list. Ensure your consumer code can handle that scenario (e.g., no steps to run). Otherwise, a fallback might be necessary.

packages/project-builder-server/src/sync/index.ts (2)

83-83: Path reorganization check.

Moving the build result file to baseplate/build/last_build_result.json is a logical step for clarity. Ensure that any documentation or references to the old path are updated accordingly.


198-198: Suggest a debug log here.

A short debug or info log could confirm that generation of the steps HTML was skipped, helping users understand why the file wasn’t written if they expected it.

packages/sync/src/utils/create-generator-with-tasks.ts (1)

56-65: Optional return from run can lead to confusion.

When ExportMap is empty, this method can return void. This might confuse future maintainers if they expect a SimpleGeneratorTaskInstance. Consider adding documentation or examples clarifying the scenarios in which a task returns nothing.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 62acb20 and 1d20dc0.

📒 Files selected for processing (13)
  • .changeset/rotten-rocks-report.md (1 hunks)
  • .changeset/small-ghosts-smash.md (1 hunks)
  • packages/core-generators/src/generators/node/node-git-ignore/index.ts (1 hunks)
  • packages/fastify-generators/src/generators/auth0/auth0-module/index.ts (0 hunks)
  • packages/fastify-generators/src/generators/yoga/yoga-plugin/index.ts (0 hunks)
  • packages/project-builder-server/src/service/environment-flags.ts (1 hunks)
  • packages/project-builder-server/src/sync/generator-steps-html-writer.ts (1 hunks)
  • packages/project-builder-server/src/sync/index.ts (4 hunks)
  • packages/react-generators/src/generators/core/react/index.ts (1 hunks)
  • packages/sync/src/core/engine/dependency-sort.ts (2 hunks)
  • packages/sync/src/core/engine/generator-runner.ts (2 hunks)
  • packages/sync/src/core/generator-output.ts (1 hunks)
  • packages/sync/src/utils/create-generator-with-tasks.ts (4 hunks)
💤 Files with no reviewable changes (2)
  • packages/fastify-generators/src/generators/yoga/yoga-plugin/index.ts
  • packages/fastify-generators/src/generators/auth0/auth0-module/index.ts
🔇 Additional comments (16)
packages/project-builder-server/src/service/environment-flags.ts (1)

1-6: Consider clarifying the intended behavior of the boolean toggle.
Currently, !!process.env.BASEPLATE_WRITE_GENERATOR_STEPS_HTML will treat any non-empty environment variable value as true. If you intend for this flag to be true only when explicitly set to "true", consider an explicit check instead, e.g.:

process.env.BASEPLATE_WRITE_GENERATOR_STEPS_HTML === 'true'
packages/project-builder-server/src/sync/generator-steps-html-writer.ts (1)

77-85: Consider more descriptive naming or error handling in cleanLabel.
If the regex fails to match or the string is unexpected, the function returns the original id. Confirm this fallback is the desired behavior, or if additional logging/validation would be helpful.

packages/sync/src/core/engine/generator-runner.ts (1)

29-32: Excellent approach to collecting metadata directly with the steps.
Destructuring metadata from getSortedRunSteps keeps the logic clean. Just ensure it’s always returned even in potential edge cases with minimal or empty tasks.

packages/sync/src/core/generator-output.ts (2)

136-139: Well-structured metadata model for generator steps.
The generatorStepNodes and generatorStepEdges fields neatly capture graph data. This will be easy to extend in the future if you decide to track additional properties.


145-145: Good use of an optional metadata property.
Opting in or out of metadata helps maintain backward compatibility while providing richer data when available.

packages/sync/src/core/engine/dependency-sort.ts (1)

137-140: Ensure consistency with the documented return type.

The updated function signature returns both steps and metadata. Ensure that all callers of getSortedRunSteps correctly handle the newly introduced metadata property, especially in code that previously expected just a string array.

packages/react-generators/src/generators/core/react/index.ts (1)

110-110: Revisiting file-watch scope.

You broadened the ignore pattern to all of baseplate/**. Verify that this won’t omit necessary updates or critical ephemeral files for local development, especially if certain files in baseplate might still need to be watched.

packages/project-builder-server/src/sync/index.ts (4)

11-11: Good use of environment flags.

Using environmentFlags prevents cluttering the main codebase with environment-specific logic. The approach is cleaner and more testable.


14-14: Validate import usage of writeGeneratorStepsHtml.

This import is only used when BASEPLATE_WRITE_GENERATOR_STEPS_HTML is true. Confirm that tree shaking or bundling tools won’t remove it before runtime. You may also want to guard its usage more explicitly if the import might cause overhead.


100-103: Confirm newly introduced path for clean temporary files.

You relocated .clean_tmp to build/clean_tmp. Confirm if any code or scripts outside this file rely on the old location. This might cause unexpected clean-up issues.


192-197: Great extension of optional HTML output.

Conditionally writing the generator steps HTML is a helpful addition. This ensures minimal overhead for most users, while enabling a richer visualization for those who opt in.

packages/sync/src/utils/create-generator-with-tasks.ts (2)

44-46: Refined type defaults are beneficial.

Allowing ExportMap, DependencyMap, and TaskDependencyMap to default to an empty record streamlines the usage of the interface, especially when tasks don’t produce or consume exports. This is a clean improvement.


136-138: Broadening defaults at the task builder level.

Setting default types here greatly reduces boilerplate in user code. Just ensure there’s no silent type mismatch if tasks unexpectedly return providers.

.changeset/small-ghosts-smash.md (1)

1-6: LGTM! Appropriate versioning for the changes.

The patch version bump is correctly applied for a backwards-compatible enhancement that allows optional returns from the run function.

.changeset/rotten-rocks-report.md (1)

1-6: LGTM! Versioning aligns with feature scope.

The patch version bump is appropriate for adding new visualization capabilities without breaking changes. The description clearly communicates the addition of Cytoscape.js for generator steps visualization, which directly addresses the PR objectives.

packages/core-generators/src/generators/node/node-git-ignore/index.ts (1)

53-54: LGTM! Improved organization of build artifacts.

The consolidation of Baseplate artifacts under a single baseplate/build directory improves maintainability.

Let's verify that this change won't affect existing projects:

✅ Verification successful

Verified: Safe to consolidate build artifacts under baseplate/build

The only reference to old patterns is in vite.config.ts for Vite's watch settings, which serves a different purpose than git ignore patterns. No existing .gitignore files will be affected by this change.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for existing .gitignore files that might be affected by this change

# Search for .gitignore files containing the old patterns
echo "Checking for .gitignore files with old patterns..."
rg -l "baseplate/\.clean_tmp|baseplate/\.build_result\.json" --type gitignore

# Check if any repositories are using the old paths
echo "Checking for actual usage of old paths..."
rg -l "baseplate/\.clean_tmp|baseplate/\.build_result\.json" --type ts

Length of output: 431


Script:

#!/bin/bash
# Search .gitignore files correctly
echo "Checking .gitignore files..."
fd -t f .gitignore$ | xargs rg "baseplate/\.clean_tmp|baseplate/\.build_result\.json"

# Check the content of vite.config.ts
echo -e "\nChecking vite.config.ts content..."
cat "tests/simple/packages/web/vite.config.ts"

Length of output: 1295

Comment on lines +333 to +334
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- task.run may return undefined
const runResult = task.run(dependencies, resolvedTaskOutputs) ?? {};
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Confirm fallback logic.

The fallback of runResult ?? {} might obscure issues if the run method is intended to return a complex structure. If tasks mistakenly return undefined in an unexpected scenario, debugging can be tricky. Adding a debug log or assertion could be helpful.

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 (2)
packages/sync/src/core/engine/dependency-sort.unit.test.ts (2)

34-34: Ensure comprehensive test coverage for metadata.
While verifying steps is sufficient for checking the order, consider adding assertions to confirm that the returned metadata property (if any) also has the desired structure.


129-129: Check for partial completion vs. final steps.
You may consider verifying partial steps or intermediate states if applicable, ensuring that all expected steps are included.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1d20dc0 and 1d30997.

📒 Files selected for processing (1)
  • packages/sync/src/core/engine/dependency-sort.unit.test.ts (7 hunks)
🔇 Additional comments (5)
packages/sync/src/core/engine/dependency-sort.unit.test.ts (5)

10-10: Good job accessing the new steps property.
No issues with the updated assertion for an empty list.


43-43: Fine approach for testing reversed dependencies.
No further suggestion as the coverage for reversed dependency order is clearly tested.


87-87: Excellent: new structure verification is consistent.
All good here; the new assertion follows the updated return structure.


202-202: Validation of complex inter-dependencies is sound.
Appropriate assertion for the final step order, no concerns.


254-254: Looks great for second-level inter-dependencies.
No change needed. The test is thorough for multiple layers of tasks.

@kingston kingston merged commit a09b91f into main Jan 6, 2025
5 checks passed
@kingston kingston deleted the kingston/eng-529-create-visualizer-for-generator-tasks-dependencies branch January 6, 2025 13:57
@github-actions github-actions bot mentioned this pull request Jan 17, 2025
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