@athrio/loom 0.0.8 → 0.0.10

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.
package/dist/main.js CHANGED
@@ -1,16 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import { t as __commonJSMin } from "./rolldown-runtime-YU9U6SYh.js";
3
- import { $ as mkString, $n as done, $t as ensuring, A as log, An as timeoutOrElse, Ar as none, At as mapDone, B as WatchBackend, Bn as provide, Br as dual, Bt as acquireRelease, C as errorExitCode, Cn as runFork, Cr as fromUndefinedOr, Ct as is, D as Crypto$1, Dn as suspend, Dr as isSome, En as succeed, Er as isNone, Et as toCodecStringTree, F as TypeId$5, Fn as catchDone, Fr as hasProperty, Ft as offerUnsafe, G as empty$1, Gn as _await, Gt as callback, H as callback$1, Hn as succeed$3, Hr as pipe, Ht as andThen, I as FileDescriptor, Ir as isNotNull, It as take, J as fromEffect, Jn as makeUnsafe$1, Jt as catchTag, K as filter$1, Kn as doneUnsafe, L as FileSystem, Ln as taggedEnum, Lr as isNotUndefined, Lt as make$7, M as FalseValues, Mn as try_, Mr as String$2, Mt as failCauseUnsafe, N as TrueValues, Nn as uninterruptible, Nr as BaseProto, Nt as make$12, O as make$9, On as sync, Or as map$4, P as Path$1, Pn as void_, Pr as format, Pt as offer, Q as merge, Qn as UnknownError, Qt as effectify, R as FileTypeId, Rn as effect, Rr as isNullish, Rt as makeUnsafe, S as make$10, Sn as result, Sr as fromNullishOr, St as decodeUnknownEffect, T as makeRunMain, Tn as serviceOption, Tr as getOrUndefined, Tt as tag, U as concat, Un as addFinalizer, Ur as pipeArguments, Ut as as, V as make$8, Vn as provideMerge, Vr as identity, Vt as addFinalizer$1, W as decodeText, Wn as MinimumLogLevel, Wt as asVoid, X as isStream, Xn as succeed$2, Xt as catch_, Y as groupedWithin, Yn as fail$2, Yt as catchTags, Z as mapEffect, Zn as Done, _ as QuitError, _n as orElseSucceed, _r as fail$1, _t as ErrorClass, a as storeDir, an as forkScoped, ar as make$6, at as transduce, b as make$13, bn as provideService, br as contains, bt as Struct, c as LoomCompiler, cn as interrupt, cr as filter, ct as make$11, dn as map$2, dt as isSink, en as fail, er as fail$3, et as orDie$1, f as PackageConfig, fn as mapError, fr as map$3, ft as BadArgument, gn as orDie, gr as sort, gt as Defect, hn as option, hr as reduce, ht as ArraySchema, i as servicePackage, in as forever, ir as getUnsafe, it as splitLines, j as Boolean, jn as tryPromise, jr as some, jt as endUnsafe, k as error, kr as match$2, kt as fromTransform, l as ignoredDirs, ln as isEffect, lt as drain, mn as matchEffect, mr as of, mt as systemError, n as installedServices, nn as fnUntraced, nr as Service, nt as runCollect, o as workspaceRoot, on as gen, or as Prototype, ot as unwrap, p as LoomConfig, pn as match$1, pr as match, pt as badArgument, q as fromChannel$1, qn as isDone, qt as catchFilter, r as removeService, rn as forEach, rr as empty, rt as runForEach, s as DocumentSource, sn as ignore, sr as dedupe, st as get, t as addService, tn as flatMap, tr as Reference, tt as run$2, ut as fromChannel, v as Terminal, vn as provide$1, vr as match$3, vt as Literal, w as errorReported, wn as scoped, wr as getOrElse, wt as optional$3, x as Stdio, xn as raceFirst, xr as flatMap$1, xt as Union, y as isQuitError, yn as provideContext, yr as succeed$1, yt as String$1, z as Size, zn as mergeAll, zr as isUndefined, zt as nominal } from "./LoomStore-C2tWuEsJ.js";
4
- import * as NodeChildProcess from "node:child_process";
5
- import { PassThrough } from "node:stream";
6
- import * as Crypto from "node:crypto";
7
- import * as NFS from "node:fs";
3
+ import { $ as orDie$1, $p as map$4, $t as Literal, Af as Prototype, Ah as identity, Al as taggedEnum, Bf as filter, Bs as gen, Bt as Defect, Cc as result, Dh as dual, Es as fail, Ff as dedupe, Fn as Union, Gp as fromNullishOr, H as groupedWithin, Hl as provide, Hs as interrupt, I as fromEffect, Il as effect, Kp as fromUndefinedOr, Ku as pretty, Lc as scoped, Lp as match$3, Mm as format, Mp as fail$1, Ms as forEach, N as filter$1, Nh as pipeArguments, O as concat, Os as flatMap, Qp as isSome, Qs as map$2, Ra as take, Rp as succeed$1, Uc as suspend, Vc as succeed, Vp as contains, Wc as sync, Wn as decodeUnknownEffect, Ws as isEffect, Wt as ErrorClass, Xc as tryPromise, Xp as getOrUndefined, Zc as try_, Zp as isNone, Zt as Int, _c as provideService, _f as Service, ah as hasProperty, al as void_, bc as raceFirst, cm as String$2, dc as option, dt as unwrap, ec as mapError, em as match$2, er as is, fc as orDie, fp as sort, fs as catchCause, gc as provideContext, gf as Reference, gs as catchTags, h as Path, hc as provide$1, hs as catchTag, ii as tag, ip as map$3, is as andThen, it as runForEach, jh as pipe, js as fnUntraced, kt as ArraySchema, l as FalseValues, lp as reduce, mc as promise, ms as catchFilter, oi as toCodecStringTree, op as match, ou as MinimumLogLevel, pc as orElseSucceed, q as mapEffect$1, qp as getOrElse, rm as some, s as Boolean, ss as as, tc as match$1, ti as optional$3, tm as none, u as TrueValues, uh as isNotUndefined, vn as String$1, wf as make$1, ws as ensuring, y as FileSystem, yf as empty, yn as Struct, zl as launch } from "./SqlClient-BHo_uVyk.js";
4
+ import { N as error, P as log, _ as orElse, c as errorExitCode, i as isQuitError, l as errorReported, n as QuitError, o as Stdio, r as Terminal, u as makeRunMain, v as tag$1, y as value } from "./dist-CKhPOkpR.js";
5
+ import { a as storeDir, c as LoomCompiler, f as PackageConfig, i as servicePackage, l as ignoredDirs, n as installedServices, o as workspaceRoot, p as LoomConfig, r as removeService, s as DocumentSource, t as addService } from "./LoomStore-BGlpRj6W.js";
6
+ import { t as layer } from "./NodeServices-CtEw3D6F.js";
8
7
  import { existsSync, readFileSync, writeFileSync } from "node:fs";
9
- import * as OS from "node:os";
10
- import * as Path from "node:path";
11
8
  import { dirname, relative, resolve } from "node:path";
12
- import * as NodeUrl from "node:url";
13
- import * as readline from "node:readline";
14
9
  //#region ../../node_modules/effect/dist/unstable/cli/CliError.js
15
10
  /**
16
11
  * Defines structured errors for the unstable CLI parser and runner.
@@ -28,7 +23,7 @@ import * as readline from "node:readline";
28
23
  * @category type IDs
29
24
  * @since 4.0.0
30
25
  */
31
- var TypeId$4 = "~effect/cli/CliError";
26
+ var TypeId$3 = "~effect/cli/CliError";
32
27
  /**
33
28
  * Type guard to check if a value is a CLI error.
34
29
  *
@@ -59,7 +54,7 @@ var TypeId$4 = "~effect/cli/CliError";
59
54
  * @category guards
60
55
  * @since 4.0.0
61
56
  */
62
- var isCliError = (u) => hasProperty(u, TypeId$4);
57
+ var isCliError = (u) => hasProperty(u, TypeId$3);
63
58
  /**
64
59
  * Error thrown when an unrecognized option is encountered.
65
60
  *
@@ -93,7 +88,7 @@ var isCliError = (u) => hasProperty(u, TypeId$4);
93
88
  * @category models
94
89
  * @since 4.0.0
95
90
  */
