Skip to content

Commit

Permalink
Merge pull request #62 from samchon/features/worker
Browse files Browse the repository at this point in the history
Publish both CJS and ESM
  • Loading branch information
samchon authored Mar 27, 2024
2 parents 02c681d + e8664ef commit 56f99cc
Show file tree
Hide file tree
Showing 27 changed files with 88 additions and 71 deletions.
19 changes: 15 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
"name": "tgrid",
"version": "0.9.8",
"version": "0.10.0",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"exports": {
".": {
"types": "./lib/index.d.ts",
"require": "./lib/index.js",
"import": "./lib/index.mjs"
}
},
"description": "Grid Computing Framework for TypeScript",
"author": {
"name": "Jeongho Nam",
Expand All @@ -12,7 +19,7 @@
"scripts": {
"api": "typedoc src --excludeNotDocumented -out ../tgrid.com/docs/api",
"build": "npm run build:main && npm run build:test",
"build:main": "rimraf lib && tsc",
"build:main": "rimraf lib && tsc && rollup -c",
"build:test": "rimraf bin && tsc --project test/tsconfig.json",
"dev": "npm run build:test -- --watch",
"prepare": "ts-patch install",
Expand All @@ -23,10 +30,12 @@
},
"dependencies": {
"import2": "^1.0.3",
"tstl": "^2.5.16",
"tstl": "3.0.0",
"ws": "^7.5.3"
},
"devDependencies": {
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/browserify": "^12.0.40",
"@types/node": "^20.11.26",
Expand All @@ -41,11 +50,13 @@
"prettier": "^3.2.5",
"puppeteer": "^22.4.1",
"rimraf": "^5.0.5",
"rollup": "^4.13.1",
"source-map-support": "^0.5.21",
"ts-node": "^10.9.2",
"ts-patch": "^3.1.2",
"tslib": "^2.6.2",
"typedoc": "^0.25.12",
"typescript": "^5.4.2",
"typescript": "^5.4.3",
"typescript-transform-paths": "^3.4.7",
"whatwg-fetch": "^3.6.2"
},
Expand Down
29 changes: 29 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const typescript = require("@rollup/plugin-typescript");
const terser = require("@rollup/plugin-terser");

module.exports = {
input: "./src/index.ts",
output: {
dir: "lib",
format: "esm",
entryFileNames: "[name].mjs",
sourcemap: true,
},
plugins: [
typescript({
tsconfig: "tsconfig.json",
module: "ES2020",
target: "ES2020",
}),
terser({
format: {
comments: "some",
beautify: true,
ecma: "2020",
},
compress: false,
mangle: false,
module: true,
}),
],
};
13 changes: 7 additions & 6 deletions src/components/Communicator.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Driver } from "../typings/Driver";
import { Invoke } from "./Invoke";

import { Pair } from "tstl/utility/Pair";
import { HashMap } from "tstl/container/HashMap";
import { ConditionVariable } from "tstl/thread/ConditionVariable";

import { DomainError } from "tstl/exception/DomainError";
import { RuntimeError } from "tstl/exception/RuntimeError";
import { serializeError } from "../utils/internal/serializeError";
import {
HashMap,
Pair,
ConditionVariable,
RuntimeError,
DomainError,
} from "tstl";

