vite-plus 0.3.3 → 1.0.0-rc.1

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.
Files changed (147) hide show
  1. package/LICENSE +35 -146
  2. package/README.md +6 -4
  3. package/binding/index.cjs +58 -54
  4. package/binding/index.d.cts +36 -4
  5. package/dist/{agent-Cu6-tXIP.js → agent-DIwEez_1.js} +6 -5
  6. package/dist/bin.js +75 -35
  7. package/dist/config/bin.js +3 -3
  8. package/dist/constants-BAsBfS1J.js +356 -0
  9. package/dist/create/bin.js +19 -13
  10. package/dist/{define-config-IgzmnvvV.js → define-config-Bz6dc3fm.js} +165 -43
  11. package/dist/{define-config-D0mevyb3.cjs → define-config-CAeeMTvb.cjs} +179 -44
  12. package/dist/{define-config-DPNEJxPz.d.ts → define-config-Cf_5GHmY.d.ts} +71 -25
  13. package/dist/define-config.cjs +1 -1
  14. package/dist/define-config.d.ts +1 -1
  15. package/dist/define-config.js +1 -1
  16. package/dist/dist-BWiANxFS.js +8052 -0
  17. package/dist/{dist-BDYZP12R.js → dist-BsAzy8OW.js} +109 -105
  18. package/dist/documentation-DqcZSthV.js +11 -0
  19. package/dist/{editor-4sjlHmUh.js → editor-DWgrWTbN.js} +246 -159
  20. package/dist/index.cjs +1 -1
  21. package/dist/index.d.ts +1 -1
  22. package/dist/index.js +1 -1
  23. package/dist/{json-cULBl7Pi.js → json-JP24qHUF.js} +14 -6
  24. package/dist/lint-plugins.cjs +1 -1
  25. package/dist/migration/bin.js +3127 -18
  26. package/dist/migration/compat/worker.js +1 -1
  27. package/dist/{oxlint-plugin-config-BVqEe9KY.js → oxlint-plugin-config-B-P1a_0g.js} +1 -1
  28. package/dist/oxlint-plugin.js +9 -7
  29. package/dist/pack-bin.js +1 -1
  30. package/dist/{package-CHH8jWan.js → package-BrupPpWA.js} +6 -2
  31. package/dist/{vitest-ecosystem-BiRqcaRI.js → package-overrides-Dpn4scvN.js} +1 -7
  32. package/dist/{prompts-k14KgthC.js → prompts-BW7_fDGJ.js} +3 -4
  33. package/dist/{report-CK5TnTsr.js → report-NhQk8VHb.js} +1 -0
  34. package/dist/{resolve-vite-config-CTOTuqTi.js → resolve-vite-config-D3XIVT6s.js} +1 -1
  35. package/dist/{resolve-vite-config-BqvS2P98.js → resolve-vite-config-DcsMQaYy.js} +2 -2
  36. package/dist/staged/bin.js +1206 -3318
  37. package/dist/sync-versions/bin.js +4 -4
  38. package/dist/sync-versions/bin.mjs +17 -2
  39. package/dist/test/browser/context.js +1 -1
  40. package/dist/test/browser/providers/playwright/context.js +1 -1
  41. package/dist/test/browser/providers/preview/context.js +1 -1
  42. package/dist/test/browser-playwright/context.js +1 -1
  43. package/dist/test/browser-preview/context.js +1 -1
  44. package/dist/test/context.d.ts +2 -942
  45. package/dist/test/context.js +1 -1
  46. package/dist/test/internal/traces.js +1 -0
  47. package/dist/test/locators.d.ts +2 -294
  48. package/dist/test/matchers.d.ts +2 -29
  49. package/dist/test/mocker.d.ts +2 -0
  50. package/dist/test/mocker.js +1 -0
  51. package/dist/test/{browser-webdriverio/context.js → plugins/browser-context.d.ts} +1 -0
  52. package/dist/test/plugins/browser-context.js +1 -1
  53. package/dist/test/plugins/browser-locators.d.ts +2 -0
  54. package/dist/test/plugins/browser-playwright.d.ts +2 -0
  55. package/dist/test/plugins/browser-preview.d.ts +2 -0
  56. package/dist/test/plugins/browser.d.ts +2 -0
  57. package/dist/test/plugins/mocker-automock.d.ts +2 -0
  58. package/dist/test/plugins/mocker-browser.d.ts +2 -0
  59. package/dist/test/plugins/mocker-node.d.ts +2 -0
  60. package/dist/test/plugins/mocker-redirect.d.ts +2 -0
  61. package/dist/test/plugins/mocker-register.d.ts +2 -0
  62. package/dist/test/plugins/mocker-transforms.d.ts +2 -0
  63. package/dist/test/plugins/mocker.d.ts +2 -0
  64. package/dist/test/plugins/pretty-format.d.ts +2 -0
  65. package/dist/test/plugins/snapshot-environment.d.ts +2 -0
  66. package/dist/test/plugins/snapshot-manager.d.ts +2 -0
  67. package/dist/test/plugins/snapshot.d.ts +2 -0
  68. package/dist/test/plugins/spy.d.ts +2 -0
  69. package/dist/test/plugins/utils-constants.d.ts +2 -0
  70. package/dist/test/plugins/utils-diff.d.ts +2 -0
  71. package/dist/test/plugins/utils-display.d.ts +2 -0
  72. package/dist/test/plugins/utils-error.d.ts +2 -0
  73. package/dist/test/plugins/utils-helpers.d.ts +2 -0
  74. package/dist/test/plugins/utils-offset.d.ts +2 -0
  75. package/dist/test/plugins/utils-resolver.d.ts +2 -0
  76. package/dist/test/plugins/utils-serialize.d.ts +2 -0
  77. package/dist/test/plugins/utils-source-map-node.d.ts +2 -0
  78. package/dist/test/plugins/utils-source-map.d.ts +2 -0
  79. package/dist/test/plugins/utils-timers.d.ts +2 -0
  80. package/dist/test/plugins/utils.d.ts +2 -0
  81. package/dist/toolchain.js +11 -11
  82. package/dist/toolchain.json +11 -11
  83. package/dist/{tsconfig-euB-GmIE.js → tsconfig-DESFDzWP.js} +1 -1
  84. package/dist/{tsconfig-C3h9CVTA.js → tsconfig-piorpNV7.js} +8 -4
  85. package/dist/version.js +5 -3
  86. package/dist/versions.js +6 -6
  87. package/dist/vitest-ecosystem-BU0AqZq-.js +23 -0
  88. package/dist/vitest-v5-entry-points-DthU1e_O.js +25 -0
  89. package/docs/config/fmt.md +4 -2
  90. package/docs/config/lint.md +4 -2
  91. package/docs/config/run.md +62 -26
  92. package/docs/guide/automatic-data-tracking.md +20 -15
  93. package/docs/guide/cache.md +12 -8
  94. package/docs/guide/check.md +2 -0
  95. package/docs/guide/commit-hooks.md +8 -1
  96. package/docs/guide/env.md +18 -13
  97. package/docs/guide/fmt.md +6 -2
  98. package/docs/guide/index.md +1 -1
  99. package/docs/guide/install.md +1 -1
  100. package/docs/guide/lint.md +5 -1
  101. package/docs/guide/local-cli.md +3 -3
  102. package/docs/guide/migrate-rules.md +58 -12
  103. package/docs/guide/migrate.md +86 -20
  104. package/docs/guide/monorepo.md +7 -1
  105. package/docs/guide/run.md +3 -1
  106. package/docs/guide/test.md +2 -0
  107. package/docs/guide/troubleshooting.md +3 -3
  108. package/docs/guide/vitest-v5.md +221 -0
  109. package/package.json +64 -87
  110. package/bin/oxfmt +0 -33
  111. package/bin/oxlint +0 -38
  112. package/dist/cli-truncate-Bg3RDXpi.js +0 -865
  113. package/dist/constants-C2dTOTe-.js +0 -80
  114. package/dist/dist-Dqv1-Clg.js +0 -3
  115. package/dist/is-fullwidth-code-point-BUNlIICg.js +0 -8
  116. package/dist/log-update-CoW8Z4Dl.js +0 -491
  117. package/dist/semver-CaDAb8vV.js +0 -1400
  118. package/dist/strip-ansi-C3wrWz9t.js +0 -853
  119. package/dist/test/browser/providers/webdriverio/context.d.ts +0 -1
  120. package/dist/test/browser/providers/webdriverio/context.js +0 -1
  121. package/dist/test/browser/providers/webdriverio.d.ts +0 -77
  122. package/dist/test/browser/providers/webdriverio.js +0 -1
  123. package/dist/test/browser-webdriverio/context.d.ts +0 -1
  124. package/dist/test/browser-webdriverio.d.ts +0 -77
  125. package/dist/test/browser-webdriverio.js +0 -1
  126. package/dist/test/coverage.d.ts +0 -2
  127. package/dist/test/coverage.js +0 -1
  128. package/dist/test/environments.d.ts +0 -2
  129. package/dist/test/environments.js +0 -1
  130. package/dist/test/plugins/browser-webdriverio.js +0 -1
  131. package/dist/test/plugins/expect.js +0 -1
  132. package/dist/test/plugins/runner-types.js +0 -1
  133. package/dist/test/plugins/runner-utils.js +0 -1
  134. package/dist/test/plugins/runner.js +0 -1
  135. package/dist/test/reporters.d.ts +0 -2
  136. package/dist/test/reporters.js +0 -1
  137. package/dist/test/runners.d.ts +0 -2
  138. package/dist/test/runners.js +0 -1
  139. package/dist/test/snapshot.d.ts +0 -2
  140. package/dist/test/snapshot.js +0 -1
  141. package/dist/test/suite.d.ts +0 -2
  142. package/dist/test/suite.js +0 -1
  143. package/dist/tsgolint-path-CbDReEOx.js +0 -34
  144. package/dist/tsgolint-path.d.ts +0 -7
  145. package/dist/tsgolint-path.js +0 -2
  146. package/dist/wrap-ansi-DNjkuBEp.js +0 -157
  147. package/dist/wrap-ansi-DUi52C6W.js +0 -2
