javascript-refactoring
SolidSplit large JavaScript files into maintainable modules safely.
Code & Development 4,819 stars
466 forks Updated today MIT
Install
Quality Score: 90/100
Stars 20%
Recency 20%
Frontmatter 20%
Documentation 15%
Issue Health 10%
License 10%
Description 5%
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
- 11 months ago
- Last Updated
- today
- Language
- Go
- License
- MIT
Integrates with
Similar Skills
Semantically similar based on skill content — not just same category
Code & Development Solid
github-script
Write robust JavaScript for GitHub Actions github-script steps.
4,819 Updated today
github Code & Development Listed
refactoring
Use when restructuring code without changing behavior -- extracting functions, renaming, moving files, reducing duplication, migrating between patterns (JS to TS, CJS to ESM), or addressing code smells. Covers safe refactoring workflows for any language.
4 Updated 3 days ago
Sagargupta16 AI & Automation Listed
ref-sp-js-javascript
Portable JavaScript guidance for scripts and browser code with JSDoc-based typing. Use when: writing plain JavaScript, adding JSDoc, or keeping JavaScript maintainable without TypeScript.
0 Updated 4 days ago
swiftpostlabs