From 57f133adfe975fddef368fb28fdcf5005b7eafbb Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 30 Dec 2021 09:11:32 -0600 Subject: [PATCH] fix: add fallback for Mac arm64 --- .github/workflows/CI.yml | 2 +- src/node/lib.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index bd8b69e..fd7ed67 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -14,7 +14,7 @@ jobs: - windows-latest - macos-latest - ubuntu-latest - - macos-11 # arm64 + # - macos-11 # arm64 d: - "ldc-1.28.0" node: diff --git a/src/node/lib.ts b/src/node/lib.ts index c252b24..8c91c5b 100644 --- a/src/node/lib.ts +++ b/src/node/lib.ts @@ -1,4 +1,5 @@ import { execFile } from "child_process" +import { readFile, writeFile } from "fs/promises"; import { join } from "path" /** @@ -10,6 +11,17 @@ import { join } from "path" * @throws {Promise} The promise is rejected with the reason for failure */ export async function minifyFiles(files: string[], hasComment = false): Promise { + if (process.platform === "darwin" && process.arch === "arm64") { + // fallback to jasonminify due to missing ARM64 binaries + // eslint-disable-next-line @typescript-eslint/no-var-requires + const jsonminify = require("jsonminify"); + files.map(async (file) => { + const jsonString = await readFile(file, 'utf8'); + const minifiedJsonString = jsonminify(jsonString) as string; + await writeFile(file, minifiedJsonString); + }) + } + const filesNum = files.length if (filesNum === 0) { return Promise.resolve()