Skip to content

Commit

Permalink
fix: 馃悰 remove swc dependencies (#2550)
Browse files Browse the repository at this point in the history
* fix: 馃悰 remove swc dependencies

* fix: 馃悰 lint issue

* fix: 馃悰 remove useless return to fit lint

* fix: 馃悰 tsconfig

* fix: 馃悰 type

* fix: 馃悰 no-undef-init lint

* fix: 馃悰 markdown fragment link

* fix: 馃悰 comment link to issue #2553

* Update tsconfig.json

Add comment to #2551

---------

Co-authored-by: Huan Li <zixia@zixia.net>
  • Loading branch information
hcfw007 and huan committed Jun 29, 2023
1 parent 8bec2d5 commit 31601af
Show file tree
Hide file tree
Showing 18 changed files with 54 additions and 46 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,15 +482,15 @@ This project exists thanks to all the people who contribute. [[Contribute](CONTR

## :sunglasses: Backers

[![Backers on Open Collective](https://opencollective.com/wechaty/backers/badge.svg)](#backers)
[![Backers on Open Collective](https://opencollective.com/wechaty/backers/badge.svg)](#sunglasses-backers)

Thank you to all our backers! 馃檹 [[Become a backer](https://opencollective.com/wechaty#backer)]

[![Open Collective Wechaty](https://opencollective.com/wechaty/backers.svg?width=890)](https://opencollective.com/wechaty#backers)

## :smirk: Sponsors

[![Sponsors on Open Collective](https://opencollective.com/wechaty/sponsors/badge.svg)](#sponsors)
[![Sponsors on Open Collective](https://opencollective.com/wechaty/sponsors/badge.svg)](#smirk-sponsors)

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/wechaty#sponsor)]

Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@
"@chatie/git-scripts": "^0.6.2",
"@chatie/semver": "^0.4.7",
"@chatie/tsconfig": "^4.6.3",
"@swc/core": "^1.2.155",
"@swc/helpers": "^0.3.6",
"@types/cross-spawn": "^6.0.2",
"@types/dotenv": "^8.2.0",
"@types/glob": "^7.2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class Doctor {
public chromedriverVersion (): string {
let version: string
try {
const cmd = spawn('chromedriver', ['--version'])
const cmd = spawn('chromedriver', [ '--version' ])
version = String(cmd.error) || cmd.stdout.toString() || cmd.stderr.toString()
} catch (e) {
version = (e as Error).message
Expand Down
6 changes: 3 additions & 3 deletions src/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ test('Wechaty Plugin uninstaller should be called after wechaty.stop()', async t

test('isWechatyPluginUninstaller()', async t => {
const FIXTURES = [
[undefined, false],
[() => {}, true],
[ undefined, false ],
[ () => {}, true ],
] as const

for (const [uninstaller, expected] of FIXTURES) {
for (const [ uninstaller, expected ] of FIXTURES) {
t.equal(isWechatyPluginUninstaller(uninstaller), expected, `isWechatyPluginUninstaller(${uninstaller}) === ${expected}`)
}
})
4 changes: 2 additions & 2 deletions src/pure-functions/xml.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ test('unifyEmoji()', async t => {
],
]

ORIGNAL_XML_LIST.forEach(([xmlList, expectedEmojiXml]) => {
ORIGNAL_XML_LIST.forEach(([ xmlList, expectedEmojiXml ]) => {
xmlList.forEach(xml => {
const unifiedXml = unifyEmoji(xml)
t.equal(unifiedXml, expectedEmojiXml, 'should convert the emoji xml to the expected unified xml')
Expand All @@ -106,7 +106,7 @@ test('stripEmoji()', async t => {
],
]

EMOJI_STR.forEach(([emojiStr, expectResult]) => {
EMOJI_STR.forEach(([ emojiStr, expectResult ]) => {
const result = stripEmoji(emojiStr)
t.equal(result, expectResult, 'should strip to the expected str')
})
Expand Down
5 changes: 4 additions & 1 deletion src/sayable/deliver-sayable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import type { Sayable } from './types.js'
* TODO: add unit test to ensure the interface validation code works
*/
const deliverSayableConversationPuppet = (puppet: PUPPET.impls.PuppetInterface) => (conversationId: string) => async (sayable: Sayable) => {
let msgId: string | void
// if we don't do this, we'll get a TS2454 error:
// src/sayable/deliver-sayable.ts:102:10 - error TS2454: Variable 'msgId' is used before being assigned.
/* eslint-disable no-undef-init */
let msgId: string | void = undefined

if (typeof sayable === 'number') {
sayable = String(sayable)
Expand Down
7 changes: 6 additions & 1 deletion src/user-mixins/poolify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ const poolifyMixin = <MixinBase extends Constructor>(mixinBase: MixinBase) => <T
return this._pool! // FIXME: why we need "!" at here?
}

public static load<L extends Constructor<T> & PoolifyMixin<T>> (
/**
* Nan(202111): We use it as a workaround to meet the requirement of Constructor parameters
*
* See: https://github.com/wechaty/wechaty/issues/2553
*/
public static load<L extends Constructor<T & {}> & PoolifyMixin<T>> (
this : L,
id : string,
): T {
Expand Down
16 changes: 8 additions & 8 deletions src/user-mixins/validation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ test('validationMixin() valid()', async t => {
interface UserClass extends UserClassImpl {}

const FIXTURES = [
[new UserClassImpl(), true],
[ new UserClassImpl(), true ],
// Invalid things
[{}, false],
[[], false],
[new Map(), false],
[ {}, false ],
[ [], false ],
[ new Map(), false ],
// Object interface
[{ bar: true, foo: true }, true],
[{ bar: true }, false],
[{ foo: true }, false],
[ { bar: true, foo: true }, true ],
[ { bar: true }, false ],
[ { foo: true }, false ],
]

for (const [input, expected] of FIXTURES) {
for (const [ input, expected ] of FIXTURES) {
const valid = expected ? 'valid' : 'invalid'
/* eslint-disable multiline-ternary */
const type = typeof input !== 'object' ? typeof input
Expand Down
2 changes: 1 addition & 1 deletion src/user-mixins/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const validationMixin = <MixinBase extends Constructor> (mixinBase: MixinBase) =
log.verbose('ValidationMixin', 'validationMixin(%s)', mixinBase.name)

const instanceOfUserClass = looseInstanceOfClass(mixinBase)
const interfaceOfUserClass = interfaceOfClass(mixinBase)<T>()
const interfaceOfUserClass = interfaceOfClass(mixinBase)<T & {}>()

const validUserClass = (o: any): o is T => {
if (instanceOfUserClass(o)) {
Expand Down
2 changes: 1 addition & 1 deletion src/user-modules/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class ContactMixin extends MixinBase implements SayableSayer {
log.warn('Contact', 'find() got more than 1 result: %d total', contactList.length)
}

for (const [idx, contact] of contactList.entries()) {
for (const [ idx, contact ] of contactList.entries()) {
// use puppet.contactValidate() to confirm double confirm that this contactId is valid.
// https://github.com/wechaty/wechaty-puppet-padchat/issues/64
// https://github.com/wechaty/wechaty/issues/1345
Expand Down
4 changes: 2 additions & 2 deletions src/user-modules/message.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ test('recalled()', async t => {

sandbox.stub(puppet, 'roomMemberList').callsFake(async () => {
await new Promise((resolve) => setImmediate(resolve))
return [EXPECTED_TALKER_CONTACT_ID, EXPECTED_LISTENER_CONTACT_ID]
return [ EXPECTED_TALKER_CONTACT_ID, EXPECTED_LISTENER_CONTACT_ID ]
})

sandbox.stub(puppet, 'contactPayload').callsFake(async (id: string) => {
Expand All @@ -93,7 +93,7 @@ test('recalled()', async t => {

const fakeIdSearcher = async (...args: any[]) => {
await new Promise(setImmediate)
return [args[0].id]
return [ args[0].id ]
}

sandbox.stub(puppet, 'messageSearch').callsFake(fakeIdSearcher)
Expand Down
4 changes: 2 additions & 2 deletions src/user-modules/post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ test.skip('Post smoke testing', async t => {
t.ok(descendantPost, 'tbw')
}

const [descendantList, _nextPageToken2] = await wechaty.Post.findAll({}, pagination)
const [ descendantList, _nextPageToken2 ] = await wechaty.Post.findAll({}, pagination)
t.ok(descendantList, 'tbw')

for await (const liker of post.taps({ type: PUPPET.types.Tap.Like })) {
t.ok(liker, 'tbw')
}

const [tapList, _nextPageToken3] = await post.tapFind({ type: PUPPET.types.Tap.Like }, pagination)
const [ tapList, _nextPageToken3 ] = await post.tapFind({ type: PUPPET.types.Tap.Like }, pagination)
t.ok(tapList, 'tbw')

await wechaty.stop()
Expand Down
18 changes: 9 additions & 9 deletions src/user-modules/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class PostMixin extends wechatifyMixinBase() {
return post
}

const [postList] = await this.findAll(filter, { pageSize: 1 })
const [ postList ] = await this.findAll(filter, { pageSize: 1 })
if (postList.length > 0) {
return postList[0]
}
Expand Down Expand Up @@ -194,7 +194,7 @@ class PostMixin extends wechatifyMixinBase() {
}
}

return [postList, nextPageToken]
return [ postList, nextPageToken ]
}

protected _payload?: PUPPET.payloads.Post
Expand Down Expand Up @@ -338,7 +338,7 @@ class PostMixin extends wechatifyMixinBase() {
parentId: this.id,
}

let [postList, nextPageToken] = await this.wechaty.Post.findAll(
let [ postList, nextPageToken ] = await this.wechaty.Post.findAll(
parentIdFilter,
pagination,
)
Expand All @@ -351,7 +351,7 @@ class PostMixin extends wechatifyMixinBase() {
break
}

[postList, nextPageToken] = await this.wechaty.Post.findAll(
[ postList, nextPageToken ] = await this.wechaty.Post.findAll(
parentIdFilter,
{
...pagination,
Expand Down Expand Up @@ -389,7 +389,7 @@ class PostMixin extends wechatifyMixinBase() {

const pagination: PUPPET.filters.PaginationRequest = {}

let [tapList, nextPageToken] = await this.tapFind(
let [ tapList, nextPageToken ] = await this.tapFind(
filter,
pagination,
)
Expand All @@ -402,7 +402,7 @@ class PostMixin extends wechatifyMixinBase() {
break
}

[tapList, nextPageToken] = await this.tapFind(
[ tapList, nextPageToken ] = await this.tapFind(
filter,
{ ...pagination, pageToken: nextPageToken },
)
Expand Down Expand Up @@ -507,8 +507,8 @@ class PostMixin extends wechatifyMixinBase() {
)

const tapList: Tap[] = []
for (const [type, data] of Object.entries(response)) {
for (const [i, contactId] of data.contactId.entries()) {
for (const [ type, data ] of Object.entries(response)) {
for (const [ i, contactId ] of data.contactId.entries()) {
const contact = await this.wechaty.Contact.find({ id: contactId })
if (!contact) {
log.warn('Post', 'tapFind() contact not found for id: %s', contactId)
Expand All @@ -526,7 +526,7 @@ class PostMixin extends wechatifyMixinBase() {
}
}

return [tapList, nextPageToken]
return [ tapList, nextPageToken ]
}

}
Expand Down
1 change: 0 additions & 1 deletion src/user-modules/room-invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ class RoomInvitationMixin extends wechatifyMixinBase() implements Accepter {
topic,
inviter,
)
return
} catch (e) {
this.wechaty.emitError(e)
log.warn('RoomInvitation', 'accept() rejection: %s',
Expand Down
10 changes: 5 additions & 5 deletions src/user-modules/room.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import type {
test('findAll()', async t => {
const EXPECTED_ROOM_ID = 'test-id'
const EXPECTED_ROOM_TOPIC = 'test-topic'
const EXPECTED_ROOM_ID_LIST = [EXPECTED_ROOM_ID]
const EXPECTED_ROOM_ID_LIST = [ EXPECTED_ROOM_ID ]

const sandbox = sinon.createSandbox()

Expand Down Expand Up @@ -106,7 +106,7 @@ test('room.say() smoke testing', async () => {

const fakeIdSearcher = async (...args: any[]) => {
await new Promise(setImmediate)
return [args[0].id]
return [ args[0].id ]
}
sandbox.stub(puppet, 'contactSearch').callsFake(fakeIdSearcher)
sandbox.stub(puppet, 'roomSearch').callsFake(fakeIdSearcher)
Expand All @@ -130,7 +130,7 @@ test('room.say() smoke testing', async () => {
// { contactId: EXPECTED_CONTACT_1_ID, roomId: EXPECTED_ROOM_ID },
EXPECTED_ROOM_ID,
'To be @little1 or not to be @big2',
[EXPECTED_CONTACT_1_ID, EXPECTED_CONTACT_2_ID],
[ EXPECTED_CONTACT_1_ID, EXPECTED_CONTACT_2_ID ],
], 'Tagged Template say should be matched')
})

Expand All @@ -142,7 +142,7 @@ test('room.say() smoke testing', async () => {
// { contactId: EXPECTED_CONTACT_1_ID, roomId: EXPECTED_ROOM_ID },
EXPECTED_ROOM_ID,
'@little1 Yo',
[EXPECTED_CONTACT_1_ID],
[ EXPECTED_CONTACT_1_ID ],
], 'Single mention should work with old ways')
})

Expand All @@ -154,7 +154,7 @@ test('room.say() smoke testing', async () => {
// { contactId: EXPECTED_CONTACT_1_ID, roomId: EXPECTED_ROOM_ID },
EXPECTED_ROOM_ID,
'@little1鈥匑big2 hey buddies, let\'s party',
[EXPECTED_CONTACT_1_ID, EXPECTED_CONTACT_2_ID],
[ EXPECTED_CONTACT_1_ID, EXPECTED_CONTACT_2_ID ],
], 'Multiple mention should work with new way')
})

Expand Down
4 changes: 2 additions & 2 deletions src/user-modules/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class RoomMixin extends MixinBase implements SayableSayer {
log.warn('Room', 'find() got more than one(%d) result', roomList.length)
}

for (const [idx, room] of roomList.entries()) {
for (const [ idx, room ] of roomList.entries()) {
// use puppet.roomValidate() to confirm double confirm that this roomId is valid.
// https://github.com/wechaty/wechaty-puppet-padchat/issues/64
// https://github.com/wechaty/wechaty/issues/1345
Expand Down Expand Up @@ -471,7 +471,7 @@ class RoomMixin extends MixinBase implements SayableSayer {
throw new Error('mentionList must be contact when not using TemplateStringsArray function call.')
}

mentionList = [...varList as any]
mentionList = [ ...varList as any ]

const AT_SEPARATOR = FOUR_PER_EM_SPACE
const mentionAlias = await Promise.all(mentionList.map(async contact =>
Expand Down
6 changes: 3 additions & 3 deletions tests/node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ test('Node.js function params destructuring behaviour test', async t => {

paramSpy.resetHistory()
paramTest()
t.same(paramSpy.args[0], [DEFAULT_N, DEFAULT_S], 'should be equal to default args')
t.same(paramSpy.args[0], [ DEFAULT_N, DEFAULT_S ], 'should be equal to default args')

paramSpy.resetHistory()
paramTest({ n: 42 })
t.same(paramSpy.args[0], [42, DEFAULT_S], 'should be equal to default s args')
t.same(paramSpy.args[0], [ 42, DEFAULT_S ], 'should be equal to default s args')

paramSpy.resetHistory()
paramTest({ s: 'life' })
t.same(paramSpy.args[0], [DEFAULT_N, 'life'], 'should be equal to default n args')
t.same(paramSpy.args[0], [ DEFAULT_N, 'life' ], 'should be equal to default n args')

sandbox.restore()
})
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"compilerOptions": {
"outDir": "dist/esm",
"lib": ["ESNext", "DOM"],
"verbatimModuleSyntax": false,
// See: https://github.com/wechaty/wechaty/issues/2551
"ignoreDeprecations": "5.0"
},
"exclude": [
"node_modules/",
Expand Down

0 comments on commit 31601af

Please sign in to comment.