@@ -1,14 +1,15 @@
1
1
  import { r as __toESM, t as __commonJSMin } from "../rolldown-runtime-CMFfr-1z.js";
2
+ import { t as documentationUrl$1 } from "../documentation-DqcZSthV.js";
2
3
  import { t as renderCliDoc } from "../help-BmKpeOP9.js";
3
4
  import { a as muted, i as log, o as printHeader, r as formatDuration, s as success, t as accent } from "../terminal-MKGAuy-p.js";
4
- import { u as VITE_PLUS_NAME } from "../constants-C2dTOTe-.js";
5
- import { i as readJsonFile, n as editJsonFile } from "../json-cULBl7Pi.js";
6
- import { o as fetchNpmResource, r as getScopeFromPackageName, s as getNpmRegistry, t as checkNpmPackageExists } from "../package-CHH8jWan.js";
7
- import { i as hasViteConfig, o as resolveViteConfig, r as findWorkspaceRoot, t as findViteConfig } from "../resolve-vite-config-BqvS2P98.js";
8
- import { C as multiselect, D as text, E as spinner, O as require_picocolors, S as log$1, T as select, a as resolveGitInit, c as selectPackageManager, d as readYamlFile, h as resolveApproveBuildTargets, i as promptGitHooks, k as isCancel, m as detectGatedBuilds, n as defaultInteractive, o as runViteFmt, p as approveBuilds, r as downloadPackageManager$1, s as runViteInstall, t as cancelAndExit, u as editYamlFile, v as DependencyType, x as intro, y as PackageManager } from "../prompts-k14KgthC.js";
9
- import { t as require_semver } from "../semver-CaDAb8vV.js";
10
- import { a as selectAgentTargets, c as writeCopilotSetupWorkflow, d as templatesDir, l as displayRelative, r as detectExistingAgentTargetPaths, s as writeAgentInstructions, t as COPILOT_AGENT_ID } from "../agent-Cu6-tXIP.js";
11
- import { F as addFrameworkShim, I as detectFramework, K as promptPrettierMigration, L as hasFrameworkShim, M as isBingoTemplate, N as updatePackageJsonWithDeps, P as updateWorkspaceConfig, Q as promptEslintMigration, S as injectCreateDefaultTemplate, V as promptTsupMigration, W as detectPrettierProject, Y as detectEslintProject, _ as installGitHooks, a as selectEditors, b as findGitRoot, c as rewriteMonorepoProject, h as setPackageManager, j as detectWorkspace$1, l as rewriteStandaloneProject, n as detectExistingEditors, o as writeEditorConfigs, s as rewriteMonorepo, x as initGitRepository, y as shouldSkipStagedMigrationForHooks, z as detectTsupProject } from "../editor-4sjlHmUh.js";
5
+ import { u as VITE_PLUS_NAME } from "../constants-BAsBfS1J.js";
6
+ import { i as readJsonFile, n as editJsonFile } from "../json-JP24qHUF.js";
7
+ import { o as fetchNpmResource, r as getScopeFromPackageName, s as getNpmRegistry, t as checkNpmPackageExists } from "../package-BrupPpWA.js";
8
+ import { i as hasViteConfig, o as resolveViteConfig, r as findWorkspaceRoot, t as findViteConfig } from "../resolve-vite-config-DcsMQaYy.js";
9
+ import { C as multiselect, D as text, E as spinner, O as require_picocolors, S as log$1, T as select, a as resolveGitInit, c as selectPackageManager, d as readYamlFile, h as resolveApproveBuildTargets, i as promptGitHooks, k as isCancel, m as detectGatedBuilds, n as defaultInteractive, o as runViteFmt, p as approveBuilds, r as downloadPackageManager$1, s as runViteInstall, t as cancelAndExit, u as editYamlFile, v as DependencyType, x as intro, y as PackageManager } from "../prompts-BW7_fDGJ.js";
10
+ import { n as require_semver } from "../dist-BWiANxFS.js";
11
+ import { a as selectAgentTargets, c as writeCopilotSetupWorkflow, d as templatesDir, l as displayRelative, r as detectExistingAgentTargetPaths, s as writeAgentInstructions, t as COPILOT_AGENT_ID } from "../agent-DIwEez_1.js";
12
+ import { B as addFrameworkShim, F as updateWorkspaceConfig, H as hasFrameworkShim, K as promptTsupMigration, L as findGitRoot, M as detectWorkspace$1, N as isBingoTemplate, P as updatePackageJsonWithDeps, R as initGitRepository, V as detectFramework, W as detectTsupProject, Y as detectPrettierProject, Z as promptPrettierMigration, _ as installGitHooks, a as selectEditors, b as injectCreateDefaultTemplate, c as rewriteMonorepoProject, et as detectEslintProject, h as setPackageManager, j as supportsCatalog, l as rewriteStandaloneProject, n as detectExistingEditors, o as writeEditorConfigs, rt as promptEslintMigration, s as rewriteMonorepo, y as shouldSkipStagedMigrationForHooks } from "../editor-DWgrWTbN.js";
12
13
  import { n as runCommandSilently, t as runCommand$1 } from "../command-CguLh2KL.js";
