@livestore/utils-dev 0.0.0-snapshot-dffcd59e9628b35efd943619b722cf924c4ed98f → 0.0.0-snapshot-1c345a0e6695466bdc7c4483444e7b3513620261

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 (72) hide show
  1. package/dist/.tsbuildinfo.json +1 -1
  2. package/dist/node/mod.d.ts +13 -7
  3. package/dist/node/mod.d.ts.map +1 -1
  4. package/dist/node/mod.js +37 -22
  5. package/dist/node/mod.js.map +1 -1
  6. package/dist/node-vitest/mod.d.ts +1 -2
  7. package/dist/node-vitest/mod.d.ts.map +1 -1
  8. package/dist/node-vitest/mod.js +1 -2
  9. package/dist/node-vitest/mod.js.map +1 -1
  10. package/dist/node-vitest/polyfill.d.ts +2 -0
  11. package/dist/node-vitest/polyfill.d.ts.map +1 -0
  12. package/dist/node-vitest/{global.js → polyfill.js} +1 -1
  13. package/dist/node-vitest/polyfill.js.map +1 -0
  14. package/package.json +23 -16
  15. package/src/node/mod.ts +77 -39
  16. package/src/node-vitest/mod.ts +1 -3
  17. package/dist/node/DockerComposeService/DockerComposeService.d.ts +0 -48
  18. package/dist/node/DockerComposeService/DockerComposeService.d.ts.map +0 -1
  19. package/dist/node/DockerComposeService/DockerComposeService.js +0 -107
  20. package/dist/node/DockerComposeService/DockerComposeService.js.map +0 -1
  21. package/dist/node/DockerComposeService/DockerComposeService.test.d.ts +0 -2
  22. package/dist/node/DockerComposeService/DockerComposeService.test.d.ts.map +0 -1
  23. package/dist/node/DockerComposeService/DockerComposeService.test.js +0 -64
  24. package/dist/node/DockerComposeService/DockerComposeService.test.js.map +0 -1
  25. package/dist/node/FileLogger.d.ts +0 -14
  26. package/dist/node/FileLogger.d.ts.map +0 -1
  27. package/dist/node/FileLogger.js +0 -151
  28. package/dist/node/FileLogger.js.map +0 -1
  29. package/dist/node/WranglerDevServer/WranglerDevServer.d.ts +0 -53
  30. package/dist/node/WranglerDevServer/WranglerDevServer.d.ts.map +0 -1
  31. package/dist/node/WranglerDevServer/WranglerDevServer.js +0 -113
  32. package/dist/node/WranglerDevServer/WranglerDevServer.js.map +0 -1
  33. package/dist/node/WranglerDevServer/WranglerDevServer.test.d.ts +0 -2
  34. package/dist/node/WranglerDevServer/WranglerDevServer.test.d.ts.map +0 -1
  35. package/dist/node/WranglerDevServer/WranglerDevServer.test.js +0 -186
  36. package/dist/node/WranglerDevServer/WranglerDevServer.test.js.map +0 -1
  37. package/dist/node/WranglerDevServer/fixtures/cf-worker.d.ts +0 -8
  38. package/dist/node/WranglerDevServer/fixtures/cf-worker.d.ts.map +0 -1
  39. package/dist/node/WranglerDevServer/fixtures/cf-worker.js +0 -11
  40. package/dist/node/WranglerDevServer/fixtures/cf-worker.js.map +0 -1
  41. package/dist/node/WranglerDevServer/process-tree-manager.d.ts +0 -55
  42. package/dist/node/WranglerDevServer/process-tree-manager.d.ts.map +0 -1
  43. package/dist/node/WranglerDevServer/process-tree-manager.js +0 -178
  44. package/dist/node/WranglerDevServer/process-tree-manager.js.map +0 -1
  45. package/dist/node/cmd.d.ts +0 -27
  46. package/dist/node/cmd.d.ts.map +0 -1
  47. package/dist/node/cmd.js +0 -55
  48. package/dist/node/cmd.js.map +0 -1
  49. package/dist/node-vitest/Vitest.d.ts +0 -52
  50. package/dist/node-vitest/Vitest.d.ts.map +0 -1
  51. package/dist/node-vitest/Vitest.js +0 -98
  52. package/dist/node-vitest/Vitest.js.map +0 -1
  53. package/dist/node-vitest/Vitest.test.d.ts +0 -2
  54. package/dist/node-vitest/Vitest.test.d.ts.map +0 -1
  55. package/dist/node-vitest/Vitest.test.js +0 -59
  56. package/dist/node-vitest/Vitest.test.js.map +0 -1
  57. package/dist/node-vitest/global.d.ts +0 -2
  58. package/dist/node-vitest/global.d.ts.map +0 -1
  59. package/dist/node-vitest/global.js.map +0 -1
  60. package/src/node/DockerComposeService/DockerComposeService.test.ts +0 -91
  61. package/src/node/DockerComposeService/DockerComposeService.ts +0 -252
  62. package/src/node/DockerComposeService/test-fixtures/docker-compose.yml +0 -4
  63. package/src/node/FileLogger.ts +0 -206
  64. package/src/node/WranglerDevServer/WranglerDevServer.test.ts +0 -268
  65. package/src/node/WranglerDevServer/WranglerDevServer.ts +0 -220
  66. package/src/node/WranglerDevServer/fixtures/cf-worker.ts +0 -11
  67. package/src/node/WranglerDevServer/fixtures/wrangler.toml +0 -11
  68. package/src/node/WranglerDevServer/process-tree-manager.ts +0 -263
  69. package/src/node/cmd.ts +0 -99
  70. package/src/node-vitest/Vitest.test.ts +0 -101
  71. package/src/node-vitest/Vitest.ts +0 -221
  72. /package/src/node-vitest/{global.ts → polyfill.ts} +0 -0
