DEV Community

Jason F
Jason F

Posted on

I created my first NPM package

Hello all! I am excited to announce that I have published my first NPM package. It's not super fancy or anything and is most certainly a work in progress. That being said, if anyone has time to check it out and provide feedback, here is the link. The library provides useful methods when working with dates in JavaScript/TypeScript. I wrote it in TypeScript, so you get type declarations right out of the box.

I'd appreciate any feedback. Also, if you want to contribute, just let me know :)

This has definitely been a learning experience for me. I live in my own little world as a front end developer. I install and use npm packages but never really considered that anyone can write one and publish it.

Discussion (15)

Collapse
lukeshiru profile image
LUKESHIRU

You might want to add an "exports" field to your package.json, and build both a CJS and an ESM version with TS. When TS 4.5 is released, you'll be able to also add "type": "module" to your package.json 🎉 Also I noticed that you have this:

"lint": "npx eslint . --ext .ts",
Enter fullscreen mode Exit fullscreen mode

And you can change it with this:

"lint": "eslint . --ext .ts",
Enter fullscreen mode Exit fullscreen mode

And I recommend you use a package such as npm-run-all which allows you to go from this:

"prepare": "npm run build",
"prepublishOnly": "npm test && npm run lint",
"preversion": "npm run lint"
Enter fullscreen mode Exit fullscreen mode

To this:

"prepare": "run-s build",
"prepublishOnly": "run-s test lint",
"preversion": "run-s lint"
Enter fullscreen mode Exit fullscreen mode

Which is generally better to support not only npm, but also pnpm and yarn. Everything git related could be handled by a package such as lefthook. Finally, you should add more keywords like "utils" or "helpers", so it's easier to find.

Cheers!

Collapse
juniordevforlife profile image
Jason F Author

This is exactly the kind of feedback I was looking for. Thank you so much.

Collapse
juniordevforlife profile image
Jason F Author

So, I looked in to adding support for CJS. This seems to be fairly complex. Any pointers/tips?

Collapse
lukeshiru profile image
LUKESHIRU

Instead of compiling everything into a lib directory, what I do is compiling to a require and import directories. Take a look at one of my packages here. You'll notice I have a tsconfig.json, but also a tsconfig.import.json, and a tsconfig.require.json, each uses the base config, and changes the output dir and compilation options accordingly, so later I run 2 different builds, each one using a different config.
Copy as much as you need from that repo, is MIT so is there to be studied and used freely ☺️

Thread Thread
juniordevforlife profile image
Jason F Author

You're an amazing person! Thank you very much!

Thread Thread
juniordevforlife profile image
Jason F Author

I got it working!!!

Thread Thread
lukeshiru profile image
LUKESHIRU

F yeah

Gratz!

Collapse
siddharthshyniben profile image
Siddharth • Edited on

I live in my own little world as a front end developer.

You need to get out of there as soon as possible! Spreading your work is important to keep you motivated

Collapse
juniordevforlife profile image
Jason F Author

Thanks!

Collapse
keyurparalkar profile image
Keyur Paralkar

Awesome.

Collapse
yassinerahhaui profile image
yassine rahhaoui

share your expirience with me

Collapse
juniordevforlife profile image
Jason F Author

I plan on creating a post with my experience, however, haven't found the time yet. I can share with you some useful links I used to help me out if you'd like.

Collapse
yassinerahhaui profile image
yassine rahhaoui

yes i want thank you very much

Thread Thread
juniordevforlife profile image
Jason F Author
Collapse
bhatvikrant profile image
Vikrant Bhat • Edited on

This is great! Don’t really have anything to add, but I like what you’re doing here in the comment section:)