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

ESM wip #163

Merged
merged 6 commits into from
Aug 31, 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.
8 changes: 4 additions & 4 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ jobs:
- 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 @@ -80,8 +80,8 @@ jobs:
- 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: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ WECHATY_PUPPET_SERVICE_TOKEN=${WECHATY_PUPPET_SERVCIE_TOKEN} node bot.js

## History

### master
### master v0.31

Refactoring
1. ES Modules supported.

### v0.30 (Aug 25, 2021)

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 @@ -9,7 +9,7 @@ import {
FileBox,
} from 'wechaty-puppet'

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

/**
*
Expand Down
46 changes: 30 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
{
"name": "wechaty-puppet-service",
"version": "0.31.3",
"version": "0.31.5",
"description": "Puppet Service for Wechaty",
"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.60",
"wechaty-puppet": ">=0.41"
"wechaty": ">=0.69",
"wechaty-puppet": ">=0.43"
},
"directories": {
"test": "tests"
},
"scripts": {
"clean": "shx rm -fr dist/*",
"dist": "npm run clean && tsc",
"dist": "npm-run-all clean build fixup",
"build": "tsc && tsc -p tsconfig.cjs.json",
"fixup": "shx echo '{\"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",
"start": "ts-node examples/ding-dong-bot.ts",
"test": "npm run lint && npm run test:unit",
"test:pack": "bash -x scripts/npm-pack-testing.sh",
"test:unit": "tap --node-arg=--require=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\""
},
"repository": {
Expand All @@ -43,34 +51,40 @@
},
"homepage": "https://github.com/wechaty/wechaty-puppet-service#readme",
"devDependencies": {
"@chatie/eslint-config": "^0.12.4",
"@chatie/eslint-config": "^0.13.5",
"@chatie/git-scripts": "^0.6.2",
"@chatie/semver": "^0.4.7",
"@chatie/tsconfig": "^0.17.2",
"@types/google-protobuf": "^3.15.2",
"@types/lru-cache": "^5.1.1",
"@types/semver": "^6.2.2",
"@types/ws": "^7.4.4",
"npm-run-all": "^4.1.5",
"pkg-jq": "^0.2.11",
"shx": "^0.3.3",
"tstest": "^0.5.16",
"typescript": "4.3",
"wechaty": "^0.61",
"wechaty-puppet": "^0.41.7",
"wechaty-puppet-mock": "^0.29.6"
"typescript": "^4.4",
"wechaty": "^0.69.12",
"wechaty-puppet": "^0.43.9",
"wechaty-puppet-mock": "^0.31.3"
},
"dependencies": {
"flash-store": "^1.1.1",
"rxjs": "^7.1.0",
"semver": "^6.3.0",
"stronger-typed-streams": "^0.2.0",
"wechaty-grpc": "^0.25.1",
"wechaty-grpc": "^0.27.6",
"wechaty-token": "^0.5.8"
},
"publishConfig": {
"access": "public",
"tag": "next"
},
"files": [
"bin/",
"dist/",
"src/"
],
"tap": {
"check-coverage": false
},
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 { 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.

42 changes: 38 additions & 4 deletions scripts/npm-pack-testing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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
Expand All @@ -18,18 +18,52 @@ mv ./*-*.*.*.tgz "$TMPDIR"
cp tests/fixtures/smoke-testing.ts "$TMPDIR"

cd $TMPDIR

npm init -y
npm install *-*.*.*.tgz \
@chatie/tsconfig \
brolog \
npm install --production *-*.*.*.tgz \
@types/node \
@chatie/tsconfig@$NPM_TAG \
"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
#

# https://stackoverflow.com/a/59203952/1123955
echo "`jq '.type="module"' package.json`" > package.json

./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 src/auth/auth-impl-token.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env ts-node
#!/usr/bin/env node --no-warnings --loader ts-node/esm

import {
test,
Expand All @@ -9,9 +9,9 @@ import {
GrpcStatus,
Metadata,
UntypedServiceImplementation,
} from './grpc-js'
} from './grpc-js.js'

import { authImplToken } from './auth-impl-token'
import { authImplToken } from './auth-impl-token.js'

test('authImplToken()', async t => {
const sandbox = sinon.createSandbox()
Expand Down
6 changes: 3 additions & 3 deletions src/auth/auth-impl-token.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { log } from '../config'
import { log } from 'wechaty-puppet'

import {
StatusBuilder,
Expand All @@ -8,9 +8,9 @@ import {
ServerUnaryCall,
GrpcStatus,
UntypedServiceImplementation,
} from './grpc-js'
} from './grpc-js.js'

import { monkeyPatchMetadataFromHttp2Headers } from './mokey-patch-header-authorization'
import { monkeyPatchMetadataFromHttp2Headers } from './mokey-patch-header-authorization.js'

/**
* Huan(202108): Monkey patch to support
Expand Down
6 changes: 3 additions & 3 deletions src/auth/ca.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#!/usr/bin/env ts-node
#!/usr/bin/env node --no-warnings --loader ts-node/esm

import {
test,
} from 'tstest'

import https from 'https'

import * as envVar from './env-vars'
import * as envVar from './env-vars.js'
import { AddressInfo } from 'ws'

import {
TLS_CA_CERT,
TLS_INSECURE_SERVER_CERT_COMMON_NAME,
TLS_INSECURE_SERVER_CERT,
TLS_INSECURE_SERVER_KEY,
} from './ca'
} from './ca.js'

test('CA smoke testing', async t => {

Expand Down
4 changes: 2 additions & 2 deletions src/auth/call-cred.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env ts-node
#!/usr/bin/env node --no-warnings --loader ts-node/esm

import {
test,
sinon,
} from 'tstest'

import { metaGeneratorToken } from './call-cred'
import { metaGeneratorToken } from './call-cred.js'

test('metaGeneratorToken()', async t => {
const TOKEN = 'UUIDv4'
Expand Down
2 changes: 1 addition & 1 deletion src/auth/call-cred.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
credentials,
CallMetadataGenerator,
Metadata,
} from './grpc-js'
} from './grpc-js.js'

/**
* With server authentication SSL/TLS and a custom header with token
Expand Down
14 changes: 8 additions & 6 deletions src/auth/grpc-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ import {
import {
CallMetadataGenerator,
} from '@grpc/grpc-js/build/src/call-credentials'
import { Status as GrpcStatus } from '@grpc/grpc-js/build/src/constants'
import { Status as GrpcStatus } from '@grpc/grpc-js/build/src/constants.js'

export type {
UntypedServiceImplementation,
UntypedHandleCall,
sendUnaryData,
ServerUnaryCall,
CallMetadataGenerator,
}
export {
credentials,
CallMetadataGenerator,
GrpcStatus,
Metadata,
sendUnaryData,
ServerUnaryCall,
StatusBuilder,
UntypedHandleCall,
UntypedServiceImplementation,
}
6 changes: 3 additions & 3 deletions src/auth/mod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { authImplToken } from './auth-impl-token'
import { monkeyPatchMetadataFromHttp2Headers } from './mokey-patch-header-authorization'
import { callCredToken } from './call-cred'
import { authImplToken } from './auth-impl-token.js'
import { monkeyPatchMetadataFromHttp2Headers } from './mokey-patch-header-authorization.js'
import { callCredToken } from './call-cred.js'

export {
authImplToken,
Expand Down
4 changes: 2 additions & 2 deletions src/auth/mokey-patch-header-authorization.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import http2 from 'http2'

import { log } from '../config'
import { log } from 'wechaty-puppet'

import {
Metadata,
} from './grpc-js'
} from './grpc-js.js'

/**
* Huan(202108): This is for compatible with old clients (version v0.26 or before)
Expand Down
6 changes: 3 additions & 3 deletions src/auth/monkey-patch-header-authorization.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env ts-node
#!/usr/bin/env node --no-warnings --loader ts-node/esm

import { test } from 'tstest'
import http2 from 'http2'

import {
Metadata,
} from './grpc-js'
} from './grpc-js.js'

import { monkeyPatchMetadataFromHttp2Headers } from './mokey-patch-header-authorization'
import { monkeyPatchMetadataFromHttp2Headers } from './mokey-patch-header-authorization.js'

test('monkeyPatchMetadataFromHttp2Headers', async t => {
const AUTHORITY = '__authority__'
Expand Down
4 changes: 2 additions & 2 deletions src/client/grpc-client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env ts-node
#!/usr/bin/env node --no-warnings --loader ts-node/esm

import { test } from 'tstest'

import { GrpcClient } from './grpc-client'
import { GrpcClient } from './grpc-client.js'

/**
* Huan(202108):
Expand Down
Loading