diff --git a/deno.json b/deno.json index 97c9e0b..4aae817 100644 --- a/deno.json +++ b/deno.json @@ -1,15 +1,10 @@ { "name": "@advanced/fetcher", - "version": "1.0.2", + "version": "1.0.3", "exports": "./mod.ts", "publish": { "exclude": [ "test/" ] - }, - "imports": { - "@cross/deepmerge": "jsr:@cross/deepmerge@^1.0.0", - "$std/": "https://deno.land/std@0.212.0/", - "~/": "./" } } \ No newline at end of file diff --git a/deno.lock b/deno.lock deleted file mode 100644 index 83c8e29..0000000 --- a/deno.lock +++ /dev/null @@ -1,52 +0,0 @@ -{ - "version": "3", - "packages": { - "specifiers": { - "jsr:@cross/deepmerge@^1.0.0": "jsr:@cross/deepmerge@1.0.0" - }, - "jsr": { - "@cross/deepmerge@1.0.0": { - "integrity": "1e1318a74e31ba1959b9aa0acae8bd417b806f74ffd25ac07c90e12f83ad6b1d" - } - } - }, - "remote": { - "https://deno.land/std@0.212.0/assert/_constants.ts": "a271e8ef5a573f1df8e822a6eb9d09df064ad66a4390f21b3e31f820a38e0975", - "https://deno.land/std@0.212.0/assert/_diff.ts": "dcc63d94ca289aec80644030cf88ccbf7acaa6fbd7b0f22add93616b36593840", - "https://deno.land/std@0.212.0/assert/_format.ts": "0ba808961bf678437fb486b56405b6fefad2cf87b5809667c781ddee8c32aff4", - "https://deno.land/std@0.212.0/assert/assert.ts": "bec068b2fccdd434c138a555b19a2c2393b71dfaada02b7d568a01541e67cdc5", - "https://deno.land/std@0.212.0/assert/assert_almost_equals.ts": "8b96b7385cc117668b0720115eb6ee73d04c9bcb2f5d2344d674918c9113688f", - "https://deno.land/std@0.212.0/assert/assert_array_includes.ts": "1688d76317fd45b7e93ef9e2765f112fdf2b7c9821016cdfb380b9445374aed1", - "https://deno.land/std@0.212.0/assert/assert_equals.ts": "4497c56fe7d2993b0d447926702802fc0becb44e319079e8eca39b482ee01b4e", - "https://deno.land/std@0.212.0/assert/assert_exists.ts": "24a7bf965e634f909242cd09fbaf38bde6b791128ece08e33ab08586a7cc55c9", - "https://deno.land/std@0.212.0/assert/assert_false.ts": "6f382568e5128c0f855e5f7dbda8624c1ed9af4fcc33ef4a9afeeedcdce99769", - "https://deno.land/std@0.212.0/assert/assert_greater.ts": "4945cf5729f1a38874d7e589e0fe5cc5cd5abe5573ca2ddca9d3791aa891856c", - "https://deno.land/std@0.212.0/assert/assert_greater_or_equal.ts": "573ed8823283b8d94b7443eb69a849a3c369a8eb9666b2d1db50c33763a5d219", - "https://deno.land/std@0.212.0/assert/assert_instance_of.ts": "72dc1faff1e248692d873c89382fa1579dd7b53b56d52f37f9874a75b11ba444", - "https://deno.land/std@0.212.0/assert/assert_is_error.ts": "6596f2b5ba89ba2fe9b074f75e9318cda97a2381e59d476812e30077fbdb6ed2", - "https://deno.land/std@0.212.0/assert/assert_less.ts": "2b4b3fe7910f65f7be52212f19c3977ecb8ba5b2d6d0a296c83cde42920bb005", - "https://deno.land/std@0.212.0/assert/assert_less_or_equal.ts": "b93d212fe669fbde959e35b3437ac9a4468f2e6b77377e7b6ea2cfdd825d38a0", - "https://deno.land/std@0.212.0/assert/assert_match.ts": "ec2d9680ed3e7b9746ec57ec923a17eef6d476202f339ad91d22277d7f1d16e1", - "https://deno.land/std@0.212.0/assert/assert_not_equals.ts": "f3edda73043bc2c9fae6cbfaa957d5c69bbe76f5291a5b0466ed132c8789df4c", - "https://deno.land/std@0.212.0/assert/assert_not_instance_of.ts": "8f720d92d83775c40b2542a8d76c60c2d4aeddaf8713c8d11df8984af2604931", - "https://deno.land/std@0.212.0/assert/assert_not_match.ts": "b4b7c77f146963e2b673c1ce4846473703409eb93f5ab0eb60f6e6f8aeffe39f", - "https://deno.land/std@0.212.0/assert/assert_not_strict_equals.ts": "da0b8ab60a45d5a9371088378e5313f624799470c3b54c76e8b8abeec40a77be", - "https://deno.land/std@0.212.0/assert/assert_object_match.ts": "e85e5eef62a56ce364c3afdd27978ccab979288a3e772e6855c270a7b118fa49", - "https://deno.land/std@0.212.0/assert/assert_rejects.ts": "e9e0c8d9c3e164c7ac962c37b3be50577c5a2010db107ed272c4c1afb1269f54", - "https://deno.land/std@0.212.0/assert/assert_strict_equals.ts": "0425a98f70badccb151644c902384c12771a93e65f8ff610244b8147b03a2366", - "https://deno.land/std@0.212.0/assert/assert_string_includes.ts": "dfb072a890167146f8e5bdd6fde887ce4657098e9f71f12716ef37f35fb6f4a7", - "https://deno.land/std@0.212.0/assert/assert_throws.ts": "edddd86b39606c342164b49ad88dd39a26e72a26655e07545d172f164b617fa7", - "https://deno.land/std@0.212.0/assert/assertion_error.ts": "9f689a101ee586c4ce92f52fa7ddd362e86434ffdf1f848e45987dc7689976b8", - "https://deno.land/std@0.212.0/assert/equal.ts": "fae5e8a52a11d3ac694bbe1a53e13a7969e3f60791262312e91a3e741ae519e2", - "https://deno.land/std@0.212.0/assert/fail.ts": "f310e51992bac8e54f5fd8e44d098638434b2edb802383690e0d7a9be1979f1c", - "https://deno.land/std@0.212.0/assert/mod.ts": "325df8c0683ad83a873b9691aa66b812d6275fc9fec0b2d180ac68a2c5efed3b", - "https://deno.land/std@0.212.0/assert/unimplemented.ts": "47ca67d1c6dc53abd0bd729b71a31e0825fc452dbcd4fde4ca06789d5644e7fd", - "https://deno.land/std@0.212.0/assert/unreachable.ts": "38cfecb95d8b06906022d2f9474794fca4161a994f83354fd079cac9032b5145", - "https://deno.land/std@0.212.0/fmt/colors.ts": "71e2d7d9911cf3f4f8cceaabe588fd9a4c0228102f4233da62ffd3e421201de7" - }, - "workspace": { - "dependencies": [ - "jsr:@cross/deepmerge@^1.0.0" - ] - } -} diff --git a/libs/fetcher.ts b/libs/fetcher.ts index be371cb..d5ffe46 100644 --- a/libs/fetcher.ts +++ b/libs/fetcher.ts @@ -1,5 +1,5 @@ import { SyncEventDispatcher } from "./sync-event-dispatcher.ts"; -import { deepMerge } from '@cross/deepmerge' +import { deepMerge } from 'deepmerge' /** * 请求拦截器 @@ -194,6 +194,8 @@ export class Fetcher extends SyncEventDispatcher<{ url: string, options: FetherConfig = {}, ): Promise { + console.log(url); + return this.request(url, { ...this.config, ...options, diff --git a/libs/sync-event-dispatcher.ts b/libs/sync-event-dispatcher.ts index beca76b..3707db7 100644 --- a/libs/sync-event-dispatcher.ts +++ b/libs/sync-event-dispatcher.ts @@ -48,11 +48,11 @@ export class SyncEventDispatcher> { */ public async dispatchEvent(type: T, data: EventMap[T]): Promise { const listeners = this.events[type]; - if (!listeners) { + if (!listeners || !listeners.length) { return data } - let result: unknown + let result: unknown = data for (const listener of listeners) { try { diff --git a/mod.ts b/mod.ts index 0f97f6b..75fe3ed 100644 --- a/mod.ts +++ b/mod.ts @@ -1,2 +1,2 @@ -export * from '~/libs/fetcher.ts' -export * from '~/libs/sync-event-dispatcher.ts' \ No newline at end of file +export * from './libs/fetcher.ts' +export * from './libs/sync-event-dispatcher.ts' \ No newline at end of file diff --git a/test/main.test.ts b/test/main.test.ts index b8e8dc1..f80512f 100644 --- a/test/main.test.ts +++ b/test/main.test.ts @@ -1,4 +1,4 @@ -import { createFetcher } from "~/libs/fetcher.ts"; +import { createFetcher } from "../libs/fetcher.ts"; import { assertEquals } from "$std/assert/mod.ts"; const urlObj = new URL('https://xjm.deno.dev/api/joke', "http://localhost:300/api/joke")