UNPKG

@backstage/backend-plugin-api

Version:

Core API used by Backstage backend plugins

37 lines (33 loc) 1.23 kB
'use strict'; var cliCommon = require('@backstage/cli-common'); var errors = require('@backstage/errors'); var node_path = require('node:path'); const packagePathMocks = /* @__PURE__ */ new Map(); function resolvePackagePath(name, ...paths) { const mockedResolve = packagePathMocks.get(name); if (mockedResolve) { const resolved = mockedResolve(paths); if (resolved) { return resolved; } } const req = typeof __non_webpack_require__ === "undefined" ? require : __non_webpack_require__; return node_path.resolve(req.resolve(`${name}/package.json`), "..", ...paths); } function resolveSafeChildPath(base, path) { const targetPath = node_path.resolve(base, path); if (!cliCommon.isChildPath(base, targetPath)) { throw new errors.NotAllowedError( "Relative path is not allowed to refer to a directory outside its parent" ); } return node_path.resolve(base, path); } Object.defineProperty(exports, "isChildPath", { enumerable: true, get: function () { return cliCommon.isChildPath; } }); exports.packagePathMocks = packagePathMocks; exports.resolvePackagePath = resolvePackagePath; exports.resolveSafeChildPath = resolveSafeChildPath; //# sourceMappingURL=paths.cjs.js.map