Skip to content

Commit fdb498f

Browse files
authored
fix: add default export (#1740)
1 parent 365e7a0 commit fdb498f

18 files changed

+49
-41
lines changed

esbuild.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const outdir = 'dist'
99
* @type {import('esbuild').BuildOptions}
1010
*/
1111
const options = {
12-
entryPoints: ['build/mqtt.js'],
12+
entryPoints: ['build/index.js'],
1313
bundle: true,
1414
outfile: `${outdir}/mqtt.js`,
1515
format: 'iife',

example.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

example.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import mqtt from '.'
2+
3+
const client = mqtt.connect('mqtt://test.mosquitto.org')
4+
5+
const testTopic = 'presence'
6+
7+
client.subscribe(testTopic, (err) => {
8+
if (!err) {
9+
console.log('subscribed to', testTopic)
10+
client.publish(testTopic, 'Hello mqtt', (err2) => {
11+
if (!err2) {
12+
console.log('message published')
13+
} else {
14+
console.error(err2)
15+
}
16+
})
17+
} else {
18+
console.error(err)
19+
}
20+
})
21+
22+
client.on('message', (topic, message) => {
23+
console.log('received message "%s" from topic "%s"', message, topic)
24+
client.end()
25+
})

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"type": "git",
2121
"url": "git://github.com/mqttjs/MQTT.js.git"
2222
},
23-
"main": "./build/mqtt.js",
23+
"main": "./build/index.js",
2424
"module": "./dist/mqtt.esm.js",
2525
"bin": {
2626
"mqtt_pub": "./build/bin/pub.js",
@@ -39,20 +39,20 @@
3939
".": {
4040
"browser": {
4141
"import": "./dist/mqtt.esm.js",
42-
"default": "./dist/mqtt.js"
42+
"default": "./dist/index.js"
4343
},
44-
"default": "./build/mqtt.js"
44+
"default": "./build/index.js"
4545
},
4646
"./package.json": "./package.json",
4747
"./*.map": "./build/*.js.map",
4848
"./dist/*": "./dist/*.js",
4949
"./*": "./build/*.js"
5050
},
51-
"types": "build/mqtt.d.ts",
51+
"types": "build/index.d.ts",
5252
"typesVersions": {
5353
"*": {
5454
"*": [
55-
"./build/mqtt.d.ts"
55+
"./build/index.d.ts"
5656
]
5757
}
5858
},

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import * as mqtt from './mqtt'
2+
3+
export default mqtt
4+
export * from './mqtt'

test/abstract_client.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@ import { assert } from 'chai'
55
import sinon from 'sinon'
66
import fs from 'fs'
77
import levelStore from 'mqtt-level-store'
8-
import * as mqtt from '../src/mqtt'
98
import Store from '../src/lib/store'
109
import serverBuilder from './server_helpers_for_client_tests'
1110
import handlePubrel from '../src/lib/handlers/pubrel'
1211
import handle from '../src/lib/handlers/index'
1312
import handlePublish from '../src/lib/handlers/publish'
14-
import {
13+
import mqtt, {
1514
IClientOptions,
1615
IClientPublishOptions,
1716
IClientSubscribeOptions,
1817
ISubscriptionMap,
1918
ISubscriptionRequest,
20-
} from '../src/lib/client'
19+
} from '../src'
2120
import { IPublishPacket, IPubrelPacket, ISubackPacket, QoS } from 'mqtt-packet'
2221
import { DoneCallback, ErrorWithReasonCode } from 'src/lib/shared'
2322
import { fail } from 'assert'

test/abstract_store.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IPublishPacket, IPubrelPacket } from 'mqtt-packet'
2-
import { IStore } from '../src/lib/store'
2+
import { IStore } from '../src'
33
import 'should'
44
import { it, beforeEach, afterEach } from 'node:test'
55

@@ -8,17 +8,13 @@ export default function abstractStoreTest(
88
) {
99
let store: IStore
1010

11-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
12-
// @ts-expect-error
1311
beforeEach((_ctx, done) => {
1412
build((err, _store) => {
1513
store = _store
1614
done(err)
1715
})
1816
})
1917

20-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
21-
// @ts-expect-error
2218
afterEach((_ctx, done) => {
2319
store.close(done)
2420
})

test/browser/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from '@esm-bundle/chai';
22
import mqtt from '../../'; // this will resolve to mqtt/dist/mqtt.esm.js
33

44
// needed to test no-esm version /dist/mqtt.js
5-
/** @type { import('../../src/mqtt').MqttClient }*/
5+
/** @type { import('../../src').MqttClient }*/
66
const mqtt2 = window.mqtt
77

88
function run(proto, port, cb) {

test/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as mqtt from '../src/mqtt'
1+
import mqtt from '../src'
22
import { assert } from 'chai'
33
import { fork } from 'child_process'
44
import path from 'path'

test/client_mqtt5.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { assert } from 'chai'
2-
import * as mqtt from '../src/mqtt'
32
import abstractClientTests from './abstract_client'
43
import { MqttServer } from './server'
54
import serverBuilder from './server_helpers_for_client_tests'
65
import getPorts from './helpers/port_list'
7-
import { ErrorWithReasonCode } from '../src/lib/shared'
6+
import mqtt, { ErrorWithReasonCode } from '../src'
87
import { after, describe, it } from 'node:test'
98

109
const ports = getPorts(1)

0 commit comments

Comments
 (0)