find-up.js 820 B

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. /**
  3. * @license
  4. * Copyright Google Inc. All Rights Reserved.
  5. *
  6. * Use of this source code is governed by an MIT-style license that can be
  7. * found in the LICENSE file at https://angular.io/license
  8. */
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. const fs_1 = require("fs");
  11. const path = require("path");
  12. function findUp(names, from) {
  13. if (!Array.isArray(names)) {
  14. names = [names];
  15. }
  16. const root = path.parse(from).root;
  17. let currentDir = from;
  18. while (currentDir && currentDir !== root) {
  19. for (const name of names) {
  20. const p = path.join(currentDir, name);
  21. if (fs_1.existsSync(p)) {
  22. return p;
  23. }
  24. }
  25. currentDir = path.dirname(currentDir);
  26. }
  27. return null;
  28. }
  29. exports.findUp = findUp;