fast_path.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.relative = relative;
  6. exports.resolve = resolve;
  7. function _path() {
  8. const data = _interopRequireDefault(require('path'));
  9. _path = function _path() {
  10. return data;
  11. };
  12. return data;
  13. }
  14. function _interopRequireDefault(obj) {
  15. return obj && obj.__esModule ? obj : {default: obj};
  16. }
  17. /**
  18. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  19. *
  20. * This source code is licensed under the MIT license found in the
  21. * LICENSE file in the root directory of this source tree.
  22. */
  23. // rootDir and filename must be absolute paths (resolved)
  24. function relative(rootDir, filename) {
  25. return filename.indexOf(rootDir + _path().default.sep) === 0
  26. ? filename.substr(rootDir.length + 1)
  27. : _path().default.relative(rootDir, filename);
  28. }
  29. const INDIRECTION_FRAGMENT = '..' + _path().default.sep; // rootDir must be an absolute path and relativeFilename must be simple
  30. // (e.g.: foo/bar or ../foo/bar, but never ./foo or foo/../bar)
  31. function resolve(rootDir, relativeFilename) {
  32. return relativeFilename.indexOf(INDIRECTION_FRAGMENT) === 0
  33. ? _path().default.resolve(rootDir, relativeFilename)
  34. : rootDir + _path().default.sep + relativeFilename;
  35. }