Skip to content

Commit 94d66d3

Browse files
committed
fix(cli): write vite lib config from current directory
1 parent c10c45a commit 94d66d3

8 files changed

Lines changed: 97 additions & 2 deletions

File tree

packages/cli/binding/src/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,11 +410,11 @@ pub async fn main<
410410
summary
411411
}
412412
Commands::Lib { args } => {
413-
let workspace = Workspace::partial_load(cwd)?;
413+
let workspace = Workspace::partial_load(cwd.clone())?;
414414
let lib_fn =
415415
options.map(|o| o.lib).expect("lib command requires CliOptions to be provided");
416416
let lib_config_path = workspace.cache_path().join("vite-lib.config.js");
417-
if write_vite_lib_config(&workspace.root_dir(), &lib_config_path).await? {
417+
if write_vite_lib_config(&cwd, &lib_config_path).await? {
418418
args.extend_from_slice(&[
419419
"--config".to_string(),
420420
lib_config_path.as_path().to_string_lossy().into_owned(),
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "command-lib-monorepo",
3+
"version": "1.0.0",
4+
"type": "module",
5+
"workspaces": [
6+
"packages/*"
7+
]
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "hello",
3+
"version": "1.0.0",
4+
"type": "module",
5+
"main": "src/index.ts",
6+
"scripts": {
7+
"build": "vite lib"
8+
}
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function hello() {
2+
console.log('Hello tsdown!');
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { hello } from './hello.ts';
2+
3+
hello();
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
entry: 'src/index.ts',
3+
format: ['esm', 'cjs'],
4+
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
> vite run hello#build # should build the library
2+
~/packages/hello$ vite lib
3+
ℹ tsdown v<semver> powered by rolldown v<semver>
4+
ℹ Using tsdown config: <cwd>/packages/hello/tsdown.config.ts
5+
ℹ entry: src/index.ts
6+
ℹ Build start
7+
ℹ [ESM] dist/index.mjs <variable> kB │ gzip: <variable> kB
8+
ℹ [ESM] 1 files, total: <variable> kB
9+
ℹ [CJS] dist/index.cjs <variable> kB │ gzip: <variable> kB
10+
ℹ [CJS] 1 files, total: <variable> kB
11+
✔ Build complete in <variable>ms
12+
13+
14+
15+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
16+
Vite+ Task Runner • Execution Summary
17+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
18+
19+
Statistics: 1 tasks • 0 cache hits • 1 cache misses
20+
Performance: 0% cache hit rate
21+
22+
Task Details:
23+
────────────────────────────────────────────────
24+
[1] lib: ~/packages/hello$ vite lib ✓
25+
→ Cache miss: no previous cache entry found
26+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
27+
28+
> ls packages/hello/dist # should have the library
29+
index.cjs
30+
index.mjs
31+
32+
> vite run hello#build # should hit cache
33+
~/packages/hello$ vite lib (✓ cache hit, replaying)
34+
ℹ tsdown v<semver> powered by rolldown v<semver>
35+
ℹ Using tsdown config: <cwd>/packages/hello/tsdown.config.ts
36+
ℹ entry: src/index.ts
37+
ℹ Build start
38+
ℹ [ESM] dist/index.mjs <variable> kB │ gzip: <variable> kB
39+
ℹ [ESM] 1 files, total: <variable> kB
40+
ℹ [CJS] dist/index.cjs <variable> kB │ gzip: <variable> kB
41+
ℹ [CJS] 1 files, total: <variable> kB
42+
✔ Build complete in <variable>ms
43+
44+
45+
46+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
47+
Vite+ Task Runner • Execution Summary
48+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
49+
50+
Statistics: 1 tasks • 1 cache hits • 0 cache misses
51+
Performance: 100% cache hit rate, <variable>ms saved in total
52+
53+
Task Details:
54+
────────────────────────────────────────────────
55+
[1] lib: ~/packages/hello$ vite lib ✓
56+
→ Cache hit - output replayed - <variable>ms saved
57+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"ignoredPlatforms": ["win32"],
3+
"env": {
4+
"VITE_DISABLE_AUTO_INSTALL": "1"
5+
},
6+
"commands": [
7+
"vite run hello#build # should build the library",
8+
"ls packages/hello/dist # should have the library",
9+
"vite run hello#build # should hit cache"
10+
]
11+
}

0 commit comments

Comments
 (0)