Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 22, 2025

Overview

This PR removes all webpack/ncc bundling artifacts from the ESLint formatters and restores them to standard Node.js modules with clean, maintainable source code.

Problem

All formatter packages were previously bundled with webpack/ncc, which added significant boilerplate code and made the source difficult to read and maintain. Each formatter file contained:

  • Webpack bootstrap code (~60 lines of boilerplate)
  • __webpack_modules__ object wrapper
  • Custom __nccwpck_require__ function instead of standard require()
  • Module cache implementation
  • Webpack runtime compatibility code

For example, a simple formatter like eslint-formatter-json that should be ~10 lines was expanded to 66 lines due to bundling overhead.

Solution

1. Removed Bundling Artifacts

  • Eliminated all webpack boilerplate code
  • Removed __webpack_modules__ wrapper objects
  • Replaced __nccwpck_require__ with standard Node.js require() calls
  • Removed module cache and webpack runtime code

2. Extracted Shared Modules

Created xml-escape.js helper modules in packages that share this functionality:

  • eslint-formatter-checkstyle/xml-escape.js
  • eslint-formatter-jslint-xml/xml-escape.js
  • eslint-formatter-junit/xml-escape.js

This follows the principle of extracting bundled modules into separate files as specified in the requirements.

3. Converted to Standard Node.js

All formatters now use standard require() calls:

// Before: bundled with __nccwpck_require__
const chalk = __nccwpck_require__(242);

// After: standard Node.js require
const chalk = require('chalk');

Impact

  • Code reduction: ~1,051 lines of bundling code removed, ~410 lines of clean source added
  • Readability: Each formatter is now easy to read and understand
  • Maintainability: Standard Node.js practices make debugging and modifications straightforward
  • Functionality: All 40 tests pass, no breaking changes
  • Security: CodeQL scan shows no vulnerabilities

Files Changed

Modified (10 files):

  • packages/eslint-formatter-checkstyle/index.js
  • packages/eslint-formatter-compact/index.js
  • packages/eslint-formatter-jslint-xml/index.js
  • packages/eslint-formatter-json/index.js
  • packages/eslint-formatter-json-with-metadata/index.js
  • packages/eslint-formatter-junit/index.js
  • packages/eslint-formatter-stylish/index.js
  • packages/eslint-formatter-tap/index.js
  • packages/eslint-formatter-unix/index.js
  • packages/eslint-formatter-visualstudio/index.js

Created (3 files):

  • packages/eslint-formatter-checkstyle/xml-escape.js
  • packages/eslint-formatter-jslint-xml/xml-escape.js
  • packages/eslint-formatter-junit/xml-escape.js

Testing

✅ All 40 existing tests pass
✅ No security vulnerabilities detected (CodeQL)
✅ Dependencies properly declared in package.json files
✅ Code formatted with Prettier

Original prompt

Cleanup the source code in the repository fregante/eslint-formatters to remove artifacts of bundling. Specifically:

  1. Leave the raw require() calls in place.
  2. If a bundle contains multiple modules, extract each module into its own file.

Ensure the code remains functional and adheres to the standard practices of Node.js development.

This pull request was created as a result of the following prompt from Copilot chat.

Cleanup the source code in the repository fregante/eslint-formatters to remove artifacts of bundling. Specifically:

  1. Leave the raw require() calls in place.
  2. If a bundle contains multiple modules, extract each module into its own file.

Ensure the code remains functional and adheres to the standard practices of Node.js development.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
Copilot AI changed the title [WIP] Cleanup source code to remove bundling artifacts Remove webpack bundling artifacts and restore standard Node.js modules Oct 22, 2025
Copilot AI requested a review from fregante October 22, 2025 16:17
@fregante fregante marked this pull request as ready for review October 22, 2025 16:34
@fregante fregante changed the title Remove webpack bundling artifacts and restore standard Node.js modules Cleanup source code from bundling artifacts Oct 22, 2025
@fregante fregante merged commit 1a5c63c into main Oct 22, 2025
3 checks passed
@fregante fregante deleted the copilot/cleanup-source-code-artifacts branch October 22, 2025 16:34
@ruben-moxio
Copy link

@fregante This change breaks the eslint-formatter-checkstyle

root@51ae34940f4b:/app# node_modules/.bin/eslint -f checkstyle -o build-logs/eslint.xml .
/app/node_modules/eslint-formatter-checkstyle/index.js Error: Cannot find module './xml-escape'
Require stack:
- /app/node_modules/eslint-formatter-checkstyle/index.js
    at Function._resolveFilename (node:internal/modules/cjs/loader:1365:15)
    at defaultResolveImpl (node:internal/modules/cjs/loader:1021:19)
    at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1026:22)
    at Function._load (node:internal/modules/cjs/loader:1175:37)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
    at Module.require (node:internal/modules/cjs/loader:1445:12)
    at require (node:internal/modules/helpers:135:16)
    at Object.<anonymous> (/app/node_modules/eslint-formatter-checkstyle/index.js:6:19)
    at Module._compile (node:internal/modules/cjs/loader:1688:14) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/app/node_modules/eslint-formatter-checkstyle/index.js' ]
}

@githrdw githrdw mentioned this pull request Oct 23, 2025
Copilot AI mentioned this pull request Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants