@effect/tsgo 0.16.2 → 0.17.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`). `effect-tsgo patch` selects the packaged Effect binary whose TypeScript git head matches the installed `typescript` package.
26
26
 
27
27
  ## Diagnostic Status
28
28
 
@@ -204437,17 +204437,14 @@ var FileReadError = class extends TaggedError("FileReadError") {
204437
204437
  //#endregion
204438
204438
  //#region package.json
204439
204439
  var name = "@effect/tsgo";
204440
- var version = "0.16.2";
204440
+ var version = "0.17.0";
204441
204441
 
204442
204442
  //#endregion
204443
204443
  //#region src/setup/consts.ts
204444
204444
  const LSP_PACKAGE_NAME = name;
204445
204445
  const LSP_PLUGIN_NAME = "@effect/language-service";
204446
- const NATIVE_PREVIEW_PACKAGE_NAME = "@typescript/native-preview";
204447
204446
  const TYPESCRIPT_PACKAGE_NAME = "typescript";
204448
204447
  const PATCH_COMMAND = "effect-tsgo patch";
204449
- const DEFAULT_LSP_VERSION = version;
204450
- const DEFAULT_NATIVE_PREVIEW_VERSION = "latest";
204451
204448
  const TSCONFIG_SCHEMA_URL = "https://raw.githubusercontent.com/Effect-TS/tsgo/refs/heads/main/schema.json";
204452
204449
  /**
204453
204450
  * `typescript` package versions >= 7 ship the native Go-ported binary that this
@@ -204458,13 +204455,7 @@ const isNativeTypescriptVersion = (version) => {
204458
204455
  const match = /\d+/.exec(version.trim());
204459
204456
  return match !== null && Number(match[0]) >= 7;
204460
204457
  };
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). */
204458
+ /** The `typescript` >= 7 backend. */
204468
204459
  const typescriptBackend = {
204469
204460
  packageName: TYPESCRIPT_PACKAGE_NAME,
204470
204461
  platformPackagePrefix: "@typescript/typescript",
@@ -204472,10 +204463,7 @@ const typescriptBackend = {
204472
204463
  versionCheck: (pkg) => isNativeTypescriptVersion(pkg.version ?? "0")
204473
204464
  };
204474
204465
  /**
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`.
204466
+ * Resolve the VS Code TypeScript 7 tsdk folder.
204479
204467
  */
204480
204468
  const nativeBackendTsdkPath = (packageName) => "node_modules/" + packageName;
204481
204469
 
@@ -204533,14 +204521,11 @@ const assessPackageJson = (input) => {
204533
204521
  return none$3();
204534
204522
  };
204535
204523
  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
- });
204524
+ const typescriptDep = assessDependency(TYPESCRIPT_PACKAGE_NAME);
204525
+ const typescriptVersion = isSome(typescriptDep) && isNativeTypescriptVersion(typescriptDep.value.version) ? some({
204526
+ ...typescriptDep.value,
204527
+ packageName: TYPESCRIPT_PACKAGE_NAME
204528
+ }) : none$3();
204544
204529
  const prepareScript = "prepare" in (parsed.scripts ?? {}) ? some({
204545
204530
  script: parsed.scripts.prepare,
204546
204531
  hasPatch: parsed.scripts.prepare.toLowerCase().includes(PATCH_COMMAND)
@@ -204551,7 +204536,7 @@ const assessPackageJson = (input) => {
204551
204536
  parsed,
204552
204537
  text: input.text,
204553
204538
  lspVersion,
204554
- nativePreviewVersion,
204539
+ typescriptVersion,
204555
204540
  prepareScript
204556
204541
  };
204557
204542
  };
@@ -204890,17 +204875,13 @@ const computePackageJsonChanges = (current, target) => {
204890
204875
  if (!rootObj) return emptyFileChangesResult();
204891
204876
  const ctx = createTrackerContext();
204892
204877
  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);
204878
+ const shouldAddTypescriptWithDependencyType = (dependencyType) => isSome(target.typescriptVersion) && isNone(current.typescriptVersion) && target.typescriptVersion.value.dependencyType === dependencyType;
204879
+ const ensureTypescriptDependency = () => {
204880
+ if (isNone(target.typescriptVersion) || isSome(current.typescriptVersion)) return;
204881
+ const targetTypescript = target.typescriptVersion.value;
204882
+ if (!findDependencyCollectionProperty(rootObj, targetTypescript.dependencyType) && isSome(target.lspVersion) && target.lspVersion.value.dependencyType === targetTypescript.dependencyType) return;
204883
+ descriptions.push(`Add ${TYPESCRIPT_PACKAGE_NAME}@${targetTypescript.version} to ${targetTypescript.dependencyType}`);
204884
+ upsertDependency(tracker, current.sourceFile, rootObj, TYPESCRIPT_PACKAGE_NAME, targetTypescript);
204904
204885
  };
204905
204886
  if (isSome(target.lspVersion)) {
204906
204887
  const targetDepType = target.lspVersion.value.dependencyType;
@@ -204918,9 +204899,9 @@ const computePackageJsonChanges = (current, target) => {
204918
204899
  const newDepsProperty = findDependencyCollectionProperty(rootObj, targetDepType);
204919
204900
  if (!newDepsProperty) {
204920
204901
  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)));
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)));
204924
204905
  }
