Files
vue-tui/vite.config.ts
Yunfei He e5015b0a80 fix(vite): resolve @vue-tui/vite from CommonJS Vite configs (#243)
* fix(vite): resolve @vue-tui/vite from CommonJS Vite configs

When a consumer project is CommonJS — package.json "type": "commonjs", or
no "type" field at all (Node defaults to CommonJS) — Vite loads vite.config.ts
as CommonJS and resolves its imports under the `require` condition.
@vue-tui/vite's exports used an `import`-only conditions object with no
fallback, so nothing matched under `require` and Vite threw:

    [plugin externalize-deps] Failed to resolve "@vue-tui/vite".
    This package is ESM only but it was tried to load by `require`.

Switch the export to a bare string (plus "./package.json"), matching the
other @vue-tui/* packages and @vitejs/plugin-vue. A string export is
condition-agnostic, so it resolves under both `import` and `require`; Node
then loads the ESM file via require(ESM), which every supported Node
(>=22.18) provides. No CommonJS build is added — this mirrors how the Vite
plugin ecosystem ships today (all ESM-only).

Add a regression test (test/cjs-config.test.ts): a `type: commonjs` fixture
whose vite.config.ts imports @vue-tui/vite by name, loaded through the real
config loader via resolveConfig(). It fails with the exact #238 error on the
old exports and passes with this change.

* chore(lint): exclude test fixtures from linting

Test fixtures are test INPUTS, not shipped source, and some are deliberately
broken: the overlay / full-reload dev-server tests transiently overwrite a
fixture's app.vue with a syntax error (to exercise the error overlay / failed
HMR), then restore it. Because `vp run ci` runs lint concurrently with those
tests, a linter that read a fixture inside that broken window failed with a
spurious "Unexpected token" — a flaky race whose surfacing depended on test
timing. Add lint.ignorePatterns ["**/test/fixtures/**"] to remove the race
(and the wasted lint work on test data).
2026-07-05 18:30:31 +08:00

110 lines
5.0 KiB
TypeScript

import { defineConfig } from "vite-plus";
export default defineConfig({
staged: {
"*": "vp check --fix",
},
fmt: {},
lint: {
// Don't lint test fixtures. They are test INPUTS, not shipped source, and some are
// deliberately broken: the overlay / full-reload dev-server tests transiently overwrite a
// fixture's app.vue with a syntax error (to exercise the error overlay / failed HMR), then
// restore it. Because `vp run ci` runs lint CONCURRENTLY with those tests, a linter that read
// a fixture inside that broken window failed with a spurious "Unexpected token" (a flaky race,
// surfaced by test timing). Excluding fixtures removes the race and the wasted lint work.
ignorePatterns: ["**/test/fixtures/**"],
options: { typeAware: true, typeCheck: false },
rules: {
// This is a terminal UI library: parsing keyboard escape sequences and
// stripping ANSI requires regexes that match control characters (ESC,
// BEL, etc.) by design. no-control-regex flags every such pattern as a
// false positive across the codebase, so disable it library-wide. We
// already write them as \x1b /  unicode escapes (the rule's own
// suggested form), not raw bytes.
"no-control-regex": "off",
},
},
run: {
cache: false,
// `ci` is the parallel verification graph used by .github/workflows/ci.yml.
// The task runner fans out independent branches concurrently. Only fmt has
// no build dependency, so it starts immediately; lint, check:type, and the
// test suites all depend on build because they need the built dist
// (@vue-tui/runtime exposes no "types" export — consumers, and the
// type-aware lint rules, resolve its types and runtime from dist/*.d.mts).
// So the wall-clock critical path is build -> test:pty. The serial `ready`
// script in package.json mirrors this order (build before lint) for local use.
tasks: {
"ci:build": { command: "vp run build" },
"ci:fmt": { command: "vp run check:fmt" },
// lint depends on build: type-aware rules (e.g. no-implied-eval) on the
// PTY fixtures need @vue-tui/runtime's built types resolved, or they
// misfire on a fresh checkout. build is already on the critical path, so
// this doesn't change overall wall-clock.
"ci:lint": { command: "vp run check:lint", dependsOn: ["ci:build"] },
"ci:type": { command: "vp run check:type", dependsOn: ["ci:build"] },
// Test branches, one per suite via package#script. Normal packages keep a
// plain `test`; only runtime-tests splits into test:integration +
// test:pty. Targeting each suite directly keeps runtime-tests' slow PTY
// suite on its own parallel branch (not serial inside its `test`), and
// covers the runtime/testing unit tests that a runtime-tests-only run
// would miss.
"ci:test:runtime": {
command: "vp run @vue-tui/runtime#test",
dependsOn: ["ci:build"],
},
"ci:test:testing": {
command: "vp run @vue-tui/testing#test",
dependsOn: ["ci:build"],
},
"ci:test:integration": {
command: "vp run @vue-tui/runtime-tests#test:integration",
dependsOn: ["ci:build"],
},
"ci:test:pty": {
command: "vp run @vue-tui/runtime-tests#test:pty",
dependsOn: ["ci:build"],
},
// @vue-tui/vite (the Vite plugin: in-process dev server + production
// build) carries its own unit suite; run it on its own parallel branch
// like the other packages.
"ci:test:vite-plugin": {
command: "vp run @vue-tui/vite#test",
dependsOn: ["ci:build"],
},
// Examples smoke suite (#212): launch examples/basic-template and basic-jsx through a real
// PTY — both the dev server and the `node dist/main.js` build — and assert each paints a
// frame with no module-system crash. This is the regression guard for "the shipped examples
// actually run". Depends on ci:build for the built @vue-tui/runtime + @vue-tui/vite dist the
// examples consume; its own PTY pool keeps it on a separate parallel branch.
"ci:test:examples": {
command: "vp run @vue-tui/runtime-tests#test:examples",
dependsOn: ["ci:build"],
},
// @vue-tui/components (high-level components composed from runtime
// primitives) carries its own unit suite; run it on its own parallel
// branch like the other packages. Depends on ci:build because its tests
// resolve @vue-tui/runtime + @vue-tui/testing from their built dist.
"ci:test:components": {
command: "vp run @vue-tui/components#test",
dependsOn: ["ci:build"],
},
ci: {
command: "echo ci ok",
dependsOn: [
"ci:fmt",
"ci:lint",
"ci:type",
"ci:test:runtime",
"ci:test:testing",
"ci:test:integration",
"ci:test:pty",
"ci:test:vite-plugin",
"ci:test:examples",
"ci:test:components",
],
},
},
},
});