Skip to content

Latest commit

 

History

History
73 lines (57 loc) · 3.64 KB

README.md

File metadata and controls

73 lines (57 loc) · 3.64 KB

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.

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