1'use strict'; 2const common = require('../common'); 3if (!common.hasCrypto) 4 common.skip('missing crypto'); 5 6const path = require('path'); 7const exec = require('child_process').exec; 8const assert = require('assert'); 9const fs = require('fs'); 10const fixtures = require('../common/fixtures'); 11 12const tmpdir = require('../common/tmpdir'); 13tmpdir.refresh(); 14const npmSandbox = path.join(tmpdir.path, 'npm-sandbox'); 15fs.mkdirSync(npmSandbox); 16const homeDir = path.join(tmpdir.path, 'home'); 17fs.mkdirSync(homeDir); 18const installDir = path.join(tmpdir.path, 'install-dir'); 19fs.mkdirSync(installDir); 20 21const corepackYarnPath = path.join( 22 __dirname, 23 '..', 24 '..', 25 'deps', 26 'corepack', 27 'dist', 28 'yarn.js' 29); 30 31const pkgContent = JSON.stringify({ 32 dependencies: { 33 'package-name': fixtures.path('packages/main') 34 } 35}); 36 37const pkgPath = path.join(installDir, 'package.json'); 38 39fs.writeFileSync(pkgPath, pkgContent); 40 41const env = { ...process.env, 42 PATH: path.dirname(process.execPath), 43 NPM_CONFIG_PREFIX: path.join(npmSandbox, 'npm-prefix'), 44 NPM_CONFIG_TMP: path.join(npmSandbox, 'npm-tmp'), 45 HOME: homeDir }; 46 47exec(`${process.execPath} ${corepackYarnPath} install`, { 48 cwd: installDir, 49 env: env 50}, common.mustCall(handleExit)); 51 52function handleExit(error, stdout, stderr) { 53 const code = error ? error.code : 0; 54 const signalCode = error ? error.signal : null; 55 56 if (code !== 0) { 57 process.stderr.write(stderr); 58 } 59 60 assert.strictEqual(code, 0, `yarn install got error code ${code}`); 61 assert.strictEqual(signalCode, null, `unexpected signal: ${signalCode}`); 62 assert(fs.existsSync(`${installDir}/node_modules/package-name`)); 63} 64