Skip to content

feat(cli): bundle jssg codemods pre-publish #1639

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 3 commits into from
Jul 22, 2025
Merged

Conversation

mohebifar
Copy link
Member

📚 Description

  • Introduced a new bundle command in the JSSG CLI for bundling JSSG codemods and their dependencies.
  • Implemented a bundler utility that processes and bundles JS files, integrating with existing module resolution.
  • Refactored existing commands to accommodate the new bundling functionality.
  • Auto bundle JSSG codemods on publish

🔗 Linked Issue

🧪 Test Plan

📄 Documentation to Update

- Introduced a new `Bundle` command in the JSSG CLI for bundling JavaScript/TypeScript files and their dependencies.
- Enhanced the `validate_package_structure` function to return JS files to be bundled.
- Implemented a bundler utility that processes and bundles JS files, integrating with existing module resolution.
- Updated the `Cargo.toml` to include the `regex` dependency and added new utility modules for bundling.
- Refactored existing commands to accommodate the new bundling functionality.
Copy link

vercel bot commented Jul 22, 2025

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

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
codemod ⬜️ Ignored (Inspect) Visit Preview Jul 22, 2025 11:04pm

Copy link

pkg-pr-new bot commented Jul 22, 2025

Open in StackBlitz

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

commit: 3aa120d

Comment on lines +57 to +61
/// CommonJS-style module system
CommonJS,
/// Custom runtime with require/module.exports
Custom,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

CJS is actually require/module.exports
and esm is import/export

Copy link
Member Author

Choose a reason for hiding this comment

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

It just means that the code in the module factory turns into CJS style code i.e. import {X} from 'module' is converted to const {X} = __codemod_require('module') and export { X } is converted to exports.X = X.

Under the hood, no import or export actually happens as the modules are stored in an object record.

Copy link
Contributor

Choose a reason for hiding this comment

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

make sens maybe rephrase little bit the comment

@AugustinMauroy
Copy link
Contributor

maybe during bundling process. You can check if import is node:* is codemod have this api let's use rewite it instead throw an error

@mohebifar mohebifar requested a review from Copilot July 22, 2025 22:02
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 introduces bundling functionality for JSSG codemods to improve distribution and dependency management. The key enhancement is automatic bundling of JavaScript/TypeScript codemods and their dependencies during the publish process.

Key Changes:

  • Added a comprehensive JavaScript/TypeScript bundler system that transforms ES6 modules to CommonJS format
  • Implemented a new bundle command in the JSSG CLI for standalone bundling operations
  • Integrated automatic bundling into the publish workflow for JS AST grep steps

Reviewed Changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
crates/codemod-sandbox/src/utils/bundler/mod.rs Core bundler implementation with dependency resolution and module transformation
crates/codemod-sandbox/src/utils/bundler/module_transformer.rs SWC-based ES6 to CommonJS module transformer
crates/codemod-sandbox/src/utils/bundler/module_analyzer.rs AST visitor for analyzing module imports and exports
crates/codemod-sandbox/src/utils/bundler/runtime_*.tpl Runtime templates for CommonJS and custom module systems
crates/cli/src/commands/jssg/bundle.rs New CLI command for manual bundling operations
crates/cli/src/commands/publish.rs Enhanced publish command with automatic JS bundling

@mohebifar
Copy link
Member Author

mohebifar commented Jul 22, 2025

maybe during bundling process. You can check if import is node:* is codemod have this api let's use rewite it instead throw an error

Ah good point to account for node:*. Will fix now.

@AugustinMauroy
Copy link
Contributor

Ah good point to account for node:*. Will fix now.

Verify if jssg correctly run node:* instead you I'll need to review it before run or make an alias.

@mohebifar
Copy link
Member Author

It just works. LLRT already comes with aliases for node:*. So all is good as per my tests.

@mohebifar mohebifar merged commit 29f3be1 into main Jul 22, 2025
13 checks passed
@mohebifar mohebifar deleted the feat/bundler-on-publish branch July 22, 2025 23:12
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