javascript-refactoring

Refactor JavaScript code into standalone CommonJS modules with JSDoc and Vitest tests.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill guides developers in refactoring JavaScript code into modular .cjs files within the gh-aw repository, ensuring clean, maintainable, and testable code for GitHub Actions workflows. It helps improve code quality and collaboration for AI-driven automation.

Core Features & Use Cases

  • Modular Code Structure: Learn to create new .cjs files for shared functionality, following clear naming conventions and JSDoc documentation.
  • Robust Testing: Implement Vitest for unit testing, including mocking GitHub Actions globals and ensuring test isolation.
  • Go Embedding & Bundling: Understand how JavaScript modules are embedded in the Go binary and bundled for execution in GitHub Actions.
  • Local require() Usage: Use CommonJS require() for seamless dependency management within JavaScript files.
  • Use Case: A developer has a large JavaScript file with shared utility functions. This skill guides them to extract these functions into a new my_module.cjs file, create corresponding tests, and integrate it into the Go build system.

Quick Start

Consult the javascript-refactoring skill to create a new format_timestamp.cjs utility module and integrate it into the gh-aw build system.

Frequently Asked Questions about javascript-refactoring

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

FAQPage Schema
How do I refactor JavaScript code into CommonJS modules for GitHub Actions?

Refactor JavaScript into standalone `.cjs` files by extracting shared functions, exporting a main function without invoking it, using `// @ts-check` and GitHub Actions types, and documenting with JSDoc. This modularizes code for reuse across workflows and enables Go embedding.

What's the best way to test CommonJS modules in a GitHub Actions workflow?

Use Vitest to write unit tests for `.cjs` modules, mocking GitHub Actions globals and ensuring test isolation. Tests verify logic before embedding modules into the Go binary for workflow execution.

Can I use CommonJS require() for dependencies in GitHub Actions scripts?

Yes, use local `require()` calls within `.cjs` files for seamless dependency management. Avoid disallowed global imports; follow the modular pattern to keep dependencies scoped and testable.

How do JavaScript modules get embedded and executed in GitHub Actions workflows?

JavaScript modules are bundled as `.cjs` files and embedded into the Go binary using `//go:embed`, then executed as part of GitHub Actions workflow execution. This approach maintains modularity while enabling inline execution.

When should I extract code into a separate CommonJS module?

Extract shared utility functions and logic into `.cjs` modules when code is reused across multiple workflow scripts. This improves maintainability, enables isolated testing, and prepares functions for bundling and inline execution.

Do I need to follow specific naming conventions for CommonJS modules in gh-aw?

Yes, create `.cjs` files with clear naming conventions and document exports with JSDoc. This ensures consistency across the gh-aw repository and clarifies intent for other developers and the Go build system.