Port over installNodeHeaders
This commit is contained in:
Родитель
e867fd7792
Коммит
4ec23b002e
42
src/main.js
42
src/main.js
|
@ -6,34 +6,34 @@ import childProcess from 'child_process';
|
|||
import spawn from './spawn';
|
||||
import promisify from './promisify';
|
||||
|
||||
const fs = promisify(require('fs'));
|
||||
|
||||
const getHeadersRootDirForVersion = (version) => {
|
||||
return path.resolve(__dirname, 'headers');
|
||||
}
|
||||
|
||||
export function installNodeHeaders(nodeVersion, nodeDistUrl=null) {
|
||||
let headersDir = getHeadersRootDirForVersion(nodeVersion);
|
||||
export async function installNodeHeaders(nodeVersion, nodeDistUrl=null, headersDir=null) {
|
||||
headersDir = headersDir || getHeadersRootDirForVersion(nodeVersion);
|
||||
let distUrl = nodeDistUrl || 'https://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist';
|
||||
|
||||
let canary = path.join(headersDir, '.node-gyp', nodeVersion, 'common.gypi');
|
||||
/*
|
||||
await fs.exists
|
||||
try {
|
||||
let stat = await fs.stat(canary)
|
||||
if (stat) return true;
|
||||
} catch (e) { }
|
||||
|
||||
if (fs.existsSync(canary))
|
||||
return rx.Observable.create (subj) ->
|
||||
grunt.verbose.ok 'Found existing node.js installation, skipping install to save time!'
|
||||
rx.Observable.return(true).subscribe(subj)
|
||||
let cmd = 'node';
|
||||
let args = [
|
||||
require.resolve('npm/node_modules/node-gyp/bin/node-gyp'), 'install',
|
||||
`--target=${nodeVersion}`,
|
||||
`--arch=${process.arch}`,
|
||||
`--dist-url=${distUrl}`
|
||||
];
|
||||
|
||||
cmd = 'node'
|
||||
args = [require.resolve('npm/node_modules/node-gyp/bin/node-gyp'), 'install',
|
||||
"--target=#{nodeVersion}",
|
||||
"--arch=#{nodeArch}",
|
||||
"--dist-url=#{distUrl}"]
|
||||
|
||||
env = _.extend {}, process.env, HOME: nodeGypHome
|
||||
env.USERPROFILE = env.HOME if process.platform is 'win32'
|
||||
|
||||
rx.Observable.create (subj) ->
|
||||
grunt.verbose.ok 'Installing node.js'
|
||||
spawnObservable({cmd, args, opts: {env}, stdout: stdout, stderr: stderr}).subscribe(subj)
|
||||
*/
|
||||
let env = _.extend({}, process.env, { HOME: headersDir });
|
||||
if (process.platform === 'win32') {
|
||||
env.USERPROFILE = env.HOME;
|
||||
}
|
||||
|
||||
await spawn({cmd, args, opts: {env}});
|
||||
}
|
||||
|
|
24
test/main.js
24
test/main.js
|
@ -1,3 +1,25 @@
|
|||
import _ from './support';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import promisify from '../lib/promisify';
|
||||
const fs = promisify(require('fs'));
|
||||
const rimraf = promisify(require('rimraf'));
|
||||
|
||||
import {installNodeHeaders} from '../lib/main.js';
|
||||
|
||||
describe('installNodeHeaders', function() {
|
||||
this.timeout(30*1000);
|
||||
|
||||
it('installs node headers for 0.25.2', async () => {
|
||||
let targetHeaderDir = path.join(__dirname, 'testheaders');
|
||||
|
||||
if (await fs.stat(targetHeaderDir)) {
|
||||
await rimraf(targetHeaderDir);
|
||||
}
|
||||
|
||||
await fs.mkdir(targetHeaderDir);
|
||||
|
||||
await installNodeHeaders('0.25.2', null, targetHeaderDir);
|
||||
let canary = await fs.stat(path.join(targetHeaderDir, '.node-gyp', '0.25.2', 'common.gypi'));
|
||||
expect(canary).to.be.ok
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче