From 62facb074104aa3a06e059c0737a8f44a204dd00 Mon Sep 17 00:00:00 2001 From: Lukasz Gornicki Date: Mon, 4 Sep 2023 14:45:27 +0200 Subject: [PATCH] fix: read context file sync way when calling context model (#778) --- .gitignore | 3 +-- package.json | 5 ++--- src/models/Context.ts | 7 +++---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 13feba0d0a3..f1631e26fea 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,5 @@ asyncapi.json asyncapi.yml test/minimaltemplate/__transpiled .vscode - - +oclif.manifest.json spec-examples.zip \ No newline at end of file diff --git a/package.json b/package.json index ab2823b9522..f2287b1264a 100644 --- a/package.json +++ b/package.json @@ -127,7 +127,7 @@ }, "repository": "asyncapi/cli", "scripts": { - "build": "rimraf lib && node scripts/fetch-asyncapi-example.js && tsc && echo \"Build Completed\"", + "build": "rimraf lib && node scripts/fetch-asyncapi-example.js && tsc && oclif manifest && echo \"Build Completed\"", "bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION", "dev": "tsc --watch", "docker:build": "docker build -t asyncapi/cli:latest .", @@ -143,8 +143,7 @@ "pack:tarballs": "oclif pack tarballs -t linux-x64 && npm run pack:rename", "pack:windows": "oclif pack win && npm run pack:rename", "pack:rename": "node scripts/releasePackagesRename.js", - "postpack": "rimraf oclif.manifest.json", - "prepublishOnly": "npm run build && oclif manifest", + "prepublishOnly": "npm run build", "pretest:coverage": "npm run build", "release": "semantic-release", "pretest": "npm run build", diff --git a/src/models/Context.ts b/src/models/Context.ts index 57cf54a63a1..2a85009d52d 100644 --- a/src/models/Context.ts +++ b/src/models/Context.ts @@ -1,4 +1,4 @@ -import { promises as fs, existsSync, lstatSync } from 'fs'; +import { readFileSync, promises as fs, existsSync, lstatSync } from 'fs'; import * as path from 'path'; import * as os from 'os'; @@ -329,9 +329,8 @@ async function getContextFilePath(): Promise { // legitimate context file, then it is considered a legitimate context // file indeed. const fileContent = JSON.parse( - await readFile(currentPathString, { - encoding: 'utf8', - }) + //we do not use await readFile because getContextFilePath cannot be called inside async function + readFileSync(currentPathString, {encoding: 'utf8'}) ); if ( fileContent &&