Skip to content

Conversation

@Karnaukhov-kh
Copy link
Member

@Karnaukhov-kh Karnaukhov-kh commented Aug 22, 2025

ESM Migration and Dependency Consolidation

Summary

Migrates the Angular MCP Toolkit from CommonJS to ES Modules (ESM) and consolidates dependencies by adopting @code-pushup/* packages to replace internal shared libraries.

Technical Changes

Module System Migration

  • Root Configuration: Added "type": "module" to root package.json
  • Jest Configuration: Migrated jest.preset.jsjest.preset.mjs with ESM export syntax
  • Webpack Configuration: Renamed webpack.config.jswebpack.config.cjs to maintain CommonJS compatibility
  • TypeScript Configuration: Updated tsconfig.json files to remove CommonJS-specific settings

Dependency Consolidation

  • External Dependencies: Migrated from internal @push-based/* packages to @code-pushup/* equivalents:
    • @push-based/models@code-pushup/models
    • @push-based/utils@code-pushup/utils
    • Internal utilities consolidated under @code-pushup/core
  • Package Removal: Eliminated packages/shared/angular-cli-utils package (149 lines removed)
  • Models Cleanup: Removed extensive test suites and implementation files from packages/shared/models (3,000+ lines removed)

Import Statement Updates

  • Import Syntax: Updated all import statements across 85+ TypeScript files to use new package paths
  • Schema Imports: Updated Zod schema imports in component contract and validation modules
  • Tool Imports: Refactored MCP server tool imports to use consolidated packages

Build System Changes

  • Package Configurations: Updated package.json files across all workspace packages to reflect new dependencies
  • TypeScript Compilation: Adjusted tsconfig.lib.json files for ESM compatibility
  • Jest Configuration: Updated test configurations for ESM module resolution

Files Modified

  • Configuration Files: 15 package.json, 8 tsconfig files, jest configurations
  • Source Code: 85+ TypeScript files with import statement updates
  • Build Tools: Webpack, Jest, and TypeScript compiler configurations

Impact

  • Bundle Size: Reduced overall codebase by ~4,100 lines through dependency consolidation
  • Build Performance: Improved build times through external dependency usage
  • Module Compatibility: Full ESM compliance for modern Node.js environments
  • Maintenance: Reduced maintenance overhead by leveraging external packages

Breaking Changes

  • Requires Node.js environments with ESM support
  • Internal package imports must be updated to use @code-pushup/* packages
  • Jest configurations require ESM-compatible setup

@Karnaukhov-kh Karnaukhov-kh changed the title feat(): migration to esm, maybe feat(): migration to esm Aug 22, 2025
.cursor/mcp.json Outdated
"args": [
"./packages/angular-mcp/dist/main.js",
"--workspaceRoot=/home/spoltorak/projects/x-mcp",
"--workspaceRoot=/Users/kyrylokarnaukhov/Documents/projects/angular-mcp-toolkit",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets avoid using local paths in the source

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Local MCP is not tracked anymore, example file available

| **Resource Provider** | `registerResources()` | Extend logic to aggregate custom docs or design-system assets. |

All tools share the `ToolsConfig` interface (`@push-based/models`) that bundles:
All tools share the `ToolsConfig` interface (`@code-pushup/models`) that bundles:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not tia everything to CP.. The reason we have out own models and utils is to decouple a bit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tools are sharing @push-based/models ToolsConfig. Import name fixed.

```ts
import { z } from 'zod';
import { ToolSchemaOptions, ToolsConfig } from '@push-based/models';
import { ToolSchemaOptions, ToolsConfig } from '@code-pushup/models';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely should be '@push-based/models';

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, fixed

Comment on lines 34 to 37
const module = await import(absPath);

// Handle both ES modules (export default) and CommonJS (module.exports)
// Support: export default dsComponents, module.exports = { dsComponents }, or direct module.exports = dsComponents
const dsComponents = module.default || module.dsComponents || module;
// Pure ESM: use export default
const dsComponents = module.default;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems quickly added instead of thought through

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open for suggestion, only thing that was not breaking tools.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If its needed to make it work, we could think of some reusable thing or docs on the WHY.
The case module.default || module; e.g. ise repeated module.dsComponents not.

It will help to establish a pattern that others can follow more easily.

Copy link
Member Author

@Karnaukhov-kh Karnaukhov-kh Aug 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a helper function in utils. Updated docs. see 720d27f & 775be79


// Handle both ES modules (export default) and CommonJS (module.exports)
const rawData = module.default || module.dsComponents || module;
// Pure ESM: use export default
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we avoid those kind of polluting comments pls

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 1f4a181


// Handle both ES modules (export default) and CommonJS (module.exports)
dsComponents = module.default || module.dsComponents || module;
// Pure ESM: use export default
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove pls. Same on all other places

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 1f4a181

Copy link
Collaborator

@BioPhoton BioPhoton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some Comments.

In general the PR was quite big which makes it harder to review and it takes longer. Also the quality of the review drops at a certain volumr of changes.

The first and best thing is to:

  • chunck big PR into smaller pieces
  • do a self revirew before commiting code or asking for feedback

@Karnaukhov-kh
Copy link
Member Author

Commits focus description for easier navigation

  • @4d92340 - Initial ESM migration attempt
  • @0f112f9 - Remove unused angular-cli-utils dependency
  • @c972a86 - Update cpu/core dependency version
  • @7422b59 - Integrate cpu/models imports throughout codebase
  • @9a538d2 - Clean up model definitions and structure
  • @5535a89 - Update documentation and remove obsolete tests
  • @4dcadc1 - Replace imports with cpu/utils where applicable
  • @b1eab19 - Package maintenance and updates
  • @4d59481 - Documentation improvements
  • @7674b0f - Fix build system issues
  • @1f4a181 - Address code review feedback and cleanup
  • @2950e39 - Improve import documentation
  • @8205922 - Clean up local MCP configuration files
  • @720d27f - Add default-export-loader utility function
  • @775be79 - Final utils documentation adjustments

Copy link
Collaborator

@BioPhoton BioPhoton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments

.cursor/mcp.json Outdated
@@ -1,22 +0,0 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we remove the setup? I think it's quite helpful for testing too.. maybe a postinstall?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have example file for this that should be copied and renamed to mcp.json by developer who want to use it, having just mcp.json causes override hell from dev to dev.

@Karnaukhov-kh Karnaukhov-kh merged commit 3b9e9d6 into main Oct 10, 2025
1 check passed
@Karnaukhov-kh Karnaukhov-kh deleted the feature/esm-migration branch October 10, 2025 11:20
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