@effect/tsgo 0.16.3 → 0.18.0

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/README.md CHANGED
@@ -22,7 +22,7 @@ This will guide you through the installation process, which includes:
22
22
  4. Hinting at any additional editor configuration needed to ensure the LSP is active.
23
23
 
24
24
  > [!NOTE]
25
- > At the moment, you still need a native TypeScript install alongside `@effect/tsgo` — either `@typescript/native-preview` (nightlies) or `typescript` >= 7 (e.g. the 7.0 RC, `typescript@rc`). `effect-tsgo patch` and `effect-tsgo setup` detect and use whichever one is installed.
25
+ > At the moment, you still need a native TypeScript install alongside `@effect/tsgo`: `typescript` >= 7 (e.g. `typescript@latest` or `typescript@next`) or an alias such as `@typescript/native`. `effect-tsgo patch` tries `typescript`, then `@typescript/native`, and accepts `--typescript-package <name>` to try a custom package name first.
26
26
 
27
27
  ## Diagnostic Status
28
28
 
@@ -1158,15 +1158,15 @@ const symbol$3 = "~effect/interfaces/Hash";
1158
1158
  const hash = (self) => {
1159
1159
  switch (typeof self) {
1160
1160
  case "number": return number$2(self);
1161
- case "bigint": return string$2(self.toString(10));
1162
- case "boolean": return string$2(String(self));
1163
- case "symbol": return string$2(String(self));
1164
- case "string": return string$2(self);
1165
- case "undefined": return string$2("undefined");
1161
+ case "bigint": return string$5(self.toString(10));
1162
+ case "boolean": return string$5(String(self));
1163
+ case "symbol": return string$5(String(self));
1164
+ case "string": return string$5(self);
1165
+ case "undefined": return string$5("undefined");
1166
1166
  case "function":
1167
- case "object": if (self === null) return string$2("null");
1168
- else if (self instanceof Date) return string$2(self.toISOString());
1169
- else if (self instanceof RegExp) return string$2(self.toString());
1167
+ case "object": if (self === null) return string$5("null");
1168
+ else if (self instanceof Date) return string$5(self.toISOString());
1169
+ else if (self instanceof RegExp) return string$5(self.toString());
1170
1170
  else {
1171
1171
  if (byReferenceInstances.has(self)) return random(self);
1172
1172
  if (hashCache.has(self)) return hashCache.get(self);
@@ -1348,9 +1348,9 @@ const isHash = (u) => hasProperty(u, symbol$3);
1348
1348
  * @since 2.0.0
1349
1349
  */
1350
1350
  const number$2 = (n) => {
1351
- if (n !== n) return string$2("NaN");
1352
- if (n === Infinity) return string$2("Infinity");
1353
- if (n === -Infinity) return string$2("-Infinity");
1351
+ if (n !== n) return string$5("NaN");
1352
+ if (n === Infinity) return string$5("Infinity");
1353
+ if (n === -Infinity) return string$5("-Infinity");
1354
1354
  let h = n | 0;
1355
1355
  if (h !== n) h ^= n * 4294967295;
1356
1356
  while (n > 4294967295) h ^= n /= 4294967295;
@@ -1386,7 +1386,7 @@ const number$2 = (n) => {
1386
1386
  * @category hashing
1387
1387
  * @since 2.0.0
1388
1388
  */
1389
- const string$2 = (str) => {
1389
+ const string$5 = (str) => {
1390
1390
  let h = 5381, i = str.length;
1391
1391
  while (i) h = h * 33 ^ str.charCodeAt(--i);
1392
1392
  return optimize(h);
@@ -1510,13 +1510,13 @@ const iterableWith = (seed, f) => (iter) => {
1510
1510
  * @since 2.0.0
1511
1511
  */
1512
1512
  const array = /* @__PURE__ */ iterableWith(6151, hash);
1513
- const hashMap = /* @__PURE__ */ iterableWith(/* @__PURE__ */ string$2("Map"), ([k, v]) => combine$2(hash(k), hash(v)));
1514
- const hashSet = /* @__PURE__ */ iterableWith(/* @__PURE__ */ string$2("Set"), hash);
1513
+ const hashMap = /* @__PURE__ */ iterableWith(/* @__PURE__ */ string$5("Map"), ([k, v]) => combine$2(hash(k), hash(v)));
1514
+ const hashSet = /* @__PURE__ */ iterableWith(/* @__PURE__ */ string$5("Set"), hash);
1515
1515
  const randomHashCache = /* @__PURE__ */ new WeakMap();
1516
1516
  const hashCache = /* @__PURE__ */ new WeakMap();
1517
1517
  const visitedObjects = /* @__PURE__ */ new WeakSet();
1518
1518
  function withVisitedTracking$1(obj, fn) {
1519
- if (visitedObjects.has(obj)) return string$2("[Circular]");
1519
+ if (visitedObjects.has(obj)) return string$5("[Circular]");
1520
1520
  visitedObjects.add(obj);
1521
1521
  const result = fn();
1522
1522
  visitedObjects.delete(obj);
@@ -2632,7 +2632,7 @@ var Fail = class extends ReasonBase {
2632
2632
  return isFailReason$1(that) && equals$2(this.error, that.error) && equals$2(this.annotations, that.annotations);
2633
2633
  }
2634
2634
  [symbol$3]() {
2635
- return combine$2(string$2(this._tag))(combine$2(hash(this.error))(hash(this.annotations)));
2635
+ return combine$2(string$5(this._tag))(combine$2(hash(this.error))(hash(this.annotations)));
2636
2636
  }
2637
2637
  };
2638
2638
  /** @internal */
@@ -2661,7 +2661,7 @@ var Die = class extends ReasonBase {
2661
2661
  return isDieReason$1(that) && equals$2(this.defect, that.defect) && equals$2(this.annotations, that.annotations);
2662
2662
  }
2663
2663
  [symbol$3]() {
2664
- return combine$2(string$2(this._tag))(combine$2(hash(this.defect))(hash(this.annotations)));
2664
+ return combine$2(string$5(this._tag))(combine$2(hash(this.defect))(hash(this.annotations)));
2665
2665
  }
2666
2666
  };
2667
2667
  /** @internal */
@@ -2721,7 +2721,7 @@ const makeExit = (options) => {
2721
2721
  return isExit$1(that) && that._tag === this._tag && equals$2(this[args], that[args]);
2722
2722
  },
2723
2723
  [symbol$3]() {
2724
- return combine$2(string$2(options.op), hash(this[args]));
2724
+ return combine$2(string$5(options.op), hash(this[args]));
2725
2725
  }
2726
2726
  };
2727
2727
  return function(value) {
@@ -6850,7 +6850,7 @@ const fromPredicate = (predicate) => (input) => predicate(input) ? succeed$4(inp
6850
6850
  * @category constructors
6851
6851
  * @since 4.0.0
6852
6852
  */
6853
- const string$1 = /* @__PURE__ */ fromPredicate(isString);
6853
+ const string$4 = /* @__PURE__ */ fromPredicate(isString);
6854
6854
  /**
6855
6855
  * A predefined filter that only passes through number values.
6856
6856
  *
@@ -7536,7 +7536,7 @@ var Interrupt = class extends ReasonBase {
7536
7536
  return isInterruptReason$1(that) && this.fiberId === that.fiberId && this.annotations === that.annotations;
7537
7537
  }
7538
7538
  [symbol$3]() {
7539
- return combine$2(string$2(`${this._tag}:${this.fiberId}`))(random(this.annotations));
7539
+ return combine$2(string$5(`${this._tag}:${this.fiberId}`))(random(this.annotations));
7540
7540
  }
7541
7541
  };
7542
7542
  /** @internal */
@@ -14187,7 +14187,7 @@ const ProtoTimeZoneNamed = {
14187
14187
  ...ProtoTimeZone,
14188
14188
  _tag: "Named",
14189
14189
  [symbol$3]() {
14190
- return string$2(`Named:${this.id}`);
14190
+ return string$5(`Named:${this.id}`);
14191
14191
  },
14192
14192
  [symbol$2](that) {
14193
14193
  return isTimeZone$1(that) && that._tag === "Named" && this.id === that.id;
@@ -14207,7 +14207,7 @@ const ProtoTimeZoneOffset = {
14207
14207
  ...ProtoTimeZone,
14208
14208
  _tag: "Offset",
14209
14209
  [symbol$3]() {
14210
- return string$2(`Offset:${this.offset}`);
14210
+ return string$5(`Offset:${this.offset}`);
14211
14211
  },
14212
14212
  [symbol$2](that) {
14213
14213
  return isTimeZone$1(that) && that._tag === "Offset" && this.offset === that.offset;
@@ -27499,6 +27499,51 @@ function BigInt$3() {
27499
27499
  function Date$2() {
27500
27500
  return transform$2((u) => new globalThis.Date(u));
27501
27501
  }
27502
+ function parseJson(options) {
27503
+ return onSome((input) => try_({
27504
+ try: () => some(JSON.parse(input, options?.reviver)),
27505
+ catch: (e) => new InvalidValue$1(some(input), { message: globalThis.String(e) })
27506
+ }));
27507
+ }
27508
+ /**
27509
+ * Stringifies a present value using `JSON.stringify`.
27510
+ *
27511
+ * **When to use**
27512
+ *
27513
+ * Use when you need a schema getter to serialize a present decoded value to
27514
+ * JSON text during encoding.
27515
+ *
27516
+ * **Details**
27517
+ *
27518
+ * - Skips `None` inputs.
27519
+ * - On thrown stringify failures, such as circular references, fails with
27520
+ * `SchemaIssue.InvalidValue`.
27521
+ * - Supports optional `replacer` and `space` options, matching
27522
+ * `JSON.stringify`.
27523
+ * - If `JSON.stringify` returns `undefined`, such as for `undefined`,
27524
+ * functions, symbols, or a replacer that removes the root value, that
27525
+ * `undefined` result is returned rather than converted into an `Issue`.
27526
+ *
27527
+ * **Example** (Stringify JSON)
27528
+ *
27529
+ * ```ts
27530
+ * import { SchemaGetter } from "effect"
27531
+ *
27532
+ * const stringify = SchemaGetter.stringifyJson()
27533
+ * // Getter<string, unknown>
27534
+ * ```
27535
+ *
27536
+ * @see {@link parseJson} for the inverse operation
27537
+ *
27538
+ * @category JSON getters
27539
+ * @since 4.0.0
27540
+ */
27541
+ function stringifyJson(options) {
27542
+ return onSome((input) => try_({
27543
+ try: () => some(JSON.stringify(input, options?.replacer, options?.space)),
27544
+ catch: (e) => new InvalidValue$1(some(input), { message: globalThis.String(e) })
27545
+ }));
27546
+ }
27502
27547
  /**
27503
27548
  * Splits a string into an array of strings by a separator.
27504
27549
  *
@@ -29298,6 +29343,38 @@ const stringFromHexString = /* @__PURE__ */ new Transformation(/* @__PURE__ */ d
29298
29343
  */
29299
29344
  const stringFromUriComponent = /* @__PURE__ */ new Transformation(/* @__PURE__ */ decodeUriComponent(), /* @__PURE__ */ encodeUriComponent());
29300
29345
  /**
29346
+ * Decodes a JSON string with `JSON.parse` and encodes a value with
29347
+ * `JSON.stringify`.
29348
+ *
29349
+ * **When to use**
29350
+ *
29351
+ * Use when you need a schema transformation to decode JSON stored or
29352
+ * transmitted as a string, usually before composing with another schema that
29353
+ * validates the parsed structure.
29354
+ *
29355
+ * **Details**
29356
+ *
29357
+ * Decode fails with `InvalidValue` for invalid JSON, and encode can fail with
29358
+ * `InvalidValue` when `JSON.stringify` cannot serialize the value.
29359
+ *
29360
+ * **Example** (Parsing JSON)
29361
+ *
29362
+ * ```ts
29363
+ * import { Schema, SchemaTransformation } from "effect"
29364
+ *
29365
+ * const schema = Schema.String.pipe(
29366
+ * Schema.decodeTo(Schema.Unknown, SchemaTransformation.fromJsonString)
29367
+ * )
29368
+ * ```
29369
+ *
29370
+ * @see {@link uint8ArrayFromBase64String}
29371
+ * @see {@link fromFormData}
29372
+ *
29373
+ * @category decoding
29374
+ * @since 4.0.0
29375
+ */
29376
+ const fromJsonString$1 = /* @__PURE__ */ new Transformation(/* @__PURE__ */ parseJson(), /* @__PURE__ */ stringifyJson());
29377
+ /**
29301
29378
  * Decodes a numeric time-zone offset in milliseconds into a
29302
29379
  * `DateTime.TimeZone.Offset` and encodes it back to the offset number.
29303
29380
  *
@@ -30006,7 +30083,7 @@ var String$2 = class extends Base {
30006
30083
  * @category constructors
30007
30084
  * @since 4.0.0
30008
30085
  */
30009
- const string = /* @__PURE__ */ new String$2();
30086
+ const string$3 = /* @__PURE__ */ new String$2();
30010
30087
  /**
30011
30088
  * AST node matching any `number` value (including `NaN`, `Infinity`,
30012
30089
  * `-Infinity`).
@@ -31369,7 +31446,7 @@ function isStringFinite$1(annotations) {
31369
31446
  ...annotations
31370
31447
  });
31371
31448
  }
31372
- const finiteString = /* @__PURE__ */ appendChecks(string, [/* @__PURE__ */ isStringFinite$1()]);
31449
+ const finiteString = /* @__PURE__ */ appendChecks(string$3, [/* @__PURE__ */ isStringFinite$1()]);
31373
31450
  const finiteToString = /* @__PURE__ */ new Link(finiteString, numberFromString);
31374
31451
  const numberToString = /* @__PURE__ */ new Link(/* @__PURE__ */ new Union$1([finiteString, nonFiniteLiterals], "anyOf"), numberFromString);
31375
31452
  /**
@@ -31389,11 +31466,11 @@ function isStringBigInt$1(annotations) {
31389
31466
  });
31390
31467
  }
31391
31468
  /** @internal */
31392
- const bigIntString = /* @__PURE__ */ appendChecks(string, [/* @__PURE__ */ isStringBigInt$1({ expected: "a string representing a bigint" })]);
31469
+ const bigIntString = /* @__PURE__ */ appendChecks(string$3, [/* @__PURE__ */ isStringBigInt$1({ expected: "a string representing a bigint" })]);
31393
31470
  const bigIntToString = /* @__PURE__ */ new Link(bigIntString, bigintFromString);
31394
31471
  const isStringSymbolRegExp = /* @__PURE__ */ new globalThis.RegExp(`^Symbol\\((.*)\\)$`);
31395
31472
  /** @internal */
31396
- const symbolString = /* @__PURE__ */ appendChecks(string, [/* @__PURE__ */ isStringSymbol$1()]);
31473
+ const symbolString = /* @__PURE__ */ appendChecks(string$3, [/* @__PURE__ */ isStringSymbol$1()]);
31397
31474
  /**
31398
31475
  * to distinguish between Symbol and String, we need to add a check to the string keyword
31399
31476
  */
@@ -38202,7 +38279,7 @@ const Undefined = /* @__PURE__ */ make$5(undefined_);
38202
38279
  * @category schemas
38203
38280
  * @since 4.0.0
38204
38281
  */
38205
- const String$1 = /* @__PURE__ */ make$5(string);
38282
+ const String$1 = /* @__PURE__ */ make$5(string$3);
38206
38283
  /**
38207
38284
  * Schema for `number` values, including `NaN`, `Infinity`, and `-Infinity`.
38208
38285
  *
@@ -39759,6 +39836,79 @@ const BigDecimal = /* @__PURE__ */ declare(isBigDecimal, {
39759
39836
  */
39760
39837
  const BigDecimalFromString = /* @__PURE__ */ BigDecimalString.pipe(/* @__PURE__ */ decodeTo(BigDecimal, bigDecimalFromString));
39761
39838
  /**
39839
+ * Returns a schema that decodes a JSON string and then decodes the parsed value
39840
+ * using the given schema.
39841
+ *
39842
+ * **Details**
39843
+ *
39844
+ * This is useful when working with JSON-encoded strings where the actual
39845
+ * structure of the value is known and described by an existing schema.
39846
+ *
39847
+ * The resulting schema first parses the input string as JSON, and then runs the
39848
+ * provided schema on the parsed result.
39849
+ *
39850
+ * JSON Schema generation:
39851
+ *
39852
+ * When using `fromJsonString` with `draft-2020-12` or `openApi3.1`, the
39853
+ * resulting schema will be a JSON Schema with a `contentSchema` property that
39854
+ * contains the JSON Schema for the given schema.
39855
+ *
39856
+ * **Example** (Decoding JSON strings with a schema)
39857
+ *
39858
+ * ```ts
39859
+ * import { Schema } from "effect"
39860
+ *
39861
+ * const schema = Schema.Struct({ a: Schema.Number })
39862
+ * const schemaFromJsonString = Schema.fromJsonString(schema)
39863
+ *
39864
+ * Schema.decodeUnknownSync(schemaFromJsonString)(`{"a":1,"b":2}`)
39865
+ * // => { a: 1 }
39866
+ * ```
39867
+ *
39868
+ * **Example** (Emitting JSON Schema for a JSON string decoder)
39869
+ *
39870
+ * ```ts
39871
+ * import { Schema } from "effect"
39872
+ *
39873
+ * const original = Schema.Struct({ a: Schema.String })
39874
+ * const schema = Schema.fromJsonString(original)
39875
+ *
39876
+ * const document = Schema.toJsonSchemaDocument(schema)
39877
+ *
39878
+ * console.log(JSON.stringify(document, null, 2))
39879
+ * // {
39880
+ * // "source": "draft-2020-12",
39881
+ * // "schema": {
39882
+ * // "type": "string",
39883
+ * // "contentMediaType": "application/json",
39884
+ * // "contentSchema": {
39885
+ * // "type": "object",
39886
+ * // "properties": {
39887
+ * // "a": {
39888
+ * // "type": "string"
39889
+ * // }
39890
+ * // },
39891
+ * // "required": [
39892
+ * // "a"
39893
+ * // ],
39894
+ * // "additionalProperties": false
39895
+ * // }
39896
+ * // },
39897
+ * // "definitions": {}
39898
+ * // }
39899
+ * ```
39900
+ *
39901
+ * @category constructors
39902
+ * @since 4.0.0
39903
+ */
39904
+ function fromJsonString(schema) {
39905
+ return String$1.annotate({
39906
+ expected: "a string that will be decoded as JSON",
39907
+ contentMediaType: "application/json",
39908
+ contentSchema: toEncoded(schema.ast)
39909
+ }).pipe(decodeTo(schema, fromJsonString$1));
39910
+ }
39911
+ /**
39762
39912
  * Schema for JavaScript `File` objects.
39763
39913
  *
39764
39914
  * **Details**
@@ -40536,7 +40686,7 @@ const toCodecEnsureArray = /* @__PURE__ */ toCodec((ast) => {
40536
40686
  if (isUnion(ast) && ast.annotations?.[SERIALIZER_ENSURE_ARRAY]) return ast;
40537
40687
  const out = onSerializerEnsureArray(ast);
40538
40688
  if (isArrays(out)) {
40539
- const ensure = new Union$1([out, decodeTo$1(string, out, new Transformation(split(), passthrough$1()))], "anyOf", { [SERIALIZER_ENSURE_ARRAY]: true });
40689
+ const ensure = new Union$1([out, decodeTo$1(string$3, out, new Transformation(split(), passthrough$1()))], "anyOf", { [SERIALIZER_ENSURE_ARRAY]: true });
40540
40690
  return isOptional(ast) ? optionalKey$1(ensure) : ensure;
40541
40691
  }
40542
40692
  return out;
@@ -53690,6 +53840,31 @@ const integer = /* @__PURE__ */ makeSchemaPrimitive("Integer", Int);
53690
53840
  */
53691
53841
  const date = /* @__PURE__ */ makeSchemaPrimitive("Date", DateValid);
53692
53842
  /**
53843
+ * Creates a primitive that accepts any string value without validation.
53844
+ *
53845
+ * **Example** (Parsing string values)
53846
+ *
53847
+ * ```ts
53848
+ * import { Effect } from "effect"
53849
+ * import { Primitive } from "effect/unstable/cli"
53850
+ *
53851
+ * const parseString = Effect.gen(function*() {
53852
+ * const result1 = yield* Primitive.string.parse("hello world")
53853
+ * console.log(result1) // "hello world"
53854
+ *
53855
+ * const result2 = yield* Primitive.string.parse("")
53856
+ * console.log(result2) // ""
53857
+ *
53858
+ * const result3 = yield* Primitive.string.parse("123")
53859
+ * console.log(result3) // "123"
53860
+ * })
53861
+ * ```
53862
+ *
53863
+ * @category constructors
53864
+ * @since 4.0.0
53865
+ */
53866
+ const string$2 = /* @__PURE__ */ makePrimitive("String", (value) => succeed(value));
53867
+ /**
53693
53868
  * Creates a primitive that accepts only specific choice values mapped to custom types.
53694
53869
  *
53695
53870
  * **Example** (Parsing choices)
@@ -54834,6 +55009,33 @@ const makeSingle = (params) => {
54834
55009
  });
54835
55010
  };
54836
55011
  /**
55012
+ * Creates a string parameter.
55013
+ *
55014
+ * **Example** (Creating string parameters)
55015
+ *
55016
+ * ```ts
55017
+ * import { Param } from "effect/unstable/cli"
55018
+ *
55019
+ * // @internal - this module is not exported publicly
55020
+ *
55021
+ * // Create a string flag
55022
+ * const nameFlag = Param.string(Param.flagKind, "name")
55023
+ *
55024
+ * // Create a string argument
55025
+ * const fileArg = Param.string(Param.argumentKind, "file")
55026
+ *
55027
+ * // Usage in CLI: --name "John Doe" or as positional argument
55028
+ * ```
55029
+ *
55030
+ * @category constructors
55031
+ * @since 4.0.0
55032
+ */
55033
+ const string$1 = (kind, name) => makeSingle({
55034
+ name,
55035
+ primitiveType: string$2,
55036
+ kind
55037
+ });
55038
+ /**
54837
55039
  * Creates a boolean parameter.
54838
55040
  *
54839
55041
  * **Example** (Creating boolean parameters)
@@ -55406,6 +55608,22 @@ const getParamMetadata = (param) => {
55406
55608
  //#endregion
55407
55609
  //#region ../../node_modules/.pnpm/effect@4.0.0-beta.83/node_modules/effect/dist/unstable/cli/Flag.js
55408
55610
  /**
55611
+ * Creates a string flag that accepts text input.
55612
+ *
55613
+ * **Example** (Creating string flags)
55614
+ *
55615
+ * ```ts
55616
+ * import { Flag } from "effect/unstable/cli"
55617
+ *
55618
+ * const nameFlag = Flag.string("name")
55619
+ * // Usage: --name "John Doe"
55620
+ * ```
55621
+ *
55622
+ * @category constructors
55623
+ * @since 4.0.0
55624
+ */
55625
+ const string = (name) => string$1(flagKind, name);
55626
+ /**
55409
55627
  * Creates a boolean flag that can be enabled or disabled.
55410
55628
  *
55411
55629
  * **Example** (Creating boolean flags)
@@ -204437,17 +204655,14 @@ var FileReadError = class extends TaggedError("FileReadError") {
204437
204655
  //#endregion
204438
204656
  //#region package.json
204439
204657
  var name = "@effect/tsgo";
204440
- var version = "0.16.3";
204658
+ var version = "0.18.0";
204441
204659
 
204442
204660
  //#endregion
204443
204661
  //#region src/setup/consts.ts
204444
204662
  const LSP_PACKAGE_NAME = name;
204445
204663
  const LSP_PLUGIN_NAME = "@effect/language-service";
204446
- const NATIVE_PREVIEW_PACKAGE_NAME = "@typescript/native-preview";
204447
- const TYPESCRIPT_PACKAGE_NAME = "typescript";
204664
+ const defaultTypescriptPackageNames = ["typescript", "@typescript/native"];
204448
204665
  const PATCH_COMMAND = "effect-tsgo patch";
204449
- const DEFAULT_LSP_VERSION = version;
204450
- const DEFAULT_NATIVE_PREVIEW_VERSION = "latest";
204451
204666
  const TSCONFIG_SCHEMA_URL = "https://raw.githubusercontent.com/Effect-TS/tsgo/refs/heads/main/schema.json";
204452
204667
  /**
204453
204668
  * `typescript` package versions >= 7 ship the native Go-ported binary that this
@@ -204458,24 +204673,8 @@ const isNativeTypescriptVersion = (version) => {
204458
204673
  const match = /\d+/.exec(version.trim());
204459
204674
  return match !== null && Number(match[0]) >= 7;
204460
204675
  };
204461
- /** The `@typescript/native-preview` nightly backend (back-compat default). */
204462
- const nativePreviewBackend = {
204463
- packageName: NATIVE_PREVIEW_PACKAGE_NAME,
204464
- platformPackagePrefix: "@typescript/native-preview",
204465
- binaryName: "tsgo"
204466
- };
204467
- /** The `typescript` >= 7 backend (stable/RC releases). */
204468
- const typescriptBackend = {
204469
- packageName: TYPESCRIPT_PACKAGE_NAME,
204470
- platformPackagePrefix: "@typescript/typescript",
204471
- binaryName: "tsc",
204472
- versionCheck: (pkg) => isNativeTypescriptVersion(pkg.version ?? "0")
204473
- };
204474
204676
  /**
204475
- * Resolve the VS Code `typescript.native-preview.tsdk` folder for a backend.
204476
- * The "TypeScript (Native Preview)" extension reads the native install from
204477
- * this path; for `@typescript/native-preview` it is `node_modules/<pkg>`, and
204478
- * for `typescript` >= 7 it is `node_modules/typescript`.
204677
+ * Resolve the VS Code TypeScript 7 tsdk folder.
204479
204678
  */
204480
204679
  const nativeBackendTsdkPath = (packageName) => "node_modules/" + packageName;
204481
204680
 
@@ -204533,14 +204732,17 @@ const assessPackageJson = (input) => {
204533
204732
  return none$3();
204534
204733
  };
204535
204734
  const lspVersion = assessDependency(LSP_PACKAGE_NAME);
204536
- const nativePreviewVersion = orElse(assessDependency(NATIVE_PREVIEW_PACKAGE_NAME), () => {
204537
- const typescriptDep = assessDependency(TYPESCRIPT_PACKAGE_NAME);
204538
- if (isSome(typescriptDep) && isNativeTypescriptVersion(typescriptDep.value.version)) return some({
204539
- ...typescriptDep.value,
204540
- packageName: TYPESCRIPT_PACKAGE_NAME
204541
- });
204542
- return none$3();
204543
- });
204735
+ let typescriptVersion = none$3();
204736
+ for (const packageName of defaultTypescriptPackageNames) {
204737
+ const typescriptDep = assessDependency(packageName);
204738
+ if (isSome(typescriptDep) && isNativeTypescriptVersion(typescriptDep.value.version)) {
204739
+ typescriptVersion = some({
204740
+ ...typescriptDep.value,
204741
+ packageName
204742
+ });
204743
+ break;
204744
+ }
204745
+ }
204544
204746
  const prepareScript = "prepare" in (parsed.scripts ?? {}) ? some({
204545
204747
  script: parsed.scripts.prepare,
204546
204748
  hasPatch: parsed.scripts.prepare.toLowerCase().includes(PATCH_COMMAND)
@@ -204551,7 +204753,7 @@ const assessPackageJson = (input) => {
204551
204753
  parsed,
204552
204754
  text: input.text,
204553
204755
  lspVersion,
204554
- nativePreviewVersion,
204756
+ typescriptVersion,
204555
204757
  prepareScript
204556
204758
  };
204557
204759
  };
@@ -204890,17 +205092,20 @@ const computePackageJsonChanges = (current, target) => {
204890
205092
  if (!rootObj) return emptyFileChangesResult();
204891
205093
  const ctx = createTrackerContext();
204892
205094
  const fileChange = tsInternal.textChanges.ChangeTracker.with(ctx, (tracker) => {
204893
- const nativeBackendPackageName = match$8(target.nativePreviewVersion, {
204894
- onNone: () => NATIVE_PREVIEW_PACKAGE_NAME,
204895
- onSome: (dep) => dep.packageName ?? NATIVE_PREVIEW_PACKAGE_NAME
204896
- });
204897
- const shouldAddNativePreviewWithDependencyType = (dependencyType) => isSome(target.nativePreviewVersion) && isNone(current.nativePreviewVersion) && target.nativePreviewVersion.value.dependencyType === dependencyType;
204898
- const ensureNativePreviewDependency = () => {
204899
- if (isNone(target.nativePreviewVersion) || isSome(current.nativePreviewVersion)) return;
204900
- const targetNativePreview = target.nativePreviewVersion.value;
204901
- if (!findDependencyCollectionProperty(rootObj, targetNativePreview.dependencyType) && isSome(target.lspVersion) && target.lspVersion.value.dependencyType === targetNativePreview.dependencyType) return;
204902
- descriptions.push(`Add ${nativeBackendPackageName}@${targetNativePreview.version} to ${targetNativePreview.dependencyType}`);
204903
- upsertDependency(tracker, current.sourceFile, rootObj, nativeBackendPackageName, targetNativePreview);
205095
+ const shouldAddTypescriptWithDependencyType = (dependencyType) => isSome(target.typescriptVersion) && isNone(current.typescriptVersion) && target.typescriptVersion.value.dependencyType === dependencyType;
205096
+ const getTypescriptPackageName = (dependency) => dependency.packageName ?? defaultTypescriptPackageNames[0];
205097
+ const appendTypescriptDependencyProperty = (dependencyProperties) => {
205098
+ const targetTypescript = target.typescriptVersion.pipe(getOrUndefined);
205099
+ if (!targetTypescript) return;
205100
+ dependencyProperties.push(import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(getTypescriptPackageName(targetTypescript)), import_typescript.factory.createStringLiteral(targetTypescript.version)));
205101
+ };
205102
+ const ensureTypescriptDependency = () => {
205103
+ if (isNone(target.typescriptVersion) || isSome(current.typescriptVersion)) return;
205104
+ const targetTypescript = target.typescriptVersion.value;
205105
+ const targetTypescriptPackageName = getTypescriptPackageName(targetTypescript);
205106
+ if (!findDependencyCollectionProperty(rootObj, targetTypescript.dependencyType) && isSome(target.lspVersion) && target.lspVersion.value.dependencyType === targetTypescript.dependencyType) return;
205107
+ descriptions.push(`Add ${targetTypescriptPackageName}@${targetTypescript.version} to ${targetTypescript.dependencyType}`);
205108
+ upsertDependency(tracker, current.sourceFile, rootObj, targetTypescriptPackageName, targetTypescript);
204904
205109
  };
204905
205110
  if (isSome(target.lspVersion)) {
204906
205111
  const targetDepType = target.lspVersion.value.dependencyType;
@@ -204918,10 +205123,7 @@ const computePackageJsonChanges = (current, target) => {
204918
205123
  const newDepsProperty = findDependencyCollectionProperty(rootObj, targetDepType);
204919
205124
  if (!newDepsProperty) {
204920
205125
  const dependencyProperties = [import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(LSP_PACKAGE_NAME), import_typescript.factory.createStringLiteral(targetVersion))];
204921
- if (shouldAddNativePreviewWithDependencyType(targetDepType)) {
204922
- const targetNativePreview = target.nativePreviewVersion.pipe(getOrUndefined);
204923
- if (targetNativePreview) dependencyProperties.push(import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(nativeBackendPackageName), import_typescript.factory.createStringLiteral(targetNativePreview.version)));
204924
- }
205126
+ if (shouldAddTypescriptWithDependencyType(targetDepType)) appendTypescriptDependencyProperty(dependencyProperties);
204925
205127
  const newDepsProp = import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(targetDepType), import_typescript.factory.createObjectLiteralExpression(dependencyProperties, false));
204926
205128
  insertNodeAtEndOfList(tracker, current.sourceFile, rootObj.properties, newDepsProp);
204927
205129
  } else if (import_typescript.isObjectLiteralExpression(newDepsProperty.initializer)) insertNodeAtEndOfList(tracker, current.sourceFile, newDepsProperty.initializer.properties, import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(LSP_PACKAGE_NAME), import_typescript.factory.createStringLiteral(targetVersion)));
@@ -204938,15 +205140,12 @@ const computePackageJsonChanges = (current, target) => {
204938
205140
  const depsProperty = findDependencyCollectionProperty(rootObj, targetDepType);
204939
205141
  if (!depsProperty) {
204940
205142
  const dependencyProperties = [import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(LSP_PACKAGE_NAME), import_typescript.factory.createStringLiteral(targetVersion))];
204941
- if (shouldAddNativePreviewWithDependencyType(targetDepType)) {
204942
- const targetNativePreview = target.nativePreviewVersion.pipe(getOrUndefined);
204943
- if (targetNativePreview) dependencyProperties.push(import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(nativeBackendPackageName), import_typescript.factory.createStringLiteral(targetNativePreview.version)));
204944
- }
205143
+ if (shouldAddTypescriptWithDependencyType(targetDepType)) appendTypescriptDependencyProperty(dependencyProperties);
204945
205144
  const newDepsProp = import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(targetDepType), import_typescript.factory.createObjectLiteralExpression(dependencyProperties, false));
204946
205145
  insertNodeAtEndOfList(tracker, current.sourceFile, rootObj.properties, newDepsProp);
204947
205146
  } else if (import_typescript.isObjectLiteralExpression(depsProperty.initializer)) insertNodeAtEndOfList(tracker, current.sourceFile, depsProperty.initializer.properties, import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(LSP_PACKAGE_NAME), import_typescript.factory.createStringLiteral(targetVersion)));
204948
205147
  }
204949
- ensureNativePreviewDependency();
205148
+ ensureTypescriptDependency();
204950
205149
  } else if (isSome(current.lspVersion)) {
204951
205150
  descriptions.push(`Remove ${LSP_PACKAGE_NAME} from dependencies`);
204952
205151
  const currentDepType = current.lspVersion.value.dependencyType;
@@ -205230,7 +205429,7 @@ const computeChanges = (assessment, target) => {
205230
205429
  if (target.editors.includes("vscode")) messages = [
205231
205430
  ...messages,
205232
205431
  "VS Code / Cursor / VS Code-based editors:",
205233
- " 1. Install the @typescript/native-preview extension",
205432
+ " 1. Install the TypeScript 7 extension",
205234
205433
  " 2. Open a TypeScript file and ensure the native TS server is active",
205235
205434
  " 3. The language service plugin will be loaded automatically",
205236
205435
  ""
@@ -207159,7 +207358,7 @@ function createRulePrompt(rules, initialSeverities) {
207159
207358
  const fromAssessment = (inputState) => ({
207160
207359
  packageJson: {
207161
207360
  lspVersion: inputState.packageJson.lspVersion,
207162
- nativePreviewVersion: inputState.packageJson.nativePreviewVersion,
207361
+ typescriptVersion: inputState.packageJson.typescriptVersion,
207163
207362
  prepareScript: map$10(inputState.packageJson.prepareScript, (_) => _.hasPatch).pipe(getOrElse$1(() => false))
207164
207363
  },
207165
207364
  tsconfig: { diagnosticSeverities: inputState.tsconfig.currentDiagnosticSeverities },
@@ -207331,7 +207530,7 @@ const gatherTargetState = (assessment, context) => gen(function* () {
207331
207530
  if (lspDependencyType === "no") return {
207332
207531
  packageJson: {
207333
207532
  lspVersion: none$3(),
207334
- nativePreviewVersion: assessment.packageJson.nativePreviewVersion,
207533
+ typescriptVersion: assessment.packageJson.typescriptVersion,
207335
207534
  prepareScript: false
207336
207535
  },
207337
207536
  tsconfig: { diagnosticSeverities: none$3() },
@@ -207378,12 +207577,9 @@ const gatherTargetState = (assessment, context) => gen(function* () {
207378
207577
  }
207379
207578
  ]
207380
207579
  });
207381
- const nativeBackendPackage = match$8(assessment.packageJson.nativePreviewVersion, {
207382
- onNone: () => NATIVE_PREVIEW_PACKAGE_NAME,
207383
- onSome: (dep) => dep.packageName ?? NATIVE_PREVIEW_PACKAGE_NAME
207384
- });
207580
+ const defaultTypescriptPackageName = defaultTypescriptPackageNames[0];
207385
207581
  const vscodeSettings = editors.includes("vscode") ? some({ settings: {
207386
- "typescript.native-preview.tsdk": nativeBackendTsdkPath(nativeBackendPackage),
207582
+ "typescript.native-preview.tsdk": nativeBackendTsdkPath(defaultTypescriptPackageName),
207387
207583
  "typescript.experimental.useTsgo": true,
207388
207584
  "js/ts.experimental.useTsgo": true
207389
207585
  } }) : none$3();
@@ -207393,9 +207589,10 @@ const gatherTargetState = (assessment, context) => gen(function* () {
207393
207589
  dependencyType: lspDependencyType,
207394
207590
  version: context.defaultLspVersion
207395
207591
  }),
207396
- nativePreviewVersion: orElse(assessment.packageJson.nativePreviewVersion, () => some({
207592
+ typescriptVersion: orElse(assessment.packageJson.typescriptVersion, () => some({
207397
207593
  dependencyType: lspDependencyType,
207398
- version: DEFAULT_NATIVE_PREVIEW_VERSION
207594
+ version: context.defaultTypescriptVersion,
207595
+ packageName: defaultTypescriptPackageName
207399
207596
  })),
207400
207597
  prepareScript: true
207401
207598
  },
@@ -207405,6 +207602,10 @@ const gatherTargetState = (assessment, context) => gen(function* () {
207405
207602
  };
207406
207603
  });
207407
207604
 
207605
+ //#endregion
207606
+ //#region upstream.json
207607
+ var tsVersion = "7.1.0-dev.20260708.3";
207608
+
207408
207609
  //#endregion
207409
207610
  //#region src/setup/index.ts
207410
207611
  const setupCommand = make("setup").pipe(withDescription("Setup @effect/tsgo for the given project using an interactive CLI."), withHandler(() => gen(function* () {
@@ -207412,7 +207613,10 @@ const setupCommand = make("setup").pipe(withDescription("Setup @effect/tsgo for
207412
207613
  const tsconfigInput = yield* selectTsConfigFile(currentDir);
207413
207614
  const assessmentInput = yield* createAssessmentInput(currentDir, tsconfigInput);
207414
207615
  const assessmentState = assess(assessmentInput);
207415
- const targetState = yield* gatherTargetState(assessmentState, { defaultLspVersion: DEFAULT_LSP_VERSION });
207616
+ const targetState = yield* gatherTargetState(assessmentState, {
207617
+ defaultLspVersion: version,
207618
+ defaultTypescriptVersion: tsVersion
207619
+ });
207416
207620
  const result = computeChanges(assessmentState, targetState);
207417
207621
  yield* reviewAndApplyChanges(result, assessmentState, { cancelMessage: "Setup cancelled. No changes were made." });
207418
207622
  })));
@@ -207421,7 +207625,27 @@ const setupCommand = make("setup").pipe(withDescription("Setup @effect/tsgo for
207421
207625
  //#region src/cli.ts
207422
207626
  var NativeBackendNotInstalledError = class extends TaggedError("NativeBackendNotInstalledError") {
207423
207627
  get message() {
207424
- return "No native TypeScript backend is installed. Install one of the following first: `@typescript/native-preview` or `typescript` (>= 7, e.g. `typescript@rc`).";
207628
+ return "No native TypeScript backend is installed. Install `typescript` >= 7 first (e.g. `typescript@latest` or `typescript@next`) or `@typescript/native` (e.g. `@typescript/native@npm:typescript@latest`). Tried: " + this.packageNames.join(", ") + ".";
207629
+ }
207630
+ };
207631
+ var PackageNotFoundError = class extends TaggedError("PackageNotFoundError") {
207632
+ get message() {
207633
+ return `Unable to resolve ${this.packageName}.`;
207634
+ }
207635
+ };
207636
+ var ParsePackageJsonError = class extends TaggedError("ParsePackageJsonError") {
207637
+ get message() {
207638
+ return `Unable to parse ${this.packageName} package.json at ${this.packageJsonPath}: ${this.reason}`;
207639
+ }
207640
+ };
207641
+ var BinaryMetadataNotFoundError = class extends TaggedError("BinaryMetadataNotFoundError") {
207642
+ get message() {
207643
+ return `Binary metadata not found at ${this.metadataPath}.`;
207644
+ }
207645
+ };
207646
+ var ParseBinaryMetadataError = class extends TaggedError("ParseBinaryMetadataError") {
207647
+ get message() {
207648
+ return `Unable to parse binary metadata at ${this.metadataPath}: ${this.reason}`;
207425
207649
  }
207426
207650
  };
207427
207651
  var UnsupportedPlatformPackageError = class extends TaggedError("UnsupportedPlatformPackageError") {
@@ -207439,6 +207663,22 @@ var ResolvePackagedBinaryError = class extends TaggedError("ResolvePackagedBinar
207439
207663
  return this.reason;
207440
207664
  }
207441
207665
  };
207666
+ var PackagedBinaryVersionMismatchError = class extends TaggedError("PackagedBinaryVersionMismatchError") {
207667
+ get message() {
207668
+ const tried = this.candidates.length === 0 ? " none" : this.candidates.map((candidate) => {
207669
+ if (candidate.tsVersion !== void 0 && candidate.tsGitHead !== void 0) return ` ${candidate.binaryName}: TypeScript ${candidate.tsVersion}, gitHead ${candidate.tsGitHead}`;
207670
+ return ` ${candidate.binaryName}: ${candidate.reason ?? "metadata unavailable"}`;
207671
+ }).join("\n");
207672
+ return [
207673
+ `No packaged Effect TypeScript binary matches installed TypeScript ${this.installedVersion} gitHead ${this.installedGitHead}.`,
207674
+ "",
207675
+ "Tried:",
207676
+ tried,
207677
+ "",
207678
+ "Install a matching @effect/tsgo release or a matching TypeScript version, or rerun with --force to use the newest packaged binary."
207679
+ ].join("\n");
207680
+ }
207681
+ };
207442
207682
  var BackupRestoreError = class extends TaggedError("BackupRestoreError") {
207443
207683
  get message() {
207444
207684
  return this.reason;
@@ -207459,74 +207699,95 @@ var VerificationFailedError = class extends TaggedError("VerificationFailedError
207459
207699
  return "Warning: verification failed for " + this.targetPath + ", but binary was patched. The binary may still work correctly.";
207460
207700
  }
207461
207701
  };
207462
- const probeBackend = (backend, cwdRequire, path) => {
207463
- const isWin = process.platform === "win32";
207464
- let mainPkg;
207465
- try {
207466
- mainPkg = cwdRequire(backend.packageName + "/package.json");
207467
- } catch {
207468
- return { _tag: "notInstalled" };
207469
- }
207470
- if (backend.versionCheck !== void 0 && !backend.versionCheck(mainPkg)) return { _tag: "notInstalled" };
207471
- let mainPackageJsonPath;
207472
- try {
207473
- mainPackageJsonPath = cwdRequire.resolve(backend.packageName + "/package.json");
207474
- } catch {
207475
- return { _tag: "notInstalled" };
207476
- }
207477
- const backendRequire = node_module.createRequire(mainPackageJsonPath);
207478
- const platformPackageName = backend.platformPackagePrefix + "-" + process.platform + "-" + process.arch;
207479
- let platformPackageJsonPath;
207480
- try {
207481
- platformPackageJsonPath = backendRequire.resolve(platformPackageName + "/package.json");
207482
- } catch {
207483
- return {
207484
- _tag: "unsupportedPlatform",
207485
- packageName: platformPackageName
207486
- };
207487
- }
207488
- const platformDir = path.dirname(platformPackageJsonPath);
207489
- const binaryName = backend.binaryName + (isWin ? ".exe" : "");
207702
+ const PackageJsonMetadataSchema = Struct({
207703
+ name: String$1,
207704
+ version: String$1,
207705
+ gitHead: String$1
207706
+ });
207707
+ const PackageJsonMetadataFromStringSchema = fromJsonString(PackageJsonMetadataSchema);
207708
+ const BinaryMetadataSchema = Struct({
207709
+ tsVersion: String$1,
207710
+ tsGitHead: String$1
207711
+ });
207712
+ const BinaryMetadataFromStringSchema = fromJsonString(BinaryMetadataSchema);
207713
+ const packagedTypeScriptBinaryNames = ["tsc", "tsc-next"];
207714
+ const decodePackageJsonText = (packageName, packageJsonPath, text) => decodeUnknownEffect(PackageJsonMetadataFromStringSchema)(text).pipe(mapError((error) => new ParsePackageJsonError({
207715
+ packageName,
207716
+ packageJsonPath,
207717
+ reason: error.message
207718
+ })));
207719
+ const readPackageJsonFile = (packageName, packageJsonPath) => gen(function* () {
207490
207720
  return {
207491
- _tag: "resolved",
207492
- path: path.join(platformDir, "lib", binaryName),
207493
- binaryName: backend.binaryName
207721
+ requestedPackageName: packageName,
207722
+ packageJsonPath,
207723
+ ...yield* decodePackageJsonText(packageName, packageJsonPath, yield* (yield* FileSystem).readFileString(packageJsonPath).pipe(mapError((error) => new ParsePackageJsonError({
207724
+ packageName,
207725
+ packageJsonPath,
207726
+ reason: error.message
207727
+ }))))
207494
207728
  };
207495
- };
207496
- /**
207497
- * Resolve the native TypeScript binary to patch. The `@typescript/native-preview`
207498
- * backend is tried first (back-compat), then the `typescript` >= 7 package so
207499
- * that the TypeScript 7 RC/stable release is supported out of the box.
207500
- *
207501
- * Returns the target binary path plus the backend's base binary name (`tsgo` or
207502
- * `tsc`); the latter selects the matching Effect-patched artifact from
207503
- * `@effect/tsgo-*` (which ships separate `lib/tsgo` and `lib/tsc` builds).
207504
- */
207505
- const getNativeBackendBinaryPath = gen(function* () {
207729
+ });
207730
+ const resolvePackageJson = (cwd, packageName) => gen(function* () {
207506
207731
  const path = yield* Path;
207507
- const cwdRequire = node_module.createRequire(path.join(process.cwd(), "noop.js"));
207508
- const nativePreviewResult = probeBackend(nativePreviewBackend, cwdRequire, path);
207509
- if (nativePreviewResult._tag === "resolved") return {
207510
- targetPath: nativePreviewResult.path,
207511
- binaryName: nativePreviewResult.binaryName
207512
- };
207513
- if (nativePreviewResult._tag === "unsupportedPlatform") return yield* fail(new UnsupportedPlatformPackageError({ packageName: nativePreviewResult.packageName }));
207514
- const typescriptResult = probeBackend(typescriptBackend, cwdRequire, path);
207515
- if (typescriptResult._tag === "resolved") return {
207516
- targetPath: typescriptResult.path,
207517
- binaryName: typescriptResult.binaryName
207732
+ const cwdRequire = node_module.createRequire(path.join(cwd, "noop.js"));
207733
+ return yield* readPackageJsonFile(packageName, yield* try_({
207734
+ try: () => cwdRequire.resolve(packageName + "/package.json"),
207735
+ catch: () => new PackageNotFoundError({ packageName })
207736
+ }));
207737
+ });
207738
+ const decodeBinaryMetadataText = (metadataPath, text) => decodeUnknownEffect(BinaryMetadataFromStringSchema)(text).pipe(mapError((error) => new ParseBinaryMetadataError({
207739
+ metadataPath,
207740
+ reason: error.message
207741
+ })));
207742
+ const readBinaryMetadata = (binaryPath) => gen(function* () {
207743
+ const fs = yield* FileSystem;
207744
+ const metadataPath = binaryPath + ".json";
207745
+ if (!(yield* fs.exists(metadataPath))) return yield* fail(new BinaryMetadataNotFoundError({ metadataPath }));
207746
+ return yield* decodeBinaryMetadataText(metadataPath, yield* fs.readFileString(metadataPath).pipe(mapError((error) => new ParseBinaryMetadataError({
207747
+ metadataPath,
207748
+ reason: error.message
207749
+ }))));
207750
+ });
207751
+ const resolveOfficialTypeScriptBinary = (typescriptPackage) => gen(function* () {
207752
+ const path = yield* Path;
207753
+ const platformPackageName = "@typescript/typescript-" + process.platform + "-" + process.arch;
207754
+ const packageRequire = node_module.createRequire(typescriptPackage.packageJsonPath);
207755
+ const platformPackageJsonPath = yield* try_({
207756
+ try: () => packageRequire.resolve(platformPackageName + "/package.json"),
207757
+ catch: () => new UnsupportedPlatformPackageError({ packageName: platformPackageName })
207758
+ });
207759
+ const platformPackage = yield* readPackageJsonFile(platformPackageName, platformPackageJsonPath);
207760
+ const binaryName = "tsc" + (process.platform === "win32" ? ".exe" : "");
207761
+ return {
207762
+ packageName: typescriptPackage.requestedPackageName,
207763
+ packageJsonPath: typescriptPackage.packageJsonPath,
207764
+ packageVersion: typescriptPackage.version,
207765
+ packageGitHead: typescriptPackage.gitHead,
207766
+ platformPackageName,
207767
+ platformPackageJsonPath,
207768
+ platformGitHead: platformPackage.gitHead,
207769
+ binaryPath: path.join(path.dirname(platformPackageJsonPath), "lib", binaryName)
207518
207770
  };
207519
- if (typescriptResult._tag === "unsupportedPlatform") return yield* fail(new UnsupportedPlatformPackageError({ packageName: typescriptResult.packageName }));
207520
- return yield* fail(new NativeBackendNotInstalledError({ details: "no native backend found" }));
207521
207771
  });
207772
+ const resolveInstalledTypeScriptBinary = (packageNames) => gen(function* () {
207773
+ for (const packageName of packageNames) {
207774
+ const packageResult = yield* resolvePackageJson(process.cwd(), packageName).pipe(catchTag("PackageNotFoundError", () => succeed(void 0)));
207775
+ if (packageResult === void 0 || !isNativeTypescriptVersion(packageResult.version)) continue;
207776
+ return yield* resolveOfficialTypeScriptBinary(packageResult);
207777
+ }
207778
+ return yield* fail(new NativeBackendNotInstalledError({ packageNames }));
207779
+ });
207780
+ const packageNamesWithPreferred = (preferredPackageName) => {
207781
+ const preferred = getOrUndefined(preferredPackageName);
207782
+ return preferred === void 0 || preferred === "" ? defaultTypescriptPackageNames : Array.from(new Set([preferred, ...defaultTypescriptPackageNames]));
207783
+ };
207522
207784
  /**
207523
207785
  * Resolve the Effect-patched binary to copy over the native target. The
207524
- * `@effect/tsgo-*` platform package ships separate `lib/tsgo` (built from
207525
- * `main`) and `lib/tsc` (built from `generated/stable`) artifacts; `binaryName`
207526
- * selects the one matching the detected native backend so the correct build is
207527
- * installed. Defaults to `tsgo` for the `get-exe-path` command.
207786
+ * `@effect/tsgo-*` platform package ships `lib/tsc` (built from
207787
+ * `generated/latest`) and `lib/tsc-next` (built from `main`). The adjacent JSON
207788
+ * metadata files identify the TypeScript gitHead each binary was built from.
207528
207789
  */
207529
- const getPackagedBinaryPath = (binaryName = "tsgo") => gen(function* () {
207790
+ const getPackagedBinaryPath = (installedTypeScript, force) => gen(function* () {
207530
207791
  const fs = yield* FileSystem;
207531
207792
  const path = yield* Path;
207532
207793
  const packageName = "@effect/tsgo-" + process.platform + "-" + process.arch;
@@ -207536,17 +207797,71 @@ const getPackagedBinaryPath = (binaryName = "tsgo") => gen(function* () {
207536
207797
  catch: () => new ResolvePackagedBinaryError({ reason: `Unable to resolve ${packageName}. Either your platform is unsupported, or the platform package is not installed.` })
207537
207798
  });
207538
207799
  const packageDir = path.dirname(packageJsonPath);
207539
- const exeName = binaryName + (process.platform === "win32" ? ".exe" : "");
207540
- const exePath = path.join(packageDir, "lib", exeName);
207541
- if (!(yield* fs.exists(exePath))) return yield* fail(new ResolvePackagedBinaryError({ reason: "Executable not found: " + exePath }));
207542
- return exePath;
207800
+ const candidates = [];
207801
+ for (const binaryName of packagedTypeScriptBinaryNames) {
207802
+ const exeName = binaryName + (process.platform === "win32" ? ".exe" : "");
207803
+ const exePath = path.join(packageDir, "lib", exeName);
207804
+ if (!(yield* fs.exists(exePath))) {
207805
+ candidates.push({
207806
+ binaryName,
207807
+ reason: "binary not packaged"
207808
+ });
207809
+ continue;
207810
+ }
207811
+ const metadataResult = yield* readBinaryMetadata(exePath).pipe(match$1({
207812
+ onFailure: (error) => ({
207813
+ _tag: "failure",
207814
+ error
207815
+ }),
207816
+ onSuccess: (metadata) => ({
207817
+ _tag: "success",
207818
+ metadata
207819
+ })
207820
+ }));
207821
+ if (metadataResult._tag === "failure") {
207822
+ candidates.push({
207823
+ binaryName,
207824
+ path: exePath,
207825
+ reason: metadataResult.error.message
207826
+ });
207827
+ continue;
207828
+ }
207829
+ const metadata = metadataResult.metadata;
207830
+ const candidate = {
207831
+ binaryName,
207832
+ path: exePath,
207833
+ metadata,
207834
+ ...metadata
207835
+ };
207836
+ if (metadata.tsGitHead === installedTypeScript.packageGitHead) return exePath;
207837
+ candidates.push(candidate);
207838
+ }
207839
+ if (force) {
207840
+ const fallback = candidates.find((candidate) => candidate.binaryName === "tsc-next" && candidate.path !== void 0) ?? candidates.find((candidate) => candidate.binaryName === "tsc" && candidate.path !== void 0);
207841
+ if (fallback?.path !== void 0) {
207842
+ yield* warn(new PackagedBinaryVersionMismatchError({
207843
+ installedVersion: installedTypeScript.packageVersion,
207844
+ installedGitHead: installedTypeScript.packageGitHead,
207845
+ candidates
207846
+ }).message);
207847
+ yield* warn("Forcing patch with " + fallback.binaryName + ". This may be incompatible.");
207848
+ return fallback.path;
207849
+ }
207850
+ }
207851
+ if (candidates.length === 0) return yield* fail(new ResolvePackagedBinaryError({ reason: "No packaged TypeScript binaries were found in " + path.join(packageDir, "lib") }));
207852
+ return yield* fail(new PackagedBinaryVersionMismatchError({
207853
+ installedVersion: installedTypeScript.packageVersion,
207854
+ installedGitHead: installedTypeScript.packageGitHead,
207855
+ candidates
207856
+ }));
207543
207857
  });
207544
- const patch = gen(function* () {
207858
+ const patch = (force, packageNames) => gen(function* () {
207545
207859
  const fs = yield* FileSystem;
207546
207860
  const path = yield* Path;
207547
- const { targetPath, binaryName } = yield* getNativeBackendBinaryPath;
207861
+ const installedTypeScript = yield* resolveInstalledTypeScriptBinary(packageNames);
207862
+ const targetPath = installedTypeScript.binaryPath;
207548
207863
  const backupPath = path.join(path.dirname(targetPath), path.basename(targetPath) + ".original");
207549
- const ourBinaryPath = yield* getPackagedBinaryPath(binaryName);
207864
+ const ourBinaryPath = yield* getPackagedBinaryPath(installedTypeScript, force);
207550
207865
  if (!(yield* fs.exists(targetPath))) return yield* fail(new MissingTargetBinaryError({ targetPath }));
207551
207866
  let actualBackupPath = backupPath;
207552
207867
  let counter = 1;
@@ -207576,7 +207891,7 @@ const patch = gen(function* () {
207576
207891
  const unpatch = gen(function* () {
207577
207892
  const fs = yield* FileSystem;
207578
207893
  const path = yield* Path;
207579
- const { targetPath } = yield* getNativeBackendBinaryPath;
207894
+ const { binaryPath: targetPath } = yield* resolveInstalledTypeScriptBinary(defaultTypescriptPackageNames);
207580
207895
  const backupPath = path.join(path.dirname(targetPath), path.basename(targetPath) + ".original");
207581
207896
  if (!(yield* fs.exists(backupPath))) {
207582
207897
  yield* error("No backup found at " + backupPath + ". Nothing to restore.");
@@ -207593,9 +207908,12 @@ const unpatch = gen(function* () {
207593
207908
  yield* fs.rename(backupPath, targetPath).pipe(mapError(() => new BackupRestoreError({ reason: `Failed to restore backup from ${backupPath} to ${targetPath}.` })));
207594
207909
  yield* log("Restored original binary at " + targetPath);
207595
207910
  });
207596
- const patchCommand = make("patch").pipe(withDescription("Patch the Effect Language Service binary"), withHandler(() => patch));
207911
+ const patchCommand = make("patch", {
207912
+ force: boolean("force"),
207913
+ typescriptPackage: optional(string("typescript-package").pipe(withDescription$1("Native TypeScript package name to try before the default package names")))
207914
+ }).pipe(withDescription("Patch the Effect Language Service binary"), withHandler(({ force, typescriptPackage }) => patch(force, packageNamesWithPreferred(typescriptPackage))));
207597
207915
  const unpatchCommand = make("unpatch").pipe(withDescription("Unpatch and restore the original TypeScript-Go binary"), withHandler(() => unpatch));
207598
- const getExePathCommand = make("get-exe-path").pipe(withDescription("Print the Effect Language Service executable path"), withHandler(() => getPackagedBinaryPath().pipe(flatMap((exePath) => log(exePath)))));
207916
+ const getExePathCommand = make("get-exe-path").pipe(withDescription("Print the Effect Language Service executable path"), withHandler(() => resolveInstalledTypeScriptBinary(defaultTypescriptPackageNames).pipe(flatMap((installedTypeScript) => getPackagedBinaryPath(installedTypeScript, false)), flatMap((exePath) => log(exePath)))));
207599
207917
  make("tsgo").pipe(withSubcommands([
207600
207918
  patchCommand,
207601
207919
  unpatchCommand,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect/tsgo",
3
- "version": "0.16.3",
3
+ "version": "0.18.0",
4
4
  "description": "Effect Language Service for TypeScript-Go — Effect-specific diagnostics and hover features.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -22,13 +22,13 @@
22
22
  "README.md"
23
23
  ],
24
24
  "optionalDependencies": {
25
- "@effect/tsgo-win32-x64": "0.16.3",
26
- "@effect/tsgo-win32-arm64": "0.16.3",
27
- "@effect/tsgo-linux-x64": "0.16.3",
28
- "@effect/tsgo-linux-arm64": "0.16.3",
29
- "@effect/tsgo-linux-arm": "0.16.3",
30
- "@effect/tsgo-darwin-x64": "0.16.3",
31
- "@effect/tsgo-darwin-arm64": "0.16.3"
25
+ "@effect/tsgo-win32-x64": "0.18.0",
26
+ "@effect/tsgo-win32-arm64": "0.18.0",
27
+ "@effect/tsgo-linux-x64": "0.18.0",
28
+ "@effect/tsgo-linux-arm64": "0.18.0",
29
+ "@effect/tsgo-linux-arm": "0.18.0",
30
+ "@effect/tsgo-darwin-x64": "0.18.0",
31
+ "@effect/tsgo-darwin-arm64": "0.18.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@effect/platform-node": "^4.0.0-beta.83",