feat: migrate from CJS to ESM by bliuchak · Pull Request #654 · apify/proxy-chain · GitHub
Skip to content

feat: migrate from CJS to ESM#654

Merged
bliuchak merged 9 commits into
version-3.0from
feat/cjs-to-esm-v3
Apr 30, 2026
Merged

feat: migrate from CJS to ESM#654
bliuchak merged 9 commits into
version-3.0from
feat/cjs-to-esm-v3

Conversation

@bliuchak

Copy link
Copy Markdown
Contributor

This PR migrates from CJS to ESM.

Close #640

@bliuchak bliuchak self-assigned this Apr 29, 2026
@bliuchak bliuchak added medium priority Medium priority issues to be done in a couple of sprints. tech roadmap Issues contributing to tech roadmap. t-unblocking Issues with this label are in the ownership of the unblocking team. labels Apr 29, 2026
@bliuchak bliuchak changed the base branch from master to version-3.0 April 29, 2026 10:48
@github-actions github-actions Bot added the tested Temporary label used only programatically for some analytics. label Apr 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Migrates the proxy-chain library and its test/docs ecosystem from CommonJS to native ECMAScript Modules (ESM), aligning the project with Node’s modern module system and enabling better tooling/tree-shaking for consumers.

Changes:

  • Switches TypeScript compilation and internal source imports to ESM-friendly NodeNext + explicit .js specifiers.
  • Converts tests and test utilities from require()/module.exports to import/export, and updates tests to import built dist/ outputs.
  • Updates package publishing metadata (type: module, exports) and refreshes README/examples for ESM usage; adjusts release tooling for type: module.

Reviewed changes

Copilot reviewed 30 out of 32 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tsconfig.json Updates TS compiler settings for ESM (NodeNext) and modern JS target.
package.json Declares ESM package (type: module) and adds exports map for the entrypoint.
src/**.ts Updates relative imports to include .js extensions to work with NodeNext/ESM output.
test/**.js Converts tests/utilities to ESM and points imports at dist/.
.mocharc.json Removes ts-node/register configuration.
README.md Updates usage examples to ESM import syntax.
examples/apify_proxy_tunnel.js Updates example to ESM import syntax.
.github/workflows/release.yaml Updates release workflow to run a .cjs script under ESM package mode.
.github/scripts/before-beta-release.cjs Adds CJS release helper script compatible with type: module.

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

Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread .mocharc.json
Comment thread README.md Outdated

@daniil-poletaev daniil-poletaev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Left few questions and suggestions

Comment thread test/http-agent.js Outdated
import proxy from 'proxy';
import request from 'request';

import { Server } from '../dist/index.js';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

are you sure we should import from /dist/ folder? This doesn't look right for me, because user needs to build it first

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good catch! fixed

Comment thread .mocharc.json
@@ -1,3 +1,2 @@
{
"require": "ts-node/register"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we remove .mocharc.json completely?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or I think we need to do

{               
    "require": "tsx"
}

and then we can import directly from src?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be nice to migrate to Viteset 😉

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 31 out of 33 changed files in this pull request and generated 5 comments.


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

Comment thread test/server.js
Comment thread test/http-agent.js
Comment thread test/https-server.js
Comment thread test/https-stress-test.js
Comment thread README.md
Comment thread .mocharc.json
@@ -1,3 +1,2 @@
{
"require": "ts-node/register"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be nice to migrate to Viteset 😉

@bliuchak

bliuchak commented Apr 29, 2026

Copy link
Copy Markdown
Contributor Author

@daniil-poletaev daniil-poletaev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great 👍

@bliuchak bliuchak merged commit 5843a28 into version-3.0 Apr 30, 2026
3 checks passed
@bliuchak bliuchak deleted the feat/cjs-to-esm-v3 branch April 30, 2026 07:39
bliuchak added a commit that referenced this pull request May 5, 2026
* feat!: update minimal supported version of Node.js to v20 (#638)
* chore: remove typeSocket assertion helper (#653)
* feat!: migrate from CJS to ESM (#654)
* feat: upgrade typescript to v5 (#655)
* feat!: replace nodeify by async/await (#656)
* chore: format changelog markdown
* docs: add new version info into changelog
* chore: bump package version to a major one

Close #637
@bliuchak bliuchak added the validated Issues that are resolved and their solutions fulfill the acceptance criteria. label May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

medium priority Medium priority issues to be done in a couple of sprints. t-unblocking Issues with this label are in the ownership of the unblocking team. tech roadmap Issues contributing to tech roadmap. tested Temporary label used only programatically for some analytics. validated Issues that are resolved and their solutions fulfill the acceptance criteria.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate library from CJS to ESM

5 participants