Skip to content

Commit

Permalink
fix: print MQTTjs version and environment on constructor (#1816)
Browse files Browse the repository at this point in the history
* fix: print  mqttjs version and environment on constructor

* fix: prevent esbuild to pick up the entire pakcage.json
  • Loading branch information
robertsLando authored Mar 13, 2024
1 parent 2b75186 commit c0a6668
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { build } = require('esbuild')
const { polyfillNode } = require('esbuild-plugin-polyfill-node');
const { rimraf } = require('rimraf')
const fs = require('fs')
const { version } = require('./package.json');

const outdir = 'dist'

Expand All @@ -15,6 +16,9 @@ const options = {
format: 'iife',
platform: 'browser',
globalName: 'mqtt',
define: {
'process.env.npm_package_version': JSON.stringify(version),
},
sourcemap: false, // this can be enabled while debugging, if we decide to keep this enabled we should also ship the `src` folder to npm
plugins: [
polyfillNode({
Expand Down
12 changes: 12 additions & 0 deletions src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
import TopicAliasSend from './topic-alias-send'
import { TypedEventEmitter } from './TypedEmitter'
import PingTimer from './PingTimer'
import isBrowser, { isWebWorker } from './is-browser'

const setImmediate =
globalThis.setImmediate ||
Expand Down Expand Up @@ -488,6 +489,17 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
this.log = this.options.log || _debug('mqttjs:client')
this.noop = this._noop.bind(this)

this.log('MqttClient :: version:', process.env.npm_package_version)

if (isWebWorker) {
this.log('MqttClient :: environment', 'webworker')
} else {
this.log(
'MqttClient :: environment',
isBrowser ? 'browser' : 'node',
)
}

this.log('MqttClient :: options.protocol', options.protocol)
this.log(
'MqttClient :: options.protocolVersion',
Expand Down

0 comments on commit c0a6668

Please sign in to comment.