From d76191b1d946677e9e9ae4e7120c25f04713f407 Mon Sep 17 00:00:00 2001 From: Amin_Khp <1amin.khp@gmail.com> Date: Sat, 7 Mar 2020 21:11:26 +0330 Subject: [PATCH] chore(gatsby-core-utils): port physical cpu count to ts --- ...physical-cpu-count.js => physical-cpu-count.ts} | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) rename packages/gatsby-core-utils/src/{physical-cpu-count.js => physical-cpu-count.ts} (79%) diff --git a/packages/gatsby-core-utils/src/physical-cpu-count.js b/packages/gatsby-core-utils/src/physical-cpu-count.ts similarity index 79% rename from packages/gatsby-core-utils/src/physical-cpu-count.js rename to packages/gatsby-core-utils/src/physical-cpu-count.ts index d6d0bd6b3218b..9455ffacd0833 100644 --- a/packages/gatsby-core-utils/src/physical-cpu-count.js +++ b/packages/gatsby-core-utils/src/physical-cpu-count.ts @@ -1,8 +1,8 @@ // Forked from physical-cpu-count package from npm -const os = require(`os`) -const childProcess = require(`child_process`) +import os from "os" +import childProcess from "child_process" -function exec(command) { +function exec(command: string): string { const output = childProcess.execSync(command, { encoding: `utf8` }) return output } @@ -10,8 +10,8 @@ function exec(command) { /* * Fallback if child process fails to receive CPU count */ -function fallbackToNodeJSCheck() { - const cores = os.cpus().filter(function(cpu, index) { +function fallbackToNodeJSCheck(): number { + const cores = os.cpus().filter((cpu, index) => { const hasHyperthreading = cpu.model.includes(`Intel`) const isOdd = index % 2 === 1 return !hasHyperthreading || isOdd @@ -22,7 +22,7 @@ function fallbackToNodeJSCheck() { const platform = os.platform() -function getPhysicalCpuCount() { +function getPhysicalCpuCount(): number { try { if (platform === `linux`) { const output = exec( @@ -52,4 +52,4 @@ function getPhysicalCpuCount() { return fallbackToNodeJSCheck() } -module.exports = getPhysicalCpuCount() +export default getPhysicalCpuCount()