Skip to content

Commit 3262bda

Browse files
authored
refactor(cli): rename vp lib to vp pack (#575)
Rename the `lib` command to `pack` across the entire codebase: - CLI command definition and dispatch (Rust + NAPI bindings) - TypeScript resolver, bin entry, types, and module augmentation - Package exports (`vite-plus/lib` → `vite-plus/pack`, `vite-plus-core/lib` → `vite-plus-core/pack`) - Config key (`lib:` → `pack:` in vite.config.ts) - Environment prefix (`VITE_LIB_` → `VITE_PACK_`) - Migration rules (tsdown → `vite pack`, import rewriter → `vite-plus/pack`) - All snap tests and test assertions - Documentation
1 parent a91dd5a commit 3262bda

58 files changed

Lines changed: 169 additions & 156 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/vite_global_cli/src/cli.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,13 @@ pub enum Commands {
565565
args: Vec<String>,
566566
},
567567

568+
/// Build library
569+
Pack {
570+
/// Additional arguments
571+
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
572+
args: Vec<String>,
573+
},
574+
568575
/// Run tasks
569576
Run {
570577
/// Additional arguments
@@ -1539,6 +1546,8 @@ pub async fn run_command(cwd: AbsolutePathBuf, args: Args) -> Result<ExitStatus,
15391546

15401547
Commands::Fmt { args } => commands::delegate::execute(cwd, "fmt", &args).await,
15411548

1549+
Commands::Pack { args } => commands::delegate::execute(cwd, "pack", &args).await,
1550+
15421551
Commands::Run { args } => commands::run_or_delegate::execute(cwd, &args).await,
15431552

15441553
Commands::Preview { args } => commands::delegate::execute(cwd, "preview", &args).await,
@@ -1591,17 +1600,18 @@ fn apply_custom_help(cmd: clap::Command) -> clap::Command {
15911600

15921601
let after_help = format!(
15931602
"{bold_underline}Core Commands:{reset}
1594-
{bold}create{reset} Create a new project from a template
1595-
{bold}dev{reset} Run the development server
1596-
{bold}build{reset} Build for production
1597-
{bold}test{reset} Run tests
1598-
{bold}lint{reset} Lint code
1599-
{bold}fmt{reset} Format code
1600-
{bold}run{reset} Run tasks
1601-
{bold}preview{reset} Preview production build
1602-
{bold}env{reset} Manage Node.js versions
1603-
{bold}migrate{reset} Migrate an existing project to Vite+
1604-
{bold}cache{reset} Manage the task cache
1603+
{bold}create{reset} Create a new project from a template
1604+
{bold}dev{reset} Run the development server
1605+
{bold}build{reset} Build for production
1606+
{bold}test{reset} Run tests
1607+
{bold}lint{reset} Lint code
1608+
{bold}fmt{reset} Format code
1609+
{bold}pack{reset} Build library
1610+
{bold}run{reset} Run tasks
1611+
{bold}preview{reset} Preview production build
1612+
{bold}env{reset} Manage Node.js versions
1613+
{bold}migrate{reset} Migrate an existing project to Vite+
1614+
{bold}cache{reset} Manage the task cache
16051615
16061616
{bold_underline}Package Manager Commands:{reset}
16071617
{bold}install, i{reset} Install all dependencies, or add packages if package names are provided

crates/vite_migration/src/import_rewriter.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ fix: $NEW_IMPORT
238238
/// ast-grep rules for rewriting tsdown imports and declare module statements
239239
///
240240
/// This rewrites:
241-
/// - `import { ... } from 'tsdown'` → `import { ... } from 'vite-plus/lib'`
242-
/// - `declare module 'tsdown' { ... }` → `declare module 'vite-plus/lib' { ... }`
241+
/// - `import { ... } from 'tsdown'` → `import { ... } from 'vite-plus/pack'`
242+
/// - `declare module 'tsdown' { ... }` → `declare module 'vite-plus/pack' { ... }`
243243
const REWRITE_TSDOWN_RULES: &str = r#"---
244244
id: rewrite-tsdown-import
245245
language: TypeScript
@@ -254,7 +254,7 @@ transform:
254254
replace:
255255
source: $STR
256256
replace: tsdown
257-
by: "vite-plus/lib"
257+
by: "vite-plus/pack"
258258
fix: $NEW_IMPORT
259259
---
260260
id: rewrite-declare-module-tsdown
@@ -270,7 +270,7 @@ transform:
270270
replace:
271271
source: $STR
272272
replace: tsdown
273-
by: "vite-plus/lib"
273+
by: "vite-plus/pack"
274274
fix: $NEW_IMPORT
275275
"#;
276276

@@ -1569,7 +1569,7 @@ export default defineConfig({
15691569
assert!(result.updated);
15701570
assert_eq!(
15711571
result.content,
1572-
r#"import { defineConfig } from 'vite-plus/lib';
1572+
r#"import { defineConfig } from 'vite-plus/pack';
15731573
15741574
export default defineConfig({
15751575
entry: 'src/index.ts',
@@ -1589,7 +1589,7 @@ export default defineConfig({
15891589
assert!(result.updated);
15901590
assert_eq!(
15911591
result.content,
1592-
r#"import { defineConfig } from "vite-plus/lib";
1592+
r#"import { defineConfig } from "vite-plus/pack";
15931593
15941594
export default defineConfig({
15951595
entry: "src/index.ts",
@@ -1609,7 +1609,7 @@ export default defineConfig({
16091609
assert!(result.updated);
16101610
assert_eq!(
16111611
result.content,
1612-
r#"declare module 'vite-plus/lib' {
1612+
r#"declare module 'vite-plus/pack' {
16131613
interface BuildConfig {
16141614
custom?: boolean;
16151615
}
@@ -1629,7 +1629,7 @@ export default defineConfig({
16291629
assert!(result.updated);
16301630
assert_eq!(
16311631
result.content,
1632-
r#"declare module "vite-plus/lib" {
1632+
r#"declare module "vite-plus/pack" {
16331633
interface BuildConfig {
16341634
custom?: boolean;
16351635
}

crates/vite_migration/src/package.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ fix: vite test
125125
assert_eq!(rewrite_script("vite test", &rules), "vite test");
126126
assert_eq!(rewrite_script("vite lint", &rules), "vite lint");
127127
assert_eq!(rewrite_script("vite fmt", &rules), "vite fmt");
128-
assert_eq!(rewrite_script("vite lib", &rules), "vite lib");
128+
assert_eq!(rewrite_script("vite pack", &rules), "vite pack");
129129
assert_eq!(rewrite_script("vite preview", &rules), "vite preview");
130130
assert_eq!(rewrite_script("vite optimize", &rules), "vite optimize");
131131
assert_eq!(rewrite_script("vite build -r", &rules), "vite build -r");

crates/vite_migration/src/vite_config.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ fn indent_multiline(s: &str, spaces: usize) -> String {
269269
/// Merge tsdown config into vite.config.ts by importing it
270270
///
271271
/// This function adds an import statement for the tsdown config file
272-
/// and adds `lib: tsdownConfig` to the defineConfig.
272+
/// and adds `pack: tsdownConfig` to the defineConfig.
273273
///
274274
/// # Arguments
275275
///
@@ -291,7 +291,7 @@ pub fn merge_tsdown_config(
291291
///
292292
/// This adds:
293293
/// 1. An import statement: `import tsdownConfig from './tsdown.config.ts'`
294-
/// 2. The lib config in defineConfig: `lib: tsdownConfig`
294+
/// 2. The pack config in defineConfig: `pack: tsdownConfig`
295295
///
296296
/// This function is idempotent - running it multiple times will not create duplicates.
297297
fn merge_tsdown_config_content(
@@ -324,9 +324,9 @@ fn merge_tsdown_config_content(
324324
let content_with_import =
325325
format!("import tsdownConfig from '{import_path}';\n\n{vite_config_content}");
326326

327-
// Step 2: Add lib: tsdownConfig to defineConfig
328-
let lib_rule = generate_merge_rule("tsdownConfig", "lib");
329-
let (final_content, _) = ast_grep::apply_rules(&content_with_import, &lib_rule)?;
327+
// Step 2: Add pack: tsdownConfig to defineConfig
328+
let pack_rule = generate_merge_rule("tsdownConfig", "pack");
329+
let (final_content, _) = ast_grep::apply_rules(&content_with_import, &pack_rule)?;
330330

331331
Ok(MergeResult { content: final_content, updated: true, uses_function_callback })
332332
}
@@ -966,7 +966,7 @@ export default defineConfig({
966966
import { defineConfig } from 'vite-plus';
967967
968968
export default defineConfig({
969-
lib: tsdownConfig,
969+
pack: tsdownConfig,
970970
plugins: [],
971971
});"#
972972
);
@@ -992,7 +992,7 @@ import { defineConfig } from 'vite-plus';
992992
import react from '@vitejs/plugin-react';
993993
994994
export default defineConfig({
995-
lib: tsdownConfig,
995+
pack: tsdownConfig,
996996
plugins: [react()],
997997
});"#
998998
);
@@ -1016,7 +1016,7 @@ export default defineConfig((env) => ({
10161016
import { defineConfig } from 'vite-plus';
10171017
10181018
export default defineConfig((env) => ({
1019-
lib: tsdownConfig,
1019+
pack: tsdownConfig,
10201020
plugins: [],
10211021
}));"#
10221022
);
@@ -1030,7 +1030,7 @@ export default defineConfig((env) => ({
10301030
import { defineConfig } from 'vite-plus';
10311031
10321032
export default defineConfig({
1033-
lib: tsdownConfig,
1033+
pack: tsdownConfig,
10341034
plugins: [],
10351035
});"#;
10361036

@@ -1050,7 +1050,7 @@ export default defineConfig({
10501050
import { defineConfig } from 'vite-plus';
10511051
10521052
export default defineConfig({
1053-
lib: tsdownConfig,
1053+
pack: tsdownConfig,
10541054
plugins: [],
10551055
});"#;
10561056

@@ -1080,15 +1080,15 @@ export default defineConfig({
10801080
r#"import tsdownConfig from './tsdown.config.js';
10811081
10821082
export default {
1083-
lib: tsdownConfig,
1083+
pack: tsdownConfig,
10841084
server: { port: 3000 }
10851085
}"#
10861086
);
10871087
}
10881088

10891089
#[test]
10901090
fn test_merge_tsdown_config_content_no_false_positive_stdlib() {
1091-
// "stdlib:" should not be detected as "lib:" key
1091+
// "stdlib:" should not be detected as "pack:" key
10921092
let vite_config = r#"import { defineConfig } from 'vite-plus';
10931093
10941094
export default defineConfig({
@@ -1098,7 +1098,7 @@ export default defineConfig({
10981098
let result = merge_tsdown_config_content(vite_config, "./tsdown.config.ts").unwrap();
10991099
assert!(result.updated);
11001100
assert!(result.content.contains("import tsdownConfig from './tsdown.config.js'"));
1101-
assert!(result.content.contains("lib: tsdownConfig"));
1101+
assert!(result.content.contains("pack: tsdownConfig"));
11021102
assert!(result.content.contains("stdlib: 'some-value'"));
11031103
}
11041104

docs/vite/guide/cli.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,22 @@ vp build [root] [OPTIONS]
100100

101101
## Build Library
102102

103-
### `vp lib`
103+
### `vp pack`
104104

105105
Build a library using tsdown.
106106

107107
#### Usage
108108

109109
```bash
110-
vp lib [<ARGS>...]
110+
vp pack [<ARGS>...]
111111
```
112112

113113
#### Examples
114114

115115
```bash
116-
vp lib
117-
vp lib --watch
118-
vp lib --outdir dist
116+
vp pack
117+
vp pack --watch
118+
vp pack --outdir dist
119119
```
120120

121121
## Build Documentation
@@ -453,7 +453,7 @@ vp build
453453
vp dev
454454

455455
# Build library
456-
vp lib
456+
vp pack
457457

458458
# Build docs
459459
vp doc build

packages/cli/binding/index.d.cts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface CliOptions {
66
fmt: (err: Error | null) => Promise<JsCommandResolvedResult>;
77
vite: (err: Error | null) => Promise<JsCommandResolvedResult>;
88
test: (err: Error | null) => Promise<JsCommandResolvedResult>;
9-
lib: (err: Error | null) => Promise<JsCommandResolvedResult>;
9+
pack: (err: Error | null) => Promise<JsCommandResolvedResult>;
1010
doc: (err: Error | null) => Promise<JsCommandResolvedResult>;
1111
cwd?: string;
1212
/** CLI arguments (should be process.argv.slice(2) from JavaScript) */

packages/cli/binding/src/cli.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub enum SynthesizableSubcommand {
7171
},
7272
/// Build library
7373
#[command(disable_help_flag = true)]
74-
Lib {
74+
Pack {
7575
#[clap(allow_hyphen_values = true, trailing_var_arg = true)]
7676
args: Vec<String>,
7777
},
@@ -133,7 +133,7 @@ pub struct CliOptions {
133133
pub fmt: BoxedResolverFn,
134134
pub vite: BoxedResolverFn,
135135
pub test: BoxedResolverFn,
136-
pub lib: BoxedResolverFn,
136+
pub pack: BoxedResolverFn,
137137
pub doc: BoxedResolverFn,
138138
pub resolve_universal_vite_config: ViteConfigResolverFn,
139139
}
@@ -407,16 +407,16 @@ impl SubcommandResolver {
407407
envs: merge_resolved_envs(envs, resolved.envs),
408408
})
409409
}
410-
SynthesizableSubcommand::Lib { args } => {
410+
SynthesizableSubcommand::Pack { args } => {
411411
let cli_options = self
412412
.cli_options
413413
.as_ref()
414-
.ok_or_else(|| anyhow::anyhow!("CLI options required for lib command"))?;
415-
let resolved = (cli_options.lib)().await?;
414+
.ok_or_else(|| anyhow::anyhow!("CLI options required for pack command"))?;
415+
let resolved = (cli_options.pack)().await?;
416416
let js_path = resolved.bin_path;
417417
let js_path_str = js_path
418418
.to_str()
419-
.ok_or_else(|| anyhow::anyhow!("lib JS path is not valid UTF-8"))?;
419+
.ok_or_else(|| anyhow::anyhow!("pack JS path is not valid UTF-8"))?;
420420

421421
Ok(ResolvedSubcommand {
422422
program: Arc::from(OsStr::new("node")),
@@ -857,7 +857,7 @@ fn print_help() {
857857
{bold}lint{reset} Lint code
858858
{bold}test{reset} Run tests
859859
{bold}fmt{reset} Format code
860-
{bold}lib{reset} Build library
860+
{bold}pack{reset} Build library
861861
{bold}run{reset} Run tasks
862862
{bold}cache{reset} Manage the task cache
863863

packages/cli/binding/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct CliOptions {
3232
pub fmt: Arc<ThreadsafeFunction<(), Promise<JsCommandResolvedResult>>>,
3333
pub vite: Arc<ThreadsafeFunction<(), Promise<JsCommandResolvedResult>>>,
3434
pub test: Arc<ThreadsafeFunction<(), Promise<JsCommandResolvedResult>>>,
35-
pub lib: Arc<ThreadsafeFunction<(), Promise<JsCommandResolvedResult>>>,
35+
pub pack: Arc<ThreadsafeFunction<(), Promise<JsCommandResolvedResult>>>,
3636
pub doc: Arc<ThreadsafeFunction<(), Promise<JsCommandResolvedResult>>>,
3737
pub cwd: Option<String>,
3838
/// CLI arguments (should be process.argv.slice(2) from JavaScript)
@@ -120,7 +120,7 @@ pub async fn run(options: CliOptions) -> Result<i32> {
120120
let fmt_tsf = options.fmt;
121121
let vite_tsf = options.vite;
122122
let test_tsf = options.test;
123-
let lib_tsf = options.lib;
123+
let pack_tsf = options.pack;
124124
let doc_tsf = options.doc;
125125
let resolve_universal_vite_config_tsf = options.resolve_universal_vite_config;
126126
let args = options.args;
@@ -138,7 +138,7 @@ pub async fn run(options: CliOptions) -> Result<i32> {
138138
fmt: create_resolver(fmt_tsf, "Failed to resolve fmt command"),
139139
vite: create_resolver(vite_tsf, "Failed to resolve vite command"),
140140
test: create_resolver(test_tsf, "Failed to resolve test command"),
141-
lib: create_resolver(lib_tsf, "Failed to resolve lib command"),
141+
pack: create_resolver(pack_tsf, "Failed to resolve pack command"),
142142
doc: create_resolver(doc_tsf, "Failed to resolve doc command"),
143143
resolve_universal_vite_config: create_vite_config_resolver(
144144
resolve_universal_vite_config_tsf,

packages/cli/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050
"require": "./binding/index.cjs"
5151
},
5252
"./package.json": "./package.json",
53-
"./lib": {
54-
"types": "./dist/lib.d.ts",
55-
"import": "./dist/lib.js"
53+
"./pack": {
54+
"types": "./dist/pack.d.ts",
55+
"import": "./dist/pack.js"
5656
},
5757
"./test": {
5858
"import": {

packages/cli/snap-tests-todo/command-lib-watch-restart/run-watch.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)