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

enable ESM #8

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.
26 changes: 17 additions & 9 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,13 +36,15 @@ 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
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: 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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ See issue: Backoff straitegy [#2](/~https://github.com/wechaty/ha-wechaty/issues/2

## History

### main (v0.7)
### master v0.9 (Sep 12, 2021)

1. ES Modules supported

### v0.7 (Jun 4, 2021)

#### BREAKING CHANGE

Expand Down
2 changes: 1 addition & 1 deletion examples/ding-dong-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from 'wechaty-plugin-contrib'
import { log } from 'wechaty'

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

import dotenv from 'dotenv'
dotenv.config()
Expand Down
6 changes: 3 additions & 3 deletions examples/redux-ducks-bot/ha-environment.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
Message,
} from 'wechaty'
import {
import type {
mock,
} from 'wechaty-puppet-mock'
import { ContactMock } from 'wechaty-puppet-mock/dist/src/mock/mod'
import type { ContactMock } from 'wechaty-puppet-mock/dist/src/mock/mod'

import {
CHATIE_OA_ID,
} from '../../src/config'
} from '../../src/config.js'

const HaEnvironment = (): mock.EnvironmentMock => {

Expand Down
6 changes: 3 additions & 3 deletions examples/redux-ducks-bot/redux-ducks-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ import { Counter as CounterDuck } from 'wechaty-ducks-contrib'
import {
HAWechaty,
Duck as HaDuck,
} from '../../src/mod'
} from '../../src/mod.js'

import { HaEnvironment } from './ha-environment'
// import { CHATIE_OA_ID } from '../../src/config'
import { HaEnvironment } from './ha-environment.js'
// import { CHATIE_OA_ID } from '../../src/config.js'

