Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ vite_glob = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "6f
vite_install = { path = "crates/vite_install" }
vite_migration = { path = "crates/vite_migration" }
vite_shared = { path = "crates/vite_shared" }
vite_static_config = { path = "crates/vite_static_config" }
vite_path = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "6fdc4f106563491be4fb36381b84c5937d74fe9c" }
vite_str = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "6fdc4f106563491be4fb36381b84c5937d74fe9c" }
vite_task = { git = "ssh://git@github.com/voidzero-dev/vite-task.git", rev = "6fdc4f106563491be4fb36381b84c5937d74fe9c" }
Expand All @@ -211,7 +212,10 @@ oxc = { version = "0.115.0", features = [
"cfg",
] }
oxc_allocator = { version = "0.115.0", features = ["pool"] }
oxc_ast = "0.115.0"
oxc_ecmascript = "0.115.0"
oxc_parser = "0.115.0"
oxc_span = "0.115.0"
oxc_napi = "0.115.0"
oxc_minify_napi = "0.115.0"
oxc_parser_napi = "0.115.0"
Expand Down
23 changes: 23 additions & 0 deletions crates/vite_static_config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "vite_static_config"
version = "0.0.0"
authors.workspace = true
edition.workspace = true
homepage.workspace = true
license.workspace = true
repository.workspace = true

[dependencies]
oxc_allocator = { workspace = true }
oxc_ast = { workspace = true }
oxc_parser = { workspace = true }
oxc_span = { workspace = true }
rustc-hash = { workspace = true }
serde_json = { workspace = true }
vite_path = { workspace = true }

[dev-dependencies]
tempfile = { workspace = true }

[lints]
workspace = true
58 changes: 58 additions & 0 deletions crates/vite_static_config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# vite_static_config

Statically extracts configuration from `vite.config.*` files without executing JavaScript.

## What it does

Parses vite config files using [oxc_parser](https://crates.io/crates/oxc_parser) and extracts
top-level fields whose values are pure JSON literals. This allows reading config like `run`
without needing a Node.js runtime (NAPI).

## Supported patterns

**ESM:**

```js
export default { run: { tasks: { build: { command: "echo build" } } } }
export default defineConfig({ run: { cacheScripts: true } })
```

**CJS:**

```js
module.exports = { run: { tasks: { build: { command: 'echo build' } } } };
module.exports = defineConfig({ run: { cacheScripts: true } });
```

## Config file resolution

Searches for config files in the same order as Vite's
[`DEFAULT_CONFIG_FILES`](https://github.com/vitejs/vite/blob/25227bbdc7de0ed07cf7bdc9a1a733e3a9a132bc/packages/vite/src/node/constants.ts#L98-L105):

1. `vite.config.js`
2. `vite.config.mjs`
3. `vite.config.ts`
4. `vite.config.cjs`
5. `vite.config.mts`
6. `vite.config.cts`

## Return type

`resolve_static_config` returns `Option<FxHashMap<Box<str>, FieldValue>>`:

- **`None`** — config is not statically analyzable (no config file, parse error, no
`export default`/`module.exports`, or the exported value is not an object literal).
Caller should fall back to runtime evaluation (e.g. NAPI).
- **`Some(map)`** — config object was successfully located:
- `FieldValue::Json(value)` — field value extracted as pure JSON
- `FieldValue::NonStatic` — field exists but contains non-JSON expressions
(function calls, variables, template literals with interpolation, etc.)
- Key absent — field does not exist in the config object

## Limitations

- Only extracts values that are pure JSON literals (strings, numbers, booleans, null,
arrays, and objects composed of these)
- Fields with dynamic values (function calls, variable references, spread operators,
computed properties, template literals with expressions) are reported as `NonStatic`
- Does not follow imports or evaluate expressions
Loading
Loading