Skip to content

Commit a2cf0d9

Browse files
path fix
1 parent 09c56bb commit a2cf0d9

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

  • src/tasks/cwv-demo-suggestions-processor

src/tasks/cwv-demo-suggestions-processor/handler.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { isNonEmptyArray } from '@adobe/spacecat-shared-utils';
1414

1515
import fs from 'fs';
1616
import path from 'path';
17-
import { fileURLToPath } from 'url';
1817
import { say } from '../../utils/slack-utils.js';
1918

2019
const TASK_TYPE = 'cwv-demo-suggestions-processor';
@@ -24,9 +23,6 @@ const INP = 'inp';
2423
const DEMO = 'demo';
2524
const MAX_CWV_DEMO_SUGGESTIONS = 2;
2625

27-
const filename = fileURLToPath(import.meta.url);
28-
const dirname = path.dirname(filename);
29-
3026
/**
3127
* CWV thresholds for determining if metrics have issues
3228
*/
@@ -77,9 +73,9 @@ function hasExistingIssues(suggestion) {
7773
*/
7874
function readStaticFile(fileName, logger) {
7975
try {
80-
const filePath = path.resolve(dirname, '../../../static', fileName);
76+
const filePath = path.resolve(process.cwd(), 'static', fileName);
8177
const content = fs.readFileSync(filePath, 'utf-8');
82-
logger.debug(`Successfully read content from ${fileName}`);
78+
logger.debug(`Successfully read content from ${fileName} at ${filePath}`);
8379
return content;
8480
} catch (error) {
8581
logger.error(`Error reading static file ${fileName}: ${error.message}`);
@@ -132,8 +128,8 @@ async function updateSuggestionWithGenericIssues(
132128

133129
let cwvReferenceSuggestions = { lcp: [], cls: [], inp: [] };
134130
try {
135-
const jsonPath = path.resolve(dirname, '../../../static/aem-best-practices.json');
136-
logger.info(`Loading CWV reference suggestions from: ${filename}, ${dirname}, ${jsonPath}`);
131+
const jsonPath = path.resolve(process.cwd(), 'static/aem-best-practices.json');
132+
logger.info(`Loading CWV reference suggestions from: ${jsonPath}`);
137133
const rawData = fs.readFileSync(jsonPath, 'utf-8');
138134
cwvReferenceSuggestions = JSON.parse(rawData);
139135
await say(env, logger, slackContext, `Loaded CWV reference suggestions from: ${jsonPath}`);

0 commit comments

Comments
 (0)