Skip to content

Commit

Permalink
feat: use github action and drop non-lts Node.js support (#4)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Drop Node.js < 14 support
  • Loading branch information
fengmk2 authored Jun 13, 2023
1 parent 3a27475 commit 9592a9b
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 268 deletions.
5 changes: 5 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"eslint-config-egg"
]
}
16 changes: 16 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CI

on:
push:
branches: [ master ]

pull_request:
branches: [ master ]

jobs:
Job:
name: Node.js
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest, macos-latest, windows-latest'
version: '14, 16, 18, 20'
14 changes: 14 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Release
on:
push:
branches: [ master ]

jobs:
release:
name: Node.js
uses: node-modules/github-actions/.github/workflows/node-release.yml@master
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
with:
checkTest: false
4 changes: 0 additions & 4 deletions .jshintignore

This file was deleted.

95 changes: 0 additions & 95 deletions .jshintrc

This file was deleted.

6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

5 changes: 0 additions & 5 deletions AUTHORS

This file was deleted.

29 changes: 7 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
/**!
* sendmessage - index.js
*
* Copyright(c) fengmk2 and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <[email protected]> (http://fengmk2.github.com)
*/
const { isMainThread, parentPort } = require('worker_threads');

'use strict';

/**
* Module dependencies.
*/
var { isMainThread, parentPort } = require('worker_threads');

var IS_NODE_DEV_RUNNER = /node\-dev$/.test(process.env._ || '');
let IS_NODE_DEV_RUNNER = /node\-dev$/.test(process.env._ || '');
if (!IS_NODE_DEV_RUNNER && process.env.IS_NODE_DEV_RUNNER) {
IS_NODE_DEV_RUNNER = true;
}
Expand All @@ -38,24 +23,24 @@ module.exports = function send(child, message) {

// child is worker
if (typeof child.postMessage === 'function') {
return child.postMessage(message)
return child.postMessage(message);
}
// in worker thread
if (!isMainThread) {
return parentPort.postMessage(message)
return parentPort.postMessage(message);
}

// cluster.fork(): child.process is process
// childprocess.fork(): child is process
var connected = child.process ? child.process.connected : child.connected;
const connected = child.process ? child.process.connected : child.connected;

if (connected) {
return child.send(message);
}

// just log warnning message
var pid = child.process ? child.process.pid : child.pid;
var err = new Error('channel closed');
const pid = child.process ? child.process.pid : child.pid;
const err = new Error('channel closed');
console.warn('[%s][sendmessage] WARN pid#%s channel closed, nothing send\nstack: %s',
Date(), pid, err.stack);
};
25 changes: 10 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,17 @@
"index.js"
],
"scripts": {
"test": "mocha --check-leaks -R spec -t 5000 -r should test/*.test.js",
"test-cov": "node node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- --check-leaks -t 5000 -r should test/*.test.js",
"test-travis": "node node_modules/.bin/istanbul cover node_modules/.bin/_mocha --report lcovonly -- --check-leaks -t 5000 -r should test/*.test.js",
"jshint": "jshint .",
"autod": "autod -w --prefix '~'",
"cnpm": "npm install --registry=https://registry.npm.taobao.org",
"contributors": "contributors -f plain -o AUTHORS"
"test": "mocha --exit -t 5000 test/*.test.js",
"ci": "c8 npm test",
"lint": "eslint ."
},
"dependencies": {},
"devDependencies": {
"autod": "*",
"contributors": "*",
"istanbul": "*",
"jshint": "*",
"mm": "^1.5.1",
"mocha": "*",
"c8": "^7.14.0",
"eslint": "^8.42.0",
"eslint-config-egg": "^12.2.1",
"mm": "^3.3.0",
"mocha": "^10.2.0",
"should": "*"
},
"homepage": "https://github.com/node-modules/sendmessage",
Expand All @@ -43,8 +38,8 @@
"channel closed"
],
"engines": {
"node": ">= 0.10.0"
"node": ">= 14.17.0"
},
"author": "fengmk2 <[email protected]> (http://fengmk2.github.com)",
"author": "fengmk2 <[email protected]> (https://github.com/fengmk2)",
"license": "MIT"
}
31 changes: 7 additions & 24 deletions test/child.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,23 @@
/**!
* sendmessage - test/child.js
*
* Copyright(c) fengmk2 and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <[email protected]> (http://fengmk2.github.com)
*/
const { isMainThread, parentPort } = require('worker_threads');
const sendmessage = require('..');

'use strict';

/**
* Module dependencies.
*/

var { isMainThread, parentPort } = require('worker_threads');
var sendmessage = require('../');


var listener = function (message) {
const listener = function(message) {
if (message.disconnect) {
process.disconnect();
}

sendmessage(process, {
from: 'child',
got: message
got: message,
});
}
};
process.on('message', listener);
if (!isMainThread) {
// worker thread
parentPort.on('message', listener)
parentPort.on('message', listener);
}

sendmessage(process, {
from: 'child',
hi: 'this is a message send to master'
hi: 'this is a message send to master',
});
Loading

0 comments on commit 9592a9b

Please sign in to comment.