Skip to content

Commit 9fbe03b

Browse files
authored
Merge branch 'main' into deps/upstream-update
2 parents c94026e + 6b036e8 commit 9fbe03b

39 files changed

Lines changed: 447 additions & 27 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ Use `vp migrate` to migrate to Vite+. It merges tool-specific config files such
113113

114114
- **run** - Run monorepo tasks
115115
- **exec** - Execute a command from local `node_modules/.bin`
116+
- **node** - Run a Node.js script with the resolved Vite+ environment
116117
- **dlx** - Execute a package binary without installing it as a dependency
117118
- **cache** - Manage the task cache
118119

@@ -124,7 +125,7 @@ Use `vp migrate` to migrate to Vite+. It merges tool-specific config files such
124125

125126
#### Manage Dependencies
126127

127-
Vite+ automatically wraps your package manager (pnpm, npm, or Yarn) based on `packageManager` and lockfiles:
128+
Vite+ automatically wraps your package manager (pnpm, npm, Yarn, or Bun) based on `packageManager` and lockfiles:
128129

129130
- **add** - Add packages to dependencies
130131
- **remove** (`rm`, `un`, `uninstall`) - Remove packages from dependencies
@@ -135,6 +136,7 @@ Vite+ automatically wraps your package manager (pnpm, npm, or Yarn) based on `pa
135136
- **why** (`explain`) - Show why a package is installed
136137
- **info** (`view`, `show`) - View package metadata from the registry
137138
- **link** (`ln`) / **unlink** - Manage local package links
139+
- **rebuild** - Rebuild native modules
138140
- **pm** - Forward a command to the package manager
139141

140142
#### Maintain

crates/vite_migration/src/vite_config.rs

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,19 +291,25 @@ fn strip_schema_property(config: &str) -> Cow<'_, str> {
291291
/// duplicate keys are resolved at runtime by JS spread semantics.
292292
///
293293
/// Returns `true` only when the key appears as a **direct** member of one of
294-
/// those recognized object literals. Comments, string occurrences, nested
295-
/// keys (e.g. `plugins: [{ fmt: ... }]`), and unrelated objects are all
296-
/// ignored correctly.
294+
/// those recognized object literals, either as a `key: value` pair or as a
295+
/// `{ key }` shorthand property (e.g. a template wiring in tooling config with
296+
/// `fmt,` / `lint,`). Comments, string occurrences, nested keys (e.g.
297+
/// `plugins: [{ fmt: ... }]`), and unrelated objects are all ignored correctly.
297298
pub fn has_config_key(vite_config_content: &str, config_key: &str) -> Result<bool, Error> {
298299
let grep = SupportLang::TypeScript.ast_grep(vite_config_content);
299300
let root = grep.root();
300301

301302
for node in root.dfs() {
302-
if node.kind() != "pair" {
303-
continue;
304-
}
305-
let Some(key_node) = node.field("key") else { continue };
306-
if !pair_key_matches(&key_node, config_key) {
303+
// Match both `key: value` pairs and `{ key }` shorthand properties. A
304+
// custom template that wires tooling config in via shorthand (`fmt,` /
305+
// `lint,`) still declares the key, so it must not get a duplicate
306+
// inline key injected by `vp create` / `vp lint --init`. See #1836.
307+
let matches_key = match node.kind().as_ref() {
308+
"pair" => node.field("key").is_some_and(|key| pair_key_matches(&key, config_key)),
309+
"shorthand_property_identifier" => node.text() == config_key,
310+
_ => continue,
311+
};
312+
if !matches_key {
307313
continue;
308314
}
309315
let Some(parent_object) = node.parent() else { continue };
@@ -1062,6 +1068,58 @@ export default () =>
10621068
assert!(has_config_key(cfg, "fmt").unwrap());
10631069
}
10641070

1071+
#[test]
1072+
fn test_has_config_key_shorthand_property() {
1073+
// A custom template that keeps tooling config in separate modules wires
1074+
// them in with shorthand properties (`fmt,` / `lint,`). The key is
1075+
// present even though there is no explicit value, so `vp create` /
1076+
// `vp lint --init` must not inject a duplicate inline key. See #1836.
1077+
let cfg = r#"import { defineConfig } from 'vite-plus';
1078+
1079+
import { fmt } from './tooling/format';
1080+
import { lint } from './tooling/lint';
1081+
1082+
export default defineConfig(({ mode }) => {
1083+
return {
1084+
server: { port: 3000 },
1085+
fmt,
1086+
lint,
1087+
};
1088+
});
1089+
"#;
1090+
assert!(has_config_key(cfg, "fmt").unwrap());
1091+
assert!(has_config_key(cfg, "lint").unwrap());
1092+
assert!(!has_config_key(cfg, "pack").unwrap());
1093+
assert!(!has_config_key(cfg, "staged").unwrap());
1094+
}
1095+
1096+
#[test]
1097+
fn test_has_config_key_shorthand_object_export() {
1098+
let cfg = r#"import { defineConfig } from 'vite-plus';
1099+
1100+
const fmt = { singleQuote: true };
1101+
1102+
export default defineConfig({
1103+
fmt,
1104+
});
1105+
"#;
1106+
assert!(has_config_key(cfg, "fmt").unwrap());
1107+
assert!(!has_config_key(cfg, "lint").unwrap());
1108+
}
1109+
1110+
#[test]
1111+
fn test_has_config_key_ignores_nested_shorthand() {
1112+
// `fmt` shorthand is nested inside a plugin's options object, not a
1113+
// top-level config key, so it must not count as present.
1114+
let cfg = r#"import { defineConfig } from 'vite-plus';
1115+
1116+
export default defineConfig({
1117+
plugins: [somePlugin({ fmt })],
1118+
});
1119+
"#;
1120+
assert!(!has_config_key(cfg, "fmt").unwrap());
1121+
}
1122+
10651123
#[test]
10661124
fn test_has_config_key_fate_template_shape() {
10671125
// Mirrors create-fate's drizzle template — the bug that motivated this fix.

docs/guide/commit-hooks.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,17 @@ If you use [`vp create`](/guide/create) or [`vp migrate`](/guide/migrate), Vite+
2222
```bash
2323
vp config
2424
vp config --hooks-dir .vite-hooks
25+
vp config --no-hooks
26+
vp config --no-agent
2527
```
2628

29+
Use `--no-hooks` when you want `vp config` to leave existing Git hook setup unchanged. Use
30+
`--no-agent` when you want it to skip updates to existing coding agent instruction files. You
31+
can pass both flags when you want `vp config` to skip both setup steps.
32+
33+
You can also set `VITE_GIT_HOOKS=0` to disable hook installation from lifecycle scripts such as
34+
`prepare` or `postinstall`.
35+
2736
### `vp staged`
2837

2938
`vp staged` runs staged-file checks using the `staged` config from `vite.config.ts`. If you set up Vite+ to handle your commit hooks, it will automatically run when you commit your local changes.

docs/guide/index.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,11 @@ Vite+ can handle the entire local frontend development cycle from starting a pro
104104
### Execute
105105

106106
- [`vp run`](/guide/run) runs tasks across workspaces with caching.
107-
- [`vp cache clean`](/guide/cache) clears task cache entries.
108-
- [`vpx`](/guide/vpx) downloads and runs binaries globally.
109107
- [`vp exec`](/guide/vpx) runs local project binaries.
108+
- [`vp node`](/guide/env) runs Node.js scripts with the resolved Vite+ environment.
110109
- [`vp dlx`](/guide/vpx) downloads and runs package binaries without adding them as dependencies.
110+
- [`vp cache clean`](/guide/cache) clears task cache entries.
111+
- [`vpx`](/guide/vpx) downloads and runs binaries globally.
111112

112113
### Build
113114

@@ -117,7 +118,8 @@ Vite+ can handle the entire local frontend development cycle from starting a pro
117118

118119
### Manage Dependencies
119120

120-
- [`vp add`](/guide/install), [`vp remove`](/guide/install), [`vp update`](/guide/install), [`vp dedupe`](/guide/install), [`vp outdated`](/guide/install), [`vp why`](/guide/install), and [`vp info`](/guide/install) wrap package-manager workflows.
121+
- [`vp add`](/guide/install), [`vp remove`](/guide/install), [`vp update`](/guide/install), [`vp dedupe`](/guide/install), [`vp outdated`](/guide/install), [`vp list`](/guide/install), [`vp why`](/guide/install), and [`vp info`](/guide/install) wrap package-manager workflows.
122+
- [`vp link`](/guide/install), [`vp unlink`](/guide/install), and [`vp rebuild`](/guide/install) cover local package links and native module rebuilds.
121123
- [`vp pm <command>`](/guide/install) calls other package manager commands directly.
122124

123125
### Maintain

docs/guide/upgrade.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ You can upgrade both of them independently.
1414
## Global `vp`
1515

1616
```bash
17-
vp upgrade # upgrade to the latest version
18-
vp upgrade --check # check for updates without installing
17+
vp upgrade # upgrade to the latest version
18+
vp upgrade --check # check for updates without installing
19+
vp upgrade <version> # install a specific version
20+
vp upgrade --registry <registry> # use a custom npm registry
1921
```
2022

2123
### Rollback

packages/cli/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
**The Unified Toolchain for the Web**
44
_runtime and package management, create, dev, check, test, build, pack, and monorepo task caching in a single dependency_
55

6-
This package provides the project-local version of Vite+. The global `vite` command automatically delegates to this package for all project-specific tasks.
6+
This package provides the project-local version of Vite+. The global `vp` command automatically delegates to this package for all project-specific tasks.
77

88
---
99

@@ -111,6 +111,7 @@ Use `vp migrate` to migrate to Vite+. It merges tool-specific config files such
111111

112112
- **run** - Run monorepo tasks
113113
- **exec** - Execute a command from local `node_modules/.bin`
114+
- **node** - Run a Node.js script with the resolved Vite+ environment
114115
- **dlx** - Execute a package binary without installing it as a dependency
115116
- **cache** - Manage the task cache
116117

@@ -122,7 +123,7 @@ Use `vp migrate` to migrate to Vite+. It merges tool-specific config files such
122123

123124
#### Manage Dependencies
124125

125-
Vite+ automatically wraps your package manager (pnpm, npm, or Yarn) based on `packageManager` and lockfiles:
126+
Vite+ automatically wraps your package manager (pnpm, npm, Yarn, or Bun) based on `packageManager` and lockfiles:
126127

127128
- **add** - Add packages to dependencies
128129
- **remove** (`rm`, `un`, `uninstall`) - Remove packages from dependencies
@@ -133,6 +134,7 @@ Vite+ automatically wraps your package manager (pnpm, npm, or Yarn) based on `pa
133134
- **why** (`explain`) - Show why a package is installed
134135
- **info** (`view`, `show`) - View package metadata from the registry
135136
- **link** (`ln`) / **unlink** - Manage local package links
137+
- **rebuild** - Rebuild native modules
136138
- **pm** - Forward a command to the package manager
137139

