nativescript
Version:
Command-line interface for building NativeScript projects
127 lines • 5.55 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Yarn2PackageManager = void 0;
const path = require("path");
const _ = require("lodash");
const base_package_manager_1 = require("./base-package-manager");
const decorators_1 = require("./common/decorators");
const yok_1 = require("./common/yok");
class Yarn2PackageManager extends base_package_manager_1.BasePackageManager {
constructor($childProcess, $errors, $fs, $hostInfo, $httpClient, $logger, $pacoteService) {
super($childProcess, $fs, $hostInfo, $pacoteService, "yarn2");
this.$errors = $errors;
this.$httpClient = $httpClient;
this.$logger = $logger;
this.$hostInfo_ = $hostInfo;
}
getPackageManagerExecutableName() {
let executableName = "yarn";
if (this.$hostInfo_.isWindows) {
executableName += ".cmd";
}
return executableName;
}
async install(packageName, pathToSave, config) {
if (config.disableNpmInstall) {
return;
}
if (config.ignoreScripts) {
config["ignore-scripts"] = true;
}
const packageJsonPath = path.join(pathToSave, "package.json");
const jsonContentBefore = this.$fs.readJson(packageJsonPath);
// remove unsupported flags
// todo: refactor all package managers to map typed flags to the actual flags
const cleanedConfig = _.omit(config, ["save-dev", "save-exact"]);
const flags = this.getFlagsString(cleanedConfig, true);
let params = [];
const isInstallingAllDependencies = packageName === pathToSave;
if (!isInstallingAllDependencies) {
params.push("add", packageName);
}
params = params.concat(flags);
const cwd = pathToSave;
try {
const result = await this.processPackageManagerInstall(packageName, params, { cwd, isInstallingAllDependencies });
return result;
}
catch (e) {
this.$fs.writeJson(packageJsonPath, jsonContentBefore);
throw e;
}
}
uninstall(packageName, config, cwd) {
const flags = this.getFlagsString(config, false);
return this.$childProcess.exec(`yarn remove ${packageName} ${flags}`, {
cwd,
});
}
async view(packageName, config) {
const wrappedConfig = _.extend({}, config, { json: true });
const flags = this.getFlagsString(wrappedConfig, false);
let viewResult;
try {
viewResult = await this.$childProcess.exec(`yarn npm info ${packageName} ${flags}`);
}
catch (e) {
this.$errors.fail(e.message);
}
try {
return JSON.parse(viewResult);
}
catch (err) {
this.$errors.fail(err.message);
return null;
}
}
search(filter, config) {
this.$errors.fail("Method not implemented. Yarn does not support searching for packages in the registry.");
return null;
}
async searchNpms(keyword) {
const httpRequestResult = await this.$httpClient.httpRequest(`https://api.npms.io/v2/search?q=keywords:${keyword}`);
const result = JSON.parse(httpRequestResult.body);
return result;
}
async getRegistryPackageData(packageName) {
const registry = await this.$childProcess.exec(`yarn config get npmRegistryServer`);
const url = `${registry.trim()}/${packageName}`;
this.$logger.trace(`Trying to get data from yarn registry for package ${packageName}, url is: ${url}`);
const responseData = (await this.$httpClient.httpRequest(url)).body;
this.$logger.trace(`Successfully received data from yarn registry for package ${packageName}. Response data is: ${responseData}`);
const jsonData = JSON.parse(responseData);
this.$logger.trace(`Successfully parsed data from yarn registry for package ${packageName}.`);
return jsonData;
}
async getCachePath() {
const result = await this.$childProcess.exec(`yarn config get cacheFolder`);
return result.toString().trim();
}
}
exports.Yarn2PackageManager = Yarn2PackageManager;
__decorate([
(0, decorators_1.exported)("yarn2")
], Yarn2PackageManager.prototype, "install", null);
__decorate([
(0, decorators_1.exported)("yarn2")
], Yarn2PackageManager.prototype, "uninstall", null);
__decorate([
(0, decorators_1.exported)("yarn2")
], Yarn2PackageManager.prototype, "view", null);
__decorate([
(0, decorators_1.exported)("yarn2")
], Yarn2PackageManager.prototype, "search", null);
__decorate([
(0, decorators_1.exported)("yarn2")
], Yarn2PackageManager.prototype, "getRegistryPackageData", null);
__decorate([
(0, decorators_1.exported)("yarn2")
], Yarn2PackageManager.prototype, "getCachePath", null);
yok_1.injector.register("yarn2", Yarn2PackageManager);
//# sourceMappingURL=yarn2-package-manager.js.map
;