Permalink
Browse files

🐐

  • Loading branch information...
zkochan committed Oct 15, 2016
0 parents commit c47b6c3903c4906c65df1288e18982ea051fe5ea
Showing with 88 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. +57 −0 index.js
  3. +26 −0 package.json
@@ -0,0 +1,5 @@
npm-debug.log
node_modules
.tmp
@@ -0,0 +1,57 @@
'use strict'
const path = require('path')
const child = require('child_process')
const mkdirp = require('mkdirp').sync
const rimraf = require('rimraf').sync
const fs = require('fs')
let PATH = 'PATH'
// windows calls it's path 'Path' usually, but this is not guaranteed.
if (process.platform === 'win32') {
PATH = 'Path'
Object.keys(process.env).forEach(e => {
if (e.match(/^PATH$/i)) {
PATH = e
}
})
}
const env = createEnv()
console.log('prepare')
child.spawnSync('npm', ['cache', 'clean'], {env, stdio: 'inherit'})
child.spawnSync('yarn', ['cache', 'clean'], {env, stdio: 'inherit'})
child.spawnSync('pnpm', ['cache', 'clean'], {env, stdio: 'inherit'})
console.log('start')
benchmark('npm', ['install', 'babel-cli', '--force', '--ignore-scripts'])
benchmark('yarn', ['add', 'babel-cli', '--force', '--ignore-scripts'])
benchmark('pnpm', ['install', 'babel-cli', '--force', '--ignore-scripts'])
function createEnv () {
const env = Object.create(process.env)
env[PATH] = [
path.join(__dirname, 'node_modules/.bin'),
path.dirname(process.execPath),
process.env[PATH]
].join(path.delimiter)
return env
}
function benchmark (cmd, args) {
const timeName = `${cmd} ${args.join(' ')}`
const cwd = path.join(__dirname, '.tmp', cmd)
mkdirp(cwd)
console.time(timeName)
fs.writeFileSync(path.join(cwd, 'package.json'), '{"name":"foo","version":"1.0.0"}', 'utf-8')
const result = child.spawnSync(cmd, args, {env, cwd})
if (result.status !== 0) {
throw new Error(`${timeName} failed with status code ${result.status}`)
}
console.timeEnd(timeName)
rimraf(cwd)
}
@@ -0,0 +1,26 @@
{
"name": "dependency-managers-benchmark",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/zkochan/dependency-managers-benchmark.git"
},
"author": "Zoltan Kochan",
"license": "MIT",
"bugs": {
"url": "https://github.com/zkochan/dependency-managers-benchmark/issues"
},
"homepage": "https://github.com/zkochan/dependency-managers-benchmark#readme",
"dependencies": {
"cross-spawn": "^4.0.2",
"mkdirp": "^0.5.1",
"npm": "^3.10.8",
"pnpm": "^0.40.0",
"rimraf": "^2.5.4"
}
}

0 comments on commit c47b6c3

Please sign in to comment.