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

removeNPMAbsolutePaths

v3.0.1

Published

Remove the fields containing local aboslute paths created by NPM

Downloads

18,316

Readme

NPM version Node.js CI Test coverage Downloads

removeNPMAbsolutePaths

removeNPMAbsolutePaths is a small utility to remove the fields that npm adds to the modules in node_modules containing local absolute paths.

It has been noted that the package.json of modules in the node_modules folder contain some extra fields like _args and where which contain the absolute path of the module. According to NPM those fields are not even used.

The problem comes when you are planning to package your application using electron, NW.js or similar and distribute it. You might not want to distribute files containing absolute paths within your computer.

A feature request has been raised to NPM to fix this issue but they have made clear they don't plan to fix this.

  • https://github.com/npm/npm/issues/12110 (feature request)
  • https://github.com/npm/npm/issues/10393 (discussion about the topic)

Using removeNPMAbsolutePaths

removeNPMAbsolutePaths simply loop through all the files in the given folder, open the files called package.json and remove all the fields starting with an underscore (_).

You can install removeNPMAbsolutePaths globally and use it from the command line

$ npm install -g removeNPMAbsolutePaths
$ removeNPMAbsolutePaths '<PROJECT_FOLDER>'

or use it from whithin your code

const  removeNPMAbsolutePaths = require('removeNPMAbsolutePaths');

try {
  const results = await removeNPMAbsolutePaths('<PROJECT_FOLDER>');
  results.forEach(result => {
    // Print only information about files that couldn't be processed
    if (!result.success) {
      console.log(result.err.message);
    }
  });
} catch(err) {
  console.log(err.message);
}

Using removeNPMAbsolutePaths from within Javascript returns a promise containing information about all the folders and files processed and whether they where successfully processed and rewritten or not.

Options

removeNPMAbsolutePaths can be configured using tags. Tags can be added to the command line commands:

$ removeNPMAbsolutePaths '<PROJECT_FOLDER>' --force --fields _where _args

or passed programmatically in an options object

removeNPMAbsolutePaths('<PROJECT_FOLDER>', { force: true, fields: ['_where', '_args']});

force

removeNPMAbsolutePaths only rewrite to disk the files that it modifies. Passing the --force tag will rewritte all the files even if they haven't been modfied. This might be useful if you want all the package.json files to have always exactly the same styling for example for hashing.

fields

removeNPMAbsolutePaths by default removes all fields starting with _. Passing the --fields tag followed by a list of field names you want removed will cause it to remove only those ones you list. This might be useful if only some of the fields in package.json are bothering you.

License

MIT