UNPKG

e2ed

Version:

E2E testing framework over Playwright

26 lines (25 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPackageInfo = void 0; const node_path_1 = require("node:path"); const asserts_1 = require("../asserts"); /** * Get information about used installed npm package from dependencies by package name. * If the second argument `packagePath` is given, then we look for the package at this absolute path. */ const getPackageInfo = (packageName, packagePath) => { let pathToSomePackageModule = packagePath ?? require.resolve(packageName); while (pathToSomePackageModule.length > 1) { if (pathToSomePackageModule.endsWith(packageName)) { break; } pathToSomePackageModule = (0, node_path_1.join)(pathToSomePackageModule, '..'); } const definedPackagePath = pathToSomePackageModule; (0, asserts_1.assertValueIsTrue)(definedPackagePath.endsWith(packageName), 'definedPackagePath ends with packageName', { packageName, packagePath }); const packageJsonPath = (0, node_path_1.join)(definedPackagePath, 'package.json'); // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires, import/no-dynamic-require const { version } = require(packageJsonPath); return { packagePath: definedPackagePath, version }; }; exports.getPackageInfo = getPackageInfo;