diff --git a/package.json b/package.json index 6e3feb8..e93d456 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.2.3", "description": "OpenCode plugin for interactive PTY management - run background processes, send input, read output with regex filtering", "author": "shekohex", @@ -26,27 +28,33 @@ }, "homepage": "https://github.com/shekohex/opencode-pty#readme", "files": [ - "index.ts", - "src", "dist" ], "license": "MIT", "type": "module", "exports": { - "./*": "./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" + } }, "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", - "prepack": "bun build:prod", + "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", + "prepublishOnly": "bun build:prod", "clean": "rm -rf dist playwright-report test-results", "lint": "biome lint .", "lint:fix": "biome lint --write .", 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/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"] +}