From ab4e8129d5c94ff96e6c85d0d2b66a04a052b4e5 Mon Sep 17 00:00:00 2001
From: HelenHuang <LinHuang@pollex.com.tw>
Date: 星期四, 09 六月 2022 15:26:15 +0800
Subject: [PATCH] TODO#139888 嚴選配對 - 文案修改

---
 PAMapp/node_modules/fork-ts-checker-webpack-plugin/lib/eslint-reporter/reporter/EsLintReporter.js |   76 ++++++++++++++++++++++++++++++-------
 1 files changed, 61 insertions(+), 15 deletions(-)

diff --git a/PAMapp/node_modules/fork-ts-checker-webpack-plugin/lib/eslint-reporter/reporter/EsLintReporter.js b/PAMapp/node_modules/fork-ts-checker-webpack-plugin/lib/eslint-reporter/reporter/EsLintReporter.js
index a62b6c5..3f4ffe7 100644
--- a/PAMapp/node_modules/fork-ts-checker-webpack-plugin/lib/eslint-reporter/reporter/EsLintReporter.js
+++ b/PAMapp/node_modules/fork-ts-checker-webpack-plugin/lib/eslint-reporter/reporter/EsLintReporter.js
@@ -13,22 +13,28 @@
 };
 Object.defineProperty(exports, "__esModule", { value: true });
 const EsLintIssueFactory_1 = require("../issue/EsLintIssueFactory");
-const path_1 = require("path");
+const path_1 = __importDefault(require("path"));
+const fs_extra_1 = __importDefault(require("fs-extra"));
 const minimatch_1 = __importDefault(require("minimatch"));
 const glob_1 = __importDefault(require("glob"));
+const isOldCLIEngine = (eslint) => eslint.resolveFileGlobPatterns !== undefined;
 function createEsLintReporter(configuration) {
     // eslint-disable-next-line @typescript-eslint/no-var-requires
-    const { CLIEngine } = require('eslint');
-    const engine = new CLIEngine(configuration.options);
+    const { CLIEngine, ESLint } = require('eslint');
+    const eslint = ESLint
+        ? new ESLint(configuration.options)
+        : new CLIEngine(configuration.options);
     let isInitialRun = true;
     let isInitialGetFiles = true;
     const lintResults = new Map();
-    const includedGlobPatterns = engine.resolveFileGlobPatterns(configuration.files);
+    const includedGlobPatterns = resolveFileGlobPatterns(configuration.files);
     const includedFiles = new Set();
     function isFileIncluded(path) {
-        return (!path.includes('node_modules') &&
-            includedGlobPatterns.some((pattern) => minimatch_1.default(path, pattern)) &&
-            !engine.isPathIgnored(path));
+        return __awaiter(this, void 0, void 0, function* () {
+            return (!path.includes('node_modules') &&
+                includedGlobPatterns.some((pattern) => minimatch_1.default(path, pattern)) &&
+                !(yield eslint.isPathIgnored(path)));
+        });
     }
     function getFiles() {
         return __awaiter(this, void 0, void 0, function* () {
@@ -47,7 +53,7 @@
                 })));
                 for (const resolvedGlob of resolvedGlobs) {
                     for (const resolvedFile of resolvedGlob) {
-                        if (isFileIncluded(resolvedFile)) {
+                        if (yield isFileIncluded(resolvedFile)) {
                             includedFiles.add(resolvedFile);
                         }
                     }
@@ -62,13 +68,40 @@
     function getExtensions() {
         return configuration.options.extensions || [];
     }
+    // Copied from the eslint 6 implementation, as it's not available in eslint 8
+    function resolveFileGlobPatterns(globPatterns) {
+        if (configuration.options.globInputPaths === false) {
+            return globPatterns.filter(Boolean);
+        }
+        const extensions = getExtensions().map((ext) => ext.replace(/^\./u, ''));
+        const dirSuffix = `/**/*.{${extensions.join(',')}}`;
+        return globPatterns.filter(Boolean).map((globPattern) => {
+            const resolvedPath = path_1.default.resolve(configuration.options.cwd || '', globPattern);
+            const newPath = directoryExists(resolvedPath)
+                ? globPattern.replace(/[/\\]$/u, '') + dirSuffix
+                : globPattern;
+            return path_1.default.normalize(newPath).replace(/\\/gu, '/');
+        });
+    }
+    // Copied from the eslint 6 implementation, as it's not available in eslint 8
+    function directoryExists(resolvedPath) {
+        try {
+            return fs_extra_1.default.statSync(resolvedPath).isDirectory();
+        }
+        catch (error) {
+            if (error && error.code === 'ENOENT') {
+                return false;
+            }
+            throw error;
+        }
+    }
     return {
         getReport: ({ changedFiles = [], deletedFiles = [] }) => __awaiter(this, void 0, void 0, function* () {
             return {
                 getDependencies() {
                     return __awaiter(this, void 0, void 0, function* () {
                         for (const changedFile of changedFiles) {
-                            if (isFileIncluded(changedFile)) {
+                            if (yield isFileIncluded(changedFile)) {
                                 includedFiles.add(changedFile);
                             }
                         }
@@ -76,8 +109,8 @@
                             includedFiles.delete(deletedFile);
                         }
                         return {
-                            files: (yield getFiles()).map((file) => path_1.normalize(file)),
-                            dirs: getDirs().map((dir) => path_1.normalize(dir)),
+                            files: (yield getFiles()).map((file) => path_1.default.normalize(file)),
+                            dirs: getDirs().map((dir) => path_1.default.normalize(dir)),
                             excluded: [],
                             extensions: getExtensions(),
                         };
@@ -95,20 +128,33 @@
                         // get reports
                         const lintReports = [];
                         if (isInitialRun) {
-                            lintReports.push(engine.executeOnFiles(includedGlobPatterns));
+                            const lintReport = yield (isOldCLIEngine(eslint)
+                                ? Promise.resolve(eslint.executeOnFiles(includedGlobPatterns))
+                                : eslint.lintFiles(includedGlobPatterns).then((results) => ({ results })));
+                            lintReports.push(lintReport);
                             isInitialRun = false;
                         }
                         else {
                             // we need to take care to not lint files that are not included by the configuration.
                             // the eslint engine will not exclude them automatically
-                            const changedAndIncludedFiles = changedFiles.filter((changedFile) => isFileIncluded(changedFile));
+                            const changedAndIncludedFiles = [];
+                            for (const changedFile of changedFiles) {
+                                if (yield isFileIncluded(changedFile)) {
+                                    changedAndIncludedFiles.push(changedFile);
+                                }
+                            }
                             if (changedAndIncludedFiles.length) {
-                                lintReports.push(engine.executeOnFiles(changedAndIncludedFiles));
+                                const lintReport = yield (isOldCLIEngine(eslint)
+                                    ? Promise.resolve(eslint.executeOnFiles(changedAndIncludedFiles))
+                                    : eslint.lintFiles(changedAndIncludedFiles).then((results) => ({ results })));
+                                lintReports.push(lintReport);
                             }
                         }
                         // output fixes if `fix` option is provided
                         if (configuration.options.fix) {
-                            yield Promise.all(lintReports.map((lintReport) => CLIEngine.outputFixes(lintReport)));
+                            yield Promise.all(lintReports.map((lintReport) => isOldCLIEngine(eslint)
+                                ? CLIEngine.outputFixes(lintReport)
+                                : ESLint.outputFixes(lintReport.results)));
                         }
                         // store results
                         for (const lintReport of lintReports) {

--
Gitblit v1.8.0