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

ES Modules support #24

Merged
merged 5 commits into from
Sep 18, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
30 changes: 19 additions & 11 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ jobs:
name: Build
strategy:
matrix:
os: [ubuntu-latest]
node: [12]
os:
- ubuntu-latest
node-version:
- 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 +34,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: 12
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 +58,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: 12
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ npm start

## History

### master
### master v0.3 (Sep 19, 2021)

1. ES Modules support

### v0.2 (Jun 5, 2020)

Expand Down
4 changes: 2 additions & 2 deletions examples/ducks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Duck as wechatyDuck,
} from 'wechaty-redux'

import { Counter as CounterDuck } from '../src/mod'
import { Counter as CounterDuck } from '../src/mod.js'
import {
PuppetMock,
mock,
Expand Down Expand Up @@ -39,7 +39,7 @@ async function main () {
bot.use(WechatyRedux({ store }))
await bot.start()

const [user, friend] = mocker.createContacts(2)
const [user, friend] = mocker.createContacts(2) as [mock.ContactMock, mock.ContactMock]
mocker.login(user)

const counterBundle = ducks.ducksify('counter')
Expand Down
70 changes: 44 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
{
"name": "wechaty-ducks-contrib",
"version": "0.2.10",
"version": "0.3.2",
"description": "Wechaty Ducks Contrib",
"main": "dist/src/mod.js",
"typings": "dist/src/mod.d.ts",
"directories": {
"test": "tests"
"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.69",
"node": ">=16",
"npm": ">=7"
},
"scripts": {
"build": "tsc && tsc -p tsconfig.cjs.json",
"clean": "shx rm -fr dist/*",
"dist": "npm run clean && tsc",
"example": "ts-node examples/ding-dong-bot.ts",
"pack": "npm pack",
"lint": "npm run lint:es && npm run lint:ts && npm run lint:md",
"dist": "npm-run-all clean build dist:commonjs",
"dist:commonjs": "jq -n \"{ type: \\\"commonjs\\\" }\" > dist/cjs/package.json",
"example": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/ding-dong-bot.ts",
"lint": "npm-run-all lint:es lint:ts lint:md",
"lint:md": "markdownlint README.md",
"lint:ts": "tsc --noEmit",
"lint:ts": "tsc --isolatedModules --noEmit",
"redux-devtools": "redux-devtools --hostname=localhost --port=8000",
"start": "ts-node --files examples/ducks.ts",
"test": "npm run lint && npm run test:unit",
"start": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node --files examples/ducks.ts",
"test": "npm-run-all lint test:unit",
"test:pack": "bash -x scripts/npm-pack-testing.sh",
"test:unit": "blue-tape -r ts-node/register \"src/**/*.spec.ts\" \"src/*.spec.ts\" \"tests/*.spec.ts\" \"tests/**/*.spec.ts\"",
"test:unit": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" tap \"src/**/*.spec.ts\" \"tests/**/*.spec.ts\"",
"lint:es": "eslint --ignore-pattern tests/fixtures/ '{bin,examples,scripts,src,tests}/**/*.ts'"
},
"repository": {
Expand All @@ -39,31 +48,40 @@
},
"homepage": "https://github.com/wechaty/wechaty-ducks-contrib#readme",
"devDependencies": {
"@chatie/eslint-config": "^0.12.1",
"@chatie/eslint-config": "^0.14.1",
"@chatie/git-scripts": "^0.6.2",
"@chatie/semver": "^0.4.7",
"@chatie/tsconfig": "^0.14.1",
"@types/glob": "^7.1.3",
"@types/remote-redux-devtools": "^0.5.4",
"ducks": "^0.10.2",
"glob": "^7.1.6",
"pkg-jq": "^0.2.4",
"@chatie/tsconfig": "^0.20.2",
"@types/glob": "^7.1.4",
"@types/remote-redux-devtools": "^0.5.5",
"cross-env": "^7.0.3",
"glob": "^7.1.7",
"npm-run-all": "^4.1.5",
"pkg-jq": "^0.2.11",
"redux-devtools-cli": "1.0.0-4",
"remote-redux-devtools": "^0.5.16",
"shx": "^0.3.3",
"tstest": "^0.4.10",
"tstest": "^0.5.16",
"utility-types": "^3.10.0",
"wechaty": "^0.60.9",
"wechaty-puppet-mock": "^0.28.2",
"wechaty-redux": "^0.2.17"
"wechaty": "^0.69.54",
"wechaty-puppet-mock": "^0.31.5"
},
"peerDependencies": {
"redux": ">=4.0",
"wechaty-redux": ">=0.2"
"ducks": "^0.11.10",
"redux": "^4.1.1",
"wechaty-redux": "^0.5.6"
},
"dependencies": {
"typesafe-actions": "^5.1.0"
},
"files": [
"bin/",
"dist/",
"src/"
],
"tap": {
"check-coverage": false
},
"git": {
"scripts": {
"pre-push": "npx git-scripts-pre-push"
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.

47 changes: 41 additions & 6 deletions scripts/npm-pack-testing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,69 @@ set -e

VERSION=$(npx pkg-jq -r .version)

if npx --package @chatie/semver semver-is-prod $VERSION; then
if npx --package @chatie/semver semver-is-prod "$VERSION"; then
NPM_TAG=latest
else
NPM_TAG=next
fi

npm run dist
npm run pack
npm pack

TMPDIR="/tmp/npm-pack-testing.$$"
mkdir "$TMPDIR"
mv ./*-*.*.*.tgz "$TMPDIR"
cp tests/fixtures/smoke-testing.ts "$TMPDIR"

cd $TMPDIR

npm init -y
npm install *-*.*.*.tgz \
@chatie/tsconfig \
npm install --production ./*-*.*.*.tgz \
@chatie/tsconfig@$NPM_TAG \
pkg-jq \
"wechaty-puppet@$NPM_TAG" \
"wechaty@$NPM_TAG" \
ducks \
wechaty-redux \
"ducks@$NPM_TAG" \
"wechaty-redux@NPM_TAG" \


#
# CommonJS
#
./node_modules/.bin/tsc \
--target es6 \
--module CommonJS \
\
--moduleResolution node \
--esModuleInterop \
--lib esnext \
--noEmitOnError \
--noImplicitAny \
--skipLibCheck \
smoke-testing.ts

echo
echo "CommonJS: pack testing..."
node smoke-testing.js

#
# ES Modules
#
npx pkg-jq -i '.type="module"'


./node_modules/.bin/tsc \
--target es2020 \
--module es2020 \
\
--moduleResolution node \
--esModuleInterop \
--lib esnext \
--noEmitOnError \
--noImplicitAny \
--skipLibCheck \
smoke-testing.ts

echo
echo "ES Module: pack testing..."
node smoke-testing.js
6 changes: 3 additions & 3 deletions scripts/update-license.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env ts-node
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm

/**
* Wechaty Open Source Software - https://github.com/wechaty
Expand Down Expand Up @@ -66,7 +66,7 @@ class LicenseTransformer extends Transform {
// super(options)
// }

public _transform (chunk: any, _: string /* encoding: string */, done: () => void) {
override _transform (chunk: any, _: string /* encoding: string */, done: () => void) {
if (this.updated) {
this.push(chunk)
} else {
Expand Down Expand Up @@ -127,7 +127,7 @@ class LicenseTransformer extends Transform {
return updatedLineList.join('\n')
}

public _flush (done: () => void) {
override _flush (done: () => void) {
if (this.lineBuf) {
this.push(this.lineBuf)
this.lineBuf = ''
Expand Down
2 changes: 1 addition & 1 deletion src/contrib/counter/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
import { createAction } from 'typesafe-actions'

import * as types from './types'
import * as types from './types.js'

const prepareWechaty = (wechatyId: string) => ({ wechatyId })

Expand Down
4 changes: 2 additions & 2 deletions src/contrib/counter/epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
*/
import { isActionOf } from 'typesafe-actions'
import { Epic } from 'redux-observable'
import type { Epic } from 'redux-observable'
import { Duck as wechatyDuck } from 'wechaty-redux'

import {
Expand All @@ -27,7 +27,7 @@ import {
map,
} from 'rxjs/operators'

import * as actions from './actions'
import * as actions from './actions.js'

const counterEpic: Epic = actions$ => actions$.pipe(
filter(isActionOf(wechatyDuck.actions.messageEvent)),
Expand Down
12 changes: 6 additions & 6 deletions src/contrib/counter/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
* limitations under the License.
*
*/
import reducer from './reducers'
import reducer from './reducers.js'

import * as actions from './actions'
import * as epics from './epics'
import * as operations from './operations'
import * as selectors from './selectors'
import * as types from './types'
import * as actions from './actions.js'
import * as epics from './epics.js'
import * as operations from './operations.js'
import * as selectors from './selectors.js'
import * as types from './types.js'

export {
actions,
Expand Down
4 changes: 2 additions & 2 deletions src/contrib/counter/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* limitations under the License.
*
*/
import { Dispatch } from 'redux'
import type { Dispatch } from 'redux'

import * as actions from './actions'
import * as actions from './actions.js'

const outgoing = (dispatch: Dispatch) => (wechatyId: string) => dispatch(actions.outgoingMessage(wechatyId))
const incoming = (dispatch: Dispatch) => (wechatyId: string) => dispatch(actions.incomingMessage(wechatyId))
Expand Down
Loading