Skip to content

Instantly share code, notes, and snippets.

@makenowjust
Created March 24, 2016 10:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makenowjust/0894cd336a4683c3fb77 to your computer and use it in GitHub Desktop.
Save makenowjust/0894cd336a4683c3fb77 to your computer and use it in GitHub Desktop.
Bye npm, Hello Git repository.
'use strict'
/*
* Rewrite package.json to get dependencies from Git repository instead of npm.
*
* See also: https://medium.com/@azerbike/i-ve-just-liberated-my-modules-9045c06be67c
* and: http://blog.npmjs.org/post/141577284765/kik-left-pad-and-npm
*
* Usage: cd /path/to/your/package && node npm2git
*
* This script is warning because:
*
* - this is forgotten dependencies' version information.
* - Git repository dose not contain all package files always.
*
* You will be happened some troubles in many case.
*
* Author: TSUYUSATO Kitsune (GitHub: @MakeNowJust, Twitter: @make_now_just)
* License: WTFPL <http://www.wtfpl.net/txt/copying/>
*
* If you have some idea to improve, you could fork this Gist, thanks;)
*/
const fs = require('fs')
const pkg = require('./package.json')
const npm2git = field => {
if (!pkg[field]) return
for (let name of Object.keys(pkg[field])) {
pkg[field][name] = require(`./node_modules/${name}/package.json`).repository.url || (()=> {
console.error(`${name} has no repository field`)
return pkg[field][name]
})()
}
}
'dependencies devDependencies peerDependencies optionalDependencies'
.split(' ')
.forEach(npm2git)
const json = JSON.stringify(pkg, null, ' ')
console.log(json)
fs.writeFileSync('package.json', json)
@demonkoryu
Copy link

Thanks. I'm thinking along the same lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment