Skip to content

Commit

Permalink
chore: improve index.d.ts generation (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
amk-dev authored Jan 2, 2025
1 parent d5c61f9 commit 2cf835e
Show file tree
Hide file tree
Showing 9 changed files with 536 additions and 99 deletions.
79 changes: 0 additions & 79 deletions packages/shortest/index.d.ts

This file was deleted.

12 changes: 6 additions & 6 deletions packages/shortest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,27 @@
"type": "module",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./index.d.ts",
"types": "./dist/index.d.ts",
"bin": {
"shortest": "./dist/cli/bin.js"
},
"exports": {
".": {
"types": "./index.d.ts",
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs"
}
},
"files": [
"dist",
"dist/cli",
"index.d.ts"
"dist/cli"
],
"scripts": {
"build": "rm -rf dist && pnpm build:types && pnpm build:js && pnpm build:cli",
"prepare": "pnpm build",
"prepublishOnly": "pnpm build",
"postinstall": "node -e \"if (process.platform !== 'win32') { try { require('child_process').execSync('chmod +x dist/cli/bin.js') } catch (_) {} }\"",
"build:types": "tsc --emitDeclarationOnly --outDir dist/types && cp index.d.ts dist/",
"build:types": "tsup src/index.ts --dts-only --format esm --outDir dist",
"build:js": "esbuild src/index.ts --bundle --platform=node --format=esm --outfile=dist/index.js --external:esbuild --external:punycode --external:playwright --external:@anthropic-ai/sdk --external:expect --external:dotenv",
"build:cjs": "esbuild src/index.ts --bundle --platform=node --format=cjs --outfile=dist/index.cjs --external:esbuild --external:punycode --external:playwright --external:@anthropic-ai/sdk --external:expect --external:dotenv",
"build:cli": "esbuild src/cli/bin.ts --bundle --platform=node --format=esm --outdir=dist/cli --metafile=dist/meta-cli.json --external:fsevents --external:chokidar --external:glob --external:esbuild --external:events --external:path --external:fs --external:util --external:stream --external:os --external:assert --external:url --external:playwright --external:@anthropic-ai/sdk --external:expect --external:dotenv --external:otplib --external:picocolors --external:punycode --external:https --external:http --external:net --external:tls --external:crypto --external:mailosaur",
Expand All @@ -50,7 +49,8 @@
"@types/node": "^20.11.24",
"tsx": "^4.7.1",
"typescript": "~5.6.2",
"package-manager-detector": "0.2.8"
"package-manager-detector": "0.2.8",
"tsup": "8.3.5"
},
"engines": {
"node": ">=18"
Expand Down
23 changes: 19 additions & 4 deletions packages/shortest/src/browser/core/browser-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,27 @@ export class BrowserTool extends BaseBrowserTool {

case "check_email": {
if (!this.mailosaurTool) {
if (!this.config.mailosaur) {
throw new ToolError("Mailosaur configuration required");
const mailosaurAPIKey =
this.config.mailosaur?.apiKey || process.env.MAILOSAUR_API_KEY;
const mailosaurServerId =
this.config.mailosaur?.serverId ||
process.env.MAILOSAUR_SERVER_ID;

if (!mailosaurAPIKey) {
throw new ToolError("Mailosaur API key is required");
}

if (!mailosaurServerId) {
throw new ToolError("Mailosaur server ID is required");
}

if (!input.email) {
throw new ToolError("Mailosaur email address is required");
}

this.mailosaurTool = new MailosaurTool({
apiKey: this.config.mailosaur.apiKey,
serverId: this.config.mailosaur.serverId,
apiKey: mailosaurAPIKey,
serverId: mailosaurServerId,
emailAddress: input.email,
});
}
Expand Down
8 changes: 1 addition & 7 deletions packages/shortest/src/browser/integrations/mailosaur.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@ export class MailosaurTool {
constructor(config: {
apiKey: string;
serverId: string;
emailAddress?: string;
emailAddress: string;
}) {
if (!config.apiKey || !config.serverId) {
throw new ToolError("Mailosaur configuration missing required fields");
} else if (!config.emailAddress) {
throw new ToolError("Mailosaur email address is required");
}

this.client = new Mailosaur(config.apiKey);
this.serverId = config.serverId;
this.emailAddress = config.emailAddress;
Expand Down
5 changes: 5 additions & 0 deletions packages/shortest/src/core/runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ export class TestRunner {
},
});

// this may never happen as the config is initlized before this code is executed
if (!this.config.anthropicKey) {
throw new Error("ANTHROPIC_KEY is not set");
}

const aiClient = new AIClient(
{
apiKey: this.config.anthropicKey,
Expand Down
6 changes: 6 additions & 0 deletions packages/shortest/src/globals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Expect } from "expect";

declare global {
// @ts-ignore
var expect: Expect;
}
3 changes: 3 additions & 0 deletions packages/shortest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
ShortestConfig,
} from "./types";

// to include the global expect in the generated d.ts file
import "./globals";

// Initialize config
let globalConfig: ShortestConfig | null = null;
const compiler = new TestCompiler();
Expand Down
6 changes: 3 additions & 3 deletions packages/shortest/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ export interface ShortestConfig {
headless: boolean;
baseUrl: string;
testPattern: string;
anthropicKey: string;
anthropicKey?: string;
mailosaur?: {
apiKey: string;
serverId: string;
apiKey?: string;
serverId?: string;
};
}
Loading

0 comments on commit 2cf835e

Please sign in to comment.