Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 18, 2025

Reduced circular dependencies from 12 to 6 by extracting commonly-imported types into separate modules. Modernized all CommonJS require() statements to ES6 imports.

Changes

Type Extraction

  • src/types.ts: Extracted environment, options, and tokenResponse types previously defined in Core.ts and Accounts.ts
  • src/resources/FilterOptions.ts: Extracted FilterOptions, Filter, and FilterType types from ListResource.ts
  • Updated 70+ files to import from new type modules instead of circular dependencies

Import Modernization

  • Replaced all 10 require('ec.errors')() and require('../package.json') statements with ES6 imports
  • Added resolveJsonModule and esModuleInterop to tsconfig.json
  • Used TypeScript import type syntax in Resource.ts for type-only ListResource reference

Before/After

Before:

// Core.ts
const { convertValidationError } = require('ec.errors')();
import { environment } from './Core';  // Circular dependency

After:

// Core.ts
import { convertValidationError } from 'ec.errors';
import { environment } from './types';  // No circular dependency

Eliminated Circular Dependencies (6 of 12)

  • Core ↔ EventEmitter
  • Core ↔ TokenStore
  • Core ↔ helper
  • helper ↔ ListResource ↔ Resource
  • Accounts ↔ AccountList ↔ AccountResource

Remaining Architectural Dependencies (6)

  • ListResource ↔ Resource (inheritance: ListResource extends Resource)
  • EntryResource → LiteEntryResource (inheritance)
  • DataManager/PublicAPI resource cross-references (4 cycles in DMAccountResource, RoleResource, LiteDMAccountResource, LiteRoleResource)

These are intentional design patterns based on class inheritance and bidirectional resource relationships.

Original prompt

remove dependency circles and require statements


💡 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.

Copilot AI and others added 3 commits November 18, 2025 17:23
Co-authored-by: michaellocher <17722361+michaellocher@users.noreply.github.com>
Co-authored-by: michaellocher <17722361+michaellocher@users.noreply.github.com>
Co-authored-by: michaellocher <17722361+michaellocher@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove dependency circles and require statements Refactor: Extract shared types and replace CommonJS require() with ES6 imports Nov 18, 2025
Copilot AI requested a review from michaellocher November 18, 2025 17:42
@michaellocher michaellocher marked this pull request as ready for review November 18, 2025 20:17
Copilot AI review requested due to automatic review settings November 18, 2025 20:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the codebase to reduce circular dependencies by extracting shared types into dedicated modules and modernizes all CommonJS require() statements to ES6 imports. The changes successfully reduce circular dependencies from 12 to 6 by moving environment, options, and tokenResponse types to src/types.ts, and FilterOptions, Filter, and FilterType to src/resources/FilterOptions.ts.

  • Extracted commonly-imported types to break circular dependencies
  • Replaced 10+ CommonJS require() calls with ES6 imports
  • Updated TypeScript configuration to support JSON imports and ES module interop

Reviewed Changes

Copilot reviewed 70 out of 71 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tsconfig.json Added resolveJsonModule and esModuleInterop compiler options to support ES6 imports
src/types.ts New file containing extracted environment, options, and tokenResponse types previously in Core.ts and Accounts.ts
src/resources/FilterOptions.ts New file containing extracted FilterOptions, Filter, and FilterType types from ListResource.ts
src/Core.ts Removed type exports, updated to import types from new modules, replaced require() with ES6 imports
src/Accounts.ts Removed tokenResponse type export, updated imports to use new type modules
src/helper.ts Replaced require() calls with ES6 imports for ec.errors and package.json
src/Problem.ts Changed function name from getLocalised to getLocalized, replaced require() with ES6 import
src/resources/Resource.ts Used import type syntax for ListResource to break circular dependency, updated FilterOptions import
src/resources/ListResource.ts Removed type definitions, added re-exports from FilterOptions for backward compatibility
src/DataManager.ts Updated imports to use new type modules, replaced require() with ES6 import
src/PublicAPI.ts Updated imports to use new type modules, replaced require() with ES6 imports
src/Session.ts Updated to import types from types.ts instead of Core.ts
src/Apps.ts Updated to import types from types.ts instead of Core.ts
src/TokenStore.ts Updated to import environment type from types.ts
src/EventEmitter.ts Updated to import environment type from types.ts
src/resources/publicAPI/*.ts Updated 13 files to import environment type from types.ts
src/resources/datamanager/*.ts Updated 13 files to import environment type from types.ts
src/resources/apps/*.ts Updated 11 files to import environment type from types.ts
src/resources/accounts/*.ts Updated 8 files to import environment and tokenResponse types from types.ts

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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