Skip to content

Commit 9c7b34e

Browse files
authored
Enable ESM (#150)
* Enable ESM * fix eslint under win32 * 0.29.1
1 parent 6407afd commit 9c7b34e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+807
-766
lines changed
File renamed without changes.

.github/workflows/npm.yml

+22-11
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,23 @@ jobs:
77
name: Build
88
strategy:
99
matrix:
10-
os: [ubuntu-latest]
11-
node: [14]
10+
os:
11+
- ubuntu-latest
12+
- windows-latest
13+
- macos-latest
14+
node:
15+
- 14
16+
- 16
1217

1318
runs-on: ${{ matrix.os }}
1419
steps:
1520
- uses: actions/checkout@v2
1621
- name: Use Node.js ${{ matrix.node-version }}
17-
uses: actions/setup-node@v1
22+
uses: actions/setup-node@v2
1823
with:
1924
node-version: ${{ matrix.node-version }}
25+
cache: 'npm'
26+
cache-dependency-path: package.json
2027

2128
- name: Install Dependencies
2229
run: npm install
@@ -30,15 +37,17 @@ jobs:
3037
runs-on: ubuntu-latest
3138
steps:
3239
- uses: actions/checkout@v2
33-
- uses: actions/setup-node@v1
40+
- uses: actions/setup-node@v2
3441
with:
35-
node-version: 14
42+
node-version: 16
43+
cache: 'npm'
44+
cache-dependency-path: package.json
3645

3746
- name: Install Dependencies
3847
run: npm install
3948

40-
- name: Generate Version
41-
run: ./scripts/generate-version.sh
49+
- name: Generate Package JSON
50+
run: ./scripts/generate-package-json.sh
4251

4352
- name: Pack Testing
4453
run: ./scripts/npm-pack-testing.sh
@@ -52,16 +61,18 @@ jobs:
5261
runs-on: ubuntu-latest
5362
steps:
5463
- uses: actions/checkout@v2
55-
- uses: actions/setup-node@v1
64+
- uses: actions/setup-node@v2
5665
with:
57-
node-version: 14
66+
node-version: 16
5867
registry-url: https://registry.npmjs.org/
68+
cache: 'npm'
69+
cache-dependency-path: package.json
5970

6071
- name: Install Dependencies
6172
run: npm install
6273

63-
- name: Generate Version
64-
run: ./scripts/generate-version.sh
74+
- name: Generate Package JSON
75+
run: ./scripts/generate-package-json.sh
6576

6677
- name: Set Publish Config
6778
run: ./scripts/package-publish-config-tag.sh

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ We use [stealth](https://www.npmjs.com/package/puppeteer-extra-plugin-stealth) t
8787

8888
## HISTORY
8989

90-
### master
90+
### master v0.29
91+
92+
1. ESM support.
9193

9294
### v0.28 (Apr 13, 2021)
9395

@@ -132,14 +134,15 @@ See: <https://github.com/wechaty/wechaty/issues/1152>
132134

133135
## AUTHOR
134136

135-
[Huan LI](http://linkedin.com/in/zixia) \<[email protected]\>
137+
[Huan LI](http://linkedin.com/in/zixia) Tencent TVP of Chatbot \<[email protected]\>
136138

139+
<!-- markdownlint-disable MD033 -->
137140
<a href="https://stackexchange.com/users/265499">
138141
<img src="https://stackexchange.com/users/flair/265499.png" width="208" height="58" alt="profile for zixia on Stack Exchange, a network of free, community-driven Q&amp;A sites" title="profile for zixia on Stack Exchange, a network of free, community-driven Q&amp;A sites">
139142
</a>
140143

141144
## COPYRIGHT & LICENSE
142145

143-
- Code & Docs © 2016-2019 Huan LI \<[email protected]\>
146+
- Code & Docs © 2016-now Huan LI \<[email protected]\>
144147
- Code released under the Apache-2.0 License
145148
- Docs released under Creative Commons

commonjs/code-root.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export declare const codeRoot: string

commonjs/code-root.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const path = require('path')
2+
3+
const codeRoot = path.join(
4+
__dirname,
5+
'..',
6+
)
7+
8+
module.exports = {
9+
codeRoot,
10+
}

commonjs/code-root.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env -S ts-node --project tsconfig.cjs.json
2+
3+
import { test } from 'tstest'
4+
5+
import { codeRoot } from './code-root'
6+
7+
test('CJS: codeRoot()', async t => {
8+
t.ok(codeRoot, 'should exist codeRoot')
9+
})

commonjs/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "type": "commonjs" }

examples/demo.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,16 @@
1616
* limitations under the License.
1717
*
1818
*/
19-
20-
// tslint:disable:no-console
21-
22-
import { PuppetWeChat } from '../src/mod'
23-
24-
import {
19+
import type {
2520
EventLogoutPayload,
2621
EventLoginPayload,
2722
EventScanPayload,
2823
EventErrorPayload,
2924
EventMessagePayload,
3025
} from 'wechaty-puppet'
3126

27+
import { PuppetWeChat } from '../src/mod.js'
28+
3229
/**
3330
*
3431
* 1. Declare your Bot!
@@ -55,7 +52,7 @@ puppet
5552
*/
5653
puppet.start()
5754
.catch(async e => {
58-
console.error('Bot start() fail:', e)
55+
console.error('Bot start() fail:', e as Error)
5956
await puppet.stop()
6057
process.exit(-1)
6158
})
@@ -100,7 +97,7 @@ function onError (payload: EventErrorPayload) {
10097
console.error('Bot error:', payload.data)
10198
/*
10299
if (bot.logonoff()) {
103-
bot.say('Wechaty error: ' + e.message).catch(console.error)
100+
bot.say('Wechaty error: ' + (e as Error).message).catch(console.error)
104101
}
105102
*/
106103
}

package.json

+50-35
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
11
{
22
"name": "wechaty-puppet-wechat",
3-
"version": "0.28.4",
3+
"version": "0.29.1",
44
"description": "Puppet WeChat for Wechaty",
5-
"main": "dist/src/mod.js",
6-
"typings": "dist/src/mod.d.ts",
5+
"type": "module",
6+
"exports": {
7+
".": {
8+
"import": "./dist/esm/src/mod.js",
9+
"require": "./dist/cjs/src/mod.js"
10+
}
11+
},
12+
"typings": "./dist/esm/src/mod.d.ts",
713
"engines": {
8-
"wechaty": ">=0.35"
14+
"wechaty": ">=0.69",
15+
"wechaty-puppet": ">=0.43"
916
},
1017
"scripts": {
1118
"clean": "shx rm -fr dist/*",
12-
"dist": "npm run clean && tsc && shx cp src/*.js dist/src/",
13-
"pack": "npm pack",
19+
"dist": "npm-run-all clean build dist:copy",
20+
"build": "tsc && tsc -p tsconfig.cjs.json && shx echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
21+
"dist:copy": "npm-run-all copy:esm copy:cjs",
22+
"copy:js": "shx cp src/*.js dist/src/",
23+
"copy:esm": "shx cp -R commonjs/ dist/esm/ && shx cp src/*.js dist/esm/src/",
24+
"copy:cjs": "shx cp -R commonjs/ dist/cjs/ && shx cp src/*.js dist/cjs/src/",
1425
"lint": "npm run lint:es && npm run lint:ts && npm run lint:md",
15-
"lint:es": "eslint '{bin,examples,scripts,src,tests}/**/*.{js,ts}' --ignore-pattern='tests/fixtures/**'",
26+
"lint:es": "eslint --ignore-pattern fixtures/ \"src/**/*.ts\" \"tests/**/*.ts\"",
1627
"lint:md": "markdownlint README.md",
17-
"lint:ts": "tsc --noEmit",
18-
"start": "ts-node examples/demo.ts",
19-
"test": "npm run lint && npm run test:unit:retry",
28+
"lint:ts": "tsc --isolatedModules --noEmit",
29+
"start": "node examples/demo.ts",
30+
"test": "npm run lint && npm run test:unit",
2031
"test:pack": "bash -x scripts/npm-pack-testing.sh",
21-
"test:unit": "blue-tape -r ts-node/register 'src/**/*.spec.ts' 'tests/**/*.spec.ts'",
22-
"test:unit:retry": "ts-node scripts/retry-unit-tests"
32+
"test:unit": "tap --node-arg=--loader=ts-node/esm --node-arg=--no-warnings \"src/**/*.spec.ts\" \"tests/**/*.spec.ts\""
2333
},
2434
"repository": {
2535
"type": "git",
@@ -41,47 +51,52 @@
4151
"url": "https://github.com/wechaty/wechaty-puppet-wechat/issues"
4252
},
4353
"devDependencies": {
44-
"@chatie/eslint-config": "^0.12.3",
54+
"@chatie/eslint-config": "^0.13.5",
4555
"@chatie/git-scripts": "^0.6.2",
4656
"@chatie/semver": "^0.4.7",
47-
"@chatie/tsconfig": "^0.14.1",
48-
"@types/bl": "^2.1.0",
49-
"@types/md5": "^2.3.0",
57+
"@chatie/tsconfig": "^0.19.6",
58+
"@types/bl": "^2",
59+
"@types/md5": "^2.3.1",
5060
"@types/mime": "^2.0.3",
51-
"@types/normalize-package-data": "^2.4.0",
52-
"@types/promise-retry": "^1.1.3",
53-
"@types/qr-image": "^3.2.3",
54-
"@types/raven": "^2.5.3",
55-
"@types/request": "^2.48.5",
56-
"@types/retry": "0.12.0",
57-
"@types/xml2js": "^0.4.8",
58-
"normalize-package-data": "^3.0.0",
61+
"@types/qr-image": "^3.2.4",
62+
"@types/raven": "^2.5.4",
63+
"@types/request": "^2.48.7",
64+
"@types/xml2js": "^0.4.9",
65+
"npm-run-all": "^4.1.5",
5966
"pkg-jq": "^0.2.11",
6067
"shx": "^0.3.3",
61-
"tstest": "^0.4.10",
62-
"wechaty-puppet": "^0.26.2"
68+
"tstest": "^0.5.16",
69+
"typescript": "^4.4.2",
70+
"wechaty-puppet": "^0.43.10"
6371
},
6472
"peerDependencies": {
6573
"wechaty-puppet": ">=0.34"
6674
},
6775
"homepage": "https://github.com/wechaty/wechaty-puppet-wechat#readme",
6876
"dependencies": {
69-
"bl": "^4.1.0",
70-
"brolog": "^1.12.4",
77+
"bl": "^2",
78+
"cockatiel": "^2.0.2",
7179
"md5": "^2.3.0",
7280
"mime": "^2.5.2",
73-
"promise-retry": "^2.0.1",
74-
"puppeteer": "^7.1.0",
75-
"puppeteer-extra": "^3.1.17",
76-
"puppeteer-extra-plugin-stealth": "^2.7.5",
81+
"puppeteer": "^10.2.0",
82+
"puppeteer-extra": "^3.1.18",
83+
"puppeteer-extra-plugin-stealth": "^2.7.8",
7784
"qr-image": "^3.2.0",
7885
"request": "^2.88.2",
79-
"rx-queue": "^0.8.5",
80-
"rxjs": "^6.6.3",
81-
"state-switch": "^0.6.18",
86+
"rx-queue": "^0.12.6",
87+
"rxjs": "^7.3.0",
88+
"state-switch": "^0.14.1",
8289
"watchdog": "^0.8.17",
8390
"xml2js": "^0.4.23"
8491
},
92+
"files": [
93+
"bin/",
94+
"dist/",
95+
"src/"
96+
],
97+
"tap": {
98+
"check-coverage": false
99+
},
85100
"publishConfig": {
86101
"access": "public",
87102
"tag": "next"

scripts/generate-package-json.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
SRC_PACKAGE_JSON_TS_FILE='src/package-json.ts'
5+
6+
[ -f ${SRC_PACKAGE_JSON_TS_FILE} ] || {
7+
echo ${SRC_PACKAGE_JSON_TS_FILE}" not found"
8+
exit 1
9+
}
10+
11+
cat <<_SRC_ > ${SRC_PACKAGE_JSON_TS_FILE}
12+
/**
13+
* This file was auto generated from scripts/generate-version.sh
14+
*/
15+
import type { PackageJson } from 'type-fest'
16+
export const packageJson: PackageJson = $(cat package.json) as any
17+
_SRC_

scripts/generate-version.sh

-18
This file was deleted.

0 commit comments

Comments
 (0)