Skip to content

Add INIT_CWD environment variable support#194

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/fix-74
Closed

Add INIT_CWD environment variable support#194
Copilot wants to merge 2 commits intomainfrom
copilot/fix-74

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 23, 2025

Implements the INIT_CWD environment variable following npm's specification, which holds the full path where vite-plus was invoked.

Background

As documented in the npm CLI docs:

Scripts are run from the root of the package folder, regardless of what the current working directory is when npm is invoked. If you want your script to use different behavior based on what subdirectory you're in, you can use the INIT_CWD environment variable, which holds the full path you were in when you ran npm run.

This enables scripts to determine the original invocation context and adapt their behavior accordingly.

Implementation

The implementation follows existing patterns in the codebase:

  • Static Variable: Uses LazyLock<Mutex<Option<AbsolutePathBuf>>> consistent with CURRENT_EXECUTION_ID
  • Automatic Injection: Added to DEFAULT_PASSTHROUGH_ENVS for automatic availability in all tasks
  • Thread-Safe: Proper synchronization for concurrent task execution
  • Zero Configuration: Works automatically without any setup required

Usage Example

# From workspace root
$ cd /path/to/workspace && vite run build
# Inside task: INIT_CWD=/path/to/workspace

# From subdirectory
$ cd /path/to/workspace/packages/app && vite run build  
# Inside task: INIT_CWD=/path/to/workspace/packages/app

Tasks can now use $INIT_CWD to access the original invocation directory, enabling context-aware script behavior.

Testing

  • Added comprehensive unit test test_init_cwd_environment_variable
  • Verified integration with real workspace scenarios
  • All existing tests pass, ensuring no regressions

Fixes #74.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: fengmk2 <156269+fengmk2@users.noreply.github.com>
Copilot AI changed the title [WIP] add INIT_CWD environment variable Add INIT_CWD environment variable support Sep 23, 2025
Copilot AI requested a review from fengmk2 September 23, 2025 07:53
@fengmk2 fengmk2 closed this Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add INIT_CWD environment variable

2 participants