verifyAndLint.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.verifyAndLint = verifyAndLint;
  6. var _chalk = _interopRequireDefault(require("next/dist/compiled/chalk"));
  7. var _jestWorker = require("next/dist/compiled/jest-worker");
  8. var _fs = require("fs");
  9. var _path = require("path");
  10. var _constants = require("./constants");
  11. var _events = require("../telemetry/events");
  12. var _compileError = require("./compile-error");
  13. var _isError = _interopRequireDefault(require("./is-error"));
  14. function _interopRequireDefault(obj) {
  15. return obj && obj.__esModule ? obj : {
  16. default: obj
  17. };
  18. }
  19. async function verifyAndLint(dir, cacheLocation, configLintDirs, numWorkers, enableWorkerThreads, telemetry, hasAppDir) {
  20. try {
  21. const lintWorkers = new _jestWorker.Worker(require.resolve("./eslint/runLintCheck"), {
  22. numWorkers,
  23. enableWorkerThreads,
  24. maxRetries: 0
  25. });
  26. lintWorkers.getStdout().pipe(process.stdout);
  27. lintWorkers.getStderr().pipe(process.stderr);
  28. const lintDirs = (configLintDirs != null ? configLintDirs : _constants.ESLINT_DEFAULT_DIRS).reduce((res, d)=>{
  29. const currDir = (0, _path).join(dir, d);
  30. if (!(0, _fs).existsSync(currDir)) return res;
  31. res.push(currDir);
  32. return res;
  33. }, []);
  34. const lintResults = await lintWorkers.runLintCheck(dir, lintDirs, {
  35. hasAppDir,
  36. lintDuringBuild: true,
  37. eslintOptions: {
  38. cacheLocation
  39. }
  40. });
  41. const lintOutput = typeof lintResults === "string" ? lintResults : lintResults == null ? void 0 : lintResults.output;
  42. if (typeof lintResults !== "string" && (lintResults == null ? void 0 : lintResults.eventInfo)) {
  43. telemetry.record((0, _events).eventLintCheckCompleted({
  44. ...lintResults.eventInfo,
  45. buildLint: true
  46. }));
  47. }
  48. if (typeof lintResults !== "string" && (lintResults == null ? void 0 : lintResults.isError) && lintOutput) {
  49. await telemetry.flush();
  50. throw new _compileError.CompileError(lintOutput);
  51. }
  52. if (lintOutput) {
  53. console.log(lintOutput);
  54. }
  55. lintWorkers.end();
  56. } catch (err) {
  57. if ((0, _isError).default(err)) {
  58. if (err.type === "CompileError" || err instanceof _compileError.CompileError) {
  59. console.error(_chalk.default.red("\nFailed to compile."));
  60. console.error(err.message);
  61. process.exit(1);
  62. } else if (err.type === "FatalError") {
  63. console.error(err.message);
  64. process.exit(1);
  65. }
  66. }
  67. throw err;
  68. }
  69. }
  70. //# sourceMappingURL=verifyAndLint.js.map