From bd485b6bd12c87d0f7cf3532cc0b06c7ccdfb5db Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Wed, 28 Apr 2021 13:43:02 +0500 Subject: [PATCH 1/2] Add workaround to fix BOM-related error during parsing global.json --- src/setup-dotnet.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index ec804eb..9613476 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -20,7 +20,8 @@ export async function run() { const globalJsonPath = path.join(process.cwd(), 'global.json'); if (fs.existsSync(globalJsonPath)) { const globalJson = JSON.parse( - fs.readFileSync(globalJsonPath, {encoding: 'utf8'}) + // .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649 + fs.readFileSync(globalJsonPath, {encoding: 'utf8'}).trim() ); if (globalJson.sdk && globalJson.sdk.version) { version = globalJson.sdk.version; From 34c59b7d0b3eead847ab3a107acfc0394b3bfa67 Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Wed, 28 Apr 2021 17:29:56 +0500 Subject: [PATCH 2/2] build dist/index.js --- dist/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 798e67e..caedb46 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7829,7 +7829,9 @@ function run() { core.debug('No version found, trying to find version from global.json'); const globalJsonPath = path.join(process.cwd(), 'global.json'); if (fs.existsSync(globalJsonPath)) { - const globalJson = JSON.parse(fs.readFileSync(globalJsonPath, { encoding: 'utf8' })); + const globalJson = JSON.parse( + // .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649 + fs.readFileSync(globalJsonPath, { encoding: 'utf8' }).trim()); if (globalJson.sdk && globalJson.sdk.version) { version = globalJson.sdk.version; }