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: enable name import #252

Closed

Conversation

yutak23
Copy link
Contributor

@yutak23 yutak23 commented Nov 15, 2023

This ought to fix #251.

One possible cause of the degradation is the lack of type definition testing.

Therefore, we will propose the addition of type definition testing in this PR. This test is similar to testing JavaScrip code, so I do not think this will significantly increase maintenance costs.

Rather, it would greatly improve the reliability of TypeScript type definitions.

※The scripts are daringly separated in test:tsd because tsd does not work due to CI's Node.js version. Local test results are below (Node.js v18.17.0).
image

For Node.js v16.20.2
image

(I have not tested anything under Node 14 as I believe it has already reached EOL. cf. https://github.com/nodejs/Release#nodejs-release-working-group)

isNetworkOrIdempotentRequestError,
isRetryableError,
isSafeRequestError
} from './index.js';
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 confirm that name import is working here (and that axiosRetry is able to import default).

@@ -58,7 +61,7 @@
"bugs": {
"url": "https://github.com/softonic/axios-retry/issues"
},
"types": "lib/esm/index.d.ts",
"types": "index.d.ts",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This project is CommonJS, so index.d.ts should have been the default, not the type definition under esm, so I fixed it.

Copy link
Member

Choose a reason for hiding this comment

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

1st of all, thank you for your commitment @yutak23 and @rchl for your feedback

This lib is actually written using ESM (es/index.mjs) and then built with babel for cjs and esm

I believe we followed this guide back in the day to implement such compatibility.

Looking at that, I still think is a good approach and may be worth follow the TS part and migrate the implementation to TS.

So my proposal would be to:

What do you guys think? Should that solve both issues #159 and the new one?

Copy link

Choose a reason for hiding this comment

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

I agree that reverting is the best way forward for now.

Those changes just raise too many questions.

Copy link
Contributor Author

@yutak23 yutak23 Nov 15, 2023

Choose a reason for hiding this comment

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

Looking at that, I still think is a good approach and may be worth follow the TS part and migrate the implementation to TS.

Migrate to TS seems easiest in the end. I agree that moving to TS would solve the problem
(I think we can handle both by setting up tsconfig for each of CJS and ESM as in https://github.com/stripe/stripe-node).
And it was not a good idea to make major changes without testing against TypeScript type definitions. I apologies.

@mindhells
I apologize for the inconvenience, but please close this PR at the appropriate time if necessary.

@rchl
Thank you for the pointers, etc. And I am sorry that my fault resulted in releasing something with bugs.

Comment on lines +11 to +16
export function isNetworkError(error: Error): boolean;
export function isRetryableError(error: Error): boolean;
export function isSafeRequestError(error: Error): boolean;
export function isIdempotentRequestError(error: Error): boolean;
export function isNetworkOrIdempotentRequestError(error: Error): boolean;
export function exponentialDelay(retryNumber?: number, error?: Error, delayFactor?: number): number;
Copy link

@rchl rchl Nov 15, 2023

Choose a reason for hiding this comment

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

Those were not exported directly before. Those were exported through AxiosRetry which should be exported instead.

I'd still want you to answer #250 (comment) more specifically because I'm not sure why the export = syntax doesn't work for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those were not exported directly before. Those were exported through AxiosRetry which should be exported instead.

This is to conform to the specification in JavaScript. It is also possible to name import the isNetworkError function as follows.
This time, it has been modified accordingly.

image

Copy link

Choose a reason for hiding this comment

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

Well, you can export those since it's a "new feature" but you also have to export AxiosRetry since it was exported before and it was possible to do import { AxiosRetry } from 'axios-retry' while it's not possible with those changes.

@mindhells
Copy link
Member

Ok guys, thank you both for your dedication and feedback on this.
I've just reverted the #250 in version 3.9.1 and I will work on the migration to TS soon

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.

[TypeScript]Unable to import names
3 participants