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.
- package/LICENSE +35 -146
- package/README.md +6 -4
- package/binding/index.cjs +58 -54
- package/binding/index.d.cts +36 -4
- package/dist/{agent-Cu6-tXIP.js → agent-DIwEez_1.js} +6 -5
- package/dist/bin.js +75 -35
- package/dist/config/bin.js +3 -3
- package/dist/constants-BAsBfS1J.js +356 -0
- package/dist/create/bin.js +19 -13
- package/dist/{define-config-IgzmnvvV.js → define-config-Bz6dc3fm.js} +165 -43
- package/dist/{define-config-D0mevyb3.cjs → define-config-CAeeMTvb.cjs} +179 -44
- package/dist/{define-config-DPNEJxPz.d.ts → define-config-Cf_5GHmY.d.ts} +71 -25
- package/dist/define-config.cjs +1 -1
- package/dist/define-config.d.ts +1 -1
- package/dist/define-config.js +1 -1
- package/dist/dist-BWiANxFS.js +8052 -0
- package/dist/{dist-BDYZP12R.js → dist-BsAzy8OW.js} +109 -105
- package/dist/documentation-DqcZSthV.js +11 -0
- package/dist/{editor-4sjlHmUh.js → editor-DWgrWTbN.js} +246 -159
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{json-cULBl7Pi.js → json-JP24qHUF.js} +14 -6
- package/dist/lint-plugins.cjs +1 -1
- package/dist/migration/bin.js +3127 -18
- package/dist/migration/compat/worker.js +1 -1
- package/dist/{oxlint-plugin-config-BVqEe9KY.js → oxlint-plugin-config-B-P1a_0g.js} +1 -1
- package/dist/oxlint-plugin.js +9 -7
- package/dist/pack-bin.js +1 -1
- package/dist/{package-CHH8jWan.js → package-BrupPpWA.js} +6 -2
- package/dist/{vitest-ecosystem-BiRqcaRI.js → package-overrides-Dpn4scvN.js} +1 -7
- package/dist/{prompts-k14KgthC.js → prompts-BW7_fDGJ.js} +3 -4
- package/dist/{report-CK5TnTsr.js → report-NhQk8VHb.js} +1 -0
- package/dist/{resolve-vite-config-CTOTuqTi.js → resolve-vite-config-D3XIVT6s.js} +1 -1
- package/dist/{resolve-vite-config-BqvS2P98.js → resolve-vite-config-DcsMQaYy.js} +2 -2
- package/dist/staged/bin.js +1206 -3318
- package/dist/sync-versions/bin.js +4 -4
- package/dist/sync-versions/bin.mjs +17 -2
- package/dist/test/browser/context.js +1 -1
- package/dist/test/browser/providers/playwright/context.js +1 -1
- package/dist/test/browser/providers/preview/context.js +1 -1
- package/dist/test/browser-playwright/context.js +1 -1
- package/dist/test/browser-preview/context.js +1 -1
- package/dist/test/context.d.ts +2 -942
- package/dist/test/context.js +1 -1
- package/dist/test/internal/traces.js +1 -0
- package/dist/test/locators.d.ts +2 -294
- package/dist/test/matchers.d.ts +2 -29
- package/dist/test/mocker.d.ts +2 -0
- package/dist/test/mocker.js +1 -0
- package/dist/test/{browser-webdriverio/context.js → plugins/browser-context.d.ts} +1 -0
- package/dist/test/plugins/browser-context.js +1 -1
- package/dist/test/plugins/browser-locators.d.ts +2 -0
- package/dist/test/plugins/browser-playwright.d.ts +2 -0
- package/dist/test/plugins/browser-preview.d.ts +2 -0
- package/dist/test/plugins/browser.d.ts +2 -0
- package/dist/test/plugins/mocker-automock.d.ts +2 -0
- package/dist/test/plugins/mocker-browser.d.ts +2 -0
- package/dist/test/plugins/mocker-node.d.ts +2 -0
- package/dist/test/plugins/mocker-redirect.d.ts +2 -0
- package/dist/test/plugins/mocker-register.d.ts +2 -0
- package/dist/test/plugins/mocker-transforms.d.ts +2 -0
- package/dist/test/plugins/mocker.d.ts +2 -0
- package/dist/test/plugins/pretty-format.d.ts +2 -0
- package/dist/test/plugins/snapshot-environment.d.ts +2 -0
- package/dist/test/plugins/snapshot-manager.d.ts +2 -0
- package/dist/test/plugins/snapshot.d.ts +2 -0
- package/dist/test/plugins/spy.d.ts +2 -0
- package/dist/test/plugins/utils-constants.d.ts +2 -0
- package/dist/test/plugins/utils-diff.d.ts +2 -0
- package/dist/test/plugins/utils-display.d.ts +2 -0
- package/dist/test/plugins/utils-error.d.ts +2 -0
- package/dist/test/plugins/utils-helpers.d.ts +2 -0
- package/dist/test/plugins/utils-offset.d.ts +2 -0
- package/dist/test/plugins/utils-resolver.d.ts +2 -0
- package/dist/test/plugins/utils-serialize.d.ts +2 -0
- package/dist/test/plugins/utils-source-map-node.d.ts +2 -0
- package/dist/test/plugins/utils-source-map.d.ts +2 -0
- package/dist/test/plugins/utils-timers.d.ts +2 -0
- package/dist/test/plugins/utils.d.ts +2 -0
- package/dist/toolchain.js +11 -11
- package/dist/toolchain.json +11 -11
- package/dist/{tsconfig-euB-GmIE.js → tsconfig-DESFDzWP.js} +1 -1
- package/dist/{tsconfig-C3h9CVTA.js → tsconfig-piorpNV7.js} +8 -4
- package/dist/version.js +5 -3
- package/dist/versions.js +6 -6
- package/dist/vitest-ecosystem-BU0AqZq-.js +23 -0
- package/dist/vitest-v5-entry-points-DthU1e_O.js +25 -0
- package/docs/config/fmt.md +4 -2
- package/docs/config/lint.md +4 -2
- package/docs/config/run.md +62 -26
- package/docs/guide/automatic-data-tracking.md +20 -15
- package/docs/guide/cache.md +12 -8
- package/docs/guide/check.md +2 -0
- package/docs/guide/commit-hooks.md +8 -1
- package/docs/guide/env.md +18 -13
- package/docs/guide/fmt.md +6 -2
- package/docs/guide/index.md +1 -1
- package/docs/guide/install.md +1 -1
- package/docs/guide/lint.md +5 -1
- package/docs/guide/local-cli.md +3 -3
- package/docs/guide/migrate-rules.md +58 -12
- package/docs/guide/migrate.md +86 -20
- package/docs/guide/monorepo.md +7 -1
- package/docs/guide/run.md +3 -1
- package/docs/guide/test.md +2 -0
- package/docs/guide/troubleshooting.md +3 -3
- package/docs/guide/vitest-v5.md +221 -0
- package/package.json +64 -87
- package/bin/oxfmt +0 -33
- package/bin/oxlint +0 -38
- package/dist/cli-truncate-Bg3RDXpi.js +0 -865
- package/dist/constants-C2dTOTe-.js +0 -80
- package/dist/dist-Dqv1-Clg.js +0 -3
- package/dist/is-fullwidth-code-point-BUNlIICg.js +0 -8
- package/dist/log-update-CoW8Z4Dl.js +0 -491
- package/dist/semver-CaDAb8vV.js +0 -1400
- package/dist/strip-ansi-C3wrWz9t.js +0 -853
- package/dist/test/browser/providers/webdriverio/context.d.ts +0 -1
- package/dist/test/browser/providers/webdriverio/context.js +0 -1
- package/dist/test/browser/providers/webdriverio.d.ts +0 -77
- package/dist/test/browser/providers/webdriverio.js +0 -1
- package/dist/test/browser-webdriverio/context.d.ts +0 -1
- package/dist/test/browser-webdriverio.d.ts +0 -77
- package/dist/test/browser-webdriverio.js +0 -1
- package/dist/test/coverage.d.ts +0 -2
- package/dist/test/coverage.js +0 -1
- package/dist/test/environments.d.ts +0 -2
- package/dist/test/environments.js +0 -1
- package/dist/test/plugins/browser-webdriverio.js +0 -1
- package/dist/test/plugins/expect.js +0 -1
- package/dist/test/plugins/runner-types.js +0 -1
- package/dist/test/plugins/runner-utils.js +0 -1
- package/dist/test/plugins/runner.js +0 -1
- package/dist/test/reporters.d.ts +0 -2
- package/dist/test/reporters.js +0 -1
- package/dist/test/runners.d.ts +0 -2
- package/dist/test/runners.js +0 -1
- package/dist/test/snapshot.d.ts +0 -2
- package/dist/test/snapshot.js +0 -1
- package/dist/test/suite.d.ts +0 -2
- package/dist/test/suite.js +0 -1
- package/dist/tsgolint-path-CbDReEOx.js +0 -34
- package/dist/tsgolint-path.d.ts +0 -7
- package/dist/tsgolint-path.js +0 -2
- package/dist/wrap-ansi-DNjkuBEp.js +0 -157
- package/dist/wrap-ansi-DUi52C6W.js +0 -2
package/dist/create/bin.js
CHANGED
|
@@ -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-
|
|
5
|
-
import { i as readJsonFile, n as editJsonFile } from "../json-
|
|
6
|
-
import { o as fetchNpmResource, r as getScopeFromPackageName, s as getNpmRegistry, t as checkNpmPackageExists } from "../package-
|
|
7
|
-
import { i as hasViteConfig, o as resolveViteConfig, r as findWorkspaceRoot, t as findViteConfig } from "../resolve-vite-config-
|
|
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-
|
|
9
|
-
import {
|
|
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-
|
|
11
|
-
import {
|
|
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
|
-
|
|
630
|
-
|
|
631
|
-
|
|
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: "
|
|
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-
|
|
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_@
|
|
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.
|
|
47
|
-
*
|
|
48
|
-
*
|
|
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
|
-
|
|
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/
|
|
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
|
|
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
|
|
161
|
-
*
|
|
162
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
-
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
if (
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
*
|
|
356
|
-
*
|
|
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(
|
|
381
|
-
return
|
|
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(
|
|
386
|
-
if (typeof project === "object" && project !== null) return
|
|
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`)
|
|
416
|
-
*
|
|
417
|
-
*
|
|
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(
|
|
544
|
+
return result instanceof Promise ? result.then(injectPlugin) : injectPlugin(result);
|
|
423
545
|
};
|
|
424
|
-
if (config instanceof Promise) return config.then(
|
|
425
|
-
return
|
|
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));
|