refactor: cleanup reservation methods scope
[e-mobility-charging-stations-simulator.git] / rollup.config.mjs
index 82b5b79aa27de94041111165e4d95eb415334288..2c8d35564c05b9925bfaf91e3c39f4aa582abc7d 100644 (file)
@@ -1,5 +1,5 @@
 /* eslint-disable n/no-unpublished-import */
-import os from 'os';
+import * as os from 'node:os';
 
 import json from '@rollup/plugin-json';
 import terser from '@rollup/plugin-terser';
@@ -8,8 +8,23 @@ import { copy } from '@web/rollup-plugin-copy';
 import analyze from 'rollup-plugin-analyzer';
 import del from 'rollup-plugin-delete';
 
+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'],
@@ -18,8 +33,8 @@ export default {
     {
       dir: 'dist',
       format: 'esm',
-      sourcemap: !!isDevelopmentBuild,
-      plugins: [terser({ maxWorkers: os.cpus().length / 2 })],
+      sourcemap: sourceMap,
+      plugins: [terser({ maxWorkers: Math.floor(availableParallelism() / 2) })],
     },
   ],
   external: [
@@ -29,17 +44,19 @@ export default {
     'ajv-formats',
     'basic-ftp',
     'chalk',
+    'date-fns',
+    'deep-clone',
     'http-status-codes',
-    'just-clone',
     'just-merge',
     'mnemonist/lru-map-with-delete.js',
-    'moment',
+    'mnemonist/queue.js',
     'mongodb',
     'node:async_hooks',
     'node:crypto',
     'node:events',
     'node:fs',
     'node:http',
+    'node:http2',
     'node:path',
     'node:perf_hooks',
     'node:stream',
@@ -57,6 +74,9 @@ export default {
     json(),
     typescript({
       tsconfig: 'tsconfig.json',
+      compilerOptions: {
+        sourceMap,
+      },
     }),
     del({
       targets: [
@@ -73,8 +93,9 @@ export default {
       patterns: 'assets/**/*.json',
       exclude: [
         'assets/config-template.json',
-        'assets/*config[-_]*.json',
+        'assets/*config[-_.]*.json',
         'assets/idtags-template.json',
+        'assets/authorization-tags-template.json',
         'assets/ui-protocol/**/*',
       ],
     }),