@ark/attest 0.10.2 → 0.12.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/README.md CHANGED
@@ -37,7 +37,7 @@ export default defineConfig({
37
37
  `setupVitest.ts`
38
38
 
39
39
  ```ts
40
- import { setup, teardown } from "@ark/attest"
40
+ import { setup } from "@ark/attest"
41
41
 
42
42
  // config options can be passed here
43
43
  export default () => setup({})
@@ -140,6 +140,88 @@ describe("attest features", () => {
140
140
  })
141
141
  ```
142
142
 
143
+ ## Options
144
+
145
+ Options can be specified in one of 3 ways:
146
+
147
+ - An argument passed to your test process, e.g. `--skipTypes` or `--benchPercentThreshold 10`
148
+ - An environment variable with an `ATTEST_` prefix, e.g. `ATTEST_skipTypes=1` or `ATTEST_benchPercentThreshold=10`
149
+ - Passed as an option to attest's `setup` function, e.g.:
150
+
151
+ `setupVitest.ts`
152
+
153
+ ```ts
154
+ import * as attest from "@ark/attest"
155
+
156
+ export const setup = () =>
157
+ attest.setup({
158
+ skipTypes: true,
159
+ benchPercentThreshold: 10
160
+ })
161
+ ```
162
+
163
+ Here are the current defaults for all available options. Please note, some of these are experimental and subject to change:
164
+
165
+ ```ts
166
+ export const getDefaultAttestConfig = (): BaseAttestConfig => ({
167
+ tsconfig:
168
+ existsSync(fromCwd("tsconfig.json")) ? fromCwd("tsconfig.json") : undefined,
169
+ attestAliases: ["attest", "attestInternal"],
170
+ updateSnapshots: false,
171
+ skipTypes: false,
172
+ skipInlineInstantiations: false,
173
+ tsVersions: "typescript",
174
+ benchPercentThreshold: 20,
175
+ benchErrorOnThresholdExceeded: true,
176
+ filter: undefined,
177
+ testDeclarationAliases: ["bench", "it", "test"],
178
+ formatter: `npm exec --no -- prettier --write`,
179
+ shouldFormat: true,
180
+ typeToStringFormat: {}
181
+ })
182
+ ```
183
+
184
+ ### `skipTypes`
185
+
186
+ `skipTypes` is extremely useful for iterating quickly during development without having to typecheck your project to test runtime logic.
187
+
188
+ When this setting is enabled, setup will skip typechecking and all assertions requiring type information will be skipped.
189
+
190
+ You likely want two scripts, one for running tests with types and one for tests without:
191
+
192
+ ```json
193
+ "test": "ATTEST_skipTypes=1 vitest run",
194
+ "testWithTypes": "vitest run",
195
+ ```
196
+
197
+ Our recommendation is to use `test` when:
198
+
199
+ - Only wanting to test runtime logic during development
200
+ - Running tests in watch mode or via VSCode's Test Explorer
201
+
202
+ Use `testWithTypes` when:
203
+
204
+ - You've made changes to your types and want to recheck your type-level assertions
205
+ - You're running your tests in CI
206
+
207
+ ### `typeToStringFormat`
208
+
209
+ A set of [`prettier.Options`](https://prettier.io/docs/en/options.html) overrides that apply specifically `type.toString` formatting.
210
+
211
+ Any options you provide will override the defaults, which are as follows:
212
+
213
+ ```jsonc
214
+ {
215
+ "semi": false,
216
+ // note this print width is optimized for type serialization, not general code
217
+ "printWidth": 60,
218
+ "trailingComma": "none",
219
+ "parser": "typescript"
220
+ }
221
+ ```
222
+
223
+ The easiest way to provide overrides is to the `setup` function, but they can also be provided as a JSON serialized string either passed to a `--typeToStringFormat` CLI flag or set as the value of `ATTEST_typeToStringFormat` on `process.env`.
224
+
143
225
  ## Benches
144
226
 
145
227
  Benches are run separately from tests and don't require any special setup. If the below file was `benches.ts`, you could run it using something like `tsx benches.ts` or `ts-node benches.ts`:
@@ -221,7 +303,7 @@ If no directories are provided, defaults to CWD.
221
303
  npm run attest trace .
222
304
  ```
223
305
 
224
- Creates a trace.json file in a .tstrace directory that can be viewed as a type performance heat map via a tool like https://ui.perfetto.dev/. Also summarizes any hot spots as identified by `@typescript/analyze-trace`.
306
+ Creates a trace.json file in `.attest/trace` that can be viewed as a type performance heat map via a tool like https://ui.perfetto.dev/. Also summarizes any hot spots as identified by `@typescript/analyze-trace`.
225
307
 
226
308
  Trace expects a single argument representing the root directory of the root package for which to gather type information.
227
309
 
@@ -18,6 +18,7 @@ export declare class TypeAssertionMapping {
18
18
  }
19
19
  export declare const versionableAssertion: (fn: AssertFn) => AssertFn;
20
20
  export declare const assertEquals: AssertFn;
21
+ export declare const assertSatisfies: AssertFn;
21
22
  export declare const typeEqualityMapping: TypeAssertionMapping;
22
23
  export declare const assertEqualOrMatching: AssertFn;
23
24
  export type AssertedFnCallResult = {
@@ -59,6 +59,16 @@ const unversionedAssertEquals = (expected, actual, ctx) => {
59
59
  }
60
60
  };
61
61
  export const assertEquals = versionableAssertion(unversionedAssertEquals);
62
+ const unversionedAssertSatisfies = (t, data, ctx) => {
63
+ try {
64
+ t.assert(data);
65
+ }
66
+ catch (e) {
67
+ e.stack = ctx.assertionStack;
68
+ throw e;
69
+ }
70
+ };
71
+ export const assertSatisfies = versionableAssertion(unversionedAssertSatisfies);
62
72
  export const typeEqualityMapping = new TypeAssertionMapping(data => {
63
73
  const expected = data.typeArgs[0];
64
74
  const actual = data.typeArgs[1] ?? data.args[0];
@@ -5,10 +5,10 @@ import { type VersionedTypeAssertion } from "../cache/getCachedAssertions.js";
5
5
  import { type AttestConfig } from "../config.js";
6
6
  import { ChainableAssertions, type AssertionKind, type rootAssertions } from "./chainableAssertions.js";
7
7
  export type AttestFn = {
8
+ <expected>(actual: expected): rootAssertions<expected, AssertionKind>;
8
9
  <expected, actual extends expected = never>(...args: actual extends never ? [
9
10
  ErrorMessage<"Type-only assertion requires two explicit genreic params, e.g. attest<expected, actual>">
10
11
  ] : []): void;
11
- <expected>(actual: expected): rootAssertions<expected, AssertionKind>;
12
12
  instantiations: (count?: Measure<"instantiations"> | undefined) => void;
13
13
  };
14
14
  export type AssertionContext = {
@@ -58,7 +58,7 @@ export type TypeAssertionsRoot = {
58
58
  type: TypeAssertionProps;
59
59
  };
60
60
  export type TypeAssertionProps = {
61
- toString: valueFromTypeAssertion<string>;
61
+ toString: valueFromTypeAssertion<string | RegExp>;
62
62
  errors: valueFromTypeAssertion<string | RegExp, string>;
63
63
  completions: (value?: Completions) => void;
64
64
  };
@@ -1,11 +1,13 @@
1
1
  import { caller } from "@ark/fs";
2
2
  import { printable, snapshot } from "@ark/util";
3
+ import prettier from "@prettier/sync";
3
4
  import { type } from "arktype";
4
5
  import * as assert from "node:assert/strict";
5
6
  import { isDeepStrictEqual } from "node:util";
6
7
  import { getSnapshotByName, queueSnapshotUpdate, updateExternalSnapshot } from "../cache/snapshots.js";
8
+ import { getConfig } from "../config.js";
7
9
  import { chainableNoOpProxy } from "../utils.js";
8
- import { TypeAssertionMapping, assertEqualOrMatching, assertEquals, callAssertedFunction, getThrownMessage, throwAssertionError } from "./assertions.js";
10
+ import { TypeAssertionMapping, assertEqualOrMatching, assertEquals, assertSatisfies, callAssertedFunction, getThrownMessage, throwAssertionError } from "./assertions.js";
9
11
  export class ChainableAssertions {
10
12
  ctx;
11
13
  constructor(ctx) {
@@ -41,7 +43,7 @@ export class ChainableAssertions {
41
43
  return this;
42
44
  }
43
45
  satisfies(def) {
44
- type(def).assert(def);
46
+ assertSatisfies(type.raw(def), this.ctx.actual, this.ctx);
45
47
  return this;
46
48
  }
47
49
  instanceOf(expected) {
@@ -153,8 +155,9 @@ export class ChainableAssertions {
153
155
  return {
154
156
  get toString() {
155
157
  self.ctx.actual = new TypeAssertionMapping(data => ({
156
- actual: data.args[0].type
158
+ actual: formatTypeString(data.args[0].type)
157
159
  }));
160
+ self.ctx.allowRegex = true;
158
161
  return self.immediateOrChained();
159
162
  },
160
163
  get errors() {
@@ -174,3 +177,14 @@ const checkCompletionsForErrors = (completions) => {
174
177
  if (typeof completions === "string")
175
178
  throw new Error(completions);
176
179
  };
180
+ const declarationPrefix = "type T = ";
181
+ const formatTypeString = (typeString) => prettier
182
+ .format(`${declarationPrefix}${typeString}`, {
183
+ semi: false,
184
+ printWidth: 60,
185
+ trailingComma: "none",
186
+ parser: "typescript",
187
+ ...getConfig().typeToStringFormat
188
+ })
189
+ .slice(declarationPrefix.length)
190
+ .trimEnd();
@@ -1,4 +1,3 @@
1
- import type { TypeRelationship } from "../cache/writeAssertionCache.js";
2
1
  import type { BenchContext } from "./bench.js";
3
2
  import { type Measure, type TypeUnit } from "./measure.js";
4
3
  export type BenchTypeAssertions = {
@@ -6,11 +5,4 @@ export type BenchTypeAssertions = {
6
5
  };
7
6
  export declare const createBenchTypeAssertion: (ctx: BenchContext) => BenchTypeAssertions;
8
7
  export declare const getContributedInstantiations: (ctx: BenchContext) => number;
9
- export type ArgAssertionData = {
10
- type: string;
11
- relationships: {
12
- args: TypeRelationship[];
13
- typeArgs: TypeRelationship[];
14
- };
15
- };
16
8
  export declare const instantiationDataHandler: (ctx: BenchContext, args?: Measure<TypeUnit>, isBenchFunction?: boolean) => void;
@@ -83,7 +83,9 @@ const writeCachedInlineSnapshotUpdates = () => {
83
83
  const snapshotArgsToQueuedUpdate = ({ position, serializedValue, snapFunctionName = "snap", baselinePath }) => {
84
84
  const snapCall = findCallExpressionAncestor(position, snapFunctionName);
85
85
  const newArgText = typeof serializedValue === "string" && serializedValue.includes("\n") ?
86
- "`" + serializedValue.replaceAll("`", "\\`") + "`"
86
+ "`" +
87
+ serializedValue.replaceAll("`", "\\`").replaceAll("${", "\\${") +
88
+ "`"
87
89
  : JSON.stringify(serializedValue);
88
90
  return {
89
91
  position,
@@ -110,7 +112,7 @@ export const writeUpdates = (queuedUpdates) => {
110
112
  runFormatterIfAvailable(queuedUpdates);
111
113
  };
112
114
  const runFormatterIfAvailable = (queuedUpdates) => {
113
- const { formatter, shouldFormat } = getConfig();
115
+ const { formatCmd: formatter, shouldFormat } = getConfig();
114
116
  if (!shouldFormat)
115
117
  return;
116
118
  try {
package/out/cache/ts.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { fromCwd } from "@ark/fs";
2
2
  import { throwInternalError } from "@ark/util";
3
- import prettier from "@prettier/sync";
4
3
  import * as tsvfs from "@typescript/vfs";
5
4
  import { readFileSync } from "node:fs";
6
5
  import { dirname, join } from "node:path";
@@ -44,9 +43,9 @@ export const nearestCallExpressionChild = (node, position) => {
44
43
  return result;
45
44
  };
46
45
  const nearestBoundingCallExpression = (node, position) => node.pos <= position && node.end >= position ?
47
- node
46
+ (node
48
47
  .getChildren()
49
- .flatMap(child => nearestBoundingCallExpression(child, position) ?? [])[0] ?? (ts.isCallExpression(node) ? node : undefined)
48
+ .flatMap(child => nearestBoundingCallExpression(child, position) ?? [])[0] ?? (ts.isCallExpression(node) ? node : undefined))
50
49
  : undefined;
51
50
  export const getAbsolutePosition = (file, position) => {
52
51
  const pos = ts.getPositionOfLineAndCharacter(file,
@@ -58,10 +57,11 @@ export const getAbsolutePosition = (file, position) => {
58
57
  return pos;
59
58
  };
60
59
  export const getTsConfigInfoOrThrow = () => {
61
- const config = getConfig().tsconfig;
62
- const configFilePath = config ?? ts.findConfigFile(fromCwd(), ts.sys.fileExists, "tsconfig.json");
60
+ const config = getConfig();
61
+ const tsconfig = config.tsconfig;
62
+ const configFilePath = tsconfig ?? ts.findConfigFile(fromCwd(), ts.sys.fileExists, "tsconfig.json");
63
63
  if (!configFilePath) {
64
- throw new Error(`File ${config ?? join(fromCwd(), "tsconfig.json")} must exist.`);
64
+ throw new Error(`File ${tsconfig ?? join(fromCwd(), "tsconfig.json")} must exist.`);
65
65
  }
66
66
  const configFileText = readFileSync(configFilePath).toString();
67
67
  const result = ts.parseConfigFileTextToJson(configFilePath, configFileText);
@@ -72,8 +72,9 @@ export const getTsConfigInfoOrThrow = () => {
72
72
  getNewLine: () => ts.sys.newLine
73
73
  }));
74
74
  }
75
- const configObject = result.config;
76
- const configParseResult = ts.parseJsonConfigFileContent(configObject, ts.sys, dirname(configFilePath), {}, configFilePath);
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);
77
78
  if (configParseResult.errors.length > 0) {
78
79
  throw new Error(ts.formatDiagnostics(configParseResult.errors, {
79
80
  getCanonicalFileName: fileName => fileName,
@@ -97,41 +98,16 @@ export const getTsLibFiles = (tsconfigOptions) => {
97
98
  export const getProgram = (env) => env?.languageService.getProgram() ??
98
99
  TsServer.instance.virtualEnv.languageService.getProgram();
99
100
  export const getInternalTypeChecker = (env) => getProgram(env).getTypeChecker();
100
- const declarationPrefix = "type T = ";
101
- const typeFormatOptions = {
102
- parser: "typescript",
103
- semi: false,
104
- useTabs: true,
105
- printWidth: 60,
106
- trailingComma: "none"
107
- };
108
- const formatTypeString = (typeString) => prettier
109
- .format(`${declarationPrefix}${typeString}`, typeFormatOptions)
110
- .slice(declarationPrefix.length)
111
- .trimEnd();
112
- const replaceKnownInvalidSyntax = (typeString) => {
113
- // Match '...' and '... x more ...' (known truncated type syntax)
114
- const regex = /\.\.\.\s*(\d+\s*more\s*\.\.\.)?/g;
115
- // replace these with a string literal "..." so that they can still
116
- // form valid expressions, e.g. "..."[]
117
- return typeString.replaceAll(regex, '"..."');
118
- };
119
101
  export const getStringifiableType = (node) => {
120
102
  const typeChecker = getInternalTypeChecker();
121
103
  const nodeType = typeChecker.getTypeAtLocation(node);
122
104
  let stringified = typeChecker.typeToString(nodeType);
123
- try {
124
- stringified = formatTypeString(stringified);
125
- }
126
- catch {
127
- // if formatting fails (e.g. due to custom typeToString syntax like ... X more),
128
- // try to comment out problematic sections
129
- try {
130
- stringified = formatTypeString(replaceKnownInvalidSyntax(stringified));
131
- }
132
- catch {
133
- // if still fails somehow, just swallow the error and use the unformatted type
134
- }
105
+ if (stringified.includes("...")) {
106
+ const nonTruncated = typeChecker.typeToString(nodeType, undefined, ts.TypeFormatFlags.NoTruncation);
107
+ if (nonTruncated.includes(" any") && !stringified.includes(" any"))
108
+ stringified = nonTruncated.replaceAll(" any", " cyclic");
109
+ else
110
+ stringified = nonTruncated;
135
111
  }
136
112
  return Object.assign(nodeType, {
137
113
  toString: () => stringified,
package/out/cli/trace.js CHANGED
@@ -1,20 +1,21 @@
1
+ import { ensureDir } from "@ark/fs";
1
2
  import { execSync } from "child_process";
2
- import { existsSync } from "fs";
3
- import { join } from "path";
3
+ import { resolve } from "path";
4
+ import { getConfig } from "../config.js";
4
5
  import { baseDiagnosticTscCmd } from "./shared.js";
5
6
  export const trace = async (args) => {
6
7
  const packageDir = args[0] ?? process.cwd();
7
- if (!existsSync(packageDir)) {
8
- throw new Error(`trace requires an argument for an existing directory to trace, e.g. 'pnpm attest trace packages/api'`);
9
- }
8
+ const config = getConfig();
9
+ const traceDir = resolve(config.cacheDir, "trace");
10
+ ensureDir(traceDir);
10
11
  try {
11
12
  console.log(`⏳ Gathering type trace data for ${packageDir}...`);
12
13
  // These cache files have to be removed before any analysis is done otherwise
13
14
  // the results will be meaningless.
14
- // the .tstrace directory will contain a trace.json file and a types.json file.
15
+ // the .attest/trace directory will contain a trace.json file and a types.json file.
15
16
  // the trace.json file can be viewed via a tool like https://ui.perfetto.dev/
16
17
  // the types.json file can be used to associate IDs from the trace file with type aliases
17
- execSync(`${baseDiagnosticTscCmd} --generateTrace .tstrace`, {
18
+ execSync(`${baseDiagnosticTscCmd} --generateTrace ${traceDir}`, {
18
19
  cwd: packageDir,
19
20
  stdio: "inherit"
20
21
  });
@@ -28,7 +29,7 @@ export const trace = async (args) => {
28
29
  process.argv = [
29
30
  "node",
30
31
  "node_modules/@typescript/analyze-trace/dist/analyze-trace-dir.js",
31
- join(packageDir, ".tstrace")
32
+ traceDir
32
33
  ];
33
34
  // TypeScript's analyze-trace tool can be used to automatically detect hot-spots in your code.
34
35
  // It's not a perfect match for what can be optimized, but it can be a helpful place to start
package/out/config.d.ts CHANGED
@@ -1,8 +1,11 @@
1
1
  import { type autocomplete } from "@ark/util";
2
+ import type * as prettier from "prettier";
3
+ import type ts from "typescript";
2
4
  import { type TsVersionData } from "./tsVersioning.js";
3
5
  export type TsVersionAliases = autocomplete<"*"> | string[];
4
6
  type BaseAttestConfig = {
5
7
  tsconfig: string | undefined;
8
+ compilerOptions: ts.CompilerOptions;
6
9
  updateSnapshots: boolean;
7
10
  /** A string or list of strings representing the TypeScript version aliases to run.
8
11
  *
@@ -25,8 +28,19 @@ type BaseAttestConfig = {
25
28
  benchErrorOnThresholdExceeded: boolean;
26
29
  filter: string | undefined;
27
30
  testDeclarationAliases: string[];
28
- formatter: string;
31
+ formatCmd: string;
29
32
  shouldFormat: boolean;
33
+ /**
34
+ * Provided options will override the following defaults.
35
+ * Any options not listed will fallback to Prettier's default value.
36
+ *
37
+ * {
38
+ * semi: false,
39
+ * printWidth: 60,
40
+ * trailingComma: "none",
41
+ * }
42
+ */
43
+ typeToStringFormat: prettier.Options;
30
44
  };
31
45
  export type AttestConfig = Partial<BaseAttestConfig>;
32
46
  export declare const getDefaultAttestConfig: () => BaseAttestConfig;
package/out/config.js CHANGED
@@ -5,6 +5,7 @@ import { join, resolve } from "node:path";
5
5
  import { findAttestTypeScriptVersions } from "./tsVersioning.js";
6
6
  export const getDefaultAttestConfig = () => ({
7
7
  tsconfig: existsSync(fromCwd("tsconfig.json")) ? fromCwd("tsconfig.json") : undefined,
8
+ compilerOptions: {},
8
9
  attestAliases: ["attest", "attestInternal"],
9
10
  updateSnapshots: false,
10
11
  skipTypes: false,
@@ -14,14 +15,26 @@ export const getDefaultAttestConfig = () => ({
14
15
  benchErrorOnThresholdExceeded: true,
15
16
  filter: undefined,
16
17
  testDeclarationAliases: ["bench", "it", "test"],
17
- formatter: `npm exec --no -- prettier --write`,
18
- shouldFormat: true
18
+ formatCmd: `npm exec --no -- prettier --write`,
19
+ shouldFormat: true,
20
+ typeToStringFormat: {}
19
21
  });
20
- const hasFlag = (flag) => process.argv.some(arg => arg.includes(flag));
22
+ const flagAliases = {
23
+ updateSnapshots: ["u", "update"]
24
+ };
25
+ const findParamIndex = (flagOrAlias) => process.argv.findIndex(arg => arg === `-${flagOrAlias}` || arg === `--${flagOrAlias}`);
26
+ const hasFlag = (flag) => findParamIndex(flag) !== -1 ||
27
+ flagAliases[flag]?.some(alias => findParamIndex(alias) !== -1);
21
28
  const getParamValue = (param) => {
22
- const paramIndex = process.argv.findIndex(arg => arg.includes(param));
23
- if (paramIndex === -1)
24
- return undefined;
29
+ let paramIndex = findParamIndex(param);
30
+ if (paramIndex === -1) {
31
+ if (!flagAliases[param])
32
+ return;
33
+ for (let i = 0; i < flagAliases[param].length && paramIndex === -1; i++)
34
+ paramIndex = findParamIndex(flagAliases[param][i]);
35
+ if (paramIndex === -1)
36
+ return;
37
+ }
25
38
  const raw = process.argv[paramIndex + 1];
26
39
  if (raw === "true")
27
40
  return true;
@@ -31,6 +44,8 @@ const getParamValue = (param) => {
31
44
  return tryParseNumber(raw, { errorOnFail: true });
32
45
  if (param === "tsVersions" || param === "attestAliases")
33
46
  return raw.split(",");
47
+ if (param === "typeToStringFormat" || param === "compilerOptions")
48
+ return JSON.parse(raw);
34
49
  return raw;
35
50
  };
36
51
  export const attestEnvPrefix = "ATTEST_";
@@ -74,7 +89,7 @@ const parseConfig = () => {
74
89
  const isTsVersionAliases = (v) => typeof v === "string" || (isArray(v) && typeof v[0] === "string");
75
90
  const parseTsVersions = (aliases) => {
76
91
  const versions = findAttestTypeScriptVersions();
77
- if (aliases === "*")
92
+ if (aliases === "*" || (isArray(aliases) && aliases[0] === "*"))
78
93
  return versions;
79
94
  return liftArray(aliases).map(alias => {
80
95
  const matching = versions.find(v => v.alias === alias);
@@ -86,9 +101,10 @@ const parseTsVersions = (aliases) => {
86
101
  return matching;
87
102
  });
88
103
  };
89
- const cachedConfig = parseConfig();
90
- export const getConfig = () => cachedConfig;
104
+ let cachedConfig;
105
+ export const getConfig = () => parseConfig();
91
106
  export const ensureCacheDirs = () => {
107
+ cachedConfig ??= getConfig();
92
108
  ensureDir(cachedConfig.cacheDir);
93
109
  ensureDir(cachedConfig.assertionCacheDir);
94
110
  };
package/out/fixtures.js CHANGED
@@ -5,9 +5,12 @@ import { writeSnapshotUpdatesOnExit } from "./cache/snapshots.js";
5
5
  import { analyzeProjectAssertions } from "./cache/writeAssertionCache.js";
6
6
  import { ensureCacheDirs, getConfig } from "./config.js";
7
7
  import { forTypeScriptVersions } from "./tsVersioning.js";
8
- export const setup = (options = {}) => {
8
+ export const setup = (options) => {
9
+ if (options) {
10
+ const existing = process.env.ATTEST_CONFIG ? JSON.parse(process.env.ATTEST_CONFIG) : {};
11
+ process.env.ATTEST_CONFIG = JSON.stringify(Object.assign(existing, options));
12
+ }
9
13
  const config = getConfig();
10
- Object.assign(config, options);
11
14
  rmSync(config.cacheDir, { recursive: true, force: true });
12
15
  ensureCacheDirs();
13
16
  if (config.skipTypes)
package/out/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
+ export { cleanup, setup, teardown, writeAssertionData } from "./fixtures.js";
1
2
  export { caller, type CallerOfOptions } from "@ark/fs";
2
3
  export { attest } from "./assert/attest.js";
3
4
  export { bench } from "./bench/bench.js";
4
5
  export { getBenchAssertionsAtPosition, getTypeAssertionsAtPosition } from "./cache/getCachedAssertions.js";
5
6
  export type { ArgAssertionData, LinePositionRange, TypeAssertionData, TypeRelationship } from "./cache/writeAssertionCache.js";
6
7
  export { getDefaultAttestConfig, type AttestConfig } from "./config.js";
7
- export { cleanup, setup, teardown, writeAssertionData } from "./fixtures.js";
8
8
  export { findAttestTypeScriptVersions, getPrimaryTsVersionUnderTest } from "./tsVersioning.js";
9
9
  export { contextualize } from "./utils.js";
package/out/index.js CHANGED
@@ -1,8 +1,9 @@
1
+ export { cleanup, setup, teardown, writeAssertionData } from "./fixtures.js";
2
+ // ensure fixtures are exported before config so additional settings can load
1
3
  export { caller } from "@ark/fs";
2
4
  export { attest } from "./assert/attest.js";
3
5
  export { bench } from "./bench/bench.js";
4
6
  export { getBenchAssertionsAtPosition, getTypeAssertionsAtPosition } from "./cache/getCachedAssertions.js";
5
7
  export { getDefaultAttestConfig } from "./config.js";
6
- export { cleanup, setup, teardown, writeAssertionData } from "./fixtures.js";
7
8
  export { findAttestTypeScriptVersions, getPrimaryTsVersionUnderTest } from "./tsVersioning.js";
8
9
  export { contextualize } from "./utils.js";
@@ -1,4 +1,4 @@
1
- import { findPackageRoot, fsRoot, readJson } from "@ark/fs";
1
+ import { assertPackageRoot, fsRoot, readJson } from "@ark/fs";
2
2
  import { existsSync, renameSync, symlinkSync, unlinkSync } from "fs";
3
3
  import { dirname } from "path";
4
4
  import { join } from "path/posix";
@@ -20,7 +20,7 @@ import ts from "typescript";
20
20
  export const forTypeScriptVersions = (versions, fn) => {
21
21
  const passedVersions = [];
22
22
  const failedVersions = [];
23
- const nodeModules = join(findPackageRoot(process.cwd()), "node_modules");
23
+ const nodeModules = join(assertPackageRoot(process.cwd()), "node_modules");
24
24
  const tsPrimaryPath = join(nodeModules, "typescript");
25
25
  const tsTemporaryPath = join(nodeModules, "typescript-temp");
26
26
  if (existsSync(tsPrimaryPath))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ark/attest",
3
- "version": "0.10.2",
3
+ "version": "0.12.0",
4
4
  "author": {
5
5
  "name": "David Blass",
6
6
  "email": "david@arktype.io",
@@ -29,9 +29,9 @@
29
29
  "@typescript/analyze-trace": "0.10.1",
30
30
  "prettier": "3.3.3",
31
31
  "@prettier/sync": "0.5.2",
32
- "arktype": "2.0.0-beta.2",
33
- "@ark/fs": "0.1.2",
34
- "@ark/util": "0.1.2"
32
+ "arktype": "2.0.0-beta.4",
33
+ "@ark/fs": "0.2.1",
34
+ "@ark/util": "0.2.1"
35
35
  },
36
36
  "devDependencies": {
37
37
  "typescript": "5.5.4"