@theia-extension-tester/adapters
Version:
Run vscode-extension-tester UI tests in Eclipse Theia based editors.
57 lines • 2.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.load = exports.AdapterModuleNotFound = void 0;
const tsPaths = require("tsconfig-paths");
const fs = require("fs");
const path = require("path");
class AdapterModuleNotFound extends Error {
}
exports.AdapterModuleNotFound = AdapterModuleNotFound;
function load(moduleMainFilePath, alias, tsConfigPath) {
var _a;
let baseUrl;
try {
const tsConfig = JSON.parse(fs.readFileSync(tsConfigPath !== null && tsConfigPath !== void 0 ? tsConfigPath : 'tsconfig.json', {
encoding: 'utf-8'
}));
baseUrl = (_a = tsConfig.compilerOptions.baseUrl) !== null && _a !== void 0 ? _a : '.';
}
catch (_b) {
baseUrl = '.';
}
if (baseUrl !== '.') {
throw new Error('tsConfig.compilerOptions.baseUrl is not supported at this moment.');
}
let mainFile;
if (path.isAbsolute(moduleMainFilePath)) {
if (!fs.existsSync(moduleMainFilePath)) {
throw new Error(`Absolute path '${moduleMainFilePath}' does not exist.`);
}
mainFile = sanitizeModuleMainFilePath(moduleMainFilePath);
}
else {
for (const nodeModulesPath of module.paths) {
const filePath = path.join(nodeModulesPath, moduleMainFilePath);
if (fs.existsSync(filePath)) {
mainFile = sanitizeModuleMainFilePath(filePath);
break;
}
}
if (mainFile === undefined) {
throw new AdapterModuleNotFound(`Could not find "${moduleMainFilePath}" in following node_modules:\n${module.paths.join('\n')}`);
}
}
const paths = {
[alias]: [path.relative(process.cwd(), mainFile)]
};
console.log(`Created aliases:\n${Object.keys(paths).map((key) => `${key} => ${paths[key].join(' | ')}`).join('\n')}`);
return tsPaths.register({
baseUrl,
paths
});
}
exports.load = load;
function sanitizeModuleMainFilePath(filePath) {
return filePath.endsWith('.js') ? filePath.slice(0, -3) : filePath;
}
//# sourceMappingURL=common.js.map