@ark/attest 0.56.7 → 0.57.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.
Files changed (40) hide show
  1. package/README.md +9 -385
  2. package/out/assert/assertions.d.ts +1 -1
  3. package/out/assert/assertions.js +12 -18
  4. package/out/assert/attest.d.ts +2 -3
  5. package/out/assert/attest.js +3 -3
  6. package/out/assert/chainableAssertions.d.ts +1 -1
  7. package/out/assert/chainableAssertions.js +2 -1
  8. package/out/bench/type.js +6 -3
  9. package/out/cache/getCachedAssertions.d.ts +33 -11
  10. package/out/cache/getCachedAssertions.js +23 -46
  11. package/out/cache/snapshots.d.ts +6 -2
  12. package/out/cache/snapshots.js +32 -26
  13. package/out/cache/ts.js +6 -3
  14. package/out/cache/utils.d.ts +1 -1
  15. package/out/cache/writeAssertionCache.d.ts +1 -30
  16. package/out/cache/writeAssertionCache.js +2 -1
  17. package/out/cli/precache.js +3 -4
  18. package/out/cli/shared.d.ts +1 -1
  19. package/out/cli/shared.js +4 -1
  20. package/out/cli/trace.js +60 -25
  21. package/out/config.d.ts +6 -22
  22. package/out/config.js +5 -30
  23. package/out/fixtures.js +5 -18
  24. package/out/index.d.ts +1 -3
  25. package/out/index.js +1 -2
  26. package/out/ts7/analyze.d.ts +10 -0
  27. package/out/ts7/analyze.js +188 -0
  28. package/out/ts7/countInstantiations.d.ts +1 -0
  29. package/out/ts7/countInstantiations.js +44 -0
  30. package/out/ts7/instantiations.d.ts +13 -0
  31. package/out/ts7/instantiations.js +113 -0
  32. package/out/ts7/server.d.ts +48 -0
  33. package/out/ts7/server.js +224 -0
  34. package/out/ts7/snapshots.d.ts +5 -0
  35. package/out/ts7/snapshots.js +27 -0
  36. package/out/utils.d.ts +17 -0
  37. package/out/utils.js +33 -1
  38. package/package.json +8 -6
  39. package/out/tsVersioning.d.ts +0 -31
  40. package/out/tsVersioning.js +0 -172
package/out/utils.d.ts CHANGED
@@ -1,4 +1,21 @@
1
+ /** TypeScript 7+ is native and only exposes its API via tsgo's IPC client */
2
+ export declare const isTs7: boolean;
1
3
  export declare const getFileKey: (path: string) => string;
4
+ /**
5
+ * Narrows the files whose assertions are analyzed to the test files named on
6
+ * the command line, e.g. `pnpm testFiles ark/type/__tests__/brand.test.ts`,
7
+ * since those are the only tests that will run. Analysis cost scales with the
8
+ * files analyzed, so one file takes seconds where the whole project takes
9
+ * minutes. With no test file named, every root file is analyzed as before.
10
+ *
11
+ * Only applies with `--onlyNamedTestFiles`, which `testFiles` passes along with
12
+ * mocha's `--no-package`. Otherwise, mocha adds named files to the configured
13
+ * spec, so every test still runs.
14
+ *
15
+ * A test that runs without having been analyzed fails with "Found no assertion
16
+ * data", so a narrowing that missed a file can never pass silently.
17
+ */
18
+ export declare const narrowToNamedTestFiles: (rootFiles: string[]) => string[];
2
19
  /**
3
20
  * Can be used to allow arbitrarily chained property access and function calls.
4
21
  */
package/out/utils.js CHANGED
@@ -1,7 +1,39 @@
1
1
  import { caller } from "@ark/fs";
2
2
  import { throwError } from "@ark/util";
3
- import { basename, relative } from "node:path";
3
+ import { existsSync } from "node:fs";
4
+ import { basename, relative, resolve } from "node:path";
5
+ import ts from "typescript";
6
+ import { getConfig } from "./config.js";
7
+ /** TypeScript 7+ is native and only exposes its API via tsgo's IPC client */
8
+ export const isTs7 = Number.parseInt(ts.version) >= 7;
4
9
  export const getFileKey = (path) => relative(".", path);
