javascript-refactoring

Extract shared JavaScript logic into .cjs modules for gh-aw workflows.

4.9k|489|Updated Aug 12, 2025
One-click install
npx skills add https://github.com/github/gh-aw --skill javascript-refactoring-github
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: javascript-refactoring
Source: https://github.com/github/gh-aw/tree/main/skills/javascript-refactoring
Command: npx skills add https://github.com/github/gh-aw --skill javascript-refactoring-github

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps developers modularize large JavaScript codebases by extracting shared logic into separate .cjs modules, enabling reuse across gh-aw workflows and simplifying maintenance.

Core Features & Use Cases

  • Modularization: Convert monolithic scripts into reusable utilities that can be required by multiple workflows.
  • Bundling Readiness: Align utilities with gh-aw's bundling process so local dependencies are inlined during build.
  • Use Case: Refactor a top-level script that handles API calls into a standalone module and import it from several scripts to avoid duplication.

Quick Start

Create a new file under pkg/workflow/js, implement a function, export it, add a test, and register it in the JavaScript sources registry so other scripts can require('./your_module.cjs').

Frequently Asked Questions about javascript-refactoring

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I modularize JavaScript code into reusable CommonJS modules?

JavaScript modularization solves the problem of duplicated logic across gh-aw workflows by extracting shared code into reusable .cjs files. You create modules under pkg/workflow/js, export functions, and import them in multiple workflow scripts to eliminate duplication and simplify maintenance.

How do I bundle local CommonJS dependencies for gh-aw workflows?

To bundle local CommonJS dependencies for gh-aw workflows, you must wire new .cjs modules into GetJavaScriptSources(). The bundler then inlines these local dependencies during the build process, ensuring workflow scripts have all required logic available at execution time.

Why does my bundled JavaScript execute immediately instead of exporting main?

Bundled JavaScript executes immediately instead of exporting main when top-level scripts invoke functions at runtime. To fix this, refactor scripts to export main without immediate invocation so the gh-aw bundler can properly inject execution logic during the build process.

Can I use .cjs modules to simplify testing for shared JavaScript utilities?

Yes, you can use .cjs modules to simplify testing for shared JavaScript utilities. Extracting logic into separate CommonJS modules under pkg/workflow/js allows you to add targeted unit tests for each utility, ensuring reusable functions are validated independently before workflow integration.

What is the best way to refactor a monolithic JavaScript script for multiple workflows?

The best way to refactor a monolithic JavaScript script for multiple workflows is to extract shared logic into a standalone .cjs module, register it in GetJavaScriptSources(), and import it where needed. This modularization approach enables reuse and aligns with gh-aw's bundling process.