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

@lexedwards/ts-pack

v1.3.4

Published

Preconfigured bundler for Typescript Libraries

Downloads

6

Readme

TS-Pack

A preconfigured rollup.js bundler for Typescript Libraries, with additional aid to help configure the library's package.json.

Usage

  A preconfigured bundler using local package.json + tsconfig.json to bundle your library.

  Configurations via flags or package.json:
    --help, -h, ts-pack.help
        Display this message

    --doctor, -d, ts-pack.doctor
        Perform a check on package.json's configuration

    --init
        Writes to package.json a standard default setup for typescript libraries

    --tsConfig, -c, ts-pack.tsConfig
        Specify the typescript config to use on build
        default: 'tsconfig.json'

    --inputFile, -i, ts-pack.inputFile
        Specify the entry point to bundle.
        default: 'src/index.ts'

    --bundle, -b, ts-pack.bundle
        Bundle dependencies in distribution.
        Useful for only relying on native node dependencies. i.e. lambdas
        default: false

    --preserveModules, -p, ts-pack.preserveModules
        Preserved for future usage, currently does not affect bundling
        default: false

    --external, -e, ts-pack.external
        Declare external packages when bundling. (Can be used multiple times)
        Useful when the runtime environment has modules additional to the core standard library. i.e. Lambdas
        default: empty

    --watch, -w, ts-pack.watch
        Enter watch mode, where files saved in the source directory will trigger an automatic rebuild
        default: false

Requirements

This library will only work on Node v18 or higher, this is because it utilises new improvements such as the new parseArgs module.

Init

An initial setup script, that when ran, will configure package.json for you with best practices and modern standards of esm, following guidance directly from npmjs. These will ensure that fields that, if not present already, are set correctly for best compatibility.

Fields that will be configured:

  • name,
  • version,
  • scripts.build,
  • files,
  • type,
  • main,
  • module,
  • types,
  • exports
  • ts-pack

Doctor

Help setup package.json the right way, the first time! Doctor will help guide through the set up and identify missing properties.

For an NPM library, package.json is the informer of what your library is, and how your library operates. Doctor is there to cover the bases for 80% of use-cases.

Multiple modules are currently not supported, see Roadmap for more information.

Example terminal output from Doctor:

🩺 Running TS-Pack: Verifying Package.json...

ES Module Package Detected

 ○ - Exports Common JS

While optional for ES Module Packages, this choice can break environments who haven't adopted ESM yet.

 ✓ - Exports ES Module
 ✓ - Exported ES Module Correct File Extension
 ○ - Exports Types for developers

Exporting types, while optional, aid developers who consume your library.
Add "types": "<dist folder>/<@types folder>/index.d.ts" to give them a hand!

 ✓ - Limited files packaged on release
 ✓ - Additional bundler support - Root
 ✓ - Additional bundler support - Root ES Modules

📦 Verifying TS-Pack Config...

 ○ - Input file configured

TS-Pack is using a default configuration for it's input file (src/index.ts)

 ○ - Typescript configured

TS-Pack is using a default configuration for it's typescript (tsconfig.json)

 ✓ - Input file found
 ✓ - tsconfig file found

Build

Create bundles determined by properties present in package.json with help from a custom pack property or script flags.

Notable Properties

  • main : CommonJS bundle.
  • module : ES Module bundle.
  • types : Type declaration bundle.

Pack configuration

If you want to persist configurations without using flags, custom package.json options are available.

  • pack.inputFile : Single entry point file.
  • pack.tsConfig : Specify a tsconfig.json file to use for bundling.
  • pack.bundle : Include external dependencies in the minified output bundle.
  • pack.exclude : Ensure packages, regardless of presence in package.json are always excluded.

Roadmap

  1. Enable Watch mode.

  2. Support React 18's Server Side Components' "use client" directive.

  3. Enable multiple inputs for libraries which export more than one module.

Many libraries have multiple named modules exported to either reduce size or complexity as an 'opt-in' measure. This is enabled through the "exports" property in package.json.