| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4739c45 commit 23f9275
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + exports.value = 42; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + { | ||
| 2 | + "name": "example", | ||
| 3 | + "version": "1.0.0", | ||
| 4 | + "main": "example.js" | ||
| 5 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + { | ||
| 2 | + "dependencies": { | ||
| 3 | + "example": "../example" | ||
| 4 | + } | ||
| 5 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,64 +6,37 @@ if (common.isInsideDirWithUnusualChars) | |||
| 6 | 6 | common.skip('npm does not support this install path'); | |
| 7 | 7 | ||
| 8 | 8 | const path = require('path'); | |
| 9 | - const exec = require('child_process').exec; | ||
| 10 | 9 | const assert = require('assert'); | |
| 11 | 10 | const fs = require('fs'); | |
| 12 | 11 | const fixtures = require('../common/fixtures'); | |
| 12 | + const { spawnSyncAndAssert } = require('../common/child_process'); | ||
| 13 | 13 | ||
| 14 | 14 | const tmpdir = require('../common/tmpdir'); | |
| 15 | 15 | tmpdir.refresh(); | |
| 16 | - const npmSandbox = tmpdir.resolve('npm-sandbox'); | ||
| 17 | - fs.mkdirSync(npmSandbox); | ||
| 18 | - const homeDir = tmpdir.resolve('home'); | ||
| 19 | - fs.mkdirSync(homeDir); | ||
| 20 | - const installDir = tmpdir.resolve('install-dir'); | ||
| 21 | - fs.mkdirSync(installDir); | ||
| 22 | - | ||
| 23 | - const npmPath = path.join( | ||
| 24 | - __dirname, | ||
| 25 | - '..', | ||
| 26 | - '..', | ||
| 27 | - 'deps', | ||
| 28 | - 'npm', | ||
| 29 | - 'bin', | ||
| 30 | - 'npm-cli.js' | ||
| 31 | - ); | ||
| 32 | - | ||
| 33 | - const pkgContent = JSON.stringify({ | ||
| 34 | - dependencies: { | ||
| 35 | - 'package-name': fixtures.path('packages/main') | ||
| 36 | - } | ||
| 37 | - }); | ||
| 38 | 16 | ||
| 39 | - const pkgPath = path.join(installDir, 'package.json'); | ||
| 17 | + // Copy fixtures/npm-install to the tmpdir for testing | ||
| 18 | + fs.cpSync(fixtures.path('npm-install'), tmpdir.path, { recursive: true }); | ||
| 40 | 19 | ||
| 41 | - fs.writeFileSync(pkgPath, pkgContent); | ||
| 20 | + const npmPath = path.join(__dirname, '..', '..', 'deps', 'npm', 'bin', 'npm-cli.js'); | ||
| 42 | 21 | ||
| 43 | - const env = { ...process.env, | ||
| 44 | - PATH: path.dirname(process.execPath), | ||
| 45 | - NODE: process.execPath, | ||
| 46 | - NPM: npmPath, | ||
| 47 | - NPM_CONFIG_PREFIX: path.join(npmSandbox, 'npm-prefix'), | ||
| 48 | - NPM_CONFIG_TMP: path.join(npmSandbox, 'npm-tmp'), | ||
| 49 | - NPM_CONFIG_AUDIT: false, | ||
| 50 | - NPM_CONFIG_UPDATE_NOTIFIER: false, | ||
| 51 | - HOME: homeDir }; | ||
| 22 | + const env = { | ||
| 23 | + ...process.env, | ||
| 24 | + PATH: path.dirname(process.execPath), | ||
| 25 | + NODE: process.execPath, | ||
| 26 | + NPM: npmPath, | ||
| 27 | + NPM_CONFIG_PREFIX: tmpdir.resolve('npm-prefix'), | ||
| 28 | + NPM_CONFIG_TMP: tmpdir.resolve('npm-tmp'), | ||
| 29 | + NPM_CONFIG_AUDIT: false, | ||
| 30 | + NPM_CONFIG_UPDATE_NOTIFIER: false, | ||
| 31 | + HOME: tmpdir.resolve('home'), | ||
| 32 | + }; | ||
| 52 | 33 | ||
| 53 | - exec(`"${common.isWindows ? process.execPath : '$NODE'}" "${common.isWindows ? npmPath : '$NPM'}" install`, { | ||
| 54 | - cwd: installDir, | ||
| 55 | - env: env | ||
| 56 | - }, common.mustCall(handleExit)); | ||
| 57 | - | ||
| 58 | - function handleExit(error, stdout, stderr) { | ||
| 59 | - const code = error ? error.code : 0; | ||
| 60 | - const signalCode = error ? error.signal : null; | ||
| 61 | - | ||
| 62 | - if (code !== 0) { | ||
| 63 | - process.stderr.write(stderr); | ||
| 64 | - } | ||
| 34 | + const installDir = tmpdir.resolve('install-dir'); | ||
| 35 | + spawnSyncAndAssert( | ||
| 36 | + process.execPath, | ||
| 37 | + [npmPath, 'install'], | ||
| 38 | + { cwd: installDir, env }, | ||
| 39 | + {} | ||
| 40 | + ); | ||
| 65 | 41 | ||
| 66 | - assert.strictEqual(code, 0, `npm install got error code ${code}`); | ||
| 67 | - assert.strictEqual(signalCode, null, `unexpected signal: ${signalCode}`); | ||
| 68 | - assert(fs.existsSync(`${installDir}/node_modules/package-name`)); | ||
| 69 | - } | ||
| 42 | + assert(fs.existsSync(path.join(installDir, 'node_modules', 'example'))); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments