From 34a0cfabc4bdc36803dfbb502f0f46704993a76b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 18 Mar 2023 16:29:45 +0100 Subject: [PATCH] feat: initial work at bundling ESM and CommonJS MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- package.json | 5 ++++- rollup.config.mjs | 32 ++++++++++++++++++++++++-------- src/pools/abstract-pool.ts | 2 +- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 65e34365..c06db4c5 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,10 @@ "version": "2.3.8", "description": "A fast, easy to use Node.js Worker Thread Pool and Cluster Pool implementation", "license": "MIT", - "main": "lib/index.js", + "exports": [ + "lib/index.js", + "lib/index.mjs" + ], "scripts": { "prepare": "node prepare.js", "build": "rollup --config --environment BUILD:development", diff --git a/rollup.config.mjs b/rollup.config.mjs index e1bdac21..8997445e 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -10,14 +10,30 @@ const isDocumentation = process.env.DOCUMENTATION export default { input: 'src/index.ts', - output: { - ...(isDevelopmentBuild ? { dir: 'lib' } : { file: 'lib/index.js' }), - format: 'cjs', - sourcemap: !!isDevelopmentBuild, - ...(isDevelopmentBuild && { preserveModules: true }), - ...(isDevelopmentBuild && { preserveModulesRoot: 'src' }), - ...(!isDevelopmentBuild && { plugins: [terser({ maxWorkers: 2 })] }) - }, + output: [ + { + ...(isDevelopmentBuild ? { dir: 'lib' } : { file: 'lib/index.js' }), + format: 'cjs', + sourcemap: !!isDevelopmentBuild, + ...(isDevelopmentBuild && { + preserveModules: true, + preserveModulesRoot: 'src' + }), + ...(!isDevelopmentBuild && { plugins: [terser({ maxWorkers: 2 })] }) + }, + { + ...(isDevelopmentBuild ? { dir: 'lib' } : { file: 'lib/index.mjs' }), + format: 'esm', + sourcemap: !!isDevelopmentBuild, + + ...(isDevelopmentBuild && { + entryFileNames: '[name].mjs', + preserveModules: true, + preserveModulesRoot: 'src' + }), + ...(!isDevelopmentBuild && { plugins: [terser({ maxWorkers: 2 })] }) + } + ], external: ['async_hooks', 'cluster', 'events', 'os', 'worker_threads'], plugins: [ typescript({ diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 695c43b3..32b4d983 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -3,7 +3,7 @@ import type { PromiseWorkerResponseWrapper } from '../utility-types' import { EMPTY_FUNCTION, EMPTY_OBJECT_LITERAL } from '../utils' -import { isKillBehavior, KillBehaviors } from '../worker/worker-options' +import { KillBehaviors, isKillBehavior } from '../worker/worker-options' import type { PoolOptions } from './pool' import { PoolEmitter } from './pool' import type { IPoolInternal, TasksUsage } from './pool-internal' -- 2.34.1