Skip to content

Commit

Permalink
fix: wrong mqttjs version printed (#1847)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Apr 19, 2024
1 parent 59009a6 commit a24cf14
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
24 changes: 21 additions & 3 deletions esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ 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 All @@ -34,6 +31,27 @@ const options = {
navigator: true, // Needed for WeChat, ref #1789
}
}),
{
name: 'resolve-package-json',
setup(build) {
// when importing 'package.json' we want to provide a custom object like { version: '1.2.3' }

build.onResolve({ filter: /package\.json$/ }, args => {
return {
path: args.path,
namespace: 'package-json'
}
})

build.onLoad({ filter: /.*/, namespace: 'package-json' }, args => {
return {
contents: JSON.stringify({ version }),
loader: 'json'
}
}
)
}
},
],
}

Expand Down
3 changes: 2 additions & 1 deletion src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
ErrorWithReasonCode,
GenericCallback,
IStream,
MQTTJS_VERSION,
StreamBuilder,
TimerVariant,
VoidCallback,
Expand Down Expand Up @@ -396,7 +397,7 @@ export interface MqttClientEventCallbacks {
* (see Connection#connect)
*/
export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbacks> {
public static VERSION = process.env.npm_package_version
public static VERSION = MQTTJS_VERSION

/** Public fields */

Expand Down
3 changes: 3 additions & 0 deletions src/lib/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,6 @@ export const nextTick =
: (callback: () => void) => {
setTimeout(callback, 0)
}

// eslint-disable-next-line @typescript-eslint/no-var-requires
export const MQTTJS_VERSION = require('../../package.json').version

0 comments on commit a24cf14

Please sign in to comment.