Skip to content

Commit

Permalink
fix: good fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
betula committed Nov 30, 2023
1 parent 31fce38 commit 68a4d15
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 37 deletions.
15 changes: 4 additions & 11 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,13 @@
"provi": "2.x.x"
},
"author": "Slava Bereza <mail@betula.co> (http://betula.co)",
"scripts": {
"build": "microbundle build --raw",
"dev": "microbundle watch --raw --format cjs"
},
"exports": {
".": {
"types": "./src/index.d.ts",
"browser": "./dist/server.module.js",
"umd": "./dist/server.umd.js",
"import": "./dist/server.mjs",
"require": "./dist/server.js"
"browser": "./dist/client.module.js",
"umd": "./dist/client.umd.js",
"import": "./dist/client.mjs",
"require": "./dist/client.js"
}
},
"devDependencies": {
"microbundle": "0.15.1"
}
}
1 change: 0 additions & 1 deletion client/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export const provide: import("provi").Provide;
export const destroy: import("provi").Destroy;
export const isolate: import("provi").Isolate;
5 changes: 2 additions & 3 deletions client/src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { factory } from 'provi';

const { provide, destroy, isolate } = factory();
const { provide, destroy } = factory();

export {
provide,
destroy,
isolate
destroy
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
"version": "2.1.1",
"description": "Minimalistic and cute Service Provider",
"types": "src/index.d.ts",
"main": "dist/server.js",
"main": "dist/server.cjs",
"module": "dist/server.module.js",
"umd:main": "dist/server.umd.js",
"source": "src/index.js",
"scripts": {
"test": "jest",
"build": "microbundle build --raw",
"dev": "microbundle watch --raw --format cjs"
"build": "yarn clean && microbundle build --raw --target node && microbundle build --raw --target web --cwd client && microbundle build --raw --target node --cwd server",
"dev": "microbundle watch --raw --format cjs",
"clean": "rm -rf client/dist server/dist dist"
},
"dependencies": {
"unsubscriber": "2.x.x"
Expand Down
7 changes: 0 additions & 7 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
"provi": "2.x.x"
},
"author": "Slava Bereza <mail@betula.co> (http://betula.co)",
"scripts": {
"build": "microbundle build --raw",
"dev": "microbundle watch --raw --format cjs"
},
"exports": {
".": {
"types": "./src/index.d.ts",
Expand All @@ -25,8 +21,5 @@
"import": "./dist/server.mjs",
"require": "./dist/server.js"
}
},
"devDependencies": {
"microbundle": "0.15.1"
}
}
2 changes: 1 addition & 1 deletion server/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { factory } from 'provi';
import asyncHooks from 'node:async_hooks';
import asyncHooks from 'async_hooks';

const { provide, destroy, isolate } = factory(asyncHooks);

Expand Down
12 changes: 6 additions & 6 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export function factory(
executionAsyncId: any,
}
): {
provide: <T>(ctor: Ctor<T>) => T;
destroy: (...args: Ctor<any>[]) => void;
isolate: <T>(fn: () => Promise<T>) => Promise<T>;
provide: Provide;
destroy: Destroy;
isolate?: Isolate;
};

export type Provide = ReturnType<typeof factory>["provide"];
export type Destroy = ReturnType<typeof factory>["destroy"];
export type Isolate = ReturnType<typeof factory>["isolate"];
export type Provide = <T>(ctor: Ctor<T>) => T;
export type Destroy = (...args: Ctor<any>[]) => void;
export type Isolate = <T>(fn: () => Promise<T>) => Promise<T>;
7 changes: 2 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ const

zones = new Map(),

isolate = async (fn) => {
if (!async_hooks) {
throw new Error('Isolate only possible on server')
}
isolate = async_hooks && (async (fn) => {

if (!hook) {
hook = async_hooks.createHook({
Expand Down Expand Up @@ -46,7 +43,7 @@ const
}
})
})
},
}),

get_instances = () => {
if (!zones.has(zone_id)) {
Expand Down

0 comments on commit 68a4d15

Please sign in to comment.