X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=rollup.config.mjs;h=e0c97bd6e4ebe607ec56d4c526c43206a6215393;hb=0b60de1faea2ed2ebbbf77393ab4d280b7a897a2;hp=0d5964e544f2ff89ed258e88e9500301ce820a66;hpb=509e904b46dca595dc59803516f9af85368a2860;p=poolifier.git diff --git a/rollup.config.mjs b/rollup.config.mjs index 0d5964e5..e0c97bd6 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -1,66 +1,103 @@ -import os from 'os' +import * as os from 'node:os' +import { dts } from 'rollup-plugin-dts' import terser from '@rollup/plugin-terser' import typescript from '@rollup/plugin-typescript' import analyze from 'rollup-plugin-analyzer' import command from 'rollup-plugin-command' import del from 'rollup-plugin-delete' +const availableParallelism = () => { + let availableParallelism = 1 + try { + availableParallelism = os.availableParallelism() + } catch { + const cpus = os.cpus() + if (Array.isArray(cpus) && cpus.length > 0) { + availableParallelism = cpus.length + } + } + return availableParallelism +} + const isDevelopmentBuild = process.env.BUILD === 'development' const isAnalyzeBuild = process.env.ANALYZE const isDocumentationBuild = process.env.DOCUMENTATION -const maxWorkers = os.cpus().length / 2 +const maxWorkers = Math.floor(availableParallelism() / 2) -export default { - input: 'src/index.ts', - strictDeprecations: true, - output: [ - { - format: 'cjs', - sourcemap: !!isDevelopmentBuild, - ...(isDevelopmentBuild && { - dir: 'lib', - preserveModules: true, - preserveModulesRoot: 'src' +export default [ + { + input: './src/index.ts', + strictDeprecations: true, + output: [ + { + format: 'cjs', + ...(isDevelopmentBuild && { + dir: './lib', + sourcemap: true, + preserveModules: true, + preserveModulesRoot: './src' + }), + ...(!isDevelopmentBuild && { + file: './lib/index.js', + plugins: [terser({ maxWorkers })] + }) + }, + { + format: 'esm', + ...(isDevelopmentBuild && { + dir: './lib', + sourcemap: true, + entryFileNames: '[name].mjs', + preserveModules: true, + preserveModulesRoot: './src' + }), + ...(!isDevelopmentBuild && { + file: './lib/index.mjs', + plugins: [terser({ maxWorkers })] + }) + } + ], + external: [ + 'node:async_hooks', + 'node:cluster', + 'node:crypto', + 'node:events', + 'node:fs', + 'node:os', + 'node:perf_hooks', + 'node:worker_threads' + ], + plugins: [ + typescript({ + tsconfig: isDevelopmentBuild + ? './tsconfig.development.json' + : './tsconfig.production.json' }), - ...(!isDevelopmentBuild && { - file: 'lib/index.js', - plugins: [terser({ maxWorkers })] - }) - }, - { - format: 'esm', - sourcemap: !!isDevelopmentBuild, - ...(isDevelopmentBuild && { - dir: 'lib', - entryFileNames: '[name].mjs', - preserveModules: true, - preserveModulesRoot: 'src' + del({ + targets: ['./lib/*'] }), - ...(!isDevelopmentBuild && { - file: 'lib/index.mjs', - plugins: [terser({ maxWorkers })] - }) - } - ], - external: [ - 'node:async_hooks', - 'node:cluster', - 'node:crypto', - 'node:events', - 'node:os', - 'node:worker_threads' - ], - plugins: [ - typescript({ - tsconfig: isDevelopmentBuild - ? 'tsconfig.development.json' - : 'tsconfig.production.json' - }), - del({ - targets: ['lib/*'] - }), - isAnalyzeBuild && analyze(), - isDocumentationBuild && command('pnpm typedoc') - ] -} + isAnalyzeBuild && analyze(), + isDocumentationBuild && command('pnpm typedoc') + ] + }, + { + input: './lib/dts/index.d.ts', + output: [{ format: 'esm', file: './lib/index.d.ts' }], + external: [ + 'node:async_hooks', + 'node:cluster', + 'node:events', + 'node:perf_hooks', + 'node:worker_threads' + ], + plugins: [ + dts(), + del({ + targets: ['./lib/dts'], + hook: 'buildEnd' + }), + isAnalyzeBuild && analyze() + ] + } +]