-
Notifications
You must be signed in to change notification settings - Fork 19
- Add ESM Module version cross build CJS #19
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: master
Are you sure you want to change the base?
Conversation
Smeagolworms4
commented
Jan 20, 2025
- Add ESM Module version cross build commonjs.
- Update to fetch 3 (compatibility commonjs)
|
All test work. |
|
@Smeagolworms4 can you explain to me a little more what is the purpose of this pull request? What is the problem you are trying to solve? |
|
The current version of telesign doesn't work with an esmodule environment. Ans, version 3 of fetch is necessarily esmodule. The pull request I'm sending you allows you to generate a commonjs + esmodule version. And all the tests are up to date. There's even an action that runs them. |
|
also it adds typescript typing (even if it is a basic version) |
77bdcf1 to
4727149
Compare
|
In package.json: Add ESM and CJS version of module (it's retrocompatible) : "main": "dist/cjs/TeleSign.js",
"module": "dist/esm/TeleSign.js", // ESM
"types": "dist/types/TeleSign.d.ts", // Typing Typescript
"exports": {
".": {
"require": "./dist/cjs/TeleSign.js", // CJS
"import": "./dist/esm/TeleSign.js" // ESM
}
},Depencency fetch 2 and 3 : "peerDependencies": {
"node-fetch": "^2.6.0 || ^3.0.0"
}This code use fetch on global or window if already loaded. async function fetchWithTimeout(url, options) {
/** @type {any} */
let fetch = (typeof window !== 'undefined' ? window : global).fetch || null;
if (!fetch) {
fetch = await import('node-fetch').then(m => m.default ?? m);
}
return await Promise.race([
fetch(url, options),
new Promise((_, reject) => setTimeout(() => reject({ code: 408, message: 'Timeout' }), options.timeout))
]);
} |
|
@Smeagolworms4 thanks for the clarification. I'll pass this along to the relevant product team to review. |
|
Fix last rebase main version |
|
Any news? As long as it's not merged, it's going to accumulate conflicts. The current version doesn't support esm and fetch 3. And this version has basic ts typing. |