rebase-path.js 694 B

1234567891011121314151617181920212223
  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. const upath = require('upath');
  9. module.exports = ({
  10. baseDirectory,
  11. file
  12. }) => {
  13. // The initial path is relative to the current directory, so make it absolute.
  14. const absolutePath = upath.resolve(file); // Convert the absolute path so that it's relative to the baseDirectory.
  15. const relativePath = upath.relative(baseDirectory, absolutePath); // Remove any leading ./ as it won't work in a glob pattern.
  16. const normalizedPath = upath.normalize(relativePath);
  17. return normalizedPath;
  18. };