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 enable #49

Merged
merged 1 commit into from
Oct 10, 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.
103 changes: 103 additions & 0 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: NPM

on: [push, pull_request]

jobs:
build:
name: Build
strategy:
matrix:
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@v2
with:
node-version: ${{ matrix.node-version }}
cache: npm
cache-dependency-path: package.json

- name: Install Dependencies
run: npm install

- name: Test
run: npm test

pack:
name: Pack
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- 16
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: npm
cache-dependency-path: package.json

- name: Install Dependencies
run: npm install

- name: Generate Package version
run: ./scripts/generate-version.sh

- name: Pack Testing
run: ./scripts/npm-pack-testing.sh

publish:
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: 16
registry-url: https://registry.npmjs.org/
cache: npm
cache-dependency-path: package.json

- name: Install Dependencies
run: npm install

- name: Generate Package version
run: ./scripts/generate-version.sh

- name: Set Publish Config
run: ./scripts/package-publish-config-tag.sh

- name: Build Dist
run: npm run dist

- name: Check Branch
id: check-branch
run: |
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
if: steps.check-branch.outputs.match == 'true'
run: |
NAME=$(npx pkg-jq -r .name)
VERSION=$(npx pkg-jq -r .version)
if npx version-exists "$NAME" "$VERSION"
then echo "$NAME@$VERSION exists on NPM, skipped."
else npm publish
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Is Not A Publish Branch
if: steps.check-branch.outputs.match != 'true'
run: echo 'Not A Publish Branch'
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ In developing ...

## THANKS

Thanks to Damon Oehlman (https://github.com/DamonOehlman) who owned the `watchdog` name of NPM module. He is so kind and nice that passed this name over to me after my request.
Thanks to Damon Oehlman (<https://github.com/DamonOehlman>)
who owned the `watchdog` name of NPM module.
He is so kind and nice that passed this name over to me after my request.

## AUTHOR

Expand All @@ -75,6 +77,6 @@ Thanks to Damon Oehlman (https://github.com/DamonOehlman) who owned the `watchdo

## COPYRIGHT & LICENSE

- Code & Docs © 2017-2019 Huan LI \<[email protected]\>
- Code & Docs © 2017-now Huan LI \<[email protected]\>
- Code released under the Apache-2.0 License
- Docs released under Creative Commons
2 changes: 1 addition & 1 deletion examples/demo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Watchdog from '../'
import { Watchdog } from '../src/mod.js'

async function main () {
const TIMEOUT = 1 * 1000 // 1 second
Expand Down
8 changes: 0 additions & 8 deletions index.ts

This file was deleted.

50 changes: 30 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
{
"name": "watchdog",
"version": "0.8.21",
"version": "0.9.0",
"description": "An Timer used to Detect and Recover from Malfunctions",
"main": "bundles/watchdog.umd.js",
"types": "dist/watchdog.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": {
"node": ">=16",
"npm": ">=7"
},
"scripts": {
"build": "tsc --module esnext --moduleResolution node",
"build": "tsc && tsc -p tsconfig.cjs.json",
"clean": "shx rm -fr dist/* bundles/*",
"dist": "npm run clean && npm run build && npm run rollup && npm run dist:es6to5",
"dist": "npm-run-all clean build dist:commonjs",
"dist:commonjs": "jq -n \"{ type: \\\"commonjs\\\" }\" > dist/cjs/package.json",
"lint": "npm-run-all lint:es lint:ts lint:md",
"dist:es6to5": "tsc --out ./bundles/watchdog.umd.js --target es5 --allowJs bundles/watchdog.es6.umd.js --lib es6,dom",
"doc": "npm run dist && echo '# Watchdog v'$(jq -r .version package.json)' Documentation\n' > docs/index.md && jsdoc2md dist/watchdog.js >> docs/index.md",
"demo": "ts-node examples/demo",
"example": "npm run dmeo",
"lint": "npm run lint:es && npm run lint:ts",
"lint:ts": "tsc --noEmit",
"lint:md": "markdownlint README.md",
"lint:es": "eslint --ignore-pattern tests/fixtures/ '{bin,examples,scripts,src,tests}/**/*.ts'",
"pack": "npm pack",
"lint:ts": "tsc --isolatedModules --noEmit",
"rollup": "rollup -c",
"test": "npm run lint && npm run test:unit",
"test:unit": "blue-tape -r ts-node/register \"src/**/*.spec.ts\" \"tests/**/*.spec.ts\"",
"test:unit": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" tap \"src/**/*.spec.ts\" \"tests/**/*.spec.ts\"",
"test:pack": "bash -x scripts/npm-pack-testing.sh"
},
"repository": {
Expand All @@ -39,32 +47,34 @@
},
"homepage": "https://github.com/huan/watchdog#readme",
"devDependencies": {
"@chatie/eslint-config": "^0.12.1",
"@chatie/eslint-config": "^0.14.1",
"@chatie/git-scripts": "^0.6.1",
"@chatie/semver": "^0.4.7",
"@chatie/tsconfig": "^0.14.1",
"@chatie/tsconfig": "^0.20.2",
"brolog": "^1.3.3",
"cross-env": "^7.0.3",
"jsdoc-to-markdown": "^7.0.0",
"npm-run-all": "^4.1.5",
"pkg-jq": "^0.2.4",
"rollup": "^2.0.0",
"rollup-plugin-json": "^4.0.0",
"shx": "^0.3.0",
"source-map-support": "^0.5.0",
"tstest": "^0.4.9"
"tstest": "^0.7.3"
},
"peerDependencies": {},
"dependencies": {
"brolog": "^1.3.3"
},
"files": [
"package.json",
"README.md",
"CHANGELOG.md",
"LICENSE",
"bin/",
"bundles/",
"src/",
"dist/"
"dist/",
"src/"
],
"tap": {
"check-coverage": false
},
"publishConfig": {
"access": "public",
"tag": "next"
Expand Down
56 changes: 48 additions & 8 deletions scripts/npm-pack-testing.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,67 @@
#!/usr/bin/env bash
set -e

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

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"
trap "rm -fr '$TMPDIR'" EXIT

mv ./*-*.*.*.tgz "$TMPDIR"
cp tests/fixtures/smoke-testing.ts "$TMPDIR"

cd $TMPDIR

npm init -y
npm install *-*.*.*.tgz \
@types/node \
typescript
npm install --production ./*-*.*.*.tgz \
@chatie/tsconfig@$NPM_TAG \
pkg-jq \

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

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

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

npx 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
15 changes: 15 additions & 0 deletions src/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {
Watchdog,
WatchdogFood,
} from './watchdog.js'
import {
VERSION,
} from './version.js'

export type {
WatchdogFood,
}
export {
VERSION,
Watchdog,
}
9 changes: 4 additions & 5 deletions src/version.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env ts-node
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm

// tslint:disable:no-shadowed-variable
import test from 'blue-tape'
import { test } from 'tstest'

import { VERSION } from './version'
import { VERSION } from './version.js'

test('Make sure the VERSION is fresh in source code', async (t) => {
test('Make sure the VERSION is fresh in source code', async t => {
t.equal(VERSION, '0.0.0', 'version should be 0.0.0 in source code, only updated before publish to NPM')
})
Loading