X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=rollup.config.mjs;h=e0c97bd6e4ebe607ec56d4c526c43206a6215393;hb=0b60de1faea2ed2ebbbf77393ab4d280b7a897a2;hp=bac8f614a5524bd3983969c29ef1d4b36f6fb202;hpb=aad2595fd9c26bcb2f0d7a22d06edf56d5b08bdb;p=poolifier.git diff --git a/rollup.config.mjs b/rollup.config.mjs index bac8f614..e0c97bd6 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -1,31 +1,103 @@ -import typescript from 'rollup-plugin-typescript2' +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 { terser } from 'rollup-plugin-terser' +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 isAnalyze = process.env.ANALYZE +const isAnalyzeBuild = process.env.ANALYZE +const isDocumentationBuild = 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({ numWorkers: 2 })] }) +const maxWorkers = Math.floor(availableParallelism() / 2) + +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' + }), + del({ + targets: ['./lib/*'] + }), + isAnalyzeBuild && analyze(), + isDocumentationBuild && command('pnpm typedoc') + ] }, - external: ['async_hooks', 'cluster', 'events', 'worker_threads'], - plugins: [ - typescript({ - tsconfig: isDevelopmentBuild - ? 'tsconfig.development.json' - : 'tsconfig.json' - }), - del({ - targets: ['lib/*'] - }), - isAnalyze && analyze() - ] -} + { + 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() + ] + } +]