fix: make ESM bundle work
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 18 Mar 2023 14:55:07 +0000 (15:55 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 18 Mar 2023 14:55:07 +0000 (15:55 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
.vscode/launch.json
package.json
rollup.config.mjs
src/charging-station/SharedLRUCache.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16RequestService.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts
src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts
src/charging-station/ocpp/2.0/OCPP20RequestService.ts
src/charging-station/ocpp/2.0/OCPP20ResponseService.ts
src/utils/Logger.ts

index 47cb8a6a112bb2611be99eade7eb98e6e8344cc4..27d7900e69da361b680fc2eacc6819b5cf601fbf 100644 (file)
@@ -4,16 +4,6 @@
   // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
   "version": "0.2.0",
   "configurations": [
-    {
-      "type": "node",
-      "request": "launch",
-      "name": "Debug Simulator via npm",
-      "cwd": "${workspaceFolder}",
-      "runtimeExecutable": "npm",
-      "runtimeArgs": ["run-script", "start:debug"],
-      "skipFiles": ["<node_internals>/**"],
-      "stopOnEntry": true
-    },
     {
       "type": "node",
       "request": "launch",
index cce44ca1a22d769393fe7e2de455f8eeba3fe63e..57f12e9d9881ee70e209e69ed5897f962daf0571 100644 (file)
     "prepare": "node prepare.js",
     "build-requirements": "node build-requirements.js",
     "start": "npm run build && cross-env NODE_ENV=production node -r source-map-support/register dist/start.cjs",
-    "start:debug": "npm run build && cross-env NODE_ENV=production node -r source-map-support/register --inspect dist/start.cjs",
+    "start:esm": "npm run build && cross-env NODE_ENV=production node -r source-map-support/register dist/start.mjs",
     "start:dev": "npm run build:dev && cross-env NODE_ENV=development node -r source-map-support/register dist/start.cjs",
     "start:dev:debug": "npm run build:dev && cross-env NODE_ENV=development node -r source-map-support/register --inspect dist/start.cjs",
     "start:dev:esm": "npm run build:dev && cross-env NODE_ENV=development node -r source-map-support/register dist/start.mjs",
+    "start:dev:esm:debug": "npm run build:dev && cross-env NODE_ENV=development node -r source-map-support/register --inspect dist/start.mjs",
     "start:prof": "cross-env NODE_ENV=production node -r source-map-support/register --prof dist/start.cjs",
     "start:doctorprof": "cross-env NODE_ENV=production clinic doctor -- node -r source-map-support/register dist/start.cjs",
     "start:flameprof": "cross-env NODE_ENV=production clinic flame -- node -r source-map-support/register dist/start.cjs",
index be3fa4d35f843333a713ed5558c3a658425e5ee3..a0128a547b2bcb4cbf8999e37157aefaf885da00 100644 (file)
@@ -9,6 +9,7 @@ const isDevelopmentBuild = process.env.BUILD === 'development';
 
 export default {
   input: ['src/start.ts', 'src/charging-station/ChargingStationWorker.ts'],
+  strictDeprecations: true,
   output: [
     {
       dir: 'dist',
@@ -41,7 +42,7 @@ export default {
     'http-status-codes',
     'just-clone',
     'just-merge',
-    'mnemonist/lru-map-with-delete',
+    'mnemonist/lru-map-with-delete.js',
     'moment',
     'mongodb',
     'node:async_hooks',
@@ -59,7 +60,7 @@ export default {
     'tar',
     'winston',
     'winston-daily-rotate-file',
-    'winston/lib/winston/transports',
+    'winston/lib/winston/transports/index.js',
     'ws',
   ],
   plugins: [
index 3ee8cd7f7fa3a054ea5ca0410ee802d9702ad8f1..b58dc79ee6a9509c3fc5a79bf4605487b500d174 100644 (file)
@@ -1,4 +1,4 @@
-import LRUCache from 'mnemonist/lru-map-with-delete';
+import LRUCache from 'mnemonist/lru-map-with-delete.js';
 
 import { Bootstrap } from './internal';
 import type { ChargingStationConfiguration, ChargingStationTemplate } from '../types';
index 8360122b2710a7b8736a05d1ac8e705fc3063034..8b23eddd1e0820c118a8b8242aaa31f413fe7353 100644 (file)
@@ -87,9 +87,9 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
   private incomingRequestHandlers: Map<OCPP16IncomingRequestCommand, IncomingRequestHandler>;
 
   public constructor() {
-    if (new.target?.name === moduleName) {
-      throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
-    }
+    // if (new.target?.name === moduleName) {
+    //   throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
+    // }
     super(OCPPVersion.VERSION_16);
     this.incomingRequestHandlers = new Map<OCPP16IncomingRequestCommand, IncomingRequestHandler>([
       [OCPP16IncomingRequestCommand.RESET, this.handleRequestReset.bind(this)],
index 1d571b042dfdedecab3add913269c88171714926..eee9e9a9d1687939a5e1d523496a6386abd97395 100644 (file)
@@ -36,9 +36,9 @@ export class OCPP16RequestService extends OCPPRequestService {
   protected jsonSchemas: Map<OCPP16RequestCommand, JSONSchemaType<JsonObject>>;
 
   public constructor(ocppResponseService: OCPPResponseService) {
-    if (new.target?.name === moduleName) {
-      throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
-    }
+    // if (new.target?.name === moduleName) {
+    //   throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
+    // }
     super(OCPPVersion.VERSION_16, ocppResponseService);
     this.jsonSchemas = new Map<OCPP16RequestCommand, JSONSchemaType<JsonObject>>([
       [
index 2c92b6bd4b19c2e1444922444f1579ff830b5a48..76bd56c297d8291cc3e5b983f24c9236bb605e02 100644 (file)
@@ -59,9 +59,9 @@ export class OCPP16ResponseService extends OCPPResponseService {
   private jsonSchemas: Map<OCPP16RequestCommand, JSONSchemaType<JsonObject>>;
 
   public constructor() {
-    if (new.target?.name === moduleName) {
-      throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
-    }
+    // if (new.target?.name === moduleName) {
+    //   throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
+    // }
     super(OCPPVersion.VERSION_16);
     this.responseHandlers = new Map<OCPP16RequestCommand, ResponseHandler>([
       [OCPP16RequestCommand.BOOT_NOTIFICATION, this.handleResponseBootNotification.bind(this)],
index 0a274caf0327e1fb64c9db385af7f5163b2a8c90..1b5cf72c2bbd6a76243fa6f8fc7bc68b21648098 100644 (file)
@@ -23,9 +23,9 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
   private incomingRequestHandlers: Map<OCPP20IncomingRequestCommand, IncomingRequestHandler>;
 
   public constructor() {
-    if (new.target?.name === moduleName) {
-      throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
-    }
+    // if (new.target?.name === moduleName) {
+    //   throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
+    // }
     super(OCPPVersion.VERSION_20);
     this.incomingRequestHandlers = new Map<OCPP20IncomingRequestCommand, IncomingRequestHandler>([
       [OCPP20IncomingRequestCommand.CLEAR_CACHE, this.handleRequestClearCache.bind(this)],
index 92d70aedcb2c63a569a5d35adf409de1a34424a8..f9d0b75855349654c2010c7ad6653af87fe2bf83 100644 (file)
@@ -29,9 +29,9 @@ export class OCPP20RequestService extends OCPPRequestService {
   protected jsonSchemas: Map<OCPP20RequestCommand, JSONSchemaType<JsonObject>>;
 
   public constructor(ocppResponseService: OCPPResponseService) {
-    if (new.target?.name === moduleName) {
-      throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
-    }
+    // if (new.target?.name === moduleName) {
+    //   throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
+    // }
     super(OCPPVersion.VERSION_20, ocppResponseService);
     this.jsonSchemas = new Map<OCPP20RequestCommand, JSONSchemaType<JsonObject>>([
       [
index eb6c00c36de26281bd744811dbc2cc52ae998845..129d8e52ddecb00fcefc437abdcedbf2c0eb9650 100644 (file)
@@ -34,9 +34,9 @@ export class OCPP20ResponseService extends OCPPResponseService {
   private jsonSchemas: Map<OCPP20RequestCommand, JSONSchemaType<JsonObject>>;
 
   public constructor() {
-    if (new.target?.name === moduleName) {
-      throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
-    }
+    // if (new.target?.name === moduleName) {
+    //   throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
+    // }
     super(OCPPVersion.VERSION_20);
     this.responseHandlers = new Map<OCPP20RequestCommand, ResponseHandler>([
       [OCPP20RequestCommand.BOOT_NOTIFICATION, this.handleResponseBootNotification.bind(this)],
index fde2f69d80c786d2a762fbde65e4cc702a17f9d9..d48659f4bbaea774db5c32b2f44ff784eeaa8245 100644 (file)
@@ -1,6 +1,6 @@
 import type { FormatWrap } from 'logform';
 import { type Logger, createLogger, format, type transport } from 'winston';
-import TransportType from 'winston/lib/winston/transports';
+import TransportType from 'winston/lib/winston/transports/index.js';
 import DailyRotateFile from 'winston-daily-rotate-file';
 
 // import { Configuration, Utils } from './internal';