Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrong mqttjs version printed #1847

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading