Skip to content

Commit

Permalink
mk: drop Node.js 18.x
Browse files Browse the repository at this point in the history
Use global CustomEvent and deprecate CustomEvent ponyfill.
  • Loading branch information
yoursunny committed May 2, 2024
1 parent c329010 commit 6297fb4
Show file tree
Hide file tree
Showing 19 changed files with 21 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
unittest:
strategy:
matrix:
node: [18, 20, 22]
node: [20, 22]
fail-fast: false
runs-on: ubuntu-22.04
steps:
Expand All @@ -48,7 +48,7 @@ jobs:
env:
PUPPETEER_SKIP_DOWNLOAD: true
- run: corepack pnpm test
if: ${{ matrix.node == 18 || matrix.node == 22 }}
if: ${{ matrix.node == 22 }}
- run: corepack pnpm cover
env:
NODE_OPTIONS: --experimental-websocket
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@

Supported platforms include:

* Node.js: 18.x and 20.x and 22.x, on Windows and Linux.
* Node.js: 20.x and 22.x, on Windows and Linux.
* Generally, I support *Active LTS* and *Current* versions.
* Support for 18.x will be dropped soon.
* Bundlers: webpack 5.
* Firefox: latest version on Windows and Mac.
* Chrome: latest version on Windows, Mac, Android, and iOS 16.0+.
11 changes: 6 additions & 5 deletions integ/browser-tests/test-fixture/serialize.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { fromHex, toHex } from "@ndn/util";
import type { Opaque, UnwrapOpaque } from "type-fest";
import type { GetTagMetadata, Tagged } from "type-fest";

export type Value<T> = Opaque<string, T>;
type Tag = "@ndn/browser-tests#serialize";
export type Value<T> = Tagged<string, Tag, T>;

const UINT8ARRAY_TAG = "7030c743-40f7-4c63-96db-2c12c5dfca75";

Expand All @@ -14,11 +15,11 @@ export function stringify<T>(obj: T): Value<T> {
}) as Value<T>;
}

export function parse<T>(value: Value<T>): T {
return JSON.parse(value as UnwrapOpaque<Value<T>>, (k, v) => {
export function parse<V extends Value<unknown>>(value: V): GetTagMetadata<V, Tag> {
return JSON.parse(value, (k, v) => {
if (Array.isArray(v) && v[0] === UINT8ARRAY_TAG) {
return fromHex(v[1]);
}
return v;
}) as T;
});
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"vitest": "^1.5.3"
},
"engines": {
"node": "^18.18.0 || ^20.12.0 || ^22.0.0"
"node": "^20.12.0 || ^22.0.0"
},
"pnpm": {
"peerDependencyRules": {
Expand Down
2 changes: 1 addition & 1 deletion pkg/l3face/src/l3face.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Forwarder, type FwFace, FwPacket } from "@ndn/fw";
import { LpService } from "@ndn/lp";
import { Interest, type NameLike } from "@ndn/packet";
import { asDataView, CustomEvent, pushable } from "@ndn/util";
import { asDataView, pushable } from "@ndn/util";
import { abortableSource, AbortError as IteratorAbortError } from "abortable-iterator";
import * as retry from "retry";
import { consume, filter, map, pipeline } from "streaming-iterables";
Expand Down
2 changes: 1 addition & 1 deletion pkg/psync/src/psync/full.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ConsumerOptions, type Endpoint, produce, type Producer, type ProducerHandler, ProducerOptions } from "@ndn/endpoint";
import type { Component, Data, Interest, Name, Signer, Verifier } from "@ndn/packet";
import { type SyncNode, type SyncProtocol, SyncUpdate } from "@ndn/sync-api";
import { CustomEvent, KeyMap, toHex, trackEventListener } from "@ndn/util";
import { KeyMap, toHex, trackEventListener } from "@ndn/util";
import pDefer, { type DeferredPromise } from "p-defer";
import { TypedEventTarget } from "typescript-event-target";

Expand Down
2 changes: 1 addition & 1 deletion pkg/psync/src/psync/partial-publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type Endpoint, produce, type Producer, type ProducerHandler, type Produ
import { Segment } from "@ndn/naming-convention2";
import { Data, type Interest, type Name, NameMap, type Signer } from "@ndn/packet";
import type { SyncNode, SyncProtocol } from "@ndn/sync-api";
import { CustomEvent, trackEventListener } from "@ndn/util";
import { trackEventListener } from "@ndn/util";
import { BloomFilter } from "@yoursunny/psync-bloom";
import pDefer, { type DeferredPromise } from "p-defer";
import { TypedEventTarget } from "typescript-event-target";
Expand Down
1 change: 0 additions & 1 deletion pkg/psync/src/psync/partial-subscriber.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ConsumerOptions, Endpoint } from "@ndn/endpoint";
import type { Component, Name, Verifier } from "@ndn/packet";
import { type Subscriber, type Subscription, SubscriptionTable, SyncUpdate } from "@ndn/sync-api";
import { CustomEvent } from "@ndn/util";
import { BloomFilter, type Parameters as BloomParameters } from "@yoursunny/psync-bloom";
import { TypedEventTarget } from "typescript-event-target";

