Skip to content

Commit

Permalink
Add tooling for vendored dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
chromakode committed Jul 15, 2016
1 parent 4f67207 commit 35179b6
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/desktop/release/**
/desktop/node_modules
/desktop/shared
/desktop/js-vendor-desktop
/react-native/node_modules
/react-native/shared
/shared/libs/immutable-interface.js
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ npm-debug.log
node_modules

Keybase.app.dSYM.zip

js-vendor-desktop
node_shrinkwrap
52 changes: 52 additions & 0 deletions desktop/npm-vendor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env node

var os = require('os')
var path = require('path')
var fs = require('fs')
var spawnSync = require('child_process').spawnSync

function ensureSymlink (target, dest) {
if (fs.existsSync(target)) {
console.log('Removing existing', target)
fs.unlinkSync(target)
}

var absDest = path.resolve(dest)
console.log('Linking', target, '->', absDest)
fs.symlinkSync(absDest, target)
}

function spawn (command, args, options) {
console.log('>', command, args.join(' '))
var res = spawnSync(command, args, Object.assign({stdio: 'inherit', encoding: 'utf8'}, options))
if (res.error) {
throw res.error
} else if (res.status !== 0) {
throw new Error('Unexpected exit code: ' + res.status)
}
}

function installVendored () {
var packageInfo = JSON.parse(fs.readFileSync('./package.json'))
var parts = packageInfo.keybaseVendoredDependencies.split('#')
var url = parts[0]
var commit = parts[1]

if (!fs.existsSync('./js-vendor-desktop')) {
spawn('git', ['clone', url, 'js-vendor-desktop'])
}
spawn('git', ['fetch', 'origin'], {cwd: './js-vendor-desktop'})
spawn('git', ['checkout', '-f', commit], {cwd: './js-vendor-desktop'})
console.log(`js-vendor-desktop: ${url} @ ${commit}`)

ensureSymlink('./npm-shrinkwrap.json', './js-vendor-desktop/npm-shrinkwrap.json')
ensureSymlink('./node_shrinkwrap', './js-vendor-desktop/node_shrinkwrap')
spawn(os.platform() === 'win32' ? 'npm.cmd' : 'npm', ['install', '--loglevel=http', '--no-optional'], {
env: Object.assign({}, process.env, {
ELECTRON_CACHE: path.resolve('./js-vendor-desktop/electron'),
ELECTRON_ONLY_CACHE: 1,
}),
})
}

installVendored()
4 changes: 3 additions & 1 deletion desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "",
"main": "./dist/main.bundle.js",
"scripts": {
"vendor-install": "node npm-vendor.js",
"start": "babel-node --presets es2015,stage-2 npm-helper.js start",
"start-hot": "babel-node --presets es2015,stage-2 npm-helper.js start-hot",
"start-cold": "babel-node --presets es2015,stage-2 npm-helper.js start-cold",
Expand Down Expand Up @@ -104,5 +105,6 @@
},
"optionalDependencies": {
"fsevents": "1.0.12"
}
},
"keybaseVendoredDependencies": "git://github.com/keybase/js-vendor-desktop#65a74f32add51d5aba96d5d0ccb1cc6bd10d73c1"
}
8 changes: 7 additions & 1 deletion visdiff/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ function checkout (commit) {
} else {
console.log(`Installing dependencies for package.json:${newPackageHash}...`)
}
spawnSync(NPM_CMD, ['install'], {stdio: 'inherit'})

if (JSON.parse(fs.readFileSync('package.json')).keybaseVendoredDependencies) {
spawnSync(NPM_CMD, ['run', 'vendor-install'], {stdio: 'inherit'})
} else {
console.log('Warning: not using vendored dependencies')
spawnSync(NPM_CMD, ['install'], {stdio: 'inherit'})
}
}

function renderScreenshots (commitRange) {
Expand Down

0 comments on commit 35179b6

Please sign in to comment.