@ark/attest 0.9.2 → 0.9.4

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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 ArkType
1
+ Copyright 2024 ArkType
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
package/README.md CHANGED
@@ -168,6 +168,31 @@ bench(
168
168
  .types([337, "instantiations"])
169
169
  ```
170
170
 
171
+ If you're benchmarking an API, you'll need to include a "baseline expression" so that instantiations created when your API is initially invoked don't add noise to the individual tests.
172
+
173
+ Here's an example of what that looks like:
174
+
175
+ ```ts
176
+ import { bench } from "@ark/attest"
177
+ import { type } from "arktype"
178
+
179
+ // baseline expression
180
+ type("boolean")
181
+
182
+ bench("single-quoted", () => {
183
+ const _ = type("'nineteen characters'")
184
+ // would be 2697 without baseline
185
+ }).types([610, "instantiations"])
186
+
187
+ bench("keyword", () => {
188
+ const _ = type("string")
189
+ // would be 2507 without baseline
190
+ }).types([356, "instantiations"])
191
+ ```
192
+
193
+ > [!WARNING]
194
+ > Be sure your baseline expression is not identical to an expression you are using in any of your benchmarks. If it is, the individual benchmarks will reuse its cached types, leading to reduced (or 0) instantiations.
195
+
171
196
  If you'd like to fail in CI above a threshold, you can add flags like the following (default value is 20%, but it will not throw unless `--benchErrorOnThresholdExceeded` is set):
172
197
 
173
198
  ```
package/out/cache/ts.d.ts CHANGED
@@ -5,6 +5,7 @@ export declare class TsServer {
5
5
  private tsConfigInfo;
6
6
  rootFiles: string[];
7
7
  virtualEnv: tsvfs.VirtualTypeScriptEnvironment;
8
+ program: ts.Program;
8
9
  private static _instance;
9
10
  static get instance(): TsServer;
10
11
  private constructor();
package/out/cache/ts.js CHANGED
@@ -9,6 +9,7 @@ export class TsServer {
9
9
  tsConfigInfo;
10
10
  rootFiles;
11
11
  virtualEnv;
12
+ program;
12
13
  static _instance = null;
13
14
  static get instance() {
14
15
  return new TsServer();
@@ -23,6 +24,7 @@ export class TsServer {
23
24
  this.rootFiles = tsConfigInfo.parsed.fileNames.filter(path => path.startsWith(normalizedCwd));
24
25
  const system = tsvfs.createFSBackedSystem(tsLibPaths.defaultMapFromNodeModules, dirname(this.tsConfigInfo.path), ts);
25
26
  this.virtualEnv = tsvfs.createVirtualTypeScriptEnvironment(system, this.rootFiles, ts, this.tsConfigInfo.parsed.options);
27
+ this.program = this.virtualEnv.languageService.getProgram();
26
28
  TsServer._instance = this;
27
29
  }
28
30
  getSourceFileOrThrow(path) {
@@ -6,4 +6,12 @@ export declare const gatherInlineInstantiationData: (file: ts.SourceFile, fileAs
6
6
  export declare const getCallExpressionsByName: (startNode: ts.Node, names: string[], isSnapCall?: boolean) => ts.CallExpression[];
7
7
  export declare const getInstantiationsContributedByNode: (file: ts.SourceFile, benchBlock: ts.FunctionExpression | ts.ArrowFunction) => number;
8
8
  export declare const createOrUpdateFile: (env: tsvfs.VirtualTypeScriptEnvironment, fileName: string, fileText: string) => ts.SourceFile | undefined;
9
+ declare module "typescript" {
10
+ interface SourceFile {
11
+ imports: ts.StringLiteral[];
12
+ }
13
+ interface Program {
14
+ getResolvedModuleFromModuleSpecifier(moduleSpecifier: ts.StringLiteralLike, sourceFile?: ts.SourceFile): ts.ResolvedModuleWithFailedLookupLocations;
15
+ }
16
+ }
9
17
  export declare const getIsolatedEnv: () => tsvfs.VirtualTypeScriptEnvironment;
@@ -1,5 +1,4 @@
1
1
  import { filePath } from "@ark/fs";
2
- import { throwInternalError } from "@ark/util";
3
2
  import * as tsvfs from "@typescript/vfs";
4
3
  import ts from "typescript";
5
4
  import { getConfig } from "../config.js";
@@ -88,8 +87,6 @@ const getInstantiationsWithFile = (fileText, fileName) => {
88
87
  const program = getProgram(env);
89
88
  program.emit(file);
90
89
  const count = program.getInstantiationCount();
91
- if (count === undefined)
92
- throwInternalError(`Unable to gather instantiation count for ${fileText}`);
93
90
  return count;
94
91
  };
95
92
  let virtualEnv = undefined;
package/out/config.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ensureDir, fromCwd } from "@ark/fs";
2
- import { arrayFrom, isArray, tryParseNumber } from "@ark/util";
2
+ import { isArray, liftArray, tryParseNumber } from "@ark/util";
3
3
  import { existsSync } from "node:fs";
4
4
  import { join, resolve } from "node:path";
5
5
  import { findAttestTypeScriptVersions } from "./tsVersioning.js";
@@ -76,7 +76,7 @@ const parseTsVersions = (aliases) => {
76
76
  const versions = findAttestTypeScriptVersions();
77
77
  if (aliases === "*")
78
78
  return versions;
79
- return arrayFrom(aliases).map(alias => {
79
+ return liftArray(aliases).map(alias => {
80
80
  const matching = versions.find(v => v.alias === alias);
81
81
  if (!matching) {
82
82
  throw new Error(`Specified TypeScript version ${alias} does not exist.` +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ark/attest",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
4
4
  "author": {
5
5
  "name": "David Blass",
6
6
  "email": "david@arktype.io",
@@ -27,9 +27,9 @@
27
27
  "dependencies": {
28
28
  "@typescript/vfs": "1.5.3",
29
29
  "@typescript/analyze-trace": "0.10.1",
30
- "arktype": "2.0.0-beta.0",
31
- "@ark/fs": "0.1.0",
32
- "@ark/util": "0.1.0"
30
+ "arktype": "2.0.0-beta.1",
31
+ "@ark/fs": "0.1.1",
32
+ "@ark/util": "0.1.1"
33
33
  },
34
34
  "devDependencies": {
35
35
  "typescript": "5.5.3"