get-project-dir.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.getProjectDir = getProjectDir;
  6. var _fs = _interopRequireDefault(require("fs"));
  7. var _path = _interopRequireDefault(require("path"));
  8. var _commands = require("./commands");
  9. var Log = _interopRequireWildcard(require("../build/output/log"));
  10. var _detectTypo = require("./detect-typo");
  11. function _interopRequireDefault(obj) {
  12. return obj && obj.__esModule ? obj : {
  13. default: obj
  14. };
  15. }
  16. function _getRequireWildcardCache() {
  17. if (typeof WeakMap !== "function") return null;
  18. var cache = new WeakMap();
  19. _getRequireWildcardCache = function() {
  20. return cache;
  21. };
  22. return cache;
  23. }
  24. function _interopRequireWildcard(obj) {
  25. if (obj && obj.__esModule) {
  26. return obj;
  27. }
  28. if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
  29. return {
  30. default: obj
  31. };
  32. }
  33. var cache = _getRequireWildcardCache();
  34. if (cache && cache.has(obj)) {
  35. return cache.get(obj);
  36. }
  37. var newObj = {};
  38. var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
  39. for(var key in obj){
  40. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  41. var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
  42. if (desc && (desc.get || desc.set)) {
  43. Object.defineProperty(newObj, key, desc);
  44. } else {
  45. newObj[key] = obj[key];
  46. }
  47. }
  48. }
  49. newObj.default = obj;
  50. if (cache) {
  51. cache.set(obj, newObj);
  52. }
  53. return newObj;
  54. }
  55. function getProjectDir(dir) {
  56. try {
  57. const resolvedDir = _path.default.resolve(dir || ".");
  58. const realDir = _fs.default.realpathSync.native(resolvedDir);
  59. if (resolvedDir !== realDir && resolvedDir.toLowerCase() === realDir.toLowerCase()) {
  60. Log.warn(`Invalid casing detected for project dir, received ${resolvedDir} actual path ${realDir}, see more info here https://nextjs.org/docs/messages/invalid-project-dir-casing`);
  61. }
  62. return realDir;
  63. } catch (err) {
  64. if (err.code === "ENOENT") {
  65. if (typeof dir === "string") {
  66. const detectedTypo = (0, _detectTypo).detectTypo(dir, Object.keys(_commands.commands));
  67. if (detectedTypo) {
  68. Log.error(`"next ${dir}" does not exist. Did you mean "next ${detectedTypo}"?`);
  69. process.exit(1);
  70. }
  71. }
  72. Log.error(`Invalid project directory provided, no such directory: ${_path.default.resolve(dir || ".")}`);
  73. process.exit(1);
  74. }
  75. throw err;
  76. }
  77. }
  78. //# sourceMappingURL=get-project-dir.js.map