Skip to content

Commit 456e3e7

Browse files
committed
Revert "refactor: split sync-engine CLI and serve binaries"
This reverts commit adfd28e. Agent too eager to commit should have been a PR
1 parent adfd28e commit 456e3e7

25 files changed

Lines changed: 158 additions & 412 deletions

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ ENV NODE_ENV=production
4949
ENV GIT_COMMIT=$GIT_COMMIT
5050
ENV BUILD_DATE=$BUILD_DATE
5151
ENV COMMIT_URL=$COMMIT_URL
52-
ENTRYPOINT ["node", "--use-env-proxy", "dist/bin/serve.js"]
52+
ENTRYPOINT ["node", "--use-env-proxy", "dist/cli/index.js"]
53+
CMD ["serve"]
5354

5455
# ===========================================================================
5556
# Service (also used for the worker container — same image, different CMD)

apps/engine/package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"description": "Stripe Sync Engine — sync Stripe data to Postgres",
66
"type": "module",
77
"bin": {
8-
"sync-engine": "./dist/bin/sync-engine.js",
9-
"sync-engine-serve": "./dist/bin/serve.js"
8+
"sync-engine": "./dist/cli/index.js"
109
},
1110
"exports": {
1211
".": {
@@ -20,9 +19,9 @@
2019
"import": "./dist/cli/command.js"
2120
},
2221
"./api": {
23-
"bun": "./src/api/index.ts",
24-
"types": "./dist/api/index.d.ts",
25-
"import": "./dist/api/index.js"
22+
"bun": "./src/api/app.ts",
23+
"types": "./dist/api/app.d.ts",
24+
"import": "./dist/api/app.js"
2625
},
2726
"./api/openapi-utils": {
2827
"bun": "./src/api/openapi-utils.ts",
@@ -33,7 +32,7 @@
3332
"scripts": {
3433
"build": "tsc",
3534
"x:watch": "sh -c 'if command -v bun > /dev/null 2>&1; then bun --watch \"$@\"; else tsx --watch --conditions bun \"$@\"; fi' --",
36-
"dev": "LOG_LEVEL=${LOG_LEVEL:-trace} LOG_PRETTY=${LOG_PRETTY:-true} DANGEROUSLY_VERBOSE_LOGGING=true pnpm x:watch src/bin/serve.ts",
35+
"dev": "LOG_LEVEL=${LOG_LEVEL:-trace} LOG_PRETTY=${LOG_PRETTY:-true} DANGEROUSLY_VERBOSE_LOGGING=true pnpm x:watch src/api/index.ts",
3736
"test": "vitest run",
3837
"generate:types": "openapi-typescript src/__generated__/openapi.json -o src/__generated__/openapi.d.ts"
3938
},

apps/engine/src/__tests__/bin-serve.test.ts

Lines changed: 0 additions & 55 deletions
This file was deleted.

apps/engine/src/__tests__/docker.test.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ describe('Docker image', { timeout: 180_000 }, () => {
3232
})
3333

3434
it('--version prints version and exits', () => {
35-
const out = docker('run', '--rm', '--entrypoint', 'node', IMAGE, 'dist/bin/sync-engine.js', '--version')
35+
const out = docker('run', '--rm', IMAGE, '--version')
3636
expect(out).toMatch(/\d+\.\d+\.\d+/)
3737
})
3838

3939
it('--help prints usage and exits', () => {
40-
const out = docker('run', '--rm', '--entrypoint', 'node', IMAGE, 'dist/bin/sync-engine.js', '--help')
40+
const out = docker('run', '--rm', IMAGE, '--help')
4141
expect(out).toContain('sync-engine')
4242
expect(out).toContain('serve')
4343
expect(out).toContain('sync')
@@ -73,17 +73,7 @@ describe('Docker image', { timeout: 180_000 }, () => {
7373

7474
it('check exits non-zero without valid config', () => {
7575
expect(() =>
76-
docker(
77-
'run',
78-
'--rm',
79-
'--entrypoint',
80-
'node',
81-
IMAGE,
82-
'dist/bin/sync-engine.js',
83-
'check',
84-
'--postgres-url',
85-
'postgres://invalid:5432/db'
86-
)
76+
docker('run', '--rm', IMAGE, 'check', '--postgres-url', 'postgres://invalid:5432/db')
8777
).toThrow()
8878
})
8979
})

apps/engine/src/api/index.test.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.

apps/engine/src/api/index.ts

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,55 @@
1-
export { createApp } from './app.js'
2-
export { startApiServer } from './server.js'
3-
export type { StartApiServerOptions } from './server.js'
1+
#!/usr/bin/env node
2+
3+
import source from '@stripe/sync-source-stripe'
4+
import pgDestination from '@stripe/sync-destination-postgres'
5+
import sheetsDestination from '@stripe/sync-destination-google-sheets'
6+
import { createConnectorResolver } from '../lib/index.js'
7+
import { createApp } from './app.js'
8+
import { logger } from '../logger.js'
9+
import { ENGINE_SERVER_OPTIONS } from '../http-server-options.js'
10+
11+
const port = Number(process.env.PORT || 3001)
12+
13+
async function main() {
14+
if (process.env.DANGEROUSLY_VERBOSE_LOGGING === 'true') {
15+
logger.warn(
16+
'⚠️ DANGEROUSLY_VERBOSE_LOGGING is enabled — all request headers and message payloads will be logged. Do not use in production.'
17+
)
18+
}
19+
20+
const resolver = await createConnectorResolver({
21+
sources: { stripe: source },
22+
destinations: { postgres: pgDestination, google_sheets: sheetsDestination },
23+
})
24+
const app = await createApp(resolver)
25+
26+
// Use the web-standard fetch handler with the runtime's native server.
27+
// Bun.serve() properly cancels ReadableStreams on client disconnect;
28+
// @hono/node-server is the fallback for Node.js / tsx.
29+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
30+
if (typeof (globalThis as any).Bun !== 'undefined') {
31+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
32+
;(globalThis as any).Bun.serve({ fetch: app.fetch, port, idleTimeout: 60 })
33+
logger.warn(
34+
{ port, server: 'Bun.serve' },
35+
`Sync Engine API listening on http://localhost:${port}`
36+
)
37+
} else {
38+
const { serve } = await import('@hono/node-server')
39+
serve(
40+
{
41+
fetch: app.fetch,
42+
port,
43+
serverOptions: ENGINE_SERVER_OPTIONS,
44+
},
45+
(info) => {
46+
logger.info(
47+
{ port: info.port },
48+
`Sync Engine API listening on http://localhost:${info.port}`
49+
)
50+
}
51+
)
52+
}
53+
}
54+
55+
main()

apps/engine/src/api/server.ts

Lines changed: 0 additions & 56 deletions
This file was deleted.

apps/engine/src/bin/bootstrap.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

apps/engine/src/bin/serve.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

apps/engine/src/bin/sync-engine.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)