javascript-refactoring
FeaturedSplit large JavaScript files into maintainable modules safely.
Code & Development 5,125 stars
539 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 split JavaScript into maintainable CommonJS modules in gh-aw without drifting into dead embedding patterns.
## Overview
The current gh-aw architecture is action-centric:
- Shared JS modules live under `pkg/workflow/js/*.cjs` and `actions/setup/js/*.cjs`
- Action source files live under `actions/<action-name>/src/`
- Generated action bundles are committed under `actions/<action-name>/index.js`
- Shipping is driven by the action build pipeline (`make actions-build`, `gh aw actions-build`) and dependency maps such as `pkg/cli/actions_build_command.go`
- `pkg/workflow/js.go` is a stub; it no longer owns the runtime JavaScript shipping path for the main workflows
If you are refactoring a workflow utility, prefer the current action/module architecture over any older `//go:embed` pattern.
### 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 workflow bundler or action build step can wrap the script with `await main()` at execution time
- The m...
Details
- Author
- github
- Repository
- github/gh-aw
- Created
- 1 years ago
- Last Updated
- today
- Language
- Go
- License
- MIT
Similar Skills
Semantically similar based on skill content — not just same category
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.
5 Updated 5 days ago
Sagargupta16 Code & Development Listed
refactor
Code refactoring patterns - extract, split, restructure without changing behavior.
3 Updated today
djnsty23 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 1 weeks ago
swiftpostlabs