diff --git a/crates/vite_task/src/session/mod.rs b/crates/vite_task/src/session/mod.rs index d3cbab86..420ac9a6 100644 --- a/crates/vite_task/src/session/mod.rs +++ b/crates/vite_task/src/session/mod.rs @@ -235,6 +235,8 @@ impl<'a> Session<'a> { // different schema versions don't share (and corrupt) one database. let cache_path = cache_root.join(cache::cache_schema_dir_name().as_str()); + envs.insert(Arc::from(OsStr::new("INIT_CWD")), Arc::from(cwd.as_path().as_os_str())); + // Prepend workspace's node_modules/.bin to PATH let workspace_node_modules_bin = workspace_root.path.join("node_modules").join(".bin"); prepend_path_env(&mut envs, &workspace_node_modules_bin)?; diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/package.json b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/package.json new file mode 100644 index 00000000..3f244a50 --- /dev/null +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/package.json @@ -0,0 +1,7 @@ +{ + "name": "init-cwd-test", + "private": true, + "workspaces": [ + "packages/*" + ] +} diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/packages/app/package.json b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/packages/app/package.json new file mode 100644 index 00000000..0a2d4152 --- /dev/null +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/packages/app/package.json @@ -0,0 +1,4 @@ +{ + "name": "app", + "private": true +} diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/packages/app/src/.gitkeep b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/packages/app/src/.gitkeep new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/packages/app/src/.gitkeep @@ -0,0 +1 @@ + diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/packages/app/vite-task.json b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/packages/app/vite-task.json new file mode 100644 index 00000000..d7455fe1 --- /dev/null +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/packages/app/vite-task.json @@ -0,0 +1,8 @@ +{ + "tasks": { + "print-init-cwd": { + "command": "vtt print-env INIT_CWD", + "cache": true + } + } +} diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/pnpm-workspace.yaml b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/pnpm-workspace.yaml new file mode 100644 index 00000000..924b55f4 --- /dev/null +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +packages: + - packages/* diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/snapshots.toml b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/snapshots.toml new file mode 100644 index 00000000..fd78cca5 --- /dev/null +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/snapshots.toml @@ -0,0 +1,7 @@ +[[e2e]] +name = "init_cwd_points_to_invocation_cwd" +comment = """ +Tasks run from their package directory, but INIT_CWD should point to the directory where vt was invoked. +""" +cwd = "packages/app/src" +steps = [["vt", "run", "print-init-cwd"]] diff --git a/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/snapshots/init_cwd_points_to_invocation_cwd.md b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/snapshots/init_cwd_points_to_invocation_cwd.md new file mode 100644 index 00000000..b1111093 --- /dev/null +++ b/crates/vite_task_bin/tests/e2e_snapshots/fixtures/init_cwd/snapshots/init_cwd_points_to_invocation_cwd.md @@ -0,0 +1,10 @@ +# init_cwd_points_to_invocation_cwd + +Tasks run from their package directory, but INIT_CWD should point to the directory where vt was invoked. + +## `vt run print-init-cwd` + +``` +~/packages/app$ vtt print-env INIT_CWD +/packages/app/src +``` diff --git a/crates/vite_task_graph/src/config/mod.rs b/crates/vite_task_graph/src/config/mod.rs index 61358ec5..a2a12bfa 100644 --- a/crates/vite_task_graph/src/config/mod.rs +++ b/crates/vite_task_graph/src/config/mod.rs @@ -411,6 +411,7 @@ pub const DEFAULT_UNTRACKED_ENV: &[&str] = &[ // CI/CD environments "CI", // Node.js specific + "INIT_CWD", "NODE_OPTIONS", "COREPACK_*", "NPM_CONFIG_STORE_DIR",