Expand Down
2 changes: 1 addition & 1 deletion pkg/psync/src/syncps/pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { consume, ConsumerOptions, type Endpoint, produce, type Producer, Produc
import { Timestamp } from "@ndn/naming-convention2";
import { type Component, Data, digestSigning, Interest, lpm, type Name, type Signer, type Verifier } from "@ndn/packet";
import { type Subscriber, type Subscription, SubscriptionTable } from "@ndn/sync-api";
import { CustomEvent, KeyMap, toHex, trackEventListener } from "@ndn/util";
import { KeyMap, toHex, trackEventListener } from "@ndn/util";
import DefaultWeakMap from "mnemonist/default-weak-map.js";
import filter from "obliterator/filter.js";
import take from "obliterator/take.js";
Expand Down
1 change: 0 additions & 1 deletion pkg/pyrepo/src/prps/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { consume, ConsumerOptions, type Endpoint, produce, type Producer, type P
import { Data, digestSigning, Interest, type Name, type Signer, type Verifier } from "@ndn/packet";
import type { Subscriber, Subscription } from "@ndn/sync-api";
import { Decoder } from "@ndn/tlv";
import { CustomEvent } from "@ndn/util";
import { TypedEventTarget } from "typescript-event-target";

import { NotifyAppParam, NotifySuffix } from "./packet";
Expand Down
2 changes: 1 addition & 1 deletion pkg/repo-api/src/bulk-insert-initiator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Transport } from "@ndn/l3face";
import type { Data } from "@ndn/packet";
import { Encoder } from "@ndn/tlv";
import { CustomEvent, pushable } from "@ndn/util";
import { pushable } from "@ndn/util";
import pDefer, { type DeferredPromise } from "p-defer";
import { consume } from "streaming-iterables";
import { TypedEventTarget } from "typescript-event-target";
Expand Down
1 change: 0 additions & 1 deletion pkg/segmented-object/src/fetch/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ConsumerOptions, Endpoint } from "@ndn/endpoint";
import { CancelInterest, Forwarder, type FwFace, FwPacket } from "@ndn/fw";
import { Data, Interest, type Name, type Verifier } from "@ndn/packet";
import { CustomEvent } from "@ndn/util";
import { TypedEventTarget } from "typescript-event-target";

import { defaultSegmentConvention, type SegmentConvention } from "../convention";
Expand Down
2 changes: 1 addition & 1 deletion pkg/segmented-object/src/fetch/logic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert, CustomEvent } from "@ndn/util";
import { assert } from "@ndn/util";
import hirestime from "hirestime";
import DefaultWeakMap from "mnemonist/default-weak-map.js";
import pDefer from "p-defer";
Expand Down
2 changes: 1 addition & 1 deletion pkg/svs/src/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Data, Interest, lpm, Name, noopSigning, TT as l3TT, type Verifier } fro
import { fetch } from "@ndn/segmented-object";
import { type Subscriber, type Subscription, SubscriptionTable, type SyncUpdate } from "@ndn/sync-api";
import { Decoder, EvDecoder } from "@ndn/tlv";
import { assert, concatBuffers, CustomEvent } from "@ndn/util";
import { assert, concatBuffers } from "@ndn/util";
import { batch, consume as consumeIterable, pipeline, transform } from "streaming-iterables";
import { TypedEventTarget } from "typescript-event-target";

Expand Down
2 changes: 1 addition & 1 deletion pkg/svs/src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Forwarder } from "@ndn/fw";
import { Component, Interest, Name, type NameLike, nullSigner, type Signer, type Verifier } from "@ndn/packet";
import { type SyncNode, type SyncProtocol, SyncUpdate } from "@ndn/sync-api";
import { Decoder, Encoder } from "@ndn/tlv";
import { assert, CustomEvent, randomJitter, trackEventListener } from "@ndn/util";
import { assert, randomJitter, trackEventListener } from "@ndn/util";
import type { Promisable } from "type-fest";
import { TypedEventTarget } from "typescript-event-target";

Expand Down
2 changes: 1 addition & 1 deletion pkg/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
"write": "^2.0.0"
},
"engines": {
"node": "^18.18.0 || ^20.12.0 || ^22.0.0"
"node": "^20.12.0 || ^22.0.0"
}
}
3 changes: 2 additions & 1 deletion pkg/util/src/event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import assert from "minimalistic-assert";

export { CustomEvent } from "./platform_node";
/** @deprecated Use global `CustomEvent`. */
export const CustomEvent = globalThis.CustomEvent;

/**
* Keep records on whether an event listener has been added.
Expand Down
2 changes: 0 additions & 2 deletions pkg/util/src/platform_browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ if (!crypto.subtle && !globalThis.isSecureContext) {
});
}

export const CustomEvent = globalThis.CustomEvent;

export function delay<T = void>(after: number, value?: T): Promise<T> {
return new Promise<T>((resolve) => setTimeout(resolve, after, value));
}
Expand Down
12 changes: 0 additions & 12 deletions pkg/util/src/platform_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,5 @@ export const console = new Console(process.stderr);
/** Web Crypto API. */
export const crypto: Crypto = webcrypto as any;

class CustomEventPonyfill extends Event {
constructor(type: string, options?: CustomEventInit) {
super(type, options);
this.detail = options?.detail;
}

public readonly detail: any;
}

/** CustomEvent object. */
export const CustomEvent: typeof globalThis["CustomEvent"] = globalThis.CustomEvent ?? CustomEventPonyfill;

/** Make a Promise that resolves after specified duration. */
export const delay: <T = void>(after: number, value?: T) => Promise<T> = setTimeoutPromise;

0 comments on commit 6297fb4

Please sign in to comment.