-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
slt: add shrinkwrap cmd for filtering fields
When using shrinkwrap, combined with a private staging registry, you may not want your internal registry's URLs baked in to the npm-shrinkwrap.json file that gets created. This utility strips out those fields.
- Loading branch information
Showing
5 changed files
with
3,722 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright IBM Corp. 2016. All Rights Reserved. | ||
// Node module: strong-tools | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
'use strict'; | ||
|
||
var _ = require('lodash'); | ||
var assert = require('assert'); | ||
var debug = require('debug')('strong-tools:fix-license'); | ||
var json = require('json-file-plus'); | ||
var path = require('path'); | ||
|
||
updateShrinkwrap.out = console.log; | ||
exports.cli = updateShrinkwrap; | ||
|
||
function updateShrinkwrap(shrinkwrap) { | ||
shrinkwrap = path.resolve(shrinkwrap || 'npm-shrinkwrap.json'); | ||
debug(shrinkwrap); | ||
|
||
updateShrinkwrap.out('removed resolution URLs from %s', shrinkwrap); | ||
|
||
return json(shrinkwrap).catch(function(err) { | ||
assert.ifError(err, 'Failed to open ' + shrinkwrap + ': ' + shrinkwrap); | ||
}).then(rewrite).catch(function(err) { | ||
assert.ifError(err, 'Failed to filter out "resolved" from ' + shrinkwrap); | ||
}); | ||
|
||
function rewrite(file) { | ||
removeResolved(file.data); | ||
updateShrinkwrap.out('removed resolution URLs from %s', shrinkwrap); | ||
return file.save(); | ||
|
||
// XXX(rmg): this is recursive, but the tree should not be too deep | ||
function removeResolved(obj, k) { | ||
if (_.isObjectLike(obj)) { | ||
// only removed resolved key when the value is a string, otherwise | ||
// we're basically blacklisting any use of the module named "resolved" | ||
if (_.isString(obj.resolved)) { | ||
delete obj.resolved; | ||
} | ||
_.each(obj, removeResolved); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.