tstyche 6.0.0-beta.1 → 6.0.0-beta.2

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.
@@ -158,7 +158,6 @@ interface ConfigFileOptions {
158
158
  checkSuppressedErrors?: boolean;
159
159
  failFast?: boolean;
160
160
  fixtureFileMatch?: Array<string>;
161
- legacyToBe?: boolean;
162
161
  plugins?: Array<string>;
163
162
  rejectAnyType?: boolean;
164
163
  rejectNeverType?: boolean;
@@ -720,9 +719,7 @@ declare class Store {
720
719
  #private;
721
720
  static manifest: Manifest | undefined;
722
721
  static fetch(tag: string): Promise<void>;
723
- static load(tag: string, options?: {
724
- notPatched?: boolean;
725
- }): Promise<typeof ts | undefined>;
722
+ static load(tag: string): Promise<typeof ts | undefined>;
726
723
  static open(): Promise<void>;
727
724
  static prune(): Promise<void>;
728
725
  static update(): Promise<void>;
package/build/tstyche.js CHANGED
@@ -1,11 +1,9 @@
1
1
  import { writeFileSync, rmSync, existsSync, watch } from 'node:fs';
2
2
  import fs from 'node:fs/promises';
3
3
  import path from 'node:path';
4
- import { fileURLToPath, pathToFileURL } from 'node:url';
4
+ import { pathToFileURL, fileURLToPath } from 'node:url';
5
5
  import os from 'node:os';
6
6
  import process from 'node:process';
7
- import { createRequire } from 'node:module';
8
- import vm from 'node:vm';
9
7
 
10
8
  class EventEmitter {
11
9
  static instanceCount = 0;
@@ -397,9 +395,9 @@ class ConfigDiagnosticText {
397
395
  }
398
396
  static rangeUsage() {
399
397
  return [
400
- "A range must be specified using an operator and a minor version: '>=5.5'.",
401
- "To set an upper bound, use the intersection of two ranges: '>=5.0 <5.3'.",
402
- "Use the '||' operator to join ranges into a union: '>=5.2 <=5.3 || 5.4.2 || >5.5'.",
398
+ "A range must be specified using an operator and a minor version: '>=5.8'.",
399
+ "To set an upper bound, use the intersection of two ranges: '>=5.4 <5.6'.",
400
+ "Use the '||' operator to join ranges into a union: '>=5.4 <5.6 || 5.6.2 || >=5.8'.",
403
401
  ];
404
402
  }
405
403
  static seen(element) {
@@ -731,7 +729,7 @@ class ManifestService {
731
729
  const versions = [];
732
730
  const packageMetadata = (await response.json());
733
731
  for (const [tag, meta] of Object.entries(packageMetadata.versions)) {
734
- if (!tag.includes("-") && Version.isSatisfiedWith(tag, "5.0.2")) {
732
+ if (!tag.includes("-") && Version.isSatisfiedWith(tag, "5.4.2")) {
735
733
  versions.push(tag);
736
734
  packages[tag] = { integrity: meta.dist.integrity, tarball: meta.dist.tarball };
737
735
  }
@@ -896,7 +894,6 @@ class PackageService {
896
894
  }
897
895
 
898
896
  class Store {
899
- static #compilerInstanceCache = new Map();
900
897
  static #fetcher;
901
898
  static #lockService;
902
899
  static manifest;
@@ -924,14 +921,10 @@ class Store {
924
921
  }
925
922
  await Store.#packageService.ensure(version, Store.manifest);
926
923
  }
927
- static async load(tag, options) {
928
- let compilerInstance = Store.#compilerInstanceCache.get(tag);
929
- if (compilerInstance != null) {
930
- return compilerInstance;
931
- }
932
- let modulePath;
924
+ static async load(tag) {
925
+ let resolvedModule;
933
926
  if (tag === "*" && environmentOptions.typescriptModule != null) {
934
- modulePath = fileURLToPath(environmentOptions.typescriptModule);
927
+ resolvedModule = environmentOptions.typescriptModule;
935
928
  }
936
929
  else {
937
930
  await Store.open();
@@ -940,40 +933,15 @@ class Store {
940
933
  Store.#onDiagnostics(Diagnostic.error(StoreDiagnosticText.cannotAddTypeScriptPackage(tag)));
941
934
  return;
942
935
  }
943
- compilerInstance = Store.#compilerInstanceCache.get(version);
944
- if (compilerInstance != null) {
945
- return compilerInstance;
946
- }
947
936
  const packagePath = await Store.#packageService.ensure(version, Store.manifest);
948
937
  if (packagePath != null) {
949
- modulePath = Path.join(packagePath, "lib", "typescript.js");
938
+ resolvedModule = pathToFileURL(`${packagePath}/lib/typescript.js`).toString();
950
939
  }
951
940
  }
952
- if (modulePath != null) {
953
- const packageConfigText = await fs.readFile(Path.resolve(modulePath, "../../package.json"), { encoding: "utf8" });
954
- const { version: packageVersion } = JSON.parse(packageConfigText);
955
- if (!Version.isSatisfiedWith(packageVersion, "5.3")) {
956
- modulePath = Path.resolve(modulePath, "../tsserverlibrary.js");
957
- }
958
- if (options?.notPatched) {
959
- const moduleSpecifier = pathToFileURL(modulePath).toString();
960
- compilerInstance = (await import(moduleSpecifier)).default;
961
- }
962
- else {
963
- compilerInstance = await Store.#loadPatchedModule(modulePath);
964
- }
965
- Store.#compilerInstanceCache.set(tag, compilerInstance);
966
- Store.#compilerInstanceCache.set(compilerInstance.version, compilerInstance);
941
+ if (resolvedModule != null) {
942
+ return (await import(resolvedModule)).default;
967
943
  }
968
- return compilerInstance;
969
- }
970
- static async #loadPatchedModule(modulePath) {
971
- const sourceText = await fs.readFile(modulePath, { encoding: "utf8" });
972
- const compiledWrapper = vm.compileFunction(sourceText.replace("return checker;", "return { ...checker, isTypeIdenticalTo };"), ["exports", "require", "module", "__filename", "__dirname"], { filename: modulePath });
973
- const exports$1 = {};
974
- const module = { exports: exports$1 };
975
- compiledWrapper(exports$1, createRequire(modulePath), module, modulePath, Path.dirname(modulePath));
976
- return module.exports;
944
+ return;
977
945
  }
978
946
  static #onDiagnostics(diagnostic) {
979
947
  EventEmitter.dispatch(["store:error", { diagnostics: [diagnostic] }]);
@@ -1107,12 +1075,6 @@ class Options {
1107
1075
  group: 2,
1108
1076
  name: "help",
1109
1077
  },
1110
- {
1111
- brand: "boolean",
1112
- description: "Use the patch-based implementation of the '.toBe()' matcher.",
1113
- group: 4,
1114
- name: "legacyToBe",
1115
- },
1116
1078
  {
1117
1079
  brand: "true",
1118
1080
  description: "Print the list of supported versions of the 'typescript' package and exit.",
@@ -1603,7 +1565,6 @@ const defaultOptions = {
1603
1565
  checkSuppressedErrors: true,
1604
1566
  failFast: false,
1605
1567
  fixtureFileMatch: ["**/__fixtures__/*.{ts,tsx}", "**/fixtures/*.{ts,tsx}"],
1606
- legacyToBe: false,
1607
1568
  plugins: [],
1608
1569
  rejectAnyType: true,
1609
1570
  rejectNeverType: true,
@@ -2432,7 +2393,7 @@ function CommandLineUsageText() {
2432
2393
  const usage = [
2433
2394
  ["tstyche", "Run all tests."],
2434
2395
  ["tstyche query-params", "Only run the matching test file."],
2435
- ["tstyche --target '5.3 || 5.5.2 || >=5.7'", "Test against specific versions of TypeScript."],
2396
+ ["tstyche --target '5.4 || 5.6.2 || >=5.8'", "Test against specific versions of TypeScript."],
2436
2397
  ];
2437
2398
  const usageText = usage.map(([commandText, descriptionText]) => (jsx(Line, { children: [jsx(CommandText, { text: commandText }), jsx(OptionDescriptionText, { text: descriptionText })] })));
2438
2399
  return jsx(Text, { children: usageText });
@@ -4363,29 +4324,6 @@ class ExpectDiagnosticText {
4363
4324
  }
4364
4325
  }
4365
4326
 
4366
- class RelationMatcherBase {
4367
- explain(matchWorker, sourceNode, targetNode) {
4368
- const sourceTypeText = matchWorker.getTypeText(sourceNode);
4369
- const targetTypeText = matchWorker.getTypeText(targetNode);
4370
- const text = matchWorker.assertionNode.isNot
4371
- ? this.explainText(sourceTypeText, targetTypeText)
4372
- : this.explainNotText(sourceTypeText, targetTypeText);
4373
- const origin = DiagnosticOrigin.fromNode(targetNode, matchWorker.assertionNode);
4374
- return [Diagnostic.error(text, origin)];
4375
- }
4376
- }
4377
-
4378
- class LegacyToBe extends RelationMatcherBase {
4379
- explainText = ExpectDiagnosticText.isTheSame;
4380
- explainNotText = ExpectDiagnosticText.isNotTheSame;
4381
- match(matchWorker, sourceNode, targetNode) {
4382
- return {
4383
- explain: () => this.explain(matchWorker, sourceNode, targetNode),
4384
- isMatch: matchWorker.checkIsIdenticalTo(sourceNode, targetNode),
4385
- };
4386
- }
4387
- }
4388
-
4389
4327
  class MatchWorker {
4390
4328
  assertionNode;
4391
4329
  #compiler;
@@ -4397,25 +4335,15 @@ class MatchWorker {
4397
4335
  this.assertionNode = assertionNode;
4398
4336
  }
4399
4337
  checkIsAssignableTo(sourceNode, targetNode) {
4400
- return this.#checkIsRelatedTo(sourceNode, targetNode, "assignable");
4338
+ return this.#checkIsRelatedTo(sourceNode, targetNode);
4401
4339
  }
4402
4340
  checkIsAssignableWith(sourceNode, targetNode) {
4403
- return this.#checkIsRelatedTo(targetNode, sourceNode, "assignable");
4341
+ return this.#checkIsRelatedTo(targetNode, sourceNode);
4404
4342
  }
4405
- checkIsIdenticalTo(sourceNode, targetNode) {
4406
- return (this.#checkIsRelatedTo(sourceNode, targetNode, "identical") &&
4407
- this.checkIsAssignableTo(sourceNode, targetNode) &&
4408
- this.checkIsAssignableWith(sourceNode, targetNode));
4409
- }
4410
- #checkIsRelatedTo(sourceNode, targetNode, relation) {
4411
- const sourceType = relation === "identical" ? this.#simplifyType(this.getType(sourceNode)) : this.getType(sourceNode);
4412
- const targetType = relation === "identical" ? this.#simplifyType(this.getType(targetNode)) : this.getType(targetNode);
4413
- switch (relation) {
4414
- case "assignable":
4415
- return this.typeChecker.isTypeAssignableTo(sourceType, targetType);
4416
- case "identical":
4417
- return this.typeChecker.isTypeIdenticalTo(sourceType, targetType);
4418
- }
4343
+ #checkIsRelatedTo(sourceNode, targetNode) {
4344
+ const sourceType = this.getType(sourceNode);
4345
+ const targetType = this.getType(targetNode);
4346
+ return this.typeChecker.isTypeAssignableTo(sourceType, targetType);
4419
4347
  }
4420
4348
  extendsObjectType(type) {
4421
4349
  const nonPrimitiveType = "getNonPrimitiveType" in this.typeChecker
@@ -4458,15 +4386,6 @@ class MatchWorker {
4458
4386
  }
4459
4387
  return DiagnosticOrigin.fromNode(enclosingNode, this.assertionNode);
4460
4388
  }
4461
- #simplifyType(type) {
4462
- if (type.isUnionOrIntersection()) {
4463
- const candidateType = this.#simplifyType(type.types[0]);
4464
- if (type.types.every((type) => this.typeChecker.isTypeIdenticalTo(this.#simplifyType(type), candidateType))) {
4465
- return candidateType;
4466
- }
4467
- }
4468
- return type;
4469
- }
4470
4389
  }
4471
4390
 
4472
4391
  function isStringOrNumberLiteralType(compiler, type) {
@@ -5131,6 +5050,18 @@ class Structure {
5131
5050
  }
5132
5051
  }
5133
5052
 
5053
+ class RelationMatcherBase {
5054
+ explain(matchWorker, sourceNode, targetNode) {
5055
+ const sourceTypeText = matchWorker.getTypeText(sourceNode);
5056
+ const targetTypeText = matchWorker.getTypeText(targetNode);
5057
+ const text = matchWorker.assertionNode.isNot
5058
+ ? this.explainText(sourceTypeText, targetTypeText)
5059
+ : this.explainNotText(sourceTypeText, targetTypeText);
5060
+ const origin = DiagnosticOrigin.fromNode(targetNode, matchWorker.assertionNode);
5061
+ return [Diagnostic.error(text, origin)];
5062
+ }
5063
+ }
5064
+
5134
5065
  class ToBe extends RelationMatcherBase {
5135
5066
  #structure;
5136
5067
  constructor(compiler, program) {
@@ -5482,12 +5413,12 @@ class ExpectService {
5482
5413
  toBeConstructableWith;
5483
5414
  toHaveProperty;
5484
5415
  toRaiseError;
5485
- constructor(compiler, program, reject, resolvedConfig) {
5416
+ constructor(compiler, program, reject) {
5486
5417
  this.#compiler = compiler;
5487
5418
  this.#program = program;
5488
5419
  this.#reject = reject;
5489
5420
  this.toAcceptProps = new ToAcceptProps(compiler, program);
5490
- this.toBe = resolvedConfig.legacyToBe ? new LegacyToBe() : new ToBe(compiler, program);
5421
+ this.toBe = new ToBe(compiler, program);
5491
5422
  this.toBeApplicable = new ToBeApplicable(compiler);
5492
5423
  this.toBeAssignableFrom = new ToBeAssignableFrom();
5493
5424
  this.toBeAssignableTo = new ToBeAssignableTo();
@@ -5732,7 +5663,7 @@ class TestTreeWalker {
5732
5663
  this.#hasOnly = options.hasOnly || resolvedConfig.only != null || options.position != null;
5733
5664
  this.#position = options.position;
5734
5665
  const reject = new Reject(compiler, program, resolvedConfig);
5735
- this.#expectService = new ExpectService(compiler, program, reject, resolvedConfig);
5666
+ this.#expectService = new ExpectService(compiler, program, reject);
5736
5667
  this.#whenService = new WhenService(reject, onFileDiagnostics);
5737
5668
  }
5738
5669
  async #resolveRunMode(flags, node) {
@@ -5977,7 +5908,7 @@ class FileRunner {
5977
5908
  class Runner {
5978
5909
  #eventEmitter = new EventEmitter();
5979
5910
  #resolvedConfig;
5980
- static version = "6.0.0-beta.1";
5911
+ static version = "6.0.0-beta.2";
5981
5912
  constructor(resolvedConfig) {
5982
5913
  this.#resolvedConfig = resolvedConfig;
5983
5914
  }
@@ -6034,7 +5965,7 @@ class Runner {
6034
5965
  for (const target of this.#resolvedConfig.target) {
6035
5966
  const targetResult = new TargetResult(target, files);
6036
5967
  EventEmitter.dispatch(["target:start", { result: targetResult }]);
6037
- const compiler = await Store.load(target, { notPatched: !this.#resolvedConfig.legacyToBe });
5968
+ const compiler = await Store.load(target);
6038
5969
  if (compiler) {
6039
5970
  const fileRunner = new FileRunner(compiler, this.#resolvedConfig);
6040
5971
  for (const file of files) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tstyche",
3
- "version": "6.0.0-beta.1",
3
+ "version": "6.0.0-beta.2",
4
4
  "description": "Everything You Need for Type Testing.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -32,7 +32,7 @@
32
32
  "types": "./build/index.d.ts",
33
33
  "bin": "./build/bin.js",
34
34
  "peerDependencies": {
35
- "typescript": ">=5.0"
35
+ "typescript": ">=5.4"
36
36
  },
37
37
  "peerDependenciesMeta": {
38
38
  "typescript": {