@@ -1,64 +0,0 @@
1
- import path from 'node:path';
2
- import { Duration, Effect, Layer, Stream } from '@livestore/utils/effect';
3
- import { PlatformNode } from '@livestore/utils/node';
4
- import { Vitest } from '@livestore/utils-dev/node-vitest';
5
- import { expect } from 'vitest';
6
- import { DockerComposeService } from "./DockerComposeService.js";
7
- const testTimeout = 30_000;
8
- const testFixturePath = path.join(import.meta.dirname, 'test-fixtures');
9
- const DockerComposeTest = (args = {}) => DockerComposeService.Default({
10
- cwd: testFixturePath,
11
- ...args,
12
- });
13
- Vitest.describe('DockerComposeService', { timeout: testTimeout }, () => {
14
- Vitest.describe('Basic Operations', () => {
15
- const withBasicTest = (args = {}) => Vitest.makeWithTestCtx({
16
- timeout: testTimeout,
17
- makeLayer: () => DockerComposeTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
18
- });
19
- Vitest.scopedLive('can pull docker images', (test) => Effect.gen(function* () {
20
- const dockerCompose = yield* DockerComposeService;
21
- // Test that pull operation works (should succeed for hello-world image)
22
- yield* dockerCompose.pull;
23
- }).pipe(withBasicTest()(test)));
24
- Vitest.scopedLive('can start and stop docker compose services', (test) => Effect.gen(function* () {
25
- const dockerCompose = yield* DockerComposeService;
26
- // Start the service
27
- yield* dockerCompose.start({ detached: true });
28
- // Stop the service
29
- yield* dockerCompose.stop;
30
- }).pipe(withBasicTest({ serviceName: 'hello-world' })(test)));
31
- Vitest.scopedLive('can get logs from docker compose services', (test) => Effect.gen(function* () {
32
- const dockerCompose = yield* DockerComposeService;
33
- // Start the service first
34
- yield* dockerCompose.start({ detached: true });
35
- // Get logs (should contain at least the "Hello from Docker!" message)
36
- const firstLogLine = yield* dockerCompose.logs().pipe(Stream.runHead);
37
- expect(firstLogLine._tag).toBe('Some');
38
- // Stop the service
39
- yield* dockerCompose.stop;
40
- }).pipe(withBasicTest({ serviceName: 'hello-world' })(test)));
41
- });
42
- Vitest.describe('Health Check Operations', () => {
43
- const withHealthCheckTest = (args = {}) => Vitest.makeWithTestCtx({
44
- timeout: testTimeout,
45
- makeLayer: () => DockerComposeTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
46
- });
47
- Vitest.scopedLive('handles health check timeout gracefully', (test) => Effect.gen(function* () {
48
- const dockerCompose = yield* DockerComposeService;
49
- // Test starting with a health check that will timeout (invalid URL)
50
- const result = yield* dockerCompose
51
- .start({
52
- detached: true,
53
- healthCheck: {
54
- url: 'http://localhost:99999/nonexistent',
55
- timeout: Duration.seconds(2),
56
- },
57
- })
58
- .pipe(Effect.either);
59
- // Should fail due to health check timeout
60
- expect(result._tag).toBe('Left');
61
- }).pipe(withHealthCheckTest({ serviceName: 'hello-world' })(test)));
62
- });
63
- });
64
- //# sourceMappingURL=DockerComposeService.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DockerComposeService.test.js","sourceRoot":"","sources":["../../../src/node/DockerComposeService/DockerComposeService.test.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAA;AACzD,OAAO,EAAE,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EAAE,GAAG,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;SAC7F,CAAC,CAAA;QAEJ,MAAM,CAAC,UAAU,CAAC,yCAAyC,EAAE,CAAC,IAAI,EAAE,EAAE,CACpE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;YAClB,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,oBAAoB,CAAA;YAEjD,oEAAoE;YACpE,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,aAAa;iBAChC,KAAK,CAAC;gBACL,QAAQ,EAAE,IAAI;gBACd,WAAW,EAAE;oBACX,GAAG,EAAE,oCAAoC;oBACzC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;iBAC7B;aACF,CAAC;iBACD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YAEtB,0CAA0C;YAC1C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAClC,CAAC,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CACnE,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,14 +0,0 @@
1
- import { Layer, Logger } from '@livestore/utils/effect';
2
- export declare const makeFileLogger: (logFilePath: string, options?: {
3
- readonly threadName: string;
4
- readonly colors?: boolean;
5
- }) => Layer.Layer<never, never, never>;
6
- export declare const defaultDateFormat: (date: Date) => string;
7
- export declare const structuredMessage: (u: unknown) => unknown;
8
- export declare const prettyLoggerTty: (options: {
9
- readonly colors: boolean;
10
- readonly stderr: boolean;
11
- readonly formatDate: (date: Date) => string;
12
- readonly onLog?: (str: string) => void;
13
- }) => Logger.Logger<unknown, string>;
14
- //# sourceMappingURL=FileLogger.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FileLogger.d.ts","sourceRoot":"","sources":["../../src/node/FileLogger.ts"],"names":[],"mappings":"AAGA,OAAO,EAML,KAAK,EAEL,MAAM,EAIP,MAAM,yBAAyB,CAAA;AAEhC,eAAO,MAAM,cAAc,GACzB,aAAa,MAAM,EACnB,UAAU;IACR,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAC1B,qCAqBA,CAAA;AAmCH,eAAO,MAAM,iBAAiB,GAAI,MAAM,IAAI,KAAG,MAI8B,CAAA;AAE7E,eAAO,MAAM,iBAAiB,GAAI,GAAG,OAAO,KAAG,OAW9C,CAAA;AAqBD,eAAO,MAAM,eAAe,GAAI,SAAS;IACvC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,CAAA;IAC3C,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;CACvC,mCAoFA,CAAA"}
@@ -1,151 +0,0 @@
1
- import * as fs from 'node:fs';
2
- import path from 'node:path';
3
- import util from 'node:util';
4
- import { Cause, Effect, FiberId, HashMap, Inspectable, Layer, List, Logger, LogSpan, ReadonlyArray, } from '@livestore/utils/effect';
5
- export const makeFileLogger = (logFilePath, options) => Layer.unwrapScoped(Effect.gen(function* () {
6
- yield* Effect.sync(() => fs.mkdirSync(path.dirname(logFilePath), { recursive: true }));
7
- const logFile = yield* Effect.acquireRelease(Effect.sync(() => fs.openSync(logFilePath, 'a', 0o666)), (fd) => Effect.sync(() => fs.closeSync(fd)));
8
- return Logger.replace(Logger.defaultLogger, prettyLoggerTty({
9
- colors: options?.colors ?? false,
10
- stderr: false,
11
- formatDate: (date) => `${defaultDateFormat(date)} ${options?.threadName ?? ''}`,
12
- onLog: (str) => fs.writeSync(logFile, str),
13
- }));
14
- }));
15
- const withColor = (text, ...colors) => {
16
- let out = '';
17
- for (let i = 0; i < colors.length; i++) {
18
- out += `\x1b[${colors[i]}m`;
19
- }
20
- return `${out}${text}\x1b[0m`;
21
- };
22
- const withColorNoop = (text, ..._colors) => text;
23
- const colors = {
24
- bold: '1',
25
- red: '31',
26
- green: '32',
27
- yellow: '33',
28
- blue: '34',
29
- cyan: '36',
30
- white: '37',
31
- gray: '90',
32
- black: '30',
33
- bgBrightRed: '101',
34
- };
35
- const logLevelColors = {
36
- None: [],
37
- All: [],
38
- Trace: [colors.gray],
39
- Debug: [colors.blue],
40
- Info: [colors.green],
41
- Warning: [colors.yellow],
42
- Error: [colors.red],
43
- Fatal: [colors.bgBrightRed, colors.black],
44
- };
45
- export const defaultDateFormat = (date) => `${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}:${date
46
- .getSeconds()
47
- .toString()
48
- .padStart(2, '0')}.${date.getMilliseconds().toString().padStart(3, '0')}`;
49
- export const structuredMessage = (u) => {
50
- switch (typeof u) {
51
- case 'bigint':
52
- case 'function':
53
- case 'symbol': {
54
- return String(u);
55
- }
56
- default: {
57
- return Inspectable.toJSON(u);
58
- }
59
- }
60
- };
61
- const consoleLogToString = (...s) => {
62
- if (s.length === 0)
63
- return '';
64
- const [first, ...rest] = s;
65
- if (typeof first === 'string') {
66
- return rest.length > 0 ? util.format(first, ...rest.map(structuredMessage)) : first;
67
- }
68
- return s
69
- .map((v) => {
70
- if (typeof v === 'string')
71
- return v;
72
- return util.inspect(structuredMessage(v), {
73
- depth: 3,
74
- colors: false,
75
- compact: false,
76
- breakLength: 120,
77
- });
78
- })
79
- .join(' ');
80
- };
81
- export const prettyLoggerTty = (options) => {
82
- const color = options.colors ? withColor : withColorNoop;
83
- return Logger.make(({ annotations, cause, date, fiberId, logLevel, message: message_, spans }) => {
84
- let str = '';
85
- const log = (...s) => {
86
- str += `${consoleLogToString(...s)}\n`;
87
- options.onLog?.(str);
88
- };
89
- const logIndented = (...s) => {
90
- str += `${consoleLogToString(...s).replace(/^/gm, ' ')}\n`;
91
- options.onLog?.(str);
92
- };
93
- const message = ReadonlyArray.ensure(message_);
94
- let firstLine = color(`[${options.formatDate(date)}]`, colors.white) +
95
- ` ${color(logLevel.label, ...logLevelColors[logLevel._tag])}` +
96
- ` (${FiberId.threadName(fiberId)})`;
97
- if (List.isCons(spans)) {
98
- const now = date.getTime();
99
- const render = LogSpan.render(now);
100
- for (const span of spans) {
101
- firstLine += ` ${render(span)}`;
102
- }
103
- }
104
- firstLine += ':';
105
- let messageIndex = 0;
106
- if (message.length > 0) {
107
- const firstMaybeString = structuredMessage(message[0]);
108
- if (typeof firstMaybeString === 'string') {
109
- firstLine += ` ${color(firstMaybeString, colors.bold, colors.cyan)}`;
110
- messageIndex++;
111
- }
112
- }
113
- log(firstLine);
114
- // if (!processIsBun) console.group()
115
- if (!Cause.isEmpty(cause)) {
116
- logIndented(Cause.pretty(cause, { renderErrorCause: true }));
117
- }
118
- if (messageIndex < message.length) {
119
- for (; messageIndex < message.length; messageIndex++) {
120
- const msg = message[messageIndex];
121
- if (typeof msg === 'object' && msg !== null) {
122
- logIndented(util.inspect(structuredMessage(msg), {
123
- depth: 3,
124
- colors: false,
125
- compact: false,
126
- breakLength: 120,
127
- }));
128
- }
129
- else {
130
- logIndented(Inspectable.redact(msg));
131
- }
132
- }
133
- }
134
- if (HashMap.size(annotations) > 0) {
135
- for (const [key, value] of annotations) {
136
- const formattedValue = typeof value === 'object' && value !== null
137
- ? util.inspect(structuredMessage(value), {
138
- depth: 3,
139
- colors: false,
140
- compact: false,
141
- breakLength: 120,
142
- })
143
- : Inspectable.redact(value);
144
- logIndented(color(`${key}:`, colors.bold, colors.white), formattedValue);
145
- }
146
- }
147
- // if (!processIsBun) console.groupEnd()
148
- return str;
149
- });
150
- };
151
- //# sourceMappingURL=FileLogger.js.map
@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QAED,wCAAwC;QAExC,OAAO,GAAG,CAAA;IACZ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
@@ -1,53 +0,0 @@
1
- import { Effect, Schema } from '@livestore/utils/effect';
2
- declare const WranglerDevServerError_base: Schema.TaggedErrorClass<WranglerDevServerError, "WranglerDevServerError", {
3
- readonly _tag: Schema.tag<"WranglerDevServerError">;
4
- } & {
5
- cause: typeof Schema.Unknown;
6
- message: typeof Schema.String;
7
- port: typeof Schema.Number;
8
- }>;
9
- /**
10
- * Error type for WranglerDevServer operations
11
- */
12
- export declare class WranglerDevServerError extends WranglerDevServerError_base {
13
- }
14
- /**
15
- * WranglerDevServer instance interface
16
- */
17
- export interface WranglerDevServer {
18
- readonly port: number;
19
- readonly url: string;
20
- readonly processId: number;
21
- }
22
- /**
23
- * Configuration for starting WranglerDevServer
24
- */
25
- export interface StartWranglerDevServerArgs {
26
- wranglerConfigPath?: string;
27
- cwd: string;
28
- port?: number;
29
- /** Inspector/debugger port for workerd. If not specified, uses a random free port */
30
- inspectorPort?: number;
31
- /** @default false */
32
- showLogs?: boolean;
33
- }
34
- declare const WranglerDevServerService_base: Effect.Service.Class<WranglerDevServerService, "WranglerDevServerService", {
35
- readonly scoped: (args: StartWranglerDevServerArgs) => Effect.Effect<{
36
- port: number;
37
- url: string;
38
- processId: import("@effect/platform/CommandExecutor").ProcessId;
39
- }, WranglerDevServerError, import("effect/Scope").Scope | import("@effect/platform/CommandExecutor").CommandExecutor>;
40
- }>;
41
- /**
42
- * WranglerDevServer as an Effect.Service.
43
- *
44
- * This service provides the WranglerDevServer properties and can be accessed
45
- * directly to get port, url, and processId.
46
- *
47
- * TODO: Allow for config to be passed in via code instead of `wrangler.toml` file
48
- * (would need to be placed in temporary file as wrangler only accepts files as config)
49
- */
50
- export declare class WranglerDevServerService extends WranglerDevServerService_base {
51
- }
52
- export {};
53
- //# sourceMappingURL=WranglerDevServer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WranglerDevServer.d.ts","sourceRoot":"","sources":["../../../src/node/WranglerDevServer/WranglerDevServer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAW,MAAM,EAA4B,MAAM,EAAU,MAAM,yBAAyB,CAAA;;;;;;;;AAInG;;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,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,qFAAqF;IACrF,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;;4BAYgB,0BAA0B;;;;;;AAV3C;;;;;;;;GAQG;AACH,qBAAa,wBAAyB,SAAQ,6BAkJ5C;CAAG"}
@@ -1,113 +0,0 @@
1
- import * as path from 'node:path';
2
- import { Command, Effect, Exit, Schema, Stream } from '@livestore/utils/effect';
3
- import { getFreePort } from '@livestore/utils/node';
4
- import { cleanupOrphanedProcesses, killProcessTree } from "./process-tree-manager.js";
5
- /**
6
- * Error type for WranglerDevServer operations
7
- */
8
- export class WranglerDevServerError extends Schema.TaggedError()('WranglerDevServerError', {
9
- cause: Schema.Unknown,
10
- message: Schema.String,
11
- port: Schema.Number,
12
- }) {
13
- }
14
- /**
15
- * WranglerDevServer as an Effect.Service.
16
- *
17
- * This service provides the WranglerDevServer properties and can be accessed
18
- * directly to get port, url, and processId.
19
- *
20
- * TODO: Allow for config to be passed in via code instead of `wrangler.toml` file
21
- * (would need to be placed in temporary file as wrangler only accepts files as config)
22
- */
23
- export class WranglerDevServerService extends Effect.Service()('WranglerDevServerService', {
24
- scoped: (args) => Effect.gen(function* () {
25
- const showLogs = args.showLogs ?? false;
26
- // Clean up any orphaned processes before starting (defensive cleanup)
27
- yield* cleanupOrphanedProcesses(['wrangler', 'workerd']).pipe(Effect.tap((result) => showLogs && (result.cleaned.length > 0 || result.failed.length > 0)
28
- ? Effect.logInfo(`Cleanup result: ${result.cleaned.length} cleaned, ${result.failed.length} failed`)
29
- : Effect.void), Effect.ignore);
30
- // Allocate port
31
- const port = args.port ??
32
- (yield* getFreePort.pipe(Effect.mapError((cause) => new WranglerDevServerError({ cause, message: 'Failed to get free port', port: -1 }))));
33
- // Allocate inspector port if not provided
34
- const inspectorPort = args.inspectorPort ??
35
- (yield* getFreePort.pipe(Effect.mapError((cause) => new WranglerDevServerError({ cause, message: 'Failed to get free inspector port', port: -1 }))));
36
- yield* Effect.annotateCurrentSpan({ port, inspectorPort });
37
- // Resolve config path
38
- const configPath = path.resolve(args.wranglerConfigPath ?? path.join(args.cwd, 'wrangler.toml'));
39
- // Start wrangler process using Effect Command
40
- // In CI, disable the inspector to avoid port conflicts
41
- const commandArgs = ['bunx', 'wrangler', 'dev', '--port', port.toString()];
42
- // Only add inspector port if not in CI to avoid conflicts
43
- // Use global process from Node.js
44
- if (!global.process.env.CI) {
45
- commandArgs.push('--inspector-port', inspectorPort.toString());
46
- }
47
- commandArgs.push('--config', configPath);
48
- const process = yield* Command.make(...commandArgs).pipe(Command.workingDirectory(args.cwd), Command.stdout('pipe'), Command.stderr('pipe'), Command.start, Effect.catchAllCause((error) => new WranglerDevServerError({
49
- cause: error,
50
- message: `Failed to start wrangler process in directory: ${args.cwd}`,
51
- port,
52
- })), Effect.withSpan('WranglerDevServerService:startProcess'));
53
- if (showLogs) {
54
- yield* process.stderr.pipe(Stream.decodeText('utf8'), Stream.tapLogWithLabel('wrangler:stderr'), Stream.runDrain, Effect.forkScoped);
55
- }
56
- const processId = process.pid;
57
- // We need to keep the `stdout` stream open, as we drain it in the waitForReady function
58
- // Otherwise we'll get a EPIPE error
59
- const stdout = yield* Stream.broadcastDynamic(process.stdout, 100);
60
- // Register cleanup finalizer with intelligent timeout handling
61
- yield* Effect.addFinalizer((exit) => Effect.gen(function* () {
62
- const isInterrupted = Exit.isInterrupted(exit);
63
- if (showLogs) {
64
- yield* Effect.logDebug(`Cleaning up wrangler process ${processId}, interrupted: ${isInterrupted}`);
65
- }
66
- // yield* Effect.logDebug(`Cleaning up wrangler process ${processId}, interrupted: ${isInterrupted}`)
67
- // Check if process is still running
68
- const isRunning = yield* process.isRunning;
69
- if (isRunning) {
70
- // Use our enhanced process tree cleanup
71
- yield* killProcessTree(processId, {
72
- timeout: isInterrupted ? 500 : 3000, // Fast cleanup on interruption
73
- signals: ['SIGTERM', 'SIGKILL'],
74
- includeRoot: true,
75
- }).pipe(Effect.tap((result) => showLogs
76
- ? Effect.logDebug(`Cleaned up ${result.killedPids.length} processes, ${result.failedPids.length} failed`)
77
- : Effect.void), Effect.mapError((error) => new WranglerDevServerError({
78
- cause: error,
79
- message: `Failed to kill process tree for PID ${processId}`,
80
- port: 0,
81
- })), Effect.ignore);
82
- // Also kill the command process handle
83
- yield* process.kill();
84
- }
85
- else if (showLogs) {
86
- yield* Effect.logDebug(`Process ${processId} already terminated`);
87
- }
88
- }).pipe(Effect.timeout('5 seconds'), // Don't let cleanup hang forever
89
- Effect.ignoreLogged));
90
- // Wait for server to be ready
91
- yield* waitForReady({ stdout, showLogs });
92
- if (showLogs) {
93
- yield* Effect.logDebug(`Wrangler dev server ready on port ${port}`);
94
- }
95
- return {
96
- port,
97
- url: `http://localhost:${port}`,
98
- processId,
99
- };
100
- }).pipe(Effect.withSpan('WranglerDevServerService', {
101
- attributes: { port: args.port ?? 'auto', cwd: args.cwd },
102
- })),
103
- }) {
104
- }
105
- /**
106
- * Waits for Wrangler server to be ready by monitoring stdout for "Ready on" message
107
- */
108
- const waitForReady = ({ stdout, showLogs, }) => stdout.pipe(Stream.decodeText('utf8'), Stream.splitLines, Stream.tap((line) => (showLogs ? Effect.logDebug(`[wrangler] ${line}`) : Effect.void)), Stream.takeUntil((line) => line.includes('Ready on')), Stream.runDrain, Effect.timeout('30 seconds'), Effect.mapError((error) => new WranglerDevServerError({
109
- cause: error,
110
- message: 'Wrangler server failed to start within timeout',
111
- port: 0,
112
- })));
113
- //# sourceMappingURL=WranglerDevServer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WranglerDevServer.js","sourceRoot":"","sources":["../../../src/node/WranglerDevServer/WranglerDevServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAsB,MAAM,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACnG,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAErF;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,MAAM,CAAC,WAAW,EAA0B,CAAC,wBAAwB,EAAE;IACjH,KAAK,EAAE,MAAM,CAAC,OAAO;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,IAAI,EAAE,MAAM,CAAC,MAAM;CACpB,CAAC;CAAG;AAwBL;;;;;;;;GAQG;AACH,MAAM,OAAO,wBAAyB,SAAQ,MAAM,CAAC,OAAO,EAA4B,CAAC,0BAA0B,EAAE;IACnH,MAAM,EAAE,CAAC,IAAgC,EAAE,EAAE,CAC3C,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,KAAK,CAAA;QAEvC,sEAAsE;QACtE,KAAK,CAAC,CAAC,wBAAwB,CAAC,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC,IAAI,CAC3D,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CACpB,QAA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AAE,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,EACrD,MAAM,CAAC,QAAQ,EACf,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAC5B,MAAM,CAAC,QAAQ,CACb,CAAC,KAAK,EAAE,EAAE,CACR,IAAI,sBAAsB,CAAC;IACzB,KAAK,EAAE,KAAK;IACZ,OAAO,EAAE,gDAAgD;IACzD,IAAI,EAAE,CAAC;CACR,CAAC,CACL,CACF,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=WranglerDevServer.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WranglerDevServer.test.d.ts","sourceRoot":"","sources":["../../../src/node/WranglerDevServer/WranglerDevServer.test.ts"],"names":[],"mappings":""}
@@ -1,186 +0,0 @@
1
- import { Effect, Exit, Fiber, Layer, Scope } from '@livestore/utils/effect';
2
- import { PlatformNode } from '@livestore/utils/node';
3
- import { Vitest } from '@livestore/utils-dev/node-vitest';
4
- import { expect } from 'vitest';
5
- import { WranglerDevServerError, WranglerDevServerService, } from "./WranglerDevServer.js";
6
- const testTimeout = 60_000;
7
- const withTestCtx = Vitest.makeWithTestCtx({
8
- timeout: testTimeout,
9
- makeLayer: () => PlatformNode.NodeContext.layer,
10
- });
11
- const WranglerDevServerTest = (args = {}) => WranglerDevServerService.Default({
12
- cwd: `${import.meta.dirname}/fixtures`,
13
- ...args,
14
- });
15
- Vitest.describe('WranglerDevServer', { timeout: testTimeout }, () => {
16
- Vitest.describe('Basic Operations', () => {
17
- const withBasicTest = (args = {}) => Vitest.makeWithTestCtx({
18
- timeout: testTimeout,
19
- makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
20
- });
21
- Vitest.scopedLive('should start wrangler dev server and return port', (test) => Effect.gen(function* () {
22
- const server = yield* WranglerDevServerService;
23
- expect(server.port).toBeGreaterThan(0);
24
- expect(server.url).toMatch(/http:\/\/localhost:\d+/);
25
- expect(typeof server.processId).toBe('number');
26
- expect(server.processId).toBeGreaterThan(0);
27
- }).pipe(withBasicTest()(test)));
28
- Vitest.scopedLive('should use specified port when provided', (test) => Effect.gen(function* () {
29
- const server = yield* WranglerDevServerService;
30
- expect(server.port).toBe(54443);
31
- expect(server.url).toBe(`http://localhost:54443`);
32
- }).pipe(withBasicTest({ port: 54443 })(test)));
33
- });
34
- Vitest.describe('Resource Management', () => {
35
- Vitest.scopedLive('should cleanup processes on scope close', (test) => Effect.gen(function* () {
36
- let processId;
37
- // Create a separate scope for the server
38
- const serverScope = yield* Scope.make();
39
- const server = yield* Effect.provide(WranglerDevServerService, WranglerDevServerTest().pipe(Layer.provide(PlatformNode.NodeContext.layer))).pipe(Scope.extend(serverScope));
40
- processId = server.processId;
41
- expect(processId).toBeGreaterThan(0);
42
- expect(server.port).toBeGreaterThan(0);
43
- expect(server.url).toMatch(/http:\/\/localhost:\d+/);
44
- // Close scope to trigger cleanup
45
- yield* Scope.close(serverScope, Exit.succeed(void 0));
46
- // Wait for cleanup to complete
47
- yield* Effect.sleep('2 seconds');
48
- // Verify process is terminated
49
- const isRunning2 = yield* Effect.promise(() => {
50
- try {
51
- process.kill(processId, 0);
52
- return Promise.resolve(true);
53
- }
54
- catch {
55
- return Promise.resolve(false);
56
- }
57
- });
58
- expect(isRunning2).toBe(false);
59
- }).pipe(withTestCtx(test)));
60
- Vitest.scopedLive('should handle interruption with fast cleanup', (test) => Effect.gen(function* () {
61
- let processId;
62
- const fiber = yield* Effect.fork(Effect.provide(Effect.gen(function* () {
63
- const server = yield* WranglerDevServerService;
64
- processId = server.processId;
65
- yield* Effect.sleep('30 seconds'); // Keep running
66
- return server;
67
- }), WranglerDevServerTest().pipe(Layer.provide(PlatformNode.NodeContext.layer))));
68
- // Wait for server to start
69
- yield* Effect.sleep('3 seconds');
70
- expect(processId).toBeGreaterThan(0);
71
- // Interrupt and measure cleanup time
72
- const start = Date.now();
73
- yield* Fiber.interrupt(fiber);
74
- const elapsed = Date.now() - start;
75
- // Should use fast cleanup (500ms timeout) + some overhead
76
- expect(elapsed).toBeLessThan(1500); // Allow some overhead
77
- // Wait for cleanup to complete
78
- yield* Effect.sleep('1 second');
79
- // Verify process is terminated
80
- const isRunningAfter = yield* Effect.promise(() => {
81
- try {
82
- process.kill(processId, 0);
83
- return Promise.resolve(true);
84
- }
85
- catch {
86
- return Promise.resolve(false);
87
- }
88
- });
89
- expect(isRunningAfter).toBe(false);
90
- }).pipe(withTestCtx(test)));
91
- });
92
- Vitest.describe('Error Handling', () => {
93
- const withErrorTest = (args = {}) => Vitest.makeWithTestCtx({
94
- timeout: testTimeout,
95
- makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
96
- });
97
- Vitest.scopedLive('should handle missing wrangler.toml', (test) => Effect.gen(function* () {
98
- // Since Wrangler can work without a config file, let's test with a truly invalid scenario
99
- const result = yield* WranglerDevServerService.pipe(Effect.either);
100
- // Note: Wrangler might still succeed even with /dev/null, so this test
101
- // verifies our implementation handles the case properly, whether it succeeds or fails
102
- expect(['Left', 'Right']).toContain(result._tag);
103
- if (result._tag === 'Left') {
104
- // If it fails, it should be a wrapped error
105
- expect(result.left).toBeInstanceOf(WranglerDevServerError);
106
- }
107
- else {
108
- // If it succeeds, the server should be properly configured
109
- expect(result.right.port).toBeGreaterThan(0);
110
- }
111
- }).pipe(withErrorTest({ cwd: '/tmp', wranglerConfigPath: '/dev/null' })(test)));
112
- Vitest.scopedLive('should handle invalid working directory', (test) => Effect.gen(function* () {
113
- const result = yield* WranglerDevServerService.pipe(Effect.provide(WranglerDevServerTest({
114
- cwd: '/completely/nonexistent/directory',
115
- }).pipe(Layer.provide(PlatformNode.NodeContext.layer))), Effect.either);
116
- expect(result._tag).toBe('Left');
117
- if (result._tag === 'Left') {
118
- expect(result.left).toBeInstanceOf(WranglerDevServerError);
119
- }
120
- }).pipe(Vitest.withTestCtx(test)));
121
- Vitest.scopedLive('should timeout if server fails to start', (test) => Effect.gen(function* () {
122
- // Create a command that will never output "Ready on"
123
- const result = yield* WranglerDevServerService.pipe(
124
- // Override the timeout for this test to be shorter
125
- Effect.timeout('5 seconds'), Effect.either);
126
- // This might succeed or fail depending on actual wrangler behavior
127
- // The main point is testing timeout functionality
128
- expect(['Left', 'Right']).toContain(result._tag);
129
- }).pipe(withErrorTest()(test)));
130
- });
131
- Vitest.describe('Process Tree Cleanup', () => {
132
- const withCleanupTest = (args = {}) => Vitest.makeWithTestCtx({
133
- timeout: testTimeout,
134
- makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
135
- });
136
- Vitest.scopedLive('should clean up child workerd processes', (test) => Effect.gen(function* () {
137
- let processId;
138
- const server = yield* WranglerDevServerService;
139
- processId = server.processId;
140
- // Wait for wrangler to spawn workerd children
141
- yield* Effect.sleep('3 seconds');
142
- // Find any child processes (workerd)
143
- const children = yield* Effect.promise(async () => {
144
- const { exec } = require('node:child_process');
145
- const { promisify } = require('node:util');
146
- const execAsync = promisify(exec);
147
- try {
148
- if (!processId)
149
- throw new Error('processId is undefined');
150
- const { stdout } = await execAsync(`ps -o pid,ppid -ax | grep -E "^\\s*[0-9]+\\s+${processId}\\s*$"`);
151
- return stdout
152
- .trim()
153
- .split('\n')
154
- .map((line) => {
155
- const match = line.trim().match(/^\s*(\d+)\s+\d+\s*$/);
156
- return match?.[1] ? Number.parseInt(match[1], 10) : null;
157
- })
158
- .filter((pid) => pid !== null);
159
- }
160
- catch {
161
- return [];
162
- }
163
- });
164
- console.log(`Found ${children.length} child processes:`, children);
165
- // The scope will close here and should clean up all processes
166
- }).pipe(withCleanupTest()(test)));
167
- });
168
- Vitest.describe('Service Pattern', () => {
169
- const withServiceTest = (args = {}) => Vitest.makeWithTestCtx({
170
- timeout: testTimeout,
171
- makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
172
- });
173
- Vitest.scopedLive('should work with service pattern', (test) => Effect.gen(function* () {
174
- const server = yield* WranglerDevServerService;
175
- expect(server.port).toBeGreaterThan(0);
176
- expect(server.url).toMatch(/http:\/\/localhost:\d+/);
177
- expect(server.processId).toBeGreaterThan(0);
178
- }).pipe(withServiceTest()(test)));
179
- Vitest.scopedLive('should work with custom port via service', (test) => Effect.gen(function* () {
180
- const server = yield* WranglerDevServerService;
181
- expect(server.port).toBe(54444);
182
- expect(server.url).toBe('http://localhost:54444');
183
- }).pipe(withServiceTest({ port: 54444 })(test)));
184
- });
185
- });
186
- //# sourceMappingURL=WranglerDevServer.test.js.map