Skip to content

Commit a24cf14

Browse files
authored
fix: wrong mqttjs version printed (#1847)
1 parent 59009a6 commit a24cf14

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

esbuild.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ const options = {
1616
format: 'iife',
1717
platform: 'browser',
1818
globalName: 'mqtt',
19-
define: {
20-
'process.env.npm_package_version': JSON.stringify(version),
21-
},
2219
sourcemap: false, // this can be enabled while debugging, if we decide to keep this enabled we should also ship the `src` folder to npm
2320
plugins: [
2421
polyfillNode({
@@ -34,6 +31,27 @@ const options = {
3431
navigator: true, // Needed for WeChat, ref #1789
3532
}
3633
}),
34+
{
35+
name: 'resolve-package-json',
36+
setup(build) {
37+
// when importing 'package.json' we want to provide a custom object like { version: '1.2.3' }
38+
39+
build.onResolve({ filter: /package\.json$/ }, args => {
40+
return {
41+
path: args.path,
42+
namespace: 'package-json'
43+
}
44+
})
45+
46+
build.onLoad({ filter: /.*/, namespace: 'package-json' }, args => {
47+
return {
48+
contents: JSON.stringify({ version }),
49+
loader: 'json'
50+
}
51+
}
52+
)
53+
}
54+
},
3755
],
3856
}
3957

src/lib/client.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
ErrorWithReasonCode,
3232
GenericCallback,
3333
IStream,
34+
MQTTJS_VERSION,
3435
StreamBuilder,
3536
TimerVariant,
3637
VoidCallback,
@@ -396,7 +397,7 @@ export interface MqttClientEventCallbacks {
396397
* (see Connection#connect)
397398
*/
398399
export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbacks> {
399-
public static VERSION = process.env.npm_package_version
400+
public static VERSION = MQTTJS_VERSION
400401

401402
/** Public fields */
402403

src/lib/shared.ts

+3
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,6 @@ export const nextTick =
8282
: (callback: () => void) => {
8383
setTimeout(callback, 0)
8484
}
85+
86+
// eslint-disable-next-line @typescript-eslint/no-var-requires
87+
export const MQTTJS_VERSION = require('../../package.json').version

0 commit comments

Comments
 (0)