-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor: Extract shared types and replace CommonJS require() with ES6 imports #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
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>
There was a problem hiding this 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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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: Extractedenvironment,options, andtokenResponsetypes previously defined in Core.ts and Accounts.tssrc/resources/FilterOptions.ts: ExtractedFilterOptions,Filter, andFilterTypetypes from ListResource.tsImport Modernization
require('ec.errors')()andrequire('../package.json')statements with ES6 importsresolveJsonModuleandesModuleInteropto tsconfig.jsonimport typesyntax in Resource.ts for type-only ListResource referenceBefore/After
Before:
After:
Eliminated Circular Dependencies (6 of 12)
Remaining Architectural Dependencies (6)
These are intentional design patterns based on class inheritance and bidirectional resource relationships.
Original prompt
💡 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.