javascript-refactoring

Solid

Split large JavaScript files into maintainable modules safely.

Code & Development 4,612 stars 420 forks Updated today MIT

Install

View on GitHub

Quality Score: 91/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# JavaScript Code Refactoring Guide Use this guide to refactor JavaScript into separate `.cjs` files in gh-aw. ## Overview gh-aw uses CommonJS modules (`.cjs`) for JavaScript in GitHub Actions workflows. These files are: - Embedded in the Go binary using `//go:embed` directives - Bundled using a custom JavaScript bundler that inlines local `require()` calls - Executed in GitHub Actions using `actions/github-script@v8` ### Top-Level Script Pattern Top-level `.cjs` scripts executed directly in workflows follow this pattern: **✅ Correct Pattern - Export main, but don't call it:** ```javascript async function main() { // Script logic here core.info("Running the script"); } module.exports = { main }; ``` **❌ Incorrect Pattern - Don't call main in the file:** ```javascript async function main() { // Script logic here core.info("Running the script"); } await main(); // ❌ Don't do this! module.exports = { main }; ``` **Why this pattern?** - The bundler automatically injects `await main()` during inline execution in GitHub Actions - This allows the script to be both imported (for testing) and executed (in workflows) - It provides a clean separation between module definition and execution - It enables better testing by allowing tests to import and call `main()` with mocks **Examples of top-level scripts:** - `create_issue.cjs` - Creates GitHub issues - `add_comment.cjs` - Adds comments to issues/PRs - `add_labels.cjs` - Adds labels to issues/PRs - `update_project.cj...

Details

Author
github
Repository
github/gh-aw
Created
10 months ago
Last Updated
today
Language
Go
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category