13
14
  import { t as unwrapCliParseOutcome } from "../cli-parse-DHE8NrBU.js";
14
15
  import path from "node:path";
@@ -618,6 +619,7 @@ var CreateConfigSchemaError = class extends Error {
618
619
  this.name = "CreateConfigSchemaError";
619
620
  }
620
621
  };
622
+ const makeCreateConfigError = (message) => new CreateConfigSchemaError(message);
621
623
  /**
622
624
  * Validate `create.templates` from `vite.config.ts`. Returns `[]` when the field
623
625
  * is absent or an empty array; throws {@link CreateConfigSchemaError} when present
@@ -626,10 +628,9 @@ var CreateConfigSchemaError = class extends Error {
626
628
  function validateCreateTemplates(templates) {
627
629
  if (templates === void 0) return [];
628
630
  if (!Array.isArray(templates)) throw new CreateConfigSchemaError("create.templates must be an array");
629
- const makeError = (message) => new CreateConfigSchemaError(message);
630
- return validateTemplateEntries(templates, "create.templates", makeError, (entry, index) => {
631
- const validated = validateTemplateEntry(entry, index, "create.templates", makeError);
632
- if (validated.name.startsWith("vite:")) throw makeError(`create.templates[${index}].name uses the reserved \`vite:\` prefix`);
631
+ return validateTemplateEntries(templates, "create.templates", makeCreateConfigError, (entry, index) => {
632
+ const validated = validateTemplateEntry(entry, index, "create.templates", makeCreateConfigError);
633
+ if (validated.name.startsWith("vite:")) throw makeCreateConfigError(`create.templates[${index}].name uses the reserved \`vite:\` prefix`);
633
634
  return validated;
634
635
  });
635
636
  }
@@ -4379,6 +4380,11 @@ async function executeGeneratorScaffold(workspaceInfo, templateInfo, options) {
4379
4380
  fs.chmodSync(path.join(fullPath, "bin/index.ts"), "755");
4380
4381
  editJsonFile(path.join(fullPath, "package.json"), (pkg) => {
4381
4382
  pkg.name = templateInfo.packageName;
4383
+ if (!supportsCatalog(workspaceInfo.packageManager, workspaceInfo.downloadPackageManager.version, workspaceInfo.isMonorepo)) {
4384
+ const { catalog } = readYamlFile(path.join(templatesDir, "monorepo/pnpm-workspace.yaml"));
4385
+ const devDependencies = pkg.devDependencies;
4386
+ for (const [name, spec] of Object.entries(devDependencies)) if (spec === "catalog:" && catalog[name]) devDependencies[name] = catalog[name];
4387
+ }
4382
4388
  if (description) pkg.description = description;
4383
4389
  return pkg;
4384
4390
  });
@@ -4691,7 +4697,7 @@ async function executeBundledTemplate(workspaceInfo, templateInfo) {
4691
4697
  const listTemplatesMessage = renderCliDoc({
4692
4698
  usage: "vp create --list",
4693
4699
  summary: "List available builtin and popular project templates.",
4694
- documentationUrl: "https://viteplus.dev/guide/create",
4700
+ documentationUrl: documentationUrl$1("/guide/create"),
4695
4701
  sections: [
4696
4702
  {
4697
4703
  title: "Vite+ Built-in Templates",
@@ -1,10 +1,11 @@
1
- import { c as VITEST_VERSION, r as CONFIG_METADATA_ENV } from "./constants-C2dTOTe-.js";
1
+ import { c as VITEST_VERSION, r as CONFIG_METADATA_ENV } from "./constants-BAsBfS1J.js";
2
+ import { t as VITEST_RESOLVER_PACKAGES } from "./vitest-ecosystem-BU0AqZq-.js";
2
3
  import { createRequire } from "node:module";
3
- import path from "node:path";
4
+ import path, { resolve } from "node:path";
4
5
  import { fileURLToPath } from "node:url";
5
6
  import { readFileSync } from "node:fs";
6
7
  import { defineConfig, defineProject } from "vitest/config";
7
- //#region ../../node_modules/.pnpm/tsdown@0.23.0_@arethetypeswrong+core@0.18.2_@tsdown+css@0.23.0_@tsdown+exe@0.23.0_@type_298964156353ef75a02894ab80b3a2e6/node_modules/tsdown/esm-shims.js
8
+ //#region ../../node_modules/.pnpm/tsdown@0.23.0_@arethetypeswrong+core@0.18.2_@tsdown+css@0.23.0_@tsdown+exe@0.23.0_@type_540e13d22e6879071cae9cd3610e4dea/node_modules/tsdown/esm-shims.js
8
9
  const getFilename = () => fileURLToPath(import.meta.url);
9
10
  const getDirname = () => path.dirname(getFilename());
10
11
  const __dirname = /* @__PURE__ */ getDirname();
