npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@vanvuongngo/ts-package

v1.0.5

Published

Tutorial to create your own typescripted package. Original tutorial see https://itnext.io/step-by-step-building-and-publishing-an-npm-typescript-package-44fe7164964c

Downloads

13

Readme

ts-package

Tutorial to create your own typescripted package. Original tutorial see https://itnext.io/step-by-step-building-and-publishing-an-npm-typescript-package-44fe7164964c

Requirements

  • nodejs
  • npm
  • yarn (optional and as default here; if there are differences in the commands between yarn and npm then it will be descibe separatly)

Init your TS package

yarn init -y

Ignore the node_modules directory for git:

echo "node_modules" >> .gitignore

add Typescript as a Dev-Dependency

yarn add -D typescript

add a TS configuration file tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "declaration": true,
    "outDir": "./lib",
    "strict": true
  },
  "include": ["src"],
  "exclude": ["node_modules", "**/__tests__/*"]
}

create a src folder

mkdir src

Build process

add a build script into package.json

  "scripts": {
    "build" : "tsc"
  }

now run build command. The lib folder contains your compiled code and typescript definitions.

yarn build

or

npm run build

you will get a /lib directory with the compiled version

add the lib directory into .gitignore file. The slash means the lib directory in the root directory.

echo "/lib" >> .gitignore

whitelist lib directory for a published package

add to package.json so no other files will include into the published package

  "files": [
    "lib/**/*"
  ]

adapt the package.json

  "main": "lib/index.js",
  "types": "lib/index.d.ts",

Deployment process

add deploy script to publish package

"deploy": "yarn publish --access public"

publish your package

yarn login
yarn publish

or

npm adduser
npm version patch
npm run publish

Use your TS library inside another project

create and initialize a new project

yarn init -y

add your ts-package library (change @vanvuongngo/ts-package to yours)

yarn add @vanvuongngo/ts-package

create an example index.mjs and import the package

import { Greeter } from '@vanvuongngo/ts-package';

console.log(Greeter("World"));

Run your example script

node .

Use your localley TS library and to prevent publishing on all development changes

Create a locally link to develop the TS library

Use link to link this package that you’d like to test into your current project.

yarn link

create a new project directory and initialize it

yarn init -y

add local ts-package as dependency to develop without need of publishing

yarn link ts-package

create an example script

import { Greeter } from 'ts-package';

console.log(Greeter('World'));