10
+ const testFilePattern = /\.test\.[cm]?[jt]sx?$/;
11
+ /**
12
+ * Narrows the files whose assertions are analyzed to the test files named on
13
+ * the command line, e.g. `pnpm testFiles ark/type/__tests__/brand.test.ts`,
14
+ * since those are the only tests that will run. Analysis cost scales with the
15
+ * files analyzed, so one file takes seconds where the whole project takes
16
+ * minutes. With no test file named, every root file is analyzed as before.
17
+ *
18
+ * Only applies with `--onlyNamedTestFiles`, which `testFiles` passes along with
19
+ * mocha's `--no-package`. Otherwise, mocha adds named files to the configured
20
+ * spec, so every test still runs.
21
+ *
22
+ * A test that runs without having been analyzed fails with "Found no assertion
23
+ * data", so a narrowing that missed a file can never pass silently.
24
+ */
25
+ export const narrowToNamedTestFiles = (rootFiles) => {
26
+ if (!getConfig().onlyNamedTestFiles)
27
+ return rootFiles;
28
+ const named = new Set(process.argv
29
+ .slice(2)
30
+ .filter(arg => testFilePattern.test(arg) && existsSync(arg))
31
+ .map(arg => resolve(arg).replace(/\\/g, "/")));
32
+ if (!named.size)
33
+ return rootFiles;
34
+ const narrowed = rootFiles.filter(path => named.has(path));
35
+ return narrowed.length ? narrowed : rootFiles;
36
+ };
5
37
  /**
6
38
  * Can be used to allow arbitrarily chained property access and function calls.
7
39
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ark/attest",
3
- "version": "0.56.7",
3
+ "version": "0.57.1",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "David Blass",
@@ -40,13 +40,15 @@
40
40
  "@typescript/analyze-trace": "0.10.1",
41
41
  "@typescript/vfs": "1.6.1",
42
42
  "prettier": "3.6.2",
43
- "@ark/fs": "0.56.6",
44
- "arktype": "2.2.7",
45
- "@ark/util": "0.56.6",
46
- "@ark/schema": "0.56.6"
43
+ "@ark/fs": "0.56.8",
44
+ "@ark/util": "0.56.8",
45
+ "@ark/schema": "0.56.8",
46
+ "arktype": "2.2.9"
47
47
  },
48
48
  "devDependencies": {
49
- "typescript": "5.9.3"
49
+ "typescript": "7.1.0-beta",
50
+ "typescript-6": "npm:typescript@6.0.3",
51
+ "typescript-7": "npm:typescript@7.1.0-beta"
50
52
  },
51
53
  "peerDependencies": {
52
54
  "typescript": "*"
@@ -1,31 +0,0 @@
1
- import type { Digit } from "@ark/util";
2
- /**
3
- * Executes a provided function for an installed set of TypeScript versions.
4
- *
5
- * Your primary TypeScript version at node_modules/typescript will be
6
- * temporarily renamed to node_modules/typescript-temp, and reset after each
7
- * version has been executed, regardless of failures.
8
- *
9
- * Throws an error if any version fails when the associated function is executed.
10
- *
11
- * fn should spawn a new process so the new symlinked version can be loaded.
12
- */
13
- export declare const forTypeScriptVersions: (versions: TsVersionData[], fn: (version: TsVersionData) => void) => void;
14
- export type TsVersionData = {
15
- alias: string;
16
- version: string;
17
- path: string;
18
- };
19
- /**
20
- * Find and return the paths of all installed TypeScript versions by directly scanning
21
- * node_modules directories in the current package and all parent packages.
22
- *
23
- * This function only looks at directories, bypassing package.json entirely.
24
- *
25
- * @returns {TsVersionData[]} Information about each TypeScript version found
26
- */
27
- export declare const findAttestTypeScriptVersions: () => TsVersionData[];
28
- /** Get the TypeScript version being used by attest as as string like "5.0"
29
- * Does not include alternate versions that may be referenced by cache files
30
- */
31
- export declare const getPrimaryTsVersionUnderTest: () => `${Digit}.${Digit}`;
@@ -1,172 +0,0 @@
1
- import { assertPackageRoot, findPackageAncestors, readJson } from "@ark/fs";
2
- import { existsSync, readdirSync, renameSync, statSync, symlinkSync, unlinkSync } from "node:fs";
3
- import { join } from "node:path";
4
- import ts from "typescript";
5
- /**
6
- * Executes a provided function for an installed set of TypeScript versions.
7
- *
8
- * Your primary TypeScript version at node_modules/typescript will be
9
- * temporarily renamed to node_modules/typescript-temp, and reset after each
10
- * version has been executed, regardless of failures.
11
- *
12
- * Throws an error if any version fails when the associated function is executed.
13
- *
14
- * fn should spawn a new process so the new symlinked version can be loaded.
15
- */
16
- export const forTypeScriptVersions = (versions, fn) => {
17
- const passedVersions = [];
18
- const failedVersions = [];
19
- const nodeModules = join(assertPackageRoot(process.cwd()), "node_modules");
20
- const tsPrimaryPath = join(nodeModules, "typescript");
21
- const tsTemporaryPath = join(nodeModules, "typescript-temp");
22
- if (existsSync(tsTemporaryPath))
23
- unlinkSync(tsTemporaryPath);
24
- if (existsSync(tsPrimaryPath))
25
- renameSync(tsPrimaryPath, tsTemporaryPath);
26
- try {
27
- for (const version of versions) {
28
- const targetPath = version.path === tsPrimaryPath ? tsTemporaryPath : version.path;
29
- console.log(`⛵ Switching to TypeScript version ${version.alias} (${version.version})...`);
30
- try {
31
- if (existsSync(tsPrimaryPath))
32
- unlinkSync(tsPrimaryPath);
33
- symlinkSync(targetPath, tsPrimaryPath, "junction");
34
- fn(version);
35
- passedVersions.push(version);
36
- }
37
- catch (e) {
38
- console.error(e);
39
- failedVersions.push(version);
40
- }
41
- }
42
- if (failedVersions.length !== 0) {
43
- throw new Error(`❌ The following TypeScript versions threw: ${failedVersions
44
- .map(v => `${v.alias} (${v.version})`)
45
- .join(", ")}`);
46
- }
47
- console.log(`✅ Successfully ran TypeScript versions ${passedVersions
48
- .map(v => `${v.alias} (${v.version})`)
49
- .join(", ")}`);
50
- }
51
- finally {
52
- if (existsSync(tsTemporaryPath)) {
53
- console.log(`⏮️ Restoring your original TypeScript version...`);
54
- unlinkSync(tsPrimaryPath);
55
- renameSync(tsTemporaryPath, tsPrimaryPath);
56
- }
57
- }
58
- };
59
- const possibleTsVersionPrefix = "typescript-";
60
- const strictTsVersionPrefix = "attest-ts-";
61
- /**
62
- * Determine the alias from the directory name
63
- */
64
- const getDirAlias = (dirName) => {
65
- if (dirName === "typescript")
66
- return "default";
67
- if (dirName.startsWith(possibleTsVersionPrefix))
68
- return dirName.slice(possibleTsVersionPrefix.length);
69
- if (dirName.startsWith(strictTsVersionPrefix))
70
- return dirName.slice(strictTsVersionPrefix.length);
71
- return null;
72
- };
73
- /**
74
- * Try to get the TypeScript version from a directory
75
- */
76
- const getTsVersion = (fullPath) => {
77
- try {
78
- // Try to read package.json for version
79
- const packageJsonPath = join(fullPath, "package.json");
80
- if (existsSync(packageJsonPath)) {
81
- const packageJson = readJson(packageJsonPath);
82
- if (packageJson &&
83
- packageJson.name === "typescript" &&
84
- typeof packageJson.version === "string")
85
- return packageJson.version;
86
- }
87
- // As a fallback, check for the lib/typescript.js file which should exist in all TS installations
88
- if (existsSync(join(fullPath, "lib", "typescript.js")))
89
- return "unknown";
90
- return null;
91
- }
92
- catch {
93
- return null;
94
- }
95
- };
96
- /**
97
- * Find and return the paths of all installed TypeScript versions by directly scanning
98
- * node_modules directories in the current package and all parent packages.
99
- *
100
- * This function only looks at directories, bypassing package.json entirely.
101
- *
102
- * @returns {TsVersionData[]} Information about each TypeScript version found
103
- */
104
- export const findAttestTypeScriptVersions = () => {
105
- const packagePaths = findPackageAncestors(process.cwd());
106
- const versions = [];
107
- const foundVersionAliases = new Set();
108
- // Check each package's node_modules directory
109
- for (const packagePath of packagePaths) {
110
- const nodeModulesPath = join(packagePath, "node_modules");
111
- if (!existsSync(nodeModulesPath) ||
112
- !statSync(nodeModulesPath).isDirectory())
113
- continue;
114
- // Check for regular typescript or typescript-* directories
115
- const dirNames = readdirSync(nodeModulesPath);
116
- for (const dirName of dirNames) {
117
- // Skip node_modules/@* directories - we'll handle them below
118
- if (dirName.startsWith("@"))
119
- continue;
120
- const fullPath = join(nodeModulesPath, dirName);
121
- if (!statSync(fullPath).isDirectory())
122
- continue;
123
- const alias = getDirAlias(dirName);
124
- if (!alias)
125
- continue;
126
- // Skip if we already found this alias in a closer package
127
- if (foundVersionAliases.has(alias))
128
- continue;
129
- const version = getTsVersion(fullPath);
130
- if (version) {
131
- foundVersionAliases.add(alias);
132
- versions.push({
133
- alias,
134
- version,
135
- path: fullPath
136
- });
137
- }
138
- }
139
- // Check for @ark/attest-ts-* directories
140
- const arkDir = join(nodeModulesPath, "@ark");
141
- if (existsSync(arkDir) && statSync(arkDir).isDirectory()) {
142
- const arkDirs = readdirSync(arkDir);
143
- for (const dirName of arkDirs) {
144
- if (!dirName.startsWith("attest-ts-"))
145
- continue;
146
- const fullPath = join(arkDir, dirName);
147
- if (!statSync(fullPath).isDirectory())
148
- continue;
149
- const alias = getDirAlias(dirName);
150
- if (!alias)
151
- continue;
152
- // Skip if we already found this alias in a closer package
153
- if (foundVersionAliases.has(alias))
154
- continue;
155
- const version = getTsVersion(fullPath);
156
- if (version) {
157
- foundVersionAliases.add(alias);
158
- versions.push({
159
- alias,
160
- version,
161
- path: fullPath
162
- });
163
- }
164
- }
165
- }
166
- }
167
- return versions;
168
- };
169
- /** Get the TypeScript version being used by attest as as string like "5.0"
170
- * Does not include alternate versions that may be referenced by cache files
171
- */
172
- export const getPrimaryTsVersionUnderTest = () => ts.versionMajorMinor;