From 3c2ce7cbe8cd36df2884391c32b7e938a773491a Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Thu, 28 Mar 2024 05:38:19 +0900 Subject: [PATCH] Publish both CJS and ESM --- package.json | 19 +++++++++--- rollup.config.js | 29 +++++++++++++++++++ src/server/ProviderGroup.ts | 2 +- .../components/ServerConditionVariable.ts | 2 +- src/server/components/ServerMutex.ts | 4 +-- src/server/components/ServerSemaphore.ts | 2 +- src/server/components/SolidComponent.ts | 2 +- src/server/providers/ProviderBase.ts | 3 +- .../test_condition_variable_disconnections.ts | 3 +- .../test_condition_variable_waits.ts | 2 +- test/internal/Validator.ts | 13 +++++---- test/semaphores/test_semaphore_acquires.ts | 2 +- test/test_destructors.ts | 2 +- 13 files changed, 62 insertions(+), 23 deletions(-) create mode 100644 rollup.config.js diff --git a/package.json b/package.json index 902b707..3768083 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,19 @@ { "name": "mutex-server", - "version": "0.4.0", + "version": "0.5.0", "description": "Mutex Server using WebSocket", "main": "lib/index.js", "typings": "lib/index.d.ts", + "exports": { + ".": { + "types": "./lib/index.d.ts", + "require": "./lib/index.js", + "import": "./lib/index.mjs" + } + }, "scripts": { "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", @@ -49,22 +56,26 @@ }, "homepage": "https://github.com/samchon/mutex", "devDependencies": { + "@rollup/plugin-terser": "^0.4.4", + "@rollup/plugin-typescript": "^11.1.6", "@trivago/prettier-plugin-sort-imports": "^4.3.0", "@types/cli": "^0.11.19", "@types/node": "^13.11.1", "cli": "^1.0.1", "prettier": "^3.2.5", "rimraf": "^3.0.2", + "rollup": "^4.13.1", "source-map-support": "^0.5.16", "ts-node": "^8.8.2", "ts-patch": "^3.1.2", + "tslib": "^2.6.2", "typedoc": "^0.25.12", "typescript": "^5.4.2", "typescript-transform-paths": "^3.4.7" }, "dependencies": { - "tgrid": "^0.9.0", - "tstl": "^2.5.13" + "tgrid": "^0.10.0", + "tstl": "^3.0.0" }, "files": [ "LICENSE", diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..f948ecc --- /dev/null +++ b/rollup.config.js @@ -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, + }), + ], +}; diff --git a/src/server/ProviderGroup.ts b/src/server/ProviderGroup.ts index c2fca44..f71b257 100644 --- a/src/server/ProviderGroup.ts +++ b/src/server/ProviderGroup.ts @@ -1,5 +1,4 @@ import { WebAcceptor } from "tgrid"; -import { List } from "tstl/container/List"; import { Joiner } from "./components/internal/Joiner"; import { GlobalGroup } from "./GlobalGroup"; @@ -8,6 +7,7 @@ import { SemaphoresProvider } from "./providers/SemaphoresProvider"; import { MutexesProvider } from "./providers/MutexesProvider"; import { BarriersProvider } from "./providers/BarriersProvider"; import { LatchesProvider } from "./providers/LatchesProvider"; +import { List } from "tstl"; /** * @internal diff --git a/src/server/components/ServerConditionVariable.ts b/src/server/components/ServerConditionVariable.ts index bb47b65..1ddf210 100644 --- a/src/server/components/ServerConditionVariable.ts +++ b/src/server/components/ServerConditionVariable.ts @@ -1,8 +1,8 @@ import { WebAcceptor } from "tgrid"; import { List, sleep_for } from "tstl"; +import { LockType } from "tstl/lib/internal/thread/LockType"; import { SolidComponent } from "./SolidComponent"; -import { LockType } from "tstl/internal/thread/LockType"; import { Joiner } from "./internal/Joiner"; /** diff --git a/src/server/components/ServerMutex.ts b/src/server/components/ServerMutex.ts index bb30fb7..94e28b4 100644 --- a/src/server/components/ServerMutex.ts +++ b/src/server/components/ServerMutex.ts @@ -1,7 +1,7 @@ import { WebAcceptor } from "tgrid"; import { List, sleep_for, OutOfRange, Pair } from "tstl"; -import { AccessType } from "tstl/internal/thread/AccessType"; -import { LockType } from "tstl/internal/thread/LockType"; +import { AccessType } from "tstl/lib/internal/thread/AccessType"; +import { LockType } from "tstl/lib/internal/thread/LockType"; import { SolidComponent } from "./SolidComponent"; import { Disolver } from "./internal/Disolver"; diff --git a/src/server/components/ServerSemaphore.ts b/src/server/components/ServerSemaphore.ts index 8e2f4a4..1915810 100644 --- a/src/server/components/ServerSemaphore.ts +++ b/src/server/components/ServerSemaphore.ts @@ -1,6 +1,6 @@ import { WebAcceptor } from "tgrid"; import { List, sleep_for, OutOfRange, Pair } from "tstl"; -import { LockType } from "tstl/internal/thread/LockType"; +import { LockType } from "tstl/lib/internal/thread/LockType"; import { SolidComponent } from "./SolidComponent"; import { Disolver } from "./internal/Disolver"; diff --git a/src/server/components/SolidComponent.ts b/src/server/components/SolidComponent.ts index b570f79..461ccac 100644 --- a/src/server/components/SolidComponent.ts +++ b/src/server/components/SolidComponent.ts @@ -1,6 +1,6 @@ import { WebAcceptor } from "tgrid"; import { HashMap, HashSet, List } from "tstl"; -import { LockType } from "tstl/internal/thread/LockType"; +import { LockType } from "tstl/lib/internal/thread/LockType"; import { IComponent } from "./IComponent"; import { Disolver } from "./internal/Disolver"; diff --git a/src/server/providers/ProviderBase.ts b/src/server/providers/ProviderBase.ts index 021d15a..6e08c08 100644 --- a/src/server/providers/ProviderBase.ts +++ b/src/server/providers/ProviderBase.ts @@ -4,11 +4,10 @@ */ //----------------------------------------------------------- import { WebAcceptor } from "tgrid"; -import { List, HashSet } from "tstl"; +import { List, HashSet, OutOfRange } from "tstl"; import { GlobalBase } from "../global/GlobalBase"; import { Joiner } from "../components/internal/Joiner"; -import { OutOfRange } from "tstl/exception/OutOfRange"; /** * @internal diff --git a/test/condition_variables/test_condition_variable_disconnections.ts b/test/condition_variables/test_condition_variable_disconnections.ts index 9ab7140..df98f1b 100644 --- a/test/condition_variables/test_condition_variable_disconnections.ts +++ b/test/condition_variables/test_condition_variable_disconnections.ts @@ -1,6 +1,5 @@ +import { IPointer, sleep_for } from "tstl"; import { ConnectionFactory } from "../internal/ConnectionFactory"; -import { sleep_for } from "tstl/thread/global"; -import { IPointer } from "tstl/functional/IPointer"; async function wait_and_disconnect( factory: ConnectionFactory, diff --git a/test/condition_variables/test_condition_variable_waits.ts b/test/condition_variables/test_condition_variable_waits.ts index c524098..0a14a5d 100644 --- a/test/condition_variables/test_condition_variable_waits.ts +++ b/test/condition_variables/test_condition_variable_waits.ts @@ -1,5 +1,5 @@ import { ConnectionFactory } from "../internal/ConnectionFactory"; -import { sleep_for } from "tstl/thread/global"; +import { sleep_for } from "tstl"; const SLEEP_TIME: number = 100; const WAIT_COUNT: number = 10; diff --git a/test/internal/Validator.ts b/test/internal/Validator.ts index 9617dd5..adadad4 100644 --- a/test/internal/Validator.ts +++ b/test/internal/Validator.ts @@ -1,9 +1,10 @@ -import { ILockable } from "tstl/base/thread/ILockable"; -import { ITimedLockable } from "tstl/base/thread/ITimedLockable"; -import { ISharedLockable } from "tstl/base/thread/ISharedLockable"; -import { ISharedTimedLockable } from "tstl/base/thread/ISharedTimedLockable"; - -import { sleep_for } from "tstl/thread/global"; +import { sleep_for } from "tstl"; +import { + ILockable, + ITimedLockable, + ISharedLockable, + ISharedTimedLockable, +} from "tstl/lib/base/thread"; export namespace Validator { const SLEEP_TIME = 50; diff --git a/test/semaphores/test_semaphore_acquires.ts b/test/semaphores/test_semaphore_acquires.ts index 8fe5969..47aaec9 100644 --- a/test/semaphores/test_semaphore_acquires.ts +++ b/test/semaphores/test_semaphore_acquires.ts @@ -1,10 +1,10 @@ import { MutexConnector, RemoteSemaphore } from "mutex-server"; import { sleep_for } from "tstl"; -import { ITimedLockable } from "tstl/base/thread"; import { ConnectionFactory } from "../internal/ConnectionFactory"; import { IActivation } from "../internal/IActivation"; import { Validator } from "../internal/Validator"; +import { ITimedLockable } from "tstl/lib/base/thread/ITimedLockable"; const SIZE = 8; diff --git a/test/test_destructors.ts b/test/test_destructors.ts index 04678c1..e88282a 100644 --- a/test/test_destructors.ts +++ b/test/test_destructors.ts @@ -1,4 +1,4 @@ -import { sleep_for } from "tstl/thread/global"; +import { sleep_for } from "tstl"; import { MutexConnector, MutexServer, RemoteMutex } from "mutex-server"; import { IActivation } from "./internal/IActivation"; import { ConnectionFactory } from "./internal/ConnectionFactory";