From: Jérôme Benoit Date: Thu, 7 Mar 2024 19:22:06 +0000 (+0100) Subject: refactor: cleanup eslint configuration X-Git-Tag: v3.1.22~13 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=ded253e27e59ae936fe91d789d8454b7eb11dd6a;p=poolifier.git refactor: cleanup eslint configuration Signed-off-by: Jérôme Benoit --- diff --git a/.eslintrc.cjs b/.eslintrc.cjs index f8251b90..713011c5 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -8,10 +8,10 @@ module.exports = defineConfig({ mocha: true }, parserOptions: { - ecmaVersion: 2022, - sourceType: 'module' + sourceType: 'module', + ecmaVersion: 2022 }, - plugins: ['promise', 'spellcheck'], + plugins: ['simple-import-sort', 'promise', 'spellcheck'], extends: [ 'eslint:recommended', 'plugin:import/recommended', @@ -25,13 +25,8 @@ module.exports = defineConfig({ } }, rules: { - 'sort-imports': [ - 'error', - { - ignoreDeclarationSort: true - } - ], - 'import/order': 'error', + 'simple-import-sort/imports': 'error', + 'simple-import-sort/exports': 'error', 'spellcheck/spell-checker': [ 'warn', diff --git a/benchmarks/internal/bench.mjs b/benchmarks/internal/bench.mjs index 88868af7..b59514d2 100644 --- a/benchmarks/internal/bench.mjs +++ b/benchmarks/internal/bench.mjs @@ -1,8 +1,9 @@ import { exit } from 'node:process' + import { + availableParallelism, PoolTypes, - WorkerTypes, - availableParallelism + WorkerTypes } from '../../lib/index.mjs' import { TaskFunctions } from '../benchmarks-types.cjs' import { runPoolifierPoolBenchmark } from '../benchmarks-utils.cjs' diff --git a/benchmarks/internal/thread-worker.mjs b/benchmarks/internal/thread-worker.mjs index 92508dd8..63d6e2de 100644 --- a/benchmarks/internal/thread-worker.mjs +++ b/benchmarks/internal/thread-worker.mjs @@ -1,7 +1,8 @@ import { isMainThread } from 'node:worker_threads' + import { ThreadWorker } from '../../lib/index.mjs' -import { executeTaskFunction } from '../benchmarks-utils.cjs' import { TaskFunctions } from '../benchmarks-types.cjs' +import { executeTaskFunction } from '../benchmarks-utils.cjs' const taskFunction = data => { data = data || {} diff --git a/benchmarks/worker-selection/least.mjs b/benchmarks/worker-selection/least.mjs index f67bebf7..d08bec0e 100644 --- a/benchmarks/worker-selection/least.mjs +++ b/benchmarks/worker-selection/least.mjs @@ -1,5 +1,7 @@ import { randomInt } from 'node:crypto' + import Benchmark from 'benchmark' + import { LIST_FORMATTER } from '../benchmarks-utils.cjs' function generateRandomTasksMap ( diff --git a/benchmarks/worker-selection/round-robin.mjs b/benchmarks/worker-selection/round-robin.mjs index b13c8111..f9d125d7 100644 --- a/benchmarks/worker-selection/round-robin.mjs +++ b/benchmarks/worker-selection/round-robin.mjs @@ -1,4 +1,5 @@ import Benchmark from 'benchmark' + import { LIST_FORMATTER } from '../benchmarks-utils.cjs' function generateWorkersArray (numberOfWorkers) { diff --git a/examples/typescript/http-client-pool/src/main.ts b/examples/typescript/http-client-pool/src/main.ts index 41028e63..722de1e6 100644 --- a/examples/typescript/http-client-pool/src/main.ts +++ b/examples/typescript/http-client-pool/src/main.ts @@ -1,4 +1,5 @@ import { availableParallelism } from 'poolifier' + import { httpClientPool } from './pool.js' import type { WorkerResponse } from './types.js' diff --git a/examples/typescript/http-client-pool/src/pool.ts b/examples/typescript/http-client-pool/src/pool.ts index 673b71b8..6988372e 100644 --- a/examples/typescript/http-client-pool/src/pool.ts +++ b/examples/typescript/http-client-pool/src/pool.ts @@ -1,6 +1,8 @@ -import { fileURLToPath } from 'node:url' import { dirname, extname, join } from 'node:path' -import { DynamicThreadPool, availableParallelism } from 'poolifier' +import { fileURLToPath } from 'node:url' + +import { availableParallelism, DynamicThreadPool } from 'poolifier' + import type { WorkerData, WorkerResponse } from './types.js' const workerFile = join( diff --git a/examples/typescript/http-client-pool/src/types.ts b/examples/typescript/http-client-pool/src/types.ts index 11fe73e8..6db45d5f 100644 --- a/examples/typescript/http-client-pool/src/types.ts +++ b/examples/typescript/http-client-pool/src/types.ts @@ -1,9 +1,10 @@ import type { URL } from 'node:url' + +import type { AxiosRequestConfig } from 'axios' import { type RequestInfo as NodeFetchRequestInfo, type RequestInit as NodeFetchRequestInit } from 'node-fetch' -import type { AxiosRequestConfig } from 'axios' export interface WorkerData { input: URL | RequestInfo | NodeFetchRequestInfo diff --git a/examples/typescript/http-client-pool/src/worker.ts b/examples/typescript/http-client-pool/src/worker.ts index 1e89761f..904279b4 100644 --- a/examples/typescript/http-client-pool/src/worker.ts +++ b/examples/typescript/http-client-pool/src/worker.ts @@ -1,9 +1,10 @@ -import { ThreadWorker } from 'poolifier' +import axios from 'axios' import nodeFetch, { type RequestInfo as NodeFetchRequestInfo, type ResponseInit as NodeFetchRequestInit } from 'node-fetch' -import axios from 'axios' +import { ThreadWorker } from 'poolifier' + import type { WorkerData, WorkerResponse } from './types.js' class HttpClientWorker extends ThreadWorker { diff --git a/examples/typescript/http-server-pool/express-cluster/rollup.config.ts b/examples/typescript/http-server-pool/express-cluster/rollup.config.ts index 2322cd9a..236d018c 100644 --- a/examples/typescript/http-server-pool/express-cluster/rollup.config.ts +++ b/examples/typescript/http-server-pool/express-cluster/rollup.config.ts @@ -1,6 +1,6 @@ import typescript from '@rollup/plugin-typescript' -import del from 'rollup-plugin-delete' import { defineConfig } from 'rollup' +import del from 'rollup-plugin-delete' export default defineConfig({ input: ['./src/main.ts', './src/worker.ts'], diff --git a/examples/typescript/http-server-pool/express-cluster/src/main.ts b/examples/typescript/http-server-pool/express-cluster/src/main.ts index 2184f970..794083cc 100644 --- a/examples/typescript/http-server-pool/express-cluster/src/main.ts +++ b/examples/typescript/http-server-pool/express-cluster/src/main.ts @@ -1,6 +1,8 @@ import { dirname, extname, join } from 'node:path' import { fileURLToPath } from 'node:url' -import { FixedClusterPool, availableParallelism } from 'poolifier' + +import { availableParallelism, FixedClusterPool } from 'poolifier' + import type { WorkerData, WorkerResponse } from './types.js' const workerFile = join( diff --git a/examples/typescript/http-server-pool/express-cluster/src/worker.ts b/examples/typescript/http-server-pool/express-cluster/src/worker.ts index d5756473..e04900ab 100644 --- a/examples/typescript/http-server-pool/express-cluster/src/worker.ts +++ b/examples/typescript/http-server-pool/express-cluster/src/worker.ts @@ -1,7 +1,9 @@ import type { Server } from 'node:http' import type { AddressInfo } from 'node:net' -import { ClusterWorker } from 'poolifier' + import express, { type Express, type Request, type Response } from 'express' +import { ClusterWorker } from 'poolifier' + import type { WorkerData, WorkerResponse } from './types.js' class ExpressWorker extends ClusterWorker { diff --git a/examples/typescript/http-server-pool/express-hybrid/rollup.config.ts b/examples/typescript/http-server-pool/express-hybrid/rollup.config.ts index b4634483..9c29f004 100644 --- a/examples/typescript/http-server-pool/express-hybrid/rollup.config.ts +++ b/examples/typescript/http-server-pool/express-hybrid/rollup.config.ts @@ -1,6 +1,6 @@ import typescript from '@rollup/plugin-typescript' -import del from 'rollup-plugin-delete' import { defineConfig } from 'rollup' +import del from 'rollup-plugin-delete' export default defineConfig({ input: [ diff --git a/examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts b/examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts index 8cc041d4..78a18d67 100644 --- a/examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts +++ b/examples/typescript/http-server-pool/express-hybrid/src/express-worker.ts @@ -1,11 +1,13 @@ import type { Server } from 'node:http' import type { AddressInfo } from 'node:net' + +import express, { type Express, type Request, type Response } from 'express' import { + availableParallelism, ClusterWorker, - DynamicThreadPool, - availableParallelism + DynamicThreadPool } from 'poolifier' -import express, { type Express, type Request, type Response } from 'express' + import { type ClusterWorkerData, type ClusterWorkerResponse, diff --git a/examples/typescript/http-server-pool/express-hybrid/src/main.ts b/examples/typescript/http-server-pool/express-hybrid/src/main.ts index e339f83a..0f96a313 100644 --- a/examples/typescript/http-server-pool/express-hybrid/src/main.ts +++ b/examples/typescript/http-server-pool/express-hybrid/src/main.ts @@ -1,6 +1,8 @@ import { dirname, extname, join } from 'node:path' import { fileURLToPath } from 'node:url' -import { FixedClusterPool, availableParallelism } from 'poolifier' + +import { availableParallelism, FixedClusterPool } from 'poolifier' + import type { ClusterWorkerData, ClusterWorkerResponse } from './types.js' const expressWorkerFile = join( diff --git a/examples/typescript/http-server-pool/express-hybrid/src/request-handler-worker.ts b/examples/typescript/http-server-pool/express-hybrid/src/request-handler-worker.ts index ac4fb97a..d769c762 100644 --- a/examples/typescript/http-server-pool/express-hybrid/src/request-handler-worker.ts +++ b/examples/typescript/http-server-pool/express-hybrid/src/request-handler-worker.ts @@ -1,4 +1,5 @@ import { ThreadWorker } from 'poolifier' + import { type DataPayload, type ThreadWorkerData, 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 3bef1a8a..fc0f2d84 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,5 +1,7 @@ import { exit } from 'node:process' + import express, { type Express, type Request, type Response } from 'express' + import { requestHandlerPool } from './pool.js' /** diff --git a/examples/typescript/http-server-pool/express-worker_threads/src/pool.ts b/examples/typescript/http-server-pool/express-worker_threads/src/pool.ts index 6ae00292..98ae657d 100644 --- a/examples/typescript/http-server-pool/express-worker_threads/src/pool.ts +++ b/examples/typescript/http-server-pool/express-worker_threads/src/pool.ts @@ -1,6 +1,8 @@ import { dirname, extname, join } from 'node:path' import { fileURLToPath } from 'node:url' -import { DynamicThreadPool, availableParallelism } from 'poolifier' + +import { availableParallelism, DynamicThreadPool } from 'poolifier' + import { type BodyPayload, type WorkerData, diff --git a/examples/typescript/http-server-pool/express-worker_threads/src/worker.ts b/examples/typescript/http-server-pool/express-worker_threads/src/worker.ts index 223ee368..c7a64055 100644 --- a/examples/typescript/http-server-pool/express-worker_threads/src/worker.ts +++ b/examples/typescript/http-server-pool/express-worker_threads/src/worker.ts @@ -1,4 +1,5 @@ import { ThreadWorker } from 'poolifier' + import { type BodyPayload, type WorkerData, diff --git a/examples/typescript/http-server-pool/fastify-cluster/rollup.config.ts b/examples/typescript/http-server-pool/fastify-cluster/rollup.config.ts index 5715e280..5e0a32d4 100644 --- a/examples/typescript/http-server-pool/fastify-cluster/rollup.config.ts +++ b/examples/typescript/http-server-pool/fastify-cluster/rollup.config.ts @@ -1,6 +1,6 @@ import typescript from '@rollup/plugin-typescript' -import del from 'rollup-plugin-delete' import { defineConfig } from 'rollup' +import del from 'rollup-plugin-delete' export default defineConfig({ input: ['./src/main.ts', './src/worker.ts'], diff --git a/examples/typescript/http-server-pool/fastify-cluster/src/main.ts b/examples/typescript/http-server-pool/fastify-cluster/src/main.ts index 6fe49eda..c165157a 100644 --- a/examples/typescript/http-server-pool/fastify-cluster/src/main.ts +++ b/examples/typescript/http-server-pool/fastify-cluster/src/main.ts @@ -1,6 +1,8 @@ import { dirname, extname, join } from 'node:path' import { fileURLToPath } from 'node:url' -import { FixedClusterPool, availableParallelism } from 'poolifier' + +import { availableParallelism, FixedClusterPool } from 'poolifier' + import type { WorkerData, WorkerResponse } from './types.js' const workerFile = join( diff --git a/examples/typescript/http-server-pool/fastify-cluster/src/worker.ts b/examples/typescript/http-server-pool/fastify-cluster/src/worker.ts index 5fca8905..8f4442ed 100644 --- a/examples/typescript/http-server-pool/fastify-cluster/src/worker.ts +++ b/examples/typescript/http-server-pool/fastify-cluster/src/worker.ts @@ -1,6 +1,8 @@ import type { AddressInfo } from 'node:net' -import { ClusterWorker } from 'poolifier' + import Fastify, { type FastifyInstance } from 'fastify' +import { ClusterWorker } from 'poolifier' + import type { WorkerData, WorkerResponse } from './types.js' class FastifyWorker extends ClusterWorker { diff --git a/examples/typescript/http-server-pool/fastify-hybrid/@types/fastify/index.d.ts b/examples/typescript/http-server-pool/fastify-hybrid/@types/fastify/index.d.ts index 3ff88aa2..e1a64b15 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/@types/fastify/index.d.ts +++ b/examples/typescript/http-server-pool/fastify-hybrid/@types/fastify/index.d.ts @@ -1,6 +1,8 @@ import type { TransferListItem } from 'node:worker_threads' + import type * as fastify from 'fastify' import type { DynamicThreadPool } from 'poolifier' + import { type ThreadWorkerData, type ThreadWorkerResponse diff --git a/examples/typescript/http-server-pool/fastify-hybrid/rollup.config.ts b/examples/typescript/http-server-pool/fastify-hybrid/rollup.config.ts index da5e1fdb..6bb949aa 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/rollup.config.ts +++ b/examples/typescript/http-server-pool/fastify-hybrid/rollup.config.ts @@ -1,6 +1,6 @@ import typescript from '@rollup/plugin-typescript' -import del from 'rollup-plugin-delete' import { defineConfig } from 'rollup' +import del from 'rollup-plugin-delete' export default defineConfig({ input: [ diff --git a/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-poolifier.ts b/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-poolifier.ts index 3c5e31e3..79d24dc6 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-poolifier.ts +++ b/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-poolifier.ts @@ -1,7 +1,9 @@ import type { TransferListItem } from 'node:worker_threads' -import { DynamicThreadPool, availableParallelism } from 'poolifier' + import type { FastifyPluginCallback } from 'fastify' import fp from 'fastify-plugin' +import { availableParallelism, DynamicThreadPool } from 'poolifier' + import { type FastifyPoolifierOptions, type ThreadWorkerData, diff --git a/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts b/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts index 0f4f6370..8e4713cf 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts +++ b/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts @@ -1,8 +1,10 @@ import type { AddressInfo } from 'node:net' -import { ClusterWorker } from 'poolifier' + import Fastify, { type FastifyInstance } from 'fastify' -import type { ClusterWorkerData, ClusterWorkerResponse } from './types.js' +import { ClusterWorker } from 'poolifier' + import { fastifyPoolifier } from './fastify-poolifier.js' +import type { ClusterWorkerData, ClusterWorkerResponse } from './types.js' class FastifyWorker extends ClusterWorker< ClusterWorkerData, diff --git a/examples/typescript/http-server-pool/fastify-hybrid/src/main.ts b/examples/typescript/http-server-pool/fastify-hybrid/src/main.ts index 6b9c1727..b2174e07 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/src/main.ts +++ b/examples/typescript/http-server-pool/fastify-hybrid/src/main.ts @@ -1,6 +1,8 @@ import { dirname, extname, join } from 'node:path' import { fileURLToPath } from 'node:url' -import { FixedClusterPool, availableParallelism } from 'poolifier' + +import { availableParallelism, FixedClusterPool } from 'poolifier' + import type { ClusterWorkerData, ClusterWorkerResponse } from './types.js' const fastifyWorkerFile = join( diff --git a/examples/typescript/http-server-pool/fastify-hybrid/src/request-handler-worker.ts b/examples/typescript/http-server-pool/fastify-hybrid/src/request-handler-worker.ts index ac4fb97a..d769c762 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/src/request-handler-worker.ts +++ b/examples/typescript/http-server-pool/fastify-hybrid/src/request-handler-worker.ts @@ -1,4 +1,5 @@ import { ThreadWorker } from 'poolifier' + import { type DataPayload, type ThreadWorkerData, diff --git a/examples/typescript/http-server-pool/fastify-worker_threads/@types/fastify/index.d.ts b/examples/typescript/http-server-pool/fastify-worker_threads/@types/fastify/index.d.ts index 93fb69eb..73f8b071 100644 --- a/examples/typescript/http-server-pool/fastify-worker_threads/@types/fastify/index.d.ts +++ b/examples/typescript/http-server-pool/fastify-worker_threads/@types/fastify/index.d.ts @@ -1,6 +1,8 @@ import type { TransferListItem } from 'node:worker_threads' + import type * as fastify from 'fastify' import type { DynamicThreadPool } from 'poolifier' + import type { WorkerData, WorkerResponse } from '../../src/types.ts' declare module 'fastify' { diff --git a/examples/typescript/http-server-pool/fastify-worker_threads/src/fastify-poolifier.ts b/examples/typescript/http-server-pool/fastify-worker_threads/src/fastify-poolifier.ts index cd1909b7..766ef44e 100644 --- a/examples/typescript/http-server-pool/fastify-worker_threads/src/fastify-poolifier.ts +++ b/examples/typescript/http-server-pool/fastify-worker_threads/src/fastify-poolifier.ts @@ -1,7 +1,9 @@ import type { TransferListItem } from 'node:worker_threads' -import { DynamicThreadPool, availableParallelism } from 'poolifier' + import type { FastifyPluginCallback } from 'fastify' import fp from 'fastify-plugin' +import { availableParallelism, DynamicThreadPool } from 'poolifier' + import { type FastifyPoolifierOptions, type WorkerData, 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 724836de..5610bc1d 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,7 +1,9 @@ import { dirname, extname, join } from 'node:path' -import { fileURLToPath } from 'node:url' import { exit } from 'node:process' +import { fileURLToPath } from 'node:url' + import Fastify from 'fastify' + import { fastifyPoolifier } from './fastify-poolifier.js' /** diff --git a/examples/typescript/http-server-pool/fastify-worker_threads/src/worker.ts b/examples/typescript/http-server-pool/fastify-worker_threads/src/worker.ts index 223ee368..c7a64055 100644 --- a/examples/typescript/http-server-pool/fastify-worker_threads/src/worker.ts +++ b/examples/typescript/http-server-pool/fastify-worker_threads/src/worker.ts @@ -1,4 +1,5 @@ import { ThreadWorker } from 'poolifier' + import { type BodyPayload, type WorkerData, diff --git a/examples/typescript/pool.ts b/examples/typescript/pool.ts index 144d5500..c55c4e96 100644 --- a/examples/typescript/pool.ts +++ b/examples/typescript/pool.ts @@ -1,12 +1,14 @@ import { dirname, extname, join } from 'node:path' import { fileURLToPath } from 'node:url' -import type { MyData, MyResponse } from './worker.js' + import { + availableParallelism, DynamicThreadPool, - FixedThreadPool, - availableParallelism + FixedThreadPool } from 'poolifier' +import type { MyData, MyResponse } from './worker.js' + const workerFile = join( dirname(fileURLToPath(import.meta.url)), `worker${extname(fileURLToPath(import.meta.url))}` diff --git a/examples/typescript/smtp-client-pool/src/main.ts b/examples/typescript/smtp-client-pool/src/main.ts index 1b463fa0..620bdb94 100644 --- a/examples/typescript/smtp-client-pool/src/main.ts +++ b/examples/typescript/smtp-client-pool/src/main.ts @@ -1,4 +1,5 @@ import type SMTPTransport from 'nodemailer/lib/smtp-transport/index.js' + import { smtpClientPool } from './pool.js' const tos = ['bar@example.com, baz@example.com'] diff --git a/examples/typescript/smtp-client-pool/src/pool.ts b/examples/typescript/smtp-client-pool/src/pool.ts index 2fc53c98..315bf4ea 100644 --- a/examples/typescript/smtp-client-pool/src/pool.ts +++ b/examples/typescript/smtp-client-pool/src/pool.ts @@ -1,7 +1,9 @@ -import { fileURLToPath } from 'node:url' import { dirname, extname, join } from 'node:path' -import { DynamicThreadPool, availableParallelism } from 'poolifier' +import { fileURLToPath } from 'node:url' + import type SMTPTransport from 'nodemailer/lib/smtp-transport/index.js' +import { availableParallelism, DynamicThreadPool } from 'poolifier' + import type { WorkerData } from './types.js' const workerFile = join( diff --git a/examples/typescript/smtp-client-pool/src/worker.ts b/examples/typescript/smtp-client-pool/src/worker.ts index 01e49b09..62288635 100644 --- a/examples/typescript/smtp-client-pool/src/worker.ts +++ b/examples/typescript/smtp-client-pool/src/worker.ts @@ -1,6 +1,7 @@ -import { ThreadWorker } from 'poolifier' import { createTransport } from 'nodemailer' import type SMTPTransport from 'nodemailer/lib/smtp-transport/index.js' +import { ThreadWorker } from 'poolifier' + import type { WorkerData } from './types.js' class SmtpClientWorker extends ThreadWorker< diff --git a/examples/typescript/websocket-server-pool/ws-cluster/rollup.config.ts b/examples/typescript/websocket-server-pool/ws-cluster/rollup.config.ts index f251709f..a4f72126 100644 --- a/examples/typescript/websocket-server-pool/ws-cluster/rollup.config.ts +++ b/examples/typescript/websocket-server-pool/ws-cluster/rollup.config.ts @@ -1,6 +1,6 @@ import typescript from '@rollup/plugin-typescript' -import del from 'rollup-plugin-delete' import { defineConfig } from 'rollup' +import del from 'rollup-plugin-delete' export default defineConfig({ input: ['./src/main.ts', './src/worker.ts'], diff --git a/examples/typescript/websocket-server-pool/ws-cluster/src/main.ts b/examples/typescript/websocket-server-pool/ws-cluster/src/main.ts index 762b1c0f..34e2a58b 100644 --- a/examples/typescript/websocket-server-pool/ws-cluster/src/main.ts +++ b/examples/typescript/websocket-server-pool/ws-cluster/src/main.ts @@ -1,6 +1,8 @@ import { dirname, extname, join } from 'node:path' import { fileURLToPath } from 'node:url' -import { FixedClusterPool, availableParallelism } from 'poolifier' + +import { availableParallelism, FixedClusterPool } from 'poolifier' + import type { WorkerData, WorkerResponse } from './types.js' const workerFile = join( diff --git a/examples/typescript/websocket-server-pool/ws-cluster/src/worker.ts b/examples/typescript/websocket-server-pool/ws-cluster/src/worker.ts index 18ece026..9ec81eb5 100644 --- a/examples/typescript/websocket-server-pool/ws-cluster/src/worker.ts +++ b/examples/typescript/websocket-server-pool/ws-cluster/src/worker.ts @@ -1,5 +1,6 @@ import { ClusterWorker } from 'poolifier' import { type RawData, WebSocketServer } from 'ws' + import { type DataPayload, type MessagePayload, diff --git a/examples/typescript/websocket-server-pool/ws-hybrid/rollup.config.ts b/examples/typescript/websocket-server-pool/ws-hybrid/rollup.config.ts index 97efb44f..e96f480b 100644 --- a/examples/typescript/websocket-server-pool/ws-hybrid/rollup.config.ts +++ b/examples/typescript/websocket-server-pool/ws-hybrid/rollup.config.ts @@ -1,6 +1,6 @@ import typescript from '@rollup/plugin-typescript' -import del from 'rollup-plugin-delete' import { defineConfig } from 'rollup' +import del from 'rollup-plugin-delete' export default defineConfig({ input: [ diff --git a/examples/typescript/websocket-server-pool/ws-hybrid/src/main.ts b/examples/typescript/websocket-server-pool/ws-hybrid/src/main.ts index b35775b4..9e663899 100644 --- a/examples/typescript/websocket-server-pool/ws-hybrid/src/main.ts +++ b/examples/typescript/websocket-server-pool/ws-hybrid/src/main.ts @@ -1,6 +1,8 @@ import { dirname, extname, join } from 'node:path' import { fileURLToPath } from 'node:url' -import { FixedClusterPool, availableParallelism } from 'poolifier' + +import { availableParallelism, FixedClusterPool } from 'poolifier' + import type { ClusterWorkerData, ClusterWorkerResponse } from './types.js' const webSocketServerWorkerFile = join( diff --git a/examples/typescript/websocket-server-pool/ws-hybrid/src/request-handler-worker.ts b/examples/typescript/websocket-server-pool/ws-hybrid/src/request-handler-worker.ts index ac4fb97a..d769c762 100644 --- a/examples/typescript/websocket-server-pool/ws-hybrid/src/request-handler-worker.ts +++ b/examples/typescript/websocket-server-pool/ws-hybrid/src/request-handler-worker.ts @@ -1,4 +1,5 @@ import { ThreadWorker } from 'poolifier' + import { type DataPayload, type ThreadWorkerData, diff --git a/examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts b/examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts index 4e6529e0..eabf72eb 100644 --- a/examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts +++ b/examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts @@ -1,9 +1,10 @@ import { + availableParallelism, ClusterWorker, - DynamicThreadPool, - availableParallelism + DynamicThreadPool } from 'poolifier' import { type RawData, WebSocketServer } from 'ws' + import { type ClusterWorkerData, type ClusterWorkerResponse, diff --git a/examples/typescript/websocket-server-pool/ws-worker_threads/src/main.ts b/examples/typescript/websocket-server-pool/ws-worker_threads/src/main.ts index d5b2cc78..f3aea4e5 100644 --- a/examples/typescript/websocket-server-pool/ws-worker_threads/src/main.ts +++ b/examples/typescript/websocket-server-pool/ws-worker_threads/src/main.ts @@ -1,6 +1,7 @@ import { type RawData, WebSocketServer } from 'ws' -import { type DataPayload, type MessagePayload, MessageType } from './types.js' + import { requestHandlerPool } from './pool.js' +import { type DataPayload, type MessagePayload, MessageType } from './types.js' const port = 8080 const wss = new WebSocketServer({ port }, () => { diff --git a/examples/typescript/websocket-server-pool/ws-worker_threads/src/pool.ts b/examples/typescript/websocket-server-pool/ws-worker_threads/src/pool.ts index 39cba844..45d458d5 100644 --- a/examples/typescript/websocket-server-pool/ws-worker_threads/src/pool.ts +++ b/examples/typescript/websocket-server-pool/ws-worker_threads/src/pool.ts @@ -1,6 +1,8 @@ import { dirname, extname, join } from 'node:path' import { fileURLToPath } from 'node:url' -import { DynamicThreadPool, availableParallelism } from 'poolifier' + +import { availableParallelism, DynamicThreadPool } from 'poolifier' + import { type DataPayload, type WorkerData, diff --git a/examples/typescript/websocket-server-pool/ws-worker_threads/src/worker.ts b/examples/typescript/websocket-server-pool/ws-worker_threads/src/worker.ts index a3b106c6..5aa9e90a 100644 --- a/examples/typescript/websocket-server-pool/ws-worker_threads/src/worker.ts +++ b/examples/typescript/websocket-server-pool/ws-worker_threads/src/worker.ts @@ -1,4 +1,5 @@ import { ThreadWorker } from 'poolifier' + import { type DataPayload, type WorkerData, diff --git a/package.json b/package.json index 2d278219..50ab2f17 100644 --- a/package.json +++ b/package.json @@ -125,6 +125,7 @@ "eslint-plugin-jsdoc": "^48.2.1", "eslint-plugin-n": "^16.6.2", "eslint-plugin-promise": "^6.1.1", + "eslint-plugin-simple-import-sort": "^12.0.0", "eslint-plugin-spellcheck": "^0.0.20", "eslint-plugin-tsdoc": "^0.2.17", "expect": "^29.7.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dd75fcd7..49b87787 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -74,6 +74,9 @@ devDependencies: eslint-plugin-promise: specifier: ^6.1.1 version: 6.1.1(eslint@8.57.0) + eslint-plugin-simple-import-sort: + specifier: ^12.0.0 + version: 12.0.0(eslint@8.57.0) eslint-plugin-spellcheck: specifier: ^0.0.20 version: 0.0.20(eslint@8.57.0) @@ -2510,6 +2513,14 @@ packages: eslint: 8.57.0 dev: true + /eslint-plugin-simple-import-sort@12.0.0(eslint@8.57.0): + resolution: {integrity: sha512-8o0dVEdAkYap0Cn5kNeklaKcT1nUsa3LITWEuFk3nJifOoD+5JQGoyDUW2W/iPWwBsNBJpyJS9y4je/BgxLcyQ==} + peerDependencies: + eslint: '>=5.0.0' + dependencies: + eslint: 8.57.0 + dev: true + /eslint-plugin-spellcheck@0.0.20(eslint@8.57.0): resolution: {integrity: sha512-GJa6vgzWAYqe0elKADAsiBRrhvqBnKyt7tpFSqlCZJsK2W9+K80oMyHhKolA7vJ13H5RCGs5/KCN+mKUyKoAiA==} peerDependencies: diff --git a/rollup.config.mjs b/rollup.config.mjs index 28d0e3a9..9dcf125d 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -1,12 +1,13 @@ 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' +import { defineConfig } from 'rollup' import analyze from 'rollup-plugin-analyzer' import command from 'rollup-plugin-command' import del from 'rollup-plugin-delete' -import { defineConfig } from 'rollup' +import { dts } from 'rollup-plugin-dts' const availableParallelism = () => { let availableParallelism = 1 diff --git a/src/index.ts b/src/index.ts index eab1ab2b..5b0eb909 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,9 @@ +export type { CircularArray } from './circular-array.js' +export type { Deque, ILinkedListNode } from './deque.js' export type { AbstractPool } from './pools/abstract-pool.js' export { DynamicClusterPool } from './pools/cluster/dynamic.js' -export { FixedClusterPool } from './pools/cluster/fixed.js' export type { ClusterPoolOptions } from './pools/cluster/fixed.js' -export { PoolEvents, PoolTypes } from './pools/pool.js' +export { FixedClusterPool } from './pools/cluster/fixed.js' export type { IPool, PoolEvent, @@ -11,7 +12,25 @@ export type { PoolType, TasksQueueOptions } from './pools/pool.js' -export { WorkerTypes } from './pools/worker.js' +export { PoolEvents, PoolTypes } from './pools/pool.js' +export type { + IWorkerChoiceStrategy, + Measurement, + MeasurementOptions, + MeasurementStatisticsRequirements, + StrategyPolicy, + TaskStatisticsRequirements, + WorkerChoiceStrategy, + WorkerChoiceStrategyOptions +} from './pools/selection-strategies/selection-strategies-types.js' +export { + Measurements, + WorkerChoiceStrategies +} from './pools/selection-strategies/selection-strategies-types.js' +export type { WorkerChoiceStrategyContext } from './pools/selection-strategies/worker-choice-strategy-context.js' +export { DynamicThreadPool } from './pools/thread/dynamic.js' +export type { ThreadPoolOptions } from './pools/thread/fixed.js' +export { FixedThreadPool } from './pools/thread/fixed.js' export type { ErrorHandler, EventHandler, @@ -30,33 +49,19 @@ export type { WorkerType, WorkerUsage } from './pools/worker.js' -export { - Measurements, - WorkerChoiceStrategies -} from './pools/selection-strategies/selection-strategies-types.js' +export { WorkerTypes } from './pools/worker.js' export type { - IWorkerChoiceStrategy, - Measurement, - MeasurementOptions, - MeasurementStatisticsRequirements, - StrategyPolicy, - TaskStatisticsRequirements, - WorkerChoiceStrategy, - WorkerChoiceStrategyOptions -} from './pools/selection-strategies/selection-strategies-types.js' -export type { WorkerChoiceStrategyContext } from './pools/selection-strategies/worker-choice-strategy-context.js' -export { DynamicThreadPool } from './pools/thread/dynamic.js' -export { FixedThreadPool } from './pools/thread/fixed.js' -export type { ThreadPoolOptions } from './pools/thread/fixed.js' + MessageValue, + PromiseResponseWrapper, + Task, + TaskPerformance, + WorkerError, + WorkerStatistics, + Writable +} from './utility-types.js' +export { availableParallelism } from './utils.js' export type { AbstractWorker } from './worker/abstract-worker.js' export { ClusterWorker } from './worker/cluster-worker.js' -export { ThreadWorker } from './worker/thread-worker.js' -export { KillBehaviors } from './worker/worker-options.js' -export type { - KillBehavior, - KillHandler, - WorkerOptions -} from './worker/worker-options.js' export type { TaskAsyncFunction, TaskFunction, @@ -64,15 +69,10 @@ export type { TaskFunctions, TaskSyncFunction } from './worker/task-functions.js' +export { ThreadWorker } from './worker/thread-worker.js' export type { - MessageValue, - PromiseResponseWrapper, - Task, - TaskPerformance, - WorkerError, - WorkerStatistics, - Writable -} from './utility-types.js' -export type { CircularArray } from './circular-array.js' -export type { Deque, ILinkedListNode } from './deque.js' -export { availableParallelism } from './utils.js' + KillBehavior, + KillHandler, + WorkerOptions +} from './worker/worker-options.js' +export { KillBehaviors } from './worker/worker-options.js' diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 6c73f43a..c5ad9cb3 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -1,17 +1,18 @@ +import { AsyncResource } from 'node:async_hooks' import { randomUUID } from 'node:crypto' +import { EventEmitterAsyncResource } from 'node:events' import { performance } from 'node:perf_hooks' import type { TransferListItem } from 'node:worker_threads' -import { EventEmitterAsyncResource } from 'node:events' -import { AsyncResource } from 'node:async_hooks' + import type { MessageValue, PromiseResponseWrapper, Task } from '../utility-types.js' import { + average, DEFAULT_TASK_NAME, EMPTY_FUNCTION, - average, exponentialDelay, isKillBehavior, isPlainObject, @@ -21,8 +22,8 @@ import { round, sleep } from '../utils.js' -import { KillBehaviors } from '../worker/worker-options.js' import type { TaskFunction } from '../worker/task-functions.js' +import { KillBehaviors } from '../worker/worker-options.js' import { type IPool, PoolEvents, @@ -32,13 +33,6 @@ import { PoolTypes, type TasksQueueOptions } from './pool.js' -import type { - IWorker, - IWorkerNode, - WorkerInfo, - WorkerNodeEventDetail, - WorkerType -} from './worker.js' import { Measurements, WorkerChoiceStrategies, @@ -46,8 +40,6 @@ import { type WorkerChoiceStrategyOptions } from './selection-strategies/selection-strategies-types.js' import { WorkerChoiceStrategyContext } from './selection-strategies/worker-choice-strategy-context.js' -import { version } from './version.js' -import { WorkerNode } from './worker-node.js' import { checkFilePath, checkValidTasksQueueOptions, @@ -59,6 +51,15 @@ import { updateWaitTimeWorkerUsage, waitWorkerNodeEvents } from './utils.js' +import { version } from './version.js' +import type { + IWorker, + IWorkerNode, + WorkerInfo, + WorkerNodeEventDetail, + WorkerType +} from './worker.js' +import { WorkerNode } from './worker-node.js' /** * Base class that implements some shared logic for all poolifier pools. diff --git a/src/pools/cluster/dynamic.ts b/src/pools/cluster/dynamic.ts index e8e51947..51d1cbee 100644 --- a/src/pools/cluster/dynamic.ts +++ b/src/pools/cluster/dynamic.ts @@ -1,5 +1,5 @@ -import { checkDynamicPoolSize } from '../utils.js' import { PoolEvents, type PoolType, PoolTypes } from '../pool.js' +import { checkDynamicPoolSize } from '../utils.js' import { type ClusterPoolOptions, FixedClusterPool } from './fixed.js' /** diff --git a/src/pools/cluster/fixed.ts b/src/pools/cluster/fixed.ts index 1fea176c..4a8cb4f1 100644 --- a/src/pools/cluster/fixed.ts +++ b/src/pools/cluster/fixed.ts @@ -1,4 +1,5 @@ import cluster, { type Worker } from 'node:cluster' + import type { MessageValue } from '../../utility-types.js' import { AbstractPool } from '../abstract-pool.js' import { type PoolOptions, type PoolType, PoolTypes } from '../pool.js' diff --git a/src/pools/pool.ts b/src/pools/pool.ts index 73ca3aa1..f6f3de36 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -1,7 +1,12 @@ -import type { TransferListItem, WorkerOptions } from 'node:worker_threads' -import type { EventEmitterAsyncResource } from 'node:events' import type { ClusterSettings } from 'node:cluster' +import type { EventEmitterAsyncResource } from 'node:events' +import type { TransferListItem, WorkerOptions } from 'node:worker_threads' + import type { TaskFunction } from '../worker/task-functions.js' +import type { + WorkerChoiceStrategy, + WorkerChoiceStrategyOptions +} from './selection-strategies/selection-strategies-types.js' import type { ErrorHandler, ExitHandler, @@ -11,10 +16,6 @@ import type { OnlineHandler, WorkerType } from './worker.js' -import type { - WorkerChoiceStrategy, - WorkerChoiceStrategyOptions -} from './selection-strategies/selection-strategies-types.js' /** * Enumeration of pool types. diff --git a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts index ff1d4b08..3618944c 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -1,7 +1,7 @@ import type { IPool } from '../pool.js' import { - DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, - buildWorkerChoiceStrategyOptions + buildWorkerChoiceStrategyOptions, + DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../utils.js' import type { IWorker } from '../worker.js' import type { diff --git a/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts index 6bbcc5f5..b1abe987 100644 --- a/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts @@ -1,6 +1,6 @@ -import type { IWorker } from '../worker.js' import type { IPool } from '../pool.js' import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../utils.js' +import type { IWorker } from '../worker.js' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js' import type { IWorkerChoiceStrategy, diff --git a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts index dfe4d623..f0484778 100644 --- a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts @@ -1,6 +1,6 @@ -import type { IWorker } from '../worker.js' import type { IPool } from '../pool.js' import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../utils.js' +import type { IWorker } from '../worker.js' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js' import type { IWorkerChoiceStrategy, diff --git a/src/pools/selection-strategies/worker-choice-strategy-context.ts b/src/pools/selection-strategies/worker-choice-strategy-context.ts index fc940a2f..f9ddb3a1 100644 --- a/src/pools/selection-strategies/worker-choice-strategy-context.ts +++ b/src/pools/selection-strategies/worker-choice-strategy-context.ts @@ -1,11 +1,11 @@ import type { IPool } from '../pool.js' -import type { IWorker } from '../worker.js' import { getWorkerChoiceStrategyRetries } from '../utils.js' +import type { IWorker } from '../worker.js' import { FairShareWorkerChoiceStrategy } from './fair-share-worker-choice-strategy.js' import { InterleavedWeightedRoundRobinWorkerChoiceStrategy } from './interleaved-weighted-round-robin-worker-choice-strategy.js' import { LeastBusyWorkerChoiceStrategy } from './least-busy-worker-choice-strategy.js' -import { LeastUsedWorkerChoiceStrategy } from './least-used-worker-choice-strategy.js' import { LeastEluWorkerChoiceStrategy } from './least-elu-worker-choice-strategy.js' +import { LeastUsedWorkerChoiceStrategy } from './least-used-worker-choice-strategy.js' import { RoundRobinWorkerChoiceStrategy } from './round-robin-worker-choice-strategy.js' import type { IWorkerChoiceStrategy, diff --git a/src/pools/thread/fixed.ts b/src/pools/thread/fixed.ts index 38dee9f0..78912c2b 100644 --- a/src/pools/thread/fixed.ts +++ b/src/pools/thread/fixed.ts @@ -1,8 +1,9 @@ import { + isMainThread, type TransferListItem, - type Worker, - isMainThread + type Worker } from 'node:worker_threads' + import type { MessageValue } from '../../utility-types.js' import { AbstractPool } from '../abstract-pool.js' import { type PoolOptions, type PoolType, PoolTypes } from '../pool.js' diff --git a/src/pools/utils.ts b/src/pools/utils.ts index ff270982..2c021534 100644 --- a/src/pools/utils.ts +++ b/src/pools/utils.ts @@ -1,22 +1,24 @@ -import { existsSync } from 'node:fs' import cluster, { Worker as ClusterWorker } from 'node:cluster' +import { randomInt } from 'node:crypto' +import { existsSync } from 'node:fs' +import { cpus } from 'node:os' +import { env } from 'node:process' import { SHARE_ENV, Worker as ThreadWorker, type WorkerOptions } from 'node:worker_threads' -import { env } from 'node:process' -import { randomInt } from 'node:crypto' -import { cpus } from 'node:os' -import { average, isPlainObject, max, median, min } from '../utils.js' + import type { MessageValue, Task } from '../utility-types.js' +import { average, isPlainObject, max, median, min } from '../utils.js' +import type { IPool, TasksQueueOptions } from './pool.js' import { type MeasurementStatisticsRequirements, WorkerChoiceStrategies, type WorkerChoiceStrategy, type WorkerChoiceStrategyOptions } from './selection-strategies/selection-strategies-types.js' -import type { IPool, TasksQueueOptions } from './pool.js' +import type { WorkerChoiceStrategyContext } from './selection-strategies/worker-choice-strategy-context.js' import { type IWorker, type IWorkerNode, @@ -26,7 +28,6 @@ import { WorkerTypes, type WorkerUsage } from './worker.js' -import type { WorkerChoiceStrategyContext } from './selection-strategies/worker-choice-strategy-context.js' /** * Default measurement statistics requirements. diff --git a/src/pools/worker-node.ts b/src/pools/worker-node.ts index 523036a5..1a4df6cd 100644 --- a/src/pools/worker-node.ts +++ b/src/pools/worker-node.ts @@ -1,9 +1,16 @@ -import { MessageChannel } from 'node:worker_threads' import { EventEmitter } from 'node:events' +import { MessageChannel } from 'node:worker_threads' + import { CircularArray } from '../circular-array.js' +import { Deque } from '../deque.js' import type { Task } from '../utility-types.js' import { DEFAULT_TASK_NAME } from '../utils.js' -import { Deque } from '../deque.js' +import { + checkWorkerNodeArguments, + createWorker, + getWorkerId, + getWorkerType +} from './utils.js' import { type EventHandler, type IWorker, @@ -15,12 +22,6 @@ import { WorkerTypes, type WorkerUsage } from './worker.js' -import { - checkWorkerNodeArguments, - createWorker, - getWorkerId, - getWorkerType -} from './utils.js' /** * Worker node. diff --git a/src/pools/worker.ts b/src/pools/worker.ts index d4075483..ee54c6ac 100644 --- a/src/pools/worker.ts +++ b/src/pools/worker.ts @@ -1,5 +1,6 @@ -import type { MessageChannel, WorkerOptions } from 'node:worker_threads' import type { EventEmitter } from 'node:events' +import type { MessageChannel, WorkerOptions } from 'node:worker_threads' + import type { CircularArray } from '../circular-array.js' import type { Task } from '../utility-types.js' diff --git a/src/utility-types.ts b/src/utility-types.ts index e407309a..c7663606 100644 --- a/src/utility-types.ts +++ b/src/utility-types.ts @@ -1,6 +1,7 @@ +import type { AsyncResource } from 'node:async_hooks' import type { EventLoopUtilization } from 'node:perf_hooks' import type { MessagePort, TransferListItem } from 'node:worker_threads' -import type { AsyncResource } from 'node:async_hooks' + import type { KillBehavior } from './worker/worker-options.js' /** diff --git a/src/utils.ts b/src/utils.ts index a33758ce..f77d84a9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,6 @@ -import * as os from 'node:os' import { getRandomValues } from 'node:crypto' +import * as os from 'node:os' + import type { KillBehavior } from './worker/worker-options.js' /** diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index e754602a..6c7fd812 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -1,6 +1,7 @@ import type { Worker } from 'node:cluster' -import type { MessagePort } from 'node:worker_threads' import { performance } from 'node:perf_hooks' +import type { MessagePort } from 'node:worker_threads' + import type { MessageValue, Task, @@ -13,7 +14,6 @@ import { isAsyncFunction, isPlainObject } from '../utils.js' -import { KillBehaviors, type WorkerOptions } from './worker-options.js' import type { TaskAsyncFunction, TaskFunction, @@ -26,6 +26,7 @@ import { checkValidTaskFunctionEntry, checkValidWorkerOptions } from './utils.js' +import { KillBehaviors, type WorkerOptions } from './worker-options.js' const DEFAULT_MAX_INACTIVE_TIME = 60000 const DEFAULT_WORKER_OPTIONS: WorkerOptions = { diff --git a/src/worker/cluster-worker.ts b/src/worker/cluster-worker.ts index eedf13bd..325b7a41 100644 --- a/src/worker/cluster-worker.ts +++ b/src/worker/cluster-worker.ts @@ -1,8 +1,9 @@ import cluster, { type Worker } from 'node:cluster' + import type { MessageValue } from '../utility-types.js' import { AbstractWorker } from './abstract-worker.js' -import type { WorkerOptions } from './worker-options.js' import type { TaskFunction, TaskFunctions } from './task-functions.js' +import type { WorkerOptions } from './worker-options.js' /** * A cluster worker used by a poolifier `ClusterPool`. diff --git a/src/worker/thread-worker.ts b/src/worker/thread-worker.ts index 638de2ba..7115d715 100644 --- a/src/worker/thread-worker.ts +++ b/src/worker/thread-worker.ts @@ -1,13 +1,14 @@ import { - type MessagePort, isMainThread, + type MessagePort, parentPort, threadId } from 'node:worker_threads' + import type { MessageValue } from '../utility-types.js' import { AbstractWorker } from './abstract-worker.js' -import type { WorkerOptions } from './worker-options.js' import type { TaskFunction, TaskFunctions } from './task-functions.js' +import type { WorkerOptions } from './worker-options.js' /** * A thread worker used by a poolifier `ThreadPool`. diff --git a/tests/circular-array.test.mjs b/tests/circular-array.test.mjs index ed069045..a6f2f693 100644 --- a/tests/circular-array.test.mjs +++ b/tests/circular-array.test.mjs @@ -1,4 +1,5 @@ import { expect } from 'expect' + import { CircularArray, DEFAULT_CIRCULAR_ARRAY_SIZE diff --git a/tests/deque.test.mjs b/tests/deque.test.mjs index 91ae5987..f9a58c85 100644 --- a/tests/deque.test.mjs +++ b/tests/deque.test.mjs @@ -1,4 +1,5 @@ import { expect } from 'expect' + import { Deque } from '../lib/deque.cjs' describe('Deque test suite', () => { diff --git a/tests/pools/abstract-pool.test.mjs b/tests/pools/abstract-pool.test.mjs index 4b32e253..89cc8995 100644 --- a/tests/pools/abstract-pool.test.mjs +++ b/tests/pools/abstract-pool.test.mjs @@ -1,10 +1,14 @@ +import { createHook, executionAsyncId } from 'node:async_hooks' import { EventEmitterAsyncResource } from 'node:events' -import { dirname, join } from 'node:path' import { readFileSync } from 'node:fs' +import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' -import { createHook, executionAsyncId } from 'node:async_hooks' + import { expect } from 'expect' import { restore, stub } from 'sinon' + +import { CircularArray } from '../../lib/circular-array.cjs' +import { Deque } from '../../lib/deque.cjs' import { DynamicClusterPool, DynamicThreadPool, @@ -15,11 +19,9 @@ import { WorkerChoiceStrategies, WorkerTypes } from '../../lib/index.cjs' -import { CircularArray } from '../../lib/circular-array.cjs' -import { Deque } from '../../lib/deque.cjs' +import { WorkerNode } from '../../lib/pools/worker-node.cjs' import { DEFAULT_TASK_NAME } from '../../lib/utils.cjs' import { waitPoolEvents } from '../test-utils.cjs' -import { WorkerNode } from '../../lib/pools/worker-node.cjs' describe('Abstract pool test suite', () => { const version = JSON.parse( diff --git a/tests/pools/cluster/dynamic.test.mjs b/tests/pools/cluster/dynamic.test.mjs index 540223bf..8e6c125b 100644 --- a/tests/pools/cluster/dynamic.test.mjs +++ b/tests/pools/cluster/dynamic.test.mjs @@ -1,4 +1,5 @@ import { expect } from 'expect' + import { DynamicClusterPool, PoolEvents, diff --git a/tests/pools/cluster/fixed.test.mjs b/tests/pools/cluster/fixed.test.mjs index ed5882c4..cf002395 100644 --- a/tests/pools/cluster/fixed.test.mjs +++ b/tests/pools/cluster/fixed.test.mjs @@ -1,8 +1,9 @@ import { expect } from 'expect' + import { FixedClusterPool, PoolEvents } from '../../../lib/index.cjs' +import { DEFAULT_TASK_NAME } from '../../../lib/utils.cjs' import { TaskFunctions } from '../../test-types.cjs' import { waitPoolEvents, waitWorkerEvents } from '../../test-utils.cjs' -import { DEFAULT_TASK_NAME } from '../../../lib/utils.cjs' describe('Fixed cluster pool test suite', () => { const numberOfWorkers = 8 diff --git a/tests/pools/selection-strategies/selection-strategies.test.mjs b/tests/pools/selection-strategies/selection-strategies.test.mjs index bca3c82b..5241168c 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.mjs +++ b/tests/pools/selection-strategies/selection-strategies.test.mjs @@ -1,4 +1,6 @@ import { expect } from 'expect' + +import { CircularArray } from '../../../lib/circular-array.cjs' import { DynamicClusterPool, DynamicThreadPool, @@ -6,7 +8,6 @@ import { FixedThreadPool, WorkerChoiceStrategies } from '../../../lib/index.cjs' -import { CircularArray } from '../../../lib/circular-array.cjs' describe('Selection strategies test suite', () => { const min = 0 diff --git a/tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.mjs b/tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.mjs index 5beffafa..80c5ec7c 100644 --- a/tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.mjs +++ b/tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.mjs @@ -1,5 +1,7 @@ import { randomInt } from 'node:crypto' + import { expect } from 'expect' + import { FixedThreadPool } from '../../../lib/index.cjs' import { InterleavedWeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.cjs' import { WeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.cjs' diff --git a/tests/pools/selection-strategies/worker-choice-strategy-context.test.mjs b/tests/pools/selection-strategies/worker-choice-strategy-context.test.mjs index eb854b58..c591235c 100644 --- a/tests/pools/selection-strategies/worker-choice-strategy-context.test.mjs +++ b/tests/pools/selection-strategies/worker-choice-strategy-context.test.mjs @@ -1,18 +1,19 @@ import { expect } from 'expect' import { createStubInstance, restore, stub } from 'sinon' + import { DynamicThreadPool, FixedThreadPool, WorkerChoiceStrategies } from '../../../lib/index.cjs' -import { WorkerChoiceStrategyContext } from '../../../lib/pools/selection-strategies/worker-choice-strategy-context.cjs' -import { RoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/round-robin-worker-choice-strategy.cjs' -import { LeastUsedWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-used-worker-choice-strategy.cjs' +import { FairShareWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy.cjs' +import { InterleavedWeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.cjs' import { LeastBusyWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-busy-worker-choice-strategy.cjs' import { LeastEluWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-elu-worker-choice-strategy.cjs' -import { FairShareWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy.cjs' +import { LeastUsedWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-used-worker-choice-strategy.cjs' +import { RoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/round-robin-worker-choice-strategy.cjs' import { WeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.cjs' -import { InterleavedWeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.cjs' +import { WorkerChoiceStrategyContext } from '../../../lib/pools/selection-strategies/worker-choice-strategy-context.cjs' describe('Worker choice strategy context test suite', () => { const min = 1 diff --git a/tests/pools/thread/dynamic.test.mjs b/tests/pools/thread/dynamic.test.mjs index 77c5aaeb..fbce8ae0 100644 --- a/tests/pools/thread/dynamic.test.mjs +++ b/tests/pools/thread/dynamic.test.mjs @@ -1,4 +1,5 @@ import { expect } from 'expect' + import { DynamicThreadPool, PoolEvents, diff --git a/tests/pools/thread/fixed.test.mjs b/tests/pools/thread/fixed.test.mjs index 44e7d80b..94f7921c 100644 --- a/tests/pools/thread/fixed.test.mjs +++ b/tests/pools/thread/fixed.test.mjs @@ -1,8 +1,9 @@ import { expect } from 'expect' + import { FixedThreadPool, PoolEvents } from '../../../lib/index.cjs' +import { DEFAULT_TASK_NAME } from '../../../lib/utils.cjs' import { TaskFunctions } from '../../test-types.cjs' import { waitPoolEvents, waitWorkerEvents } from '../../test-utils.cjs' -import { DEFAULT_TASK_NAME } from '../../../lib/utils.cjs' describe('Fixed thread pool test suite', () => { const numberOfThreads = 6 diff --git a/tests/pools/utils.test.mjs b/tests/pools/utils.test.mjs index 6869bda6..c6cc06d3 100644 --- a/tests/pools/utils.test.mjs +++ b/tests/pools/utils.test.mjs @@ -1,25 +1,27 @@ -import { Worker as ThreadWorker } from 'node:worker_threads' import cluster, { Worker as ClusterWorker } from 'node:cluster' +import { Worker as ThreadWorker } from 'node:worker_threads' + import { expect } from 'expect' + import { CircularArray, DEFAULT_CIRCULAR_ARRAY_SIZE } from '../../lib/circular-array.cjs' import { - DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, + FixedClusterPool, + FixedThreadPool, + WorkerTypes +} from '../../lib/index.cjs' +import { buildWorkerChoiceStrategyOptions, createWorker, + DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, getDefaultTasksQueueOptions, getWorkerChoiceStrategyRetries, getWorkerId, getWorkerType, updateMeasurementStatistics } from '../../lib/pools/utils.cjs' -import { - FixedClusterPool, - FixedThreadPool, - WorkerTypes -} from '../../lib/index.cjs' describe('Pool utils test suite', () => { it('Verify DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS values', () => { diff --git a/tests/pools/worker-node.test.mjs b/tests/pools/worker-node.test.mjs index 549db4b6..5633530f 100644 --- a/tests/pools/worker-node.test.mjs +++ b/tests/pools/worker-node.test.mjs @@ -1,10 +1,12 @@ -import { MessageChannel, Worker as ThreadWorker } from 'node:worker_threads' import { Worker as ClusterWorker } from 'node:cluster' +import { MessageChannel, Worker as ThreadWorker } from 'node:worker_threads' + import { expect } from 'expect' -import { WorkerNode } from '../../lib/pools/worker-node.cjs' -import { WorkerTypes } from '../../lib/index.cjs' + import { CircularArray } from '../../lib/circular-array.cjs' import { Deque } from '../../lib/deque.cjs' +import { WorkerTypes } from '../../lib/index.cjs' +import { WorkerNode } from '../../lib/pools/worker-node.cjs' import { DEFAULT_TASK_NAME } from '../../lib/utils.cjs' describe('Worker node test suite', () => { diff --git a/tests/utils.test.mjs b/tests/utils.test.mjs index cd8deb8c..bf6d3f08 100644 --- a/tests/utils.test.mjs +++ b/tests/utils.test.mjs @@ -1,11 +1,14 @@ -import os from 'node:os' import { randomInt } from 'node:crypto' +import os from 'node:os' + import { expect } from 'expect' + +import { KillBehaviors } from '../lib/index.cjs' import { - DEFAULT_TASK_NAME, - EMPTY_FUNCTION, availableParallelism, average, + DEFAULT_TASK_NAME, + EMPTY_FUNCTION, exponentialDelay, isAsyncFunction, isKillBehavior, @@ -18,7 +21,6 @@ import { secureRandom, sleep } from '../lib/utils.cjs' -import { KillBehaviors } from '../lib/index.cjs' describe('Utils test suite', () => { it('Verify DEFAULT_TASK_NAME value', () => { diff --git a/tests/worker-files/thread/testWorker.mjs b/tests/worker-files/thread/testWorker.mjs index 8a74ae3a..f4840e53 100644 --- a/tests/worker-files/thread/testWorker.mjs +++ b/tests/worker-files/thread/testWorker.mjs @@ -1,6 +1,6 @@ import { KillBehaviors, ThreadWorker } from '../../../lib/index.cjs' -import { executeTaskFunction } from '../../test-utils.cjs' import { TaskFunctions } from '../../test-types.cjs' +import { executeTaskFunction } from '../../test-utils.cjs' /** * diff --git a/tests/worker/abstract-worker.test.mjs b/tests/worker/abstract-worker.test.mjs index 3e5f5518..781f7790 100644 --- a/tests/worker/abstract-worker.test.mjs +++ b/tests/worker/abstract-worker.test.mjs @@ -1,5 +1,6 @@ import { expect } from 'expect' import { restore, stub } from 'sinon' + import { ClusterWorker, KillBehaviors, ThreadWorker } from '../../lib/index.cjs' import { DEFAULT_TASK_NAME, EMPTY_FUNCTION } from '../../lib/utils.cjs' diff --git a/tests/worker/cluster-worker.test.mjs b/tests/worker/cluster-worker.test.mjs index 33ddf374..3392d96c 100644 --- a/tests/worker/cluster-worker.test.mjs +++ b/tests/worker/cluster-worker.test.mjs @@ -1,5 +1,6 @@ import { expect } from 'expect' import { restore, stub } from 'sinon' + import { ClusterWorker } from '../../lib/index.cjs' import { DEFAULT_TASK_NAME } from '../../lib/utils.cjs' diff --git a/tests/worker/thread-worker.test.mjs b/tests/worker/thread-worker.test.mjs index 77bb6c08..e4a408d5 100644 --- a/tests/worker/thread-worker.test.mjs +++ b/tests/worker/thread-worker.test.mjs @@ -1,5 +1,6 @@ import { expect } from 'expect' import { restore, stub } from 'sinon' + import { ThreadWorker } from '../../lib/index.cjs' import { DEFAULT_TASK_NAME } from '../../lib/utils.cjs' diff --git a/typedoc.mjs b/typedoc.mjs index b9f9cc99..86f160da 100644 --- a/typedoc.mjs +++ b/typedoc.mjs @@ -1,7 +1,7 @@ +import { execSync } from 'node:child_process' import { copyFileSync, mkdirSync, readdirSync, rmSync } from 'node:fs' import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' -import { execSync } from 'node:child_process' try { mkdirSync(join(dirname(fileURLToPath(import.meta.url)), 'tmp'), {