Skip to content

Convert from CJS to ESM#1219

Draft
Copilot wants to merge 5 commits intodevelopfrom
copilot/convert-cjs-to-esm
Draft

Convert from CJS to ESM#1219
Copilot wants to merge 5 commits intodevelopfrom
copilot/convert-cjs-to-esm

Conversation

Copy link
Contributor

Copilot AI commented Mar 24, 2026

Converts the module system from CommonJS to ESM, following the pattern from Azure/avocado#220.

tsconfig.json

  • target: esnext, module: nodenext, moduleResolution: nodenext
  • isolatedModules: true (required by ts-jest for nodenext)

package.json

  • Added "type": "module"
  • Test scripts use NODE_OPTIONS="--experimental-vm-modules" for Jest ESM support

Import changes

  • Added .js extensions to all ~430 relative imports
  • CJS packages (lodash, ajv, yargs, etc.) use default imports instead of named/namespace imports — Jest's ESM VM doesn't support CJS named export detection:
    // Before
    import { parseInt } from "lodash";
    import * as _ from "lodash";
    
    // After
    import lodash from "lodash";
    const { parseInt } = lodash;
    import _ from "lodash";
  • Type-only re-exports use export type for isolatedModules compliance
  • JSON imports use createRequire(import.meta.url) (prettier 2.x doesn't support with { type: "json" })

Config files

  • Renamed .js.cjs: jest.config, .eslintrc, jest.setup-file, regression jest configs
  • Added eslint-import-resolver-typescript for .js.ts resolution

Circular dependency fix

  • Extracted TYPES symbols into lib/inversifyTypes.ts to break the cycle: inversifyUtils → ajvSchemaValidator → inversifyUtils
  • Files import TYPES from inversifyTypes.ts and inversifyGetInstance/inversifyGetContainer from inversifyUtils.ts

CLI

  • Replaced yargs.commandDir() (uses require() internally) with explicit .command() calls
  • __dirname replaced with import.meta.url + fileURLToPath

Jest

  • useESM: true with extensionsToTreatAsEsm: [".ts"]
  • moduleNameMapper strips .js from relative imports for source resolution
  • Test files import jest from @jest/globals where jest.setTimeout() is used
Original prompt

This section details on the original issue you should resolve

<issue_title>Convert from CJS to ESM</issue_title>
<issue_description>Similar to Azure/avocado#220, but use these in tsconfig.json:

target: esnext
module: nodenext</issue_description>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI and others added 4 commits March 24, 2026 05:40
…config files

Co-authored-by: mikeharder <9459391+mikeharder@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/oav/sessions/90b96f9c-b1f5-4c79-911e-10f9721aa8a2
Convert namespace and named imports from CJS packages to default imports
to ensure compatibility with Jest's ESM mode. CJS packages don't provide
named exports in ESM mode, so 'import { x } from "cjs-pkg"' and
'import * as x from "cjs-pkg"' don't work as expected.

Changes:
- yargs: use default import in cli.ts, type-only imports in commands
- json-pointer: use default import across all files
- js-yaml: use default import with destructuring
- commonmark: use default import
- difflib: use default import with destructuring
- ajv: separate value (default) and type-only imports
- winston: use default import
- toposort: use default import with destructuring
- fast-json-stable-stringify: simplify to default import

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ESM compatibility

Co-authored-by: mikeharder <9459391+mikeharder@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/oav/sessions/90b96f9c-b1f5-4c79-911e-10f9721aa8a2
Copilot AI changed the title [WIP] Convert from CJS to ESM in tsconfig.json Convert from CJS to ESM Mar 24, 2026
Copilot AI requested a review from mikeharder March 24, 2026 06:18
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.

Convert from CJS to ESM

2 participants