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: add default export #1740

Merged
merged 3 commits into from
Nov 14, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const outdir = 'dist'
* @type {import('esbuild').BuildOptions}
*/
const options = {
entryPoints: ['build/mqtt.js'],
entryPoints: ['build/index.js'],
bundle: true,
outfile: `${outdir}/mqtt.js`,
format: 'iife',
Expand Down
12 changes: 0 additions & 12 deletions example.js

This file was deleted.

25 changes: 25 additions & 0 deletions example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import mqtt from '.'

const client = mqtt.connect('mqtt://test.mosquitto.org')

const testTopic = 'presence'

client.subscribe(testTopic, (err) => {
if (!err) {
console.log('subscribed to', testTopic)
client.publish(testTopic, 'Hello mqtt', (err2) => {
if (!err2) {
console.log('message published')
} else {
console.error(err2)
}
})
} else {
console.error(err)
}
})

client.on('message', (topic, message) => {
console.log('received message "%s" from topic "%s"', message, topic)
client.end()
})
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"type": "git",
"url": "git://github.com/mqttjs/MQTT.js.git"
},
"main": "./build/mqtt.js",
"main": "./build/index.js",
"module": "./dist/mqtt.esm.js",
"bin": {
"mqtt_pub": "./build/bin/pub.js",
Expand All @@ -39,20 +39,20 @@
".": {
"browser": {
"import": "./dist/mqtt.esm.js",
"default": "./dist/mqtt.js"
"default": "./dist/index.js"
},
"default": "./build/mqtt.js"
"default": "./build/index.js"
},
"./package.json": "./package.json",
"./*.map": "./build/*.js.map",
"./dist/*": "./dist/*.js",
"./*": "./build/*.js"
},
"types": "build/mqtt.d.ts",
"types": "build/index.d.ts",
"typesVersions": {
"*": {
"*": [
"./build/mqtt.d.ts"
"./build/index.d.ts"
]
}
},
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as mqtt from './mqtt'

export default mqtt
export * from './mqtt'
5 changes: 2 additions & 3 deletions test/abstract_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ import { assert } from 'chai'
import sinon from 'sinon'
import fs from 'fs'
import levelStore from 'mqtt-level-store'
import * as mqtt from '../src/mqtt'
import Store from '../src/lib/store'
import serverBuilder from './server_helpers_for_client_tests'
import handlePubrel from '../src/lib/handlers/pubrel'
import handle from '../src/lib/handlers/index'
import handlePublish from '../src/lib/handlers/publish'
import {
import mqtt, {
IClientOptions,
IClientPublishOptions,
IClientSubscribeOptions,
ISubscriptionMap,
ISubscriptionRequest,
} from '../src/lib/client'
} from '../src'
import { IPublishPacket, IPubrelPacket, ISubackPacket, QoS } from 'mqtt-packet'
import { DoneCallback, ErrorWithReasonCode } from 'src/lib/shared'
import { fail } from 'assert'
Expand Down
6 changes: 1 addition & 5 deletions test/abstract_store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IPublishPacket, IPubrelPacket } from 'mqtt-packet'
import { IStore } from '../src/lib/store'
import { IStore } from '../src'
import 'should'
import { it, beforeEach, afterEach } from 'node:test'

Expand All @@ -8,17 +8,13 @@ export default function abstractStoreTest(
) {
let store: IStore

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
beforeEach((_ctx, done) => {
build((err, _store) => {
store = _store
done(err)
})
})

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
afterEach((_ctx, done) => {
store.close(done)
})
Expand Down
2 changes: 1 addition & 1 deletion test/browser/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from '@esm-bundle/chai';
import mqtt from '../../'; // this will resolve to mqtt/dist/mqtt.esm.js

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

function run(proto, port, cb) {
Expand Down
2 changes: 1 addition & 1 deletion test/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as mqtt from '../src/mqtt'
import mqtt from '../src'
import { assert } from 'chai'
import { fork } from 'child_process'
import path from 'path'
Expand Down
3 changes: 1 addition & 2 deletions test/client_mqtt5.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { assert } from 'chai'
import * as mqtt from '../src/mqtt'
import abstractClientTests from './abstract_client'
import { MqttServer } from './server'
import serverBuilder from './server_helpers_for_client_tests'
import getPorts from './helpers/port_list'
import { ErrorWithReasonCode } from '../src/lib/shared'
import mqtt, { ErrorWithReasonCode } from '../src'
import { after, describe, it } from 'node:test'

const ports = getPorts(1)
Expand Down
3 changes: 1 addition & 2 deletions test/message-id-provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { assert } from 'chai'
import DefaultMessageIdProvider from '../src/lib/default-message-id-provider'
import UniqueMessageIdProvider from '../src/lib/unique-message-id-provider'
import { DefaultMessageIdProvider, UniqueMessageIdProvider } from '../src'
import { describe, it } from 'node:test'

describe('message id provider', () => {
Expand Down
3 changes: 1 addition & 2 deletions test/mqtt.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import fs from 'fs'
import path from 'path'
import * as mqtt from '../src/mqtt'
import { IClientOptions } from '../src/lib/client'
import mqtt, { IClientOptions } from '../src'
import { describe, it } from 'node:test'
import 'should'

Expand Down
2 changes: 1 addition & 1 deletion test/mqtt_store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Store from '../src/lib/store'
import { Store } from '../src'
import { describe, it } from 'node:test'
import 'should'

Expand Down
2 changes: 1 addition & 1 deletion test/secure_client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path'
import fs from 'fs'
import * as mqtt from '../src/mqtt'
import mqtt from '../src'
import abstractClientTests from './abstract_client'
import { MqttSecureServer, MqttServerListener } from './server'
import { assert } from 'chai'
Expand Down
3 changes: 1 addition & 2 deletions test/unique_message_id_provider_client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import abstractClientTests from './abstract_client'
import serverBuilder from './server_helpers_for_client_tests'
import UniqueMessageIdProvider from '../src/lib/unique-message-id-provider'
import { UniqueMessageIdProvider, IClientOptions } from '../src'
import getPorts from './helpers/port_list'
import { IClientOptions } from 'src/mqtt'
import { describe, after } from 'node:test'

const ports = getPorts(3)
Expand Down
3 changes: 1 addition & 2 deletions test/websocket_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import assert from 'assert'
import abstractClientTests from './abstract_client'
import getPorts from './helpers/port_list'
import { MqttServerNoWait } from './server'
import * as mqtt from '../src/mqtt'
import { IClientOptions } from '../src/lib/client'
import mqtt, { IClientOptions } from '../src'
import { after, describe, it } from 'node:test'

const ports = getPorts(4)
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "build"],
"exclude": ["node_modules", "test", "dist", "build", "example.ts"],
}

1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"include": [
"src",
"test",
"example.ts"
],
"exclude": [
"dist",
Expand Down