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
Updated dependencies, switch to ESM and require node 12.20 #162
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change in this PR unfortunately means that some developers would no longer be able to use this library, as we're no longer shipping a CJS module.
For example, with this code:
const ms = require("ms");
Users will see the following:
require() of ES modules is not supported.
I (personally) feel that TypeScript might actually be a better solution here as we could use it to generate ES and CJS modules, and also emit types.
They can still import it using the async syntax
You can still do that with allowJS + checkJS + plus you would not need to waste time compiling. |
Hi @jimmywarting, sorry for the slow response.
I've discussed this with a few colleagues, and we still think we should ship ESM and CJS:
I like the approach, and use it myself sometime for small utilities, but this is only good internally. TypeScript would allow us to ship types - which we don't do today - saving over 700,000 additional package downloads a week. That's a win for our users, and the environment :) The cost of compiling this to CJS and ESM with TypeScript is around 2.8s on my M1, so I don't think it's a notable cost here. Are you OK to make these changes? No pressure if not! I can take a look at this over the next few days. |
@@ -7,6 +7,10 @@ | |||
"files": [ | |||
"index.js" | |||
], | |||
"type": "module", | |||
"engines": { | |||
"node": ">=12.20" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick question on this, why 12.20
specifically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sindresorhus is converting all his 1k packages to ESM only sindresorhus/meta#15
in normal situations you can use 12.17 - that is the lowest support for ESM
12.20 is for those who mostly use node:
prefix to import eg: import fs from 'node:fs'
If you want typescript, then fine by me. The outcome is the same for me. just don't expect any more PR from me.
You can still utilize typescript to generate d.ts from vanilla js + jsdoc and i do think your project is considered a "small utility" that typescript isn't even worth it. I use typescript myself (but only for it's typing support - using jsdoc) I never use the typescript syntax.
i don't like build tools as much as everyone other typescript user dose. |
infact if you try out the Deno plugin for VSCode and import this vanila js library (as an example) written in ESM and JSDoc ...then you do get typing support (and description as well) and you won't need any extra typing is baked in into the vanila js file itself with jsdoc |
Thanks for your time on this @jimmywarting. I'll make the changes as discussed, I've just opened #163 for early feedback and hope to ship this within the next week. |
fyi, this is the tsconfig i mostly use on all my projects {
"include": ["*.js"],
"compilerOptions": {
"target": "ES2020",
"lib": ["ES2020"],
"module": "ES2020",
"moduleResolution": "node",
"allowJs": true,
"checkJs": true,
"declaration": true,
"emitDeclarationOnly": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"strictNullChecks": true
}
} Gives u all the benefits of typescript without actually writing any typescript syntax |
Closes #159
Personally i don't see any reason for converting it to TypeScript. JSDoc works just as well for providing typing support.
...and dose not require compiling so importing it to Deno with http import gives you typing with ease as well as making it possible to import it using http loader from browsers and nodes new HTTP loader