2020-09-21 01:14:06 -04:00
|
|
|
"use strict";
|
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
|
|
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) : adopt(result.value).then(fulfilled, rejected); }
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
});
|
|
|
|
};
|
|
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
|
|
};
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2021-03-30 19:55:25 -04:00
|
|
|
exports.publish = exports.getPackage = void 0;
|
2020-10-03 02:20:50 -04:00
|
|
|
const libnpmpublish_1 = require("libnpmpublish");
|
2020-09-21 01:14:06 -04:00
|
|
|
const semver_1 = __importDefault(require("semver"));
|
|
|
|
const geturl_1 = require("./geturl");
|
|
|
|
const local_1 = require("./local");
|
2020-10-03 02:20:50 -04:00
|
|
|
const log_1 = require("./log");
|
2020-09-21 01:14:06 -04:00
|
|
|
const cache = {};
|
|
|
|
function getPackageInfo(name) {
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
// Convert dirname to package if needed
|
|
|
|
name = local_1.getPackage(name).name;
|
|
|
|
if (!cache[name]) {
|
|
|
|
try {
|
|
|
|
const result = yield geturl_1.getUrl("http:/" + "/registry.npmjs.org/" + name);
|
|
|
|
cache[name] = JSON.parse(Buffer.from(result.body).toString("utf8"));
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
if (error.status === 404) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cache[name] || null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function getPackage(name, version) {
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
const infos = yield getPackageInfo(name);
|
|
|
|
if (infos == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (version == null) {
|
|
|
|
const versions = Object.keys(infos.versions);
|
|
|
|
versions.sort(semver_1.default.compare);
|
|
|
|
version = versions.pop();
|
|
|
|
}
|
|
|
|
const info = infos.versions[version];
|
|
|
|
return {
|
|
|
|
dependencies: (info.dependencies || {}),
|
|
|
|
devDependencies: (info.devDependencies || {}),
|
2020-09-22 22:54:48 -04:00
|
|
|
gitHead: info.gitHead,
|
2020-09-21 01:14:06 -04:00
|
|
|
location: "remote",
|
|
|
|
name: info.name,
|
|
|
|
tarballHash: info.tarballHash,
|
|
|
|
version: info.version,
|
|
|
|
_ethers_nobuild: !!info._ethers_nobuild,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
exports.getPackage = getPackage;
|
2020-10-03 02:20:50 -04:00
|
|
|
function publish(path, manifest, options) {
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
try {
|
|
|
|
yield libnpmpublish_1.publish(path, manifest, options);
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
// We need an OTP
|
|
|
|
if (error.code === "EOTP") {
|
|
|
|
const otp = yield log_1.getPrompt(log_1.colorify.bold("Enter OTP: "));
|
|
|
|
options.otp = otp.replace(" ", "");
|
|
|
|
// Retry with the new OTP
|
|
|
|
return yield publish(path, manifest, options);
|
|
|
|
}
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
exports.publish = publish;
|