rebase-path.js 1017 B

123456789101112131415161718192021222324
  1. "use strict";
  2. /*
  3. Copyright 2019 Google LLC
  4. Use of this source code is governed by an MIT-style
  5. license that can be found in the LICENSE file or at
  6. https://opensource.org/licenses/MIT.
  7. */
  8. var __importDefault = (this && this.__importDefault) || function (mod) {
  9. return (mod && mod.__esModule) ? mod : { "default": mod };
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. exports.rebasePath = void 0;
  13. const upath_1 = __importDefault(require("upath"));
  14. function rebasePath({ baseDirectory, file, }) {
  15. // The initial path is relative to the current directory, so make it absolute.
  16. const absolutePath = upath_1.default.resolve(file);
  17. // Convert the absolute path so that it's relative to the baseDirectory.
  18. const relativePath = upath_1.default.relative(baseDirectory, absolutePath);
  19. // Remove any leading ./ as it won't work in a glob pattern.
  20. const normalizedPath = upath_1.default.normalize(relativePath);
  21. return normalizedPath;
  22. }
  23. exports.rebasePath = rebasePath;