File size: 5,878 Bytes
fea495a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "nextLint", {
    enumerable: true,
    get: function() {
        return nextLint;
    }
});
const _fs = require("fs");
const _path = require("path");
const _config = /*#__PURE__*/ _interop_require_default(require("../server/config"));
const _utils = require("../server/lib/utils");
const _storage = require("../telemetry/storage");
const _picocolors = require("../lib/picocolors");
const _constants = require("../lib/constants");
const _runLintCheck = require("../lib/eslint/runLintCheck");
const _compileerror = require("../lib/compile-error");
const _constants1 = require("../shared/lib/constants");
const _events = require("../telemetry/events");
const _getprojectdir = require("../lib/get-project-dir");
const _findpagesdir = require("../lib/find-pages-dir");
const _verifytypescriptsetup = require("../lib/verify-typescript-setup");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
const eslintOptions = (options, defaultCacheLocation)=>({
        overrideConfigFile: options.config || null,
        extensions: options.ext ?? [],
        resolvePluginsRelativeTo: options.resolvePluginsRelativeTo || null,
        rulePaths: options.rulesdir ?? [],
        fix: options.fix ?? false,
        fixTypes: options.fixType ?? null,
        ignorePath: options.ignorePath || null,
        ignore: options.ignore,
        allowInlineConfig: options.inlineConfig,
        reportUnusedDisableDirectives: options.reportUnusedDisableDirectivesSeverity || null,
        cache: options.cache,
        cacheLocation: options.cacheLocation || defaultCacheLocation,
        cacheStrategy: options.cacheStrategy,
        errorOnUnmatchedPattern: options.errorOnUnmatchedPattern ?? false
    });
const nextLint = async (options, directory)=>{
    var _nextConfig_eslint;
    // Show deprecation warning
    console.warn((0, _picocolors.yellow)('`next lint` is deprecated and will be removed in Next.js 16.\n') + 'For new projects, use ' + (0, _picocolors.bold)('create-next-app') + ' to choose your preferred linter.\n' + 'For existing projects, migrate to the ESLint CLI:\n' + (0, _picocolors.bold)('npx @next/codemod@canary next-lint-to-eslint-cli .') + '\n');
    const baseDir = (0, _getprojectdir.getProjectDir)(directory);
    // Check if the provided directory exists
    if (!(0, _fs.existsSync)(baseDir)) {
        (0, _utils.printAndExit)(`> No such directory exists as the project root: ${baseDir}`);
    }
    const nextConfig = await (0, _config.default)(_constants1.PHASE_PRODUCTION_BUILD, baseDir);
    const files = options.file ?? [];
    const dirs = options.dir ?? ((_nextConfig_eslint = nextConfig.eslint) == null ? void 0 : _nextConfig_eslint.dirs);
    const filesToLint = [
        ...dirs ?? [],
        ...files
    ];
    const pathsToLint = (filesToLint.length ? filesToLint : _constants.ESLINT_DEFAULT_DIRS).reduce((res, d)=>{
        const currDir = (0, _path.isAbsolute)(d) ? d : (0, _path.join)(baseDir, d);
        if (!(0, _fs.existsSync)(currDir)) {
            return res;
        }
        res.push(currDir);
        return res;
    }, []);
    const reportErrorsOnly = Boolean(options.quiet);
    const maxWarnings = options.maxWarnings;
    const formatter = options.format || null;
    const strict = Boolean(options.strict);
    const outputFile = options.outputFile || null;
    const distDir = (0, _path.join)(baseDir, nextConfig.distDir);
    const defaultCacheLocation = (0, _path.join)(distDir, 'cache', 'eslint/');
    const { pagesDir, appDir } = (0, _findpagesdir.findPagesDir)(baseDir);
    await (0, _verifytypescriptsetup.verifyTypeScriptSetup)({
        dir: baseDir,
        distDir: nextConfig.distDir,
        intentDirs: [
            pagesDir,
            appDir
        ].filter(Boolean),
        typeCheckPreflight: false,
        tsconfigPath: nextConfig.typescript.tsconfigPath,
        disableStaticImages: nextConfig.images.disableStaticImages,
        hasAppDir: !!appDir,
        hasPagesDir: !!pagesDir
    });
    (0, _runLintCheck.runLintCheck)(baseDir, pathsToLint, {
        lintDuringBuild: false,
        eslintOptions: eslintOptions(options, defaultCacheLocation),
        reportErrorsOnly,
        maxWarnings,
        formatter,
        outputFile,
        strict
    }).then(async (lintResults)=>{
        const lintOutput = typeof lintResults === 'string' ? lintResults : lintResults == null ? void 0 : lintResults.output;
        if (typeof lintResults !== 'string' && (lintResults == null ? void 0 : lintResults.eventInfo)) {
            const telemetry = new _storage.Telemetry({
                distDir
            });
            telemetry.record((0, _events.eventLintCheckCompleted)({
                ...lintResults.eventInfo,
                buildLint: false
            }));
            await telemetry.flush();
        }
        if (typeof lintResults !== 'string' && (lintResults == null ? void 0 : lintResults.isError) && lintOutput) {
            throw Object.defineProperty(new _compileerror.CompileError(lintOutput), "__NEXT_ERROR_CODE", {
                value: "E394",
                enumerable: false,
                configurable: true
            });
        }
        if (lintOutput) {
            (0, _utils.printAndExit)(lintOutput, 0);
        } else if (lintResults && !lintOutput) {
            (0, _utils.printAndExit)((0, _picocolors.green)('✔ No ESLint warnings or errors'), 0);
        } else {
            // this makes sure we exit 1 after the error from line 116
            // in packages/next/src/lib/eslint/runLintCheck
            process.exit(1);
        }
    }).catch((err)=>{
        (0, _utils.printAndExit)(err.message);
    });
};

//# sourceMappingURL=next-lint.js.map