const ducks = new Ducks({
counter : CounterDuck,
Expand Down
8 changes: 4 additions & 4 deletions examples/redux/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ import {
createEpicMiddleware,
Epic,
} from 'redux-observable'
import {
import type {
// ActionType,
// StateType,
RootState,
RootAction,
// createAsyncAction,
} from 'typesafe-actions'

// import rootAction from './root-action'
import rootReducer from './root-reducer'
import rootEpic from './root-epic'
// import rootAction from './root-action.js'
import rootReducer from './root-reducer.js'
import rootEpic from './root-epic.js'

export interface Dependency {}
const dependencies = {} as Dependency
Expand Down
2 changes: 1 addition & 1 deletion examples/redux/root-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { Duck as WechatyDuck } from 'wechaty-redux'
import { Counter as CounterDuck } from 'wechaty-ducks-contrib'

import * as HaDuck from '../../src/duck/mod'
import * as HaDuck from '../../src/duck/mod.js'

export default {
counter : CounterDuck.actions,
Expand Down
2 changes: 1 addition & 1 deletion examples/redux/root-epic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { combineEpics } from 'redux-observable'
import { Duck as WechatyDuck } from 'wechaty-redux'
import { Counter as CounterDuck } from 'wechaty-ducks-contrib'

import * as HaDuck from '../../src/duck/mod'
import * as HaDuck from '../../src/duck/mod.js'

export default combineEpics(
...Object.values(HaDuck.epics),
Expand Down
2 changes: 1 addition & 1 deletion examples/redux/root-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { combineReducers } from 'redux'
import { Duck as WechatyDuck } from 'wechaty-redux'
import { Counter as CounterDuck } from 'wechaty-ducks-contrib'

import * as HaDuck from '../../src/duck/mod'
import * as HaDuck from '../../src/duck/mod.js'

export default combineReducers({
counter : CounterDuck.default,
Expand Down
6 changes: 3 additions & 3 deletions examples/remote-devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ import { Counter as CounterDuck } from 'wechaty-ducks-contrib'
import {
Duck as HaDuck,
configureHa,
} from '../src/mod'
} from '../src/mod.js'

import { HaEnvironment } from './redux-ducks-bot/ha-environment'
// import { CHATIE_OA_ID } from '../../src/config'
import { HaEnvironment } from './redux-ducks-bot/ha-environment.js'
// import { CHATIE_OA_ID } from '../../src/config.js'

const ducks = new Ducks({
counter : CounterDuck,
Expand Down
52 changes: 35 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
{
"name": "ha-wechaty",
"version": "0.7.7",
"version": "0.9.1",
"description": "HAWechaty is a Load Balance for providing High Availability for Wechaty Chatbot by spreading requests across multiple WeChat individual accounts.",
"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",
"wechaty-puppet": ">=0.43",
"node": ">=14"
},
"directories": {
Expand All @@ -13,19 +21,20 @@
"test": "tests"
},
"scripts": {
"build": "tsc && tsc -p tsconfig.cjs.json",
"clean": "shx rm -fr dist/*",
"dist": "npm run clean && tsc",
"dist": "npm-run-all clean build dist:commonjs",
"dist:commonjs": "jq -n \"{ type: \\\"commonjs\\\" }\" > dist/cjs/package.json",
"example": "ts-node examples/ding-dong-bot.ts",
"pack": "npm pack",
"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": "ts-node --files examples/ding-dong-bot.ts",
"redux": "ts-node --files examples/redux-ducks-bot/redux-ducks-bot.ts",
"start": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/ding-dong-bot.ts",
"redux": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/redux-ducks-bot/redux-ducks-bot.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\" \"src/*.spec.ts\" \"tests/*.spec.ts\" \"tests/**/*.spec.ts\"",
"test:unit": "tap --node-arg=--loader=ts-node/esm --node-arg=--no-warnings \"src/**/*.spec.ts\" \"src/*.spec.ts\" \"tests/*.spec.ts\" \"tests/**/*.spec.ts\"",
"lint:es": "eslint --ignore-pattern fixtures/ 'src/**/*.ts' 'tests/**/*.ts'"
},
"dependencies": {
Expand All @@ -41,23 +50,24 @@
"wechaty": ">=0.62.3"
},
"devDependencies": {
"@chatie/eslint-config": "^0.12.4",
"@chatie/eslint-config": "^0.14.1",
"@chatie/git-scripts": "^0.6.2",
"@chatie/semver": "^0.4.7",
"@chatie/tsconfig": "^0.17.2",
"@types/cuid": "^2.0.1",
"@types/glob": "^7.1.4",
"@types/redux-mock-store": "^1.0.3",
"@types/remote-redux-devtools": "^0.5.5",
"@chatie/tsconfig": "^0.20.2",
"@types/cuid": "^1.3.1",
"@types/glob": "^7.1.3",
"@types/redux-mock-store": "^1.0.2",
"@types/remote-redux-devtools": "^0.5.4",
"dotenv": "^10.0.0",
"glob": "^7.1.7",
"npm-run-all": "^4.1.5",
"pkg-jq": "^0.2.11",
"redux-devtools-cli": "1.0.0-4",
"redux-mock-store": "^1.5.4",
"remote-redux-devtools": "^0.5.16",
"shx": "^0.3.3",
"tstest": "^0.4.10",
"typescript": "4.3",
"tstest": "^0.5.16",
"typescript": "^4.4.3",
"utility-types": "^3.10.0",
"wechaty": "^0.61.9",
"wechaty-ducks-contrib": "^0.2.2",
Expand Down Expand Up @@ -85,6 +95,14 @@
"access": "public",
"tag": "next"
},
"files": [
"bin/",
"dist/",
"src/"
],
"tap": {
"check-coverage": false
},
"git": {
"scripts": {
"pre-push": "npx git-scripts-pre-push"
Expand Down
20 changes: 20 additions & 0 deletions scripts/generate-package-json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/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
}

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

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.

43 changes: 39 additions & 4 deletions scripts/npm-pack-testing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +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 install --production *-*.*.*.tgz \
@types/node \
@chatie/tsconfig@$NPM_TAG \
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
2 changes: 1 addition & 1 deletion 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
Loading