Skip to content

Commit 24b8a4a

Browse files
author
JosXa
committed
Ship pre-compiled JS to avoid Bun transpilation cost on install
1 parent d30971f commit 24b8a4a

File tree

4 files changed

+48
-16
lines changed

4 files changed

+48
-16
lines changed

package.json

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"name": "opencode-pty",
3-
"module": "index.ts",
3+
"main": "dist/index.js",
4+
"types": "dist/index.d.ts",
5+
"module": "dist/index.js",
46
"version": "0.3.2",
57
"description": "OpenCode plugin for interactive PTY management - run background processes, send input, read output with regex filtering",
68
"author": "shekohex",
@@ -26,27 +28,40 @@
2628
},
2729
"homepage": "https://github.com/shekohex/opencode-pty#readme",
2830
"files": [
29-
"index.ts",
30-
"src",
3131
"dist"
3232
],
3333
"license": "MIT",
3434
"type": "module",
3535
"exports": {
36-
"./server": "./index.ts",
37-
"./*": "./src/*.ts",
38-
"./*/*": "./src/*/*.ts",
39-
"./*/*/*": "./src/*/*/*.ts",
40-
"./*/*/*/*": "./src/*/*/*/*.ts",
41-
"./*/*/*/*/*": "./src/*/*/*/*/*.ts"
36+
".": {
37+
"types": "./dist/index.d.ts",
38+
"default": "./dist/index.js"
39+
},
40+
"./*": {
41+
"types": "./dist/src/*.d.ts",
42+
"default": "./dist/src/*.js"
43+
},
44+
"./*/*": {
45+
"types": "./dist/src/*/*.d.ts",
46+
"default": "./dist/src/*/*.js"
47+
},
48+
"./*/*/*": {
49+
"types": "./dist/src/*/*/*.d.ts",
50+
"default": "./dist/src/*/*/*.js"
51+
},
52+
"./*/*/*/*": {
53+
"types": "./dist/src/*/*/*/*.d.ts",
54+
"default": "./dist/src/*/*/*/*.js"
55+
}
4256
},
4357
"scripts": {
4458
"typecheck": "tsc --noEmit",
4559
"unittest": "bun test",
4660
"test:e2e": "PW_DISABLE_TS_ESM=1 NODE_ENV=test bun --bun playwright test",
4761
"test:all": "bun unittest && bun test:e2e",
48-
"build:dev": "bun clean && vite build --mode development",
49-
"build:prod": "bun clean && vite build --mode production",
62+
"build:plugin": "tsc -p tsconfig.build.json && bun x copyfiles -u 0 \"src/**/*.txt\" dist",
63+
"build:dev": "bun clean && bun build:plugin && vite build --mode development",
64+
"build:prod": "bun clean && bun build:plugin && vite build --mode production",
5065
"prepack": "bun build:prod",
5166
"clean": "rm -rf dist playwright-report test-results",
5267
"lint": "biome lint .",

src/web/server/handlers/static.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { resolve } from 'node:path'
21
import { readdirSync, statSync } from 'node:fs'
3-
import { join, extname } from 'node:path'
2+
import { extname, join, resolve } from 'node:path'
43
import { ASSET_CONTENT_TYPES } from '../../shared/constants.ts'
54

65
// ----- MODULE-SCOPE CONSTANTS -----
7-
const PROJECT_ROOT = resolve(import.meta.dir, '../../../..')
6+
// Resolve project root regardless of whether we're running from source or dist/
7+
const MODULE_DIR = resolve(import.meta.dir, '../../../..')
8+
const PROJECT_ROOT = MODULE_DIR.replace(/[\\/]dist$/, '')
89
const SECURITY_HEADERS = {
910
'X-Content-Type-Options': 'nosniff',
1011
'X-Frame-Options': 'DENY',

test/npm-pack-integration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ describe('npm pack integration', () => {
8787
join(tempDir, 'test', 'start-server.ts')
8888
)
8989

90-
// Verify the package structure
90+
// Verify the package structure (compiled JS shipped in dist/)
9191
const packageDir = join(tempDir, 'node_modules/opencode-pty')
92-
expect(existsSync(join(packageDir, 'src/plugin/pty/manager.ts'))).toBe(true)
92+
expect(existsSync(join(packageDir, 'dist/src/plugin/pty/manager.js'))).toBe(true)
9393
expect(existsSync(join(packageDir, 'dist/web/index.html'))).toBe(true)
9494
const portFile = join('/tmp', 'test-server-port-0.txt')
9595
if (await Bun.file(portFile).exists()) {

tsconfig.build.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
3+
"extends": "./tsconfig.json",
4+
"compilerOptions": {
5+
"noEmit": false,
6+
"rootDir": ".",
7+
"outDir": "dist",
8+
"declaration": true,
9+
"declarationMap": true,
10+
"sourceMap": true,
11+
"allowImportingTsExtensions": false,
12+
"rewriteRelativeImportExtensions": true
13+
},
14+
"include": ["index.ts", "src/**/*.ts"],
15+
"exclude": ["src/web/client/**", "**/*.test.ts", "**/*.spec.ts"]
16+
}

0 commit comments

Comments
 (0)