Skip to content

Commit

Permalink
chore: use esbuild to build package
Browse files Browse the repository at this point in the history
  • Loading branch information
vwong committed Jan 30, 2025
1 parent 7c4a520 commit 0c1fd8d
Show file tree
Hide file tree
Showing 15 changed files with 531 additions and 508 deletions.
22 changes: 22 additions & 0 deletions build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { build, BuildOptions } from "esbuild";

const opts: BuildOptions = {
bundle: true,
entryPoints: ["src/compare/index.ts"],
outdir: "dist",
packages: "external",
platform: "node",
sourcemap: true,
};

await Promise.all([
build({
...opts,
format: "cjs",
}),
build({
...opts,
format: "esm",
outExtension: { ".js": ".mjs" },
}),
]);
883 changes: 442 additions & 441 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
"name": "openapi-pact-comparator",
"version": "1.0.0",
"description": "",
"exports": {
".": "./dist/compare/index.js"
},
"main": "dist/compare/index.js",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/compare/index.d.ts",
"files": [
"dist"
],
"exports": {
".": {
"import": "./dist/index.mjs",
"default": "./dist/index.js"
}
},
"scripts": {
"dev": "tsx src/cli.ts",
"build": "tsc --emitDeclarationOnly && tsx build.ts",
"lint": "eslint --max-warnings=0",
"postinstall": "patch-package",
"prepare": "tsc --project tsconfig.json",
Expand Down Expand Up @@ -44,6 +49,7 @@
"@types/lodash-es": "^4.17.12",
"@types/node": "^22.12.0",
"@types/qs": "^6.9.18",
"esbuild": "^0.24.2",
"eslint": "^9.19.0",
"eslint-config-prettier": "^10.0.1",
"prettier": "^3.4.2",
Expand Down
24 changes: 12 additions & 12 deletions src/compare/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import type { OpenAPIV2, OpenAPIV3 } from "openapi-types";
import Ajv from "ajv/dist/2019";
import Router, { HTTPMethod } from "find-my-way";

import type { Pact } from "../documents/pact.js";
import type { Result } from "../results/index.js";
import { setupAjv, setupRouter } from "./setup.js";
import { parse as parseOas } from "../documents/oas.js";
import { parse as parsePact } from "../documents/pact.js";
import { compareReqPath } from "./requestPath.js";
import { compareReqQuery } from "./requestQuery.js";
import { compareReqBody } from "./requestBody.js";
import { compareReqHeader } from "./requestHeader.js";
import { compareResBody } from "./responseBody.js";
import { compareResHeader } from "./responseHeader.js";
import { baseMockDetails } from "../results/index.js";
import type { Pact } from "../documents/pact";
import type { Result } from "../results/index";
import { setupAjv, setupRouter } from "./setup";
import { parse as parseOas } from "../documents/oas";
import { parse as parsePact } from "../documents/pact";
import { compareReqPath } from "./requestPath";
import { compareReqQuery } from "./requestQuery";
import { compareReqBody } from "./requestBody";
import { compareReqHeader } from "./requestHeader";
import { compareResBody } from "./responseBody";
import { compareResHeader } from "./responseHeader";
import { baseMockDetails } from "../results/index";

export class Comparator {
#ajvCoerce: Ajv;
Expand Down
12 changes: 6 additions & 6 deletions src/compare/requestBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import type Router from "find-my-way";
import { get } from "lodash-es";
import qs from "qs";

import type { Interaction } from "../documents/pact.js";
import type { Result } from "../results/index.js";
import type { Interaction } from "../documents/pact";
import type { Result } from "../results/index";
import {
baseMockDetails,
formatErrorMessage,
formatInstancePath,
formatSchemaPath,
} from "../results/index.js";
import { minimumSchema, transformRequestSchema } from "../transform/index.js";
import { findMatchingType } from "./utils/content.js";
import { dereferenceOas } from "./utils/schema.js";
} from "../results/index";
import { minimumSchema, transformRequestSchema } from "../transform/index";
import { findMatchingType } from "./utils/content";
import { dereferenceOas } from "./utils/schema";

const parseBody = (body: unknown, contentType: string) => {
if (
Expand Down
17 changes: 7 additions & 10 deletions src/compare/requestHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@ import type Ajv from "ajv/dist/2019";
import type Router from "find-my-way";
import { get } from "lodash-es";

import type { Interaction } from "../documents/pact.js";
import type { Result } from "../results/index.js";
import type { Interaction } from "../documents/pact";
import type { Result } from "../results/index";
import {
baseMockDetails,
formatErrorMessage,
formatInstancePath,
formatSchemaPath,
} from "../results/index.js";
import { minimumSchema } from "../transform/index.js";
import {
findMatchingType,
standardHttpRequestHeaders,
} from "./utils/content.js";
import { parseValue } from "./utils/parse.js";
import { dereferenceOas } from "./utils/schema.js";
} from "../results/index";
import { minimumSchema } from "../transform/index";
import { findMatchingType, standardHttpRequestHeaders } from "./utils/content";
import { parseValue } from "./utils/parse";
import { dereferenceOas } from "./utils/schema";

export function* compareReqHeader(
ajv: Ajv,
Expand Down
14 changes: 7 additions & 7 deletions src/compare/requestPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import type { SchemaObject } from "ajv";
import type Ajv from "ajv/dist/2019";
import type Router from "find-my-way";

import type { Interaction } from "../documents/pact.js";
import type { Result } from "../results/index.js";
import { baseMockDetails } from "../results/index.js";
import { minimumSchema } from "../transform/index.js";
import { cleanPathParameter } from "./utils/parameters.js";
import { parseValue } from "./utils/parse.js";
import { dereferenceOas } from "./utils/schema.js";
import type { Interaction } from "../documents/pact";
import type { Result } from "../results/index";
import { baseMockDetails } from "../results/index";
import { minimumSchema } from "../transform/index";
import { cleanPathParameter } from "./utils/parameters";
import { parseValue } from "./utils/parse";
import { dereferenceOas } from "./utils/schema";

export function* compareReqPath(
ajv: Ajv,
Expand Down
10 changes: 5 additions & 5 deletions src/compare/requestQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import type Router from "find-my-way";
import { get } from "lodash-es";
import qs from "qs";

import type { Result } from "../results/index.js";
import type { Interaction } from "../documents/pact.js";
import type { Result } from "../results/index";
import type { Interaction } from "../documents/pact";
import {
baseMockDetails,
formatErrorMessage,
formatInstancePath,
formatSchemaPath,
} from "../results/index.js";
import { minimumSchema } from "../transform/index.js";
import { dereferenceOas } from "./utils/schema.js";
} from "../results/index";
import { minimumSchema } from "../transform/index";
import { dereferenceOas } from "./utils/schema";

export function* compareReqQuery(
ajv: Ajv,
Expand Down
12 changes: 6 additions & 6 deletions src/compare/responseBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import type Router from "find-my-way";
import type { OpenAPIV2, OpenAPIV3 } from "openapi-types";
import { get } from "lodash-es";

import type { Interaction } from "../documents/pact.js";
import type { Result } from "../results/index.js";
import type { Interaction } from "../documents/pact";
import type { Result } from "../results/index";
import {
baseMockDetails,
formatErrorMessage,
formatInstancePath,
formatSchemaPath,
} from "../results/index.js";
import { minimumSchema, transformResponseSchema } from "../transform/index.js";
import { findMatchingType } from "./utils/content.js";
import { dereferenceOas } from "./utils/schema.js";
} from "../results/index";
import { minimumSchema, transformResponseSchema } from "../transform/index";
import { findMatchingType } from "./utils/content";
import { dereferenceOas } from "./utils/schema";

const DEFAULT_CONTENT_TYPE = "application/json";

Expand Down
15 changes: 6 additions & 9 deletions src/compare/responseHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ import type Ajv from "ajv/dist/2019";
import type Router from "find-my-way";
import { get } from "lodash-es";

import type { Interaction } from "../documents/pact.js";
import type { Result } from "../results/index.js";
import type { Interaction } from "../documents/pact";
import type { Result } from "../results/index";
import {
baseMockDetails,
formatErrorMessage,
formatInstancePath,
formatSchemaPath,
} from "../results/index.js";
import { minimumSchema } from "../transform/index.js";
import {
findMatchingType,
standardHttpResponseHeaders,
} from "./utils/content.js";
import { dereferenceOas } from "./utils/schema.js";
} from "../results/index";
import { minimumSchema } from "../transform/index";
import { findMatchingType, standardHttpResponseHeaders } from "./utils/content";
import { dereferenceOas } from "./utils/schema";

export function* compareResHeader(
ajv: Ajv,
Expand Down
2 changes: 1 addition & 1 deletion src/compare/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { OpenAPIV2, OpenAPIV3 } from "openapi-types";
import Ajv, { Options } from "ajv/dist/2019.js";
import addFormats from "ajv-formats";
import Router, { HTTPMethod } from "find-my-way";
import { cleanPathParameter } from "./utils/parameters.js";
import { cleanPathParameter } from "./utils/parameters";

export function setupAjv(options: Options): Ajv {
const ajv = new Ajv(options);
Expand Down
6 changes: 3 additions & 3 deletions src/transform/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { transformRequestSchema } from "./requestSchema.js";
export { transformResponseSchema } from "./responseSchema.js";
export { minimumSchema } from "./minimumSchema.js";
export { transformRequestSchema } from "./requestSchema";
export { transformResponseSchema } from "./responseSchema";
export { minimumSchema } from "./minimumSchema";
2 changes: 1 addition & 1 deletion src/transform/minimumSchema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { OpenAPIV3 } from "openapi-types";
import { SchemaObject } from "ajv";
import { cloneDeep, get, set } from "lodash-es";
import { traverse } from "./utils.js";
import { traverse } from "./utils";

export const minimumSchema = (
originalSchema: SchemaObject,
Expand Down
2 changes: 1 addition & 1 deletion src/transform/requestSchema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SchemaObject } from "ajv";
import { each } from "lodash-es";
import { traverse } from "./utils.js";
import { traverse } from "./utils";

export const transformRequestSchema = (schema: SchemaObject): SchemaObject => {
// OpenAPI defines allOf to mean the union of all sub-schemas. JSON-Schema
Expand Down
2 changes: 1 addition & 1 deletion src/transform/responseSchema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SchemaObject } from "ajv";
import { each, get } from "lodash-es";
import { traverse } from "./utils.js";
import { traverse } from "./utils";

export const transformResponseSchema = (schema: SchemaObject): SchemaObject => {
// a provider must provide a superset of what the consumer asks for
Expand Down

0 comments on commit 0c1fd8d

Please sign in to comment.