Skip to content

Commit c0a6668

Browse files
authored
fix: print MQTTjs version and environment on constructor (#1816)
* fix: print mqttjs version and environment on constructor * fix: prevent esbuild to pick up the entire pakcage.json
1 parent 2b75186 commit c0a6668

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

esbuild.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const { build } = require('esbuild')
22
const { polyfillNode } = require('esbuild-plugin-polyfill-node');
33
const { rimraf } = require('rimraf')
44
const fs = require('fs')
5+
const { version } = require('./package.json');
56

67
const outdir = 'dist'
78

@@ -15,6 +16,9 @@ const options = {
1516
format: 'iife',
1617
platform: 'browser',
1718
globalName: 'mqtt',
19+
define: {
20+
'process.env.npm_package_version': JSON.stringify(version),
21+
},
1822
sourcemap: false, // this can be enabled while debugging, if we decide to keep this enabled we should also ship the `src` folder to npm
1923
plugins: [
2024
polyfillNode({

src/lib/client.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
import TopicAliasSend from './topic-alias-send'
3939
import { TypedEventEmitter } from './TypedEmitter'
4040
import PingTimer from './PingTimer'
41+
import isBrowser, { isWebWorker } from './is-browser'
4142

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

492+
this.log('MqttClient :: version:', process.env.npm_package_version)
493+
494+
if (isWebWorker) {
495+
this.log('MqttClient :: environment', 'webworker')
496+
} else {
497+
this.log(
498+
'MqttClient :: environment',
499+
isBrowser ? 'browser' : 'node',
500+
)
501+
}
502+
491503
this.log('MqttClient :: options.protocol', options.protocol)
492504
this.log(
493505
'MqttClient :: options.protocolVersion',

0 commit comments

Comments
 (0)