138140
#### Maintain

packages/cli/snap-tests-global/command-config-custom-dir-hook-path/snap.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
> git init
2-
> vp config --hooks-only --hooks-dir .config/husky
2+
> vp config --no-agent --hooks-dir .config/husky
33
> mkdir -p node_modules/.bin && printf '#!/usr/bin/env sh\necho hook-path-ok' > node_modules/.bin/test-hook-cmd && chmod +x node_modules/.bin/test-hook-cmd
44
> mkdir -p .config/husky && printf 'test-hook-cmd\n' > .config/husky/pre-commit
55
> echo test > file.txt && git add file.txt

packages/cli/snap-tests-global/command-config-custom-dir-hook-path/steps.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"commands": [
33
{ "command": "git init", "ignoreOutput": true },
4-
{ "command": "vp config --hooks-only --hooks-dir .config/husky", "ignoreOutput": true },
4+
{ "command": "vp config --no-agent --hooks-dir .config/husky", "ignoreOutput": true },
55
{
66
"command": "mkdir -p node_modules/.bin && printf '#!/usr/bin/env sh\\necho hook-path-ok' > node_modules/.bin/test-hook-cmd && chmod +x node_modules/.bin/test-hook-cmd",
77
"ignoreOutput": true

packages/cli/snap-tests-global/command-config-help/snap.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Configure Vite+ for the current project (hooks + agent integration).
55

66
Options:
77
--hooks-dir <path> Custom hooks directory (default: .vite-hooks)
8+
--no-hooks Skip hook installation
9+
--no-agent Skip updating coding agent instructions
810
-h, --help Show this help message
911

1012
Environment:
@@ -20,6 +22,8 @@ Configure Vite+ for the current project (hooks + agent integration).
2022

2123
Options:
2224
--hooks-dir <path> Custom hooks directory (default: .vite-hooks)
25+
--no-hooks Skip hook installation
26+
--no-agent Skip updating coding agent instructions
2327
-h, --help Show this help message
2428

2529
Environment:
@@ -35,6 +39,8 @@ Configure Vite+ for the current project (hooks + agent integration).
3539

3640
Options:
3741
--hooks-dir <path> Custom hooks directory (default: .vite-hooks)
42+
--no-hooks Skip hook installation
43+
--no-agent Skip updating coding agent instructions
3844
-h, --help Show this help message
3945

4046
Environment:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# My Project
2+
3+
Custom instructions here.
4+
5+
<!--VITE PLUS START-->
6+
7+
OUTDATED CONTENT THAT SHOULD NOT BE REPLACED
8+
9+
<!--VITE PLUS END-->
10+
11+
More custom content below.

0 commit comments

Comments
 (0)