@@ -43,10 +44,9 @@ const vitePlusRequire = createRequire(typeof __dirname !== "undefined" ? __dirna
43
44
  const vitePlusModuleFile = fileURLToPath(import.meta.url);
44
45
  /**
45
46
  * Absolute path to the bundled `vitest` package's `package.json`, used as a
46
- * second `this.resolve` importer. The nested `@vitest/*` family (`@vitest/expect`,
47
- * `@vitest/runner`, `@vitest/snapshot`, …) are dependencies of `vitest` itself —
48
- * not direct deps of `vite-plus` — so under pnpm's isolated layout they are
49
- * reachable from `vitest`'s location but not from [[vitePlusModuleFile]].
47
+ * second `this.resolve` importer. Supported transitive packages can be
48
+ * reachable from `vitest`'s location but not from [[vitePlusModuleFile]]
49
+ * under pnpm's isolated layout.
50
50
  * Resolving `package.json` is condition-agnostic, so this is safe with
51
51
  * `require.resolve`. Cached; `null` once an attempt has failed so we never retry.
52
52
  */
@@ -60,6 +60,19 @@ function getVitestAnchor() {
60
60
  }
61
61
  return vitestAnchor;
62
62
  }
63
+ let vitestExports;
64
+ function getVitestImportTarget(id) {
65
+ const anchor = getVitestAnchor();
66
+ if (!anchor) throw new Error("Cannot resolve the bundled Vitest package. Reinstall vite-plus.");
67
+ vitestExports ??= JSON.parse(readFileSync(anchor, "utf8")).exports;
68
+ let target = vitestExports[id === "vitest" ? "." : `.${id.slice(6)}`];
69
+ while (target && typeof target === "object") {
70
+ const conditions = target;
71
+ target = conditions.import ?? conditions.default;
72
+ }
73
+ if (typeof target !== "string" || !target.startsWith("./")) throw new Error(`The bundled Vitest has no ESM export for ${id}.`);
74
+ return resolve(anchor, "..", target);
75
+ }
63
76
  /**
64
77
  * Match the `vitest` / `@vitest/*` family of bare specifiers — the imports a
65
78
  * browser-mode Vite dev server must resolve. Any query string is stripped
@@ -70,7 +83,9 @@ function getVitestAnchor() {
70
83
  function isVitestFamilySpecifier(id) {
71
84
  const bare = id.split("?")[0];
72
85
  if (bare.startsWith(".") || bare.startsWith("/") || bare.startsWith("\0")) return false;
73
- return bare === "vitest" || bare.startsWith("vitest/") || bare === "@vitest/browser" || bare.startsWith("@vitest/");
86
+ const segments = bare.split("/");
87
+ const packageName = bare.startsWith("@") ? segments.slice(0, 2).join("/") : segments[0];
88
+ return VITEST_RESOLVER_PACKAGES.has(packageName);
74
89
  }
75
90
  /**
76
91
  * Rescue `vitest` / `@vitest/*` resolution for browser-mode tests.
@@ -79,10 +94,10 @@ function isVitestFamilySpecifier(id) {
79
94
  * and `@vitest/browser` are transitive deps. pnpm's isolated layout only
80
95
  * exposes a package's *direct* deps, so the browser-mode Vite dev server
81
96
  * (rooted at the consumer project) cannot resolve `vitest/internal/browser`,
82
- * `@vitest/expect`, etc. Non-browser tests are unaffected — vitest's own
97
+ * `@vitest/mocker`, etc. Non-browser tests are unaffected — vitest's own
83
98
  * module runner handles resolution there.
84
99
  *
85
- * This plugin re-resolves the `vitest` / `@vitest/*` family through Vite's OWN
100
+ * This plugin re-resolves the explicit Vitest runtime allowlist through Vite's OWN
86
101
  * resolver, but ROOTED at `vite-plus`'s location ([[vitePlusModuleFile]]) and
87
102
  * then the bundled `vitest`'s location ([[getVitestAnchor]]) BEFORE the
88
103
  * project. So every such import binds to the same physical (pinned) Vitest that
@@ -123,10 +138,61 @@ function isVitestFamilySpecifier(id) {
123
138
  * [[vitePlusCoverageVersionGuardPlugin]] fails fast on a mismatch instead.
124
139
  */
