Skip to content

Commit

Permalink
Merge branch 'release/3.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
codenirvana committed Jun 11, 2024
2 parents 78bae16 + 3358c3c commit 1ff5bdd
Show file tree
Hide file tree
Showing 36 changed files with 10,894 additions and 3,427 deletions.
293 changes: 149 additions & 144 deletions .eslintrc

Large diffs are not rendered by default.

Binary file removed .github/travis-deploy-key.enc
Binary file not shown.
91 changes: 91 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: CI

on:
push:
paths-ignore:
- '*.md'
pull_request:
branches: [$default-branch]
schedule:
- cron: '0 12 * * 0'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: 'npm'

- name: Install
run: npm ci

- name: Run lint tests
run: npm run test-lint

browser-tests:
name: Browser Tests
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: 'npm'

- name: Install
run: npm ci

- name: Run browser tests
run: npm run test-browser

tests:
name: Tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node-version: [16, 18]
os: [ubuntu-latest, windows-latest]
include:
- coverage: true
node-version: 20
os: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install
run: npm ci

- name: Run system tests
run: npm run test-system

- name: Run unit tests
run: npm run test-unit

- if: ${{ matrix.coverage }}
name: Upload coverage
run: npm run codecov -- -c -Z -f .coverage/coverage-final.json -F unit
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,5 @@ test/
.eslintrc
.nycrc.js
codecov.yml
.travis.yml
.editorconfig
.jsdoc-config.json
96 changes: 0 additions & 96 deletions .travis.yml

This file was deleted.

11 changes: 11 additions & 0 deletions CHANGELOG.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
3.0.0:
date: 2024-06-11
new feature:
- GH-666 Replaced Node VM with Worker threads
breaking changes:
- GH-668 Dropped support for Node < v16
chores:
- GH-667 Added GitHub CI and remove Travis
- Updated ESLint rules
- Updated dependencies

2.1.1:
date: 2022-07-12
fixed bugs:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# UVM [![Build Status](https://travis-ci.com/postmanlabs/uvm.svg?branch=develop)](https://travis-ci.com/postmanlabs/uvm) [![codecov](https://codecov.io/gh/postmanlabs/uvm/branch/develop/graph/badge.svg)](https://codecov.io/gh/postmanlabs/uvm)
# UVM [![CI](https://github.com/postmanlabs/uvm/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/postmanlabs/uvm/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/postmanlabs/uvm/branch/develop/graph/badge.svg)](https://codecov.io/gh/postmanlabs/uvm)

