Skip to content

Commit

Permalink
feat(bundle)!: support for esbuild and skypack
Browse files Browse the repository at this point in the history
  • Loading branch information
awlayton committed Mar 1, 2024
1 parent b0cf1de commit 9d29748
Show file tree
Hide file tree
Showing 13 changed files with 329 additions and 92 deletions.
4 changes: 2 additions & 2 deletions lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type { EventEmitter } from 'eventemitter3';
import debug from 'debug';
import deepClone from 'deep-clone';

import { fileTypeFromBuffer } from '@oada/client/dist/file-type.js';
import { fileTypeFromBuffer } from '#file-type';
import { generate as ksuid } from 'xksuid';

import type { Tree, TreeKey } from '@oada/types/oada/tree/v1.js';
Expand All @@ -34,7 +34,7 @@ import {
toArrayPath,
toStringPath,
} from './utils.js';
import { AbortController } from './fetch.js';
import { AbortController } from '#fetch';
import { HttpClient } from './http.js';
import { WebSocketClient } from './websocket.js';

Expand Down
3 changes: 1 addition & 2 deletions lib/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

import { setTimeout } from 'isomorphic-timers-promises';

// eslint-disable-next-line node/no-extraneous-import -- hack for skypack?
import { Headers } from '@oada/client/dist/fetch.js';
import { Headers } from '#fetch';
import debug from 'debug';

import { fixError } from './utils.js';
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/fetch.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

export const { AbortController, Response, fetch } = globalThis;
export const { AbortController, Headers, Response, fetch } = globalThis;

// eslint-disable-next-line @typescript-eslint/naming-convention
export const Agent = undefined;
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { generate as ksuid } from 'xksuid';

import { assert as assertOADASocketRequest } from '@oada/types/oada/websockets/request.js';

