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

Updated dependencies, switch to ESM and require node 12.20 #162

Closed
wants to merge 1 commit into from

Conversation

jimmywarting
Copy link

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

Copy link
Contributor

@mrmckeb mrmckeb left a 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.

@jimmywarting
Copy link
Author

jimmywarting commented Aug 13, 2021

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.

They can still import it using the async syntax import('ms')

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.

You can still do that with allowJS + checkJS + plus you would not need to waste time compiling.

@mrmckeb
Copy link
Contributor

mrmckeb commented Aug 16, 2021

Hi @jimmywarting, sorry for the slow response.

They can still import it using the async syntax import('ms')

I've discussed this with a few colleagues, and we still think we should ship ESM and CJS:

  • import() would require some users to reimplement ms, which we can avoid by shipping CJS alongside ESM.
  • It's fairly standard for libraries to ship and support both formats today, and this is what users will expect.

You can still do that with allowJS + checkJS + plus you would not need to waste time compiling.

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"
Copy link
Contributor

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?

Copy link
Author

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'

@jimmywarting
Copy link
Author

jimmywarting commented Aug 16, 2021

Are you OK to make these changes? No pressure if not! I can take a look at this over the next few days.

If you want typescript, then fine by me. The outcome is the same for me. just don't expect any more PR from me.
Love typing but hate the syntax and not being able to run things natively in browser... still prefer jsdoc over ts and non bundled files for easier code spliting.
Lot's of Typescript project unfortunately bundle everything together... (but you only have one index file so it don't apply to u)

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 :)

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.
https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html


I use typescript myself (but only for it's typing support - using jsdoc) I never use the typescript syntax.
best part of it is that you can

  • import vanila js directly in the browser and also to Deno
  • Ship typing support to Deno using the same browser based files without loading extra d.ts files
  • and you could also use node's new http loader to import files without npm

i don't like build tools as much as everyone other typescript user dose.
i prefer buildless projects and files that can be imported in all environments (Deno, Browser & Nodes http loader) for best cross compatible code

@jimmywarting
Copy link
Author

jimmywarting commented Aug 16, 2021

infact if you try out the Deno plugin for VSCode and import this vanila js library (as an example) written in ESM and JSDoc

image
image

...then you do get typing support (and description as well) and you won't need any extra d.ts files or any NPM package manager
Pretty sweet if you ask me

typing is baked in into the vanila js file itself with jsdoc

@mrmckeb
Copy link
Contributor

mrmckeb commented Aug 17, 2021

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.

@mrmckeb mrmckeb closed this Aug 17, 2021
@jimmywarting
Copy link
Author

jimmywarting commented Aug 25, 2021

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

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.

ESM version
2 participants