From b768993dd4636df8276b0ea47158dd9bdc9a997b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 18 Mar 2023 15:55:07 +0100 Subject: [PATCH] fix: make ESM bundle work MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .vscode/launch.json | 10 ---------- package.json | 3 ++- rollup.config.mjs | 5 +++-- src/charging-station/SharedLRUCache.ts | 2 +- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 6 +++--- src/charging-station/ocpp/1.6/OCPP16RequestService.ts | 6 +++--- src/charging-station/ocpp/1.6/OCPP16ResponseService.ts | 6 +++--- .../ocpp/2.0/OCPP20IncomingRequestService.ts | 6 +++--- src/charging-station/ocpp/2.0/OCPP20RequestService.ts | 6 +++--- src/charging-station/ocpp/2.0/OCPP20ResponseService.ts | 6 +++--- src/utils/Logger.ts | 2 +- 11 files changed, 25 insertions(+), 33 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 47cb8a6a..27d7900e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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": ["/**"], - "stopOnEntry": true - }, { "type": "node", "request": "launch", diff --git a/package.json b/package.json index cce44ca1..57f12e9d 100644 --- a/package.json +++ b/package.json @@ -43,10 +43,11 @@ "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", diff --git a/rollup.config.mjs b/rollup.config.mjs index be3fa4d3..a0128a54 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -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: [ diff --git a/src/charging-station/SharedLRUCache.ts b/src/charging-station/SharedLRUCache.ts index 3ee8cd7f..b58dc79e 100644 --- a/src/charging-station/SharedLRUCache.ts +++ b/src/charging-station/SharedLRUCache.ts @@ -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'; diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 8360122b..8b23eddd 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -87,9 +87,9 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { private incomingRequestHandlers: Map; 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.RESET, this.handleRequestReset.bind(this)], diff --git a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts index 1d571b04..eee9e9a9 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -36,9 +36,9 @@ export class OCPP16RequestService extends OCPPRequestService { protected jsonSchemas: Map>; 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>([ [ diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 2c92b6bd..76bd56c2 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -59,9 +59,9 @@ export class OCPP16ResponseService extends OCPPResponseService { private jsonSchemas: Map>; 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.BOOT_NOTIFICATION, this.handleResponseBootNotification.bind(this)], diff --git a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts index 0a274caf..1b5cf72c 100644 --- a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts @@ -23,9 +23,9 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { private incomingRequestHandlers: Map; 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.CLEAR_CACHE, this.handleRequestClearCache.bind(this)], diff --git a/src/charging-station/ocpp/2.0/OCPP20RequestService.ts b/src/charging-station/ocpp/2.0/OCPP20RequestService.ts index 92d70aed..f9d0b758 100644 --- a/src/charging-station/ocpp/2.0/OCPP20RequestService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20RequestService.ts @@ -29,9 +29,9 @@ export class OCPP20RequestService extends OCPPRequestService { protected jsonSchemas: Map>; 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>([ [ diff --git a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts index eb6c00c3..129d8e52 100644 --- a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts @@ -34,9 +34,9 @@ export class OCPP20ResponseService extends OCPPResponseService { private jsonSchemas: Map>; 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.BOOT_NOTIFICATION, this.handleResponseBootNotification.bind(this)], diff --git a/src/utils/Logger.ts b/src/utils/Logger.ts index fde2f69d..d48659f4 100644 --- a/src/utils/Logger.ts +++ b/src/utils/Logger.ts @@ -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'; -- 2.34.1