From 6cea2958f58fbf5a1fd36f66e612db36b9569079 Mon Sep 17 00:00:00 2001 From: MH35 Date: Fri, 29 Aug 2025 23:24:59 +0900 Subject: [PATCH 1/7] convert to ES module --- src/api.js | 4 ++-- src/events_wrapper.js | 6 +++--- src/helper.js | 9 +++------ src/index.js | 30 +++++++++++++++--------------- src/resources/accounts.js | 4 ++-- src/resources/emojis.js | 4 ++-- src/resources/events.js | 4 ++-- src/resources/filters.js | 4 ++-- src/resources/messages.js | 4 ++-- src/resources/queues.js | 4 ++-- src/resources/reactions.js | 4 ++-- src/resources/server.js | 4 ++-- src/resources/streams.js | 4 ++-- src/resources/typing.js | 4 ++-- src/resources/users.js | 4 ++-- 15 files changed, 45 insertions(+), 48 deletions(-) diff --git a/src/api.js b/src/api.js index 3367890..6f1a668 100644 --- a/src/api.js +++ b/src/api.js @@ -1,4 +1,4 @@ -const helper = require('./helper'); +import helper from './helper'; async function api(baseUrl, config, method, params) { const url = new URL(baseUrl); @@ -45,4 +45,4 @@ async function api(baseUrl, config, method, params) { } } -module.exports = api; +export default api; diff --git a/src/events_wrapper.js b/src/events_wrapper.js index 3d42706..fcc3246 100644 --- a/src/events_wrapper.js +++ b/src/events_wrapper.js @@ -1,5 +1,5 @@ -const queues = require('./resources/queues'); -const events = require('./resources/events'); +import queues from './resources/queues'; +import events from './resources/events'; function sleep(ms) { // TODO add jitter. @@ -73,4 +73,4 @@ function eventsWrapper(config) { return callOnEachEvent; } -module.exports = eventsWrapper; +export default eventsWrapper; diff --git a/src/helper.js b/src/helper.js index 45935fb..8a778d1 100644 --- a/src/helper.js +++ b/src/helper.js @@ -1,7 +1,4 @@ -const fetch = require('isomorphic-fetch'); -const FormData = require('isomorphic-form-data'); +import fetch from 'isomorphic-fetch' +import FormData from 'isomorphic-form-data' -module.exports = { - fetch, - FormData, -}; +export default {fetch, FormData} diff --git a/src/index.js b/src/index.js index b68baf1..4e8898e 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,20 @@ -// eslint-disable-next-line import/no-import-module-exports import parseConfigFile from './zuliprc'; -const api = require('./api'); +import api from './api'; -const accounts = require('./resources/accounts'); -const streams = require('./resources/streams'); -const messages = require('./resources/messages'); -const queues = require('./resources/queues'); -const events = require('./resources/events'); -const users = require('./resources/users'); -const emojis = require('./resources/emojis'); -const typing = require('./resources/typing'); -const reactions = require('./resources/reactions'); -const server = require('./resources/server'); -const filters = require('./resources/filters'); -const eventsWapper = require('./events_wrapper'); +import accounts from './resources/accounts'; + +import streams from './resources/streams'; +import messages from './resources/messages'; +import queues from './resources/queues'; +import events from './resources/events'; +import users from './resources/users'; +import emojis from './resources/emojis'; +import typing from './resources/typing'; +import reactions from './resources/reactions'; +import server from './resources/server'; +import filters from './resources/filters'; +import eventsWapper from './events_wrapper'; function getCallEndpoint(config) { return function callEndpoint(endpoint, method = 'GET', params = {}) { @@ -65,4 +65,4 @@ async function zulip(initialConfig) { return resources(config); } -module.exports = zulip; +export default zulip; diff --git a/src/resources/accounts.js b/src/resources/accounts.js index 26c6220..8387e76 100644 --- a/src/resources/accounts.js +++ b/src/resources/accounts.js @@ -1,4 +1,4 @@ -const helper = require('../helper'); +import helper from '../helper'; function accounts(config) { return { @@ -16,4 +16,4 @@ function accounts(config) { }; } -module.exports = accounts; +export default accounts; diff --git a/src/resources/emojis.js b/src/resources/emojis.js index aa35d96..f914617 100644 --- a/src/resources/emojis.js +++ b/src/resources/emojis.js @@ -1,4 +1,4 @@ -const api = require('../api'); +import api from '../api'; function emojis(config) { return { @@ -9,4 +9,4 @@ function emojis(config) { }; } -module.exports = emojis; +export default emojis; diff --git a/src/resources/events.js b/src/resources/events.js index c95c571..a241103 100644 --- a/src/resources/events.js +++ b/src/resources/events.js @@ -1,4 +1,4 @@ -const api = require('../api'); +import api from '../api'; function events(config) { return { @@ -9,4 +9,4 @@ function events(config) { }; } -module.exports = events; +export default events; diff --git a/src/resources/filters.js b/src/resources/filters.js index 8ecd8b4..6876d3b 100644 --- a/src/resources/filters.js +++ b/src/resources/filters.js @@ -1,4 +1,4 @@ -const api = require('../api'); +import api from '../api'; function filters(config) { return { @@ -9,4 +9,4 @@ function filters(config) { }; } -module.exports = filters; +export default filters; diff --git a/src/resources/messages.js b/src/resources/messages.js index 75bbf23..5956f93 100644 --- a/src/resources/messages.js +++ b/src/resources/messages.js @@ -1,4 +1,4 @@ -const api = require('../api'); +import api from '../api'; function messages(config) { const baseURL = `${config.apiURL}/messages`; @@ -71,4 +71,4 @@ function messages(config) { }; } -module.exports = messages; +export default messages; diff --git a/src/resources/queues.js b/src/resources/queues.js index d5c967b..dd6bb4d 100644 --- a/src/resources/queues.js +++ b/src/resources/queues.js @@ -1,4 +1,4 @@ -const api = require('../api'); +import api from '../api'; function queues(config) { return { @@ -17,4 +17,4 @@ function queues(config) { }; } -module.exports = queues; +export default queues; diff --git a/src/resources/reactions.js b/src/resources/reactions.js index b58f906..ddc1d00 100644 --- a/src/resources/reactions.js +++ b/src/resources/reactions.js @@ -1,4 +1,4 @@ -const api = require('../api'); +import api from '../api'; function reactions(config) { const url = (messageID) => `${config.apiURL}/messages/${messageID}/reactions`; @@ -13,4 +13,4 @@ function reactions(config) { }; } -module.exports = reactions; +export default reactions; diff --git a/src/resources/server.js b/src/resources/server.js index 83d5f95..1de29b4 100644 --- a/src/resources/server.js +++ b/src/resources/server.js @@ -1,4 +1,4 @@ -const api = require('../api'); +import api from '../api'; function server(config) { return { @@ -9,4 +9,4 @@ function server(config) { }; } -module.exports = server; +export default server; diff --git a/src/resources/streams.js b/src/resources/streams.js index d632169..ac47cc4 100644 --- a/src/resources/streams.js +++ b/src/resources/streams.js @@ -1,4 +1,4 @@ -const api = require('../api'); +import api from '../api'; function streams(config) { return { @@ -35,4 +35,4 @@ function streams(config) { }; } -module.exports = streams; +export default streams; diff --git a/src/resources/typing.js b/src/resources/typing.js index 0f9fbd4..5801414 100644 --- a/src/resources/typing.js +++ b/src/resources/typing.js @@ -1,4 +1,4 @@ -const api = require('../api'); +import api from '../api'; function typing(config) { return { @@ -13,4 +13,4 @@ function typing(config) { }; } -module.exports = typing; +export default typing; diff --git a/src/resources/users.js b/src/resources/users.js index 624faa8..ff4178c 100644 --- a/src/resources/users.js +++ b/src/resources/users.js @@ -1,4 +1,4 @@ -const api = require('../api'); +import api from '../api'; function users(config) { return { @@ -45,4 +45,4 @@ function users(config) { }; } -module.exports = users; +export default users; From ef5435e91580fe3fad9e1969d853517cc737e4f5 Mon Sep 17 00:00:00 2001 From: MH35 Date: Fri, 29 Aug 2025 23:28:17 +0900 Subject: [PATCH 2/7] fix: format --- src/helper.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helper.js b/src/helper.js index 8a778d1..f5ac1db 100644 --- a/src/helper.js +++ b/src/helper.js @@ -1,4 +1,4 @@ -import fetch from 'isomorphic-fetch' -import FormData from 'isomorphic-form-data' +import fetch from 'isomorphic-fetch'; +import FormData from 'isomorphic-form-data'; -export default {fetch, FormData} +export default { fetch, FormData }; From 17a1b748b8a4f16220fb454affa7b2c70b5142d5 Mon Sep 17 00:00:00 2001 From: MH35 Date: Fri, 29 Aug 2025 23:45:57 +0900 Subject: [PATCH 3/7] fix: Test to ES module --- test/common.js | 6 +++--- test/index.js | 6 +++--- test/resources/accounts.js | 6 +++--- test/resources/emojis.js | 6 +++--- test/resources/events.js | 6 +++--- test/resources/filters.js | 6 +++--- test/resources/messages.js | 6 +++--- test/resources/queues.js | 6 +++--- test/resources/reactions.js | 6 +++--- test/resources/server.js | 6 +++--- test/resources/streams.js | 6 +++--- test/resources/typing.js | 6 +++--- test/resources/users.js | 6 +++--- 13 files changed, 39 insertions(+), 39 deletions(-) diff --git a/test/common.js b/test/common.js index c4602d1..9f4da66 100644 --- a/test/common.js +++ b/test/common.js @@ -1,5 +1,5 @@ -const sinon = require('sinon'); -const helper = require('../lib/helper'); +import sinon from 'sinon'; +import helper from '../lib/helper'; const getFakes = (validator, output) => { const fetch = (url, options) => { @@ -48,7 +48,7 @@ const config = { realm: 'https://valid.realm.url/api', }; -module.exports = { +export default { getFakes, stubNetwork, config, diff --git a/test/index.js b/test/index.js index 7ce6648..6ba9771 100644 --- a/test/index.js +++ b/test/index.js @@ -1,6 +1,6 @@ -const chai = require('chai'); -const lib = require('../lib/index'); -const common = require('./common'); +import chai from 'chai'; +import lib from '../lib/index'; +import common from './common'; chai.should(); diff --git a/test/resources/accounts.js b/test/resources/accounts.js index 0333127..eb3d7a3 100644 --- a/test/resources/accounts.js +++ b/test/resources/accounts.js @@ -1,6 +1,6 @@ -const chai = require('chai'); -const accounts = require('../../lib/resources/accounts'); -const common = require('../common'); +import chai from 'chai'; +import accounts from '../../lib/resources/accounts'; +import common from '../common'; chai.should(); diff --git a/test/resources/emojis.js b/test/resources/emojis.js index 2d9e26c..2b7cfb8 100644 --- a/test/resources/emojis.js +++ b/test/resources/emojis.js @@ -1,6 +1,6 @@ -const chai = require('chai'); -const emojis = require('../../lib/resources/emojis'); -const common = require('../common'); +import chai from 'chai'; +import emojis from '../../lib/resources/emojis'; +import common from '../common'; chai.should(); diff --git a/test/resources/events.js b/test/resources/events.js index 0e53c3d..7f84f0b 100644 --- a/test/resources/events.js +++ b/test/resources/events.js @@ -1,6 +1,6 @@ -const chai = require('chai'); -const events = require('../../lib/resources/events'); -const common = require('../common'); +import chai from 'chai'; +import events from '../../lib/resources/events'; +import common from '../common'; chai.should(); diff --git a/test/resources/filters.js b/test/resources/filters.js index 9cfff3b..08aca75 100644 --- a/test/resources/filters.js +++ b/test/resources/filters.js @@ -1,6 +1,6 @@ -const chai = require('chai'); -const filters = require('../../lib/resources/filters'); -const common = require('../common'); +import chai from 'chai'; +import filters from '../../lib/resources/filters'; +import common from '../common'; chai.should(); diff --git a/test/resources/messages.js b/test/resources/messages.js index 83f66fb..d5d83cb 100644 --- a/test/resources/messages.js +++ b/test/resources/messages.js @@ -1,6 +1,6 @@ -const chai = require('chai'); -const messages = require('../../lib/resources/messages'); -const common = require('../common'); +import chai from 'chai'; +import messages from '../../lib/resources/messages'; +import common from '../common'; chai.should(); diff --git a/test/resources/queues.js b/test/resources/queues.js index f92ca3a..18b0d83 100644 --- a/test/resources/queues.js +++ b/test/resources/queues.js @@ -1,6 +1,6 @@ -const chai = require('chai'); -const queues = require('../../lib/resources/queues'); -const common = require('../common'); +import chai from 'chai'; +import queues from '../../lib/resources/queues'; +import common from '../common'; chai.should(); diff --git a/test/resources/reactions.js b/test/resources/reactions.js index 6d1693b..564302d 100644 --- a/test/resources/reactions.js +++ b/test/resources/reactions.js @@ -1,6 +1,6 @@ -const chai = require('chai'); -const reactions = require('../../lib/resources/reactions'); -const common = require('../common'); +import chai from 'chai'; +import reactions from '../../lib/resources/reactions'; +import common from '../common'; chai.should(); diff --git a/test/resources/server.js b/test/resources/server.js index cb73395..c881a95 100644 --- a/test/resources/server.js +++ b/test/resources/server.js @@ -1,6 +1,6 @@ -const chai = require('chai'); -const server = require('../../lib/resources/server'); -const common = require('../common'); +import chai from 'chai'; +import server from '../../lib/resources/server'; +import common from '../common'; chai.should(); diff --git a/test/resources/streams.js b/test/resources/streams.js index 47dc950..792e005 100644 --- a/test/resources/streams.js +++ b/test/resources/streams.js @@ -1,6 +1,6 @@ -const chai = require('chai'); -const streams = require('../../lib/resources/streams'); -const common = require('../common'); +import chai from 'chai'; +import streams from '../../lib/resources/streams'; +import common from '../common'; chai.should(); diff --git a/test/resources/typing.js b/test/resources/typing.js index 2bacd9f..3b97791 100644 --- a/test/resources/typing.js +++ b/test/resources/typing.js @@ -1,6 +1,6 @@ -const chai = require('chai'); -const typing = require('../../lib/resources/typing'); -const common = require('../common'); +import chai from 'chai'; +import typing from '../../lib/resources/typing'; +import common from '../common'; chai.should(); diff --git a/test/resources/users.js b/test/resources/users.js index fbd71e5..3f3cd2f 100644 --- a/test/resources/users.js +++ b/test/resources/users.js @@ -1,6 +1,6 @@ -const chai = require('chai'); -const users = require('../../lib/resources/users'); -const common = require('../common'); +import chai from 'chai'; +import users from '../../lib/resources/users'; +import common from '../common'; chai.should(); From 3237e83e20851ae2fbf975a1b01782dac3ae66b8 Mon Sep 17 00:00:00 2001 From: MH35 Date: Fri, 29 Aug 2025 23:54:15 +0900 Subject: [PATCH 4/7] fix: command line parameter --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index aaee3e8..5433853 100644 --- a/package.json +++ b/package.json @@ -30,8 +30,8 @@ "scripts": { "build": "babel --delete-dir-on-start -d lib/ src/", "prepare": "npm run build", - "lint": "eslint . && prettier --loglevel=warn --check .", - "lint:fix": "eslint --fix . && prettier --loglevel=warn --write .", + "lint": "eslint . && prettier --log-level=warn --check .", + "lint:fix": "eslint --fix . && prettier --log-level=warn --write .", "test": "npm run lint && npm run build && mocha test/*", "call": "node examples/interactive_call_endpoint.js" }, From 262e75dccede76c450fdbe32d49ffc7f4f3ab493 Mon Sep 17 00:00:00 2001 From: mh35 Date: Mon, 1 Sep 2025 10:12:07 +0900 Subject: [PATCH 5/7] fix: Use ESM in examples --- examples/accounts.js | 2 +- examples/call_endpoint.js | 2 +- examples/emojis.js | 2 +- examples/events.js | 2 +- examples/filters.js | 2 +- examples/init.js | 4 ++-- examples/interactive_call_endpoint.js | 8 +++++--- examples/messages.js | 2 +- examples/private-messages.js | 2 +- examples/queue_helper.js | 4 ++-- examples/queues.js | 2 +- examples/reactions.js | 2 +- examples/server.js | 2 +- examples/streams.js | 2 +- examples/subscriptions.js | 4 ++-- examples/typing-notifications/send-and-recieve.js | 2 +- examples/typing-notifications/send-often.js | 2 +- examples/typing-notifications/send.js | 2 +- examples/users.js | 2 +- 19 files changed, 26 insertions(+), 24 deletions(-) diff --git a/examples/accounts.js b/examples/accounts.js index 708feb6..c7fbaf6 100644 --- a/examples/accounts.js +++ b/examples/accounts.js @@ -1,4 +1,4 @@ -const zulip = require('../lib'); +import zulip from '../lib'; process.on('unhandledRejection', (err) => { console.error(err); diff --git a/examples/call_endpoint.js b/examples/call_endpoint.js index 1356b08..21281a9 100644 --- a/examples/call_endpoint.js +++ b/examples/call_endpoint.js @@ -1,4 +1,4 @@ -const zulip = require('../lib'); +import zulip from '../lib'; const config = { username: process.env.ZULIP_USERNAME, diff --git a/examples/emojis.js b/examples/emojis.js index 5929f6f..f340cc3 100644 --- a/examples/emojis.js +++ b/examples/emojis.js @@ -1,4 +1,4 @@ -const zulip = require('../lib'); +import zulip from '../lib'; const config = { username: process.env.ZULIP_USERNAME, diff --git a/examples/events.js b/examples/events.js index e0b5390..be36299 100644 --- a/examples/events.js +++ b/examples/events.js @@ -1,4 +1,4 @@ -const zulip = require('../lib'); +import zulip from '../lib'; const config = { username: process.env.ZULIP_USERNAME, diff --git a/examples/filters.js b/examples/filters.js index bffed51..d74aab1 100644 --- a/examples/filters.js +++ b/examples/filters.js @@ -1,4 +1,4 @@ -const zulip = require('../lib'); +import zulip from '../lib'; const config = { username: process.env.ZULIP_USERNAME, diff --git a/examples/init.js b/examples/init.js index b011718..6030bdd 100644 --- a/examples/init.js +++ b/examples/init.js @@ -1,5 +1,5 @@ -const path = require('path'); -const zulip = require('../lib'); +import path from 'path'; +import zulip from '../lib'; (async () => { // Initialization with zuliprc diff --git a/examples/interactive_call_endpoint.js b/examples/interactive_call_endpoint.js index 2aed684..a2ac494 100644 --- a/examples/interactive_call_endpoint.js +++ b/examples/interactive_call_endpoint.js @@ -1,6 +1,8 @@ -const path = require('path'); -const homedir = require('os').homedir(); -const zulip = require('../lib'); +import path from 'path'; +import os from 'os'; +import zulip from '../lib'; + +const homedir = os.homedir(); if (process.argv[2] === 'help') { console.log('This is a helper script to test Zulip APIs.'); diff --git a/examples/messages.js b/examples/messages.js index dacb44c..8e4d19d 100644 --- a/examples/messages.js +++ b/examples/messages.js @@ -1,4 +1,4 @@ -const zulip = require('../lib'); +import zulip from '../lib'; const stream = 'test-bot'; diff --git a/examples/private-messages.js b/examples/private-messages.js index 7ee2a57..f23fef3 100644 --- a/examples/private-messages.js +++ b/examples/private-messages.js @@ -1,4 +1,4 @@ -const zulip = require('../lib'); +import zulip from '../lib'; const config = { username: process.env.ZULIP_USERNAME, diff --git a/examples/queue_helper.js b/examples/queue_helper.js index 3bf6911..df53ff0 100644 --- a/examples/queue_helper.js +++ b/examples/queue_helper.js @@ -1,5 +1,5 @@ -const path = require('path'); -const zulip = require('../lib'); +import path from 'path'; +import zulip from '../lib'; const zuliprc = path.resolve('/path/to/your/zuliprc'); diff --git a/examples/queues.js b/examples/queues.js index a2a7fde..1e39ccd 100644 --- a/examples/queues.js +++ b/examples/queues.js @@ -1,4 +1,4 @@ -const zulip = require('../lib'); +import zulip from '../lib'; const config = { username: process.env.ZULIP_USERNAME, diff --git a/examples/reactions.js b/examples/reactions.js index 08f8a0a..0f9f324 100644 --- a/examples/reactions.js +++ b/examples/reactions.js @@ -1,4 +1,4 @@ -const zulip = require('../lib'); +import zulip from '../lib'; const config = { username: process.env.ZULIP_USERNAME, diff --git a/examples/server.js b/examples/server.js index 8fa113a..7ee48e8 100644 --- a/examples/server.js +++ b/examples/server.js @@ -1,4 +1,4 @@ -const zulip = require('../lib'); +import zulip from '../lib'; const config = { username: process.env.ZULIP_USERNAME, diff --git a/examples/streams.js b/examples/streams.js index bb4f0e2..1a747de 100644 --- a/examples/streams.js +++ b/examples/streams.js @@ -1,4 +1,4 @@ -const zulip = require('../lib'); +import zulip from '../lib'; const config = { username: process.env.ZULIP_USERNAME, diff --git a/examples/subscriptions.js b/examples/subscriptions.js index 4ed7c39..d767216 100644 --- a/examples/subscriptions.js +++ b/examples/subscriptions.js @@ -1,11 +1,11 @@ +import zulip from '../lib'; + const config = { username: process.env.ZULIP_USERNAME, apiKey: process.env.ZULIP_API_KEY, realm: process.env.ZULIP_REALM, }; -const zulip = require('../lib'); - (async () => { const z = await zulip(config); diff --git a/examples/typing-notifications/send-and-recieve.js b/examples/typing-notifications/send-and-recieve.js index df4c82c..d146c31 100644 --- a/examples/typing-notifications/send-and-recieve.js +++ b/examples/typing-notifications/send-and-recieve.js @@ -1,4 +1,4 @@ -const zulip = require('../../lib'); +import zulip from '../../lib'; if (process.argv.length < 7) { console.log( diff --git a/examples/typing-notifications/send-often.js b/examples/typing-notifications/send-often.js index 6d60d19..a637f36 100644 --- a/examples/typing-notifications/send-often.js +++ b/examples/typing-notifications/send-often.js @@ -1,4 +1,4 @@ -const zulip = require('../../lib'); +import zulip from '../../lib'; if (process.argv.length < 6) { console.log( diff --git a/examples/typing-notifications/send.js b/examples/typing-notifications/send.js index 550f32a..cee029d 100644 --- a/examples/typing-notifications/send.js +++ b/examples/typing-notifications/send.js @@ -1,4 +1,4 @@ -const zulip = require('../../lib'); +import zulip from '../../lib'; const recipient = Number(process.env.ZULIP_TYPING_RECIPIENT); diff --git a/examples/users.js b/examples/users.js index 580ef7a..fa6ec3e 100644 --- a/examples/users.js +++ b/examples/users.js @@ -1,4 +1,4 @@ -const zulip = require('../lib'); +import zulip from '../lib'; const config = { username: process.env.ZULIP_USERNAME, From b13773537920b112e318c86472cd08d2608c4f59 Mon Sep 17 00:00:00 2001 From: mh35 Date: Mon, 1 Sep 2025 10:15:23 +0900 Subject: [PATCH 6/7] fix: Test --- .mocharc.yml | 1 + package-lock.json | 231 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 233 insertions(+) create mode 100644 .mocharc.yml diff --git a/.mocharc.yml b/.mocharc.yml new file mode 100644 index 0000000..15a5e8f --- /dev/null +++ b/.mocharc.yml @@ -0,0 +1 @@ +require: '@babel/register' diff --git a/package-lock.json b/package-lock.json index dcd54ab..ef56ab9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "@babel/core": "^7.25.8", "@babel/plugin-transform-runtime": "^7.25.7", "@babel/preset-env": "^7.25.8", + "@babel/register": "^7.28.3", "chai": "^4.5.0", "eslint": "^8.57.1", "eslint-config-airbnb": "^19.0.4", @@ -1558,6 +1559,26 @@ "@babel/core": "^7.0.0-0 || ^8.0.0-0 <8.0.0" } }, + "node_modules/@babel/register": { + "version": "7.28.3", + "resolved": "https://registry.npmjs.org/@babel/register/-/register-7.28.3.tgz", + "integrity": "sha512-CieDOtd8u208eI49bYl4z1J22ySFw87IGwE+IswFEExH7e3rLgKb0WNQeumnacQ1+VoDJLYI5QFA3AJZuyZQfA==", + "dev": true, + "license": "MIT", + "dependencies": { + "clone-deep": "^4.0.1", + "find-cache-dir": "^2.0.0", + "make-dir": "^2.1.0", + "pirates": "^4.0.6", + "source-map-support": "^0.5.16" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/@babel/runtime": { "version": "7.25.7", "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.25.7.tgz", @@ -2351,6 +2372,13 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, + "node_modules/buffer-from": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", + "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", + "dev": true, + "license": "MIT" + }, "node_modules/call-bind": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", @@ -2499,6 +2527,21 @@ "wrap-ansi": "^7.0.0" } }, + "node_modules/clone-deep": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/clone-deep/-/clone-deep-4.0.1.tgz", + "integrity": "sha512-neHB9xuzh/wk0dIHweyAXv2aPGZIVk3pLMe+/RNzINf17fe0OG96QroktYAUm7SM1PBnzTabaLboqqxDyMU+SQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-plain-object": "^2.0.4", + "kind-of": "^6.0.2", + "shallow-clone": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", @@ -2538,6 +2581,13 @@ "node": ">= 6" } }, + "node_modules/commondir": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", + "integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==", + "dev": true, + "license": "MIT" + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -3622,6 +3672,21 @@ "node": ">=8" } }, + "node_modules/find-cache-dir": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-2.1.0.tgz", + "integrity": "sha512-Tq6PixE0w/VMFfCgbONnkiQIVol/JJL7nRMi20fqzA4NRs9AfeqMGeRdPi3wIhYkxjeBaWh2rxwapn5Tu3IqOQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "commondir": "^1.0.1", + "make-dir": "^2.0.0", + "pkg-dir": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/find-up": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", @@ -4380,6 +4445,19 @@ "node": ">=8" } }, + "node_modules/is-plain-object": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", + "integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==", + "dev": true, + "license": "MIT", + "dependencies": { + "isobject": "^3.0.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/is-regex": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", @@ -4544,6 +4622,16 @@ "dev": true, "license": "ISC" }, + "node_modules/isobject": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/isomorphic-fetch": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-3.0.0.tgz", @@ -4680,6 +4768,16 @@ "json-buffer": "3.0.1" } }, + "node_modules/kind-of": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", + "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/language-subtag-registry": { "version": "0.3.23", "resolved": "https://registry.npmjs.org/language-subtag-registry/-/language-subtag-registry-0.3.23.tgz", @@ -5327,6 +5425,16 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/p-try": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", @@ -5427,6 +5535,95 @@ "node": ">=6" } }, + "node_modules/pirates": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.7.tgz", + "integrity": "sha512-TfySrs/5nm8fQJDcBDuUng3VOUKsd7S+zqvbOTiGXHfxX4wK31ard+hoNuvkicM/2YFzlpDgABOevKSsB4G/FA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 6" + } + }, + "node_modules/pkg-dir": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-3.0.0.tgz", + "integrity": "sha512-/E57AYkoeQ25qkxMj5PBOVgF8Kiu/h7cYS30Z5+R7WaiCCBfLq58ZI/dSeaEKb9WVJV5n/03QwrN3IeWIFllvw==", + "dev": true, + "license": "MIT", + "dependencies": { + "find-up": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/pkg-dir/node_modules/find-up": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", + "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "dev": true, + "license": "MIT", + "dependencies": { + "locate-path": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/pkg-dir/node_modules/locate-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", + "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", + "dev": true, + "license": "MIT", + "dependencies": { + "p-locate": "^3.0.0", + "path-exists": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/pkg-dir/node_modules/p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "dev": true, + "license": "MIT", + "dependencies": { + "p-try": "^2.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/pkg-dir/node_modules/p-locate": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", + "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "p-limit": "^2.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/pkg-dir/node_modules/path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, "node_modules/possible-typed-array-names": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz", @@ -5854,6 +6051,19 @@ "node": ">= 0.4" } }, + "node_modules/shallow-clone": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/shallow-clone/-/shallow-clone-3.0.1.tgz", + "integrity": "sha512-/6KqX+GVUdqPuPPd2LxDDxzX6CAbjJehAAOKlNpqqUpAqPM6HeL8f+o3a+JsyGjn2lv0WY8UsTgUJjU9Ok55NA==", + "dev": true, + "license": "MIT", + "dependencies": { + "kind-of": "^6.0.2" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", @@ -5958,6 +6168,27 @@ "node": ">=6" } }, + "node_modules/source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/source-map-support": { + "version": "0.5.21", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", + "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", + "dev": true, + "license": "MIT", + "dependencies": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + }, "node_modules/stop-iteration-iterator": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/stop-iteration-iterator/-/stop-iteration-iterator-1.0.0.tgz", diff --git a/package.json b/package.json index 5433853..30c41e1 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "@babel/core": "^7.25.8", "@babel/plugin-transform-runtime": "^7.25.7", "@babel/preset-env": "^7.25.8", + "@babel/register": "^7.28.3", "chai": "^4.5.0", "eslint": "^8.57.1", "eslint-config-airbnb": "^19.0.4", From cb58fdefd965734c5538ad785d3492b645249a82 Mon Sep 17 00:00:00 2001 From: mh35 Date: Mon, 1 Sep 2025 10:29:08 +0900 Subject: [PATCH 7/7] fix: Update README to use ESM --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8d779c4..04504ac 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Javascript library to access the Zulip API ### With API Key ```js -const zulipInit = require('zulip-js'); +import zulipInit from 'zulip-js'; const config = { username: process.env.ZULIP_USERNAME, apiKey: process.env.ZULIP_API_KEY, @@ -28,7 +28,7 @@ const config = { You will need to first retrieve the API key by calling `await zulipInit(config)`. ```js -const zulipInit = require('zulip-js'); +import zulipInit from 'zulip-js'; const config = { username: process.env.ZULIP_USERNAME, password: process.env.ZULIP_PASSWORD, @@ -57,7 +57,7 @@ site=http://localhost:9991 Please remember to add this file to your `.gitignore`! Calling `await zulipInit({ zuliprc: 'zuliprc' })` will read this file. ```js -const zulipInit = require('zulip-js'); +import zulipInit from 'zulip-js'; const path = require('path'); const zuliprc = path.resolve(__dirname, 'zuliprc'); (async () => { @@ -141,9 +141,9 @@ Use `npm test` to run the tests. Currently, we have a simple testing framework which stubs our network requests and also allows us to test the input passed to it. This is what a sample test for an API endpoint looks like: ```js -const chai = require('chai'); -const users = require('../../lib/resources/users'); // File to test. -const common = require('../common'); // Common functions for tests. +import chai from 'chai'; +import users from '../../lib/resources/users'; // File to test. +import common from '../common'; // Common functions for tests. chai.should();