Skip to content

Commit

Permalink
Enable ESM (#150)
Browse files Browse the repository at this point in the history
* Enable ESM

* fix eslint under win32

* 0.29.1
  • Loading branch information
huan authored Sep 1, 2021
1 parent 6407afd commit 9c7b34e
Show file tree
Hide file tree
Showing 46 changed files with 807 additions and 766 deletions.
File renamed without changes.
33 changes: 22 additions & 11 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@ jobs:
name: Build
strategy:
matrix:
os: [ubuntu-latest]
node: [14]
os:
- ubuntu-latest
- windows-latest
- macos-latest
node:
- 14
- 16

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: package.json

- name: Install Dependencies
run: npm install
Expand All @@ -30,15 +37,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: 14
node-version: 16
cache: 'npm'
cache-dependency-path: package.json

- name: Install Dependencies
run: npm install

- name: Generate Version
run: ./scripts/generate-version.sh
- name: Generate Package JSON
run: ./scripts/generate-package-json.sh

- name: Pack Testing
run: ./scripts/npm-pack-testing.sh
Expand All @@ -52,16 +61,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: 14
node-version: 16
registry-url: https://registry.npmjs.org/
cache: 'npm'
cache-dependency-path: package.json

- name: Install Dependencies
run: npm install

- name: Generate Version
run: ./scripts/generate-version.sh
- name: Generate Package JSON
run: ./scripts/generate-package-json.sh

- name: Set Publish Config
run: ./scripts/package-publish-config-tag.sh
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ We use [stealth](https://www.npmjs.com/package/puppeteer-extra-plugin-stealth) t

## HISTORY

### master
### master v0.29

1. ESM support.

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

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

## AUTHOR

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

<!-- markdownlint-disable MD033 -->
<a href="https://stackexchange.com/users/265499">
<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">
</a>

## COPYRIGHT & LICENSE

- Code & Docs © 2016-2019 Huan LI \<[email protected]\>
- Code & Docs © 2016-now Huan LI \<[email protected]\>
- Code released under the Apache-2.0 License
- Docs released under Creative Commons
1 change: 1 addition & 0 deletions commonjs/code-root.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const codeRoot: string
10 changes: 10 additions & 0 deletions commonjs/code-root.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const path = require('path')

const codeRoot = path.join(
__dirname,
'..',
)

module.exports = {
codeRoot,
}
9 changes: 9 additions & 0 deletions commonjs/code-root.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env -S ts-node --project tsconfig.cjs.json

import { test } from 'tstest'

import { codeRoot } from './code-root'

test('CJS: codeRoot()', async t => {
t.ok(codeRoot, 'should exist codeRoot')
})
1 change: 1 addition & 0 deletions commonjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "type": "commonjs" }
13 changes: 5 additions & 8 deletions examples/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@
* limitations under the License.
*
*/

// tslint:disable:no-console

import { PuppetWeChat } from '../src/mod'

import {
import type {
EventLogoutPayload,
EventLoginPayload,
EventScanPayload,
EventErrorPayload,
EventMessagePayload,
} from 'wechaty-puppet'

import { PuppetWeChat } from '../src/mod.js'

/**
*
* 1. Declare your Bot!
Expand All @@ -55,7 +52,7 @@ puppet
*/
puppet.start()
.catch(async e => {
console.error('Bot start() fail:', e)
console.error('Bot start() fail:', e as Error)
await puppet.stop()
process.exit(-1)
})
Expand Down Expand Up @@ -100,7 +97,7 @@ function onError (payload: EventErrorPayload) {
console.error('Bot error:', payload.data)
/*
if (bot.logonoff()) {
bot.say('Wechaty error: ' + e.message).catch(console.error)
bot.say('Wechaty error: ' + (e as Error).message).catch(console.error)
}
*/
}
Expand Down
85 changes: 50 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
{
"name": "wechaty-puppet-wechat",
"version": "0.28.4",
"version": "0.29.1",
"description": "Puppet WeChat for Wechaty",
"main": "dist/src/mod.js",
"typings": "dist/src/mod.d.ts",
"type": "module",
"exports": {
".": {
"import": "./dist/esm/src/mod.js",
"require": "./dist/cjs/src/mod.js"
}
},
"typings": "./dist/esm/src/mod.d.ts",
"engines": {
"wechaty": ">=0.35"
"wechaty": ">=0.69",
"wechaty-puppet": ">=0.43"
},
"scripts": {
"clean": "shx rm -fr dist/*",
"dist": "npm run clean && tsc && shx cp src/*.js dist/src/",
"pack": "npm pack",
"dist": "npm-run-all clean build dist:copy",
"build": "tsc && tsc -p tsconfig.cjs.json && shx echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
"dist:copy": "npm-run-all copy:esm copy:cjs",
"copy:js": "shx cp src/*.js dist/src/",
"copy:esm": "shx cp -R commonjs/ dist/esm/ && shx cp src/*.js dist/esm/src/",
"copy:cjs": "shx cp -R commonjs/ dist/cjs/ && shx cp src/*.js dist/cjs/src/",
"lint": "npm run lint:es && npm run lint:ts && npm run lint:md",
"lint:es": "eslint '{bin,examples,scripts,src,tests}/**/*.{js,ts}' --ignore-pattern='tests/fixtures/**'",
"lint:es": "eslint --ignore-pattern fixtures/ \"src/**/*.ts\" \"tests/**/*.ts\"",
"lint:md": "markdownlint README.md",
"lint:ts": "tsc --noEmit",
"start": "ts-node examples/demo.ts",
"test": "npm run lint && npm run test:unit:retry",
"lint:ts": "tsc --isolatedModules --noEmit",
"start": "node examples/demo.ts",
"test": "npm run lint && npm run test:unit",
"test:pack": "bash -x scripts/npm-pack-testing.sh",
"test:unit": "blue-tape -r ts-node/register 'src/**/*.spec.ts' 'tests/**/*.spec.ts'",
"test:unit:retry": "ts-node scripts/retry-unit-tests"
"test:unit": "tap --node-arg=--loader=ts-node/esm --node-arg=--no-warnings \"src/**/*.spec.ts\" \"tests/**/*.spec.ts\""
},
"repository": {
"type": "git",
Expand All @@ -41,47 +51,52 @@
"url": "https://github.com/wechaty/wechaty-puppet-wechat/issues"
},
"devDependencies": {
"@chatie/eslint-config": "^0.12.3",
"@chatie/eslint-config": "^0.13.5",
"@chatie/git-scripts": "^0.6.2",
"@chatie/semver": "^0.4.7",
"@chatie/tsconfig": "^0.14.1",
"@types/bl": "^2.1.0",
"@types/md5": "^2.3.0",
"@chatie/tsconfig": "^0.19.6",
"@types/bl": "^2",
"@types/md5": "^2.3.1",
"@types/mime": "^2.0.3",
"@types/normalize-package-data": "^2.4.0",
"@types/promise-retry": "^1.1.3",
"@types/qr-image": "^3.2.3",
"@types/raven": "^2.5.3",
"@types/request": "^2.48.5",
"@types/retry": "0.12.0",
"@types/xml2js": "^0.4.8",
"normalize-package-data": "^3.0.0",
"@types/qr-image": "^3.2.4",
"@types/raven": "^2.5.4",
"@types/request": "^2.48.7",
"@types/xml2js": "^0.4.9",
"npm-run-all": "^4.1.5",
"pkg-jq": "^0.2.11",
"shx": "^0.3.3",
"tstest": "^0.4.10",
"wechaty-puppet": "^0.26.2"
"tstest": "^0.5.16",
"typescript": "^4.4.2",
"wechaty-puppet": "^0.43.10"
},
"peerDependencies": {
"wechaty-puppet": ">=0.34"
},
"homepage": "https://github.com/wechaty/wechaty-puppet-wechat#readme",
"dependencies": {
"bl": "^4.1.0",
"brolog": "^1.12.4",
"bl": "^2",
"cockatiel": "^2.0.2",
"md5": "^2.3.0",
"mime": "^2.5.2",
"promise-retry": "^2.0.1",
"puppeteer": "^7.1.0",
"puppeteer-extra": "^3.1.17",
"puppeteer-extra-plugin-stealth": "^2.7.5",
"puppeteer": "^10.2.0",
"puppeteer-extra": "^3.1.18",
"puppeteer-extra-plugin-stealth": "^2.7.8",
"qr-image": "^3.2.0",
"request": "^2.88.2",
"rx-queue": "^0.8.5",
"rxjs": "^6.6.3",
"state-switch": "^0.6.18",
"rx-queue": "^0.12.6",
"rxjs": "^7.3.0",
"state-switch": "^0.14.1",
"watchdog": "^0.8.17",
"xml2js": "^0.4.23"
},
"files": [
"bin/",
"dist/",
"src/"
],
"tap": {
"check-coverage": false
},
"publishConfig": {
"access": "public",
"tag": "next"
Expand Down
17 changes: 17 additions & 0 deletions scripts/generate-package-json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -e

SRC_PACKAGE_JSON_TS_FILE='src/package-json.ts'

[ -f ${SRC_PACKAGE_JSON_TS_FILE} ] || {
echo ${SRC_PACKAGE_JSON_TS_FILE}" not found"
exit 1
}

cat <<_SRC_ > ${SRC_PACKAGE_JSON_TS_FILE}
/**
* This file was auto generated from scripts/generate-version.sh
*/
import type { PackageJson } from 'type-fest'
export const packageJson: PackageJson = $(cat package.json) as any
_SRC_
18 changes: 0 additions & 18 deletions scripts/generate-version.sh

This file was deleted.

Loading

0 comments on commit 9c7b34e

Please sign in to comment.