-
Notifications
You must be signed in to change notification settings - Fork 102
Implement npm install foo --save equivalent #118
base: master
Are you sure you want to change the base?
Changes from 1 commit
02f6d1a
3d54c94
3470920
9df9888
ff8288a
2a60f02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,7 +69,9 @@ exports.run = function (settings, args) { | |
| var a = argParse(args, { | ||
| 'repository': {match: ['-r', '--repository'], value: true}, | ||
| 'target_dir': {match: ['-d', '--package-dir'], value: true}, | ||
| 'baseurl': {match: ['-b', '--baseurl'], value: true} | ||
| 'baseurl': {match: ['-b', '--baseurl'], value: true}, | ||
| 'save': {match: ['-S', '--save'], value: false}, | ||
| 'save_dev': {match: ['-D', '--save-dev'], value: false} | ||
| }); | ||
|
|
||
| var opt = a.options; | ||
|
|
@@ -159,7 +161,6 @@ exports.reinstallPackages = function (cfg, opt, callback) { | |
| if (err) { | ||
| return logger.error(err); | ||
| } | ||
| // TODO: write package.json if --save option provided | ||
| project.updateRequireConfig(opt.target_dir, opt.baseurl, | ||
| function (err) { | ||
| if (err) { | ||
|
|
@@ -187,7 +188,6 @@ exports.installPackages = function (cfg, names, opt, callback) { | |
| if (err) { | ||
| return callback(err); | ||
| } | ||
| // TODO: write package.json if --save option provided | ||
| project.updateRequireConfig(opt.target_dir, opt.baseurl, callback); | ||
| }); | ||
| }; | ||
|
|
@@ -406,7 +406,34 @@ exports.installRepo = function (name, range, opt, callback) { | |
| if (err) { | ||
| return callback(err); | ||
| } | ||
| exports.cpDir(name, v, from_cache, cdir, opt, callback); | ||
| if (opt.save || opt.save_dev) { | ||
| exports.cpDir(name, v, from_cache, cdir, opt, function() { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no error handling for the cpDir callback?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Turns out I had no reason at all for leaving that out. Fix'd! |
||
| fs.readFile('package.json', function(err, data) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this path work when in a sub-directory of the project? Currently commands will walk up the directory hierarchy to find the project directory containing package.json. |
||
| var deps = opt.save ? 'dependencies' : 'devDependencies'; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's also possible to use jam.dependencies in package.json... devDependencies is currently unused by jam. I'd recommend we only use jam.dependencies to avoid conflicting with NPM's 'dependencies' property when saving. ...and I've just noticed you are namespacing it under 'jam' later on ;) |
||
|
|
||
| try { | ||
| data = JSON.parse(data.toString('utf8')); | ||
| } catch(e) { | ||
| err = e; | ||
| } | ||
| if (err) { | ||
| return callback(); | ||
| } | ||
| if (!data.jam) { | ||
| data.jam = {}; | ||
| } | ||
| data.jam[deps] = data.jam[deps] || {}; | ||
| data.jam[deps][name] = v; | ||
|
|
||
| data = JSON.stringify(data, null, 2) + '\n'; | ||
| fs.writeFile('package.json', data, function(err) { | ||
| callback(err); | ||
| }); | ||
| }); | ||
| }); | ||
| } else { | ||
| exports.cpDir(name, v, from_cache, cdir, opt, callback); | ||
| } | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this option, since Jam doesn't use devDependencies