Skip to content

Commit 7f1d657

Browse files
feat: complete ES modules migration
- Convert all imports to use .js extensions for ES module compatibility - Update package.json to use ES modules (type: module) - Update tsconfig.json to use NodeNext module resolution - Migrate from CommonJS to modern ES modules standard - Maintain full backward compatibility while modernizing codebase - All 25 tools now work with ES modules and explicit file extensions
1 parent 273d778 commit 7f1d657

24 files changed

+67
-65
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@auto-browse/auto-browse",
33
"version": "0.1.6",
44
"description": "AI-powered browser automation",
5+
"type": "module",
56
"author": "auto-browse",
67
"homepage": "https://www.auto-browse.com/",
78
"repository": {

src/analytics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PostHog } from 'posthog-node';
2-
import { analyticsProvider, analyticsModel } from './llm';
2+
import { analyticsProvider, analyticsModel } from './llm.js';
33

44
const ANALYTICS_OPT_IN = process.env.ANALYTICS_OPT_IN !== 'false'; // defaults to true
55

src/auto.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import { test as base } from '@playwright/test';
22
import { z } from 'zod';
3-
import { AutoConfig } from './types';
4-
import { context } from './context';
5-
import { sessionManager } from './session-manager';
6-
import { captureAutoCall, shutdown } from './analytics';
3+
import { AutoConfig } from './types.js';
4+
import { context } from './context.js';
5+
import { sessionManager } from './session-manager.js';
6+
import { captureAutoCall, shutdown } from './analytics.js';
77
import { createReactAgent } from '@langchain/langgraph/prebuilt';
88
import { HumanMessage } from '@langchain/core/messages';
9-
import { createLLMModel } from './llm';
9+
import { createLLMModel } from './llm.js';
1010
import { Tool } from "@langchain/core/tools";
11-
import snapshot from './tools/snapshot';
12-
import navigateTools from './tools/navigate';
13-
import assertTools from './tools/assert';
14-
import consoleTools from './tools/console';
15-
import dialogTools from './tools/dialogs';
16-
import fileTools from './tools/files';
17-
import keyboardTools from './tools/keyboard';
18-
import networkTools from './tools/network';
19-
import tabTools from './tools/tabs';
20-
import testingTools from './tools/testing';
21-
import waitTools from './tools/wait';
22-
import commonTools from './tools/common';
23-
24-
import { createLangChainTool } from './tools/tool';
11+
import snapshot from './tools/snapshot.js';
12+
import navigateTools from './tools/navigate.js';
13+
import assertTools from './tools/assert.js';
14+
import consoleTools from './tools/console.js';
15+
import dialogTools from './tools/dialogs.js';
16+
import fileTools from './tools/files.js';
17+
import keyboardTools from './tools/keyboard.js';
18+
import networkTools from './tools/network.js';
19+
import tabTools from './tools/tabs.js';
20+
import testingTools from './tools/testing.js';
21+
import waitTools from './tools/wait.js';
22+
import commonTools from './tools/common.js';
23+
24+
import { createLangChainTool } from './tools/tool.js';
2525

2626

2727
// Convert our custom tools to LangChain tools
@@ -376,5 +376,5 @@ process.on('beforeExit', async () => {
376376
});
377377

378378
// Export everything needed for the package
379-
export { sessionManager } from './session-manager';
380-
export * from './types';
379+
export { sessionManager } from './session-manager.js';
380+
export * from './types.js';

src/browserContextFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import * as playwright from 'playwright';
7-
import { sessionManager } from './session-manager';
7+
import { sessionManager } from './session-manager.js';
88

99
export interface BrowserContextFactory {
1010
createContext(): Promise<{ browserContext: playwright.BrowserContext, close: () => Promise<void> }>;

src/context.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
import debug from 'debug';
1818
import * as playwright from 'playwright';
1919

20-
import { callOnPageNoTrace, waitForCompletion } from './tools/utils';
21-
import { ManualPromise } from './manualPromise';
22-
import { Tab } from './tab';
23-
import { outputFile, defaultConfig } from './config';
24-
import { sessionManager } from './session-manager';
25-
import { createSessionManagerContextFactory } from './browserContextFactory';
26-
27-
import type { ImageContent, TextContent } from '@modelcontextprotocol/sdk/types';
28-
import type { ModalState, Tool, ToolActionResult } from './tools/tool';
29-
import type { FullConfig } from './config';
30-
import type { BrowserContextFactory } from './browserContextFactory';
20+
import { callOnPageNoTrace, waitForCompletion } from './tools/utils.js';
21+
import { ManualPromise } from './manualPromise.js';
22+
import { Tab } from './tab.js';
23+
import { outputFile, defaultConfig } from './config.js';
24+
import { sessionManager } from './session-manager.js';
25+
import { createSessionManagerContextFactory } from './browserContextFactory.js';
26+
27+
import type { ImageContent, TextContent } from '@modelcontextprotocol/sdk/types.js';
28+
import type { ModalState, Tool, ToolActionResult } from './tools/tool.js';
29+
import type { FullConfig } from './config.js';
30+
import type { BrowserContextFactory } from './browserContextFactory.js';
3131

3232
type PendingAction = {
3333
dialogShown: ManualPromise<void>;

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { auto, test } from './auto';
2-
export * from './types';
1+
export { auto, test } from './auto.js';
2+
export * from './types.js';

src/pageSnapshot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import * as playwright from 'playwright';
18-
import { callOnPageNoTrace } from './tools/utils';
18+
import { callOnPageNoTrace } from './tools/utils.js';
1919

2020
type PageEx = playwright.Page & {
2121
_snapshotForAI: () => Promise<string>;

src/tab.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
import * as playwright from 'playwright';
1818

19-
import { PageSnapshot } from './pageSnapshot';
19+
import { PageSnapshot } from './pageSnapshot.js';
2020

21-
import type { Context } from './context';
22-
import { callOnPageNoTrace } from './tools/utils';
21+
import type { Context } from './context.js';
22+
import { callOnPageNoTrace } from './tools/utils.js';
2323

2424
export class Tab {
2525
readonly context: Context;

src/tools/assert.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616

1717
import { z } from 'zod';
18-
import { defineTool } from './tool';
18+
import { defineTool } from './tool.js';
1919
import { expect } from '@playwright/test';
20-
import * as javascript from '../javascript';
20+
import * as javascript from '../javascript.js';
2121

2222
const pageAssertSchema = z.object({
2323
assertion: z.enum(['hasTitle', 'hasURL']).describe('Type of page assertion to perform'),

src/tools/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { z } from 'zod';
18-
import { defineTool, type ToolFactory } from './tool';
18+
import { defineTool, type ToolFactory } from './tool.js';
1919

2020
const close = defineTool({
2121
capability: 'core',

0 commit comments

Comments
 (0)