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

Prepare to ESM support #44

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
time: "13:00"
open-pull-requests-limit: 10
91 changes: 91 additions & 0 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: NPM

on: [push, pull_request]

jobs:
build:
name: Build
strategy:
matrix:
os:
- ubuntu-latest
node:
- 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 }}

- name: Install Dependencies
run: npm install

- name: Test
run: npm test

pack:
name: Pack
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16

- name: Install Dependencies
run: npm install

- name: Generate 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/

- name: Install Dependencies
run: npm install

- name: Generate 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'
58 changes: 0 additions & 58 deletions .travis.yml

This file was deleted.

10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ _Hot Module Replacement_ (HMR) is a feature to inject updated modules into the a
## INSTALL

```shell
$ npm install hot-import
npm install hot-import
```

## USAGE
Expand Down Expand Up @@ -240,6 +240,14 @@ This module is highly inspired by [@gcaufy](https://github.com/gcaufy) via his b

## RELEASE NOTES

### master v0.3

1. ESM & CJS support.

### v0.2 Jun, 2019

1. Add macOS CI.

### v0.1 Oct, 2017

1. Passed all the unit tests under Windows/Linux/Mac
Expand Down
4 changes: 2 additions & 2 deletions examples/demo-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import * as assert from 'assert'
import * as fs from 'fs'
import * as path from 'path'

import hotImport from '../'
import hotImport from '../src/mod.js'

// import { log } from 'brolog'
// log.level('silly')

async function main() {
async function main () {
const MODULE_CODE_42 = 'module.exports = () => 42'
const MODULE_CODE_17 = 'module.exports.default = () => 17'

Expand Down
2 changes: 1 addition & 1 deletion examples/demo-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as assert from 'assert'
import * as fs from 'fs'
import * as path from 'path'

import hotImport from '../'
import hotImport from '../src/mod.js'

// import { log } from 'brolog'
// log.level('silly')
Expand Down
12 changes: 0 additions & 12 deletions index.ts

This file was deleted.

29 changes: 18 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
{
"name": "hot-import",
"version": "0.2.15",
"version": "0.3.3",
"description": "Hot Module Replacement (HMR) for Node.js",
"main": "dist/index.js",
"types": "dist/index.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": {
"node": ">=14"
},
"directories": {
"doc": "docs",
"test": "tests"
Expand All @@ -14,12 +23,13 @@
"demo": "npm run demo:ts",
"demo:ts": "ts-node examples/demo-ts",
"demo:js": "ts-node examples/demo-js",
"dist": "npm run clean && tsc",
"dist": "npm run clean && tsc && tsc -p tsconfig.cjs.json && npm run fixup",
"fixup": "echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
"lint": "npm run lint:es && npm run clean && tsc --noEmit",
"lint:es": "eslint 'src/**/*.ts' 'tests/**/*.spec.ts' --ignore-pattern tests/fixtures/",
"test": "npm run lint && npm run check-node-version && npm run test:unit",
"test:pack": "bash -x scripts/npm-pack-testing.sh",
"test:unit": "blue-tape -r ts-node/register \"src/**/*.spec.ts\" \"tests/**/*.spec.ts\""
"test:unit": "tap --node-arg=--loader=ts-node/esm \"src/**/*.spec.ts\" \"tests/**/*.spec.ts\""
},
"repository": {
"type": "git",
Expand All @@ -43,18 +53,18 @@
"callsites": "^3.0.0"
},
"devDependencies": {
"@chatie/eslint-config": "^0.8.1",
"@chatie/eslint-config": "^0.13.5",
"@chatie/git-scripts": "^0.2.5",
"@chatie/semver": "^0.4.7",
"@chatie/tsconfig": "^0.6.1",
"@chatie/tsconfig": "^0.17.2",
"@types/rimraf": "^2.0.2",
"check-node-version": "^4.0.0",
"cross-env": "^7.0.0",
"pkg-jq": "^0.2.4",
"rimraf": "^3.0.0",
"shx": "^0.3.2",
"source-map-support": "^0.5.8",
"tstest": "^0.4.2"
"tstest": "^0.5.16"
},
"files": [
"bin/",
Expand All @@ -65,9 +75,6 @@
"package.json",
"README.md"
],
"engines": {
"node": ">= 7"
},
"publishConfig": {
"access": "public",
"tag": "next"
Expand Down
Loading