204925
204906
  const newDepsProp = import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(targetDepType), import_typescript.factory.createObjectLiteralExpression(dependencyProperties, false));
204926
204907
  insertNodeAtEndOfList(tracker, current.sourceFile, rootObj.properties, newDepsProp);
@@ -204938,15 +204919,15 @@ const computePackageJsonChanges = (current, target) => {
204938
204919
  const depsProperty = findDependencyCollectionProperty(rootObj, targetDepType);
204939
204920
  if (!depsProperty) {
204940
204921
  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)));
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)));
204944
204925
  }
204945
204926
  const newDepsProp = import_typescript.factory.createPropertyAssignment(import_typescript.factory.createStringLiteral(targetDepType), import_typescript.factory.createObjectLiteralExpression(dependencyProperties, false));
204946
204927
  insertNodeAtEndOfList(tracker, current.sourceFile, rootObj.properties, newDepsProp);
204947
204928
  } 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
204929
  }
204949
- ensureNativePreviewDependency();
204930
+ ensureTypescriptDependency();
204950
204931
  } else if (isSome(current.lspVersion)) {
204951
204932
  descriptions.push(`Remove ${LSP_PACKAGE_NAME} from dependencies`);
204952
204933
  const currentDepType = current.lspVersion.value.dependencyType;
@@ -205230,7 +205211,7 @@ const computeChanges = (assessment, target) => {
205230
205211
  if (target.editors.includes("vscode")) messages = [
205231
205212
  ...messages,
205232
205213
  "VS Code / Cursor / VS Code-based editors:",
205233
- " 1. Install the @typescript/native-preview extension",
205214
+ " 1. Install the TypeScript 7 extension",
205234
205215
  " 2. Open a TypeScript file and ensure the native TS server is active",
205235
205216
  " 3. The language service plugin will be loaded automatically",
205236
205217
  ""
@@ -207159,7 +207140,7 @@ function createRulePrompt(rules, initialSeverities) {
207159
207140
  const fromAssessment = (inputState) => ({
207160
207141
  packageJson: {
207161
207142
  lspVersion: inputState.packageJson.lspVersion,
207162
- nativePreviewVersion: inputState.packageJson.nativePreviewVersion,
207143
+ typescriptVersion: inputState.packageJson.typescriptVersion,
207163
207144
  prepareScript: map$10(inputState.packageJson.prepareScript, (_) => _.hasPatch).pipe(getOrElse$1(() => false))
207164
207145
  },
207165
207146
  tsconfig: { diagnosticSeverities: inputState.tsconfig.currentDiagnosticSeverities },
@@ -207331,7 +207312,7 @@ const gatherTargetState = (assessment, context) => gen(function* () {
207331
207312
  if (lspDependencyType === "no") return {
207332
207313
  packageJson: {
207333
207314
  lspVersion: none$3(),
207334
- nativePreviewVersion: assessment.packageJson.nativePreviewVersion,
207315
+ typescriptVersion: assessment.packageJson.typescriptVersion,
207335
207316
  prepareScript: false
207336
207317
  },
207337
207318
  tsconfig: { diagnosticSeverities: none$3() },
@@ -207378,12 +207359,8 @@ const gatherTargetState = (assessment, context) => gen(function* () {
207378
207359
  }
207379
207360
  ]
207380
207361
  });
207381
- const nativeBackendPackage = match$8(assessment.packageJson.nativePreviewVersion, {
207382
- onNone: () => NATIVE_PREVIEW_PACKAGE_NAME,
207383
- onSome: (dep) => dep.packageName ?? NATIVE_PREVIEW_PACKAGE_NAME
207384
- });
207385
207362
  const vscodeSettings = editors.includes("vscode") ? some({ settings: {
207386
- "typescript.native-preview.tsdk": nativeBackendTsdkPath(nativeBackendPackage),
207363
+ "typescript.native-preview.tsdk": nativeBackendTsdkPath(TYPESCRIPT_PACKAGE_NAME),
207387
207364
  "typescript.experimental.useTsgo": true,
207388
207365
  "js/ts.experimental.useTsgo": true
207389
207366
  } }) : none$3();
@@ -207393,9 +207370,10 @@ const gatherTargetState = (assessment, context) => gen(function* () {
207393
207370
  dependencyType: lspDependencyType,
207394
207371
  version: context.defaultLspVersion
207395
207372
  }),
207396
- nativePreviewVersion: orElse(assessment.packageJson.nativePreviewVersion, () => some({
207373
+ typescriptVersion: orElse(assessment.packageJson.typescriptVersion, () => some({
207397
207374
  dependencyType: lspDependencyType,
207398
- version: DEFAULT_NATIVE_PREVIEW_VERSION
207375
+ version: context.defaultTypescriptVersion,
207376
+ packageName: TYPESCRIPT_PACKAGE_NAME
207399
207377
  })),
207400
207378
  prepareScript: true
207401
207379
  },
@@ -207405,6 +207383,10 @@ const gatherTargetState = (assessment, context) => gen(function* () {
207405
207383
  };
207406
207384
  });
207407
207385
 
207386
+ //#endregion
207387
+ //#region upstream.json
207388
+ var tsVersion = "7.1.0-dev.20260708.3";
207389
+
207408
207390
  //#endregion
207409
207391
  //#region src/setup/index.ts
207410
207392
  const setupCommand = make("setup").pipe(withDescription("Setup @effect/tsgo for the given project using an interactive CLI."), withHandler(() => gen(function* () {
@@ -207412,7 +207394,10 @@ const setupCommand = make("setup").pipe(withDescription("Setup @effect/tsgo for
207412
207394
  const tsconfigInput = yield* selectTsConfigFile(currentDir);
207413
207395
  const assessmentInput = yield* createAssessmentInput(currentDir, tsconfigInput);
207414
207396
  const assessmentState = assess(assessmentInput);
207415
- const targetState = yield* gatherTargetState(assessmentState, { defaultLspVersion: DEFAULT_LSP_VERSION });
207397
+ const targetState = yield* gatherTargetState(assessmentState, {
207398
+ defaultLspVersion: version,
207399
+ defaultTypescriptVersion: tsVersion
207400
+ });
207416
207401
  const result = computeChanges(assessmentState, targetState);
207417
207402
  yield* reviewAndApplyChanges(result, assessmentState, { cancelMessage: "Setup cancelled. No changes were made." });
207418
207403
  })));
@@ -207421,7 +207406,12 @@ const setupCommand = make("setup").pipe(withDescription("Setup @effect/tsgo for
207421
207406
  //#region src/cli.ts
207422
207407
  var NativeBackendNotInstalledError = class extends TaggedError("NativeBackendNotInstalledError") {
207423
207408
  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`).";
207409
+ return "No native TypeScript backend is installed. Install `typescript` >= 7 first (e.g. `typescript@latest` or `typescript@next`).";
207410
+ }
207411
+ };
207412
+ var MissingTypeScriptMetadataError = class extends TaggedError("MissingTypeScriptMetadataError") {
207413
+ get message() {
207414
+ return `Installed ${this.packageName} package.json does not contain a gitHead. Unable to select a compatible Effect binary.`;
207425
207415
  }
207426
207416
  };
207427
207417
  var UnsupportedPlatformPackageError = class extends TaggedError("UnsupportedPlatformPackageError") {
@@ -207439,6 +207429,22 @@ var ResolvePackagedBinaryError = class extends TaggedError("ResolvePackagedBinar
207439
207429
  return this.reason;
207440
207430
  }
207441
207431
  };
207432
+ var PackagedBinaryVersionMismatchError = class extends TaggedError("PackagedBinaryVersionMismatchError") {
207433
+ get message() {
207434
+ const tried = this.candidates.length === 0 ? " none" : this.candidates.map((candidate) => {
207435
+ if (candidate.tsVersion !== void 0 && candidate.tsGitHead !== void 0) return ` ${candidate.binaryName}: TypeScript ${candidate.tsVersion}, gitHead ${candidate.tsGitHead}`;
207436
+ return ` ${candidate.binaryName}: ${candidate.reason ?? "metadata unavailable"}`;
207437
+ }).join("\n");
207438
+ return [
207439
+ `No packaged Effect TypeScript binary matches installed TypeScript ${this.installedVersion} gitHead ${this.installedGitHead}.`,
207440
+ "",
207441
+ "Tried:",
207442
+ tried,
207443
+ "",
207444
+ "Install a matching @effect/tsgo release or a matching TypeScript version, or rerun with --force to use the newest packaged binary."
207445
+ ].join("\n");
207446
+ }
207447
+ };
207442
207448
  var BackupRestoreError = class extends TaggedError("BackupRestoreError") {
207443
207449
  get message() {
207444
207450
  return this.reason;
@@ -207459,6 +207465,7 @@ var VerificationFailedError = class extends TaggedError("VerificationFailedError
207459
207465
  return "Warning: verification failed for " + this.targetPath + ", but binary was patched. The binary may still work correctly.";
207460
207466
  }
207461
207467
  };
207468
+ const packagedTypeScriptBinaryNames = ["tsc", "tsc-next"];
207462
207469
  const probeBackend = (backend, cwdRequire, path) => {
207463
207470
  const isWin = process.platform === "win32";
207464
207471
  let mainPkg;
@@ -207490,43 +207497,38 @@ const probeBackend = (backend, cwdRequire, path) => {
207490
207497
  return {
207491
207498
  _tag: "resolved",
207492
207499
  path: path.join(platformDir, "lib", binaryName),
207493
- binaryName: backend.binaryName
207500
+ binaryName: backend.binaryName,
207501
+ packageJson: mainPkg
207494
207502
  };
207495
207503
  };
207496
207504
  /**
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).
207505
+ * Resolve the native TypeScript binary to patch. The supported upstream package
207506
+ * is `typescript` >= 7, whose platform package exposes a `tsc` executable.
207504
207507
  */
207505
207508
  const getNativeBackendBinaryPath = gen(function* () {
207506
207509
  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
207518
- };
207510
+ const typescriptResult = probeBackend(typescriptBackend, node_module.createRequire(path.join(process.cwd(), "noop.js")), path);
207511
+ if (typescriptResult._tag === "resolved") {
207512
+ const installedGitHead = typescriptResult.packageJson.gitHead;
207513
+ if (installedGitHead === void 0) return yield* fail(new MissingTypeScriptMetadataError({ packageName: typescriptBackend.packageName }));
207514
+ return {
207515
+ targetPath: typescriptResult.path,
207516
+ installedTypeScript: {
207517
+ version: typescriptResult.packageJson.version ?? "unknown",
207518
+ gitHead: installedGitHead
207519
+ }
207520
+ };
207521
+ }
207519
207522
  if (typescriptResult._tag === "unsupportedPlatform") return yield* fail(new UnsupportedPlatformPackageError({ packageName: typescriptResult.packageName }));
207520
207523
  return yield* fail(new NativeBackendNotInstalledError({ details: "no native backend found" }));
207521
207524
  });
207522
207525
  /**
207523
207526
  * 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.
207527
+ * `@effect/tsgo-*` platform package ships `lib/tsc` (built from
207528
+ * `generated/latest`) and `lib/tsc-next` (built from `main`). The adjacent JSON
207529
+ * metadata files identify the TypeScript gitHead each binary was built from.
207528
207530
  */
207529
- const getPackagedBinaryPath = (binaryName = "tsgo") => gen(function* () {
207531
+ const getPackagedBinaryPath = (installedTypeScript, force) => gen(function* () {
207530
207532
  const fs = yield* FileSystem;
207531
207533
  const path = yield* Path;
207532
207534
  const packageName = "@effect/tsgo-" + process.platform + "-" + process.arch;
@@ -207536,17 +207538,71 @@ const getPackagedBinaryPath = (binaryName = "tsgo") => gen(function* () {
207536
207538
  catch: () => new ResolvePackagedBinaryError({ reason: `Unable to resolve ${packageName}. Either your platform is unsupported, or the platform package is not installed.` })
207537
207539
  });
207538
207540
  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;
207541
+ const candidates = [];
207542
+ for (const binaryName of packagedTypeScriptBinaryNames) {
207543
+ const exeName = binaryName + (process.platform === "win32" ? ".exe" : "");
207544
+ const exePath = path.join(packageDir, "lib", exeName);
207545
+ const metadataPath = exePath + ".json";
207546
+ if (!(yield* fs.exists(exePath))) {
207547
+ candidates.push({
207548
+ binaryName,
207549
+ reason: "binary not packaged"
207550
+ });
207551
+ continue;
207552
+ }
207553
+ if (!(yield* fs.exists(metadataPath))) {
207554
+ candidates.push({
207555
+ binaryName,
207556
+ path: exePath,
207557
+ reason: "metadata not packaged"
207558
+ });
207559
+ continue;
207560
+ }
207561
+ const metadata = yield* fs.readFileString(metadataPath).pipe(flatMap((text) => try_({
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
+ })));
207572
+ const candidate = {
207573
+ binaryName,
207574
+ path: exePath,
207575
+ metadata,
207576
+ ...metadata
207577
+ };
207578
+ if (metadata.tsGitHead === installedTypeScript.gitHead) return exePath;
207579
+ candidates.push(candidate);
207580
+ }
207581
+ if (force) {
207582
+ const fallback = candidates.find((candidate) => candidate.binaryName === "tsc-next" && candidate.path !== void 0) ?? candidates.find((candidate) => candidate.binaryName === "tsc" && candidate.path !== void 0);
207583
+ if (fallback?.path !== void 0) {
207584
+ yield* warn(new PackagedBinaryVersionMismatchError({
207585
+ installedVersion: installedTypeScript.version,
207586
+ installedGitHead: installedTypeScript.gitHead,
207587
+ candidates
207588
+ }).message);
207589
+ yield* warn("Forcing patch with " + fallback.binaryName + ". This may be incompatible.");
207590
+ return fallback.path;
207591
+ }
207592
+ }
207593
+ if (candidates.length === 0) return yield* fail(new ResolvePackagedBinaryError({ reason: "No packaged TypeScript binaries were found in " + path.join(packageDir, "lib") }));
207594
+ return yield* fail(new PackagedBinaryVersionMismatchError({
207595
+ installedVersion: installedTypeScript.version,
207596
+ installedGitHead: installedTypeScript.gitHead,
207597
+ candidates
207598
+ }));
207543
207599
  });
207544
- const patch = gen(function* () {
207600
+ const patch = (force) => gen(function* () {
207545
207601
  const fs = yield* FileSystem;
207546
207602
  const path = yield* Path;
207547
- const { targetPath, binaryName } = yield* getNativeBackendBinaryPath;
207603
+ const { targetPath, installedTypeScript } = yield* getNativeBackendBinaryPath;
207548
207604
  const backupPath = path.join(path.dirname(targetPath), path.basename(targetPath) + ".original");
207549
- const ourBinaryPath = yield* getPackagedBinaryPath(binaryName);
207605
+ const ourBinaryPath = yield* getPackagedBinaryPath(installedTypeScript, force);
207550
207606
  if (!(yield* fs.exists(targetPath))) return yield* fail(new MissingTargetBinaryError({ targetPath }));
207551
207607
  let actualBackupPath = backupPath;
207552
207608
  let counter = 1;
@@ -207593,9 +207649,9 @@ const unpatch = gen(function* () {
207593
207649
  yield* fs.rename(backupPath, targetPath).pipe(mapError(() => new BackupRestoreError({ reason: `Failed to restore backup from ${backupPath} to ${targetPath}.` })));
207594
207650
  yield* log("Restored original binary at " + targetPath);
207595
207651
  });
207596
- const patchCommand = make("patch").pipe(withDescription("Patch the Effect Language Service binary"), withHandler(() => patch));
207652
+ const patchCommand = make("patch", { force: boolean("force") }).pipe(withDescription("Patch the Effect Language Service binary"), withHandler(({ force }) => patch(force)));
207597
207653
  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)))));
207654
+ const getExePathCommand = make("get-exe-path").pipe(withDescription("Print the Effect Language Service executable path"), withHandler(() => getNativeBackendBinaryPath.pipe(flatMap(({ installedTypeScript }) => getPackagedBinaryPath(installedTypeScript, false)), flatMap((exePath) => log(exePath)))));
207599
207655
  make("tsgo").pipe(withSubcommands([
207600
207656
  patchCommand,
207601
207657
  unpatchCommand,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect/tsgo",
3
- "version": "0.16.2",
3
+ "version": "0.17.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.2",
26
- "@effect/tsgo-win32-arm64": "0.16.2",
27
- "@effect/tsgo-linux-x64": "0.16.2",
28
- "@effect/tsgo-linux-arm64": "0.16.2",
29
- "@effect/tsgo-linux-arm": "0.16.2",
30
- "@effect/tsgo-darwin-x64": "0.16.2",
31
- "@effect/tsgo-darwin-arm64": "0.16.2"
25
+ "@effect/tsgo-win32-x64": "0.17.0",
26
+ "@effect/tsgo-win32-arm64": "0.17.0",
27
+ "@effect/tsgo-linux-x64": "0.17.0",
28
+ "@effect/tsgo-linux-arm64": "0.17.0",
29
+ "@effect/tsgo-linux-arm": "0.17.0",
30
+ "@effect/tsgo-darwin-x64": "0.17.0",
31
+ "@effect/tsgo-darwin-arm64": "0.17.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@effect/platform-node": "^4.0.0-beta.83",