UNPKG

pnpm

Version:

A fast implementation of npm install

116 lines 4.73 kB
"use strict"; 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()); }); }; const readPkgUp = require('read-pkg-up'); const path = require('path'); const semver = require('semver'); const common_tags_1 = require('common-tags'); const requireJson_1 = require('../fs/requireJson'); const writeJson_1 = require('../fs/writeJson'); const expandTilde_1 = require('../fs/expandTilde'); const logger_1 = require('../logger'); const storeJsonController_1 = require('../fs/storeJsonController'); const mkdirp_1 = require('../fs/mkdirp'); const cache_1 = require('./cache'); const normalizePath = require('normalize-path'); function default_1(opts) { return __awaiter(this, void 0, void 0, function* () { const pkg = yield (opts.global ? readGlobalPkg(opts.globalPath) : readPkgUp({ cwd: opts.cwd })); const root = normalizePath(pkg.path ? path.dirname(pkg.path) : opts.cwd); const store = resolveStorePath(opts.storePath, root); const storeJson = storeJsonController_1.read(store); if (storeJson) { failIfNotCompatible(storeJson.pnpm); } const ctx = { pkg: pkg.pkg, root, cache: cache_1.getCachePath(opts.globalPath), store, storeJson }; if (!opts.silent) logger_1.default(opts.logger); yield mkdirp_1.default(ctx.cache); yield mkdirp_1.default(ctx.store); return ctx; }); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; function failIfNotCompatible(storeVersion) { if (!storeVersion || !semver.satisfies(storeVersion, '>=0.28')) { const msg = structureChangeMsg('More info about what was changed at: https://github.com/rstacruz/pnpm/issues/276'); throw new Error(msg); } if (!semver.satisfies(storeVersion, '>=0.33')) { const msg = structureChangeMsg(common_tags_1.stripIndent ` The change was needed to fix the GitHub rate limit issue: Issue: https://github.com/rstacruz/pnpm/issues/361 PR: https://github.com/rstacruz/pnpm/pull/363 `); throw new Error(msg); } if (!semver.satisfies(storeVersion, '>=0.37')) { const msg = structureChangeMsg(common_tags_1.stripIndent ` The structure of store.json/dependencies was changed to map dependencies to their fullnames `); throw new Error(msg); } if (!semver.satisfies(storeVersion, '>=0.38')) { const msg = structureChangeMsg(common_tags_1.stripIndent ` The structure of store.json/dependencies was changed to not include the redundunt package.json at the end `); throw new Error(msg); } } function structureChangeMsg(moreInfo) { return common_tags_1.stripIndent ` The store structure was changed. Remove it and run pnpm again. ${moreInfo} TIPS: If you have a shared store, remove both the node_modules and the shared store. Otherwise just run \`rm -rf node_modules\` `; } function readGlobalPkg(globalPath) { return __awaiter(this, void 0, void 0, function* () { if (!globalPath) throw new Error('globalPath is required'); const globalPnpm = expandTilde_1.default(globalPath); const globalPkgPath = path.resolve(globalPnpm, 'package.json'); const globalPkgJson = yield readGlobalPkgJson(globalPkgPath); return { pkg: globalPkgJson, path: globalPkgPath }; }); } function readGlobalPkgJson(globalPkgPath) { return __awaiter(this, void 0, void 0, function* () { try { const globalPkgJson = requireJson_1.default(globalPkgPath); return globalPkgJson; } catch (err) { const pkgJson = {}; yield mkdirp_1.default(path.dirname(globalPkgPath)); yield writeJson_1.default(globalPkgPath, pkgJson); return pkgJson; } }); } function resolveStorePath(storePath, pkgRoot) { if (expandTilde_1.isHomepath(storePath)) { return expandTilde_1.default(storePath); } return path.resolve(pkgRoot, storePath); } //# sourceMappingURL=getContext.js.map