11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciif (!common.hasCrypto)
41cb0ef41Sopenharmony_ci  common.skip('missing crypto');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst path = require('path');
71cb0ef41Sopenharmony_ciconst exec = require('child_process').exec;
81cb0ef41Sopenharmony_ciconst assert = require('assert');
91cb0ef41Sopenharmony_ciconst fs = require('fs');
101cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
131cb0ef41Sopenharmony_citmpdir.refresh();
141cb0ef41Sopenharmony_ciconst npmSandbox = path.join(tmpdir.path, 'npm-sandbox');
151cb0ef41Sopenharmony_cifs.mkdirSync(npmSandbox);
161cb0ef41Sopenharmony_ciconst homeDir = path.join(tmpdir.path, 'home');
171cb0ef41Sopenharmony_cifs.mkdirSync(homeDir);
181cb0ef41Sopenharmony_ciconst installDir = path.join(tmpdir.path, 'install-dir');
191cb0ef41Sopenharmony_cifs.mkdirSync(installDir);
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ciconst npmPath = path.join(
221cb0ef41Sopenharmony_ci  __dirname,
231cb0ef41Sopenharmony_ci  '..',
241cb0ef41Sopenharmony_ci  '..',
251cb0ef41Sopenharmony_ci  'deps',
261cb0ef41Sopenharmony_ci  'npm',
271cb0ef41Sopenharmony_ci  'bin',
281cb0ef41Sopenharmony_ci  'npm-cli.js'
291cb0ef41Sopenharmony_ci);
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ciconst pkgContent = JSON.stringify({
321cb0ef41Sopenharmony_ci  dependencies: {
331cb0ef41Sopenharmony_ci    'package-name': fixtures.path('packages/main')
341cb0ef41Sopenharmony_ci  }
351cb0ef41Sopenharmony_ci});
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ciconst pkgPath = path.join(installDir, 'package.json');
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_cifs.writeFileSync(pkgPath, pkgContent);
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ciconst env = { ...process.env,
421cb0ef41Sopenharmony_ci              PATH: path.dirname(process.execPath),
431cb0ef41Sopenharmony_ci              NPM_CONFIG_PREFIX: path.join(npmSandbox, 'npm-prefix'),
441cb0ef41Sopenharmony_ci              NPM_CONFIG_TMP: path.join(npmSandbox, 'npm-tmp'),
451cb0ef41Sopenharmony_ci              NPM_CONFIG_AUDIT: false,
461cb0ef41Sopenharmony_ci              NPM_CONFIG_UPDATE_NOTIFIER: false,
471cb0ef41Sopenharmony_ci              HOME: homeDir };
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ciexec(`${process.execPath} ${npmPath} install`, {
501cb0ef41Sopenharmony_ci  cwd: installDir,
511cb0ef41Sopenharmony_ci  env: env
521cb0ef41Sopenharmony_ci}, common.mustCall(handleExit));
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_cifunction handleExit(error, stdout, stderr) {
551cb0ef41Sopenharmony_ci  const code = error ? error.code : 0;
561cb0ef41Sopenharmony_ci  const signalCode = error ? error.signal : null;
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci  if (code !== 0) {
591cb0ef41Sopenharmony_ci    process.stderr.write(stderr);
601cb0ef41Sopenharmony_ci  }
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ci  assert.strictEqual(code, 0, `npm install got error code ${code}`);
631cb0ef41Sopenharmony_ci  assert.strictEqual(signalCode, null, `unexpected signal: ${signalCode}`);
641cb0ef41Sopenharmony_ci  assert(fs.existsSync(`${installDir}/node_modules/package-name`));
651cb0ef41Sopenharmony_ci}
66