@livestore/utils-dev 0.0.0-snapshot-d677008bdbdee9280bb55474e2e095d3d09a6d60 → 0.0.0-snapshot-61ffc7dbe7378bd127038444529800e35e2ebb4b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/.tsbuildinfo.json +1 -1
  2. package/dist/node/DockerComposeService/DockerComposeService.d.ts +1 -1
  3. package/dist/node/DockerComposeService/DockerComposeService.js +8 -8
  4. package/dist/node/DockerComposeService/DockerComposeService.js.map +1 -1
  5. package/dist/node/mod.d.ts +0 -2
  6. package/dist/node/mod.d.ts.map +1 -1
  7. package/dist/node/mod.js +0 -2
  8. package/dist/node/mod.js.map +1 -1
  9. package/dist/{node/WranglerDevServer → wrangler}/WranglerDevServer.d.ts +3 -5
  10. package/dist/wrangler/WranglerDevServer.d.ts.map +1 -0
  11. package/dist/wrangler/WranglerDevServer.js +90 -0
  12. package/dist/wrangler/WranglerDevServer.js.map +1 -0
  13. package/dist/wrangler/WranglerDevServer.test.d.ts.map +1 -0
  14. package/dist/wrangler/WranglerDevServer.test.js +77 -0
  15. package/dist/wrangler/WranglerDevServer.test.js.map +1 -0
  16. package/dist/wrangler/fixtures/cf-worker.d.ts.map +1 -0
  17. package/dist/wrangler/fixtures/cf-worker.js.map +1 -0
  18. package/dist/wrangler/mod.d.ts +2 -0
  19. package/dist/wrangler/mod.d.ts.map +1 -0
  20. package/dist/wrangler/mod.js +2 -0
  21. package/dist/wrangler/mod.js.map +1 -0
  22. package/package.json +6 -3
  23. package/src/node/DockerComposeService/DockerComposeService.ts +8 -8
  24. package/src/node/mod.ts +0 -7
  25. package/src/wrangler/WranglerDevServer.test.ts +133 -0
  26. package/src/wrangler/WranglerDevServer.ts +180 -0
  27. package/src/wrangler/mod.ts +6 -0
  28. package/dist/node/WranglerDevServer/WranglerDevServer.d.ts.map +0 -1
  29. package/dist/node/WranglerDevServer/WranglerDevServer.js +0 -150
  30. package/dist/node/WranglerDevServer/WranglerDevServer.js.map +0 -1
  31. package/dist/node/WranglerDevServer/WranglerDevServer.test.d.ts.map +0 -1
  32. package/dist/node/WranglerDevServer/WranglerDevServer.test.js +0 -179
  33. package/dist/node/WranglerDevServer/WranglerDevServer.test.js.map +0 -1
  34. package/dist/node/WranglerDevServer/fixtures/cf-worker.d.ts.map +0 -1
  35. package/dist/node/WranglerDevServer/fixtures/cf-worker.js.map +0 -1
  36. package/dist/node/WranglerDevServer/process-tree-manager.d.ts +0 -55
  37. package/dist/node/WranglerDevServer/process-tree-manager.d.ts.map +0 -1
  38. package/dist/node/WranglerDevServer/process-tree-manager.js +0 -178
  39. package/dist/node/WranglerDevServer/process-tree-manager.js.map +0 -1
  40. package/src/node/WranglerDevServer/WranglerDevServer.test.ts +0 -270
  41. package/src/node/WranglerDevServer/WranglerDevServer.ts +0 -302
  42. package/src/node/WranglerDevServer/process-tree-manager.ts +0 -263
  43. /package/dist/{node/WranglerDevServer → wrangler}/WranglerDevServer.test.d.ts +0 -0
  44. /package/dist/{node/WranglerDevServer → wrangler}/fixtures/cf-worker.d.ts +0 -0
  45. /package/dist/{node/WranglerDevServer → wrangler}/fixtures/cf-worker.js +0 -0
  46. /package/src/{node/WranglerDevServer → wrangler}/fixtures/cf-worker.ts +0 -0
  47. /package/src/{node/WranglerDevServer → wrangler}/fixtures/wrangler.toml +0 -0
