skywalking-apache
Version:
The NodeJS agent for Apache SkyWalking
72 lines • 3.16 kB
JavaScript
;
/*!
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var fs = tslib_1.__importStar(require("fs"));
var path = tslib_1.__importStar(require("path"));
var logging_1 = require("../logging");
var semver = tslib_1.__importStar(require("semver"));
var logger = logging_1.createLogger(__filename);
var PluginInstaller = /** @class */ (function () {
function PluginInstaller() {
var _this = this;
this.isBuiltIn = function (module) { return require.resolve(module) === module; };
this.checkModuleVersion = function (plugin) {
if (_this.isBuiltIn(plugin.module)) {
return {
version: '*',
isSupported: true,
};
}
var packageJsonPath = require.resolve(plugin.module + "/package.json");
var version = require(packageJsonPath).version;
if (!semver.satisfies(version, plugin.versions)) {
logger.info("Plugin " + plugin.module + " " + version + " doesn't satisfy the supported version " + plugin.versions);
return {
version: version,
isSupported: false,
};
}
return {
version: version,
isSupported: true,
};
};
this.pluginDir = path.resolve(__dirname, '..', 'plugins');
}
PluginInstaller.prototype.install = function () {
var _this = this;
fs.readdirSync(this.pluginDir)
.filter(function (file) { return !(file.endsWith('.d.ts') || file.endsWith('.js.map')); })
.forEach(function (file) {
var plugin = require(path.join(_this.pluginDir, file)).default;
var _a = _this.checkModuleVersion(plugin), isSupported = _a.isSupported, version = _a.version;
if (!isSupported) {
logger.info("Plugin " + plugin.module + " " + version + " doesn't satisfy the supported version " + plugin.versions);
return;
}
logger.info("Installing plugin " + plugin.module + " " + plugin.versions);
plugin.install();
});
};
return PluginInstaller;
}());
exports.default = new PluginInstaller();
//# sourceMappingURL=PluginInstaller.js.map