@cosyte/vitest-config 0.1.1 → 0.1.3

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/CHANGELOG.md CHANGED
@@ -1,26 +1,38 @@
1
1
  # Changelog
2
2
 
3
- All notable changes to `@cosyte/vitest-config` are documented here, following
4
- [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). Versions are managed with Changesets;
5
- this file is hand-maintained (Changesets' own changelog generation is disabled). The package is on the
6
- **`0.1.x`** line: its surface is settled, and bump types follow ordinary semver rather than a
7
- pre-alpha rule. See
8
- [ADR 0002](../../documentation/decisions/0002-the-0-1-0-version-line.md).
3
+ ## 0.1.3
9
4
 
10
- > Because the generator is disabled, **`[Unreleased]` is promoted to a version heading BY HAND**, in
11
- > the pull request that adds the changeset. Nothing does it automatically. Until 2026-08-04 nothing
12
- > did it at all, so shipped content stayed under `[Unreleased]` and every release republished it.
5
+ ### Patch Changes
13
6
 
14
- ## [Unreleased]
7
+ - 095c103: `@cosyte/vitest-config/snippets` reads a markdown fence opener and a `// =>` doctest line in time linear in the line's length. Two regular expressions there let several quantifiers take the same spaces, so a long line that failed to match took time quadratic in its length: 100,000 spaces took 8 to 32 seconds on Node 26 (CodeQL js/polynomial-redos). Every snippet with an expression and a value is read as before. A doctest line with no expression, `; // => 1`, now becomes `expect()`, which fails the snippet, where an unindented one used to pass as a line that asserted nothing.
15
8
 
16
- ## [0.1.1] - Unreleased
9
+ ## 0.1.2
10
+
11
+ ### Patch Changes
12
+
13
+ - bcdb7ea: The README's license line names the legal owner: "MIT, copyright Cosyte LLC." The READMEs of `@cosyte/eslint-config`, `@cosyte/process` and `@cosyte/script-utils` also use US spelling where they did not (license, behavior, generalize, recognized, honored). No code, configuration or type changes.
14
+ - 75c1056: `@cosyte/vitest-config` accepts Vitest 5 as well as Vitest 4: the `vitest` and `@vitest/coverage-v8` peer ranges are now `^4.0.0 || ^5.0.0`, so a package on Vitest 5 installs it without a peer warning. The configuration it returns is unchanged; Vitest 5 reads the same `coverage` options, and its own `vite` range (6.4 or later, 7 or 8) sits inside this package's.
15
+
16
+ ## Released before this file was generated
17
+
18
+ Every release section above this heading is written by
19
+ [Changesets](https://github.com/changesets/changesets) from the changesets in `.changeset/`, newest
20
+ release first. A release writes its own version heading, so nothing above this line is maintained by
21
+ hand: a change is recorded by adding a changeset rather than by editing this file.
22
+
23
+ The sections below were kept by hand, in the
24
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) format, until 2026-11-07. A version heading
25
+ that still read "Unreleased" after its version reached npm now carries that date; no entry was
26
+ reworded.
27
+
28
+ ## [0.1.1] - 2026-11-07
17
29
 
18
30
  ### Changed
19
31
 
20
32
  - **Published through npm trusted publishing, with provenance.** The code and configuration are
21
33
  unchanged from 0.1.0. Only the README differs: it writes Cosyte with a capital C.
22
34
 
23
- ## [0.1.0] - Unreleased
35
+ ## [0.1.0] - 2026-09-21
24
36
 
25
37
  ### Changed
26
38
 
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Cosyte
3
+ Copyright (c) 2026 Cosyte LLC
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -42,9 +42,9 @@ the bump type it deserves rather than absorbed into a patch.
42
42
  pnpm add -D @cosyte/vitest-config vitest @vitest/coverage-v8 vite
43
43
  ```
44
44
 
45
- `vitest`, `@vitest/coverage-v8`, and `vite` are peer dependencies. Install `vite` explicitly:
46
- Vitest 4 requires major version 6 or later, and without a direct declaration the resolver will
47
- happily keep an incompatible vite 5. Node `>=22.14`. ESM only.
45
+ `vitest` (4 or 5), `@vitest/coverage-v8` (the same major) and `vite` are peer dependencies.
46
+ Install `vite` explicitly: Vitest 4 and 5 require major version 6 or later, and without a direct
47
+ declaration the resolver will happily keep an incompatible vite 5. Node `>=22.14`. ESM only.
48
48
 
49
49
  ## Usage
50
50
 
@@ -174,4 +174,4 @@ a changeset saying what moved: it can red a consumer that was passing.
174
174
 
175
175
  ## License
176
176
 
177
- MIT, copyright Cosyte. See [LICENSE](https://github.com/cosyte/config/blob/main/LICENSE).
177
+ MIT, copyright Cosyte LLC. See [LICENSE](https://github.com/cosyte/config/blob/main/LICENSE).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosyte/vitest-config",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Shared Vitest config (v8 coverage, per-directory >=90 gates) for @cosyte/* packages.",
5
5
  "keywords": [
6
6
  "vitest",
@@ -43,8 +43,8 @@
43
43
  "access": "public"
44
44
  },
45
45
  "peerDependencies": {
46
- "@vitest/coverage-v8": "^4.0.0",
46
+ "@vitest/coverage-v8": "^4.0.0 || ^5.0.0",
47
47
  "vite": "^6.0.0 || ^7.0.0 || ^8.0.0",
48
- "vitest": "^4.0.0"
48
+ "vitest": "^4.0.0 || ^5.0.0"
49
49
  }
50
50
  }
package/snippets.js CHANGED
@@ -30,6 +30,30 @@ const RUNNABLE_LANGS = new Set(["ts", "typescript", "tsx"]);
30
30
  /** Monotonic counter so every emitted temp module gets a unique, cache-busting filename. */
31
31
  let moduleCounter = 0;
32
32
 
33
+ /**
34
+ * A fence opener's indentation and its run of three or more backticks or tildes.
35
+ *
36
+ * Nothing follows the run in the pattern: the info string is the rest of the line, cut off by hand.
37
+ * The earlier form, `\s*(.*)$` after the run, had two quantifiers that could both take the same
38
+ * spaces, so a long line that failed to match cost time quadratic in its length (CodeQL
39
+ * js/polynomial-redos). These docs come from the package being tested, and a markdown file is
40
+ * still input this harness should read in linear time.
41
+ */
42
+ const FENCE_OPEN = /^(\s*)(`{3,}|~{3,})/;
43
+
44
+ /**
45
+ * The characters `.` does not match in a JavaScript regular expression. A fence's info string, a
46
+ * doctest expression and its expected value were each `.+` or `.*` in the earlier patterns, so none
47
+ * of them may hold one; the hand-written parsing below keeps that rule.
48
+ */
49
+ const LINE_TERMINATOR = /[\n\r\u2028\u2029]/;
50
+
51
+ /**
52
+ * The `; // =>` marker of a doctest assertion. Each quantifier is followed by a character it cannot
53
+ * match, so a scan of a line is linear in its length.
54
+ */
55
+ const ASSERTION_MARKER = /;\s*\/\/\s*=>/g;
56
+
33
57
  /**
34
58
  * Extract the opt-in runnable snippets from a markdown string.
35
59
  *
@@ -50,12 +74,13 @@ export function extractRunnableSnippets(markdown, opts = {}) {
50
74
  const out = [];
51
75
  let i = 0;
52
76
  while (i < lines.length) {
53
- const open = lines[i].match(/^(\s*)(`{3,}|~{3,})\s*(.*)$/);
54
- if (!open) {
77
+ const open = FENCE_OPEN.exec(lines[i]);
78
+ const info = open ? lines[i].slice(open[0].length).trimStart() : "";
79
+ if (!open || LINE_TERMINATOR.test(info)) {
55
80
  i++;
56
81
  continue;
57
82
  }
58
- const [, indent, fence, info] = open;
83
+ const [, indent, fence] = open;
59
84
  const firstCodeLine = i + 2; // 1-based line of the first body line
60
85
  const body = [];
61
86
  let j = i + 1;
@@ -107,16 +132,46 @@ export function rewriteAssertions(code) {
107
132
  const rewritten = code
108
133
  .split(/\r?\n/)
109
134
  .map((line) => {
110
- const m = line.match(/^(\s*)(.+?);\s*\/\/\s*=>\s*(.+?)\s*$/);
135
+ const m = splitAssertion(line);
111
136
  if (!m) return line;
112
137
  assertions++;
113
- const [, ws, expr, expected] = m;
114
- return `${ws}expect(${expr}).toStrictEqual(${expected});`;
138
+ return `${m.ws}expect(${m.expr}).toStrictEqual(${m.expected});`;
115
139
  })
116
140
  .join("\n");
117
141
  return { code: rewritten, assertions };
118
142
  }
119
143
 
144
+ /**
145
+ * Split a doctest line into its indentation, its expression and its expected value.
146
+ *
147
+ * The first `; // =>` with anything after it splits the line: the expression is what lies between
148
+ * the indentation and that marker, the expected value is the rest, trimmed. A line with no such
149
+ * marker, or whose expression or value holds a line terminator, is not an assertion.
150
+ *
151
+ * Parsed by hand rather than by one pattern: `^(\s*)(.+?);\s*\/\/\s*=>\s*(.+?)\s*$` let several
152
+ * quantifiers take the same spaces, so a long line that failed to match cost time quadratic in its
153
+ * length (CodeQL js/polynomial-redos). This is linear. It agrees with that pattern on every line
154
+ * with an expression and a value. Where the expression is empty (`; // => 1`), it emits `expect()`,
155
+ * which fails the snippet; the pattern emitted `expect( )` for an indented line and left an
156
+ * unindented one as it was, a line that asserts nothing.
157
+ *
158
+ * @param {string} line - One source line.
159
+ * @returns {{ ws: string, expr: string, expected: string } | null} The parts, or `null`.
160
+ */
161
+ function splitAssertion(line) {
162
+ for (const marker of line.matchAll(ASSERTION_MARKER)) {
163
+ const end = marker.index + marker[0].length;
164
+ // Only the last marker can end the line, so this skips at most once.
165
+ if (end === line.length) continue;
166
+ const ws = line.slice(0, line.length - line.trimStart().length);
167
+ const expr = line.slice(ws.length, marker.index);
168
+ const expected = line.slice(end).trim();
169
+ if (LINE_TERMINATOR.test(expr) || LINE_TERMINATOR.test(expected)) return null;
170
+ return { ws, expr, expected };
171
+ }
172
+ return null;
173
+ }
174
+
120
175
  /**
121
176
  * Rewrite the module specifiers in a snippet's `import ... from "<spec>"` clauses.
122
177
  *