javascript-refactoring

Refactor JavaScript into modular CommonJS .cjs files for GitHub Actions workflows.

Updated Feb 26, 2026
One-click install
npx skills add https://github.com/kaushal-waygood/agentic-self-healing-ci --skill javascript-refactoring-kaushal-waygood
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: javascript-refactoring
Source: https://github.com/kaushal-waygood/agentic-self-healing-ci/tree/main/skills/javascript-refactoring
Command: npx skills add https://github.com/kaushal-waygood/agentic-self-healing-ci --skill javascript-refactoring-kaushal-waygood

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This guide reduces friction when extracting shared JavaScript functionality into standalone CommonJS .cjs modules for use in GitHub Actions, ensuring code is testable, bundleable, and embeddable in the Go binary.

Core Features & Use Cases

  • Module Pattern Guidance: Explains the required top-level pattern of exporting main without calling it so scripts can be both imported for tests and executed when bundled.
  • Bundling & Embedding: Describes how to register sources with //go:embed, add entries to GetJavaScriptSources or scripts.go, and implement a sync.Once bundling getter for main scripts.
  • Testing & Conventions: Covers vitest test patterns with global core/github mocks, naming conventions for .cjs and .test.cjs files, and guidelines for using relative require() imports so the custom bundler can inline dependencies.

Quick Start

Extract the shared functions into a new pkg/workflow/js/my_module.cjs, add a corresponding my_module.test.cjs with vitest and global mocks, and register the module in pkg/workflow/js.go using a //go:embed variable so it can be bundled into workflows.

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 into reusable CommonJS modules for GitHub Actions?

Refactoring JavaScript into reusable CommonJS .cjs modules involves extracting shared utilities into standalone files, exporting main functions without invoking them in-file, and registering sources with //go:embed for bundling into the Go binary.

How do I test JavaScript modules extracted for GitHub Actions workflows?

Testing extracted JavaScript modules requires adding corresponding .test.cjs files using vitest, setting up global mocks for core and github APIs, and importing the module to verify exported functions without triggering execution.

How does bundling JavaScript into a Go binary work with go:embed?

Bundling JavaScript into a Go binary uses //go:embed directives to register .cjs files in pkg/workflow/js.go or scripts.go, adding entries to GetJavaScriptSources, and implementing bundler getter functions with sync.Once for lazy initialization.

Can I use relative require() imports when refactoring JavaScript into CommonJS modules?

Relative require() imports are required when refactoring JavaScript into CommonJS .cjs modules so the custom bundler can properly inline dependencies during the Go binary embedding process.

Why should exported main functions not be called directly in refactored .cjs files?

Exported main functions must not be called directly in .cjs files so the scripts remain importable for vitest testing while still executing when bundled and run via actions/github-script in GitHub Actions workflows.

What naming conventions should I follow when creating CommonJS modules for GitHub Actions?

CommonJS modules should use .cjs file extensions for source files and .test.cjs for corresponding vitest test files, placing them in the pkg/workflow/js/ directory to ensure proper bundler recognition and Go embedding.