@@ -0,0 +1,133 @@
1
+ import { Effect, FetchHttpClient, Layer } from '@livestore/utils/effect'
2
+ import { getFreePort, PlatformNode } from '@livestore/utils/node'
3
+ import { Vitest } from '@livestore/utils-dev/node-vitest'
4
+ import { expect } from 'vitest'
5
+ import {
6
+ type StartWranglerDevServerArgs,
7
+ WranglerDevServerError,
8
+ WranglerDevServerService,
9
+ } from './WranglerDevServer.ts'
10
+
11
+ const testTimeout = 60_000
12
+
13
+ const WranglerDevServerTest = (args: Partial<StartWranglerDevServerArgs> = {}) =>
14
+ WranglerDevServerService.Default({
15
+ cwd: `${import.meta.dirname}/fixtures`,
16
+ ...args,
17
+ }).pipe(Layer.provide(FetchHttpClient.layer))
18
+
19
+ Vitest.describe('WranglerDevServer', { timeout: testTimeout }, () => {
20
+ Vitest.describe('Basic Operations', () => {
21
+ const withBasicTest = (args: Partial<StartWranglerDevServerArgs> = {}) =>
22
+ Vitest.makeWithTestCtx({
23
+ timeout: testTimeout,
24
+ makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
25
+ })
26
+
27
+ Vitest.scopedLive('should start wrangler dev server and return port', (test) =>
28
+ Effect.gen(function* () {
29
+ const server = yield* WranglerDevServerService
30
+
31
+ expect(server.port).toBeGreaterThan(0)
32
+ expect(server.url).toMatch(/http:\/\/127.0.0.1:\d+/)
33
+ }).pipe(withBasicTest()(test)),
34
+ )
35
+
36
+ Vitest.scopedLive('should use specified port when provided', (test) =>
37
+ Effect.andThen(getFreePort, (port) =>
38
+ Effect.gen(function* () {
39
+ const server = yield* WranglerDevServerService
40
+
41
+ expect(server.port).toBe(port)
42
+ expect(server.url).toBe(`http://127.0.0.1:${port}`)
43
+ }).pipe(withBasicTest({ preferredPort: port })(test)),
44
+ ),
45
+ )
46
+ })
47
+
48
+ Vitest.describe('Error Handling', () => {
49
+ const withErrorTest = (args: Partial<StartWranglerDevServerArgs> = {}) =>
50
+ Vitest.makeWithTestCtx({
51
+ timeout: testTimeout,
52
+ makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
53
+ })
54
+
55
+ Vitest.scopedLive('should handle missing wrangler.toml but should timeout', (test) =>
56
+ Effect.gen(function* () {
57
+ const error = yield* WranglerDevServerService.pipe(
58
+ Effect.provide(
59
+ WranglerDevServerTest({
60
+ cwd: '/tmp',
61
+ wranglerConfigPath: '/dev/null',
62
+ connectTimeout: '500 millis',
63
+ }).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
64
+ ),
65
+ Effect.flip,
66
+ )
67
+
68
+ expect(error).toBeInstanceOf(WranglerDevServerError)
69
+ }).pipe(Vitest.withTestCtx(test)),
70
+ )
71
+
72
+ Vitest.scopedLive('should handle invalid working directory', (test) =>
73
+ Effect.gen(function* () {
74
+ const result = yield* WranglerDevServerService.pipe(
75
+ Effect.provide(
76
+ WranglerDevServerTest({
77
+ cwd: '/completely/nonexistent/directory',
78
+ }).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
79
+ ),
80
+ Effect.either,
81
+ )
82
+
83
+ expect(result._tag).toBe('Left')
84
+ if (result._tag === 'Left') {
85
+ expect(result.left).toBeInstanceOf(WranglerDevServerError)
86
+ }
87
+ }).pipe(Vitest.withTestCtx(test)),
88
+ )
89
+
90
+ Vitest.scopedLive('should timeout if server fails to start', (test) =>
91
+ Effect.gen(function* () {
92
+ // Create a command that will never output "Ready on"
93
+ const result = yield* WranglerDevServerService.pipe(
94
+ // Override the timeout for this test to be shorter
95
+ Effect.timeout('5 seconds'),
96
+ Effect.either,
97
+ )
98
+
99
+ // This might succeed or fail depending on actual wrangler behavior
100
+ // The main point is testing timeout functionality
101
+ expect(['Left', 'Right']).toContain(result._tag)
102
+ }).pipe(withErrorTest()(test)),
103
+ )
104
+ })
105
+
106
+ Vitest.describe('Service Pattern', () => {
107
+ const withServiceTest = (args: Partial<StartWranglerDevServerArgs> = {}) =>
108
+ Vitest.makeWithTestCtx({
109
+ timeout: testTimeout,
110
+ makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
111
+ })
112
+
113
+ Vitest.scopedLive('should work with service pattern', (test) =>
114
+ Effect.gen(function* () {
115
+ const server = yield* WranglerDevServerService
116
+
117
+ expect(server.port).toBeGreaterThan(0)
118
+ expect(server.url).toMatch(/http:\/\/127.0.0.1:\d+/)
119
+ }).pipe(withServiceTest()(test)),
120
+ )
121
+
122
+ Vitest.scopedLive('should work with custom port via service', (test) =>
123
+ Effect.andThen(getFreePort, (port) =>
124
+ Effect.gen(function* () {
125
+ const server = yield* WranglerDevServerService
126
+
127
+ expect(server.port).toBe(port)
128
+ expect(server.url).toBe(`http://127.0.0.1:${port}`)
129
+ }).pipe(withServiceTest({ preferredPort: port })(test)),
130
+ ),
131
+ )
132
+ })
133
+ })
@@ -0,0 +1,180 @@
1
+ import * as path from 'node:path'
2
+ import * as Toml from '@iarna/toml'
3
+ import { IS_CI } from '@livestore/utils'
4
+ import { Cause, Duration, Effect, FileSystem, HttpClient, Schedule, Schema } from '@livestore/utils/effect'
5
+ import { getFreePort } from '@livestore/utils/node'
6
+ import * as wrangler from 'wrangler'
7
+
8
+ /**
9
+ * Error type for WranglerDevServer operations
10
+ */
11
+ export class WranglerDevServerError extends Schema.TaggedError<WranglerDevServerError>()('WranglerDevServerError', {
12
+ cause: Schema.Unknown,
13
+ message: Schema.String,
14
+ port: Schema.Number,
15
+ }) {}
16
+
17
+ /**
18
+ * WranglerDevServer instance interface
19
+ */
20
+ export interface WranglerDevServer {
21
+ readonly port: number
22
+ readonly url: string
23
+ // readonly processId: number
24
+ }
25
+
26
+ /**
27
+ * Configuration for starting WranglerDevServer
28
+ */
29
+ export interface StartWranglerDevServerArgs {
30
+ wranglerConfigPath?: string
31
+ cwd: string
32
+ /** The port to try first. The dev server may bind a different port if unavailable. */
33
+ preferredPort?: number
34
+ /** @default false */
35
+ showLogs?: boolean
36
+ inspectorPort?: number
37
+ connectTimeout?: Duration.DurationInput
38
+ }
39
+
40
+ /**
41
+ * WranglerDevServer as an Effect.Service.
42
+ *
43
+ * This service provides the WranglerDevServer properties and can be accessed
44
+ * directly to get port and url.
45
+ *
46
+ * TODO: Allow for config to be passed in via code instead of `wrangler.toml` file
47
+ * (would need to be placed in temporary file as wrangler only accepts files as config)
48
+ */
49
+ export class WranglerDevServerService extends Effect.Service<WranglerDevServerService>()('WranglerDevServerService', {
50
+ scoped: (args: StartWranglerDevServerArgs) =>
51
+ Effect.gen(function* () {
52
+ const showLogs = args.showLogs ?? false
53
+
54
+ // Allocate preferred port (Wrangler may bind a different one if unavailable)
55
+ const preferredPort =
56
+ args.preferredPort ??
57
+ (yield* getFreePort.pipe(
58
+ Effect.mapError(
59
+ (cause) => new WranglerDevServerError({ cause, message: 'Failed to get free port', port: -1 }),
60
+ ),
61
+ ))
62
+
63
+ yield* Effect.annotateCurrentSpan({ preferredPort })
64
+
65
+ const configPath = path.resolve(args.wranglerConfigPath ?? path.join(args.cwd, 'wrangler.toml'))
66
+
67
+ const fs = yield* FileSystem.FileSystem
68
+ const configContent = yield* fs.readFileString(configPath)
69
+ const parsedConfig = yield* Effect.try(() => Toml.parse(configContent)).pipe(
70
+ Effect.andThen(Schema.decodeUnknown(Schema.Struct({ main: Schema.String }))),
71
+ Effect.mapError(
72
+ (error) => new WranglerDevServerError({ cause: error, message: 'Failed to parse wrangler config', port: -1 }),
73
+ ),
74
+ )
75
+ const resolvedMainPath = yield* Effect.try(() => path.resolve(args.cwd, parsedConfig.main))
76
+
77
+ const devServer = yield* Effect.promise(() =>
78
+ wrangler.unstable_dev(resolvedMainPath, {
79
+ config: configPath,
80
+ port: preferredPort,
81
+ inspectorPort: args.inspectorPort ?? 0,
82
+ persistTo: path.join(args.cwd, '.wrangler/state'),
83
+ logLevel: showLogs ? 'info' : 'none',
84
+ experimental: {
85
+ disableExperimentalWarning: true,
86
+ },
87
+ }),
88
+ )
89
+
90
+ yield* Effect.addFinalizer(
91
+ Effect.fn(
92
+ function* (exit) {
93
+ if (exit._tag === 'Failure' && Cause.isInterruptedOnly(exit.cause) === false) {
94
+ yield* Effect.logError('Closing wrangler dev server on failure', exit.cause)
95
+ }
96
+
97
+ yield* Effect.tryPromise(async () => {
98
+ await devServer.stop()
99
+ // TODO investigate whether we need to wait until exit (see workers-sdk repo/talk to Cloudflare team)
100
+ // await devServer.waitUntilExit()
101
+ })
102
+ },
103
+ Effect.timeout('5 seconds'),
104
+ Effect.orDie,
105
+ Effect.tapCauseLogPretty,
106
+ Effect.withSpan('WranglerDevServerService:stopDevServer'),
107
+ ),
108
+ )
109
+
110
+ const actualPort = devServer.port
111
+ const actualHost = devServer.address
112
+ const url = `http://${actualHost}:${actualPort}`
113
+
114
+ // Use longer timeout in CI environments to account for slower startup times
115
+ const defaultTimeout = Duration.seconds(IS_CI ? 30 : 5)
116
+
117
+ yield* verifyHttpConnectivity({ url, showLogs, connectTimeout: args.connectTimeout ?? defaultTimeout })
118
+
119
+ if (showLogs) {
120
+ yield* Effect.logDebug(
121
+ `Wrangler dev server ready and accepting connections on port ${actualPort} (preferred: ${preferredPort})`,
122
+ )
123
+ }
124
+
125
+ return {
126
+ port: actualPort,
127
+ url,
128
+ } satisfies WranglerDevServer
129
+ }).pipe(
130
+ Effect.mapError(
131
+ (error) =>
132
+ new WranglerDevServerError({ cause: error, message: 'Failed to start wrangler dev server', port: -1 }),
133
+ ),
134
+ Effect.withSpan('WranglerDevServerService', {
135
+ attributes: { preferredPort: args.preferredPort ?? 'auto', cwd: args.cwd },
136
+ }),
137
+ ),
138
+ }) {}
139
+
140
+ /**
141
+ * Verifies the server is actually accepting HTTP connections by making a test request
142
+ */
143
+ const verifyHttpConnectivity = ({
144
+ url,
145
+ showLogs,
146
+ connectTimeout,
147
+ }: {
148
+ url: string
149
+ showLogs: boolean
150
+ connectTimeout: Duration.DurationInput
151
+ }): Effect.Effect<void, WranglerDevServerError, HttpClient.HttpClient> =>
152
+ Effect.gen(function* () {
153
+ const client = yield* HttpClient.HttpClient
154
+
155
+ if (showLogs) {
156
+ yield* Effect.logDebug(`Verifying HTTP connectivity to ${url}`)
157
+ }
158
+
159
+ // Try to connect with retries using exponential backoff
160
+ yield* client.get(url).pipe(
161
+ Effect.retryOrElse(
162
+ Schedule.exponential('50 millis', 2).pipe(
163
+ Schedule.jittered,
164
+ Schedule.intersect(Schedule.elapsed.pipe(Schedule.whileOutput(Duration.lessThanOrEqualTo(connectTimeout)))),
165
+ Schedule.compose(Schedule.count),
166
+ ),
167
+ (error, attemptCount) =>
168
+ Effect.fail(
169
+ new WranglerDevServerError({
170
+ cause: error,
171
+ message: `Failed to establish HTTP connection to Wrangler server at ${url} after ${attemptCount} attempts (timeout: ${Duration.toMillis(connectTimeout)}ms)`,
172
+ port: 0,
173
+ }),
174
+ ),
175
+ ),
176
+ Effect.tap(() => (showLogs ? Effect.logDebug(`HTTP connectivity verified for ${url}`) : Effect.void)),
177
+ Effect.asVoid,
178
+ Effect.withSpan('verifyHttpConnectivity'),
179
+ )
180
+ })
@@ -0,0 +1,6 @@
1
+ export {
2
+ type StartWranglerDevServerArgs,
3
+ type WranglerDevServer,
4
+ WranglerDevServerError,
5
+ WranglerDevServerService,
6
+ } from './WranglerDevServer.ts'
@@ -1 +0,0 @@
1
- {"version":3,"file":"WranglerDevServer.d.ts","sourceRoot":"","sources":["../../../src/node/WranglerDevServer/WranglerDevServer.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,QAAQ,EACR,MAAM,EAEN,UAAU,EAIV,MAAM,EAEP,MAAM,yBAAyB,CAAA;;;;;;;;AAIhC;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,2BAI1C;CAAG;AAEL;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,sFAAsF;IACtF,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,cAAc,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAA;CACxC;;4BAYgB,0BAA0B;;;;;;AAV3C;;;;;;;;GAQG;AACH,qBAAa,wBAAyB,SAAQ,6BAsJ5C;CAAG"}
@@ -1,150 +0,0 @@
1
- import { error } from 'node:console';
2
- import * as path from 'node:path';
3
- import { IS_CI, shouldNeverHappen } from '@livestore/utils';
4
- import { Command, Duration, Effect, Exit, HttpClient, Option, Schedule, Schema, Stream, } from '@livestore/utils/effect';
5
- import { getFreePort } from '@livestore/utils/node';
6
- import { cleanupOrphanedProcesses, killProcessTree } from "./process-tree-manager.js";
7
- /**
8
- * Error type for WranglerDevServer operations
9
- */
10
- export class WranglerDevServerError extends Schema.TaggedError()('WranglerDevServerError', {
11
- cause: Schema.Unknown,
12
- message: Schema.String,
13
- port: Schema.Number,
14
- }) {
15
- }
16
- /**
17
- * WranglerDevServer as an Effect.Service.
18
- *
19
- * This service provides the WranglerDevServer properties and can be accessed
20
- * directly to get port, url, and processId.
21
- *
22
- * TODO: Allow for config to be passed in via code instead of `wrangler.toml` file
23
- * (would need to be placed in temporary file as wrangler only accepts files as config)
24
- */
25
- export class WranglerDevServerService extends Effect.Service()('WranglerDevServerService', {
26
- scoped: (args) => Effect.gen(function* () {
27
- const showLogs = args.showLogs ?? false;
28
- // Clean up any orphaned processes before starting (defensive cleanup)
29
- yield* cleanupOrphanedProcesses(['wrangler', 'workerd']).pipe(Effect.tap((result) => showLogs && (result.cleaned.length > 0 || result.failed.length > 0)
30
- ? Effect.logInfo(`Cleanup result: ${result.cleaned.length} cleaned, ${result.failed.length} failed`)
31
- : Effect.void), Effect.ignore);
32
- // Allocate preferred port (Wrangler may bind a different one if unavailable)
33
- const preferredPort = args.preferredPort ??
34
- (yield* getFreePort.pipe(Effect.mapError((cause) => new WranglerDevServerError({ cause, message: 'Failed to get free port', port: -1 }))));
35
- yield* Effect.annotateCurrentSpan({ preferredPort });
36
- // Resolve config path
37
- const configPath = path.resolve(args.wranglerConfigPath ?? path.join(args.cwd, 'wrangler.toml'));
38
- const inspectorPort = args.inspectorPort ?? (yield* getFreePort);
39
- // Start wrangler process using Effect Command
40
- const process = yield* Command.make('bunx', 'wrangler', 'dev', '--port', preferredPort.toString(), '--inspector-port', inspectorPort.toString(), '--config', configPath).pipe(Command.workingDirectory(args.cwd), Command.stdout('pipe'), Command.stderr('pipe'), Command.start, Effect.catchAllCause((error) => new WranglerDevServerError({
41
- cause: error,
42
- message: `Failed to start wrangler process in directory: ${args.cwd}`,
43
- port: preferredPort,
44
- })), Effect.withSpan('WranglerDevServerService:startProcess'));
45
- if (showLogs) {
46
- yield* process.stderr.pipe(Stream.decodeText('utf8'), Stream.tapLogWithLabel('wrangler:stderr'), Stream.runDrain, Effect.forkScoped);
47
- }
48
- const processId = process.pid;
49
- // We need to keep the `stdout` stream open, as we drain it in the waitForReady function
50
- // Otherwise we'll get a EPIPE error
51
- const stdout = yield* Stream.broadcastDynamic(process.stdout, 100);
52
- // Register cleanup finalizer with intelligent timeout handling
53
- yield* Effect.addFinalizer((exit) => Effect.gen(function* () {
54
- const isInterrupted = Exit.isInterrupted(exit);
55
- if (showLogs) {
56
- yield* Effect.logDebug(`Cleaning up wrangler process ${processId}, interrupted: ${isInterrupted}`);
57
- }
58
- // yield* Effect.logDebug(`Cleaning up wrangler process ${processId}, interrupted: ${isInterrupted}`)
59
- // Check if process is still running
60
- const isRunning = yield* process.isRunning;
61
- if (isRunning) {
62
- // Use our enhanced process tree cleanup
63
- yield* killProcessTree(processId, {
64
- timeout: isInterrupted ? 500 : 3000, // Fast cleanup on interruption
65
- signals: ['SIGTERM', 'SIGKILL'],
66
- includeRoot: true,
67
- }).pipe(Effect.tap((result) => showLogs
68
- ? Effect.logDebug(`Cleaned up ${result.killedPids.length} processes, ${result.failedPids.length} failed`)
69
- : Effect.void), Effect.mapError((error) => new WranglerDevServerError({
70
- cause: error,
71
- message: `Failed to kill process tree for PID ${processId}`,
72
- port: 0,
73
- })), Effect.ignore);
74
- // Also kill the command process handle
75
- yield* process.kill();
76
- }
77
- else if (showLogs) {
78
- yield* Effect.logDebug(`Process ${processId} already terminated`);
79
- }
80
- }).pipe(Effect.withSpan('WranglerDevServerService:cleanupProcess'), Effect.timeout('5 seconds'), // Don't let cleanup hang forever
81
- Effect.ignoreLogged));
82
- // Wait for server to be ready and parse the actual bound host:port from stdout
83
- const readyInfo = yield* waitForReady({ stdout, showLogs });
84
- const actualPort = readyInfo.port;
85
- const actualHost = readyInfo.host;
86
- const url = `http://${actualHost}:${actualPort}`;
87
- // Use longer timeout in CI environments to account for slower startup times
88
- const defaultTimeout = Duration.seconds(IS_CI ? 30 : 5);
89
- yield* verifyHttpConnectivity({ url, showLogs, connectTimeout: args.connectTimeout ?? defaultTimeout });
90
- if (showLogs) {
91
- yield* Effect.logDebug(`Wrangler dev server ready and accepting connections on port ${actualPort} (preferred: ${preferredPort})`);
92
- }
93
- return {
94
- port: actualPort,
95
- url,
96
- processId,
97
- };
98
- }).pipe(Effect.withSpan('WranglerDevServerService', {
99
- attributes: { preferredPort: args.preferredPort ?? 'auto', cwd: args.cwd },
100
- })),
101
- }) {
102
- }
103
- /**
104
- * Waits for Wrangler server to be ready by monitoring stdout for "Ready on" message
105
- */
106
- const waitForReady = ({ stdout, showLogs, }) => stdout.pipe(Stream.decodeText('utf8'), Stream.splitLines, Stream.tap((line) => (showLogs ? Effect.logDebug(`[wrangler] ${line}`) : Effect.void)),
107
- // Find the first readiness line and try to parse the port from it
108
- Stream.filterMap((line) => {
109
- if (line.includes('Ready on')) {
110
- // Expect: "Ready on http://<host>:<port>"
111
- const m = line.match(/https?:\/\/([^:\s]+):(\d+)/i);
112
- if (!m)
113
- return shouldNeverHappen('Could not parse host:port from Wrangler "Ready on" line', line);
114
- const host = m[1];
115
- const port = Number.parseInt(m[2], 10);
116
- if (!Number.isFinite(port))
117
- return shouldNeverHappen('Parsed non-finite port from Wrangler output', line);
118
- return Option.some({ host, port });
119
- }
120
- else {
121
- return Option.none();
122
- }
123
- }), Stream.take(1), Stream.runHead, Effect.flatten, Effect.orElse(() => new WranglerDevServerError({
124
- cause: 'WranglerReadyLineMissing',
125
- message: 'Wrangler server did not emit a "Ready on" line',
126
- port: 0,
127
- })), Effect.timeoutFail({
128
- duration: '30 seconds',
129
- onTimeout: () => new WranglerDevServerError({
130
- cause: error,
131
- message: 'Wrangler server failed to start within timeout',
132
- port: 0,
133
- }),
134
- }));
135
- /**
136
- * Verifies the server is actually accepting HTTP connections by making a test request
137
- */
138
- const verifyHttpConnectivity = ({ url, showLogs, connectTimeout, }) => Effect.gen(function* () {
139
- const client = yield* HttpClient.HttpClient;
140
- if (showLogs) {
141
- yield* Effect.logDebug(`Verifying HTTP connectivity to ${url}`);
142
- }
143
- // Try to connect with retries using exponential backoff
144
- yield* client.get(url).pipe(Effect.retryOrElse(Schedule.exponential('50 millis', 2).pipe(Schedule.jittered, Schedule.intersect(Schedule.elapsed.pipe(Schedule.whileOutput(Duration.lessThanOrEqualTo(connectTimeout)))), Schedule.compose(Schedule.count)), (error, attemptCount) => Effect.fail(new WranglerDevServerError({
145
- cause: error,
146
- message: `Failed to establish HTTP connection to Wrangler server at ${url} after ${attemptCount} attempts (timeout: ${Duration.toMillis(connectTimeout)}ms)`,
147
- port: 0,
148
- }))), Effect.tap(() => (showLogs ? Effect.logDebug(`HTTP connectivity verified for ${url}`) : Effect.void)), Effect.asVoid, Effect.withSpan('verifyHttpConnectivity'));
149
- });
150
- //# sourceMappingURL=WranglerDevServer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WranglerDevServer.js","sourceRoot":"","sources":["../../../src/node/WranglerDevServer/WranglerDevServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAC3D,OAAO,EACL,OAAO,EACP,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,UAAU,EACV,MAAM,EAEN,QAAQ,EACR,MAAM,EACN,MAAM,GACP,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACn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