From 7bd1e443f96172ba7a3b5c821bdb0d62734f7815 Mon Sep 17 00:00:00 2001 From: Sebastian Szewczyk Date: Mon, 25 Sep 2023 20:50:34 +0200 Subject: [PATCH] Debugging read files problems --- .../actions/javascript/authorChecklist/index.js | 14 +++++++++++--- .../authorChecklist/newComponentCategory.js | 14 +++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.github/actions/javascript/authorChecklist/index.js b/.github/actions/javascript/authorChecklist/index.js index 64f166c9709e..92acecf09395 100644 --- a/.github/actions/javascript/authorChecklist/index.js +++ b/.github/actions/javascript/authorChecklist/index.js @@ -202,6 +202,7 @@ const { parse } = __nccwpck_require__(639); const traverse = __nccwpck_require__(5008).default; const _ = __nccwpck_require__(2947); const fs = __nccwpck_require__(5747); +const path = __nccwpck_require__(5622); const CONST = __nccwpck_require__(4097); const items = [ @@ -248,16 +249,23 @@ function detectReactComponent(code) { }; function readFile(filename) { - const path = `./${filename}`; + const filePath = `./${filename}`; try { - return fs.readFileSync(path, 'utf-8'); + console.log('reading', filePath, fs.existsSync('./package.json')); + return fs.readFileSync(filePath, 'utf-8'); } catch (error) { - console.error(`Error reading ${path}`, error); + console.error(`Error reading ${filePath}`, error); } } function detectFunction(changedFiles) { console.log('detectFunction', process.cwd()); + + fs.readdirSync(process.cwd()).forEach(file => { + console.log(file); + }); + + const filteredFiles = _.filter((changedFiles), ({ filename }) => filename.endsWith('.js') || filename.endsWith('.jsx') || filename.endsWith('.ts') || filename.endsWith('.tsx')); return _.some(filteredFiles, ({ filename }) => detectReactComponent(readFile(filename))); } diff --git a/.github/actions/javascript/authorChecklist/newComponentCategory.js b/.github/actions/javascript/authorChecklist/newComponentCategory.js index fe7c2e7597e3..4be84a9515a0 100644 --- a/.github/actions/javascript/authorChecklist/newComponentCategory.js +++ b/.github/actions/javascript/authorChecklist/newComponentCategory.js @@ -2,6 +2,7 @@ const { parse } = require('@babel/parser'); const traverse = require('@babel/traverse').default; const _ = require('underscore'); const fs = require('fs'); +const path = require('path'); const CONST = require('../../../libs/CONST'); const items = [ @@ -48,16 +49,23 @@ function detectReactComponent(code) { }; function readFile(filename) { - const path = `./${filename}`; + const filePath = `./${filename}`; try { - return fs.readFileSync(path, 'utf-8'); + console.log('reading', filePath, fs.existsSync('./package.json')); + return fs.readFileSync(filePath, 'utf-8'); } catch (error) { - console.error(`Error reading ${path}`, error); + console.error(`Error reading ${filePath}`, error); } } function detectFunction(changedFiles) { console.log('detectFunction', process.cwd()); + + fs.readdirSync(process.cwd()).forEach(file => { + console.log(file); + }); + + const filteredFiles = _.filter((changedFiles), ({ filename }) => filename.endsWith('.js') || filename.endsWith('.jsx') || filename.endsWith('.ts') || filename.endsWith('.tsx')); return _.some(filteredFiles, ({ filename }) => detectReactComponent(readFile(filename))); }