125
140
  function vitePlusVitestResolverPlugin() {
141
+ let isVitestServer = false;
126
142
  return {
127
143
  name: "vite-plus:vitest-resolver",
128
144
  enforce: "pre",
145
+ config: {
146
+ order: "post",
147
+ handler(config, { command }) {
148
+ isVitestServer = command === "serve" && !!config.environments?.["__vitest__"];
149
+ if (!isVitestServer || !config.test?.browser?.enabled) return;
150
+ const aliases = config.resolve?.alias;
151
+ const entries = Array.isArray(aliases) ? [...aliases] : Object.entries(aliases ?? {}).map(([find, replacement]) => ({
152
+ find,
153
+ replacement
154
+ }));
155
+ const runtimeRequire = createRequire(getVitestAnchor());
156
+ const targets = new Map([
157
+ "vitest",
158
+ "vitest/internal/browser",
159
+ "vitest/internal/traces",
160
+ "expect-type",
161
+ "magic-string",
162
+ "chai",
163
+ "vite/module-runner"
164
+ ].map((id) => [id, id.startsWith("vitest") ? getVitestImportTarget(id) : runtimeRequire.resolve(id)]));
165
+ if (config.test.browser.provider?.name === "preview") {
166
+ const previewRequire = createRequire(vitePlusRequire.resolve("@vitest/browser-preview"));
167
+ for (const id of ["@testing-library/user-event", "@testing-library/dom"]) targets.set(id, previewRequire.resolve(id));
168
+ }
169
+ for (const [id, replacement] of targets) {
170
+ if (entries.some(({ find }) => typeof find === "string" ? id === find || id.startsWith(`${find}/`) : new RegExp(find).test(id))) continue;
171
+ entries.push({
172
+ find: new RegExp(`^${id}$`),
173
+ replacement
174
+ });
175
+ }
176
+ config.resolve ??= {};
177
+ config.resolve.alias = entries;
178
+ }
179
+ },
180
+ configResolved(config) {
181
+ const seen = /* @__PURE__ */ new Set();
182
+ const plugins = config.plugins;
183
+ const unique = plugins.filter((plugin) => {
184
+ if (!VITE_PLUS_TEST_PLUGIN_NAMES.has(plugin.name)) return true;
185
+ if (seen.has(plugin.name)) return false;
186
+ seen.add(plugin.name);
187
+ return true;
188
+ });
189
+ plugins.splice(0, plugins.length, ...unique);
190
+ },
129
191
  async resolveId(id, importer, options) {
192
+ if (isVitestServer && id === "vite-plus/test") return this.resolve("vitest", importer, {
193
+ ...options,
194
+ skipSelf: true
195
+ });
130
196
  if (!isVitestFamilySpecifier(id)) return null;
131
197
  if (id.includes("?")) return null;
132
198
  const vitestAnchorPath = getVitestAnchor();
@@ -157,10 +223,9 @@ function vitePlusVitestResolverPlugin() {
157
223
  * Absent packages are silently skipped so the server-deps optimizer never
158
224
  * tries to resolve a name that does not exist in the project's node_modules.
159
225
  *
160
- * The check is deferred to a `configResolved` plugin hook so that
161
- * `resolvedConfig.root` points at the actual project root (the value vite has
162
- * already normalised), rather than relying on `process.cwd()` at config-load
163
- * time (which can differ in workspace / monorepo setups).
226
+ * The environment hook adds installed packages to the module-runner options
227
+ * inherited by shared-server projects. The resolved-config hook also handles
228
+ * independent project servers, using each project's resolved root.
164
229
  *
165
230
  * Exported for unit testing.
166
231
  */
@@ -179,18 +244,26 @@ const AUTO_INLINE_DEPS = [
179
244
  *
180
245
  * Exported for unit testing. The `_createRequire` parameter lets tests inject
181
246
  * a controlled resolver without needing to spy on Node's ESM module namespace.
247
+ * Callers may share installation results for the same root within one config load.
182
248
  */
183
- function computeAutoInlineList(existingInline, projectRoot, _createRequire = createRequire) {
249
+ function computeAutoInlineList(existingInline, projectRoot, _createRequire = createRequire, installedPackages = /* @__PURE__ */ new Map()) {
184
250
  if (existingInline === true) return null;
185
- const projectRequire = _createRequire(`${projectRoot}/package.json`);
251
+ let projectRequire;
186
252
  const merged = Array.isArray(existingInline) ? [...existingInline] : [];
187
253
  for (const pkg of AUTO_INLINE_DEPS) {
188
254
  if (merged.some((entry) => entry === pkg || entry instanceof RegExp && entry.test(pkg))) continue;
189
- try {
190
- projectRequire.resolve(pkg);
191
- } catch {
192
- continue;
255
+ let installed = installedPackages.get(pkg);
256
+ if (installed === void 0) {
257
+ projectRequire ??= _createRequire(`${projectRoot}/package.json`);
258
+ try {
259
+ projectRequire.resolve(pkg);
260
+ installed = true;
261
+ } catch {
262
+ installed = false;
263
+ }
264
+ installedPackages.set(pkg, installed);
193
265
  }
266
+ if (!installed) continue;
194
267
  merged.push(pkg);
195
268
  }
196
269
  const hadEntries = Array.isArray(existingInline) ? existingInline.length : 0;
@@ -198,18 +271,47 @@ function computeAutoInlineList(existingInline, projectRoot, _createRequire = cre
198
271
  return merged;
199
272
  }
200
273
  function vitePlusAutoInlineMatcherPlugin() {
274
+ let projectRoot = "";
275
+ let isVitestServer = false;
276
+ const installedByRoot = /* @__PURE__ */ new Map();
277
+ function inlineList(existing, root) {
278
+ root = resolve(root);
279
+ let installed = installedByRoot.get(root);
280
+ if (!installed) {
281
+ installed = /* @__PURE__ */ new Map();
282
+ installedByRoot.set(root, installed);
283
+ }
284
+ return computeAutoInlineList(existing, root, createRequire, installed);
285
+ }
201
286
  return {
202
287
  name: "vite-plus:auto-inline-matcher-deps",
203
288
  enforce: "pre",
289
+ config: {
290
+ order: "post",
291
+ handler(config, { command }) {
292
+ isVitestServer = command === "serve" && !!config.environments?.["__vitest__"];
293
+ projectRoot = resolve(config.root ?? ".");
294
+ installedByRoot.clear();
295
+ }
296
+ },
297
+ configEnvironment(_name, config) {
298
+ if (!isVitestServer) return;
299
+ const existing = config.resolve?.noExternal;
300
+ const merged = inlineList(typeof existing === "string" || existing instanceof RegExp ? [existing] : existing, projectRoot);
301
+ if (merged !== null) {
302
+ config.resolve ??= {};
303
+ config.resolve.noExternal = merged;
304
+ }
305
+ },
204
306
  configResolved(resolvedConfig) {
205
- const testConfig = resolvedConfig.test;
206
- const merged = computeAutoInlineList(testConfig?.server?.deps?.inline, resolvedConfig.root);
207
- if (merged === null) return;
208
- if (!testConfig) resolvedConfig.test = { server: { deps: { inline: merged } } };
209
- else {
210
- if (!testConfig.server) testConfig.server = {};
211
- if (!testConfig.server.deps) testConfig.server.deps = {};
212
- testConfig.server.deps.inline = merged;
307
+ if (!isVitestServer) return;
308
+ const config = resolvedConfig;
309
+ const merged = inlineList(config.test?.server?.deps?.inline, config.root);
310
+ if (merged !== null) {
311
+ config.test ??= {};
312
+ config.test.server ??= {};
313
+ config.test.server.deps ??= {};
314
+ config.test.server.deps.inline = merged;
213
315
  }
214
316
  }
215
317
  };
@@ -340,6 +442,19 @@ function vitePlusCoverageVersionGuardPlugin() {
340
442
  * an optional `test.server.deps.inline`), so a shared helper keeps the
341
443
  * wiring consistent.
342
444
  */
445
+ const VITE_PLUS_TEST_PLUGIN_NAMES = /* @__PURE__ */ new Set([
446
+ "vite-plus:vitest-resolver",
447
+ "vite-plus:auto-inline-matcher-deps",
448
+ "vite-plus:coverage-version-guard"
449
+ ]);
450
+ function withoutVitePlusTestPlugins(plugin) {
451
+ if (Array.isArray(plugin)) return plugin.filter(keepUserPlugin).map(withoutVitePlusTestPlugins);
452
+ if (plugin instanceof Promise) return plugin.then(withoutVitePlusTestPlugins);
453
+ return plugin && VITE_PLUS_TEST_PLUGIN_NAMES.has(plugin.name) ? false : plugin;
454
+ }
455
+ function keepUserPlugin(plugin) {
456
+ return !plugin || !("name" in plugin) || !VITE_PLUS_TEST_PLUGIN_NAMES.has(plugin.name);
457
+ }
343
458
  function injectPluginIntoInlineConfig(config) {
344
459
  return {
345
460
  ...config,
@@ -347,15 +462,13 @@ function injectPluginIntoInlineConfig(config) {
347
462
  vitePlusVitestResolverPlugin(),
348
463
  vitePlusAutoInlineMatcherPlugin(),
349
464
  vitePlusCoverageVersionGuardPlugin(),
350
- ...config.plugins ?? []
465
+ ...(config.plugins ?? []).filter(keepUserPlugin).map(withoutVitePlusTestPlugins)
351
466
  ]
352
467
  };
353
468
  }
354
469
  /**
355
- * Walk `config.test?.projects` and inject the vite-plus plugins into each
356
- * project entry. Vitest spins up an independent Vite pipeline per project, so
357
- * root-level plugins do NOT propagate — without this, files matched by a
358
- * project's `include` glob never get the vitest resolver / auto-inline plugins.
470
+ * Inline projects inherit root plugins by default in Vitest v5. Only projects
471
+ * with inheritance disabled or an external base need their own injection.
359
472
  *
360
473
  * Entry shapes (from `TestProjectConfiguration`):
361
474
  * - string (glob path like `'./packages/*'`) → passed through unchanged.
@@ -377,15 +490,18 @@ function injectPluginIntoProject(project) {
377
490
  if (typeof project === "function") {
378
491
  const wrapped = (env) => {
379
492
  const result = project(env);
380
- if (result instanceof Promise) return result.then(injectPluginIntoInlineConfig);
381
- return injectPluginIntoInlineConfig(result);
493
+ if (result instanceof Promise) return result.then(injectIndependentProject);
494
+ return injectIndependentProject(result);
382
495
  };
383
496
  return wrapped;
384
497
  }
385
- if (project instanceof Promise) return project.then(injectPluginIntoInlineConfig);
386
- if (typeof project === "object" && project !== null) return injectPluginIntoInlineConfig(project);
498
+ if (project instanceof Promise) return project.then(injectIndependentProject);
499
+ if (typeof project === "object" && project !== null) return injectIndependentProject(project);
387
500
  return project;
388
501
  }
502
+ function injectIndependentProject(config) {
503
+ return config.extends === false || typeof config.extends === "string" ? injectPlugin(config) : config;
504
+ }
389
505
  function injectPlugin(config) {
390
506
  const injected = injectPluginIntoInlineConfig(config);
391
507
  const projects = injected.test?.projects;
@@ -407,22 +523,28 @@ function injectPluginIntoConfig(config) {
407
523
  if (config instanceof Promise) return config.then(injectPlugin);
408
524
  return injectPlugin(config);
409
525
  }
526
+ /**
527
+ * Keep a single generic signature so callback returns receive one contextual
528
+ * config type. Separate sync and async overloads make TypeScript widen nested
529
+ * literals in async callbacks before overload resolution (for example, an
530
+ * Oxlint rule severity of `'warn'` becomes `string`).
531
+ */
410
532
  function defineConfig$1(config) {
411
533
  return defineConfig(injectPluginIntoConfig(config));
412
534
  }
413
535
  /**
414
536
  * Inject the vite-plus plugins into a `defineProject` export. A project config
415
- * (`UserWorkspaceConfig`) cannot itself nest `test.projects`, so this only
416
- * touches the top-level `plugins` array (no project recursion like
417
- * [[injectPluginIntoConfig]] does).
537
+ * (`UserWorkspaceConfig`) can itself declare nested projects in v5. Referenced
538
+ * configs own a Vite server, so inject at their root and apply inheritance rules
539
+ * to their inline children.
418
540
  */
419
541
  function injectPluginIntoProjectExport(config) {
420
542
  if (typeof config === "function") return (env) => {
421
543
  const result = config(env);
422
- return result instanceof Promise ? result.then(injectPluginIntoInlineConfig) : injectPluginIntoInlineConfig(result);
544
+ return result instanceof Promise ? result.then(injectPlugin) : injectPlugin(result);
423
545
  };
424
- if (config instanceof Promise) return config.then(injectPluginIntoInlineConfig);
425
- return injectPluginIntoInlineConfig(config);
546
+ if (config instanceof Promise) return config.then(injectPlugin);
547
+ return injectPlugin(config);
426
548
  }
427
549
  function defineProject$1(config) {
428
550
  return defineProject(injectPluginIntoProjectExport(config));