refactor: cleanup reservation methods scope
[e-mobility-charging-stations-simulator.git] / rollup.config.mjs
index 890bc33a0b9ff7eeed53c7cf24d4b6a226367083..2c8d35564c05b9925bfaf91e3c39f4aa582abc7d 100644 (file)
@@ -1,34 +1,40 @@
+/* eslint-disable n/no-unpublished-import */
+import * as os from 'node:os';
+
 import json from '@rollup/plugin-json';
+import terser from '@rollup/plugin-terser';
+import typescript from '@rollup/plugin-typescript';
+import { copy } from '@web/rollup-plugin-copy';
 import analyze from 'rollup-plugin-analyzer';
-import copy from 'rollup-plugin-copy';
 import del from 'rollup-plugin-delete';
-import { terser } from 'rollup-plugin-terser';
-import ts from 'rollup-plugin-ts';
+
+const availableParallelism = () => {
+  // eslint-disable-next-line no-shadow
+  let availableParallelism = 1;
+  try {
+    availableParallelism = os.availableParallelism();
+  } catch {
+    const numberOfCpus = os.cpus();
+    if (Array.isArray(numberOfCpus) && numberOfCpus.length > 0) {
+      availableParallelism = numberOfCpus.length;
+    }
+  }
+  return availableParallelism;
+};
 
 const isDevelopmentBuild = process.env.BUILD === 'development';
+const isAnalyzeBuild = process.env.ANALYZE;
+const sourceMap = !!isDevelopmentBuild;
 
 export default {
   input: ['src/start.ts', 'src/charging-station/ChargingStationWorker.ts'],
+  strictDeprecations: true,
   output: [
     {
       dir: 'dist',
-      format: 'es',
-      exports: 'auto',
-      sourcemap: true,
-      preserveModules: true,
-      preserveModulesRoot: 'src',
-      entryFileNames: '[name].mjs',
-      ...(!isDevelopmentBuild && { plugins: [terser({ numWorkers: 2 })] }),
-    },
-    {
-      dir: 'dist',
-      format: 'cjs',
-      exports: 'auto',
-      sourcemap: true,
-      preserveModules: true,
-      preserveModulesRoot: 'src',
-      entryFileNames: '[name].cjs',
-      ...(!isDevelopmentBuild && { plugins: [terser({ numWorkers: 2 })] }),
+      format: 'esm',
+      sourcemap: sourceMap,
+      plugins: [terser({ maxWorkers: Math.floor(availableParallelism() / 2) })],
     },
   ],
   external: [
@@ -36,48 +42,63 @@ export default {
     '@mikro-orm/reflection',
     'ajv',
     'ajv-formats',
-    'async_hooks',
     'basic-ftp',
     'chalk',
-    'crypto',
-    'fs',
-    'http',
+    'date-fns',
+    'deep-clone',
     'http-status-codes',
-    'just-clone',
     'just-merge',
-    'mnemonist/lru-map-with-delete',
-    'moment',
+    'mnemonist/lru-map-with-delete.js',
+    'mnemonist/queue.js',
     'mongodb',
-    'path',
-    'perf_hooks',
+    'node:async_hooks',
+    'node:crypto',
+    'node:events',
+    'node:fs',
+    'node:http',
+    'node:http2',
+    'node:path',
+    'node:perf_hooks',
+    'node:stream',
+    'node:url',
+    'node:util',
+    'node:worker_threads',
     'poolifier',
-    'proper-lockfile',
     'tar',
-    'url',
     'winston',
     'winston-daily-rotate-file',
-    'winston/lib/winston/transports',
-    'worker_threads',
+    'winston/lib/winston/transports/index.js',
     'ws',
   ],
   plugins: [
     json(),
-    ts({
+    typescript({
       tsconfig: 'tsconfig.json',
-      browserslist: false,
+      compilerOptions: {
+        sourceMap,
+      },
     }),
     del({
       targets: [
         'dist/*',
         '!dist/assets',
         'dist/assets/*.json',
-        'dist/assets/station-templates',
         'dist/assets/json-schemas',
+        'dist/assets/station-templates',
+        'dist/assets/ui-protocol',
       ],
     }),
     copy({
-      targets: [{ src: 'src/assets', dest: 'dist/' }],
+      rootDir: 'src',
+      patterns: 'assets/**/*.json',
+      exclude: [
+        'assets/config-template.json',
+        'assets/*config[-_.]*.json',
+        'assets/idtags-template.json',
+        'assets/authorization-tags-template.json',
+        'assets/ui-protocol/**/*',
+      ],
     }),
-    isDevelopmentBuild && analyze(),
+    isAnalyzeBuild && analyze(),
   ],
 };