@ark/attest 0.36.0 → 0.38.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/out/cache/ts.d.ts CHANGED
@@ -14,7 +14,7 @@ export declare class TsServer {
14
14
  export declare const nearestCallExpressionChild: (node: ts.Node, position: number) => ts.CallExpression;
15
15
  export declare const getAbsolutePosition: (file: ts.SourceFile, position: SourcePosition) => number;
16
16
  export type TsconfigInfo = {
17
- path: string;
17
+ path: string | undefined;
18
18
  parsed: ts.ParsedCommandLine;
19
19
  };
20
20
  export declare const getTsConfigInfoOrThrow: () => TsconfigInfo;
package/out/cache/ts.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { fromCwd } from "@ark/fs";
2
- import { printable, throwInternalError } from "@ark/util";
2
+ import { printable, throwError, throwInternalError } from "@ark/util";
3
3
  import * as tsvfs from "@typescript/vfs";
4
4
  import { readFileSync } from "node:fs";
5
5
  import { dirname, join } from "node:path";
@@ -22,7 +22,7 @@ export class TsServer {
22
22
  // TS represents windows paths as `C:/Users/ssalb/...`
23
23
  const normalizedCwd = fromCwd().replaceAll(/\\/g, "/");
24
24
  this.rootFiles = this.tsConfigInfo.parsed.fileNames.filter(path => path.startsWith(normalizedCwd));
25
- const system = tsvfs.createFSBackedSystem(tsLibPaths.defaultMapFromNodeModules, dirname(this.tsConfigInfo.path), ts);
25
+ const system = tsvfs.createFSBackedSystem(tsLibPaths.defaultMapFromNodeModules, this.tsConfigInfo.path ? dirname(this.tsConfigInfo.path) : fromCwd(), ts);
26
26
  this.virtualEnv = tsvfs.createVirtualTypeScriptEnvironment(system, this.rootFiles, ts, this.tsConfigInfo.parsed.options);
27
27
  this.program = this.virtualEnv.languageService.getProgram();
28
28
  TsServer._instance = this;
@@ -59,34 +59,50 @@ export const getAbsolutePosition = (file, position) => {
59
59
  export const getTsConfigInfoOrThrow = () => {
60
60
  const config = getConfig();
61
61
  const tsconfig = config.tsconfig;
62
- const configFilePath = tsconfig ?? ts.findConfigFile(fromCwd(), ts.sys.fileExists, "tsconfig.json");
63
- if (!configFilePath) {
64
- throw new Error(`File ${tsconfig ?? join(fromCwd(), "tsconfig.json")} must exist`);
65
- }
66
- const configFileText = readFileSync(configFilePath).toString();
67
- const result = ts.parseConfigFileTextToJson(configFilePath, configFileText);
68
- if (result.error) {
69
- throw new Error(ts.formatDiagnostics([result.error], {
70
- getCanonicalFileName: fileName => fileName,
71
- getCurrentDirectory: process.cwd,
72
- getNewLine: () => ts.sys.newLine
73
- }));
74
- }
75
- const configJson = result.config;
76
- configJson.compilerOptions = Object.assign(configJson.compilerOptions ?? {}, config.compilerOptions);
77
- const configParseResult = ts.parseJsonConfigFileContent(configJson, ts.sys, dirname(configFilePath), {}, configFilePath);
78
- if (configParseResult.errors.length > 0) {
79
- throw new Error(ts.formatDiagnostics(configParseResult.errors, {
80
- getCanonicalFileName: fileName => fileName,
81
- getCurrentDirectory: process.cwd,
82
- getNewLine: () => ts.sys.newLine
83
- }));
62
+ let instantiatedConfig;
63
+ let configFilePath;
64
+ if (tsconfig !== null) {
65
+ configFilePath =
66
+ tsconfig ??
67
+ ts.findConfigFile(fromCwd(), ts.sys.fileExists, "tsconfig.json");
68
+ if (configFilePath)
69
+ instantiatedConfig = instantiateTsconfigFromPath(configFilePath);
84
70
  }
71
+ instantiatedConfig ??= instantiateNoFileConfig();
85
72
  return {
86
73
  path: configFilePath,
87
- parsed: configParseResult
74
+ parsed: instantiatedConfig
88
75
  };
89
76
  };
77
+ const instantiateNoFileConfig = () => {
78
+ const arkConfig = getConfig();
79
+ const instantiatedConfig = ts.parseJsonConfigFileContent({
80
+ compilerOptions: arkConfig.compilerOptions
81
+ }, ts.sys, fromCwd());
82
+ if (instantiatedConfig.errors.length > 0)
83
+ throwConfigInstantiationError(instantiatedConfig);
84
+ return instantiatedConfig;
85
+ };
86
+ const instantiateTsconfigFromPath = (path) => {
87
+ const arkConfig = getConfig();
88
+ const configFileText = readFileSync(path).toString();
89
+ const result = ts.parseConfigFileTextToJson(path, configFileText);
90
+ if (result.error)
91
+ throwConfigParseError(result.error);
92
+ const rawConfig = result.config;
93
+ rawConfig.compilerOptions = Object.assign(rawConfig.compilerOptions ?? {}, arkConfig.compilerOptions);
94
+ const instantiatedConfig = ts.parseJsonConfigFileContent(rawConfig, ts.sys, dirname(path), {}, path);
95
+ if (instantiatedConfig.errors.length > 0)
96
+ throwConfigInstantiationError(instantiatedConfig);
97
+ return instantiatedConfig;
98
+ };
99
+ const defaultDiagnosticHost = {
100
+ getCanonicalFileName: fileName => fileName,
101
+ getCurrentDirectory: process.cwd,
102
+ getNewLine: () => ts.sys.newLine
103
+ };
104
+ const throwConfigParseError = (error) => throwError(ts.formatDiagnostics([error], defaultDiagnosticHost));
105
+ const throwConfigInstantiationError = (instantiatedConfig) => throwError(ts.formatDiagnostics(instantiatedConfig.errors, defaultDiagnosticHost));
90
106
  export const getTsLibFiles = (tsconfigOptions) => {
91
107
  const defaultMapFromNodeModules = tsvfs.createDefaultMapFromNodeModules(tsconfigOptions);
92
108
  const libPath = dirname(ts.getDefaultLibFilePath(tsconfigOptions));
package/out/config.js CHANGED
@@ -40,6 +40,8 @@ const getParamValue = (param) => {
40
40
  return true;
41
41
  if (raw === "false")
42
42
  return false;
43
+ if (raw === "null")
44
+ return null;
43
45
  if (param === "benchPercentThreshold")
44
46
  return tryParseNumber(raw, { errorOnFail: true });
45
47
  if (param === "tsVersions" || param === "attestAliases")
@@ -9,9 +9,7 @@ import type { Digit } from "@ark/util";
9
9
  *
10
10
  * Throws an error if any version fails when the associated function is executed.
11
11
  *
12
- * @param {TsVersionData[]} versions The set of versions for which to exceute the function
13
- * @param {function} fn - The function to execute for each TypeScript version.
14
- * Should spawn a new process so the new symlinked version can be loaded.
12
+ * fn should spawn a new process so the new symlinked version can be loaded.
15
13
  */
16
14
  export declare const forTypeScriptVersions: (versions: TsVersionData[], fn: (version: TsVersionData) => void) => void;
17
15
  export type TsVersionData = {
@@ -13,9 +13,7 @@ import ts from "typescript";
13
13
  *
14
14
  * Throws an error if any version fails when the associated function is executed.
15
15
  *
16
- * @param {TsVersionData[]} versions The set of versions for which to exceute the function
17
- * @param {function} fn - The function to execute for each TypeScript version.
18
- * Should spawn a new process so the new symlinked version can be loaded.
16
+ * fn should spawn a new process so the new symlinked version can be loaded.
19
17
  */
20
18
  export const forTypeScriptVersions = (versions, fn) => {
21
19
  const passedVersions = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ark/attest",
3
- "version": "0.36.0",
3
+ "version": "0.38.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
- "arktype": "2.0.0-rc.32",
40
- "@ark/util": "0.32.0",
41
- "@ark/fs": "0.32.0"
39
+ "@ark/util": "0.34.0",
40
+ "arktype": "2.0.0",
41
+ "@ark/fs": "0.34.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "typescript": "5.7.2"