Add and run removeNPMAbsolutePaths
This commit is contained in:
parent
a76042ab4a
commit
256c63a715
712 changed files with 13722 additions and 18895 deletions
21
node_modules/removeNPMAbsolutePaths/LICENSE
generated
vendored
Normal file
21
node_modules/removeNPMAbsolutePaths/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Juanjo Diaz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
69
node_modules/removeNPMAbsolutePaths/README.md
generated
vendored
Normal file
69
node_modules/removeNPMAbsolutePaths/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
[![NPM version][npm-image]][npm-url]
|
||||
[![build status][travis-image]][travis-url]
|
||||
[![Test coverage][coveralls-image]][coveralls-url]
|
||||
[![Downloads][downloads-image]][downloads-url]
|
||||
|
||||
# removeNPMAbsolutePaths
|
||||
|
||||
removeNPMAbsolutePaths is a small utility to remove the fields that npm adds to the modules in `node_modules` containing local aboslute 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
|
||||
```sh
|
||||
$ npm install -g removeNPMAbsolutePaths
|
||||
$ removeNPMAbsolutePaths '<PROJECT_FOLDER>'
|
||||
```
|
||||
or use it from whithin your code
|
||||
```javascript
|
||||
var removeNPMAbsolutePaths = require('removeNPMAbsolutePaths');
|
||||
removeNPMAbsolutePaths('<PROJECT_FOLDER>')
|
||||
.then(results => 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:
|
||||
```sh
|
||||
$ removeNPMAbsolutePaths '<PROJECT_FOLDER>' --force --fields _where _args
|
||||
```
|
||||
or passed programmatically in an options object
|
||||
```javascript
|
||||
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
|
||||
|
||||
|
||||
[npm-image]: https://img.shields.io/npm/v/removeNPMAbsolutePaths.svg?style=flat-square
|
||||
[npm-url]: https://www.npmjs.com/package/removeNPMAbsolutePaths
|
||||
[travis-image]: https://img.shields.io/travis/juanjoDiaz/removeNPMAbsolutePaths/master.svg?style=flat-square
|
||||
[travis-url]: https://travis-ci.org/juanjoDiaz/removeNPMAbsolutePaths
|
||||
[coveralls-image]: https://img.shields.io/coveralls/juanjoDiaz/removeNPMAbsolutePaths/master.svg?style=flat-square
|
||||
[coveralls-url]: https://coveralls.io/github/juanjoDiaz/removeNPMAbsolutePaths?branch=master
|
||||
[downloads-image]: https://img.shields.io/npm/dm/removeNPMAbsolutePaths.svg?style=flat-square
|
||||
[downloads-url]: https://www.npmjs.com/package/removeNPMAbsolutePaths
|
||||
30
node_modules/removeNPMAbsolutePaths/bin/removeNPMAbsolutePaths
generated
vendored
Executable file
30
node_modules/removeNPMAbsolutePaths/bin/removeNPMAbsolutePaths
generated
vendored
Executable file
|
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
/* eslint-disable no-console */
|
||||
|
||||
'use strict';
|
||||
|
||||
const cli = require('../src/cli');
|
||||
const removeNPMAbsolutePaths = require('../src/removeNPMAbsolutePaths');
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
const args = await cli.parseArguments(process.argv.slice(2));
|
||||
|
||||
if (args.ignored.length) {
|
||||
console.warn(`The following options are unknown and will be ignored:\n${args.ignored.join('\n')}`);
|
||||
}
|
||||
|
||||
const results = await removeNPMAbsolutePaths(args.path, args.opts);
|
||||
|
||||
results.forEach((result) => {
|
||||
if (!result.success) {
|
||||
console.log(result.err.message);
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
52
node_modules/removeNPMAbsolutePaths/package.json
generated
vendored
Normal file
52
node_modules/removeNPMAbsolutePaths/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
{
|
||||
"name": "removeNPMAbsolutePaths",
|
||||
"version": "2.0.0",
|
||||
"description": "Remove the fields containing local aboslute paths created by NPM",
|
||||
"keywords": [
|
||||
"npm",
|
||||
"modules"
|
||||
],
|
||||
"main": "src/removeNPMAbsolutePaths.js",
|
||||
"scripts": {
|
||||
"lint": "eslint bin/removeNPMAbsolutePaths src test --ignore-pattern 'test/data/malformed/module/'",
|
||||
"test": "mocha test",
|
||||
"test-with-coverage": "nyc --reporter=text mocha test",
|
||||
"travis": "npm run lint && npm run test-with-coverage",
|
||||
"coveralls": "nyc report --reporter=text-lcov | coveralls"
|
||||
},
|
||||
"author": "Juanjo Diaz <juanjo.diazmo@gmail.com>",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/juanjoDiaz/removeNPMAbsolutePaths"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/removeNPMAbsolutePaths/issues",
|
||||
"email": "juanjo.diazmo@gmail.com"
|
||||
},
|
||||
"license": "MIT",
|
||||
"preferGlobal": true,
|
||||
"bin": {
|
||||
"removeNPMAbsolutePaths": "bin/removeNPMAbsolutePaths"
|
||||
},
|
||||
"files": [
|
||||
"LICENSE",
|
||||
"README.md",
|
||||
"bin/",
|
||||
"src/"
|
||||
],
|
||||
"devDependencies": {
|
||||
"chai": "^4.2.0",
|
||||
"chai-as-promised": "^7.1.1",
|
||||
"coveralls": "^3.0.5",
|
||||
"eslint": "^6.0.1",
|
||||
"eslint-config-airbnb-base": "^13.2.0",
|
||||
"eslint-plugin-import": "^2.18.0",
|
||||
"mocha": "^6.1.4",
|
||||
"nyc": "^14.1.1",
|
||||
"sinon": "^7.3.2",
|
||||
"sinon-chai": "^3.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4.0.0"
|
||||
}
|
||||
}
|
||||
51
node_modules/removeNPMAbsolutePaths/src/cli.js
generated
vendored
Normal file
51
node_modules/removeNPMAbsolutePaths/src/cli.js
generated
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
'use strict';
|
||||
|
||||
const defaultOpts = {
|
||||
force: false,
|
||||
};
|
||||
|
||||
function parseArguments(args) {
|
||||
if (args.length < 1) {
|
||||
throw new Error('Missing path.\nThe first argument should be the path to a directory or a package.json file.');
|
||||
}
|
||||
|
||||
const path = args[0];
|
||||
const opts = { ...defaultOpts };
|
||||
|
||||
const ignored = [];
|
||||
|
||||
for (let i = 1; i < args.length; i += 1) {
|
||||
const arg = args[i];
|
||||
switch (arg) {
|
||||
case '--force':
|
||||
opts.force = true;
|
||||
break;
|
||||
case '--fields':
|
||||
if (opts.fields) {
|
||||
throw new Error('Duplicated argument: --fields.\nThe --fields flag has been detected twice.');
|
||||
}
|
||||
|
||||
opts.fields = [];
|
||||
while (args[i + 1] && args[i + 1].slice(0, 2) !== '--') {
|
||||
opts.fields.push(args[i += 1]);
|
||||
}
|
||||
|
||||
if (opts.fields && opts.fields.length === 0) {
|
||||
throw new Error('Invalid argument usage: --fields.\nThe --fields flag should be followed by the specific fields that should be removed but none was found.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ignored.push(arg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
path,
|
||||
opts,
|
||||
ignored,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports.defaultOpts = defaultOpts;
|
||||
module.exports.parseArguments = parseArguments;
|
||||
310
node_modules/removeNPMAbsolutePaths/src/errno.js
generated
vendored
Normal file
310
node_modules/removeNPMAbsolutePaths/src/errno.js
generated
vendored
Normal file
|
|
@ -0,0 +1,310 @@
|
|||
'use strict';
|
||||
|
||||
const all = [
|
||||
{
|
||||
errno: -2,
|
||||
code: 'ENOENT',
|
||||
description: 'No such file or directory',
|
||||
},
|
||||
{
|
||||
errno: -1,
|
||||
code: 'UNKNOWN',
|
||||
description: 'Unknown error',
|
||||
},
|
||||
{
|
||||
errno: 0,
|
||||
code: 'OK',
|
||||
description: 'Success',
|
||||
},
|
||||
{
|
||||
errno: 1,
|
||||
code: 'EOF',
|
||||
description: 'End of file',
|
||||
},
|
||||
{
|
||||
errno: 2,
|
||||
code: 'EADDRINFO',
|
||||
description: 'Getaddrinfo error',
|
||||
},
|
||||
{
|
||||
errno: 3,
|
||||
code: 'EACCES',
|
||||
description: 'Permission denied',
|
||||
},
|
||||
{
|
||||
errno: 4,
|
||||
code: 'EAGAIN',
|
||||
description: 'Resource temporarily unavailable',
|
||||
},
|
||||
{
|
||||
errno: 5,
|
||||
code: 'EADDRINUSE',
|
||||
description: 'Address already in use',
|
||||
},
|
||||
{
|
||||
errno: 6,
|
||||
code: 'EADDRNOTAVAIL',
|
||||
description: 'Address not available',
|
||||
},
|
||||
{
|
||||
errno: 7,
|
||||
code: 'EAFNOSUPPORT',
|
||||
description: 'Address family not supported',
|
||||
},
|
||||
{
|
||||
errno: 8,
|
||||
code: 'EALREADY',
|
||||
description: 'Connection already in progress',
|
||||
},
|
||||
{
|
||||
errno: 9,
|
||||
code: 'EBADF',
|
||||
description: 'Bad file descriptor',
|
||||
},
|
||||
{
|
||||
errno: 10,
|
||||
code: 'EBUSY',
|
||||
description: 'Resource busy or locked',
|
||||
},
|
||||
{
|
||||
errno: 11,
|
||||
code: 'ECONNABORTED',
|
||||
description: 'Software caused connection abort',
|
||||
},
|
||||
{
|
||||
errno: 12,
|
||||
code: 'ECONNREFUSED',
|
||||
description: 'Connection refused',
|
||||
},
|
||||
{
|
||||
errno: 13,
|
||||
code: 'ECONNRESET',
|
||||
description: 'Connection reset by peer',
|
||||
},
|
||||
{
|
||||
errno: 14,
|
||||
code: 'EDESTADDRREQ',
|
||||
description: 'Destination address required',
|
||||
},
|
||||
{
|
||||
errno: 15,
|
||||
code: 'EFAULT',
|
||||
description: 'Bad address in system call argument',
|
||||
},
|
||||
{
|
||||
errno: 16,
|
||||
code: 'EHOSTUNREACH',
|
||||
description: 'Host is unreachable',
|
||||
},
|
||||
{
|
||||
errno: 17,
|
||||
code: 'EINTR',
|
||||
description: 'Interrupted system call',
|
||||
},
|
||||
{
|
||||
errno: 18,
|
||||
code: 'EINVAL',
|
||||
description: 'Invalid argument',
|
||||
},
|
||||
{
|
||||
errno: 19,
|
||||
code: 'EISCONN',
|
||||
description: 'Socket is already connected',
|
||||
},
|
||||
{
|
||||
errno: 20,
|
||||
code: 'EMFILE',
|
||||
description: 'Too many open files',
|
||||
},
|
||||
{
|
||||
errno: 21,
|
||||
code: 'EMSGSIZE',
|
||||
description: 'Message too long',
|
||||
},
|
||||
{
|
||||
errno: 22,
|
||||
code: 'ENETDOWN',
|
||||
description: 'Network is down',
|
||||
},
|
||||
{
|
||||
errno: 23,
|
||||
code: 'ENETUNREACH',
|
||||
description: 'Network is unreachable',
|
||||
},
|
||||
{
|
||||
errno: 24,
|
||||
code: 'ENFILE',
|
||||
description: 'File table overflow',
|
||||
},
|
||||
{
|
||||
errno: 25,
|
||||
code: 'ENOBUFS',
|
||||
description: 'No buffer space available',
|
||||
},
|
||||
{
|
||||
errno: 26,
|
||||
code: 'ENOMEM',
|
||||
description: 'Not enough memory',
|
||||
},
|
||||
{
|
||||
errno: 27,
|
||||
code: 'ENOTDIR',
|
||||
description: 'Not a directory',
|
||||
},
|
||||
{
|
||||
errno: 28,
|
||||
code: 'EISDIR',
|
||||
description: 'Illegal operation on a directory',
|
||||
},
|
||||
{
|
||||
errno: 29,
|
||||
code: 'ENONET',
|
||||
description: 'Machine is not on the network',
|
||||
},
|
||||
{
|
||||
errno: 31,
|
||||
code: 'ENOTCONN',
|
||||
description: 'Socket is not connected',
|
||||
},
|
||||
{
|
||||
errno: 32,
|
||||
code: 'ENOTSOCK',
|
||||
description: 'Socket operation on non-socket',
|
||||
},
|
||||
{
|
||||
errno: 33,
|
||||
code: 'ENOTSUP',
|
||||
description: 'Operation not supported on socket',
|
||||
},
|
||||
{
|
||||
errno: 34,
|
||||
code: 'ENOENT',
|
||||
description: 'No such file or directory',
|
||||
},
|
||||
{
|
||||
errno: 35,
|
||||
code: 'ENOSYS',
|
||||
description: 'Function not implemented',
|
||||
},
|
||||
{
|
||||
errno: 36,
|
||||
code: 'EPIPE',
|
||||
description: 'Broken pipe',
|
||||
},
|
||||
{
|
||||
errno: 37,
|
||||
code: 'EPROTO',
|
||||
description: 'Protocol error',
|
||||
},
|
||||
{
|
||||
errno: 38,
|
||||
code: 'EPROTONOSUPPORT',
|
||||
description: 'Protocol not supported',
|
||||
},
|
||||
{
|
||||
errno: 39,
|
||||
code: 'EPROTOTYPE',
|
||||
description: 'Protocol wrong type for socket',
|
||||
},
|
||||
{
|
||||
errno: 40,
|
||||
code: 'ETIMEDOUT',
|
||||
description: 'Connection timed out',
|
||||
},
|
||||
{
|
||||
errno: 41,
|
||||
code: 'ECHARSET',
|
||||
description: 'Invalid Unicode character',
|
||||
},
|
||||
{
|
||||
errno: 42,
|
||||
code: 'EAIFAMNOSUPPORT',
|
||||
description: 'Address family for hostname not supported',
|
||||
},
|
||||
{
|
||||
errno: 44,
|
||||
code: 'EAISERVICE',
|
||||
description: 'Servname not supported for ai_socktype',
|
||||
},
|
||||
{
|
||||
errno: 45,
|
||||
code: 'EAISOCKTYPE',
|
||||
description: 'Ai_socktype not supported',
|
||||
},
|
||||
{
|
||||
errno: 46,
|
||||
code: 'ESHUTDOWN',
|
||||
description: 'Cannot send after transport endpoint shutdown',
|
||||
},
|
||||
{
|
||||
errno: 47,
|
||||
code: 'EEXIST',
|
||||
description: 'File already exists',
|
||||
},
|
||||
{
|
||||
errno: 48,
|
||||
code: 'ESRCH',
|
||||
description: 'No such process',
|
||||
},
|
||||
{
|
||||
errno: 49,
|
||||
code: 'ENAMETOOLONG',
|
||||
description: 'Name too long',
|
||||
},
|
||||
{
|
||||
errno: 50,
|
||||
code: 'EPERM',
|
||||
description: 'Operation not permitted',
|
||||
},
|
||||
{
|
||||
errno: 51,
|
||||
code: 'ELOOP',
|
||||
description: 'Too many symbolic links encountered',
|
||||
},
|
||||
{
|
||||
errno: 52,
|
||||
code: 'EXDEV',
|
||||
description: 'Cross-device link not permitted',
|
||||
},
|
||||
{
|
||||
errno: 53,
|
||||
code: 'ENOTEMPTY',
|
||||
description: 'Directory not empty',
|
||||
},
|
||||
{
|
||||
errno: 54,
|
||||
code: 'ENOSPC',
|
||||
description: 'No space left on device',
|
||||
},
|
||||
{
|
||||
errno: 55,
|
||||
code: 'EIO',
|
||||
description: 'I/O error',
|
||||
},
|
||||
{
|
||||
errno: 56,
|
||||
code: 'EROFS',
|
||||
description: 'Read-only file system',
|
||||
},
|
||||
{
|
||||
errno: 57,
|
||||
code: 'ENODEV',
|
||||
description: 'No such device',
|
||||
},
|
||||
{
|
||||
errno: 58,
|
||||
code: 'ESPIPE',
|
||||
description: 'Invalid seek',
|
||||
},
|
||||
{
|
||||
errno: 59,
|
||||
code: 'ECANCELED',
|
||||
description: 'Operation canceled',
|
||||
},
|
||||
];
|
||||
|
||||
module.exports = {};
|
||||
|
||||
all.forEach((error) => {
|
||||
module.exports[error.errno] = error.description;
|
||||
});
|
||||
137
node_modules/removeNPMAbsolutePaths/src/removeNPMAbsolutePaths.js
generated
vendored
Normal file
137
node_modules/removeNPMAbsolutePaths/src/removeNPMAbsolutePaths.js
generated
vendored
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const {
|
||||
stat, readdir, readFile, writeFile,
|
||||
} = require('fs');
|
||||
const { promisify } = require('util');
|
||||
const errno = require('./errno');
|
||||
|
||||
const statAsync = promisify(stat);
|
||||
const readdirAsync = promisify(readdir);
|
||||
const readFileAsync = promisify(readFile);
|
||||
const writeFileAsync = promisify(writeFile);
|
||||
|
||||
class ProcessingError extends Error {
|
||||
constructor(message, err) {
|
||||
super(message + ((err && err.errno) ? ` (${errno[err.errno]})` : ''));
|
||||
this.cause = err;
|
||||
}
|
||||
}
|
||||
|
||||
async function getStats(filePath) {
|
||||
try {
|
||||
return await statAsync(filePath);
|
||||
} catch (err) {
|
||||
throw new ProcessingError(`Can't read directory/file at "${filePath}"`, err);
|
||||
}
|
||||
}
|
||||
|
||||
async function processFile(filePath, opts) {
|
||||
try {
|
||||
let data;
|
||||
try {
|
||||
data = await readFileAsync(filePath, 'utf8');
|
||||
} catch (err) {
|
||||
throw new ProcessingError(`Can't read file at "${filePath}"`, err);
|
||||
}
|
||||
|
||||
let shouldWriteFile = false;
|
||||
let obj;
|
||||
try {
|
||||
obj = JSON.parse(data);
|
||||
} catch (err) {
|
||||
throw new ProcessingError(`Malformed package.json file at "${filePath}"`, err);
|
||||
}
|
||||
|
||||
Object.keys(obj).forEach((key) => {
|
||||
const shouldBeDeleted = opts.fields ? (opts.fields.indexOf(key) !== -1) : (key[0] === '_');
|
||||
if (shouldBeDeleted) {
|
||||
delete obj[key];
|
||||
shouldWriteFile = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (shouldWriteFile || opts.force) {
|
||||
try {
|
||||
await writeFileAsync(filePath, JSON.stringify(obj, null, ' '));
|
||||
} catch (err) {
|
||||
throw new ProcessingError(`Can't write processed file to "${filePath}"`, err);
|
||||
}
|
||||
|
||||
return { filePath, rewritten: true, success: true };
|
||||
}
|
||||
|
||||
return { filePath, rewritten: false, success: true };
|
||||
} catch (err) {
|
||||
return { filePath, err, success: false };
|
||||
}
|
||||
}
|
||||
|
||||
async function processDir(dirPath, opts) {
|
||||
try {
|
||||
let files;
|
||||
try {
|
||||
files = await readdirAsync(dirPath);
|
||||
} catch (err) {
|
||||
throw new ProcessingError(`Can't read directory at "${dirPath}"`, err);
|
||||
}
|
||||
|
||||
const results = await Promise.all(files.map(async (fileName) => {
|
||||
const filePath = path.join(dirPath, fileName);
|
||||
|
||||
const stats = await getStats(filePath);
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
return processDir(filePath, opts);
|
||||
}
|
||||
|
||||
if (fileName === 'package.json') {
|
||||
return processFile(filePath, opts);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}));
|
||||
|
||||
return results.reduce((arr, value) => {
|
||||
if (!value) {
|
||||
return arr;
|
||||
}
|
||||
|
||||
if (value.constructor === Array) {
|
||||
return arr.concat(value);
|
||||
}
|
||||
|
||||
arr.push(value);
|
||||
return arr;
|
||||
}, [{ dirPath, success: true }]);
|
||||
} catch (err) {
|
||||
return [{ dirPath, err, success: false }];
|
||||
}
|
||||
}
|
||||
|
||||
async function removeNPMAbsolutePaths(filePath, opts) {
|
||||
opts = opts || {}; // eslint-disable-line no-param-reassign
|
||||
|
||||
if (!filePath) {
|
||||
throw new ProcessingError('Missing path.\nThe first argument should be the path to a directory or a package.json file.');
|
||||
}
|
||||
|
||||
if (opts.fields && (opts.fields.constructor !== Array || opts.fields.length === 0)) {
|
||||
throw new ProcessingError('Invalid option: fields.\nThe fields option should be an array cotaining the names of the specific fields that should be removed.');
|
||||
}
|
||||
|
||||
const stats = await getStats(filePath);
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
return processDir(filePath, opts);
|
||||
}
|
||||
|
||||
if (path.basename(filePath) === 'package.json') {
|
||||
return [await processFile(filePath, opts)];
|
||||
}
|
||||
|
||||
throw new Error('Invalid path provided. The path should be a directory or a package.json file.');
|
||||
}
|
||||
|
||||
module.exports = removeNPMAbsolutePaths;
|
||||
Loading…
Add table
Add a link
Reference in a new issue