diff --git a/__tests__/mergeAxeResults.test.ts b/__tests__/mergeAxeResults.test.ts index 5f1110a6..19a19311 100644 --- a/__tests__/mergeAxeResults.test.ts +++ b/__tests__/mergeAxeResults.test.ts @@ -34,7 +34,7 @@ const { createFilenames, createFinalResultsInJson, } = require('../__mocks__/mockFunctions'); -const { getCurrentDate, getFormattedTime } = require('../utils'); +const { getCurrentDate, getFormattedTime } = require('../src/utils/index.js'); const { consoleLogger, silentLogger } = require('../logs'); let randomToken; diff --git a/__tests__/utils.test.ts b/__tests__/utils.test.ts index d64a5817..db505088 100644 --- a/__tests__/utils.test.ts +++ b/__tests__/utils.test.ts @@ -7,7 +7,7 @@ import { validateUrl, getStoragePath, setHeadlessMode, -} from '../utils.js'; +} from '../src/utils/index.js'; describe('test setting of threshold warn level', () => { const OLD_ENV = process.env; diff --git a/src/cli.ts b/src/cli.ts index 00219933..ad08c0a6 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -5,7 +5,13 @@ import printMessage from 'print-message'; import { devices } from 'playwright'; import { fileURLToPath } from 'url'; import path from 'path'; -import { setHeadlessMode, getVersion, getStoragePath, listenForCleanUp, cleanUpAndExit } from './utils.js'; +import { + listenForCleanUp, + cleanUpAndExit, + getStoragePath, + getVersion, + setHeadlessMode, +} from './utils/index.js'; import { checkUrl, prepareData, diff --git a/src/combine.ts b/src/combine.ts index 1ff7958d..4c7a4249 100644 --- a/src/combine.ts +++ b/src/combine.ts @@ -5,7 +5,12 @@ import crawlDomain from './crawlers/crawlDomain.js'; import crawlLocalFile from './crawlers/crawlLocalFile.js'; import crawlIntelligentSitemap from './crawlers/crawlIntelligentSitemap.js'; import generateArtifacts from './mergeAxeResults.js'; -import { getHost, createAndUpdateResultsFolders, cleanUpAndExit, getStoragePath } from './utils.js'; +import { + cleanUpAndExit, + createAndUpdateResultsFolders, + getHost, + getStoragePath, +} from './utils/index.js'; import { ScannerTypes, UrlsCrawled } from './constants/constants.js'; import { getBlackListedPatterns, submitForm } from './constants/common.js'; import { consoleLogger, silentLogger } from './logs.js'; @@ -328,4 +333,4 @@ const combineRun = async (details: Data, deviceToScan: string) => { } }; -export default combineRun; \ No newline at end of file +export default combineRun; diff --git a/src/constants/cliFunctions.ts b/src/constants/cliFunctions.ts index e85f6f1e..69113399 100644 --- a/src/constants/cliFunctions.ts +++ b/src/constants/cliFunctions.ts @@ -1,7 +1,7 @@ import { Options } from 'yargs'; import printMessage from 'print-message'; import { BrowserTypes, RuleFlags, ScannerTypes } from './constants.js'; -import { cleanUpAndExit } from '../utils.js'; +import { cleanUpAndExit } from '../utils/index.js'; export const messageOptions = { border: false, @@ -342,4 +342,3 @@ To obtain the JSON files, you need to base64-decode the file followed by gunzip. coerce: val => Number(val), }, }; - diff --git a/src/constants/common.ts b/src/constants/common.ts index d21609b8..51e7ff49 100644 --- a/src/constants/common.ts +++ b/src/constants/common.ts @@ -33,7 +33,8 @@ import constants, { } from './constants.js'; import { consoleLogger } from '../logs.js'; import { isUrlPdf } from '../crawlers/commonCrawlerFunc.js'; -import { cleanUpAndExit, randomThreeDigitNumberString, register } from '../utils.js'; +import { randomThreeDigitNumberString } from '../utils/index.js'; +import { cleanUpAndExit, register } from '../utils/index.js'; import { Answers, Data } from '../index.js'; import { DeviceDescriptor } from '../types/types.js'; import { getProxyInfo, proxyInfoToResolution, ProxySettings } from '../proxyService.js'; diff --git a/src/constants/constants.ts b/src/constants/constants.ts index 4d084bf3..ca8959e5 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -361,7 +361,7 @@ export const sitemapPaths = [ '/sitemap_index.xml.xz', ]; -// Remember to update getWcagPassPercentage() in src/utils/utils.ts if you change this +// Remember to update getWcagPassPercentage() in src/utils/wcagProgress.ts if you change this const wcagLinks = { 'WCAG 1.1.1': 'https://www.w3.org/TR/WCAG22/#non-text-content', 'WCAG 1.2.2': 'https://www.w3.org/TR/WCAG22/#captions-prerecorded', diff --git a/src/constants/questions.ts b/src/constants/questions.ts index 134fa84d..dc33b31f 100644 --- a/src/constants/questions.ts +++ b/src/constants/questions.ts @@ -1,6 +1,6 @@ import { Question } from 'inquirer'; import { Answers } from '../index.js'; -import { getUserDataTxt, randomThreeDigitNumberString, setHeadlessMode } from '../utils.js'; +import { getUserDataTxt, randomThreeDigitNumberString, setHeadlessMode } from '../utils/index.js'; import { checkUrl, getBrowserToRun, diff --git a/src/crawlers/commonCrawlerFunc.ts b/src/crawlers/commonCrawlerFunc.ts index c93780b5..dd32abc8 100644 --- a/src/crawlers/commonCrawlerFunc.ts +++ b/src/crawlers/commonCrawlerFunc.ts @@ -22,7 +22,7 @@ import { flagUnlabelledClickableElements } from './custom/flagUnlabelledClickabl import xPathToCss from './custom/xPathToCss.js'; import type { Response as PlaywrightResponse } from 'playwright'; import fs from 'fs'; -import { getStoragePath } from '../utils.js'; +import { getStoragePath } from '../utils/index.js'; import path from 'path'; // types diff --git a/src/crawlers/crawlDomain.ts b/src/crawlers/crawlDomain.ts index 065d43b2..09fa0971 100644 --- a/src/crawlers/crawlDomain.ts +++ b/src/crawlers/crawlDomain.ts @@ -32,7 +32,7 @@ import { getUrlsFromRobotsTxt, waitForPageLoaded, } from '../constants/common.js'; -import { areLinksEqual, isFollowStrategy, register } from '../utils.js'; +import { areLinksEqual, isFollowStrategy, register } from '../utils/index.js'; import { handlePdfDownload, runPdfScan, diff --git a/src/crawlers/crawlIntelligentSitemap.ts b/src/crawlers/crawlIntelligentSitemap.ts index 9bc4d3a9..df259683 100644 --- a/src/crawlers/crawlIntelligentSitemap.ts +++ b/src/crawlers/crawlIntelligentSitemap.ts @@ -8,7 +8,7 @@ import crawlDomain from './crawlDomain.js'; import crawlSitemap from './crawlSitemap.js'; import { ViewportSettingsClass } from '../combine.js'; import { getPlaywrightLaunchOptions } from '../constants/common.js'; -import { register } from '../utils.js'; +import { register } from '../utils/index.js'; const crawlIntelligentSitemap = async ( url: string, diff --git a/src/crawlers/crawlLocalFile.ts b/src/crawlers/crawlLocalFile.ts index b00e7f5b..af0bda54 100644 --- a/src/crawlers/crawlLocalFile.ts +++ b/src/crawlers/crawlLocalFile.ts @@ -19,7 +19,7 @@ import { import { runPdfScan, mapPdfScanResults, doPdfScreenshots } from './pdfScanFunc.js'; import { guiInfoLog } from '../logs.js'; import crawlSitemap from './crawlSitemap.js'; -import { getPdfStoragePath, getStoragePath, register } from '../utils.js'; +import { getPdfStoragePath, register } from '../utils/index.js'; export const crawlLocalFile = async ({ url, diff --git a/src/crawlers/crawlSitemap.ts b/src/crawlers/crawlSitemap.ts index 3f5c3fae..64f0c375 100644 --- a/src/crawlers/crawlSitemap.ts +++ b/src/crawlers/crawlSitemap.ts @@ -23,7 +23,7 @@ import { waitForPageLoaded, isFilePath, } from '../constants/common.js'; -import { areLinksEqual, isWhitelistedContentType, register } from '../utils.js'; +import { areLinksEqual, isWhitelistedContentType, register } from '../utils/index.js'; import { handlePdfDownload, runPdfScan, @@ -447,4 +447,4 @@ const crawlSitemap = async ({ return { urlsCrawled, durationExceeded }; }; -export default crawlSitemap; \ No newline at end of file +export default crawlSitemap; diff --git a/src/crawlers/pdfScanFunc.ts b/src/crawlers/pdfScanFunc.ts index 66fe86b8..a29279a0 100644 --- a/src/crawlers/pdfScanFunc.ts +++ b/src/crawlers/pdfScanFunc.ts @@ -15,7 +15,7 @@ import constants, { STATUS_CODE_METADATA, UrlsCrawled, } from '../constants/constants.js'; -import { cleanUpAndExit, getPdfStoragePath, getStoragePath } from '../utils.js'; +import { cleanUpAndExit, getPdfStoragePath, getStoragePath } from '../utils/index.js'; import { error } from 'console'; const require = createRequire(import.meta.url); diff --git a/src/crawlers/runCustom.ts b/src/crawlers/runCustom.ts index 0a08d006..81cff149 100644 --- a/src/crawlers/runCustom.ts +++ b/src/crawlers/runCustom.ts @@ -1,7 +1,7 @@ /* eslint-env browser */ import { chromium } from 'playwright'; import { createCrawleeSubFolders } from './commonCrawlerFunc.js'; -import { cleanUpAndExit, register, registerSoftClose } from '../utils.js'; +import { cleanUpAndExit, register, registerSoftClose } from '../utils/index.js'; import constants, { getIntermediateScreenshotsPath, guiInfoStatusTypes, diff --git a/src/index.ts b/src/index.ts index 76529731..8c0bcf6f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,12 +3,12 @@ import printMessage from 'print-message'; import inquirer from 'inquirer'; import { EnqueueStrategy } from 'crawlee'; import { - getVersion, - getUserDataTxt, - writeToUserDataTxt, listenForCleanUp, cleanUpAndExit, -} from './utils.js'; + getUserDataTxt, + getVersion, + writeToUserDataTxt, +} from './utils/index.js'; import { prepareData, messageOptions, diff --git a/src/mergeAxeResults.ts b/src/mergeAxeResults.ts index d7575898..607c68db 100644 --- a/src/mergeAxeResults.ts +++ b/src/mergeAxeResults.ts @@ -26,19 +26,19 @@ import constants, { import { getBrowserToRun, getPlaywrightLaunchOptions } from './constants/common.js'; import { + categorizeWcagCriteria, createScreenshotsFolder, getStoragePath, + getUserDataTxt, getVersion, + getWcagCriteriaMap, getWcagPassPercentage, getProgressPercentage, - retryFunction, - zipResults, getIssuesPercentage, - getWcagCriteriaMap, - categorizeWcagCriteria, - getUserDataTxt, register, -} from './utils.js'; + retryFunction, + zipResults, +} from './utils/index.js'; import { consoleLogger, silentLogger } from './logs.js'; import itemTypeDescription from './constants/itemTypeDescription.js'; import { oobeeAiHtmlETL, oobeeAiRules } from './constants/oobeeAi.js'; @@ -182,7 +182,9 @@ const parseContentToJson = async (rPath: string) => { } consoleLogger.error(`[parseContentToJson] Failed to parse file: ${rPath}`); - consoleLogger.error(`[parseContentToJson] ${parseError?.name || 'Error'}: ${parseError?.message || parseError}`); + consoleLogger.error( + `[parseContentToJson] ${parseError?.name || 'Error'}: ${parseError?.message || parseError}`, + ); if (position !== null) { consoleLogger.error(`[parseContentToJson] JSON parse position: ${position}`); } @@ -416,12 +418,14 @@ const writeHTML = async ( const scanItemsWithHtmlGroupRefs = convertItemsToReferences(allIssues); // Write the lighter items to a file and get the base64 path - const { jsonFilePath: scanItemsWithHtmlGroupRefsJsonFilePath, base64FilePath: scanItemsWithHtmlGroupRefsBase64FilePath } = - await writeJsonFileAndCompressedJsonFile( - scanItemsWithHtmlGroupRefs.items, - storagePath, - 'scanItems-light', - ); + const { + jsonFilePath: scanItemsWithHtmlGroupRefsJsonFilePath, + base64FilePath: scanItemsWithHtmlGroupRefsBase64FilePath, + } = await writeJsonFileAndCompressedJsonFile( + scanItemsWithHtmlGroupRefs.items, + storagePath, + 'scanItems-light', + ); return new Promise((resolve, reject) => { const scanDetailsReadStream = fs.createReadStream(scanDetailsFilePath, { @@ -448,7 +452,7 @@ const writeHTML = async ( outputStream.write(prefixData); // For Proxied AI environments only - outputStream.write(`let proxyUrl = "${process.env.PROXY_API_BASE_URL || ""}"\n`); + outputStream.write(`let proxyUrl = "${process.env.PROXY_API_BASE_URL || ''}"\n`); // Initialize GenAI feature flag outputStream.write(` @@ -478,17 +482,15 @@ const writeHTML = async ( } \n`); - outputStream.write( - "\n\n\n\n\n"); + outputStream.write('\n'); // Write scanItems in 2MB chunks using a stream to avoid loading entire file into memory try { @@ -499,11 +501,13 @@ const writeHTML = async ( }); for await (const chunk of scanItemsStream) { - outputStream.write(`\n`); + outputStream.write( + `\n`, + ); chunkIndex++; } - outputStream.write("