forked from bazel-contrib/rules_nodejs
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vendor in removeNPMAbsolutePaths (bazel-contrib#763)
Fixes npm_install target cycle Bazel crash
- Loading branch information
1 parent
0102fed
commit 9817704
Showing
14 changed files
with
650 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
third_party/github.com/juanjoDiaz/removeNPMAbsolutePaths/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
licenses(["notice"]) | ||
|
||
# Downloaded from https://github.com/juanjoDiaz/removeNPMAbsolutePaths/archive/v1.0.4.tar.gz | ||
# Timestamp: 2019-05-27 | ||
# SHA256: 3e8309c823660df6edeb4580f1d2df06ebfec0d65e196c46b488f53e644bd7aa | ||
exports_files(["LICENSE"]) | ||
|
||
filegroup( | ||
name = "package_contents", | ||
srcs = glob(["**/*"]), | ||
) |
21 changes: 21 additions & 0 deletions
21
third_party/github.com/juanjoDiaz/removeNPMAbsolutePaths/LICENSE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
77 changes: 77 additions & 0 deletions
77
third_party/github.com/juanjoDiaz/removeNPMAbsolutePaths/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
[![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 | ||
```Javascript | ||
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: | ||
```Javascript | ||
removeNPMAbsolutePaths '<PROJECT_FOLDER>' --tag1 --tag2 | ||
``` | ||
or passed programmatically in an options object | ||
```Javascript | ||
removeNPMAbsolutePaths('<PROJECT_FOLDER>', { tag1: true, tag2: false}); | ||
``` | ||
|
||
#### 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. | ||
|
||
```Javascript | ||
removeNPMAbsolutePaths '<PROJECT_FOLDER>' --fields _where _args | ||
``` | ||
|
||
```Javascript | ||
removeNPMAbsolutePaths('<PROJECT_FOLDER>', { tag1: true, fields: ['_where', '_args']}); | ||
``` | ||
|
||
|
||
## 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 |
49 changes: 49 additions & 0 deletions
49
third_party/github.com/juanjoDiaz/removeNPMAbsolutePaths/bin/removeNPMAbsolutePaths
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env node | ||
|
||
/* eslint-disable no-console */ | ||
|
||
'use strict'; | ||
|
||
const removeNPMAbsolutePaths = require('../src/removeNPMAbsolutePaths'); | ||
|
||
if (process.argv < 1) { | ||
console.log('Invalid argument.', 'The first argument should be the path to a directory or a package.json file.'); | ||
} | ||
|
||
const args = process.argv.slice(2); | ||
const folder = args[0]; | ||
const opts = { | ||
force: false, | ||
}; | ||
|
||
const ignoredOptions = []; | ||
|
||
for (let i = 1; i < args.length; i += 1) { | ||
const arg = args[i]; | ||
switch (arg) { | ||
case '--force': | ||
opts.force = true; | ||
break; | ||
case '--fields': | ||
opts.fields = opts.fields || []; | ||
while (args[i + 1] && args[i + 1].slice(0, 2) !== '--') { | ||
opts.fields.push(args[i += 1]); | ||
} | ||
break; | ||
default: | ||
ignoredOptions.push(arg); | ||
break; | ||
} | ||
} | ||
|
||
if (ignoredOptions.length) { | ||
console.warn(`The following options are unknown and will be ignored:\n${ignoredOptions.join('\n')}`); | ||
} | ||
|
||
removeNPMAbsolutePaths(folder, opts) | ||
.then(results => results.forEach((result) => { | ||
if (!result.success) { | ||
console.log(result.err.message); | ||
} | ||
})) | ||
.catch(err => console.log(err.message)); |
46 changes: 46 additions & 0 deletions
46
third_party/github.com/juanjoDiaz/removeNPMAbsolutePaths/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "removeNPMAbsolutePaths", | ||
"version": "1.0.4", | ||
"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", | ||
"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 <[email protected]>", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/juanjoDiaz/removeNPMAbsolutePaths" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/removeNPMAbsolutePaths/issues", | ||
"email": "[email protected]" | ||
}, | ||
"license": "MIT", | ||
"preferGlobal": "true", | ||
"bin": { | ||
"removeNPMAbsolutePaths": "bin/removeNPMAbsolutePaths" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.1.1", | ||
"chai-as-promised": "^7.1.1", | ||
"coveralls": "^2.13.1", | ||
"eslint": "^4.4.1", | ||
"eslint-config-airbnb-base": "^11.3.1", | ||
"eslint-plugin-import": "^2.7.0", | ||
"mocha": "^3.5.0", | ||
"nyc": "^11.1.0", | ||
"sinon": "^3.2.0", | ||
"sinon-chai": "^2.12.0" | ||
}, | ||
"engines": { | ||
"node": ">=4.0.0" | ||
} | ||
} |
Oops, something went wrong.