Skip to content

Feat(jssg): better validation #1620

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

AugustinMauroy
Copy link
Contributor

@AugustinMauroy AugustinMauroy commented Jul 18, 2025

Description

It's reduce the amount of possible bug

  • validate js entry point if they exist
  • clean serval thing

Copy link

vercel bot commented Jul 18, 2025

@AugustinMauroy is attempting to deploy a commit to the Codemod Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

pkg-pr-new bot commented Jul 18, 2025

Open in StackBlitz

npm i https://pkg.pr.new/codemod@1620

commit: 93323e6

@AugustinMauroy AugustinMauroy changed the title Feat(jssg): bundle js file Feat(jssg): better validation Jul 22, 2025
@AugustinMauroy AugustinMauroy marked this pull request as ready for review July 22, 2025 21:49
@mohebifar mohebifar requested a review from Copilot July 22, 2025 22:43
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances validation for JavaScript AST-grep files and refactors package handling code to use "codemod" terminology consistently. The changes aim to reduce bugs by ensuring referenced JavaScript files exist before workflow execution.

  • Adds validation for js-ast-grep step JavaScript file existence
  • Refactors function and variable names from "package" to "codemod" terminology
  • Consolidates validation logic by moving duplicate code to shared functions

Reviewed Changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
crates/models/src/workflow.rs Adds validate_js_ast_grep_files method and optional name/description fields
crates/models/Cargo.toml Adds anyhow dependency for error handling
crates/core/src/utils.rs Adds file existence check in parse_workflow_file and reorganizes imports
crates/core/Cargo.toml Adds anyhow dependency
crates/cli/src/commands/workflow/validate.rs Moves validation logic here and integrates JS file validation
crates/cli/src/commands/publish.rs Refactors to use shared validation and "codemod" terminology
crates/cli/README.md Documents new JS file validation feature
Comments suppressed due to low confidence (1)

crates/cli/src/commands/publish.rs:386

  • The variable tarball_data is assigned but never used in the visible code. Consider removing it or using it in the multipart form creation.
    let tarball_data = fs::read(tarball_path)?;

/// Parse a workflow definition from a file
pub fn parse_workflow_file<P: AsRef<Path>>(path: P) -> Result<Workflow> {
if !path.as_ref().exists() {
return Err(anyhow!(
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

The anyhow! macro is used but anyhow is imported with different syntax. The import shows use anyhow::{Context, Result}; but anyhow! macro requires use anyhow::anyhow; or the macro won't be available.

Copilot uses AI. Check for mistakes.

Comment on lines +3 to 10
use butterflow_models::{Error, Node, Result, Workflow};
use serde_yaml;
use std::collections::{HashMap, HashSet};
use std::fs;
use std::path::{Path, PathBuf};

use butterflow_models::step::StepAction;
use serde_yaml;

use butterflow_models::{Error, Node, Result, Workflow};

/// Parse a workflow definition from a file
pub fn parse_workflow_file<P: AsRef<Path>>(path: P) -> Result<Workflow> {
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

There are conflicting Result imports. Line 1 imports anyhow::Result and line 3 imports butterflow_models::Result. This will cause a compilation error due to ambiguous type resolution.

Copilot uses AI. Check for mistakes.

@@ -186,7 +189,7 @@ pub async fn handler(args: &Command, telemetry: &dyn TelemetrySender) -> Result<
})?;

// Upload package
let response = upload_package(
let response = upload_codemod(
&registry_url,
&bundle_path,
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

The variable bundle_path is used but it was renamed to tarball_path on line 159. This will cause a compilation error.

Suggested change
&bundle_path,
&tarball_path,

Copilot uses AI. Check for mistakes.

validate_codemod_manifest_structure(
&args.workflow,
&utils::parse_workflow_file(&args.workflow)?,
)?;
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

Missing Ok(()) return statement. The function signature indicates it returns Result<()> but there's no explicit return value after the validation calls.

Suggested change
)?;
)?;
Ok(())

Copilot uses AI. Check for mistakes.

Copy link
Member

@mohebifar mohebifar left a comment

Choose a reason for hiding this comment

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

CI is failing. Have you tried running cargo check and cargo clippy --fix --allow-dirty && cargo fmt?

@@ -1,14 +1,20 @@
use anyhow::{Context, Result};
Copy link
Member

Choose a reason for hiding this comment

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

We use anyhow in CLI only. In CLI, we use anyhow for ergonomic error propagation and user-facing reports.
In core/library crates, we define typed errors with thiserror.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it I had moved the function from cli to core to reused it so I have to modify that

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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy