From: Jérôme Benoit Date: Sat, 18 Mar 2023 15:29:45 +0000 (+0100) Subject: feat: initial work at bundling ESM and CommonJS X-Git-Tag: v2.3.9~5 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=34a0cfabc4bdc36803dfbb502f0f46704993a76b;p=poolifier.git feat: initial work at bundling ESM and CommonJS Signed-off-by: Jérôme Benoit --- 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'