Module that exposes an event emitter to send data across contexts ([VM](https://nodejs.org/api/vm.html) in Node.js and [Web Workers](https://www.w3.org/TR/workers/) in browser).
Module that exposes an event emitter to send data across contexts ([Worker threads](https://nodejs.org/api/worker_threads.html) in Node.js and [Web Workers](https://www.w3.org/TR/workers/) in browser).

## Installation
UVM can be installed using NPM or directly from the git repository within your NodeJS projects. If installing from NPM, the following command installs the module and saves in your `package.json`
Expand Down
11 changes: 11 additions & 0 deletions firmware/sandbox-base.browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = `
(function (self) {
var init = function (e) {
self.removeEventListener('message', init);
const __init_uvm = e && (e.__init_uvm || (e.data && e.data.__init_uvm));
// eslint-disable-next-line no-eval
(typeof __init_uvm === 'string') && eval(__init_uvm);
};
self.addEventListener('message', init);
}(self));
`;
11 changes: 5 additions & 6 deletions firmware/sandbox-base.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module.exports = `
(function (self) {
var init = function (e) {
self.removeEventListener('message', init);
(function (parentPort) {
var init = function (m) {
// eslint-disable-next-line no-eval
(e && e.data && (typeof e.data.__init_uvm === 'string')) && eval(e.data.__init_uvm);
m && m.__init_uvm && (typeof m.__init_uvm === 'string') && eval(m.__init_uvm);
};
self.addEventListener('message', init);
}(self));
parentPort.once('message', init);
}(require('worker_threads').parentPort));
`;
57 changes: 22 additions & 35 deletions lib/bridge-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,55 @@
*/

/**
* Hold reference to this for security purpose
* Generate code to be executed inside a worker for bootstrap.
*
* @private
*/
const toString = String.prototype.toString;

/**
* Generate code to be executed inside a VM for bootstrap.
*
* @param {String|Buffer} bootCode
* @return {String}
*/
/* eslint-disable max-len */
module.exports = function (bootCode) {
/* eslint-disable @stylistic/js/max-len */
module.exports = function () {
return `;
(function (emit) {
/*! (c) 2020 Andrea Giammarchi, (ISC) */
var Flatted=function(n){"use strict";function t(n){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},t(n)}var r=JSON.parse,e=JSON.stringify,o=Object.keys,u=String,f="string",i={},c="object",a=function(n,t){return t},l=function(n){return n instanceof u?u(n):n},s=function(n,r){return t(r)===f?new u(r):r},y=function n(r,e,f,a){for(var l=[],s=o(f),y=s.length,p=0;p<y;p++){var v=s[p],S=f[v];if(S instanceof u){var b=r[S];t(b)!==c||e.has(b)?f[v]=a.call(f,v,b):(e.add(b),f[v]=i,l.push({k:v,a:[r,e,b,a]}))}else f[v]!==i&&(f[v]=a.call(f,v,S))}for(var m=l.length,g=0;g<m;g++){var h=l[g],O=h.k,d=h.a;f[O]=a.call(f,O,n.apply(null,d))}return f},p=function(n,t,r){var e=u(t.push(r)-1);return n.set(r,e),e},v=function(n,e){var o=r(n,s).map(l),u=o[0],f=e||a,i=t(u)===c&&u?y(o,new Set,u,f):u;return f.call({"":i},"",i)},S=function(n,r,o){for(var u=r&&t(r)===c?function(n,t){return""===n||-1<r.indexOf(n)?t:void 0}:r||a,i=new Map,l=[],s=[],y=+p(i,l,u.call({"":n},"",n)),v=!y;y<l.length;)v=!0,s[y]=e(l[y++],S,o);return"["+s.join(",")+"]";function S(n,r){if(v)return v=!v,r;var e=u.call(this,n,r);switch(t(e)){case c:if(null===e)return e;case f:return i.get(e)||p(i,l,e)}return e}};return n.fromJSON=function(n){return v(e(n))},n.parse=v,n.stringify=S,n.toJSON=function(n){return r(S(n))},n}({});
const Flatted=function(n){"use strict";function t(n){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},t(n)}var r=JSON.parse,e=JSON.stringify,o=Object.keys,u=String,f="string",i={},c="object",a=function(n,t){return t},l=function(n){return n instanceof u?u(n):n},s=function(n,r){return t(r)===f?new u(r):r},y=function n(r,e,f,a){for(var l=[],s=o(f),y=s.length,p=0;p<y;p++){var v=s[p],S=f[v];if(S instanceof u){var b=r[S];t(b)!==c||e.has(b)?f[v]=a.call(f,v,b):(e.add(b),f[v]=i,l.push({k:v,a:[r,e,b,a]}))}else f[v]!==i&&(f[v]=a.call(f,v,S))}for(var m=l.length,g=0;g<m;g++){var h=l[g],O=h.k,d=h.a;f[O]=a.call(f,O,n.apply(null,d))}return f},p=function(n,t,r){var e=u(t.push(r)-1);return n.set(r,e),e},v=function(n,e){var o=r(n,s).map(l),u=o[0],f=e||a,i=t(u)===c&&u?y(o,new Set,u,f):u;return f.call({"":i},"",i)},S=function(n,r,o){for(var u=r&&t(r)===c?function(n,t){return""===n||-1<r.indexOf(n)?t:void 0}:r||a,i=new Map,l=[],s=[],y=+p(i,l,u.call({"":n},"",n)),v=!y;y<l.length;)v=!0,s[y]=e(l[y++],S,o);return"["+s.join(",")+"]";function S(n,r){if(v)return v=!v,r;var e=u.call(this,n,r);switch(t(e)){case c:if(null===e)return e;case f:return i.get(e)||p(i,l,e)}return e}};return n.fromJSON=function(n){return v(e(n))},n.parse=v,n.stringify=S,n.toJSON=function(n){return r(S(n))},n}({});
/*! (C) Postdot Technologies, Inc (Apache-2.0) */
var arrayProtoSlice = Array.prototype.slice;
bridge = { // ensure global using no var
_events: {},
emit: function (name) {
var self = this,
args = arrayProtoSlice.call(arguments, 1);
this._events[name] && [...this._events[name]].forEach(function (listener) {
listener.apply(self, args);
emit(name, ...args) {
[...this.listeners(name)].forEach((listener) => {
listener.apply(this, args);
});
},
dispatch: function () {
emit(Flatted.stringify(arrayProtoSlice.call(arguments)));
listeners(name) {
return this._events[name] || [];
},
on: function (name, listener) {
dispatch(...args) {
emit(Flatted.stringify(args));
},
on(name, listener) {
if (typeof listener !== 'function') { return; }
!this._events[name] && (this._events[name] = []);
this._events[name].push(listener);
},
once: function (name, listener) {
once(name, listener) {
const self = this;
self.on(name, function fn () {
self.off(name, fn);
listener.apply(self, arguments);
});
},
off: function (name, listener) {
var e = this._events[name],
i = e && e.length || 0;
off(name, listener) {
const e = this.listeners(name);
let i = e && e.length || 0;
if (!e) { return; }
if (arguments.length === 1) {
return delete this._events[name];
}
if (typeof listener === 'function' && (i >= 1)) {
if (!i) { return; }
if (!listener) { return delete this._events[name]; }
if (typeof listener === 'function') {
while (i >= 0) {
(e[i] === listener) && e.splice(i, 1);
i -= 1;
Expand All @@ -81,7 +70,5 @@ module.exports = function (bootCode) {
}(bridge, bridge.emit));
}(__uvm_emit));
// boot code starts hereafter
${(typeof bootCode === 'string') ? toString.call(bootCode) : ''};`;
`;
};
Loading

0 comments on commit 1ff5bdd

Please sign in to comment.