/**
* The basic communicator.
Expand Down
4 changes: 1 addition & 3 deletions src/protocols/internal/AcceptorBase.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { DomainError, RuntimeError } from "tstl";
import { Communicator } from "../../components/Communicator";

import { DomainError } from "tstl/exception/DomainError";
import { RuntimeError } from "tstl/exception/RuntimeError";

/**
* Basic Acceptor.
*
Expand Down
4 changes: 1 addition & 3 deletions src/protocols/internal/ConnectorBase.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { DomainError, RuntimeError } from "tstl";
import { Communicator } from "../../components/Communicator";

import { DomainError } from "tstl/exception/DomainError";
import { RuntimeError } from "tstl/exception/RuntimeError";

/**
* Basic Connector.
*
Expand Down
2 changes: 1 addition & 1 deletion src/protocols/web/WebAcceptor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type http from "http";
import type WebSocket from "ws";
import { DomainError } from "tstl/exception/DomainError";
import { DomainError } from "tstl";

import { AcceptorBase } from "../internal/AcceptorBase";
import { IWebCommunicator } from "./internal/IWebCommunicator";
Expand Down
5 changes: 1 addition & 4 deletions src/protocols/web/WebConnector.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { DomainError } from "tstl/exception/DomainError";
import { is_node } from "tstl/utility/node";
import { sleep_for } from "tstl/thread/global";

import { Invoke } from "../../components/Invoke";
import { WebError } from "./WebError";

Expand All @@ -10,6 +6,7 @@ import { IHeaderWrapper } from "../internal/IHeaderWrapper";
import { IWebCommunicator } from "./internal/IWebCommunicator";
import { once } from "../internal/once";
import { WebSocketPolyfill } from "./internal/WebSocketPolyfill";
import { DomainError, is_node, sleep_for } from "tstl";

/**
* Web Socket Connector.
Expand Down
2 changes: 1 addition & 1 deletion src/protocols/web/WebError.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DomainError } from "tstl/exception/DomainError";
import { DomainError } from "tstl";

/**
* Web Socket Error.
Expand Down
4 changes: 1 addition & 3 deletions src/protocols/web/WebServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import type http from "http";
import type https from "https";
import type net from "net";
import type WebSocket from "ws";
import { is_node } from "tstl/utility/node";

import { WebAcceptor } from "./WebAcceptor";
import { IServer } from "../internal/IServer";

import { IHeaderWrapper } from "../internal/IHeaderWrapper";
import { DomainError } from "tstl/exception/DomainError";
import { RuntimeError } from "tstl/exception/RuntimeError";
import { NodeModule } from "../../utils/internal/NodeModule";
import { is_node, DomainError, RuntimeError } from "tstl";

/**
* Web Socket Server.
Expand Down
2 changes: 1 addition & 1 deletion src/protocols/workers/SharedWorkerAcceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IWorkerSystem } from "./internal/IWorkerSystem";

import { Invoke } from "../../components/Invoke";
import { IReject } from "./internal/IReject";
import { DomainError } from "tstl/exception/DomainError";
import { DomainError } from "tstl";

/**
* SharedWorker acceptor for client.
Expand Down
5 changes: 1 addition & 4 deletions src/protocols/workers/SharedWorkerConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import { IHeaderWrapper } from "../internal/IHeaderWrapper";
import { IReject } from "./internal/IReject";
import { WebWorkerCompiler } from "./internal/WebWorkerCompiler";
import { once } from "../internal/once";

import { DomainError } from "tstl/exception/DomainError";
import { RuntimeError } from "tstl/exception/RuntimeError";
import { sleep_until } from "tstl/thread/global";
import { DomainError, RuntimeError, sleep_until } from "tstl";

/**
* SharedWorker Connector
Expand Down
5 changes: 1 addition & 4 deletions src/protocols/workers/SharedWorkerServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { SharedWorkerAcceptor } from "./SharedWorkerAcceptor";

import { IHeaderWrapper } from "../internal/IHeaderWrapper";
import { once } from "../internal/once";

import { DomainError } from "tstl/exception/DomainError";
import { HashSet } from "tstl/container/HashSet";
import { is_node } from "tstl/utility/node";
import { HashSet, is_node, DomainError } from "tstl";

/**
* SharedWorker server.
Expand Down
6 changes: 1 addition & 5 deletions src/protocols/workers/WorkerConnector.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { DomainError } from "tstl/exception/DomainError";
import { is_node } from "tstl/utility/node";
import { sleep_until } from "tstl/thread/global";

import { Invoke } from "../../components/Invoke";

import { IHeaderWrapper } from "../internal/IHeaderWrapper";
Expand All @@ -11,7 +7,7 @@ import { ConnectorBase } from "../internal/ConnectorBase";
import { NodeWorkerCompiler } from "./internal/NodeWorkerCompiler";
import { WebWorkerCompiler } from "./internal/WebWorkerCompiler";
import { once } from "../internal/once";
import { Singleton } from "tstl/thread/Singleton";
import { Singleton, is_node, DomainError, sleep_until } from "tstl";

/**
* Worker Connector.
Expand Down
13 changes: 7 additions & 6 deletions src/protocols/workers/WorkerServer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import { DomainError } from "tstl/exception/DomainError";
import { RuntimeError } from "tstl/exception/RuntimeError";
import { Singleton } from "tstl/thread/Singleton";
import { sleep_until } from "tstl/thread/global";
import { is_node } from "tstl/utility/node";

import { Communicator } from "../../components/Communicator";
import { IServer } from "../internal/IServer";
import { IWorkerSystem } from "./internal/IWorkerSystem";
Expand All @@ -14,6 +8,13 @@ import { once } from "../internal/once";

import { ThreadPort } from "./internal/threads/ThreadPort";
import { ProcessChannel } from "./internal/processes/ProcessChannel";
import {
Singleton,
is_node,
DomainError,
sleep_until,
RuntimeError,
} from "tstl";

/**
* Worker Server.
Expand Down
2 changes: 1 addition & 1 deletion src/utils/internal/NodeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type * as __ws from "ws";
import type * as __process from "process";

import import2 from "import2";
import { Singleton } from "tstl/thread/Singleton";
import { Singleton } from "tstl";

export namespace NodeModule {
export const cp: Singleton<Promise<typeof __cp>> = new Singleton(() =>
Expand Down
2 changes: 1 addition & 1 deletion test/browser/web-client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InvalidArgument } from "tstl/exception/InvalidArgument";
import { InvalidArgument } from "tstl";

import { ICalculator } from "../controllers/ICalculator";
import { complete } from "./internal";
Expand Down
5 changes: 1 addition & 4 deletions test/controllers/ICalculator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { DomainError } from "tstl/exception/DomainError";
import { InvalidArgument } from "tstl/exception/InvalidArgument";
import { randint } from "tstl/algorithm/random";

import { DomainError, InvalidArgument, randint } from "tstl";
import { Calculator } from "../providers/Calculator";
import { Driver } from "tgrid";

Expand Down
3 changes: 1 addition & 2 deletions test/controllers/IScript.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { DomainError } from "tstl/exception/DomainError";
import { LengthError } from "tstl/exception/LengthError";
import { LengthError, DomainError } from "tstl";

export interface IScript {
name: string;
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/IVector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { DomainError } from "tstl/exception/DomainError";
import { randint } from "tstl/algorithm/random";
import { Driver } from "tgrid";
import { randint, DomainError } from "tstl";

export interface IVector<T> {
size(): T;
Expand Down
2 changes: 1 addition & 1 deletion test/node/components/test_pseudo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Communicator, Invoke, Driver } from "tgrid";
import { InvalidArgument } from "tstl/exception/InvalidArgument";
import { InvalidArgument } from "tstl";

import { Calculator } from "../../providers/Calculator";
import { ICalculator } from "../../controllers/ICalculator";
Expand Down
2 changes: 1 addition & 1 deletion test/node/protocols/web/test_web_calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Calculator } from "../../../providers/Calculator";
import { ICalculator } from "../../../controllers/ICalculator";
import { IVector } from "../../../controllers/IVector";

import { Vector } from "tstl/container/Vector";
import { Vector } from "tstl";
import { Driver, WebConnector, WebServer } from "tgrid";

const PORT: number = 10101;
Expand Down
2 changes: 1 addition & 1 deletion test/node/protocols/web/test_web_chat.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Driver, WebConnector, WebServer } from "tgrid";
import { sleep_for } from "tstl/thread/global";
import { sleep_for } from "tstl";

import { IScript } from "../../../controllers/IScript";
import { IChatPrinter } from "../../../controllers/IChatPrinter";
Expand Down
15 changes: 8 additions & 7 deletions test/node/protocols/web/test_web_mutex.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Vector } from "tstl/container/Vector";
import { Mutex } from "tstl/thread/Mutex";
import { DomainError } from "tstl/exception/DomainError";
import { RuntimeError } from "tstl/exception/RuntimeError";

import { is_sorted } from "tstl/algorithm/sorting";
import { sleep_for } from "tstl/thread/global";
import { Driver, WebConnector, WebServer } from "tgrid";
import {
Mutex,
Vector,
sleep_for,
RuntimeError,
is_sorted,
DomainError,
} from "tstl";

const PORT: number = 10101;
const COUNT: number = 10;
Expand Down
2 changes: 1 addition & 1 deletion test/node/protocols/workers/internal/chat-child.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IScript } from "../../../../controllers/IScript";
import { IChatService } from "../../../../controllers/IChatService";

import { sleep_for } from "tstl/thread/global";
import { sleep_for } from "tstl";
import { Driver, WorkerServer } from "tgrid";

async function main(): Promise<void> {
Expand Down
3 changes: 1 addition & 2 deletions test/node/protocols/workers/test_worker_chat.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { DomainError } from "tstl/exception/DomainError";
import { LengthError } from "tstl/exception/LengthError";
import { LengthError, DomainError } from "tstl";

export interface IScript {
name: string;
Expand Down
2 changes: 1 addition & 1 deletion test/node/protocols/workers/test_worker_join.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from "fs";
import { WorkerConnector } from "tgrid";
import { sleep_for } from "tstl/thread";
import { sleep_for } from "tstl";

const FILE_PATH = __dirname + "/log.dat";

Expand Down
3 changes: 1 addition & 2 deletions test/providers/ChatService.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { IChatService } from "../controllers/IChatService";

import { HashMap } from "tstl/container/HashMap";
import { IChatPrinter } from "../controllers/IChatPrinter";

import { IScript } from "../controllers/IScript";
import { DomainError } from "tstl/exception/DomainError";
import { Driver } from "tgrid";
import { HashMap, DomainError } from "tstl";

export class ChatService implements IChatService {
private static participants_: HashMap<string, Driver<IChatPrinter>> =
Expand Down

0 comments on commit 56f99cc

Please sign in to comment.