UNPKG

zephyr-agent

Version:
118 lines (117 loc) • 6.52 kB
"use strict"; var __webpack_require__ = {}; (()=>{ __webpack_require__.n = (module)=>{ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module; __webpack_require__.d(getter, { a: getter }); return getter; }; })(); (()=>{ __webpack_require__.d = (exports1, getters, values)=>{ var define = (defs, kind)=>{ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, { enumerable: true, [kind]: defs[key] }); }; define(getters, "get"); define(values, "value"); }; })(); (()=>{ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop); })(); (()=>{ __webpack_require__.r = (exports1)=>{ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, { value: 'Module' }); Object.defineProperty(exports1, '__esModule', { value: true }); }; })(); var __webpack_exports__ = {}; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { getPackageJson: ()=>getPackageJson }); const external_node_fs_namespaceObject = require("node:fs"); var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject); const external_node_path_namespaceObject = require("node:path"); const external_zephyr_edge_contract_namespaceObject = require("zephyr-edge-contract"); const index_js_namespaceObject = require("../errors/index.js"); const external_logging_index_js_namespaceObject = require("../logging/index.js"); const ze_log_event_js_namespaceObject = require("../logging/ze-log-event.js"); const external_find_nearest_package_json_js_namespaceObject = require("./find-nearest-package-json.js"); const external_ze_util_parse_ze_dependencies_js_namespaceObject = require("./ze-util-parse-ze-dependencies.js"); const external_zephyr_config_js_namespaceObject = require("./zephyr-config.js"); const DEFAULT_PACKAGE_VERSION = '0.0.0'; async function getPackageJson(context, zephyrConfig = (0, external_zephyr_config_js_namespaceObject.getZephyrConfig)(context)) { let startingPath; try { startingPath = context || process.cwd(); if (startingPath && external_node_fs_default().statSync(startingPath).isFile()) startingPath = (0, external_node_path_namespaceObject.resolve)(startingPath, '..'); external_logging_index_js_namespaceObject.ze_log["package"]('getPackageJson searching from path', startingPath); } catch (error) { throw new index_js_namespaceObject.ZephyrError(index_js_namespaceObject.ZeErrors.ERR_PACKAGE_JSON_NOT_FOUND, `Invalid starting path: ${context}. Error: ${error}`); } let nearest_package_json; try { nearest_package_json = await (0, external_find_nearest_package_json_js_namespaceObject.find_nearest_package_json)(startingPath); if (!nearest_package_json) throw new index_js_namespaceObject.ZephyrError(index_js_namespaceObject.ZeErrors.ERR_PACKAGE_JSON_NOT_FOUND, `No package.json found starting from: ${startingPath}`); external_logging_index_js_namespaceObject.ze_log["package"]('Found package.json at', nearest_package_json.path); } catch (error) { if (error instanceof index_js_namespaceObject.ZephyrError) throw error; throw new index_js_namespaceObject.ZephyrError(index_js_namespaceObject.ZeErrors.ERR_PACKAGE_JSON_NOT_FOUND, `Error finding package.json from path: ${startingPath}. Error: ${error}`); } try { const { json, path: packageJsonPath } = nearest_package_json; const parsed_package_json = (0, external_zephyr_edge_contract_namespaceObject.safe_json_parse)(json); if (!parsed_package_json) throw new index_js_namespaceObject.ZephyrError(index_js_namespaceObject.ZeErrors.ERR_PACKAGE_JSON_NOT_VALID, `Invalid JSON in package.json at: ${packageJsonPath}`); if (!parsed_package_json.name) throw new index_js_namespaceObject.ZephyrError(index_js_namespaceObject.ZeErrors.ERR_PACKAGE_JSON_MUST_HAVE_NAME, { path: packageJsonPath, data: { path: packageJsonPath } }); if (!parsed_package_json.version) { parsed_package_json.version = DEFAULT_PACKAGE_VERSION; const warning = new index_js_namespaceObject.ZephyrError(index_js_namespaceObject.ZeErrors.ERR_PACKAGE_JSON_MISSING_VERSION, { path: packageJsonPath, defaultVersion: DEFAULT_PACKAGE_VERSION, data: { path: packageJsonPath, defaultVersion: DEFAULT_PACKAGE_VERSION } }); (0, ze_log_event_js_namespaceObject.logFn)('warn', `${warning.code}: ${warning.message}`); } const zephyr_dependencies = (0, external_zephyr_config_js_namespaceObject.mergeRemoteDependencies)(parsed_package_json['zephyr:dependencies'], zephyrConfig); if (zephyr_dependencies) parsed_package_json.zephyrDependencies = (0, external_ze_util_parse_ze_dependencies_js_namespaceObject.parseZeDependencies)(zephyr_dependencies); else { (0, ze_log_event_js_namespaceObject.logFn)('info', 'No zephyr:dependencies found in package.json, to give you more control over your dependencies, check out our documentation:'); (0, ze_log_event_js_namespaceObject.logFn)('info', 'https://docs.zephyr-cloud.io/features/remote-dependencies'); } external_logging_index_js_namespaceObject.ze_log["package"]('Successfully parsed package.json', { name: parsed_package_json.name, version: parsed_package_json.version, path: packageJsonPath }); return parsed_package_json; } catch (error) { if (error instanceof index_js_namespaceObject.ZephyrError) throw error; throw new index_js_namespaceObject.ZephyrError(index_js_namespaceObject.ZeErrors.ERR_PACKAGE_JSON_NOT_VALID, `Error processing package.json: ${error}`); } } exports.getPackageJson = __webpack_exports__.getPackageJson; for(var __rspack_i in __webpack_exports__)if (-1 === [ "getPackageJson" ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i]; Object.defineProperty(exports, '__esModule', { value: true }); //# sourceMappingURL=ze-util-read-package-json.js.map