import { AbortController, Agent, type Response, fetch } from './fetch.js';
import { AbortController, Agent, type Response, fetch } from '#fetch';
import type {
Body,
Connection,
Expand Down Expand Up @@ -51,7 +51,7 @@ function isJson(contentType: string) {
}

async function getBody(result: Response): Promise<Body> {
return isJson(result.headers.get('content-type')!)
return isJson(result.headers.get('content-type') ?? '')
? ((await result.json()) as Json)
: new Uint8Array(await result.arrayBuffer());
}
Expand Down
2 changes: 0 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,4 @@ declare global {

export type Change = ChangeArray[0];

export { JobsRequest, JobEventType, doJob } from './jobs.js';

export { TimeoutError } from './utils.js';
2 changes: 1 addition & 1 deletion lib/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export class JobsRequest<J extends Job> {
}
}

export const enum JobEventType {
export enum JobEventType {
// The job is finished; a status arrives
Status = 'Status',
// Success status
Expand Down
2 changes: 1 addition & 1 deletion lib/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { assert as assertOADASocketRequest } from '@oada/types/oada/websockets/r
import { is as isOADASocketChange } from '@oada/types/oada/websockets/change.js';
import { is as isOADASocketResponse } from '@oada/types/oada/websockets/response.js';

import { on, once } from '@oada/client/dist/event-iterator.js';
import { on, once } from '#event-iterator';

import type {
Connection,
Expand Down
78 changes: 53 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,69 @@
"version": "5.0.0",
"description": "A lightweight client tool to interact with an OADA-compliant server",
"repository": "https://github.com/OADA/client",
"main": "dist/index.js",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"module": "./lib/index.ts",
"type": "module",
"engines": {
"node": ">=18.0.0"
},
"keywords": [
"oada",
"rest",
"api",
"rest-api",
"client"
],
"exports": {
".": "./dist/index.js",
"./dist/event-iterator.js": {
"node": "./dist/event-iterator.js",
"default": "./dist/event-iterator-browser.js"
".": {
"types": "./dist/index.d.ts",
"module": "./lib/index.ts",
"default": "./dist/index.js"
},
"./dist/fetch.js": {
"node": "./dist/fetch.js",
"default": "./dist/fetch.browser.js"
"./jobs": {
"types": "./dist/jobs.d.ts",
"modules": "./lib/jobs.ts",
"node": "./dist/jobs.js",
"default": null
}
},
"imports": {
"#event-iterator": {
"node": {
"module": "./lib/event-iterator.ts",
"default": "./dist/event-iterator.js"
},
"default": {
"module": "./lib/event-iterator.browser.ts",
"default": "./dist/event-iterator.browser.js"
}
},
"./dist/file-type.js": {
"node": "./dist/file-type.js",
"default": "./dist/file-type-browser.js"
"#fetch": {
"node": {
"module": "./lib/fetch.ts",
"default": "./dist/fetch.js"
},
"default": {
"module": "./lib/fetch.browser.ts",
"default": "./dist/fetch.browser.js"
}
},
"#file-type": {
"node": {
"module": "./lib/file-type.ts",
"default": "./dist/file-type.js"
},
"default": {
"module": "./lib/file-type.browser.ts",
"default": "./dist/file-type.browser.js"
}
}
},
"browser": {
"./dist/event-iterator.js": "./dist/event-iterator-browser.js",
"./dist/fetch.js": "./dist/fetch.browser.js",
"events": false,
"file-type": "./dist/file-type-browser.js",
"resolve-alpn": false
},
"react-native": {
"./dist/event-iterator.js": "./dist/event-iterator-browser.js",
"./dist/fetch.js": "./dist/fetch.browser.js",
"events": false,
"file-type": "./dist/file-type-browser.js",
"resolve-alpn": false
},
"files": [
Expand All @@ -45,7 +76,7 @@
"test": "$npm_execpath run build test && c8 ava",
"test:debug": "ava -T 60m -svc 1 --no-worker-threads",
"build": "tsc -b",
"bundle": "webpack",
"bundle": "esbuild . --bundle",
"prepare": "$npm_execpath run build",
"prestart": "$npm_execpath run build"
},
Expand Down Expand Up @@ -82,11 +113,8 @@
"license": "Apache-2.0",
"dependencies": {
"@oada/types": "^3.5.3",
"buffer": "^6.0.3",
"bufferutil": "^4.0.8",
"debug": "^4.3.4",
"deep-clone": "^4.0.0",
"encoding": "^0.1.13",
"event-iterator": "^2.0.0",
"eventemitter3": "^5.0.1",
"file-type": "^19.0.0",
Expand All @@ -101,10 +129,8 @@
"reconnecting-websocket": "^4.4.0",
"resolve-alpn": "^1.2.1",
"serialize-error": "^11.0.3",
"supports-color": "^9.4.0",
"tslib": "^2.6.2",
"undici": "^6.6.2",
"utf-8-validate": "^6.0.3",
"ws": "^8.16.0",
"xksuid": "https://github.com/aultac/xksuid.git#commit=22a21eb01331191feb62ea0a4e67d96d2e80f396"
},
Expand All @@ -119,6 +145,7 @@
"devDependencies": {
"@ava/typescript": "^4.1.0",
"@oada/jobs": "^4.4.4",
"@skypack/package-check": "^0.2.2",
"@tsconfig/node18": "^18.2.2",
"@types/debug": "^4.1.12",
"@types/node": "^20.11.24",
Expand All @@ -130,6 +157,7 @@
"ava": "6.1.2",
"c8": "^9.1.0",
"dotenv": "^16.4.5",
"esbuild": "^0.20.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-xo": "^0.44.0",
Expand Down
4 changes: 1 addition & 3 deletions test/job.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ import ava, { type TestFn } from 'ava';

import { Service, type WorkerFunction } from '@oada/jobs';

import { JobEventType, JobsRequest, doJob } from '@oada/client/jobs';
import {
JobEventType,
JobsRequest,
type OADAClient,
connect,
doJob,
// eslint-disable-next-line node/no-extraneous-import
} from '@oada/client';

Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"extends": "@tsconfig/node18",
"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {
"module": "node16",
"moduleResolution": "node16",
"isolatedModules": true,
"composite": true,
"stripInternal": true,
"importHelpers": true,
Expand Down
Loading

0 comments on commit 9d29748

Please sign in to comment.