test(tui): drive the ink-form patch through the plugin, and drop the esbuild type import
Review follow-ups on #1983. The patch's tests called the string helper directly, so nothing exercised the esbuild `onLoad` filter that decides whether the helper runs at all. A filter that stopped matching would leave the build green, the tests green, and the typo shipped — the silent no-op the throwing helper exists to prevent, reintroduced one level up. The plugin is now driven the way esbuild drives it (register, then invoke) against the real `ink-form` module path, and a second test pins the filter's scope: it matches that path and a Windows-separator one, and rejects `Form.js`, `ink-select-input`'s own `SubmitButton.js`, and a first-party `src/SubmitButton.jsx`. The plugin type came from `import type { Plugin } from "esbuild"`, but `esbuild` is tsup's transitive dependency, not one this client declares — it typechecked only while npm happened to hoist it, and would break on a lock change that nested it. Derive it from tsup's own `Options["esbuildPlugins"]` instead of adding a dependency for a type. Closes #1952 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WLYmVPVLdeYpE6aMTUsCks
This commit is contained in:
parent
3c1bbbcb5f
commit
39575ff060
1 changed files with 81 additions and 15 deletions
|
|
@ -1,5 +1,4 @@
|
|||
import { defineConfig } from "tsup";
|
||||
import type { Plugin } from "esbuild";
|
||||
import { defineConfig, type Options } from "tsup";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
|
@ -45,11 +44,25 @@ export function fixInkFormIncompleteHint(source: string, file: string): string {
|
|||
);
|
||||
}
|
||||
|
||||
const inkFormLabelPatch: Plugin = {
|
||||
/**
|
||||
* Which module the patch above is applied to.
|
||||
*
|
||||
* Exported so the tests can check it against the *resolved* path of the real
|
||||
* `ink-form` module — a filter that stops matching is the one way this patch
|
||||
* can silently no-op, since `fixInkFormIncompleteHint` would then never run.
|
||||
*/
|
||||
export const INK_FORM_SUBMIT_BUTTON = /ink-form[\\/]lib[\\/]SubmitButton\.js$/;
|
||||
|
||||
// The plugin type is derived from tsup rather than imported from `esbuild`:
|
||||
// `esbuild` is tsup's transitive dependency, not a declared one of this client,
|
||||
// so a direct import typechecks only while npm happens to hoist it.
|
||||
type EsbuildPlugin = NonNullable<Options["esbuildPlugins"]>[number];
|
||||
|
||||
export const inkFormLabelPatch: EsbuildPlugin = {
|
||||
name: "ink-form-label-patch",
|
||||
setup(build) {
|
||||
build.onLoad(
|
||||
{ filter: /ink-form[\\/]lib[\\/]SubmitButton\.js$/ },
|
||||
{ filter: INK_FORM_SUBMIT_BUTTON },
|
||||
async ({ path: file }) => ({
|
||||
contents: fixInkFormIncompleteHint(await readFile(file, "utf8"), file),
|
||||
loader: "js",
|
||||
|
|
|
|||
Loading…
Reference in a new issue