@ark/attest 0.44.7 → 0.45.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.
@@ -19,7 +19,7 @@ export const attestInternal = (value, { cfg: cfgHooks, ...ctxHooks } = {}) => {
19
19
  };
20
20
  if (!cfg.skipTypes) {
21
21
  ctx.typeRelationshipAssertionEntries = getTypeAssertionsAtPosition(position);
22
- if (ctx.typeRelationshipAssertionEntries[0][1].typeArgs[0]) {
22
+ if (ctx.typeRelationshipAssertionEntries[0]?.[1].typeArgs[0]) {
23
23
  // if there is an expected type arg, check it immediately
24
24
  assertEquals(undefined, typeEqualityMapping, ctx);
25
25
  }
package/out/cache/ts.js CHANGED
@@ -1,4 +1,4 @@
1
- import { fromCwd } from "@ark/fs";
1
+ import { fromCwd, readFile } from "@ark/fs";
2
2
  import { printable, throwError, throwInternalError } from "@ark/util";
3
3
  import * as tsvfs from "@typescript/vfs";
4
4
  import { readFileSync } from "node:fs";
@@ -21,7 +21,14 @@ export class TsServer {
21
21
  const tsLibPaths = getTsLibFiles(this.tsConfigInfo.parsed.options);
22
22
  // TS represents windows paths as `C:/Users/ssalb/...`
23
23
  const normalizedCwd = fromCwd().replaceAll(/\\/g, "/");
24
- this.rootFiles = this.tsConfigInfo.parsed.fileNames.filter(path => path.startsWith(normalizedCwd));
24
+ this.rootFiles = this.tsConfigInfo.parsed.fileNames.filter(path => {
25
+ if (!path.startsWith(normalizedCwd))
26
+ return;
27
+ // exclude empty files as they lead to a crash
28
+ // when createVirtualTypeScriptEnvironment is called
29
+ const contents = readFile(path).trim();
30
+ return contents !== "";
31
+ });
25
32
  const system = tsvfs.createFSBackedSystem(tsLibPaths.defaultMapFromNodeModules, this.tsConfigInfo.path ? dirname(this.tsConfigInfo.path) : fromCwd(), ts);
26
33
  this.virtualEnv = tsvfs.createVirtualTypeScriptEnvironment(system, this.rootFiles, ts, this.tsConfigInfo.parsed.options);
27
34
  this.program = this.virtualEnv.languageService.getProgram();
@@ -6,7 +6,6 @@ import type { Digit } from "@ark/util";
6
6
  * temporarily renamed to node_modules/typescript-temp, and reset after each
7
7
  * version has been executed, regardless of failures.
8
8
  *
9
- *
10
9
  * Throws an error if any version fails when the associated function is executed.
11
10
  *
12
11
  * fn should spawn a new process so the new symlinked version can be loaded.
@@ -18,22 +17,12 @@ export type TsVersionData = {
18
17
  path: string;
19
18
  };
20
19
  /**
21
- * Find and return the paths of all installed TypeScript versions, including the
22
- * all dependencies beginning with "typescript" or "@ark/attest-ts-".
23
- *
24
- * Starts checking from the current directory and looks for node_modules in parent
25
- * directories up to the file system root.
26
- *
27
- * Alternate versions can be installed using a package.json dependency like:
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.
28
22
  *
29
- * ```json
30
- * "@ark/attest-ts-min": "npm:typescript@5.1.6"
31
- * ```
32
- * @returns {TsVersionData[]} Each version mapped to data, e.g.:
33
- * {alias: "@ark/attest-ts-min", version: "5.1.6", path: "/home/ssalb/arktype/node_modules/@ark/attest-ts-min" } *
23
+ * This function only looks at directories, bypassing package.json entirely.
34
24
  *
35
- * @throws {Error} If a TypeScript version specified in package.json is not
36
- * installed at the expected location in node_modules.
25
+ * @returns {TsVersionData[]} Information about each TypeScript version found
37
26
  */
38
27
  export declare const findAttestTypeScriptVersions: () => TsVersionData[];
39
28
  /** Get the TypeScript version being used by attest as as string like "5.0"
@@ -1,7 +1,6 @@
1
- import { assertPackageRoot, fsRoot, readJson } from "@ark/fs";
2
- import { existsSync, renameSync, symlinkSync, unlinkSync } from "fs";
3
- import { dirname } from "path";
4
- import { join } from "path/posix";
1
+ import { assertPackageRoot, findPackageAncestors, readJson } from "@ark/fs";
2
+ import { existsSync, readdirSync, renameSync, statSync, symlinkSync, unlinkSync } from "fs";
3
+ import { join } from "path";
5
4
  import ts from "typescript";
6
5
  /**
7
6
  * Executes a provided function for an installed set of TypeScript versions.
@@ -10,7 +9,6 @@ import ts from "typescript";
10
9
  * temporarily renamed to node_modules/typescript-temp, and reset after each
11
10
  * version has been executed, regardless of failures.
12
11
  *
13
- *
14
12
  * Throws an error if any version fails when the associated function is executed.
15
13
  *
16
14
  * fn should spawn a new process so the new symlinked version can be loaded.
@@ -59,70 +57,117 @@ export const forTypeScriptVersions = (versions, fn) => {
59
57
  }
60
58
  };
61
59
  const possibleTsVersionPrefix = "typescript-";
62
- const strictTsVersionPrefix = "@ark/attest-ts-";
63
- const parseInstalledTsAlias = (installedAlias) => {
64
- if (installedAlias === "typescript")
60
+ const strictTsVersionPrefix = "attest-ts-";
61
+ /**
62
+ * Determine the alias from the directory name
63
+ */
64
+ const getDirAlias = (dirName) => {
65
+ if (dirName === "typescript")
65
66
  return "default";
66
- if (installedAlias.startsWith(possibleTsVersionPrefix))
67
- return installedAlias.slice(possibleTsVersionPrefix.length);
68
- if (installedAlias.startsWith(strictTsVersionPrefix))
69
- return installedAlias.slice(strictTsVersionPrefix.length);
67
+ if (dirName.startsWith(possibleTsVersionPrefix))
68
+ return dirName.slice(possibleTsVersionPrefix.length);
69
+ if (dirName.startsWith(strictTsVersionPrefix))
70
+ return dirName.slice(strictTsVersionPrefix.length);
70
71
  return null;
71
72
  };
72
73
  /**
73
- * Find and return the paths of all installed TypeScript versions, including the
74
- * all dependencies beginning with "typescript" or "@ark/attest-ts-".
75
- *
76
- * Starts checking from the current directory and looks for node_modules in parent
77
- * directories up to the file system root.
78
- *
79
- * Alternate versions can be installed using a package.json dependency like:
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.
80
99
  *
81
- * ```json
82
- * "@ark/attest-ts-min": "npm:typescript@5.1.6"
83
- * ```
84
- * @returns {TsVersionData[]} Each version mapped to data, e.g.:
85
- * {alias: "@ark/attest-ts-min", version: "5.1.6", path: "/home/ssalb/arktype/node_modules/@ark/attest-ts-min" } *
100
+ * This function only looks at directories, bypassing package.json entirely.
86
101
  *
87
- * @throws {Error} If a TypeScript version specified in package.json is not
88
- * installed at the expected location in node_modules.
102
+ * @returns {TsVersionData[]} Information about each TypeScript version found
89
103
  */
90
104
  export const findAttestTypeScriptVersions = () => {
91
- let currentDir = process.cwd();
105
+ const packagePaths = findPackageAncestors(process.cwd());
92
106
  const versions = [];
93
- while (currentDir !== fsRoot) {
94
- const packageJsonPath = join(currentDir, "package.json");
95
- if (!existsSync(packageJsonPath)) {
96
- currentDir = dirname(currentDir);
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())
97
113
  continue;
98
- }
99
- const nodeModulesPath = join(currentDir, "node_modules");
100
- const packageJson = readJson(packageJsonPath);
101
- const dependencies = {
102
- ...packageJson.dependencies,
103
- ...packageJson.devDependencies
104
- };
105
- for (const installedAlias in dependencies) {
106
- const alias = parseInstalledTsAlias(installedAlias);
107
- if (alias === null)
108
- continue;
109
- const path = join(nodeModulesPath, installedAlias);
110
- if (!existsSync(path)) {
111
- throw Error(`TypeScript version ${installedAlias} specified in ${packageJsonPath} must be installed at ${path} `);
114
+ try {
115
+ // Check for regular typescript or typescript-* directories
116
+ const dirNames = readdirSync(nodeModulesPath);
117
+ for (const dirName of dirNames) {
118
+ // Skip node_modules/@* directories - we'll handle them below
119
+ if (dirName.startsWith("@"))
120
+ continue;
121
+ const fullPath = join(nodeModulesPath, dirName);
122
+ if (!statSync(fullPath).isDirectory())
123
+ continue;
124
+ const alias = getDirAlias(dirName);
125
+ if (!alias)
126
+ continue;
127
+ // Skip if we already found this alias in a closer package
128
+ if (foundVersionAliases.has(alias))
129
+ continue;
130
+ const version = getTsVersion(fullPath);
131
+ if (version) {
132
+ foundVersionAliases.add(alias);
133
+ versions.push({
134
+ alias,
135
+ version,
136
+ path: fullPath
137
+ });
138
+ }
112
139
  }
113
- const typescriptJson = readJson(join(path, "package.json"));
114
- if (typescriptJson.name !== "typescript") {
115
- if (installedAlias.startsWith(strictTsVersionPrefix))
116
- throw new Error(`Package at ${path} should be named "typescript"`);
117
- continue;
140
+ // Check for @ark/attest-ts-* directories
141
+ const arkDir = join(nodeModulesPath, "@ark");
142
+ if (existsSync(arkDir) && statSync(arkDir).isDirectory()) {
143
+ const arkDirs = readdirSync(arkDir);
144
+ for (const dirName of arkDirs) {
145
+ if (!dirName.startsWith("attest-ts-"))
146
+ continue;
147
+ const fullPath = join(arkDir, dirName);
148
+ if (!statSync(fullPath).isDirectory())
149
+ continue;
150
+ const alias = getDirAlias(dirName);
151
+ if (!alias)
152
+ continue;
153
+ // Skip if we already found this alias in a closer package
154
+ if (foundVersionAliases.has(alias))
155
+ continue;
156
+ const version = getTsVersion(fullPath);
157
+ if (version) {
158
+ foundVersionAliases.add(alias);
159
+ versions.push({
160
+ alias,
161
+ version,
162
+ path: fullPath
163
+ });
164
+ }
165
+ }
118
166
  }
119
- versions.push({
120
- alias,
121
- version: typescriptJson.version,
122
- path
123
- });
124
167
  }
125
- currentDir = dirname(currentDir);
168
+ catch (err) {
169
+ console.warn(`Warning: Error scanning ${nodeModulesPath}: ${err}`);
170
+ }
126
171
  }
127
172
  return versions;
128
173
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ark/attest",
3
- "version": "0.44.7",
3
+ "version": "0.45.0",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "David Blass",
@@ -36,9 +36,9 @@
36
36
  "@typescript/analyze-trace": "0.10.1",
37
37
  "@typescript/vfs": "1.6.0",
38
38
  "prettier": "3.4.2",
39
- "@ark/fs": "0.44.5",
40
- "@ark/util": "0.44.5",
41
- "arktype": "2.1.9"
39
+ "@ark/fs": "0.45.0",
40
+ "arktype": "2.1.10",
41
+ "@ark/util": "0.45.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "typescript": "5.8.2"