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

@brinkdevteam/derive-npmignore

v1.2.0

Published

Derive .npmignore from .gitignore with certain lines omitted as a build script

Downloads

3

Readme

If you use transpilation for your package, you may want to avoid committing the compiled JavaScript to your repository while still publishing your scripts to npmjs. However, npm publish/npm pack will use .gitignore to decide on files to exclude from the package unless you create a .npmignore. Thus, one option you have is to maintain both .gitignore and .npmignore. However, this duplicates code.

With this script, you have a second option. Write .gitignore, mark a few lines as excluded from .npmignore, and you’re done!

The script provided by this package, brinkdevteam-derive-npmignore, will automatically read your .gitignore, filter out any lines between #BEGIN_NPMIGNORE_EXCLUDE and #END_NPMIGNORE_EXCLUDE, and output the result to .npmignore. It will also take any lines between #BEGIN_NPMIGNORE_INCLUDE and #END_NPMIGNORE_INCLUDE and remove exactly one # from the beginning of each line.

Example

This example shows how one might combine this with a pattern of developing in TypeScript and publishing compiled JavaScript files with type definitions.

Note that .npmignore is considered a built file when using this pattern!

.gitignore:

# Common editor swap files
*.swp
*~
*\#*

# Build/restored
*.tgz
package-lock.json
node_modules

#BEGIN_NPMIGNORE_EXCLUDE

# Ignore built files.
*.d.ts
*.map
.npmignore

# However, sometimes we need to author and commit custom typings for untyped
# modules or to augment modules which have not been pushed upstream yet. Put
# these *.d.ts files inside of any directory called “types”:
!**/types/*.d.ts

#END_NPMIGNORE_EXCLUDE

#BEGIN_NPMIGNORE_INCLUDE
## TypeScript consumers generally cannot handle it when packages
## publish the source .ts depending on what loader is used to consume
## the files.
#*.ts
#!*.d.ts
#*.tsx
#END_NPMIGNORE_INCLUDE

Put your compilation and call to this sript in the prepare hook which is automatically called by npm pack/npm publish and also called whenever your module is included via a VCS reference.

package.json:

{
  "devDependencies": {
    "@brinkdevteam/derive-npmignore": "^1.1.0",
    "typescript": "^3.0.1"
  },
  "scripts": {
    "prepare": "tsc -d && brinkdevteam-derive-npmignore"
  }
}

Usage

brinkdevteam-derive-npmignore [-h] [--] [path-to-.gitignore [path-to-.npmignore]]

  • -h: Prints the basic usage line and exits.

  • --: Disabled interpretation of - for the remainder of the arguments. Useful if you may refer to paths starting with -.

  • path-to-.gitignore: (Default: .gitignore) You may supply the path to the .gitignore file to use as a template. For example, in one of my projects, that is ../../.gitignore. Regardless of the path to .gitignore, .npmignore will be output to the current directory by default.

  • path-to-.npmignore: (Default: .npmignore) You may supply an alternate output path for the .npmignore. For example, you may wish to run this command from outside of the directory which you want to package.