96
- var UnrecognizedOption = class extends ErrorClass(`${TypeId$4}/UnrecognizedOption`)({
91
+ var UnrecognizedOption = class extends ErrorClass(`${TypeId$3}/UnrecognizedOption`)({
97
92
  _tag: /*#__PURE__*/ tag("UnrecognizedOption"),
98
93
  option: String$1,
99
94
  command: /*#__PURE__*/ optional$3(/*#__PURE__*/ ArraySchema(String$1)),
@@ -104,7 +99,7 @@ var UnrecognizedOption = class extends ErrorClass(`${TypeId$4}/UnrecognizedOptio
104
99
  *
105
100
  * @since 4.0.0
106
101
  */
107
- [TypeId$4] = TypeId$4;
102
+ [TypeId$3] = TypeId$3;
108
103
  /**
109
104
  * Formats the unrecognized option with command context and suggestions.
110
105
  *
@@ -137,7 +132,7 @@ var UnrecognizedOption = class extends ErrorClass(`${TypeId$4}/UnrecognizedOptio
137
132
  * @category models
138
133
  * @since 4.0.0
139
134
  */
140
- var DuplicateOption = class extends ErrorClass(`${TypeId$4}/DuplicateOption`)({
135
+ var DuplicateOption = class extends ErrorClass(`${TypeId$3}/DuplicateOption`)({
141
136
  _tag: /*#__PURE__*/ tag("DuplicateOption"),
142
137
  option: String$1,
143
138
  parentCommand: String$1,
@@ -148,7 +143,7 @@ var DuplicateOption = class extends ErrorClass(`${TypeId$4}/DuplicateOption`)({
148
143
  *
149
144
  * @since 4.0.0
150
145
  */
151
- [TypeId$4] = TypeId$4;
146
+ [TypeId$3] = TypeId$3;
152
147
  /**
153
148
  * Explains which parent and child commands define the duplicate option.
154
149
  *
@@ -188,7 +183,7 @@ var DuplicateOption = class extends ErrorClass(`${TypeId$4}/DuplicateOption`)({
188
183
  * @category models
189
184
  * @since 4.0.0
190
185
  */
191
- var MissingOption = class extends ErrorClass(`${TypeId$4}/MissingOption`)({
186
+ var MissingOption = class extends ErrorClass(`${TypeId$3}/MissingOption`)({
192
187
  _tag: /*#__PURE__*/ tag("MissingOption"),
193
188
  option: String$1
194
189
  }) {
@@ -197,7 +192,7 @@ var MissingOption = class extends ErrorClass(`${TypeId$4}/MissingOption`)({
197
192
  *
198
193
  * @since 4.0.0
199
194
  */
200
- [TypeId$4] = TypeId$4;
195
+ [TypeId$3] = TypeId$3;
201
196
  /**
202
197
  * Formats the missing required flag for display.
203
198
  *
@@ -236,7 +231,7 @@ var MissingOption = class extends ErrorClass(`${TypeId$4}/MissingOption`)({
236
231
  * @category models
237
232
  * @since 4.0.0
238
233
  */
239
- var MissingArgument = class extends ErrorClass(`${TypeId$4}/MissingArgument`)({
234
+ var MissingArgument = class extends ErrorClass(`${TypeId$3}/MissingArgument`)({
240
235
  _tag: /*#__PURE__*/ tag("MissingArgument"),
241
236
  argument: String$1
242
237
  }) {
@@ -245,7 +240,7 @@ var MissingArgument = class extends ErrorClass(`${TypeId$4}/MissingArgument`)({
245
240
  *
246
241
  * @since 4.0.0
247
242
  */
248
- [TypeId$4] = TypeId$4;
243
+ [TypeId$3] = TypeId$3;
249
244
  /**
250
245
  * Formats the missing required positional argument for display.
251
246
  *
@@ -289,7 +284,7 @@ var MissingArgument = class extends ErrorClass(`${TypeId$4}/MissingArgument`)({
289
284
  * @category models
290
285
  * @since 4.0.0
291
286
  */
292
- var InvalidValue = class extends ErrorClass(`${TypeId$4}/InvalidValue`)({
287
+ var InvalidValue = class extends ErrorClass(`${TypeId$3}/InvalidValue`)({
293
288
  _tag: /*#__PURE__*/ tag("InvalidValue"),
294
289
  option: String$1,
295
290
  value: String$1,
@@ -301,7 +296,7 @@ var InvalidValue = class extends ErrorClass(`${TypeId$4}/InvalidValue`)({
301
296
  *
302
297
  * @since 4.0.0
303
298
  */
304
- [TypeId$4] = TypeId$4;
299
+ [TypeId$3] = TypeId$3;
305
300
  /**
306
301
  * Formats the invalid flag or argument value with the expected input.
307
302
  *
@@ -348,7 +343,7 @@ var InvalidValue = class extends ErrorClass(`${TypeId$4}/InvalidValue`)({
348
343
  * @category models
349
344
  * @since 4.0.0
350
345
  */
351
- var UnknownSubcommand = class extends ErrorClass(`${TypeId$4}/UnknownSubcommand`)({
346
+ var UnknownSubcommand = class extends ErrorClass(`${TypeId$3}/UnknownSubcommand`)({
352
347
  _tag: /*#__PURE__*/ tag("UnknownSubcommand"),
353
348
  subcommand: String$1,
354
349
  parent: /*#__PURE__*/ optional$3(/*#__PURE__*/ ArraySchema(String$1)),
@@ -359,7 +354,7 @@ var UnknownSubcommand = class extends ErrorClass(`${TypeId$4}/UnknownSubcommand`
359
354
  *
360
355
  * @since 4.0.0
361
356
  */
362
- [TypeId$4] = TypeId$4;
357
+ [TypeId$3] = TypeId$3;
363
358
  /**
364
359
  * Formats the unknown subcommand with parent command context and suggestions.
365
360
  *
@@ -406,7 +401,7 @@ var UnknownSubcommand = class extends ErrorClass(`${TypeId$4}/UnknownSubcommand`
406
401
  * @category models
407
402
  * @since 4.0.0
408
403
  */
409
- var UserError = class extends ErrorClass(`${TypeId$4}/UserError`)({
404
+ var UserError = class extends ErrorClass(`${TypeId$3}/UserError`)({
410
405
  _tag: /*#__PURE__*/ tag("UserError"),
411
406
  cause: /*#__PURE__*/ Defect()
412
407
  }) {
@@ -415,7 +410,7 @@ var UserError = class extends ErrorClass(`${TypeId$4}/UserError`)({
415
410
  *
416
411
  * @since 4.0.0
417
412
  */
418
- [TypeId$4] = TypeId$4;
413
+ [TypeId$3] = TypeId$3;
419
414
  };
420
415
  /**
421
416
  * Schema for concrete CLI errors that can be reported together with help output.
@@ -449,12 +444,12 @@ var NonShowHelpErrors = /*#__PURE__*/ Union([
449
444
  * @category models
450
445
  * @since 4.0.0
451
446
  */
452
- var ShowHelp = class extends ErrorClass(`${TypeId$4}/ShowHelp`)({
447
+ var ShowHelp = class extends ErrorClass(`${TypeId$3}/ShowHelp`)({
453
448
  _tag: /*#__PURE__*/ tag("ShowHelp"),
454
449
  commandPath: /*#__PURE__*/ ArraySchema(String$1),
455
450
  errors: /*#__PURE__*/ ArraySchema(NonShowHelpErrors)
456
451
  }) {
457
- [TypeId$4] = TypeId$4;
452
+ [TypeId$3] = TypeId$3;
458
453
  [errorExitCode] = this.errors.length ? 1 : 0;
459
454
  [errorReported] = false;
460
455
  get message() {
@@ -4823,14 +4818,14 @@ var require_toml = /* @__PURE__ */ __commonJSMin(((exports, module) => {
4823
4818
  }));
4824
4819
  require_ini();
4825
4820
  require_toml();
4826
- var Proto$3 = { ["~effect/cli/Primitive"]: { _A: identity } };
4821
+ var Proto$2 = { ["~effect/cli/Primitive"]: { _A: identity } };
4827
4822
  /** @internal */
4828
4823
  var isTrueValue = /*#__PURE__*/ is(TrueValues);
4829
4824
  /** @internal */
4830
4825
  var isFalseValue = /*#__PURE__*/ is(FalseValues);
4831
4826
  /** @internal */
4832
4827
  var isBoolean = (p) => p._tag === "Boolean";
4833
- var makePrimitive = (tag, parse) => Object.assign(Object.create(Proto$3), {
4828
+ var makePrimitive = (tag, parse) => Object.assign(Object.create(Proto$2), {
4834
4829
  _tag: tag,
4835
4830
  parse
4836
4831
  });
@@ -4873,6 +4868,31 @@ var makeSchemaPrimitive = (tag, schema) => {
4873
4868
  */
4874
4869
  var boolean$2 = /*#__PURE__*/ makeSchemaPrimitive("Boolean", Boolean);
4875
4870
  /**
4871
+ * Creates a primitive that parses integer numbers from string input.
4872
+ *
4873
+ * **Example** (Parsing integer values)
4874
+ *
4875
+ * ```ts
4876
+ * import { Effect } from "effect"
4877
+ * import { Primitive } from "effect/unstable/cli"
4878
+ *
4879
+ * const parseInteger = Effect.gen(function*() {
4880
+ * const result1 = yield* Primitive.integer.parse("42")
4881
+ * console.log(result1) // 42
4882
+ *
4883
+ * const result2 = yield* Primitive.integer.parse("-123")
4884
+ * console.log(result2) // -123
4885
+ *
4886
+ * const result3 = yield* Primitive.integer.parse("0")
4887
+ * console.log(result3) // 0
4888
+ * })
4889
+ * ```
4890
+ *
4891
+ * @category constructors
4892
+ * @since 4.0.0
4893
+ */
4894
+ var integer$2 = /*#__PURE__*/ makeSchemaPrimitive("Integer", Int);
4895
+ /**
4876
4896
  * Creates a primitive that accepts any string value without validation.
4877
4897
  *
4878
4898
  * **Example** (Parsing string values)
@@ -4968,7 +4988,7 @@ var choice$2 = (choices) => {
4968
4988
  */
4969
4989
  var path$1 = (pathType, mustExist) => makePrimitive("Path", fnUntraced(function* (value) {
4970
4990
  const fs = yield* FileSystem;
4971
- const path = yield* Path$1;
4991
+ const path = yield* Path;
4972
4992
  const absolutePath = path.isAbsolute(value) ? value : path.resolve(value);
4973
4993
  const exists = yield* mapError(fs.exists(absolutePath), (error) => `Failed to check path existence: ${error.message}`);
4974
4994
  if (mustExist === true && !exists) return yield* fail(`Path does not exist: ${absolutePath}`);
@@ -5118,7 +5138,7 @@ var eraseLines = (rows) => {
5118
5138
  *
5119
5139
  * @since 4.0.0
5120
5140
  */
5121
- var TypeId$3 = "~effect/cli/Prompt";
5141
+ var TypeId$2 = "~effect/cli/Prompt";
5122
5142
  var defaultFigures = {
5123
5143
  arrowUp: "↑",
5124
5144
  arrowDown: "↓",
@@ -5219,7 +5239,7 @@ var proto = {
5219
5239
  return run$1(this);
5220
5240
  }
5221
5241
  }),
5222
- [TypeId$3]: { _Output: (_) => _ }
5242
+ [TypeId$2]: { _Output: (_) => _ }
5223
5243
  };
5224
5244
  var runWithInput = (prompt, terminal, input) => suspend(() => {
5225
5245
  const op = prompt;
@@ -5473,7 +5493,7 @@ var basePrompt = (options, type) => {
5473
5493
  };
5474
5494
  //#endregion
5475
5495
  //#region ../../node_modules/effect/dist/unstable/cli/Param.js
5476
- var TypeId$2 = "~effect/cli/Param";
5496
+ var TypeId$1 = "~effect/cli/Param";
5477
5497
  /**
5478
5498
  * Defines the kind discriminator for positional argument parameters.
5479
5499
  *
@@ -5503,8 +5523,8 @@ var argumentKind = "argument";
5503
5523
  * @since 4.0.0
5504
5524
  */
5505
5525
  var flagKind = "flag";
5506
- var Proto$2 = {
5507
- [TypeId$2]: { _A: identity },
5526
+ var Proto$1 = {
5527
+ [TypeId$1]: { _A: identity },
5508
5528
  pipe() {
5509
5529
  return pipeArguments(this, arguments);
5510
5530
  }
@@ -5527,7 +5547,7 @@ var Proto$2 = {
5527
5547
  * @category refinements
5528
5548
  * @since 4.0.0
5529
5549
  */
5530
- var isParam = (u) => hasProperty(u, TypeId$2);
5550
+ var isParam = (u) => hasProperty(u, TypeId$1);
5531
5551
  /**
5532
5552
  * Type guard to check if a Single param is a flag (not an argument).
5533
5553
  *
@@ -5548,7 +5568,7 @@ var isFlagParam = (single) => single.kind === "flag";
5548
5568
  */
5549
5569
  var makeSingle = (params) => {
5550
5570
  const parse = (args) => params.kind === "argument" ? parsePositional(params.name, params.primitiveType, args) : parseFlag(params.name, params.primitiveType, args);
5551
- return Object.assign(Object.create(Proto$2), {
5571
+ return Object.assign(Object.create(Proto$1), {
5552
5572
  _tag: "Single",
5553
5573
  ...params,
5554
5574
  description: params.description ?? none(),
@@ -5609,6 +5629,31 @@ var boolean$1 = (kind, name) => makeSingle({
5609
5629
  kind
5610
5630
  });
5611
5631
  /**
5632
+ * Creates an integer parameter.
5633
+ *
5634
+ * **Example** (Creating integer parameters)
5635
+ *
5636
+ * ```ts
5637
+ * import { Param } from "effect/unstable/cli"
5638
+ *
5639
+ * // Create an integer flag
5640
+ * const portFlag = Param.integer(Param.flagKind, "port")
5641
+ *
5642
+ * // Create an integer argument
5643
+ * const countArg = Param.integer(Param.argumentKind, "count")
5644
+ *
5645
+ * // Usage in CLI: --port 8080 or as positional argument: 42
5646
+ * ```
5647
+ *
5648
+ * @category constructors
5649
+ * @since 4.0.0
5650
+ */
5651
+ var integer$1 = (kind, name) => makeSingle({
5652
+ name,
5653
+ primitiveType: integer$2,
5654
+ kind
5655
+ });
5656
+ /**
5612
5657
  * Constructs command-line params that represent a choice between several
5613
5658
  * inputs. The input will be mapped to it's associated value during parsing.
5614
5659
  *
@@ -5811,7 +5856,7 @@ var withDescription$1 = /*#__PURE__*/ dual(2, (self, description) => {
5811
5856
  */
5812
5857
  var map$1 = /*#__PURE__*/ dual(2, (self, f) => {
5813
5858
  const parse = (args) => map$2(self.parse(args), ([operands, value]) => [operands, f(value)]);
5814
- return Object.assign(Object.create(Proto$2), {
5859
+ return Object.assign(Object.create(Proto$1), {
5815
5860
  _tag: "Map",
5816
5861
  kind: self.kind,
5817
5862
  param: self,
@@ -5819,7 +5864,7 @@ var map$1 = /*#__PURE__*/ dual(2, (self, f) => {
5819
5864
  parse
5820
5865
  });
5821
5866
  });
5822
- var transform = (self, f) => Object.assign(Object.create(Proto$2), {
5867
+ var transform = (self, f) => Object.assign(Object.create(Proto$1), {
5823
5868
  _tag: "Transform",
5824
5869
  kind: self.kind,
5825
5870
  param: self,
@@ -5827,6 +5872,35 @@ var transform = (self, f) => Object.assign(Object.create(Proto$2), {
5827
5872
  parse: f(self.parse)
5828
5873
  });
5829
5874
  /**
5875
+ * Transforms the parsed value of an option using an effectful mapping function.
5876
+ *
5877
+ * **Example** (Mapping parsed values effectfully)
5878
+ *
5879
+ * ```ts
5880
+ * import { Effect } from "effect"
5881
+ * import { CliError, Param } from "effect/unstable/cli"
5882
+ *
5883
+ * const validatedEmail = Param.string(Param.flagKind, "email").pipe(
5884
+ * Param.mapEffect((email) =>
5885
+ * email.includes("@")
5886
+ * ? Effect.succeed(email)
5887
+ * : Effect.fail(
5888
+ * new CliError.InvalidValue({
5889
+ * option: "email",
5890
+ * value: email,
5891
+ * expected: "valid email format",
5892
+ * kind: "flag"
5893
+ * })
5894
+ * )
5895
+ * )
5896
+ * )
5897
+ * ```
5898
+ *
5899
+ * @category combinators
5900
+ * @since 4.0.0
5901
+ */
5902
+ var mapEffect = /*#__PURE__*/ dual(2, (self, f) => transform(self, (parse) => (args) => flatMap(parse(args), ([leftover, a]) => f(a).pipe(map$2((b) => [leftover, b])))));
5903
+ /**
5830
5904
  * Makes a flag or positional argument optional.
5831
5905
  *
5832
5906
  * **Details**
@@ -5858,7 +5932,7 @@ var optional$2 = (param) => {
5858
5932
  MissingArgument: () => succeed([args.arguments, none()])
5859
5933
  }));
5860
5934
  });
5861
- return Object.assign(Object.create(Proto$2), {
5935
+ return Object.assign(Object.create(Proto$1), {
5862
5936
  _tag: "Optional",
5863
5937
  kind: param.kind,
5864
5938
  param,
@@ -5866,6 +5940,42 @@ var optional$2 = (param) => {
5866
5940
  });
5867
5941
  };
5868
5942
  /**
5943
+ * Makes a flag or positional argument optional by supplying a fallback value.
5944
+ *
5945
+ * **Details**
5946
+ *
5947
+ * The fallback may be a pure value or an effect. It is used only when the
5948
+ * parameter is absent; provided values are parsed normally.
5949
+ *
5950
+ * **Example** (Providing default values)
5951
+ *
5952
+ * ```ts
5953
+ * import { Param } from "effect/unstable/cli"
5954
+ *
5955
+ * // Using the pipe operator to make an option optional
5956
+ * const port = Param.integer(Param.flagKind, "port").pipe(
5957
+ * Param.withDefault(8080)
5958
+ * )
5959
+ *
5960
+ * // Can also be used with other combinators
5961
+ * const verbose = Param.boolean(Param.flagKind, "verbose").pipe(
5962
+ * Param.withAlias("-v"),
5963
+ * Param.withDescription("Enable verbose output"),
5964
+ * Param.withDefault(false)
5965
+ * )
5966
+ * ```
5967
+ *
5968
+ * @category combinators
5969
+ * @since 4.0.0
5970
+ */
5971
+ var withDefault$1 = /*#__PURE__*/ dual(2, (self, defaultValue) => {
5972
+ if (!isEffect(defaultValue)) return map$1(optional$2(self), getOrElse(() => defaultValue));
5973
+ return mapEffect(optional$2(self), match$2({
5974
+ onNone: () => defaultValue,
5975
+ onSome: succeed
5976
+ }));
5977
+ });
5978
+ /**
5869
5979
  * Creates a variadic parameter that can be specified multiple times.
5870
5980
  *
5871
5981
  * **Details**
@@ -5904,7 +6014,7 @@ var variadic = (self, options) => {
5904
6014
  if (single.kind === "argument") return parsePositionalVariadic(self, single, args, options);
5905
6015
  else return parseOptionVariadic(self, single, args, options);
5906
6016
  };
5907
- return Object.assign(Object.create(Proto$2), {
6017
+ return Object.assign(Object.create(Proto$1), {
5908
6018
  _tag: "Variadic",
5909
6019
  kind: self.kind,
5910
6020
  param: self,
@@ -6879,6 +6989,22 @@ var generate = (executableName, shell, descriptor) => {
6879
6989
  */
6880
6990
  var boolean = (name) => boolean$1(flagKind, name);
6881
6991
  /**
6992
+ * Creates an integer flag that accepts whole number input.
6993
+ *
6994
+ * **Example** (Creating integer flags)
6995
+ *
6996
+ * ```ts
6997
+ * import { Flag } from "effect/unstable/cli"
6998
+ *
6999
+ * const portFlag = Flag.integer("port")
7000
+ * // Usage: --port 8080
7001
+ * ```
7002
+ *
7003
+ * @category constructors
7004
+ * @since 4.0.0
7005
+ */
7006
+ var integer = (name) => integer$1(flagKind, name);
7007
+ /**
6882
7008
  * Constructs option parameters that represent a choice between several inputs.
6883
7009
  * Each tuple maps a string flag value to an associated typed value.
6884
7010
  *
@@ -7024,6 +7150,29 @@ var withMetavar = /*#__PURE__*/ dual(2, (self, metavar) => withMetavar$1(self, m
7024
7150
  */
7025
7151
  var optional = (param) => optional$2(param);
7026
7152
  /**
7153
+ * Provides a default value for a flag when it's not specified.
7154
+ *
7155
+ * **Example** (Providing default values)
7156
+ *
7157
+ * ```ts
7158
+ * import { Flag } from "effect/unstable/cli"
7159
+ *
7160
+ * const portFlag = Flag.integer("port").pipe(
7161
+ * Flag.withDefault(8080)
7162
+ * )
7163
+ * // If --port is not provided, defaults to 8080
7164
+ *
7165
+ * const hostFlag = Flag.string("host").pipe(
7166
+ * Flag.withDefault("localhost")
7167
+ * )
7168
+ * // If --host is not provided, defaults to "localhost"
7169
+ * ```
7170
+ *
7171
+ * @category optionality
7172
+ * @since 4.0.0
7173
+ */
7174
+ var withDefault = withDefault$1;
7175
+ /**
7027
7176
  * Transforms the parsed value of a flag using a mapping function.
7028
7177
  *
7029
7178
  * **Example** (Mapping parsed values)
@@ -7174,13 +7323,13 @@ var reconstructTree = (tree, results) => {
7174
7323
  * Internal implementation details for CLI commands.
7175
7324
  * Public API is in ../Command.ts
7176
7325
  */
7177
- var TypeId$1 = "~effect/cli/Command";
7326
+ var TypeId = "~effect/cli/Command";
7178
7327
  /**
7179
7328
  * Casts a Command to its internal implementation.
7180
7329
  * For use by internal modules that need access to config, parse, handle, etc.
7181
7330
  */
7182
7331
  var toImpl = (self) => self;
7183
- var Proto$1 = { .../*#__PURE__*/ Prototype({
7332
+ var Proto = { .../*#__PURE__*/ Prototype({
7184
7333
  label: "Command",
7185
7334
  evaluate() {
7186
7335
  return toImpl(this).service;
@@ -7255,8 +7404,8 @@ var makeCommand = (options) => {
7255
7404
  ...examples.length > 0 && { examples }
7256
7405
  };
7257
7406
  };
7258
- return Object.assign(Object.create(Proto$1), {
7259
- [TypeId$1]: TypeId$1,
7407
+ return Object.assign(Object.create(Proto), {
7408
+ [TypeId]: TypeId,
7260
7409
  name: options.name,
7261
7410
  examples: options.examples ?? [],
7262
7411
  annotations,
@@ -8317,7 +8466,7 @@ var scanCommandLevel = (tokens, context) => {
8317
8466
  * @category guards
8318
8467
  * @since 4.0.0
8319
8468
  */
8320
- var isCommand = (u) => hasProperty(u, TypeId$1);
8469
+ var isCommand = (u) => hasProperty(u, TypeId);
8321
8470
  /**
8322
8471
  * Creates a `Command` from a name, an optional configuration, and an optional
8323
8472
  * handler.
@@ -8375,7 +8524,7 @@ var isCommand = (u) => hasProperty(u, TypeId$1);
8375
8524
  * @category constructors
8376
8525
  * @since 4.0.0
8377
8526
  */
8378
- var make$5 = (name, config, handler) => {
8527
+ var make = (name, config, handler) => {
8379
8528
  return makeCommand({
8380
8529
  name,
8381
8530
  config: parseConfig(config ?? {}),
@@ -8668,1483 +8817,12 @@ var runWith = (command, config) => {
8668
8817
  program = provideService(program, LogLevel, logLevel);
8669
8818
  const services = match$2(logLevel, {
8670
8819
  onNone: () => empty(),
8671
- onSome: (level) => make$6(MinimumLogLevel, level)
8820
+ onSome: (level) => make$1(MinimumLogLevel, level)
8672
8821
  });
8673
8822
  yield* provideContext(program, services);
8674
8823
  }, catchFilter((error) => isCliError(error) && error._tag === "ShowHelp" ? succeed$1(error) : fail$1(error), (error) => andThen(showHelp(command, error), fail(error))), catchFilter((e) => isQuitError(e) ? succeed$1(e) : fail$1(e), (_) => interrupt));
8675
8824
  };
8676
8825
  //#endregion
8677
- //#region ../../node_modules/effect/dist/unstable/process/ChildProcessSpawner.js
8678
- /**
8679
- * Service boundary for starting and controlling child processes.
8680
- *
8681
- * `ChildProcessSpawner` is the service used by `ChildProcess` commands to start
8682
- * operating-system processes. A spawner turns a command description into a
8683
- * handle that can write to stdin, read stdout and stderr, wait for exit, kill
8684
- * the process, and manage whether the process keeps its parent alive. Platform
8685
- * backends implement this service, while most application code uses the higher
8686
- * level `ChildProcess` module.
8687
- *
8688
- * @since 4.0.0
8689
- */
8690
- /**
8691
- * Constructs branded child process `ExitCode` values.
8692
- *
8693
- * @category constructors
8694
- * @since 4.0.0
8695
- */
8696
- var ExitCode = /*#__PURE__*/ nominal();
8697
- /**
8698
- * Constructs branded child process `ProcessId` values.
8699
- *
8700
- * @category constructors
8701
- * @since 4.0.0
8702
- */
8703
- var ProcessId = /*#__PURE__*/ nominal();
8704
- var HandleTypeId = "~effect/ChildProcessSpawner/ChildProcessHandle";
8705
- var HandleProto = {
8706
- [HandleTypeId]: HandleTypeId,
8707
- ...BaseProto,
8708
- toJSON() {
8709
- return {
8710
- _id: "ChildProcessHandle",
8711
- pid: this.pid
8712
- };
8713
- }
8714
- };
8715
- /**
8716
- * Constructs a new `ChildProcessHandle`.
8717
- *
8718
- * @category constructors
8719
- * @since 4.0.0
8720
- */
8721
- var makeHandle = (params) => Object.assign(Object.create(HandleProto), params);
8722
- /**
8723
- * Creates a `ChildProcessSpawner` service from a `spawn` function, deriving
8724
- * helpers for exit codes and output collection from that implementation.
8725
- *
8726
- * @category models
8727
- * @since 4.0.0
8728
- */
8729
- var make$4 = (spawn) => {
8730
- const streamString = (command, options) => spawn(command).pipe(map$2((handle) => decodeText(options?.includeStderr === true ? handle.all : handle.stdout)), unwrap);
8731
- const streamLines = (command, options) => splitLines(streamString(command, options));
8732
- return ChildProcessSpawner.of({
8733
- spawn,
8734
- exitCode: (command) => scoped(flatMap(spawn(command), (handle) => handle.exitCode)),
8735
- streamString,
8736
- streamLines,
8737
- lines: (command, options) => runCollect(streamLines(command, options)),
8738
- string: (command, options) => mkString(streamString(command, options))
8739
- });
8740
- };
8741
- /**
8742
- * Service tag for child process spawning.
8743
- *
8744
- * @category services
8745
- * @since 4.0.0
8746
- */
8747
- var ChildProcessSpawner = class extends Service()("effect/process/ChildProcessSpawner") {};
8748
- //#endregion
8749
- //#region ../../node_modules/effect/dist/unstable/process/ChildProcess.js
8750
- /**
8751
- * Describes child processes before they are started.
8752
- *
8753
- * A `Command` stores the executable, arguments, environment, standard streams,
8754
- * working directory, and other process options. Commands can also be piped
8755
- * together. A command is an `Effect`; running it asks the
8756
- * `ChildProcessSpawner` service to start the process and returns a
8757
- * `ChildProcessHandle`.
8758
- *
8759
- * @since 4.0.0
8760
- */
8761
- var TypeId = "~effect/unstable/process/ChildProcess";
8762
- var Proto = {
8763
- .../*#__PURE__*/ Prototype({
8764
- label: "Command",
8765
- evaluate(fiber) {
8766
- return getUnsafe(fiber.context, ChildProcessSpawner).spawn(this);
8767
- }
8768
- }),
8769
- [TypeId]: TypeId
8770
- };
8771
- var makeStandardCommand = (command, args, options) => Object.assign(Object.create(Proto), {
8772
- _tag: "StandardCommand",
8773
- command,
8774
- args,
8775
- options
8776
- });
8777
- /**
8778
- * Create a command from a template literal, options + template, or array form.
8779
- *
8780
- * **Details**
8781
- *
8782
- * This function supports three calling conventions:
8783
- * 1. Template literal: `make\`npm run build\``
8784
- * 2. Options + template literal: `make({ cwd: "/app" })\`npm run build\``
8785
- * 3. Array form: `make("npm", ["run", "build"], options?)`
8786
- *
8787
- * Template literals are not parsed until execution time, allowing parsing
8788
- * errors to flow through Effect's error channel.
8789
- *
8790
- * **Example** (Creating commands)
8791
- *
8792
- * ```ts
8793
- * import { ChildProcess } from "effect/unstable/process"
8794
- *
8795
- * // Template literal form
8796
- * const cmd1 = ChildProcess.make`echo "hello"`
8797
- *
8798
- * // With options
8799
- * const cmd2 = ChildProcess.make({ cwd: "/tmp" })`ls -la`
8800
- *
8801
- * // Array form
8802
- * const cmd3 = ChildProcess.make("git", ["status"])
8803
- * ```
8804
- *
8805
- * @category constructors
8806
- * @since 4.0.0
8807
- */
8808
- var make$3 = function make(...args) {
8809
- if (isTemplateString(args[0])) {
8810
- const [templates, ...expressions] = args;
8811
- const tokens = parseTemplates(templates, expressions);
8812
- return makeStandardCommand(tokens[0] ?? "", tokens.slice(1), {});
8813
- }
8814
- if (typeof args[0] === "object" && !Array.isArray(args[0]) && !isTemplateString(args[0])) {
8815
- const options = args[0];
8816
- return function(templates, ...expressions) {
8817
- const tokens = parseTemplates(templates, expressions);
8818
- return makeStandardCommand(tokens[0] ?? "", tokens.slice(1), options);
8819
- };
8820
- }
8821
- if (typeof args[0] === "string" && !Array.isArray(args[1])) {
8822
- const [command, options = {}] = args;
8823
- return makeStandardCommand(command, [], options);
8824
- }
8825
- const [command, cmdArgs = [], options = {}] = args;
8826
- return makeStandardCommand(command, cmdArgs, options);
8827
- };
8828
- var isTemplateString = (u) => Array.isArray(u) && "raw" in u && Array.isArray(u.raw);
8829
- /**
8830
- * Parses an fd name like "fd3" to its numeric index.
8831
- * Returns undefined if the name is invalid.
8832
- *
8833
- * @category converting
8834
- * @since 4.0.0
8835
- */
8836
- var parseFdName = (name) => {
8837
- const match = /^fd(\d+)$/.exec(name);
8838
- if (match === null) return void 0;
8839
- const fd = parseInt(match[1], 10);
8840
- return fd >= 3 ? fd : void 0;
8841
- };
8842
- /**
8843
- * Create an fd name from its numeric index.
8844
- *
8845
- * @category converting
8846
- * @since 4.0.0
8847
- */
8848
- var fdName = (fd) => `fd${fd}`;
8849
- var parseTemplates = (templates, expressions) => {
8850
- let tokens = [];
8851
- for (const [index, template] of templates.entries()) tokens = parseTemplate(templates, expressions, tokens, template, index);
8852
- return tokens;
8853
- };
8854
- var parseTemplate = (templates, expressions, prevTokens, template, index) => {
8855
- const rawTemplate = templates.raw[index];
8856
- if (rawTemplate === void 0) throw new Error(`Invalid backslash sequence: ${templates.raw[index]}`);
8857
- const { hasLeadingWhitespace, hasTrailingWhitespace, tokens } = splitByWhitespaces(template, rawTemplate);
8858
- const nextTokens = concatTokens(prevTokens, tokens, hasLeadingWhitespace);
8859
- if (index === expressions.length) return nextTokens;
8860
- const expression = expressions[index];
8861
- return concatTokens(nextTokens, Array.isArray(expression) ? expression.map((expression) => parseExpression(expression)) : [parseExpression(expression)], hasTrailingWhitespace);
8862
- };
8863
- /**
8864
- * Convert valid expressions defined in a template string command (i.e. using
8865
- * `${expression}` into strings.
8866
- */
8867
- var parseExpression = (expression) => {
8868
- if (typeof expression === "string") return expression;
8869
- return String(expression);
8870
- };
8871
- var DELIMITERS = /*#__PURE__*/ new Set([
8872
- " ",
8873
- " ",
8874
- "\r",
8875
- "\n"
8876
- ]);
8877
- /**
8878
- * Number of characters in backslash escape sequences: \0 \xXX or \uXXXX
8879
- * \cX is allowed in RegExps but not in strings
8880
- * Octal sequences are not allowed in strict mode
8881
- */
8882
- var ESCAPE_LENGTH = {
8883
- x: 3,
8884
- u: 5
8885
- };
8886
- /**
8887
- * Splits a template string by whitespace while also properly handling escape
8888
- * sequences.
8889
- *
8890
- * As an example, let's review the following valid commands:
8891
- *
8892
- * ```ts
8893
- * ChildProcess.exec`echo foo\n bar`
8894
- * // We should run `["echo", "foo\n", "bar"]`
8895
- *
8896
- * ChildProcess.exec`echo foo
8897
- * bar`
8898
- * // We should run `["echo", "foo", "bar]`
8899
- * ```
8900
- *
8901
- * The problem is that when we evaluate the template string for both of the above
8902
- * commands, we will end up with the same string "echo foo\n bar".
8903
- *
8904
- * What we really want is to include the escaped character in the arguments for
8905
- * the first command, since it was written explicitly by the user.
8906
- *
8907
- * This is why also having access to the raw template string is useful - in a
8908
- * template string, there are two representations of the same string:
8909
- * 1. `template` - The processed string (escape sequences are evaluated).
8910
- * 2. `template.raw` - The raw string (escape sequences are literal).
8911
- */
8912
- var splitByWhitespaces = (template, rawTemplate) => {
8913
- if (rawTemplate.length === 0) return {
8914
- tokens: [],
8915
- hasLeadingWhitespace: false,
8916
- hasTrailingWhitespace: false
8917
- };
8918
- const hasLeadingWhitespace = DELIMITERS.has(rawTemplate[0]);
8919
- const tokens = [];
8920
- let templateCursor = 0;
8921
- for (let templateIndex = 0, rawIndex = 0; templateIndex < template.length; templateIndex += 1, rawIndex += 1) {
8922
- const rawCharacter = rawTemplate[rawIndex];
8923
- if (DELIMITERS.has(rawCharacter)) {
8924
- if (templateCursor !== templateIndex) tokens.push(template.slice(templateCursor, templateIndex));
8925
- templateCursor = templateIndex + 1;
8926
- } else if (rawCharacter === "\\") {
8927
- const nextRawCharacter = rawTemplate[rawIndex + 1];
8928
- if (nextRawCharacter === "\n") {
8929
- templateIndex -= 1;
8930
- rawIndex += 1;
8931
- } else if (nextRawCharacter === "u" && rawTemplate[rawIndex + 2] === "{") rawIndex = rawTemplate.indexOf("}", rawIndex + 3);
8932
- else rawIndex += ESCAPE_LENGTH[nextRawCharacter] ?? 1;
8933
- }
8934
- }
8935
- const hasTrailingWhitespace = templateCursor === template.length;
8936
- if (!hasTrailingWhitespace) tokens.push(template.slice(templateCursor));
8937
- return {
8938
- tokens,
8939
- hasLeadingWhitespace,
8940
- hasTrailingWhitespace
8941
- };
8942
- };
8943
- /**
8944
- * Concatenates two separate sets of string tokens together.
8945
- *
8946
- * If either set is empty or `isSeparated=false`, the last element of `prevTokens`
8947
- * and the first element of `nextTokens` will be joined into a single token.
8948
- */
8949
- var concatTokens = (prevTokens, nextTokens, isSeparated) => isSeparated || prevTokens.length === 0 || nextTokens.length === 0 ? [...prevTokens, ...nextTokens] : [
8950
- ...prevTokens.slice(0, -1),
8951
- `${prevTokens.at(-1)}${nextTokens.at(0)}`,
8952
- ...nextTokens.slice(1)
8953
- ];
8954
- //#endregion
8955
- //#region ../../node_modules/@effect/platform-node-shared/dist/internal/utils.js
8956
- /** @internal */
8957
- var handleErrnoException = (module, method) => (err, [path]) => {
8958
- let reason = "Unknown";
8959
- switch (err.code) {
8960
- case "ENOENT":
8961
- reason = "NotFound";
8962
- break;
8963
- case "EACCES":
8964
- reason = "PermissionDenied";
8965
- break;
8966
- case "EEXIST":
8967
- reason = "AlreadyExists";
8968
- break;
8969
- case "EISDIR":
8970
- reason = "BadResource";
8971
- break;
8972
- case "ENOTDIR":
8973
- reason = "BadResource";
8974
- break;
8975
- case "EBUSY":
8976
- reason = "Busy";
8977
- break;
8978
- case "ELOOP":
8979
- reason = "BadResource";
8980
- break;
8981
- }
8982
- return systemError({
8983
- _tag: reason,
8984
- module,
8985
- method,
8986
- pathOrDescriptor: path,
8987
- syscall: err.syscall,
8988
- cause: err
8989
- });
8990
- };
8991
- //#endregion
8992
- //#region ../../node_modules/@effect/platform-node-shared/dist/NodeSink.js
8993
- /**
8994
- * Creates a `Sink` that writes chunks to a Node writable stream, respecting
8995
- * backpressure, mapping writable errors with `onError`, and ending the stream
8996
- * on completion unless `endOnDone` is `false`.
8997
- *
8998
- * @category constructors
8999
- * @since 4.0.0
9000
- */
9001
- var fromWritable = (options) => fromChannel(mapDone(fromWritableChannel(options), (_) => [_]));
9002
- /**
9003
- * Creates a `Channel` that pulls chunks from upstream and writes them to a
9004
- * Node writable stream, respecting backpressure and optionally ending the
9005
- * writable when upstream is done.
9006
- *
9007
- * @category constructors
9008
- * @since 4.0.0
9009
- */
9010
- var fromWritableChannel = (options) => fromTransform((pull) => {
9011
- const writable = options.evaluate();
9012
- return succeed(pullIntoWritable({
9013
- ...options,
9014
- writable,
9015
- pull
9016
- }));
9017
- });
9018
- /**
9019
- * Writes Effect chunks into a Node writable stream.
9020
- *
9021
- * **When to use**
9022
- *
9023
- * Use to implement custom Node stream adapters that already have an upstream
9024
- * pull and need direct control over a writable stream.
9025
- *
9026
- * **Details**
9027
- *
9028
- * The loop waits for `drain` when needed, fails on writable errors, and ends
9029
- * the writable on upstream completion unless `endOnDone` is `false`.
9030
- *
9031
- * @category converting
9032
- * @since 4.0.0
9033
- */
9034
- var pullIntoWritable = (options) => options.pull.pipe(flatMap((chunk) => {
9035
- let i = 0;
9036
- return callback(function loop(resume) {
9037
- for (; i < chunk.length;) if (!options.writable.write(chunk[i++], options.encoding)) {
9038
- options.writable.once("drain", () => loop(resume));
9039
- return;
9040
- }
9041
- resume(void_);
9042
- });
9043
- }), forever({ disableYield: true }), raceFirst(callback((resume) => {
9044
- const onError = (error) => resume(fail(options.onError(error)));
9045
- options.writable.once("error", onError);
9046
- return sync(() => {
9047
- options.writable.off("error", onError);
9048
- });
9049
- })), options.endOnDone !== false ? catchDone((_) => {
9050
- if ("closed" in options.writable && options.writable.closed) return done(_);
9051
- return callback((resume) => {
9052
- options.writable.once("finish", () => resume(done(_)));
9053
- options.writable.end();
9054
- });
9055
- }) : identity);
9056
- //#endregion
9057
- //#region ../../node_modules/@effect/platform-node-shared/dist/NodeStream.js
9058
- /**
9059
- * Adapters between Node streams and Effect streams, channels, and readables.
9060
- *
9061
- * This module is the stream boundary for Node APIs. It wraps `Readable` and
9062
- * `Duplex` values as Effect `Stream`s and `Channel`s, pipes Effect streams
9063
- * through Node duplex streams, exposes an Effect `Stream` back to Node as a
9064
- * `Readable`, and collects readable payloads into strings, array buffers, or
9065
- * `Uint8Array`s with optional byte limits.
9066
- *
9067
- * @since 4.0.0
9068
- */
9069
- /**
9070
- * Converts a Node readable stream into an Effect `Stream`, reading chunks with
9071
- * an optional chunk size, mapping stream errors with `onError`, and destroying
9072
- * the readable on completion unless `closeOnDone` is `false`.
9073
- *
9074
- * @category constructors
9075
- * @since 4.0.0
9076
- */
9077
- var fromReadable = (options) => fromChannel$1(fromReadableChannel(options));
9078
- /**
9079
- * Creates a `Channel` that pulls chunks from a Node readable stream, mapping
9080
- * errors with `onError` and destroying the readable on completion unless
9081
- * `closeOnDone` is `false`.
9082
- *
9083
- * @category constructors
9084
- * @since 4.0.0
9085
- */
9086
- var fromReadableChannel = (options) => fromTransform((_, scope) => readableToPullUnsafe({
9087
- scope,
9088
- readable: options.evaluate(),
9089
- onError: options.onError ?? defaultOnError,
9090
- chunkSize: options.chunkSize,
9091
- closeOnDone: options.closeOnDone
9092
- }));
9093
- var readableToPullUnsafe = (options) => {
9094
- const readable = options.readable;
9095
- const closeOnDone = options.closeOnDone ?? true;
9096
- const exit = options.exit ?? make$7(void 0);
9097
- const latch = makeUnsafe(false);
9098
- function onReadable() {
9099
- latch.openUnsafe();
9100
- }
9101
- function onError(error) {
9102
- exit.current = fail$2(options.onError(error));
9103
- latch.openUnsafe();
9104
- }
9105
- function onEnd() {
9106
- exit.current = fail$2(Done());
9107
- latch.openUnsafe();
9108
- }
9109
- readable.on("readable", onReadable);
9110
- readable.once("error", onError);
9111
- readable.once("end", onEnd);
9112
- const pull = suspend(function loop() {
9113
- let item = options.readable.read(options.chunkSize);
9114
- if (item === null) {
9115
- if (exit.current) return exit.current;
9116
- if (readable.readableEnded) return fail(Done());
9117
- latch.closeUnsafe();
9118
- return flatMap(latch.await, loop);
9119
- }
9120
- const chunk = of(item);
9121
- while (true) {
9122
- item = options.readable.read(options.chunkSize);
9123
- if (item === null) break;
9124
- chunk.push(item);
9125
- }
9126
- return succeed(chunk);
9127
- });
9128
- return as(addFinalizer(options.scope, sync(() => {
9129
- readable.off("readable", onReadable);
9130
- readable.off("error", onError);
9131
- readable.off("end", onEnd);
9132
- if (closeOnDone && "closed" in options.readable && !options.readable.closed) options.readable.destroy();
9133
- })), pull);
9134
- };
9135
- var defaultOnError = (error) => new UnknownError(error);
9136
- //#endregion
9137
- //#region ../../node_modules/@effect/platform-node-shared/dist/NodeChildProcessSpawner.js
9138
- var toError = (error) => error instanceof globalThis.Error ? error : new globalThis.Error(String(error));
9139
- var toPlatformError = (method, error, command) => {
9140
- const { commands } = flattenCommand(command);
9141
- const commandStr = commands.reduce((acc, curr) => {
9142
- const cmd = `${curr.command} ${curr.args.join(" ")}`;
9143
- return acc.length === 0 ? cmd : `${acc} | ${cmd}`;
9144
- }, "");
9145
- return handleErrnoException("ChildProcess", method)(error, [commandStr]);
9146
- };
9147
- /**
9148
- * Layer that provides the `NodeChildProcessSpawner` implementation.
9149
- *
9150
- * @category layers
9151
- * @since 4.0.0
9152
- */
9153
- var layer$11 = /*#__PURE__*/ effect(ChildProcessSpawner, /* @__PURE__ */ gen(function* () {
9154
- const fs = yield* FileSystem;
9155
- const path = yield* Path$1;
9156
- const resolveWorkingDirectory = fnUntraced(function* (options) {
9157
- if (isUndefined(options.cwd)) return void 0;
9158
- yield* fs.access(options.cwd);
9159
- return path.resolve(options.cwd);
9160
- });
9161
- const resolveEnvironment = (options) => {
9162
- return options.extendEnv ? {
9163
- ...globalThis.process.env,
9164
- ...options.env
9165
- } : options.env;
9166
- };
9167
- const inputToStdioOption = (input) => isStream(input) ? "pipe" : input;
9168
- const outputToStdioOption = (input) => isSink(input) ? "pipe" : input;
9169
- const resolveStdinOption = (options) => {
9170
- const defaultConfig = {
9171
- stream: "pipe",
9172
- encoding: "utf-8",
9173
- endOnDone: true
9174
- };
9175
- if (isUndefined(options.stdin)) return defaultConfig;
9176
- if (typeof options.stdin === "string") return {
9177
- ...defaultConfig,
9178
- stream: options.stdin
9179
- };
9180
- if (isStream(options.stdin)) return {
9181
- ...defaultConfig,
9182
- stream: options.stdin
9183
- };
9184
- return {
9185
- stream: options.stdin.stream,
9186
- encoding: options.stdin.encoding ?? defaultConfig.encoding,
9187
- endOnDone: options.stdin.endOnDone ?? defaultConfig.endOnDone
9188
- };
9189
- };
9190
- const resolveOutputOption = (options, streamName) => {
9191
- const option = options[streamName];
9192
- if (isUndefined(option)) return { stream: "pipe" };
9193
- if (typeof option === "string") return { stream: option };
9194
- if (isSink(option)) return { stream: option };
9195
- return { stream: option.stream };
9196
- };
9197
- const resolveAdditionalFds = (options) => {
9198
- if (isUndefined(options.additionalFds)) return [];
9199
- const result = [];
9200
- for (const [name, config] of Object.entries(options.additionalFds)) {
9201
- const fd = parseFdName(name);
9202
- if (isNotUndefined(fd)) result.push({
9203
- fd,
9204
- config
9205
- });
9206
- }
9207
- return result.sort((a, b) => a.fd - b.fd);
9208
- };
9209
- const buildStdioArray = (stdinConfig, stdoutConfig, stderrConfig, additionalFds) => {
9210
- const stdio = [
9211
- inputToStdioOption(stdinConfig.stream),
9212
- outputToStdioOption(stdoutConfig.stream),
9213
- outputToStdioOption(stderrConfig.stream)
9214
- ];
9215
- if (additionalFds.length === 0) return stdio;
9216
- const maxFd = additionalFds.reduce((max, { fd }) => Math.max(max, fd), 2);
9217
- for (let i = 3; i <= maxFd; i++) stdio[i] = "ignore";
9218
- for (const { fd } of additionalFds) stdio[fd] = "pipe";
9219
- return stdio;
9220
- };
9221
- const setupAdditionalFds = fnUntraced(function* (command, childProcess, additionalFds) {
9222
- if (additionalFds.length === 0) return {
9223
- getInputFd: () => drain,
9224
- getOutputFd: () => empty$1
9225
- };
9226
- const inputSinks = /* @__PURE__ */ new Map();
9227
- const outputStreams = /* @__PURE__ */ new Map();
9228
- for (const { config, fd } of additionalFds) {
9229
- const nodeStream = childProcess.stdio[fd];
9230
- switch (config.type) {
9231
- case "input": {
9232
- let sink = drain;
9233
- if (nodeStream && "write" in nodeStream) sink = fromWritable({
9234
- evaluate: () => nodeStream,
9235
- onError: (error) => toPlatformError(`fromWritable(fd${fd})`, toError(error), command)
9236
- });
9237
- if (config.stream) yield* forkScoped(run$2(config.stream, sink));
9238
- inputSinks.set(fd, sink);
9239
- break;
9240
- }
9241
- case "output": {
9242
- let stream = empty$1;
9243
- if (nodeStream && "read" in nodeStream) {
9244
- const passThrough = new PassThrough();
9245
- nodeStream.on("error", (error) => passThrough.destroy(error));
9246
- nodeStream.pipe(passThrough);
9247
- stream = fromReadable({
9248
- evaluate: () => passThrough,
9249
- onError: (error) => toPlatformError(`fromReadable(fd${fd})`, toError(error), command)
9250
- });
9251
- }
9252
- if (config.sink) stream = transduce(stream, config.sink);
9253
- outputStreams.set(fd, stream);
9254
- break;
9255
- }
9256
- }
9257
- }
9258
- return {
9259
- getInputFd: (fd) => inputSinks.get(fd) ?? drain,
9260
- getOutputFd: (fd) => outputStreams.get(fd) ?? empty$1
9261
- };
9262
- });
9263
- const setupChildStdin = (command, childProcess, config) => suspend(() => {
9264
- let sink = drain;
9265
- if (isNotNull(childProcess.stdin)) sink = fromWritable({
9266
- evaluate: () => childProcess.stdin,
9267
- onError: (error) => toPlatformError("fromWritable(stdin)", toError(error), command),
9268
- endOnDone: config.endOnDone,
9269
- encoding: config.encoding
9270
- });
9271
- if (isStream(config.stream)) return as(forkScoped(run$2(config.stream, sink)), sink);
9272
- return succeed(sink);
9273
- });
9274
- const setupChildOutputStreams = (command, childProcess, stdoutConfig, stderrConfig) => {
9275
- let stdout = childProcess.stdout ? (() => {
9276
- const passThrough = new PassThrough();
9277
- childProcess.stdout.on("error", (error) => passThrough.destroy(error));
9278
- childProcess.stdout.pipe(passThrough);
9279
- return fromReadable({
9280
- evaluate: () => passThrough,
9281
- onError: (error) => toPlatformError("fromReadable(stdout)", toError(error), command)
9282
- });
9283
- })() : empty$1;
9284
- let stderr = childProcess.stderr ? (() => {
9285
- const passThrough = new PassThrough();
9286
- childProcess.stderr.on("error", (error) => passThrough.destroy(error));
9287
- childProcess.stderr.pipe(passThrough);
9288
- return fromReadable({
9289
- evaluate: () => passThrough,
9290
- onError: (error) => toPlatformError("fromReadable(stderr)", toError(error), command)
9291
- });
9292
- })() : empty$1;
9293
- if (isSink(stdoutConfig.stream)) stdout = transduce(stdout, stdoutConfig.stream);
9294
- if (isSink(stderrConfig.stream)) stderr = transduce(stderr, stderrConfig.stream);
9295
- const all = merge(stdout, stderr);
9296
- return {
9297
- stdout,
9298
- stderr,
9299
- all
9300
- };
9301
- };
9302
- const spawn = (command, spawnOptions) => callback((resume) => {
9303
- const deferred = makeUnsafe$1();
9304
- const handle = NodeChildProcess.spawn(command.command, command.args, spawnOptions);
9305
- handle.on("error", (error) => {
9306
- resume(fail(toPlatformError("spawn", error, command)));
9307
- });
9308
- handle.on("exit", (...args) => {
9309
- doneUnsafe(deferred, succeed$2(args));
9310
- });
9311
- handle.on("spawn", () => {
9312
- resume(succeed([handle, deferred]));
9313
- });
9314
- return sync(() => {
9315
- handle.kill("SIGTERM");
9316
- });
9317
- });
9318
- const killProcessGroup = (command, childProcess, signal) => {
9319
- if (globalThis.process.platform === "win32") return callback((resume) => {
9320
- NodeChildProcess.exec(`taskkill /pid ${childProcess.pid} /T /F`, (error) => {
9321
- if (error) resume(fail(toPlatformError("kill", toError(error), command)));
9322
- else resume(void_);
9323
- });
9324
- });
9325
- return try_({
9326
- try: () => {
9327
- globalThis.process.kill(-childProcess.pid, signal);
9328
- },
9329
- catch: (error) => toPlatformError("kill", toError(error), command)
9330
- });
9331
- };
9332
- const killProcessGroupOnExit = (childProcess, signal) => {
9333
- if (globalThis.process.platform === "win32") {
9334
- NodeChildProcess.exec(`taskkill /pid ${childProcess.pid} /T /F`, () => {});
9335
- return;
9336
- }
9337
- try {
9338
- globalThis.process.kill(-childProcess.pid, signal);
9339
- } catch {}
9340
- };
9341
- const killProcess = (command, childProcess, signal) => suspend(() => {
9342
- if (!childProcess.kill(signal)) return fail(toPlatformError("kill", new globalThis.Error("Failed to kill child process"), command));
9343
- return void_;
9344
- });
9345
- const withTimeout = (childProcess, command, options) => (kill) => {
9346
- const killSignal = options?.killSignal ?? "SIGTERM";
9347
- return isUndefined(options?.forceKillAfter) ? kill(command, childProcess, killSignal) : timeoutOrElse(kill(command, childProcess, killSignal), {
9348
- duration: options.forceKillAfter,
9349
- orElse: () => kill(command, childProcess, "SIGKILL")
9350
- });
9351
- };
9352
- /**
9353
- * Get the appropriate source stream from a process handle based on the
9354
- * `from` pipe option.
9355
- */
9356
- const getSourceStream = (handle, from) => {
9357
- const fromOption = from ?? "stdout";
9358
- switch (fromOption) {
9359
- case "stdout": return handle.stdout;
9360
- case "stderr": return handle.stderr;
9361
- case "all": return handle.all;
9362
- default: {
9363
- const fd = parseFdName(fromOption);
9364
- if (isNotUndefined(fd)) return handle.getOutputFd(fd);
9365
- return handle.stdout;
9366
- }
9367
- }
9368
- };
9369
- const spawnCommand = fnUntraced(function* (cmd) {
9370
- switch (cmd._tag) {
9371
- case "StandardCommand": {
9372
- const stdinConfig = resolveStdinOption(cmd.options);
9373
- const stdoutConfig = resolveOutputOption(cmd.options, "stdout");
9374
- const stderrConfig = resolveOutputOption(cmd.options, "stderr");
9375
- const resolvedAdditionalFds = resolveAdditionalFds(cmd.options);
9376
- let isReferenced = true;
9377
- const cwd = yield* resolveWorkingDirectory(cmd.options);
9378
- const env = resolveEnvironment(cmd.options);
9379
- const stdio = buildStdioArray(stdinConfig, stdoutConfig, stderrConfig, resolvedAdditionalFds);
9380
- const [childProcess, exitSignal] = yield* acquireRelease(spawn(cmd, {
9381
- cwd,
9382
- env,
9383
- stdio,
9384
- detached: cmd.options.detached ?? process.platform !== "win32",
9385
- shell: cmd.options.shell
9386
- }), fnUntraced(function* ([childProcess, exitSignal]) {
9387
- const exited = yield* isDone(exitSignal);
9388
- const killWithTimeout = withTimeout(childProcess, cmd, cmd.options);
9389
- if (exited) {
9390
- const [code] = yield* _await(exitSignal);
9391
- if (code !== 0 && isNotNull(code)) return yield* ignore(killWithTimeout(killProcessGroup));
9392
- return yield* void_;
9393
- }
9394
- if (!isReferenced) return yield* void_;
9395
- return yield* killWithTimeout((command, childProcess, signal) => catch_(killProcessGroup(command, childProcess, signal), () => killProcess(command, childProcess, signal))).pipe(andThen(_await(exitSignal)), ignore);
9396
- }));
9397
- const pid = ProcessId(childProcess.pid);
9398
- childProcess.on("exit", (code) => {
9399
- if (code !== 0 && isNotNull(code)) killProcessGroupOnExit(childProcess, cmd.options.killSignal ?? "SIGTERM");
9400
- });
9401
- const reref = sync(() => {
9402
- if (!isReferenced) {
9403
- childProcess.ref();
9404
- isReferenced = true;
9405
- }
9406
- });
9407
- const unref = sync(() => {
9408
- if (isReferenced) {
9409
- childProcess.unref();
9410
- isReferenced = false;
9411
- }
9412
- return reref;
9413
- });
9414
- const stdin = yield* setupChildStdin(cmd, childProcess, stdinConfig);
9415
- const { all, stderr, stdout } = setupChildOutputStreams(cmd, childProcess, stdoutConfig, stderrConfig);
9416
- const { getInputFd, getOutputFd } = yield* setupAdditionalFds(cmd, childProcess, resolvedAdditionalFds);
9417
- const isRunning = map$2(isDone(exitSignal), (done) => !done);
9418
- const exitCode = flatMap(_await(exitSignal), ([code, signal]) => {
9419
- if (isNotNull(code)) return succeed(ExitCode(code));
9420
- return fail(toPlatformError("exitCode", new globalThis.Error(`Process interrupted due to receipt of signal: '${signal}'`), cmd));
9421
- });
9422
- const kill = (options) => {
9423
- return withTimeout(childProcess, cmd, options)((command, childProcess, signal) => catch_(killProcessGroup(command, childProcess, signal), () => killProcess(command, childProcess, signal))).pipe(andThen(_await(exitSignal)), asVoid);
9424
- };
9425
- return makeHandle({
9426
- pid,
9427
- exitCode,
9428
- isRunning,
9429
- kill,
9430
- stdin,
9431
- stdout,
9432
- stderr,
9433
- all,
9434
- getInputFd,
9435
- getOutputFd,
9436
- unref
9437
- });
9438
- }
9439
- case "PipedCommand": {
9440
- const { commands, pipeOptions } = flattenCommand(cmd);
9441
- const [root, ...pipeline] = commands;
9442
- const handles = [yield* spawnCommand(root)];
9443
- for (let i = 0; i < pipeline.length; i++) {
9444
- const command = pipeline[i];
9445
- const options = pipeOptions[i] ?? {};
9446
- const stdinConfig = resolveStdinOption(command.options);
9447
- const sourceStream = unwrap(succeed(getSourceStream(handles[handles.length - 1], options.from)));
9448
- const toOption = options.to ?? "stdin";
9449
- if (toOption === "stdin") handles.push(yield* spawnCommand(make$3(command.command, command.args, {
9450
- ...command.options,
9451
- stdin: {
9452
- ...stdinConfig,
9453
- stream: sourceStream
9454
- }
9455
- })));
9456
- else {
9457
- const fd = parseFdName(toOption);
9458
- if (isNotUndefined(fd)) {
9459
- const fdName$1 = fdName(fd);
9460
- const existingFds = command.options.additionalFds ?? {};
9461
- handles.push(yield* spawnCommand(make$3(command.command, command.args, {
9462
- ...command.options,
9463
- additionalFds: {
9464
- ...existingFds,
9465
- [fdName$1]: {
9466
- type: "input",
9467
- stream: sourceStream
9468
- }
9469
- }
9470
- })));
9471
- } else handles.push(yield* spawnCommand(make$3(command.command, command.args, {
9472
- ...command.options,
9473
- stdin: {
9474
- ...stdinConfig,
9475
- stream: sourceStream
9476
- }
9477
- })));
9478
- }
9479
- }
9480
- const handle = handles[handles.length - 1];
9481
- const unref = gen(function* () {
9482
- const rerefs = [];
9483
- for (const handle of handles) rerefs.push(yield* handle.unref);
9484
- return forEach([...rerefs].reverse(), (reref) => reref, { discard: true });
9485
- });
9486
- return makeHandle({
9487
- pid: handle.pid,
9488
- exitCode: handle.exitCode,
9489
- isRunning: handle.isRunning,
9490
- kill: handle.kill,
9491
- stdin: handle.stdin,
9492
- stdout: handle.stdout,
9493
- stderr: handle.stderr,
9494
- all: handle.all,
9495
- getInputFd: handle.getInputFd,
9496
- getOutputFd: handle.getOutputFd,
9497
- unref
9498
- });
9499
- }
9500
- }
9501
- });
9502
- return make$4(spawnCommand);
9503
- }));
9504
- /**
9505
- * Flattens a `Command` into an array of `StandardCommand`s along with pipe
9506
- * options for each connection.
9507
- *
9508
- * @category transforming
9509
- * @since 4.0.0
9510
- */
9511
- var flattenCommand = (command) => {
9512
- const commands = [];
9513
- const pipeOptions = [];
9514
- const flatten = (cmd) => {
9515
- switch (cmd._tag) {
9516
- case "StandardCommand":
9517
- commands.push(cmd);
9518
- break;
9519
- case "PipedCommand":
9520
- flatten(cmd.left);
9521
- pipeOptions.push(cmd.options);
9522
- flatten(cmd.right);
9523
- break;
9524
- }
9525
- };
9526
- flatten(command);
9527
- if (commands.length === 0) throw new Error("flattenCommand produced empty commands array");
9528
- const [first, ...rest] = commands;
9529
- return {
9530
- commands: [first, ...rest],
9531
- pipeOptions
9532
- };
9533
- };
9534
- //#endregion
9535
- //#region ../../node_modules/@effect/platform-node-shared/dist/NodeFileSystem.js
9536
- /**
9537
- * Shared Node-compatible implementation of Effect's `FileSystem` service.
9538
- *
9539
- * This module adapts Node's `node:fs`, `node:os`, and `node:path` APIs into a
9540
- * `FileSystem` layer for Effect programs running on Node-compatible runtimes.
9541
- * Platform packages use it to provide file and directory I/O, permissions,
9542
- * links, metadata, temporary files and directories, and file watching through
9543
- * the shared `FileSystem` service.
9544
- *
9545
- * @since 4.0.0
9546
- */
9547
- var handleBadArgument = (method) => (err) => badArgument({
9548
- module: "FileSystem",
9549
- method,
9550
- description: err.message ?? String(err)
9551
- });
9552
- var access = /*#__PURE__*/ (() => {
9553
- const nodeAccess = /*#__PURE__*/ effectify(NFS.access, /*#__PURE__*/ handleErrnoException("FileSystem", "access"), /*#__PURE__*/ handleBadArgument("access"));
9554
- return (path, options) => {
9555
- let mode = NFS.constants.F_OK;
9556
- if (options?.readable) mode |= NFS.constants.R_OK;
9557
- if (options?.writable) mode |= NFS.constants.W_OK;
9558
- return nodeAccess(path, mode);
9559
- };
9560
- })();
9561
- var copy = /*#__PURE__*/ (() => {
9562
- const nodeCp = /*#__PURE__*/ effectify(NFS.cp, /*#__PURE__*/ handleErrnoException("FileSystem", "copy"), /*#__PURE__*/ handleBadArgument("copy"));
9563
- return (fromPath, toPath, options) => nodeCp(fromPath, toPath, {
9564
- force: options?.overwrite ?? false,
9565
- preserveTimestamps: options?.preserveTimestamps ?? false,
9566
- recursive: true
9567
- });
9568
- })();
9569
- var copyFile = /*#__PURE__*/ (() => {
9570
- const nodeCopyFile = /*#__PURE__*/ effectify(NFS.copyFile, /*#__PURE__*/ handleErrnoException("FileSystem", "copyFile"), /*#__PURE__*/ handleBadArgument("copyFile"));
9571
- return (fromPath, toPath) => nodeCopyFile(fromPath, toPath);
9572
- })();
9573
- var chmod = /*#__PURE__*/ (() => {
9574
- const nodeChmod = /*#__PURE__*/ effectify(NFS.chmod, /*#__PURE__*/ handleErrnoException("FileSystem", "chmod"), /*#__PURE__*/ handleBadArgument("chmod"));
9575
- return (path, mode) => nodeChmod(path, mode);
9576
- })();
9577
- var chown = /*#__PURE__*/ (() => {
9578
- const nodeChown = /*#__PURE__*/ effectify(NFS.chown, /*#__PURE__*/ handleErrnoException("FileSystem", "chown"), /*#__PURE__*/ handleBadArgument("chown"));
9579
- return (path, uid, gid) => nodeChown(path, uid, gid);
9580
- })();
9581
- var glob = /*#__PURE__*/ (() => {
9582
- const nodeGlob = /*#__PURE__*/ effectify(NFS.glob, /*#__PURE__*/ handleErrnoException("FileSystem", "glob"), /*#__PURE__*/ handleBadArgument("glob"));
9583
- return (pattern, options) => nodeGlob(pattern, {
9584
- cwd: options?.root,
9585
- exclude: options?.exclude
9586
- });
9587
- })();
9588
- var link = /*#__PURE__*/ (() => {
9589
- const nodeLink = /*#__PURE__*/ effectify(NFS.link, /*#__PURE__*/ handleErrnoException("FileSystem", "link"), /*#__PURE__*/ handleBadArgument("link"));
9590
- return (existingPath, newPath) => nodeLink(existingPath, newPath);
9591
- })();
9592
- var makeDirectory = /*#__PURE__*/ (() => {
9593
- const nodeMkdir = /*#__PURE__*/ effectify(NFS.mkdir, /*#__PURE__*/ handleErrnoException("FileSystem", "makeDirectory"), /*#__PURE__*/ handleBadArgument("makeDirectory"));
9594
- return (path, options) => nodeMkdir(path, {
9595
- recursive: options?.recursive ?? false,
9596
- mode: options?.mode
9597
- });
9598
- })();
9599
- var makeTempDirectoryFactory = (method) => {
9600
- const nodeMkdtemp = effectify(NFS.mkdtemp, handleErrnoException("FileSystem", method), handleBadArgument(method));
9601
- return (options) => suspend(() => {
9602
- const prefix = options?.prefix ?? "";
9603
- const directory = typeof options?.directory === "string" ? Path.join(options.directory, ".") : OS.tmpdir();
9604
- return nodeMkdtemp(prefix ? Path.join(directory, prefix) : directory + "/");
9605
- });
9606
- };
9607
- var makeTempDirectory = /*#__PURE__*/ makeTempDirectoryFactory("makeTempDirectory");
9608
- var removeFactory = (method) => {
9609
- const nodeRm = effectify(NFS.rm, handleErrnoException("FileSystem", method), handleBadArgument(method));
9610
- return (path, options) => nodeRm(path, {
9611
- recursive: options?.recursive ?? false,
9612
- force: options?.force ?? false
9613
- });
9614
- };
9615
- var remove$1 = /*#__PURE__*/ removeFactory("remove");
9616
- var makeTempDirectoryScoped = /*#__PURE__*/ (() => {
9617
- const makeDirectory = /*#__PURE__*/ makeTempDirectoryFactory("makeTempDirectoryScoped");
9618
- const removeDirectory = /*#__PURE__*/ removeFactory("makeTempDirectoryScoped");
9619
- return (options) => acquireRelease(makeDirectory(options), (directory) => orDie(removeDirectory(directory, { recursive: true })));
9620
- })();
9621
- var openFactory = (method) => {
9622
- const nodeOpen = effectify(NFS.open, handleErrnoException("FileSystem", method), handleBadArgument(method));
9623
- const nodeClose = effectify(NFS.close, handleErrnoException("FileSystem", method), handleBadArgument(method));
9624
- return (path, options) => pipe(acquireRelease(nodeOpen(path, options?.flag ?? "r", options?.mode), (fd) => orDie(nodeClose(fd))), map$2((fd) => makeFile(FileDescriptor(fd), options?.flag?.startsWith("a") ?? false)));
9625
- };
9626
- var open = /*#__PURE__*/ openFactory("open");
9627
- var makeFile = /*#__PURE__*/ (() => {
9628
- const nodeReadFactory = (method) => effectify(NFS.read, handleErrnoException("FileSystem", method), handleBadArgument(method));
9629
- const nodeRead = /*#__PURE__*/ nodeReadFactory("read");
9630
- const nodeReadAlloc = /*#__PURE__*/ nodeReadFactory("readAlloc");
9631
- const nodeStat = /*#__PURE__*/ effectify(NFS.fstat, /*#__PURE__*/ handleErrnoException("FileSystem", "stat"), /*#__PURE__*/ handleBadArgument("stat"));
9632
- const nodeTruncate = /*#__PURE__*/ effectify(NFS.ftruncate, /*#__PURE__*/ handleErrnoException("FileSystem", "truncate"), /*#__PURE__*/ handleBadArgument("truncate"));
9633
- const nodeSync = /*#__PURE__*/ effectify(NFS.fsync, /*#__PURE__*/ handleErrnoException("FileSystem", "sync"), /*#__PURE__*/ handleBadArgument("sync"));
9634
- const nodeWriteFactory = (method) => effectify(NFS.write, handleErrnoException("FileSystem", method), handleBadArgument(method));
9635
- const nodeWrite = /*#__PURE__*/ nodeWriteFactory("write");
9636
- const nodeWriteAll = /*#__PURE__*/ nodeWriteFactory("writeAll");
9637
- class FileImpl {
9638
- [FileTypeId];
9639
- fd;
9640
- append;
9641
- position = /*#__PURE__*/ BigInt(0);
9642
- constructor(fd, append) {
9643
- this[FileTypeId] = FileTypeId;
9644
- this.fd = fd;
9645
- this.append = append;
9646
- }
9647
- get stat() {
9648
- return map$2(nodeStat(this.fd), makeFileInfo);
9649
- }
9650
- get sync() {
9651
- return nodeSync(this.fd);
9652
- }
9653
- seek(offset, from) {
9654
- const offsetSize = Size(offset);
9655
- return sync(() => {
9656
- if (from === "start") this.position = offsetSize;
9657
- else if (from === "current") this.position = this.position + offsetSize;
9658
- return this.position;
9659
- });
9660
- }
9661
- read(buffer) {
9662
- return suspend(() => {
9663
- const position = this.position;
9664
- return map$2(nodeRead(this.fd, {
9665
- buffer,
9666
- position
9667
- }), (bytesRead) => {
9668
- const sizeRead = Size(bytesRead);
9669
- this.position = position + sizeRead;
9670
- return sizeRead;
9671
- });
9672
- });
9673
- }
9674
- readAlloc(size) {
9675
- const sizeNumber = Number(size);
9676
- return suspend(() => {
9677
- const buffer = Buffer.allocUnsafeSlow(sizeNumber);
9678
- const position = this.position;
9679
- return map$2(nodeReadAlloc(this.fd, {
9680
- buffer,
9681
- position
9682
- }), (bytesRead) => {
9683
- if (bytesRead === 0) return none();
9684
- this.position = position + BigInt(bytesRead);
9685
- if (bytesRead === sizeNumber) return some(buffer);
9686
- const dst = Buffer.allocUnsafeSlow(bytesRead);
9687
- buffer.copy(dst, 0, 0, bytesRead);
9688
- return some(dst);
9689
- });
9690
- });
9691
- }
9692
- truncate(length) {
9693
- return map$2(nodeTruncate(this.fd, length ? Number(length) : void 0), () => {
9694
- if (!this.append) {
9695
- const len = BigInt(length ?? 0);
9696
- if (this.position > len) this.position = len;
9697
- }
9698
- });
9699
- }
9700
- write(buffer) {
9701
- return suspend(() => {
9702
- const position = this.position;
9703
- return map$2(nodeWrite(this.fd, buffer, void 0, void 0, this.append ? void 0 : Number(position)), (bytesWritten) => {
9704
- const sizeWritten = Size(bytesWritten);
9705
- if (!this.append) this.position = position + sizeWritten;
9706
- return sizeWritten;
9707
- });
9708
- });
9709
- }
9710
- writeAllChunk(buffer) {
9711
- return suspend(() => {
9712
- const position = this.position;
9713
- return flatMap(nodeWriteAll(this.fd, buffer, void 0, void 0, this.append ? void 0 : Number(position)), (bytesWritten) => {
9714
- if (bytesWritten === 0) return fail(systemError({
9715
- module: "FileSystem",
9716
- method: "writeAll",
9717
- _tag: "WriteZero",
9718
- pathOrDescriptor: this.fd,
9719
- description: "write returned 0 bytes written"
9720
- }));
9721
- if (!this.append) this.position = position + BigInt(bytesWritten);
9722
- return bytesWritten < buffer.length ? this.writeAllChunk(buffer.subarray(bytesWritten)) : void_;
9723
- });
9724
- });
9725
- }
9726
- writeAll(buffer) {
9727
- return this.writeAllChunk(buffer);
9728
- }
9729
- }
9730
- return (fd, append) => new FileImpl(fd, append);
9731
- })();
9732
- var makeTempFileFactory = (method) => {
9733
- const makeDirectory = makeTempDirectoryFactory(method);
9734
- return fnUntraced(function* (options) {
9735
- const directory = yield* makeDirectory(options);
9736
- const random = Crypto.randomBytes(6).toString("hex");
9737
- const name = Path.join(directory, options?.suffix ? `${random}${options.suffix}` : random);
9738
- yield* writeFile(name, /* @__PURE__ */ new Uint8Array(0));
9739
- return name;
9740
- });
9741
- };
9742
- var makeTempFile = /*#__PURE__*/ makeTempFileFactory("makeTempFile");
9743
- var makeTempFileScoped = /*#__PURE__*/ (() => {
9744
- const makeFile = /*#__PURE__*/ makeTempFileFactory("makeTempFileScoped");
9745
- const removeDirectory = /*#__PURE__*/ removeFactory("makeTempFileScoped");
9746
- return (options) => acquireRelease(makeFile(options), (file) => orDie(removeDirectory(Path.dirname(file), { recursive: true })));
9747
- })();
9748
- var readDirectory = (path, options) => tryPromise({
9749
- try: () => NFS.promises.readdir(path, options),
9750
- catch: (err) => handleErrnoException("FileSystem", "readDirectory")(err, [path])
9751
- });
9752
- var readFile = (path) => callback((resume, signal) => {
9753
- try {
9754
- NFS.readFile(path, { signal }, (err, data) => {
9755
- if (err) resume(fail(handleErrnoException("FileSystem", "readFile")(err, [path])));
9756
- else resume(succeed(data));
9757
- });
9758
- } catch (err) {
9759
- resume(fail(handleBadArgument("readFile")(err)));
9760
- }
9761
- });
9762
- var readLink = /*#__PURE__*/ (() => {
9763
- const nodeReadLink = /*#__PURE__*/ effectify(NFS.readlink, /*#__PURE__*/ handleErrnoException("FileSystem", "readLink"), /*#__PURE__*/ handleBadArgument("readLink"));
9764
- return (path) => nodeReadLink(path);
9765
- })();
9766
- var realPath = /*#__PURE__*/ (() => {
9767
- const nodeRealPath = /*#__PURE__*/ effectify(NFS.realpath, /*#__PURE__*/ handleErrnoException("FileSystem", "realPath"), /*#__PURE__*/ handleBadArgument("realPath"));
9768
- return (path) => nodeRealPath(path);
9769
- })();
9770
- var rename = /*#__PURE__*/ (() => {
9771
- const nodeRename = /*#__PURE__*/ effectify(NFS.rename, /*#__PURE__*/ handleErrnoException("FileSystem", "rename"), /*#__PURE__*/ handleBadArgument("rename"));
9772
- return (oldPath, newPath) => nodeRename(oldPath, newPath);
9773
- })();
9774
- var makeFileInfo = (stat) => ({
9775
- type: stat.isFile() ? "File" : stat.isDirectory() ? "Directory" : stat.isSymbolicLink() ? "SymbolicLink" : stat.isBlockDevice() ? "BlockDevice" : stat.isCharacterDevice() ? "CharacterDevice" : stat.isFIFO() ? "FIFO" : stat.isSocket() ? "Socket" : "Unknown",
9776
- mtime: fromNullishOr(stat.mtime),
9777
- atime: fromNullishOr(stat.atime),
9778
- birthtime: fromNullishOr(stat.birthtime),
9779
- dev: stat.dev,
9780
- rdev: fromNullishOr(stat.rdev),
9781
- ino: fromNullishOr(stat.ino),
9782
- mode: stat.mode,
9783
- nlink: fromNullishOr(stat.nlink),
9784
- uid: fromNullishOr(stat.uid),
9785
- gid: fromNullishOr(stat.gid),
9786
- size: Size(stat.size),
9787
- blksize: stat.blksize !== void 0 ? some(Size(stat.blksize)) : none(),
9788
- blocks: fromNullishOr(stat.blocks)
9789
- });
9790
- var stat = /*#__PURE__*/ (() => {
9791
- const nodeStat = /*#__PURE__*/ effectify(NFS.stat, /*#__PURE__*/ handleErrnoException("FileSystem", "stat"), /*#__PURE__*/ handleBadArgument("stat"));
9792
- return (path) => map$2(nodeStat(path), makeFileInfo);
9793
- })();
9794
- var symlink = /*#__PURE__*/ (() => {
9795
- const nodeSymlink = /*#__PURE__*/ effectify(NFS.symlink, /*#__PURE__*/ handleErrnoException("FileSystem", "symlink"), /*#__PURE__*/ handleBadArgument("symlink"));
9796
- return (target, path) => nodeSymlink(target, path);
9797
- })();
9798
- var truncate = /*#__PURE__*/ (() => {
9799
- const nodeTruncate = /*#__PURE__*/ effectify(NFS.truncate, /*#__PURE__*/ handleErrnoException("FileSystem", "truncate"), /*#__PURE__*/ handleBadArgument("truncate"));
9800
- return (path, length) => nodeTruncate(path, length !== void 0 ? Number(length) : void 0);
9801
- })();
9802
- var utimes = /*#__PURE__*/ (() => {
9803
- const nodeUtimes = /*#__PURE__*/ effectify(NFS.utimes, /*#__PURE__*/ handleErrnoException("FileSystem", "utime"), /*#__PURE__*/ handleBadArgument("utime"));
9804
- return (path, atime, mtime) => nodeUtimes(path, atime, mtime);
9805
- })();
9806
- var watchNode = (path) => callback$1((queue) => acquireRelease(sync(() => {
9807
- const watcher = NFS.watch(path, { recursive: true }, (event, path) => {
9808
- if (!path) return;
9809
- switch (event) {
9810
- case "rename":
9811
- runFork(matchEffect(stat(path), {
9812
- onSuccess: (_) => offer(queue, {
9813
- _tag: "Create",
9814
- path
9815
- }),
9816
- onFailure: (_) => offer(queue, {
9817
- _tag: "Remove",
9818
- path
9819
- })
9820
- }));
9821
- return;
9822
- case "change":
9823
- offerUnsafe(queue, {
9824
- _tag: "Update",
9825
- path
9826
- });
9827
- return;
9828
- }
9829
- });
9830
- watcher.on("error", (error) => {
9831
- failCauseUnsafe(queue, fail$3(systemError({
9832
- module: "FileSystem",
9833
- _tag: "Unknown",
9834
- method: "watch",
9835
- pathOrDescriptor: path,
9836
- cause: error
9837
- })));
9838
- });
9839
- watcher.on("close", () => {
9840
- endUnsafe(queue);
9841
- });
9842
- return watcher;
9843
- }), (watcher) => sync(() => watcher.close())));
9844
- var watch = (backend, path) => stat(path).pipe(map$2((stat) => backend.pipe(flatMap$1((_) => _.register(path, stat)), getOrElse(() => watchNode(path)))), unwrap);
9845
- var writeFile = (path, data, options) => callback((resume, signal) => {
9846
- try {
9847
- NFS.writeFile(path, data, {
9848
- signal,
9849
- flag: options?.flag,
9850
- mode: options?.mode
9851
- }, (err) => {
9852
- if (err) resume(fail(handleErrnoException("FileSystem", "writeFile")(err, [path])));
9853
- else resume(void_);
9854
- });
9855
- } catch (err) {
9856
- resume(fail(handleBadArgument("writeFile")(err)));
9857
- }
9858
- });
9859
- var makeFileSystem = /*#__PURE__*/ map$2(/*#__PURE__*/ serviceOption(WatchBackend), (backend) => make$8({
9860
- access,
9861
- chmod,
9862
- chown,
9863
- copy,
9864
- copyFile,
9865
- glob,
9866
- link,
9867
- makeDirectory,
9868
- makeTempDirectory,
9869
- makeTempDirectoryScoped,
9870
- makeTempFile,
9871
- makeTempFileScoped,
9872
- open,
9873
- readDirectory,
9874
- readFile,
9875
- readLink,
9876
- realPath,
9877
- remove: remove$1,
9878
- rename,
9879
- stat,
9880
- symlink,
9881
- truncate,
9882
- utimes,
9883
- watch(path) {
9884
- return watch(backend, path);
9885
- },
9886
- writeFile
9887
- }));
9888
- //#endregion
9889
- //#region ../../node_modules/@effect/platform-node/dist/NodeFileSystem.js
9890
- /**
9891
- * Node.js `FileSystem` layer for programs that perform real filesystem I/O.
9892
- *
9893
- * The exported layer satisfies the platform-independent `FileSystem` service
9894
- * with Node-backed operations for files, directories, metadata, permissions,
9895
- * links, temporary paths, and path watching. Effects still call the service from
9896
- * `effect/FileSystem`; this module only chooses the Node implementation.
9897
- *
9898
- * @since 4.0.0
9899
- */
9900
- /**
9901
- * Provides the `FileSystem` service backed by Node filesystem APIs.
9902
- *
9903
- * @category layers
9904
- * @since 4.0.0
9905
- */
9906
- var layer$9 = /* @__PURE__ */ effect(FileSystem)(makeFileSystem);
9907
- //#endregion
9908
- //#region ../../node_modules/@effect/platform-node-shared/dist/NodeCrypto.js
9909
- /**
9910
- * Node-compatible implementation of Effect's `Crypto` service.
9911
- *
9912
- * This module builds the service from `node:crypto`, using `randomBytes` for
9913
- * random data and `createHash` for supported digest algorithms. It exports
9914
- * `make` as the concrete service value and `layer` for providing it through
9915
- * Effect context.
9916
- *
9917
- * @since 1.0.0
9918
- */
9919
- var toHashAlgorithm = (algorithm) => {
9920
- switch (algorithm) {
9921
- case "SHA-1": return "sha1";
9922
- case "SHA-256": return "sha256";
9923
- case "SHA-384": return "sha384";
9924
- case "SHA-512": return "sha512";
9925
- }
9926
- };
9927
- var digest = (algorithm, data) => try_({
9928
- try: () => Uint8Array.from(Crypto.createHash(toHashAlgorithm(algorithm)).update(data).digest()),
9929
- catch: (cause) => systemError({
9930
- module: "Crypto",
9931
- method: "digest",
9932
- _tag: "Unknown",
9933
- description: "Could not compute digest",
9934
- cause
9935
- })
9936
- });
9937
- //#endregion
9938
- //#region ../../node_modules/@effect/platform-node/dist/NodeCrypto.js
9939
- /**
9940
- * The `NodeCrypto` module provides the Node.js `Crypto` service layer for
9941
- * Effect programs. Provide {@link layer} at the edge of a Node application,
9942
- * CLI, script, or test to satisfy `effect/Crypto` with Node's `node:crypto`
9943
- * implementation for secure random bytes, UUID generation, random values, and
9944
- * SHA digest operations.
9945
- *
9946
- * This module is the public Node adapter around the shared Node-compatible
9947
- * implementation. Digest failures are reported as platform errors, and SHA-1
9948
- * remains available only for interoperability with existing protocols.
9949
- *
9950
- * @since 1.0.0
9951
- */
9952
- /**
9953
- * Layer that provides the Node.js Crypto service implementation.
9954
- *
9955
- * @category layers
9956
- * @since 1.0.0
9957
- */
9958
- var layer$7 = /* @__PURE__ */ succeed$3(Crypto$1, /* @__PURE__ */ make$9({
9959
- randomBytes: Crypto.randomBytes,
9960
- digest
9961
- }));
9962
- //#endregion
9963
- //#region ../../node_modules/@effect/platform-node-shared/dist/NodePath.js
9964
- /**
9965
- * Node-backed provider for Effect's `Path` service.
9966
- *
9967
- * This module turns Node's `node:path` and `node:url` APIs into `Path` layers.
9968
- * `layer` uses the host platform path implementation, while `layerPosix` and
9969
- * `layerWin32` provide fixed POSIX and Windows variants. All three layers also
9970
- * include helpers for converting between file paths and file URLs.
9971
- *
9972
- * @since 4.0.0
9973
- */
9974
- var fromFileUrl = (url) => try_({
9975
- try: () => NodeUrl.fileURLToPath(url),
9976
- catch: (cause) => new BadArgument({
9977
- module: "Path",
9978
- method: "fromFileUrl",
9979
- cause
9980
- })
9981
- });
9982
- var toFileUrl = (path) => try_({
9983
- try: () => NodeUrl.pathToFileURL(path),
9984
- catch: (cause) => new BadArgument({
9985
- module: "Path",
9986
- method: "toFileUrl",
9987
- cause
9988
- })
9989
- });
9990
- ({ ...Path.posix });
9991
- ({ ...Path.win32 });
9992
- //#endregion
9993
- //#region ../../node_modules/@effect/platform-node/dist/NodePath.js
9994
- /**
9995
- * Node.js layers for Effect's `Path` service.
9996
- *
9997
- * This module provides the default, POSIX, and Windows variants of the
9998
- * platform-independent `Path` service by reusing the shared Node path
9999
- * implementation. The provided path services include Node file URL conversion
10000
- * behavior.
10001
- *
10002
- * @since 4.0.0
10003
- */
10004
- /**
10005
- * Provides the default Node `Path` service using the platform's `node:path`
10006
- * implementation.
10007
- *
10008
- * @category layers
10009
- * @since 4.0.0
10010
- */
10011
- var layer$5 = /* @__PURE__ */ succeed$3(Path$1)({
10012
- [TypeId$5]: TypeId$5,
10013
- ...Path,
10014
- fromFileUrl,
10015
- toFileUrl
10016
- });
10017
- //#endregion
10018
- //#region ../../node_modules/@effect/platform-node/dist/NodeStdio.js
10019
- /**
10020
- * Node.js `Stdio` layer for the current process.
10021
- *
10022
- * The exported layer reuses the shared Node stdio implementation. It satisfies
10023
- * the platform-independent `Stdio` service by reading command-line arguments
10024
- * from `process.argv`, consuming input from `process.stdin`, and writing output
10025
- * streams to `process.stdout` and `process.stderr`.
10026
- *
10027
- * @since 4.0.0
10028
- */
10029
- /**
10030
- * Provides the `Stdio` service backed by the current process arguments,
10031
- * stdin, stdout, and stderr streams.
10032
- *
10033
- * @category layers
10034
- * @since 4.0.0
10035
- */
10036
- var layer$3 = /* @__PURE__ */ succeed$3(Stdio, /*#__PURE__*/ make$10({
10037
- args: /*#__PURE__*/ sync(() => process.argv.slice(2)),
10038
- stdout: (options) => fromWritable({
10039
- evaluate: () => process.stdout,
10040
- onError: (cause) => systemError({
10041
- module: "Stdio",
10042
- method: "stdout",
10043
- _tag: "Unknown",
10044
- cause
10045
- }),
10046
- endOnDone: options?.endOnDone ?? false
10047
- }),
10048
- stderr: (options) => fromWritable({
10049
- evaluate: () => process.stderr,
10050
- onError: (cause) => systemError({
10051
- module: "Stdio",
10052
- method: "stderr",
10053
- _tag: "Unknown",
10054
- cause
10055
- }),
10056
- endOnDone: options?.endOnDone ?? false
10057
- }),
10058
- stdin: /*#__PURE__*/ fromReadable({
10059
- evaluate: () => process.stdin,
10060
- onError: (cause) => systemError({
10061
- module: "Stdio",
10062
- method: "stdin",
10063
- _tag: "Unknown",
10064
- cause
10065
- }),
10066
- closeOnDone: false
10067
- })
10068
- }));
10069
- /**
10070
- * Provides the default process-backed `Terminal` service, ending key input on
10071
- * Ctrl+C or Ctrl+D.
10072
- *
10073
- * @category layers
10074
- * @since 4.0.0
10075
- */
10076
- var layer$2 = /*#__PURE__*/ effect(Terminal, /*#__PURE__*/ (/* @__PURE__ */ fnUntraced(function* (shouldQuit = defaultShouldQuit) {
10077
- const stdin = process.stdin;
10078
- const stdout = process.stdout;
10079
- const rlRef = yield* make$11({ acquire: acquireRelease(sync(() => {
10080
- const rl = readline.createInterface({
10081
- input: stdin,
10082
- escapeCodeTimeout: 50
10083
- });
10084
- readline.emitKeypressEvents(stdin, rl);
10085
- if (stdin.isTTY) stdin.setRawMode(true);
10086
- return rl;
10087
- }), (rl) => sync(() => {
10088
- if (stdin.isTTY) stdin.setRawMode(false);
10089
- rl.close();
10090
- })) });
10091
- const columns = sync(() => stdout.columns ?? 0);
10092
- const rows = sync(() => stdout.rows ?? 0);
10093
- const readInput = gen(function* () {
10094
- yield* get(rlRef);
10095
- const queue = yield* make$12();
10096
- const handleKeypress = (s, k) => {
10097
- const userInput = {
10098
- input: fromUndefinedOr(s),
10099
- key: {
10100
- name: k.name ?? "",
10101
- ctrl: !!k.ctrl,
10102
- meta: !!k.meta,
10103
- shift: !!k.shift
10104
- }
10105
- };
10106
- offerUnsafe(queue, userInput);
10107
- if (shouldQuit(userInput)) endUnsafe(queue);
10108
- };
10109
- yield* addFinalizer$1(() => sync(() => stdin.off("keypress", handleKeypress)));
10110
- stdin.on("keypress", handleKeypress);
10111
- return queue;
10112
- });
10113
- const readLine = scoped(flatMap(get(rlRef), (readlineInterface) => callback((resume) => {
10114
- const onLine = (line) => resume(succeed(line));
10115
- readlineInterface.once("line", onLine);
10116
- return sync(() => readlineInterface.off("line", onLine));
10117
- })));
10118
- const display = (prompt) => uninterruptible(callback((resume) => {
10119
- stdout.write(prompt, (err) => isNullish(err) ? resume(void_) : resume(fail(badArgument({
10120
- module: "Terminal",
10121
- method: "display",
10122
- description: "Failed to write prompt to stdout",
10123
- cause: err
10124
- }))));
10125
- }));
10126
- return make$13({
10127
- columns,
10128
- rows,
10129
- readInput,
10130
- readLine,
10131
- display
10132
- });
10133
- }))(defaultShouldQuit));
10134
- function defaultShouldQuit(input) {
10135
- return input.key.ctrl && (input.key.name === "c" || input.key.name === "d");
10136
- }
10137
- //#endregion
10138
- //#region ../../node_modules/@effect/platform-node/dist/NodeServices.js
10139
- /**
10140
- * Provides the default Node implementations for child process spawning,
10141
- * filesystem, path, stdio, and terminal services.
10142
- *
10143
- * @category layers
10144
- * @since 4.0.0
10145
- */
10146
- var layer = /*#__PURE__*/ provideMerge(layer$11, /*#__PURE__*/ mergeAll(layer$9, layer$7, layer$5, layer$3, layer$2));
10147
- //#endregion
10148
8826
  //#region ../../node_modules/@effect/platform-node/dist/NodeRuntime.js
10149
8827
  /**
10150
8828
  * Node.js process runner for Effect programs.
@@ -10259,7 +8937,7 @@ var LoomTangler = class extends Service()("LoomTangler", { make: gen(function* (
10259
8937
  const batchLimit = 1e3;
10260
8938
  const isLoomEvent = (event) => event.path.endsWith(".loom") && !isStorePath(event.path);
10261
8939
  const watchRoot = (path) => fs.stat(path).pipe(orDie, flatMap((info) => info.type === "Directory" ? succeed(path) : config.resolve(path).pipe(map$2(({ corpusDir }) => getOrElse(fromNullishOr(corpusDir), () => dirname(path))))));
10262
- const watch = (path) => unwrap(watchRoot(path).pipe(map$2((root) => concat(fromEffect(result(tangle(path))), fs.watch(root).pipe(filter$1(isLoomEvent), groupedWithin(batchLimit, batchWindow), mapEffect((events) => forEach(dedupe(map$3(events, (event) => resolve(root, event.path))), (changed) => compiler.invalidate(changed), { discard: true }).pipe(andThen(result(tangle(path))))), orDie$1)))));
8940
+ const watch = (path) => unwrap(watchRoot(path).pipe(map$2((root) => concat(fromEffect(result(tangle(path))), fs.watch(root).pipe(filter$1(isLoomEvent), groupedWithin(batchLimit, batchWindow), mapEffect$1((events) => forEach(dedupe(map$3(events, (event) => resolve(root, event.path))), (changed) => compiler.invalidate(changed), { discard: true }).pipe(andThen(result(tangle(path))))), orDie$1)))));
10263
8941
  return {
10264
8942
  tangle,
10265
8943
  orphans,
@@ -10317,7 +8995,7 @@ var tangleWatch = (file) => gen(function* () {
10317
8995
  yield* log(`loom: watching ${file} — re-tangling on change`);
10318
8996
  yield* runForEach(tangler.watch(resolve(process.cwd(), file)), match$3({
10319
8997
  onSuccess: reportWritten,
10320
- onFailure: (error$1) => error(error$1.message)
8998
+ onFailure: (error$2) => error(error$2.message)
10321
8999
  }));
10322
9000
  });
10323
9001
  var tangle = (file, watch) => watch ? tangleWatch(file) : tangleOnce(file);
@@ -10392,7 +9070,7 @@ var add = (language) => gen(function* () {
10392
9070
  yield* addService(language, dir);
10393
9071
  yield* updateLanguages(config, dir, (ids) => [.../* @__PURE__ */ new Set([...ids, language])]);
10394
9072
  yield* log(`\n ${teal("✓")} activated ${language}\n ${dim(`store: ${storeDir(dir)}`)}\n`);
10395
- }).pipe(catchTag("StoreError", (error$2) => error(`loom: could not install ${servicePackage(error$2.id)} — ${String(error$2.cause)}`).pipe(andThen(sync(() => void (process.exitCode = 1))))));
9073
+ }).pipe(catchTag("StoreError", (error$1) => error(`loom: could not install ${servicePackage(error$1.id)} — ${String(error$1.cause)}`).pipe(andThen(sync(() => void (process.exitCode = 1))))));
10396
9074
  var remove = (language) => gen(function* () {
10397
9075
  const config = yield* LoomConfig;
10398
9076
  const dir = process.cwd();
@@ -10437,25 +9115,71 @@ var set = (name, value) => gen(function* () {
10437
9115
  const corpus = resolve(workspace, current?.corpus ?? "corpus");
10438
9116
  yield* log(`loom: set ${name} = ${value} (re-tangled ${(yield* tangler.tangle(corpus)).length} files)`);
10439
9117
  }).pipe(catchTag("TangleError", (e) => error(e.message).pipe(andThen(sync(() => void (process.exitCode = 1))))));
10440
- var tangleCommand = make$5("tangle", {
9118
+ var PORT_ONLY = /^[0-9]+$/;
9119
+ var HAS_SCHEME = /^[a-z][a-z0-9+.-]*:\/\//i;
9120
+ var addressOf = (given) => HAS_SCHEME.test(given) ? given : PORT_ONLY.test(given) ? `http://localhost:${given}` : `http://${given}`;
9121
+ var within = (one, other) => one === other || one.startsWith(`${other}/`) || other.startsWith(`${one}/`);
9122
+ var refusalOf = (standing, project, directory) => value(standing).pipe(tag$1("Taken", () => some(`loom: \`${project}\` is registered to another project, and its notes point elsewhere.\n This directory is ${directory}.\n Run Design here under a different name, or run it in the directory that owns \`${project}\`.`)), tag$1("Misplaced", () => some(`loom: \`${project}\` is registered, but ${directory} carries no identity for it.\n This is almost always the wrong directory. Run Design from the project it names.`)), orElse(() => none()));
9123
+ var design = (project, given, port) => {
9124
+ const application = addressOf(given);
9125
+ return gen(function* () {
9126
+ const directory = process.cwd();
9127
+ yield* promise(async () => {
9128
+ const { createRequire } = await import("node:module");
9129
+ const scope = globalThis;
9130
+ scope.require = scope.require ?? createRequire(import.meta.url);
9131
+ });
9132
+ const proxy = yield* tryPromise(() => import("./design-S_129JVC.js"));
9133
+ const kept = yield* tryPromise(() => import("./store-CtvrwAS8.js"));
9134
+ const projects = yield* tryPromise(() => import("./identity-DvFsrt2d.js"));
9135
+ const store = kept.localStore();
9136
+ yield* match$2(refusalOf(yield* projects.settle({
9137
+ project,
9138
+ directory,
9139
+ address: application,
9140
+ store
9141
+ }), project, directory), {
9142
+ onSome: (message) => error(message).pipe(andThen(sync(() => void (process.exitCode = 1)))),
9143
+ onNone: () => gen(function* () {
9144
+ yield* match$2(yield* projects.servedFrom(application), {
9145
+ onNone: () => void_,
9146
+ onSome: (from) => within(from, directory) ? void_ : error(`loom: warning — the server on ${application} is running in ${from}, not in ${directory}`)
9147
+ });
9148
+ yield* log(`loom: Design on http://localhost:${port}, in front of ${application}, noting ${project} in ${directory}`);
9149
+ yield* launch(proxy.designServer({
9150
+ port,
9151
+ application,
9152
+ project,
9153
+ store
9154
+ }));
9155
+ })
9156
+ });
9157
+ }).pipe(catchCause((cause) => error(`loom: Design could not run in front of ${application}\n${pretty(cause)}`).pipe(andThen(sync(() => void (process.exitCode = 1))))));
9158
+ };
9159
+ var tangleCommand = make("tangle", {
10441
9160
  path: string("path"),
10442
9161
  watch: boolean("watch")
10443
9162
  }, ({ path, watch }) => tangle(path, watch));
10444
- var orphansCommand = make$5("orphans", { prune: boolean("prune") }, ({ prune }) => orphans(prune));
10445
- var weaveCommand = make$5("weave", {
9163
+ var orphansCommand = make("orphans", { prune: boolean("prune") }, ({ prune }) => orphans(prune));
9164
+ var weaveCommand = make("weave", {
10446
9165
  path: string("path"),
10447
9166
  out: string("out")
10448
9167
  }, ({ path, out }) => weave(path, out));
10449
- var tocCommand = make$5("toc", { path: string("path") }, ({ path }) => toc(path));
10450
- var initCommand = make$5("init", { dir: optional$1(directory("dir")) }, ({ dir }) => init(dir));
10451
- var addCommand = make$5("add", { language: string("language") }, ({ language }) => add(language));
10452
- var removeCommand = make$5("remove", { language: string("language") }, ({ language }) => remove(language));
10453
- var statusCommand = make$5("status", {}, () => status);
10454
- var setCommand = make$5("set", {
9168
+ var tocCommand = make("toc", { path: string("path") }, ({ path }) => toc(path));
9169
+ var initCommand = make("init", { dir: optional$1(directory("dir")) }, ({ dir }) => init(dir));
9170
+ var addCommand = make("add", { language: string("language") }, ({ language }) => add(language));
9171
+ var removeCommand = make("remove", { language: string("language") }, ({ language }) => remove(language));
9172
+ var statusCommand = make("status", {}, () => status);
9173
+ var setCommand = make("set", {
10455
9174
  name: string("name"),
10456
9175
  value: string("value")
10457
9176
  }, ({ name, value }) => set(name, value));
10458
- var program = run(make$5("loom").pipe(withSubcommands([
9177
+ var designCommand = make("design", {
9178
+ project: string("name"),
9179
+ application: string("address"),
9180
+ port: integer("port").pipe(withDefault(5710))
9181
+ }, ({ project, application, port }) => design(project, application, port));
9182
+ var program = run(make("loom").pipe(withSubcommands([
10459
9183
  tangleCommand,
10460
9184
  orphansCommand,
10461
9185
  weaveCommand,
@@ -10464,12 +9188,13 @@ var program = run(make$5("loom").pipe(withSubcommands([
10464
9188
  addCommand,
10465
9189
  removeCommand,
10466
9190
  statusCommand,
10467
- setCommand
10468
- ])), { version: "0.0.8" }).pipe(provide$1(LoomTangler.layer), provide$1(LoomWeaver.layer), provide$1(LoomContents.layer), provide$1(DocumentSource.layer), provide$1(PackageConfig.layer), provide$1(LoomConfig.layer), provide$1(layer));
9191
+ setCommand,
9192
+ designCommand
9193
+ ])), { version: "0.0.10" }).pipe(provide$1(LoomTangler.layer), provide$1(LoomWeaver.layer), provide$1(LoomContents.layer), provide$1(DocumentSource.layer), provide$1(PackageConfig.layer), provide$1(LoomConfig.layer), provide$1(layer));
10469
9194
  if (process.argv[2] === "lsp") {
10470
9195
  const { createRequire } = await import("node:module");
10471
9196
  globalThis.require = createRequire(import.meta.url);
10472
- const { startLanguageServer } = await import("./LoomServer-CxdKR04b.js");
9197
+ const { startLanguageServer } = await import("./LoomServer-JbCtLtxV.js");
10473
9198
  startLanguageServer();
10474
9199
  } else runMain(program);
10475
9200
  //#endregion