@effect/tsgo 0.17.0 → 0.18.1
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 +1 -1
- package/dist/effect-tsgo.js +399 -130
- package/package.json +8 -8
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`: `typescript` >= 7 (e.g. `typescript@latest` or `typescript@next`)
|
|
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
|
|
package/dist/effect-tsgo.js
CHANGED
|
@@ -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$
|
|
1162
|
-
case "boolean": return string$
|
|
1163
|
-
case "symbol": return string$
|
|
1164
|
-
case "string": return string$
|
|
1165
|
-
case "undefined": return string$
|
|
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$
|
|
1168
|
-
else if (self instanceof Date) return string$
|
|
1169
|
-
else if (self instanceof RegExp) return string$
|
|
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$
|
|
1352
|
-
if (n === Infinity) return string$
|
|
1353
|
-
if (n === -Infinity) return string$
|
|
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$
|
|
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$
|
|
1514
|
-
const hashSet = /* @__PURE__ */ iterableWith(/* @__PURE__ */ string$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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,13 +204655,13 @@ var FileReadError = class extends TaggedError("FileReadError") {
|
|
|
204437
204655
|
//#endregion
|
|
204438
204656
|
//#region package.json
|
|
204439
204657
|
var name = "@effect/tsgo";
|
|
204440
|
-
var version = "0.
|
|
204658
|
+
var version = "0.18.1";
|
|
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
|
|
204664
|
+
const defaultTypescriptPackageNames = ["typescript", "@typescript/native"];
|
|
204447
204665
|
const PATCH_COMMAND = "effect-tsgo patch";
|
|
204448
204666
|
const TSCONFIG_SCHEMA_URL = "https://raw.githubusercontent.com/Effect-TS/tsgo/refs/heads/main/schema.json";
|
|
204449
204667
|
/**
|
|
@@ -204455,13 +204673,6 @@ const isNativeTypescriptVersion = (version) => {
|
|
|
204455
204673
|
const match = /\d+/.exec(version.trim());
|
|
204456
204674
|
return match !== null && Number(match[0]) >= 7;
|
|
204457
204675
|
};
|
|
204458
|
-
/** The `typescript` >= 7 backend. */
|
|
204459
|
-
const typescriptBackend = {
|
|
204460
|
-
packageName: TYPESCRIPT_PACKAGE_NAME,
|
|
204461
|
-
platformPackagePrefix: "@typescript/typescript",
|
|
204462
|
-
binaryName: "tsc",
|
|
204463
|
-
versionCheck: (pkg) => isNativeTypescriptVersion(pkg.version ?? "0")
|
|
204464
|
-
};
|
|
204465
204676
|
/**
|
|
204466
204677
|
* Resolve the VS Code TypeScript 7 tsdk folder.
|
|
204467
204678
|
*/
|
|
@@ -204521,11 +204732,17 @@ const assessPackageJson = (input) => {
|
|
|
204521
204732
|
return none$3();
|
|
204522
204733
|
};
|
|
204523
204734
|
const lspVersion = assessDependency(LSP_PACKAGE_NAME);
|
|
204524
|
-
|
|
204525
|
-
const
|
|
204526
|
-
|
|
204527
|
-
|
|
204528
|
-
|
|
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
|
+
}
|
|
204529
204746
|
const prepareScript = "prepare" in (parsed.scripts ?? {}) ? some({
|
|
204530
204747
|
script: parsed.scripts.prepare,
|
|
204531
204748
|
hasPatch: parsed.scripts.prepare.toLowerCase().includes(PATCH_COMMAND)
|
|
@@ -204876,12 +205093,19 @@ const computePackageJsonChanges = (current, target) => {
|
|
|
204876
205093
|
const ctx = createTrackerContext();
|
|
204877
205094
|
const fileChange = tsInternal.textChanges.ChangeTracker.with(ctx, (tracker) => {
|
|
204878
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
|
+
};
|
|
204879
205102
|
const ensureTypescriptDependency = () => {
|
|
204880
205103
|
if (isNone(target.typescriptVersion) || isSome(current.typescriptVersion)) return;
|
|
204881
205104
|
const targetTypescript = target.typescriptVersion.value;
|
|
205105
|
+
const targetTypescriptPackageName = getTypescriptPackageName(targetTypescript);
|
|
204882
205106
|
if (!findDependencyCollectionProperty(rootObj, targetTypescript.dependencyType) && isSome(target.lspVersion) && target.lspVersion.value.dependencyType === targetTypescript.dependencyType) return;
|
|
204883
|
-
descriptions.push(`Add ${
|
|
204884
|
-
upsertDependency(tracker, current.sourceFile, rootObj,
|
|
205107
|
+
descriptions.push(`Add ${targetTypescriptPackageName}@${targetTypescript.version} to ${targetTypescript.dependencyType}`);
|
|
205108
|
+
upsertDependency(tracker, current.sourceFile, rootObj, targetTypescriptPackageName, targetTypescript);
|
|
204885
205109
|
};
|
|
204886
205110
|
if (isSome(target.lspVersion)) {
|
|
204887
205111
|
const targetDepType = target.lspVersion.value.dependencyType;
|
|
@@ -204899,10 +205123,7 @@ const computePackageJsonChanges = (current, target) => {
|
|
|
204899
205123
|
const newDepsProperty = findDependencyCollectionProperty(rootObj, targetDepType);
|
|
204900
205124
|
if (!newDepsProperty) {
|
|
204901
205125
|
const dependencyProperties = [import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(LSP_PACKAGE_NAME), import_typescript.factory.createStringLiteral(targetVersion))];
|
|
204902
|
-
if (shouldAddTypescriptWithDependencyType(targetDepType))
|
|
204903
|
-
const targetTypescript = target.typescriptVersion.pipe(getOrUndefined);
|
|
204904
|
-
if (targetTypescript) dependencyProperties.push(import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(TYPESCRIPT_PACKAGE_NAME), import_typescript.factory.createStringLiteral(targetTypescript.version)));
|
|
204905
|
-
}
|
|
205126
|
+
if (shouldAddTypescriptWithDependencyType(targetDepType)) appendTypescriptDependencyProperty(dependencyProperties);
|
|
204906
205127
|
const newDepsProp = import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(targetDepType), import_typescript.factory.createObjectLiteralExpression(dependencyProperties, false));
|
|
204907
205128
|
insertNodeAtEndOfList(tracker, current.sourceFile, rootObj.properties, newDepsProp);
|
|
204908
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)));
|
|
@@ -204919,10 +205140,7 @@ const computePackageJsonChanges = (current, target) => {
|
|
|
204919
205140
|
const depsProperty = findDependencyCollectionProperty(rootObj, targetDepType);
|
|
204920
205141
|
if (!depsProperty) {
|
|
204921
205142
|
const dependencyProperties = [import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(LSP_PACKAGE_NAME), import_typescript.factory.createStringLiteral(targetVersion))];
|
|
204922
|
-
if (shouldAddTypescriptWithDependencyType(targetDepType))
|
|
204923
|
-
const targetTypescript = target.typescriptVersion.pipe(getOrUndefined);
|
|
204924
|
-
if (targetTypescript) dependencyProperties.push(import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(TYPESCRIPT_PACKAGE_NAME), import_typescript.factory.createStringLiteral(targetTypescript.version)));
|
|
204925
|
-
}
|
|
205143
|
+
if (shouldAddTypescriptWithDependencyType(targetDepType)) appendTypescriptDependencyProperty(dependencyProperties);
|
|
204926
205144
|
const newDepsProp = import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(targetDepType), import_typescript.factory.createObjectLiteralExpression(dependencyProperties, false));
|
|
204927
205145
|
insertNodeAtEndOfList(tracker, current.sourceFile, rootObj.properties, newDepsProp);
|
|
204928
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)));
|
|
@@ -207359,8 +207577,9 @@ const gatherTargetState = (assessment, context) => gen(function* () {
|
|
|
207359
207577
|
}
|
|
207360
207578
|
]
|
|
207361
207579
|
});
|
|
207580
|
+
const defaultTypescriptPackageName = defaultTypescriptPackageNames[0];
|
|
207362
207581
|
const vscodeSettings = editors.includes("vscode") ? some({ settings: {
|
|
207363
|
-
"typescript.native-preview.tsdk": nativeBackendTsdkPath(
|
|
207582
|
+
"typescript.native-preview.tsdk": nativeBackendTsdkPath(defaultTypescriptPackageName),
|
|
207364
207583
|
"typescript.experimental.useTsgo": true,
|
|
207365
207584
|
"js/ts.experimental.useTsgo": true
|
|
207366
207585
|
} }) : none$3();
|
|
@@ -207373,7 +207592,7 @@ const gatherTargetState = (assessment, context) => gen(function* () {
|
|
|
207373
207592
|
typescriptVersion: orElse(assessment.packageJson.typescriptVersion, () => some({
|
|
207374
207593
|
dependencyType: lspDependencyType,
|
|
207375
207594
|
version: context.defaultTypescriptVersion,
|
|
207376
|
-
packageName:
|
|
207595
|
+
packageName: defaultTypescriptPackageName
|
|
207377
207596
|
})),
|
|
207378
207597
|
prepareScript: true
|
|
207379
207598
|
},
|
|
@@ -207406,7 +207625,17 @@ const setupCommand = make("setup").pipe(withDescription("Setup @effect/tsgo for
|
|
|
207406
207625
|
//#region src/cli.ts
|
|
207407
207626
|
var NativeBackendNotInstalledError = class extends TaggedError("NativeBackendNotInstalledError") {
|
|
207408
207627
|
get message() {
|
|
207409
|
-
return "No native TypeScript backend is installed. Install `typescript` >= 7 first (e.g. `typescript@latest` or `typescript@next`).";
|
|
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}`;
|
|
207410
207639
|
}
|
|
207411
207640
|
};
|
|
207412
207641
|
var MissingTypeScriptMetadataError = class extends TaggedError("MissingTypeScriptMetadataError") {
|
|
@@ -207414,6 +207643,16 @@ var MissingTypeScriptMetadataError = class extends TaggedError("MissingTypeScrip
|
|
|
207414
207643
|
return `Installed ${this.packageName} package.json does not contain a gitHead. Unable to select a compatible Effect binary.`;
|
|
207415
207644
|
}
|
|
207416
207645
|
};
|
|
207646
|
+
var BinaryMetadataNotFoundError = class extends TaggedError("BinaryMetadataNotFoundError") {
|
|
207647
|
+
get message() {
|
|
207648
|
+
return `Binary metadata not found at ${this.metadataPath}.`;
|
|
207649
|
+
}
|
|
207650
|
+
};
|
|
207651
|
+
var ParseBinaryMetadataError = class extends TaggedError("ParseBinaryMetadataError") {
|
|
207652
|
+
get message() {
|
|
207653
|
+
return `Unable to parse binary metadata at ${this.metadataPath}: ${this.reason}`;
|
|
207654
|
+
}
|
|
207655
|
+
};
|
|
207417
207656
|
var UnsupportedPlatformPackageError = class extends TaggedError("UnsupportedPlatformPackageError") {
|
|
207418
207657
|
get message() {
|
|
207419
207658
|
return `Unable to resolve ${this.packageName}. Your platform may not be supported by the installed native TypeScript backend.`;
|
|
@@ -207465,63 +207704,90 @@ var VerificationFailedError = class extends TaggedError("VerificationFailedError
|
|
|
207465
207704
|
return "Warning: verification failed for " + this.targetPath + ", but binary was patched. The binary may still work correctly.";
|
|
207466
207705
|
}
|
|
207467
207706
|
};
|
|
207707
|
+
const PackageJsonMetadataSchema = Struct({
|
|
207708
|
+
name: String$1,
|
|
207709
|
+
version: String$1,
|
|
207710
|
+
gitHead: optionalKey(String$1)
|
|
207711
|
+
});
|
|
207712
|
+
const PackageJsonMetadataFromStringSchema = fromJsonString(PackageJsonMetadataSchema);
|
|
207713
|
+
const BinaryMetadataSchema = Struct({
|
|
207714
|
+
tsVersion: String$1,
|
|
207715
|
+
tsGitHead: String$1
|
|
207716
|
+
});
|
|
207717
|
+
const BinaryMetadataFromStringSchema = fromJsonString(BinaryMetadataSchema);
|
|
207468
207718
|
const packagedTypeScriptBinaryNames = ["tsc", "tsc-next"];
|
|
207469
|
-
const
|
|
207470
|
-
|
|
207471
|
-
|
|
207472
|
-
|
|
207473
|
-
|
|
207474
|
-
|
|
207475
|
-
return { _tag: "notInstalled" };
|
|
207476
|
-
}
|
|
207477
|
-
if (backend.versionCheck !== void 0 && !backend.versionCheck(mainPkg)) return { _tag: "notInstalled" };
|
|
207478
|
-
let mainPackageJsonPath;
|
|
207479
|
-
try {
|
|
207480
|
-
mainPackageJsonPath = cwdRequire.resolve(backend.packageName + "/package.json");
|
|
207481
|
-
} catch {
|
|
207482
|
-
return { _tag: "notInstalled" };
|
|
207483
|
-
}
|
|
207484
|
-
const backendRequire = node_module.createRequire(mainPackageJsonPath);
|
|
207485
|
-
const platformPackageName = backend.platformPackagePrefix + "-" + process.platform + "-" + process.arch;
|
|
207486
|
-
let platformPackageJsonPath;
|
|
207487
|
-
try {
|
|
207488
|
-
platformPackageJsonPath = backendRequire.resolve(platformPackageName + "/package.json");
|
|
207489
|
-
} catch {
|
|
207490
|
-
return {
|
|
207491
|
-
_tag: "unsupportedPlatform",
|
|
207492
|
-
packageName: platformPackageName
|
|
207493
|
-
};
|
|
207494
|
-
}
|
|
207495
|
-
const platformDir = path.dirname(platformPackageJsonPath);
|
|
207496
|
-
const binaryName = backend.binaryName + (isWin ? ".exe" : "");
|
|
207719
|
+
const decodePackageJsonText = (packageName, packageJsonPath, text) => decodeUnknownEffect(PackageJsonMetadataFromStringSchema)(text).pipe(mapError((error) => new ParsePackageJsonError({
|
|
207720
|
+
packageName,
|
|
207721
|
+
packageJsonPath,
|
|
207722
|
+
reason: error.message
|
|
207723
|
+
})));
|
|
207724
|
+
const readPackageJsonFile = (packageName, packageJsonPath) => gen(function* () {
|
|
207497
207725
|
return {
|
|
207498
|
-
|
|
207499
|
-
|
|
207500
|
-
|
|
207501
|
-
|
|
207726
|
+
requestedPackageName: packageName,
|
|
207727
|
+
packageJsonPath,
|
|
207728
|
+
...yield* decodePackageJsonText(packageName, packageJsonPath, yield* (yield* FileSystem).readFileString(packageJsonPath).pipe(mapError((error) => new ParsePackageJsonError({
|
|
207729
|
+
packageName,
|
|
207730
|
+
packageJsonPath,
|
|
207731
|
+
reason: error.message
|
|
207732
|
+
}))))
|
|
207502
207733
|
};
|
|
207503
|
-
};
|
|
207504
|
-
|
|
207505
|
-
* Resolve the native TypeScript binary to patch. The supported upstream package
|
|
207506
|
-
* is `typescript` >= 7, whose platform package exposes a `tsc` executable.
|
|
207507
|
-
*/
|
|
207508
|
-
const getNativeBackendBinaryPath = gen(function* () {
|
|
207734
|
+
});
|
|
207735
|
+
const resolvePackageJson = (cwd, packageName) => gen(function* () {
|
|
207509
207736
|
const path = yield* Path;
|
|
207510
|
-
const
|
|
207511
|
-
|
|
207512
|
-
|
|
207513
|
-
|
|
207514
|
-
|
|
207515
|
-
|
|
207516
|
-
|
|
207517
|
-
|
|
207518
|
-
|
|
207519
|
-
|
|
207520
|
-
|
|
207737
|
+
const cwdRequire = node_module.createRequire(path.join(cwd, "noop.js"));
|
|
207738
|
+
return yield* readPackageJsonFile(packageName, yield* try_({
|
|
207739
|
+
try: () => cwdRequire.resolve(packageName + "/package.json"),
|
|
207740
|
+
catch: () => new PackageNotFoundError({ packageName })
|
|
207741
|
+
}));
|
|
207742
|
+
});
|
|
207743
|
+
const decodeBinaryMetadataText = (metadataPath, text) => decodeUnknownEffect(BinaryMetadataFromStringSchema)(text).pipe(mapError((error) => new ParseBinaryMetadataError({
|
|
207744
|
+
metadataPath,
|
|
207745
|
+
reason: error.message
|
|
207746
|
+
})));
|
|
207747
|
+
const readBinaryMetadata = (binaryPath) => gen(function* () {
|
|
207748
|
+
const fs = yield* FileSystem;
|
|
207749
|
+
const metadataPath = binaryPath + ".json";
|
|
207750
|
+
if (!(yield* fs.exists(metadataPath))) return yield* fail(new BinaryMetadataNotFoundError({ metadataPath }));
|
|
207751
|
+
return yield* decodeBinaryMetadataText(metadataPath, yield* fs.readFileString(metadataPath).pipe(mapError((error) => new ParseBinaryMetadataError({
|
|
207752
|
+
metadataPath,
|
|
207753
|
+
reason: error.message
|
|
207754
|
+
}))));
|
|
207755
|
+
});
|
|
207756
|
+
const resolveOfficialTypeScriptBinary = (typescriptPackage) => gen(function* () {
|
|
207757
|
+
const packageGitHead = typescriptPackage.gitHead;
|
|
207758
|
+
if (packageGitHead === void 0) return yield* fail(new MissingTypeScriptMetadataError({ packageName: typescriptPackage.requestedPackageName }));
|
|
207759
|
+
const path = yield* Path;
|
|
207760
|
+
const platformPackageName = "@typescript/typescript-" + process.platform + "-" + process.arch;
|
|
207761
|
+
const packageRequire = node_module.createRequire(typescriptPackage.packageJsonPath);
|
|
207762
|
+
const platformPackageJsonPath = yield* try_({
|
|
207763
|
+
try: () => packageRequire.resolve(platformPackageName + "/package.json"),
|
|
207764
|
+
catch: () => new UnsupportedPlatformPackageError({ packageName: platformPackageName })
|
|
207765
|
+
});
|
|
207766
|
+
const platformPackage = yield* readPackageJsonFile(platformPackageName, platformPackageJsonPath);
|
|
207767
|
+
const binaryName = "tsc" + (process.platform === "win32" ? ".exe" : "");
|
|
207768
|
+
return {
|
|
207769
|
+
packageName: typescriptPackage.requestedPackageName,
|
|
207770
|
+
packageJsonPath: typescriptPackage.packageJsonPath,
|
|
207771
|
+
packageVersion: typescriptPackage.version,
|
|
207772
|
+
packageGitHead,
|
|
207773
|
+
platformPackageName,
|
|
207774
|
+
platformPackageJsonPath,
|
|
207775
|
+
platformGitHead: platformPackage.gitHead,
|
|
207776
|
+
binaryPath: path.join(path.dirname(platformPackageJsonPath), "lib", binaryName)
|
|
207777
|
+
};
|
|
207778
|
+
});
|
|
207779
|
+
const resolveInstalledTypeScriptBinary = (packageNames) => gen(function* () {
|
|
207780
|
+
for (const packageName of packageNames) {
|
|
207781
|
+
const packageResult = yield* resolvePackageJson(process.cwd(), packageName).pipe(catchTag("PackageNotFoundError", () => succeed(void 0)));
|
|
207782
|
+
if (packageResult === void 0 || !isNativeTypescriptVersion(packageResult.version)) continue;
|
|
207783
|
+
return yield* resolveOfficialTypeScriptBinary(packageResult);
|
|
207521
207784
|
}
|
|
207522
|
-
|
|
207523
|
-
return yield* fail(new NativeBackendNotInstalledError({ details: "no native backend found" }));
|
|
207785
|
+
return yield* fail(new NativeBackendNotInstalledError({ packageNames }));
|
|
207524
207786
|
});
|
|
207787
|
+
const packageNamesWithPreferred = (preferredPackageName) => {
|
|
207788
|
+
const preferred = getOrUndefined(preferredPackageName);
|
|
207789
|
+
return preferred === void 0 || preferred === "" ? defaultTypescriptPackageNames : Array.from(new Set([preferred, ...defaultTypescriptPackageNames]));
|
|
207790
|
+
};
|
|
207525
207791
|
/**
|
|
207526
207792
|
* Resolve the Effect-patched binary to copy over the native target. The
|
|
207527
207793
|
* `@effect/tsgo-*` platform package ships `lib/tsc` (built from
|
|
@@ -207542,7 +207808,6 @@ const getPackagedBinaryPath = (installedTypeScript, force) => gen(function* () {
|
|
|
207542
207808
|
for (const binaryName of packagedTypeScriptBinaryNames) {
|
|
207543
207809
|
const exeName = binaryName + (process.platform === "win32" ? ".exe" : "");
|
|
207544
207810
|
const exePath = path.join(packageDir, "lib", exeName);
|
|
207545
|
-
const metadataPath = exePath + ".json";
|
|
207546
207811
|
if (!(yield* fs.exists(exePath))) {
|
|
207547
207812
|
candidates.push({
|
|
207548
207813
|
binaryName,
|
|
@@ -207550,40 +207815,40 @@ const getPackagedBinaryPath = (installedTypeScript, force) => gen(function* () {
|
|
|
207550
207815
|
});
|
|
207551
207816
|
continue;
|
|
207552
207817
|
}
|
|
207553
|
-
|
|
207818
|
+
const metadataResult = yield* readBinaryMetadata(exePath).pipe(match$1({
|
|
207819
|
+
onFailure: (error) => ({
|
|
207820
|
+
_tag: "failure",
|
|
207821
|
+
error
|
|
207822
|
+
}),
|
|
207823
|
+
onSuccess: (metadata) => ({
|
|
207824
|
+
_tag: "success",
|
|
207825
|
+
metadata
|
|
207826
|
+
})
|
|
207827
|
+
}));
|
|
207828
|
+
if (metadataResult._tag === "failure") {
|
|
207554
207829
|
candidates.push({
|
|
207555
207830
|
binaryName,
|
|
207556
207831
|
path: exePath,
|
|
207557
|
-
reason:
|
|
207832
|
+
reason: metadataResult.error.message
|
|
207558
207833
|
});
|
|
207559
207834
|
continue;
|
|
207560
207835
|
}
|
|
207561
|
-
const metadata =
|
|
207562
|
-
try: () => {
|
|
207563
|
-
const parsed = JSON.parse(text);
|
|
207564
|
-
if (typeof parsed.tsVersion !== "string" || typeof parsed.tsGitHead !== "string") throw new Error("invalid metadata");
|
|
207565
|
-
return {
|
|
207566
|
-
tsVersion: parsed.tsVersion,
|
|
207567
|
-
tsGitHead: parsed.tsGitHead
|
|
207568
|
-
};
|
|
207569
|
-
},
|
|
207570
|
-
catch: () => new ResolvePackagedBinaryError({ reason: "Invalid binary metadata: " + metadataPath })
|
|
207571
|
-
})));
|
|
207836
|
+
const metadata = metadataResult.metadata;
|
|
207572
207837
|
const candidate = {
|
|
207573
207838
|
binaryName,
|
|
207574
207839
|
path: exePath,
|
|
207575
207840
|
metadata,
|
|
207576
207841
|
...metadata
|
|
207577
207842
|
};
|
|
207578
|
-
if (metadata.tsGitHead === installedTypeScript.
|
|
207843
|
+
if (metadata.tsGitHead === installedTypeScript.packageGitHead) return exePath;
|
|
207579
207844
|
candidates.push(candidate);
|
|
207580
207845
|
}
|
|
207581
207846
|
if (force) {
|
|
207582
207847
|
const fallback = candidates.find((candidate) => candidate.binaryName === "tsc-next" && candidate.path !== void 0) ?? candidates.find((candidate) => candidate.binaryName === "tsc" && candidate.path !== void 0);
|
|
207583
207848
|
if (fallback?.path !== void 0) {
|
|
207584
207849
|
yield* warn(new PackagedBinaryVersionMismatchError({
|
|
207585
|
-
installedVersion: installedTypeScript.
|
|
207586
|
-
installedGitHead: installedTypeScript.
|
|
207850
|
+
installedVersion: installedTypeScript.packageVersion,
|
|
207851
|
+
installedGitHead: installedTypeScript.packageGitHead,
|
|
207587
207852
|
candidates
|
|
207588
207853
|
}).message);
|
|
207589
207854
|
yield* warn("Forcing patch with " + fallback.binaryName + ". This may be incompatible.");
|
|
@@ -207592,15 +207857,16 @@ const getPackagedBinaryPath = (installedTypeScript, force) => gen(function* () {
|
|
|
207592
207857
|
}
|
|
207593
207858
|
if (candidates.length === 0) return yield* fail(new ResolvePackagedBinaryError({ reason: "No packaged TypeScript binaries were found in " + path.join(packageDir, "lib") }));
|
|
207594
207859
|
return yield* fail(new PackagedBinaryVersionMismatchError({
|
|
207595
|
-
installedVersion: installedTypeScript.
|
|
207596
|
-
installedGitHead: installedTypeScript.
|
|
207860
|
+
installedVersion: installedTypeScript.packageVersion,
|
|
207861
|
+
installedGitHead: installedTypeScript.packageGitHead,
|
|
207597
207862
|
candidates
|
|
207598
207863
|
}));
|
|
207599
207864
|
});
|
|
207600
|
-
const patch = (force) => gen(function* () {
|
|
207865
|
+
const patch = (force, packageNames) => gen(function* () {
|
|
207601
207866
|
const fs = yield* FileSystem;
|
|
207602
207867
|
const path = yield* Path;
|
|
207603
|
-
const
|
|
207868
|
+
const installedTypeScript = yield* resolveInstalledTypeScriptBinary(packageNames);
|
|
207869
|
+
const targetPath = installedTypeScript.binaryPath;
|
|
207604
207870
|
const backupPath = path.join(path.dirname(targetPath), path.basename(targetPath) + ".original");
|
|
207605
207871
|
const ourBinaryPath = yield* getPackagedBinaryPath(installedTypeScript, force);
|
|
207606
207872
|
if (!(yield* fs.exists(targetPath))) return yield* fail(new MissingTargetBinaryError({ targetPath }));
|
|
@@ -207632,7 +207898,7 @@ const patch = (force) => gen(function* () {
|
|
|
207632
207898
|
const unpatch = gen(function* () {
|
|
207633
207899
|
const fs = yield* FileSystem;
|
|
207634
207900
|
const path = yield* Path;
|
|
207635
|
-
const { targetPath } = yield*
|
|
207901
|
+
const { binaryPath: targetPath } = yield* resolveInstalledTypeScriptBinary(defaultTypescriptPackageNames);
|
|
207636
207902
|
const backupPath = path.join(path.dirname(targetPath), path.basename(targetPath) + ".original");
|
|
207637
207903
|
if (!(yield* fs.exists(backupPath))) {
|
|
207638
207904
|
yield* error("No backup found at " + backupPath + ". Nothing to restore.");
|
|
@@ -207649,9 +207915,12 @@ const unpatch = gen(function* () {
|
|
|
207649
207915
|
yield* fs.rename(backupPath, targetPath).pipe(mapError(() => new BackupRestoreError({ reason: `Failed to restore backup from ${backupPath} to ${targetPath}.` })));
|
|
207650
207916
|
yield* log("Restored original binary at " + targetPath);
|
|
207651
207917
|
});
|
|
207652
|
-
const patchCommand = make("patch", {
|
|
207918
|
+
const patchCommand = make("patch", {
|
|
207919
|
+
force: boolean("force"),
|
|
207920
|
+
typescriptPackage: optional(string("typescript-package").pipe(withDescription$1("Native TypeScript package name to try before the default package names")))
|
|
207921
|
+
}).pipe(withDescription("Patch the Effect Language Service binary"), withHandler(({ force, typescriptPackage }) => patch(force, packageNamesWithPreferred(typescriptPackage))));
|
|
207653
207922
|
const unpatchCommand = make("unpatch").pipe(withDescription("Unpatch and restore the original TypeScript-Go binary"), withHandler(() => unpatch));
|
|
207654
|
-
const getExePathCommand = make("get-exe-path").pipe(withDescription("Print the Effect Language Service executable path"), withHandler(() =>
|
|
207923
|
+
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)))));
|
|
207655
207924
|
make("tsgo").pipe(withSubcommands([
|
|
207656
207925
|
patchCommand,
|
|
207657
207926
|
unpatchCommand,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/tsgo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.1",
|
|
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.
|
|
26
|
-
"@effect/tsgo-win32-arm64": "0.
|
|
27
|
-
"@effect/tsgo-linux-x64": "0.
|
|
28
|
-
"@effect/tsgo-linux-arm64": "0.
|
|
29
|
-
"@effect/tsgo-linux-arm": "0.
|
|
30
|
-
"@effect/tsgo-darwin-x64": "0.
|
|
31
|
-
"@effect/tsgo-darwin-arm64": "0.
|
|
25
|
+
"@effect/tsgo-win32-x64": "0.18.1",
|
|
26
|
+
"@effect/tsgo-win32-arm64": "0.18.1",
|
|
27
|
+
"@effect/tsgo-linux-x64": "0.18.1",
|
|
28
|
+
"@effect/tsgo-linux-arm64": "0.18.1",
|
|
29
|
+
"@effect/tsgo-linux-arm": "0.18.1",
|
|
30
|
+
"@effect/tsgo-darwin-x64": "0.18.1",
|
|
31
|
+
"@effect/tsgo-darwin-arm64": "0.18.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@effect/platform-node": "^4.0.0-beta.83",
|