Skip to content
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

fix: disable esModuleInterop #375

Open
wants to merge 7 commits into
base: current
Choose a base branch
from

Conversation

SimenB
Copy link
Contributor

@SimenB SimenB commented Jul 14, 2023

#374, but going as far as disabling the option in this repo to avoid regressions.

I'm having some issues getting tests to run with this

Copy link
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the effort, let me know what you think about the comment 🙂

@@ -1,6 +1,6 @@
import { AbortController } from 'abort-controller';
import { EventEmitter } from 'events';
import Piscina from '..';
import Piscina = require('..');
Copy link
Member

Choose a reason for hiding this comment

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

Let's tackle this differently, by exporting Piscina in different manners by exporting it as default, and named export.

Otherwise, this can potentially break the current user's expectations if esModuleInterop is set to false. Wdyt?

Copy link
Contributor Author

@SimenB SimenB Jul 19, 2023

Choose a reason for hiding this comment

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

does the default export created by TS work as an actual default export in Node? The current one does as it's just module.exports =

Copy link
Member

Choose a reason for hiding this comment

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

If exported by default, it will export it as module.exports.default = Piscina, if by named export, it translates to module.Piscina = Piscina. If just used as export Piscina, it just does module.exports = Piscina.

Exporting it as default, and named will enable imports like:

  • import { Piscina } from 'piscina'
  • import Piscina, { SomeType } from 'piscina'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems #517 did this 👍

@metcoder95 metcoder95 mentioned this pull request Jul 19, 2023
src/index.ts Outdated
import { AsyncResource } from 'async_hooks';
import { cpus } from 'os';
import { fileURLToPath, URL } from 'url';
import { resolve } from 'path';
import { inspect, types } from 'util';
import assert from 'assert';
import assert = require('assert');
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can change the way this is imported as discussed in #374 ?

@@ -1,6 +1,6 @@
import { AbortController } from 'abort-controller';
import { EventEmitter } from 'events';
import Piscina from '..';
import Piscina = require('..');
Copy link
Member

Choose a reason for hiding this comment

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

If exported by default, it will export it as module.exports.default = Piscina, if by named export, it translates to module.Piscina = Piscina. If just used as export Piscina, it just does module.exports = Piscina.

Exporting it as default, and named will enable imports like:

  • import { Piscina } from 'piscina'
  • import Piscina, { SomeType } from 'piscina'

Copy link

This issue has been marked as stale because it has been opened 45 days without activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the stale label May 12, 2024
@SimenB
Copy link
Contributor Author

SimenB commented May 12, 2024

Completely forgot about this - can take a look at reviving tomorrow

@SimenB SimenB marked this pull request as ready for review May 13, 2024 07:07
@SimenB
Copy link
Contributor Author

SimenB commented May 13, 2024

@metcoder95 due to #517, this PR simply needs to flip the flag and fix the assert import 👍

@@ -5,7 +5,7 @@ import { availableParallelism } from 'os';
import { fileURLToPath, URL } from 'url';
import { resolve } from 'path';
import { inspect, types } from 'util';
import assert from 'assert';
import { strict as assert } from 'assert';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I doubt the change to use strict is visible to consumers, but assert is used as a function, so we need to tweak this import

Copy link
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM 👍

@metcoder95 metcoder95 removed the stale label May 13, 2024
@metcoder95
Copy link
Member

metcoder95 commented May 13, 2024

Sorry, finally made the tests works as expected; overall it seems there's an issue with the exports 🤔

@SimenB
Copy link
Contributor Author

SimenB commented May 13, 2024

Oh, interesting! I'll take a new look tomorrow 😅

@SimenB
Copy link
Contributor Author

SimenB commented May 14, 2024

Right, the problem is that the types file do not reflect what is actually used at runtime by TS - types point to main.d.ts, but require loads a file which is just export = for CJS compat. This only works with esModuleInterop active. Not sure how to best handle this if you do want const Piscina = require('piscina'); work. Might require a major that only has named exports?

@metcoder95
Copy link
Member

I've been thinking about refactoring the way the types are overall exported, as currently everything happens with the Piscina class, which is practical but it seems that it comes with the tradeoffs of constrains at the moment of importing it that requires to do some tricks.

If you are willing to, I'm more than happy support you on a PR that refactors the way types are exported. Meanwhile we are able to do

const Piscina = require('piscina');
// or
const { Piscina } = require('piscina');

// and ofc
import { Piscina, HelperPiscinaTypes } from 'piscina';
import Piscina, { HelperPiscinaMethods } from 'piscina'; 

Copy link

This issue has been marked as stale because it has been opened 45 days without activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the stale label Jun 23, 2024
@SimenB
Copy link
Contributor Author

SimenB commented Jun 24, 2024

not stale, just low on OSS time 😅 It's on my list!

@metcoder95 metcoder95 added never-stale Issues/PRs that are not stale and removed stale labels Jun 25, 2024
Copy link

This issue has been marked as stale because it has been opened 45 days without activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the stale label Jul 28, 2024
@SimenB
Copy link
Contributor Author

SimenB commented Jul 28, 2024

On vacation, will get back to this (hopefully in August)

@github-actions github-actions bot removed the stale label Aug 4, 2024
@metcoder95 metcoder95 added backport v4 Backport work label related with v4.x wip PRs WIP and removed never-stale Issues/PRs that are not stale labels Sep 15, 2024
@metcoder95 metcoder95 removed the wip PRs WIP label Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport v4 Backport work label related with v4.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants