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 Module support #35

Merged
merged 3 commits into from
Sep 12, 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.
28 changes: 18 additions & 10 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ jobs:
name: Build
strategy:
matrix:
os: [ubuntu-latest]
node: [14]
os:
- ubuntu-latest
node:
- 16

runs-on: ${{ matrix.os }}
steps:
Expand All @@ -17,6 +19,8 @@ jobs:
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 @@ -32,34 +36,38 @@ jobs:
- uses: actions/checkout@v2
- 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

publish:
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/v'))
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/v'))
name: Publish
needs: [build, pack]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- 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 All @@ -70,7 +78,7 @@ jobs:
- name: Check Branch
id: check-branch
run: |
if [[ ${{ github.ref }} =~ ^refs/heads/(master|v[0-9]+\.[0-9]+.*)$ ]]; then
if [[ ${{ github.ref }} =~ ^refs/heads/(main|v[0-9]+\.[0-9]+.*)$ ]]; then
echo ::set-output name=match::true
fi # See: https://stackoverflow.com/a/58869470/1123955
- name: Is A Publish Branch
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,10 @@ See: [api/index.ts](src/api/index.ts)

## History

### Main
### Main v0.5

1. Upgrade RxJS version from 6 to 7.1
1. ES Modules support

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

Expand Down
2 changes: 1 addition & 1 deletion examples/ducks-proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Ducks } from 'ducks'
import {
WechatyRedux,
Duck,
} from '../src/mod' // 'wechaty-redux'
} from '../src/mod.js' // 'wechaty-redux'

async function main () {
/**
Expand Down
2 changes: 1 addition & 1 deletion examples/vanilla-redux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { Wechaty } from 'wechaty'
import {
WechatyRedux,
Duck,
} from '../src/mod' // 'wechaty-redux'
} from '../src/mod.js' // 'wechaty-redux'

async function main () {
/**
Expand Down
54 changes: 36 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
{
"name": "wechaty-redux",
"version": "0.3.6",
"version": "0.5.2",
"description": "Wechaty Redux Plugin Powered By Ducks",
"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.69.41",
"node": ">=14"
},
"scripts": {
"build": "tsc && tsc -p tsconfig.cjs.json",
"clean": "shx rm -fr dist/*",
"dist": "npm run clean && tsc",
"pack": "npm pack",
"dist": "npm-run-all clean build dist:commonjs",
"dist:commonjs": "jq -n \"{ type: \\\"commonjs\\\" }\" > dist/cjs/package.json",
"lint": "npm run lint:es && npm run lint:ts && npm run 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": "npm run quack",
"test": "npm run lint && npm run test:unit",
"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\" \"examples/**/*.spec.ts\" \"tests/*.spec.ts\" \"tests/**/*.spec.ts\"",
"test:unit": "tap --node-arg=--loader=ts-node/esm --node-arg=--no-warnings \"src/**/*.spec.ts\" \"tests/**/*.spec.ts\"",
"lint:es": "eslint --ignore-pattern tests/fixtures/ '{bin,examples,scripts,src,tests}/**/*.ts'"
},
"repository": {
Expand All @@ -38,32 +49,39 @@
"tag": "next"
},
"dependencies": {
"redux": "^4.1.0",
"redux-observable": "^2.0.0-rc.2",
"rxjs": "^7.1",
"redux": "^4.1.1",
"redux-observable": "^2.0.0",
"rxjs": "^7.3",
"typesafe-actions": "^5.1.0"
},
"peerDependencies": {
"wechaty": ">=0.61.2"
},
"devDependencies": {
"@chatie/eslint-config": "^0.14.1",
"@chatie/git-scripts": "^0.6.2",
"@chatie/semver": "^0.4.7",
"@chatie/tsconfig": "^0.20.2",
"@types/glob": "^7.1.3",
"@types/remote-redux-devtools": "^0.5.4",
"@types/glob": "^7.1.4",
"@types/remote-redux-devtools": "^0.5.5",
"cross-env": "^7.0.3",
"ducks": "^0.10.2",
"glob": "^7.1.7",
"npm-run-all": "^4.1.5",
"pkg-jq": "^0.2.11",
"remote-redux-devtools": "^0.5.16",
"shx": "^0.3.3",
"tstest": "^0.4.10",
"tstest": "^0.5.16",
"typescript": "4.4",
"utility-types": "^3.10.0",
"wechaty": "^0.68.1",
"wechaty": "^0.69.41",
"wechaty-puppet-mock": "^0.31.3"
},
"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.

44 changes: 39 additions & 5 deletions scripts/npm-pack-testing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,67 @@ 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_TAG" \
"wechaty@$NPM_TAG" \
npm install --production *-*.*.*.tgz \
@types/node \
@chatie/tsconfig@$NPM_TAG \
ducks \
pkg-jq \
"wechaty-puppet@$NPM_TAG" \
"wechaty@$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
7 changes: 7 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { packageJson } from './package-json.js'

const VERSION = packageJson.version || '0.0.0'

export {
VERSION,
}
4 changes: 2 additions & 2 deletions src/duck/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
createAsyncAction,
} from 'typesafe-actions'

import {
import type {
EventDongPayload,
EventErrorPayload,
EventScanPayload,
Expand All @@ -44,7 +44,7 @@ import {

import cuid from 'cuid'

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

// interface ContactIdOptions { contactId: string }
interface ErrorOptions { error: Error }
Expand Down
8 changes: 4 additions & 4 deletions src/duck/epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import {
map,
} from 'rxjs/operators'

import {
import type {
Epic,
} from 'redux-observable'

import * as actions from './actions'
import * as rxAsync from './rx-async'
import * as utils from './utils'
import * as actions from './actions.js'
import * as rxAsync from './rx-async.js'
import * as utils from './utils.js'

const dingEpic: Epic = actions$ => actions$.pipe(
filter(isActionOf(actions.ding)),
Expand Down
14 changes: 7 additions & 7 deletions src/duck/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
* 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 utils from './utils'
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'
import * as utils from './utils.js'

export {
actions,
Expand Down
Loading