From 4a6421b5261d2ebc33281682654361c5c4b2d069 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 25 Sep 2023 20:39:34 +0200 Subject: [PATCH] refactor: avoid direct process usage MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../http-server-pool/express-worker_threads/src/main.ts | 3 ++- .../http-server-pool/fastify-worker_threads/src/main.ts | 3 ++- prepare.js | 4 +++- rollup.config.mjs | 7 ++++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/typescript/http-server-pool/express-worker_threads/src/main.ts b/examples/typescript/http-server-pool/express-worker_threads/src/main.ts index 4f1a4d95..3bef1a8a 100644 --- a/examples/typescript/http-server-pool/express-worker_threads/src/main.ts +++ b/examples/typescript/http-server-pool/express-worker_threads/src/main.ts @@ -1,3 +1,4 @@ +import { exit } from 'node:process' import express, { type Express, type Request, type Response } from 'express' import { requestHandlerPool } from './pool.js' @@ -45,5 +46,5 @@ try { }) } catch (err) { console.error(err) - process.exit(1) + exit(1) } diff --git a/examples/typescript/http-server-pool/fastify-worker_threads/src/main.ts b/examples/typescript/http-server-pool/fastify-worker_threads/src/main.ts index cc647a0f..724836de 100644 --- a/examples/typescript/http-server-pool/fastify-worker_threads/src/main.ts +++ b/examples/typescript/http-server-pool/fastify-worker_threads/src/main.ts @@ -1,5 +1,6 @@ import { dirname, extname, join } from 'node:path' import { fileURLToPath } from 'node:url' +import { exit } from 'node:process' import Fastify from 'fastify' import { fastifyPoolifier } from './fastify-poolifier.js' @@ -43,5 +44,5 @@ try { await fastify.listen({ port }) } catch (err) { fastify.log.error(err) - process.exit(1) + exit(1) } diff --git a/prepare.js b/prepare.js index eef41216..3dcaff37 100644 --- a/prepare.js +++ b/prepare.js @@ -1,4 +1,6 @@ -const isCIEnvironment = process.env.CI != null +const { env } = require('node:process') + +const isCIEnvironment = env.CI != null if (isCIEnvironment === false) { require('husky').install() } diff --git a/rollup.config.mjs b/rollup.config.mjs index aac1c8cd..8f1f2656 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -1,4 +1,5 @@ import * as os from 'node:os' +import { env } from 'node:process' import { dts } from 'rollup-plugin-dts' import terser from '@rollup/plugin-terser' import typescript from '@rollup/plugin-typescript' @@ -20,9 +21,9 @@ const availableParallelism = () => { return availableParallelism } -const isDevelopmentBuild = process.env.BUILD === 'development' -const isAnalyzeBuild = process.env.ANALYZE -const isDocumentationBuild = process.env.DOCUMENTATION +const isDevelopmentBuild = env.BUILD === 'development' +const isAnalyzeBuild = env.ANALYZE +const isDocumentationBuild = env.DOCUMENTATION const maxWorkers = Math.floor(availableParallelism() / 2) -- 2.34.1