diff --git a/package.json b/package.json index d828a48..a23f5b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,8 @@ { "name": "opencode-pty", - "module": "index.ts", + "main": "dist/index.js", + "types": "dist/index.d.ts", + "module": "dist/index.js", "version": "0.3.1", "description": "OpenCode plugin for interactive PTY management - run background processes, send input, read output with regex filtering", "author": "shekohex", @@ -26,27 +28,40 @@ }, "homepage": "https://github.com/shekohex/opencode-pty#readme", "files": [ - "index.ts", - "src", "dist" ], "license": "MIT", "type": "module", "exports": { - "./server": "./index.ts", - "./*": "./src/*.ts", - "./*/*": "./src/*/*.ts", - "./*/*/*": "./src/*/*/*.ts", - "./*/*/*/*": "./src/*/*/*/*.ts", - "./*/*/*/*/*": "./src/*/*/*/*/*.ts" + ".": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + }, + "./*": { + "types": "./dist/src/*.d.ts", + "default": "./dist/src/*.js" + }, + "./*/*": { + "types": "./dist/src/*/*.d.ts", + "default": "./dist/src/*/*.js" + }, + "./*/*/*": { + "types": "./dist/src/*/*/*.d.ts", + "default": "./dist/src/*/*/*.js" + }, + "./*/*/*/*": { + "types": "./dist/src/*/*/*/*.d.ts", + "default": "./dist/src/*/*/*/*.js" + } }, "scripts": { "typecheck": "tsc --noEmit", "unittest": "bun test", "test:e2e": "PW_DISABLE_TS_ESM=1 NODE_ENV=test bun --bun playwright test", "test:all": "bun unittest && bun test:e2e", - "build:dev": "bun clean && vite build --mode development", - "build:prod": "bun clean && vite build --mode production", + "build:plugin": "tsc -p tsconfig.build.json && bun x copyfiles -u 0 \"src/**/*.txt\" dist", + "build:dev": "bun clean && bun build:plugin && vite build --mode development", + "build:prod": "bun clean && bun build:plugin && vite build --mode production", "prepack": "bun build:prod", "clean": "rm -rf dist playwright-report test-results", "lint": "biome lint .", diff --git a/src/web/server/handlers/static.ts b/src/web/server/handlers/static.ts index c62d018..1c354c7 100644 --- a/src/web/server/handlers/static.ts +++ b/src/web/server/handlers/static.ts @@ -1,10 +1,11 @@ -import { resolve } from 'node:path' import { readdirSync, statSync } from 'node:fs' -import { join, extname } from 'node:path' +import { extname, join, resolve } from 'node:path' import { ASSET_CONTENT_TYPES } from '../../shared/constants.ts' // ----- MODULE-SCOPE CONSTANTS ----- -const PROJECT_ROOT = resolve(import.meta.dir, '../../../..') +// Resolve project root regardless of whether we're running from source or dist/ +const MODULE_DIR = resolve(import.meta.dir, '../../../..') +const PROJECT_ROOT = MODULE_DIR.replace(/[\\/]dist$/, '') const SECURITY_HEADERS = { 'X-Content-Type-Options': 'nosniff', 'X-Frame-Options': 'DENY', diff --git a/test/npm-pack-integration.test.ts b/test/npm-pack-integration.test.ts index 4482506..5e3cc64 100644 --- a/test/npm-pack-integration.test.ts +++ b/test/npm-pack-integration.test.ts @@ -87,9 +87,9 @@ describe('npm pack integration', () => { join(tempDir, 'test', 'start-server.ts') ) - // Verify the package structure + // Verify the package structure (compiled JS shipped in dist/) const packageDir = join(tempDir, 'node_modules/opencode-pty') - expect(existsSync(join(packageDir, 'src/plugin/pty/manager.ts'))).toBe(true) + expect(existsSync(join(packageDir, 'dist/src/plugin/pty/manager.js'))).toBe(true) expect(existsSync(join(packageDir, 'dist/web/index.html'))).toBe(true) const portFile = join('/tmp', 'test-server-port-0.txt') if (await Bun.file(portFile).exists()) { diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..c371385 --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false, + "rootDir": ".", + "outDir": "dist", + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "allowImportingTsExtensions": false, + "rewriteRelativeImportExtensions": true + }, + "include": ["index.ts", "src/**/*.ts"], + "exclude": ["src/web/client/**", "**/*.test.ts", "**/*.spec.ts"] +}