pnpm
Version:
A fast implementation of npm install
572 lines • 29.6 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
});
};
require('sepia');
const tape = require('tape');
const promisifyTape = require('tape-promise');
const test = promisifyTape(tape);
const path = require('path');
const fs = require('fs');
const caw = require('caw');
const semver = require('semver');
const crossSpawn = require('cross-spawn');
const spawnSync = crossSpawn.sync;
const isCI = require('is-ci');
const rimraf = require('rimraf-then');
const distTags_1 = require('./support/distTags');
const prepare_1 = require('./support/prepare');
const requireJson_1 = require('../src/fs/requireJson');
const basicPackageJson = requireJson_1.default(path.join(__dirname, './support/simple-package.json'));
const src_1 = require('../src');
const isExecutable_1 = require('./support/isExecutable');
const testDefaults_1 = require('./support/testDefaults');
const exists = require('exists-file');
const globalPath_1 = require('./support/globalPath');
const localPkg_1 = require('./support/localPkg');
const isWindows = process.platform === 'win32';
const preserveSymlinks = semver.satisfies(process.version, '>=6.3.0');
if (!caw() && !isWindows) {
process.env.VCR_MODE = 'cache';
}
test('small with dependencies (rimraf)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['rimraf@2.5.1'], testDefaults_1.default());
const rimraf = require(path.join(process.cwd(), 'node_modules', 'rimraf'));
t.ok(typeof rimraf === 'function', 'rimraf() is available');
isExecutable_1.default(t, path.join(process.cwd(), 'node_modules', '.bin', 'rimraf'));
});
});
test('no dependencies (lodash)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['lodash@4.0.0'], testDefaults_1.default());
const _ = require(path.join(process.cwd(), 'node_modules', 'lodash'));
t.ok(typeof _ === 'function', '_ is available');
t.ok(typeof _.clone === 'function', '_.clone is available');
});
});
test('scoped modules without version spec (@rstacruz/tap-spec)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['@rstacruz/tap-spec'], testDefaults_1.default());
const _ = require(path.join(process.cwd(), 'node_modules', '@rstacruz/tap-spec'));
t.ok(typeof _ === 'function', 'tap-spec is available');
});
});
test('scoped modules with versions (@rstacruz/tap-spec@4.1.1)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['@rstacruz/tap-spec@4.1.1'], testDefaults_1.default());
const _ = require(path.join(process.cwd(), 'node_modules', '@rstacruz/tap-spec'));
t.ok(typeof _ === 'function', 'tap-spec is available');
});
});
test('scoped modules (@rstacruz/tap-spec@*)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['@rstacruz/tap-spec@*'], testDefaults_1.default());
const _ = require(path.join(process.cwd(), 'node_modules', '@rstacruz/tap-spec'));
t.ok(typeof _ === 'function', 'tap-spec is available');
});
});
test('multiple scoped modules (@rstacruz/...)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['@rstacruz/tap-spec@*', '@rstacruz/travis-encrypt@*'], testDefaults_1.default());
const tapSpec = require(path.join(process.cwd(), 'node_modules', '@rstacruz/tap-spec'));
t.ok(typeof tapSpec === 'function', 'tap-spec is available');
const travisEncrypt = require(path.join(process.cwd(), 'node_modules', '@rstacruz/travis-encrypt'));
t.ok(typeof travisEncrypt === 'function', 'travis-encrypt is available');
});
});
test('nested scoped modules (test-pnpm-issue219 -> @zkochan/test-pnpm-issue219)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['test-pnpm-issue219@1.0.2'], testDefaults_1.default());
const _ = require(path.join(process.cwd(), 'node_modules', 'test-pnpm-issue219'));
t.ok(_ === 'test-pnpm-issue219,@zkochan/test-pnpm-issue219', 'nested scoped package is available');
});
});
test('scoped modules from a directory', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs([localPkg_1.local('local-scoped-pkg')], testDefaults_1.default());
const localPkg = require(path.join(process.cwd(), 'node_modules', '@scope', 'local-scoped-pkg'));
t.equal(localPkg(), '@scope/local-scoped-pkg', 'localScopedPkg() is available');
});
});
test('skip failing optional dependencies', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['pkg-with-failing-optional-dependency@1.0.1'], testDefaults_1.default());
const isNegative = require(path.join(process.cwd(), 'node_modules', 'pkg-with-failing-optional-dependency'));
t.ok(isNegative(-1), 'package with failed optional dependency has the dependencies installed correctly');
});
});
test('idempotency (rimraf)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['rimraf@2.5.1'], testDefaults_1.default());
yield src_1.installPkgs(['rimraf@2.5.1'], testDefaults_1.default());
const rimraf = require(path.join(process.cwd(), 'node_modules', 'rimraf'));
t.ok(typeof rimraf === 'function', 'rimraf is available');
});
});
test('overwriting (magic-hook@2.0.0 and @0.1.0)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['magic-hook@2.0.0'], testDefaults_1.default());
const flattenPathInStore = path.join(process.cwd(), 'node_modules/.store/nested/flatten@1.0.2');
let flattenExists = yield exists(flattenPathInStore);
t.ok(flattenExists, 'flatten@1.0.2 is in the store');
yield src_1.installPkgs(['magic-hook@0.1.0'], testDefaults_1.default());
flattenExists = yield exists(flattenPathInStore);
t.ok(!flattenExists, 'dependency of magic-hook@2.0.0 is removed');
const _ = require(path.join(process.cwd(), 'node_modules', 'magic-hook', 'package.json'));
t.ok(_.version === '0.1.0', 'magic-hook is 0.1.0');
});
});
test('overwriting (is-positive@3.0.0 with is-positive@latest)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['is-positive@3.0.0'], testDefaults_1.default({ save: true }));
let _ = yield exists(path.join(process.cwd(), 'node_modules/.store/nested/is-positive@3.0.0'));
t.ok(_, 'magic-hook@3.0.0 exists');
yield src_1.installPkgs(['is-positive@latest'], testDefaults_1.default({ save: true }));
_ = yield exists(path.join(process.cwd(), 'node_modules/.store/nested/is-positive@3.1.0'));
t.ok(_, 'magic-hook@3.1.0 exists after installing the latest');
});
});
test('forcing', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['magic-hook@2.0.0'], testDefaults_1.default());
const distPath = path.join(process.cwd(), 'node_modules/.store/nested/magic-hook@2.0.0/_/dist');
yield rimraf(distPath);
yield src_1.installPkgs(['magic-hook@2.0.0'], testDefaults_1.default({ force: true }));
const distPathExists = yield exists(distPath);
t.ok(distPathExists, 'magic-hook@2.0.0 dist folder reinstalled');
});
});
test('no forcing', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['magic-hook@2.0.0'], testDefaults_1.default());
const distPath = path.join(process.cwd(), 'node_modules/.store/nested/magic-hook@2.0.0/_/dist');
yield rimraf(distPath);
yield src_1.installPkgs(['magic-hook@2.0.0'], testDefaults_1.default());
const distPathExists = yield exists(distPath);
t.ok(!distPathExists, 'magic-hook@2.0.0 dist folder not reinstalled');
});
});
test('circular deps', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['circular-deps-1-of-2'], testDefaults_1.default());
const dep = require(path.join(process.cwd(), 'node_modules/circular-deps-1-of-2/mirror'));
t.equal(dep(), 'circular-deps-1-of-2', 'circular dependencies can access each other');
});
});
test('big with dependencies and circular deps (babel-preset-2015)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['babel-preset-es2015@6.3.13'], testDefaults_1.default());
const b = require(path.join(process.cwd(), 'node_modules', 'babel-preset-es2015'));
t.ok(typeof b === 'object', 'babel-preset-es2015 is available');
});
});
test('bundleDependencies (fsevents@1.0.6)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
if (isWindows) {
t.skip("fsevents can't be installed on Windows");
return;
}
prepare_1.default();
yield src_1.installPkgs(['fsevents@1.0.6'], testDefaults_1.default());
isExecutable_1.default(t, path.join(process.cwd(), 'node_modules', 'fsevents', 'node_modules', '.bin', 'mkdirp'));
});
});
test('compiled modules (ursa@0.9.1)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
if (!isCI || isWindows) {
t.skip('only ran on CI');
return t.end();
}
prepare_1.default();
yield src_1.installPkgs(['ursa@0.9.1'], testDefaults_1.default());
const ursa = require(path.join(process.cwd(), 'node_modules', 'ursa'));
t.ok(typeof ursa === 'object', 'ursa() is available');
});
});
test('tarballs (is-array-1.0.1.tgz)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['http://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz'], testDefaults_1.default());
const isArray = require(path.join(process.cwd(), 'node_modules', 'is-array'));
t.ok(isArray, 'isArray() is available');
const stat = fs.statSync(path.join(process.cwd(), 'node_modules/.store/nested', 'is-array-1.0.1#a83102a9c117983e6ff4d85311fb322231abe3d6'));
t.ok(stat.isDirectory(), 'stored in the proper location');
});
});
test('tarballs from GitHub (is-negative)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['is-negative@https://github.com/kevva/is-negative/archive/1d7e288222b53a0cab90a331f1865220ec29560c.tar.gz'], testDefaults_1.default());
const isNegative = require(path.join(process.cwd(), 'node_modules', 'is-negative'));
t.ok(isNegative, 'isNegative() is available');
});
});
test('local file', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs([localPkg_1.local('local-pkg')], testDefaults_1.default());
const localPkg = require(path.join(process.cwd(), 'node_modules', 'local-pkg'));
t.ok(localPkg, 'localPkg() is available');
});
});
test('nested local dependency of a local dependency', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs([localPkg_1.local('pkg-with-local-dep')], testDefaults_1.default());
const pkgWithLocalDep = require(path.join(process.cwd(), 'node_modules', 'pkg-with-local-dep'));
t.ok(pkgWithLocalDep, 'pkgWithLocalDep() is available');
t.equal(pkgWithLocalDep(), 'local-pkg', 'pkgWithLocalDep() returns data from local-pkg');
});
});
test('from a github repo', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['kevva/is-negative'], testDefaults_1.default());
const localPkg = require(path.join(process.cwd(), 'node_modules', 'is-negative'));
t.ok(localPkg, 'isNegative() is available');
});
});
test('from a git repo', function (t) {
return __awaiter(this, void 0, void 0, function* () {
if (isCI) {
t.skip('not testing the SSH GIT access via CI');
return t.end();
}
prepare_1.default();
yield src_1.installPkgs(['git+ssh://git@github.com/kevva/is-negative.git'], testDefaults_1.default());
const localPkg = require(path.join(process.cwd(), 'node_modules', 'is-negative'));
t.ok(localPkg, 'isNegative() is available');
});
});
test('shrinkwrap compatibility', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default({ dependencies: { rimraf: '*' } });
yield src_1.installPkgs(['rimraf@2.5.1'], testDefaults_1.default());
return new Promise((resolve, reject) => {
const proc = crossSpawn.spawn('npm', ['shrinkwrap']);
proc.on('error', reject);
proc.on('close', (code) => {
if (code > 0)
return reject(new Error('Exit code ' + code));
const wrap = JSON.parse(fs.readFileSync('npm-shrinkwrap.json', 'utf-8'));
t.ok(wrap.dependencies.rimraf.version === '2.5.1', 'npm shrinkwrap is successful');
resolve();
});
});
});
});
test('run pre/postinstall scripts', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs([localPkg_1.local('pre-and-postinstall-scripts-example')], testDefaults_1.default());
const generatedByPreinstall = require(path.join(process.cwd(), 'node_modules', 'pre-and-postinstall-scripts-example/generated-by-preinstall'));
t.ok(typeof generatedByPreinstall === 'function', 'generatedByPreinstall() is available');
const generatedByPostinstall = require(path.join(process.cwd(), 'node_modules', 'pre-and-postinstall-scripts-example/generated-by-postinstall'));
t.ok(typeof generatedByPostinstall === 'function', 'generatedByPostinstall() is available');
});
});
test('run install scripts', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs([localPkg_1.local('install-script-example')], testDefaults_1.default());
const generatedByInstall = require(path.join(process.cwd(), 'node_modules', 'install-script-example/generated-by-install'));
t.ok(typeof generatedByInstall === 'function', 'generatedByInstall() is available');
});
});
test('save to package.json (rimraf@2.5.1)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['rimraf@2.5.1'], testDefaults_1.default({ save: true }));
const rimraf = require(path.join(process.cwd(), 'node_modules', 'rimraf'));
t.ok(typeof rimraf === 'function', 'rimraf() is available');
const pkgJson = fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf8');
const dependencies = JSON.parse(pkgJson).dependencies;
t.deepEqual(dependencies, { rimraf: '^2.5.1' }, 'rimraf has been added to dependencies');
});
});
test('saveDev scoped module to package.json (@rstacruz/tap-spec)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['@rstacruz/tap-spec'], testDefaults_1.default({ saveDev: true }));
const tapSpec = require(path.join(process.cwd(), 'node_modules', '@rstacruz/tap-spec'));
t.ok(typeof tapSpec === 'function', 'tapSpec() is available');
const pkgJson = fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf8');
const devDependencies = JSON.parse(pkgJson).devDependencies;
t.deepEqual(devDependencies, { '@rstacruz/tap-spec': '^4.1.1' }, 'tap-spec has been added to devDependencies');
});
});
test('multiple save to package.json with `exact` versions (@rstacruz/tap-spec & rimraf@2.5.1) (in sorted order)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['rimraf@2.5.1', '@rstacruz/tap-spec@latest'], testDefaults_1.default({ save: true, saveExact: true }));
const tapSpec = require(path.join(process.cwd(), 'node_modules', '@rstacruz/tap-spec'));
t.ok(typeof tapSpec === 'function', 'tapSpec() is available');
const rimraf = require(path.join(process.cwd(), 'node_modules', 'rimraf'));
t.ok(typeof rimraf === 'function', 'rimraf() is available');
const pkgJson = fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf8');
const dependencies = JSON.parse(pkgJson).dependencies;
const expectedDeps = {
'@rstacruz/tap-spec': '4.1.1',
rimraf: '2.5.1'
};
t.deepEqual(dependencies, expectedDeps, 'tap-spec and rimraf have been added to dependencies');
t.deepEqual(Object.keys(dependencies), Object.keys(expectedDeps), 'tap-spec and rimraf have been added to dependencies in sorted order');
});
});
test('flattening symlinks (minimatch@3.0.0)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['minimatch@3.0.0'], testDefaults_1.default());
const stat = fs.lstatSync(path.join(process.cwd(), 'node_modules/.store/nested/node_modules/balanced-match'));
t.ok(stat.isSymbolicLink(), 'balanced-match is linked into store node_modules');
const _ = yield exists(path.join(process.cwd(), 'node_modules', 'balanced-match'));
t.ok(!_, 'balanced-match is not linked into main node_modules');
});
});
test('flattening symlinks (minimatch + balanced-match)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['minimatch@3.0.0'], testDefaults_1.default());
yield src_1.installPkgs(['balanced-match@^0.3.0'], testDefaults_1.default());
let _ = yield exists(path.join(process.cwd(), 'node_modules/.store/nested/node_modules/balanced-match'));
t.ok(!_, 'balanced-match is removed from store node_modules');
_ = yield exists(path.join(process.cwd(), 'node_modules', 'balanced-match'));
t.ok(_, 'balanced-match now in main node_modules');
});
});
test('production install (with --production flag)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default(basicPackageJson);
yield src_1.install(testDefaults_1.default({ production: true }));
const rimrafDir = fs.statSync(path.join(process.cwd(), 'node_modules', 'rimraf'));
let tapStatErrCode = 0;
try {
fs.statSync(path.join(process.cwd(), 'node_modules', '@rstacruz'));
}
catch (err) {
tapStatErrCode = err.code;
}
t.ok(rimrafDir.isSymbolicLink, 'rimraf exists');
t.is(tapStatErrCode, 'ENOENT', 'tap-spec does not exist');
});
});
test('production install (with production NODE_ENV)', function (t) {
return __awaiter(this, void 0, void 0, function* () {
const originalNodeEnv = process.env.NODE_ENV;
process.env.NODE_ENV = 'production';
prepare_1.default(basicPackageJson);
yield src_1.install(testDefaults_1.default());
// reset NODE_ENV
process.env.NODE_ENV = originalNodeEnv;
const rimrafDir = fs.statSync(path.join(process.cwd(), 'node_modules', 'rimraf'));
let tapStatErrCode = 0;
try {
fs.statSync(path.join(process.cwd(), 'node_modules', '@rstacruz'));
}
catch (err) {
tapStatErrCode = err.code;
}
t.ok(rimrafDir.isSymbolicLink, 'rimraf exists');
t.is(tapStatErrCode, 'ENOENT', 'tap-spec does not exist');
});
});
const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms));
test('fail when trying to install into the same store simultaneously', t => {
prepare_1.default();
return Promise.all([
src_1.installPkgs([localPkg_1.local('pkg-that-installs-slowly')], testDefaults_1.default()),
wait(500) // to be sure that lock was created
.then(_ => src_1.installPkgs(['rimraf@2.5.1'], testDefaults_1.default()))
.then(_ => t.fail('the store should have been locked'))
.catch(err => t.ok(err, 'store is locked'))
]);
});
test('fail when trying to install and uninstall from the same store simultaneously', t => {
prepare_1.default();
return Promise.all([
src_1.installPkgs([localPkg_1.local('pkg-that-installs-slowly')], testDefaults_1.default()),
wait(500) // to be sure that lock was created
.then(_ => src_1.uninstall(['rimraf@2.5.1'], testDefaults_1.default()))
.then(_ => t.fail('the store should have been locked'))
.catch(err => t.ok(err, 'store is locked'))
]);
});
test('packages should find the plugins they use when symlinks are preserved', function (t) {
return __awaiter(this, void 0, void 0, function* () {
if (!preserveSymlinks) {
t.skip('this test only for NodeJS with --preserve-symlinks support');
return;
}
prepare_1.default({
scripts: {
test: 'pkg-that-uses-plugins'
}
});
yield src_1.installPkgs([localPkg_1.local('pkg-that-uses-plugins'), localPkg_1.local('plugin-example')], testDefaults_1.default({ save: true }));
const result = spawnSync('npm', ['test']);
t.ok(result.stdout.toString().indexOf('My plugin is plugin-example') !== -1, 'package executable have found its plugin');
t.equal(result.status, 0, 'executable exited with success');
});
});
test('run js bin file', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default({
scripts: {
test: 'hello-world-js-bin'
}
});
yield src_1.installPkgs([localPkg_1.local('hello-world-js-bin')], testDefaults_1.default({ save: true }));
const result = spawnSync('npm', ['test']);
t.ok(result.stdout.toString().indexOf('Hello world!') !== -1, 'package executable printed its message');
t.equal(result.status, 0, 'executable exited with success');
});
});
const pnpmBin = path.join(__dirname, '../src/bin/pnpm.ts');
test('bin files are found by lifecycle scripts', t => {
prepare_1.default({
scripts: {
postinstall: 'hello-world-js-bin'
}
});
const result = spawnSync('ts-node', [pnpmBin, 'install', localPkg_1.local('hello-world-js-bin')]);
t.equal(result.status, 0, 'installation was successfull');
t.ok(result.stdout.toString().indexOf('Hello world!') !== -1, 'postinstall script was executed');
t.end();
});
test('installation via the CLI', t => {
prepare_1.default();
const result = spawnSync('ts-node', [pnpmBin, 'install', 'rimraf@2.5.1']);
console.log(result.stderr.toString());
t.equal(result.status, 0, 'install successful');
const rimraf = require(path.join(process.cwd(), 'node_modules', 'rimraf'));
t.ok(typeof rimraf === 'function', 'rimraf() is available');
isExecutable_1.default(t, path.join(process.cwd(), 'node_modules', '.bin', 'rimraf'));
t.end();
});
test('pass through to npm CLI for commands that are not supported by npm', t => {
const result = spawnSync('ts-node', [pnpmBin, 'config', 'get', 'user-agent']);
t.equal(result.status, 0, 'command was successfull');
t.ok(result.stdout.toString().indexOf('npm/') !== -1, 'command returned correct result');
t.end();
});
test('postinstall is executed after installation', t => {
prepare_1.default({
scripts: {
postinstall: 'echo "Hello world!"'
}
});
const result = spawnSync('ts-node', [pnpmBin, 'install', 'is-negative']);
t.equal(result.status, 0, 'installation was successfull');
t.ok(result.stdout.toString().indexOf('Hello world!') !== -1, 'postinstall script was executed');
t.end();
});
test('prepublish is not executed after installation with arguments', t => {
prepare_1.default({
scripts: {
prepublish: 'echo "Hello world!"'
}
});
const result = spawnSync('ts-node', [pnpmBin, 'install', 'is-negative']);
t.equal(result.status, 0, 'installation was successfull');
t.ok(result.stdout.toString().indexOf('Hello world!') === -1, 'prepublish script was not executed');
t.end();
});
test('prepublish is executed after argumentless installation', t => {
prepare_1.default({
scripts: {
prepublish: 'echo "Hello world!"'
}
});
const result = spawnSync('ts-node', [pnpmBin, 'install']);
t.equal(result.status, 0, 'installation was successfull');
t.ok(result.stdout.toString().indexOf('Hello world!') !== -1, 'prepublish script was executed');
t.end();
});
test('global installation', function (t) {
return __awaiter(this, void 0, void 0, function* () {
yield src_1.installPkgs(['is-positive'], testDefaults_1.default({ globalPath: globalPath_1.default, global: true }));
const isPositive = require(path.join(globalPath_1.default, 'node_modules', 'is-positive'));
t.ok(typeof isPositive === 'function', 'isPositive() is available');
});
});
test('tarball local package', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs([localPkg_1.pathToLocalPkg('tar-pkg/tar-pkg-1.0.0.tgz')], testDefaults_1.default());
const localPkg = require(path.join(process.cwd(), 'node_modules', 'tar-pkg'));
t.equal(localPkg(), 'tar-pkg', 'tarPkg() is available');
});
});
test("don't fail when peer dependency is fetched from GitHub", t => {
prepare_1.default();
return src_1.installPkgs([localPkg_1.local('test-pnpm-peer-deps')], testDefaults_1.default());
});
test('create a pnpm-debug.log file when the command fails', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
const result = spawnSync('ts-node', [pnpmBin, 'install', '@zkochan/i-do-not-exist']);
t.equal(result.status, 1, 'install failed');
t.ok(yield exists('pnpm-debug.log'), 'log file created');
t.end();
});
});
test('building native addons', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
yield src_1.installPkgs(['runas@3.1.1'], testDefaults_1.default());
t.ok(yield exists('node_modules/.store/nested/runas@3.1.1/_/build'), 'build folder created');
});
});
test('should update subdep on second install', function (t) {
return __awaiter(this, void 0, void 0, function* () {
prepare_1.default();
const latest = 'stable';
yield distTags_1.add('dep-of-pkg-with-1-dep', '1.0.0', latest);
yield src_1.installPkgs(['pkg-with-1-dep'], testDefaults_1.default({ save: true, tag: latest, cacheTTL: 0 }));
t.ok(yield exists('node_modules/.store/nested/dep-of-pkg-with-1-dep@1.0.0'), 'should install dep-of-pkg-with-1-dep@1.0.0');
yield distTags_1.add('dep-of-pkg-with-1-dep', '1.1.0', latest);
yield src_1.install(testDefaults_1.default({ depth: 1, tag: latest, cacheTTL: 0 }));
t.ok(yield exists('node_modules/.store/nested/dep-of-pkg-with-1-dep@1.1.0'), 'should update to dep-of-pkg-with-1-dep@1.1.0');
});
});
test('should install flat tree', function (t) {
return __awaiter(this, void 0, void 0, function* () {
if (!preserveSymlinks) {
t.skip('this test only for NodeJS with --preserve-symlinks support');
return;
}
prepare_1.default();
yield src_1.installPkgs(['rimraf@2.5.1'], testDefaults_1.default({ flatTree: true }));
isAvailable('balanced-match');
isAvailable('rimraf');
isAvailable('brace-expansion');
isAvailable('concat-map');
function isAvailable(depName) {
const dep = require(path.join(process.cwd(), 'node_modules', depName));
t.ok(dep, `${depName} is available`);
}
});
});
//# sourceMappingURL=install.js.map