Skip to content

Commit cedae5c

Browse files
Copilotrebornix
andcommitted
Add Node.js version checking and enhanced Copilot setup instructions
Co-authored-by: rebornix <876920+rebornix@users.noreply.github.com>
1 parent 1ec31ab commit cedae5c

6 files changed

Lines changed: 419 additions & 6 deletions

File tree

CONTRIBUTING.md

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,65 @@ Please include the following with each issue:
6767
# Developing
6868

6969
## Requirements
70-
- Node 22.x
70+
- **Node.js 22.14.0 or higher** (see [Node Version](#node-version-management) below)
71+
- **npm 9.0.0 or higher**
7172
- Python >= 3.10, <= 3.12
7273
- Git Large File Storage (LFS) - for running tests
7374
- (Windows) Visual Studio Build Tools >=2019 - for building with node-gyp [see node-gyp docs](https://github.com/nodejs/node-gyp?tab=readme-ov-file#on-windows)
7475

76+
### Node Version Management
77+
78+
This project requires Node.js 22.14.0 or higher. The exact version used by the project is specified in `.nvmrc`.
79+
80+
**Using Node Version Manager (nvm) - Recommended:**
81+
```bash
82+
# Install and use the correct Node.js version
83+
nvm install 22.15.1
84+
nvm use 22.15.1
85+
86+
# Verify version
87+
node --version # should show v22.15.1 or higher
88+
```
89+
90+
**Manual Installation:**
91+
Download Node.js 22.x from [nodejs.org](https://nodejs.org/) if you prefer not to use nvm.
92+
93+
### Copilot Agent Environment Setup
94+
95+
This extension works with GitHub Copilot agents and requires proper authentication and environment configuration. Follow these steps for agent environment customization:
96+
97+
1. **GitHub Authentication**: Ensure you have access to GitHub Copilot
98+
2. **Development Token**: Run `npm run get_token` to set up your development OAuth token
99+
3. **Environment Variables**: Run `npm run get_env` to configure additional secrets (for Microsoft team members)
100+
101+
For more details on customizing the Copilot agent environment, see the [GitHub Copilot documentation](https://docs.github.com/en/copilot/how-tos/use-copilot-agents/coding-agent/customize-the-agent-environment).
102+
75103
### First-time setup
76-
- on Windows you need to run `Set-ExecutionPolicy Unrestricted` as admin in Powershell.
77-
- `npm install`
78-
- `npm run get_token`
79-
- Then you can run the build task with `cmd+shift+B`, or just start the "Launch Copilot Extension - Watch Mode" launch config to start the build then start debugging the extension.
104+
1. **Check Prerequisites**: Verify your development environment meets the requirements
105+
```bash
106+
# Check Node.js and npm versions
107+
npm run check-env
108+
```
109+
110+
2. **Windows Setup**: On Windows, run `Set-ExecutionPolicy Unrestricted` as admin in Powershell.
111+
112+
3. **Install Dependencies**:
113+
```bash
114+
npm install
115+
```
116+
117+
4. **Authentication Setup**:
118+
```bash
119+
# Set up GitHub OAuth token for development
120+
npm run get_token
121+
122+
# (Microsoft team members only) Set up additional environment variables
123+
npm run get_env
124+
```
125+
126+
5. **Start Development**:
127+
- Use VS Code's build task: `Ctrl+Shift+P` → "Tasks: Run Build Task"
128+
- Or start the "Launch Copilot Extension - Watch Mode" launch config to build and debug the extension
80129

81130
**Tip:** If "Launch Copilot Extension - Watch Mode" doesn't work for you, try using the "Launch Copilot Extension" debug configuration instead.
82131

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,33 @@ To get the latest security fixes, please use the latest version of the Copilot e
6868
* **[FAQ](https://code.visualstudio.com/docs/copilot/faq)**
6969
* **[Feedback](https://github.com/microsoft/vscode-copilot-release/issues)**: We'd love to get your help in making GitHub Copilot better!
7070

71+
## Development Setup
72+
73+
Interested in contributing to the GitHub Copilot Chat extension? Get started with development:
74+
75+
### Prerequisites
76+
- **Node.js 22.14.0+**: Required for building and running the extension
77+
- **GitHub Copilot Access**: Needed for testing and development
78+
- **Git LFS**: Required for accessing test fixtures and large files
79+
80+
### Quick Start
81+
```bash
82+
# Check your development environment
83+
npm run check-env
84+
85+
# Install dependencies and set up authentication
86+
npm run setup
87+
88+
# Start development in VS Code
89+
# Use "Launch Copilot Extension - Watch Mode" debug configuration
90+
```
91+
92+
### Detailed Instructions
93+
For comprehensive setup instructions, development guidelines, and contribution information, see [CONTRIBUTING.md](CONTRIBUTING.md).
94+
95+
### Customizing the Agent Environment
96+
Learn about customizing GitHub Copilot agents for your development workflow in the [GitHub documentation](https://docs.github.com/en/copilot/how-tos/use-copilot-agents/coding-agent/customize-the-agent-environment).
97+
7198
## Data and telemetry
7299

73100
The GitHub Copilot Extension for Visual Studio Code collects usage data and sends it to Microsoft to help improve our products and services. Read our [privacy statement](https://privacy.microsoft.com/privacystatement) to learn more. This extension respects the `telemetry.telemetryLevel` setting which you can learn more about at https://code.visualstudio.com/docs/supporting/faq#_how-to-disable-telemetry-reporting.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3936,6 +3936,7 @@
39363936
"singleQuote": true
39373937
},
39383938
"scripts": {
3939+
"check-env": "node ./script/setup/checkNodeVersion.js",
39393940
"postinstall": "tsx ./script/postinstall.ts",
39403941
"prepare": "husky",
39413942
"vscode-dts:dev": "node node_modules/@vscode/dts/index.js dev && mv vscode.proposed.*.ts src/extension",
@@ -3965,7 +3966,7 @@
39653966
"simulate-ci": "node dist/simulationMain.js --ci --require-cache",
39663967
"simulate-update-baseline": "node dist/simulationMain.js --update-baseline",
39673968
"simulate-gc": "node dist/simulationMain.js --require-cache --gc",
3968-
"setup": "npm run get_env && npm run get_token",
3969+
"setup": "npm run check-env && npm run get_env && npm run get_token",
39693970
"setup:dotnet": "run-script-os",
39703971
"setup:dotnet:darwin:linux": "curl -O https://raw.githubusercontent.com/dotnet/install-scripts/main/src/dotnet-install.sh && chmod u+x dotnet-install.sh && ./dotnet-install.sh --channel 10.0 && rm dotnet-install.sh",
39713972
"setup:dotnet:win32": "powershell.exe -NoProfile -ExecutionPolicy Bypass -Command \"Invoke-WebRequest -Uri https://raw.githubusercontent.com/dotnet/install-scripts/main/src/dotnet-install.ps1 -OutFile dotnet-install.ps1; ./dotnet-install.ps1 -channel 10.0; Remove-Item dotnet-install.ps1\"",

script/postinstall.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,46 @@
66
import { downloadZMQ } from '@vscode/zeromq';
77
import * as fs from 'fs';
88
import * as path from 'path';
9+
import { execSync } from 'child_process';
910
import { compressTikToken } from './build/compressTikToken';
1011
import { copyStaticAssets } from './build/copyStaticAssets';
1112

13+
// Check Node.js version before proceeding
14+
function checkNodeVersion(): void {
15+
const packageJsonPath = path.join(__dirname, 'package.json');
16+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
17+
18+
const requiredNodeVersion = packageJson.engines?.node;
19+
if (!requiredNodeVersion) {
20+
return;
21+
}
22+
23+
const currentNodeVersion = process.version;
24+
const currentVersion = currentNodeVersion.slice(1);
25+
26+
const requiredMatch = requiredNodeVersion.match(/>=(\d+)\.(\d+)\.(\d+)/);
27+
if (!requiredMatch) {
28+
return;
29+
}
30+
31+
const [, reqMajor, reqMinor, reqPatch] = requiredMatch.map(Number);
32+
const [currentMajor, currentMinor, currentPatch] = currentVersion.split('.').map(Number);
33+
34+
const isVersionValid =
35+
currentMajor > reqMajor ||
36+
(currentMajor === reqMajor && currentMinor > reqMinor) ||
37+
(currentMajor === reqMajor && currentMinor === reqMinor && currentPatch >= reqPatch);
38+
39+
if (!isVersionValid) {
40+
console.error('\n❌ Node.js version requirement not met!');
41+
console.error(`Required: ${requiredNodeVersion}`);
42+
console.error(`Current: ${currentNodeVersion}`);
43+
console.error('\nPlease upgrade your Node.js version.');
44+
console.error('Run: npm run check-env for detailed instructions.');
45+
process.exit(1);
46+
}
47+
}
48+
1249
export interface ITreeSitterGrammar {
1350
name: string;
1451
/**
@@ -63,6 +100,9 @@ const treeSitterGrammars: ITreeSitterGrammar[] = [
63100
const REPO_ROOT = path.join(__dirname, '..');
64101

65102
async function main() {
103+
// Check Node.js version before starting
104+
checkNodeVersion();
105+
66106
await fs.promises.mkdir(path.join(REPO_ROOT, '.build'), { recursive: true });
67107

68108
const vendoredTiktokenFiles = ['src/platform/tokenizer/node/cl100k_base.tiktoken', 'src/platform/tokenizer/node/o200k_base.tiktoken'];

script/setup/checkNodeVersion.js

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
const fs = require('fs');
7+
const path = require('path');
8+
const { execSync } = require('child_process');
9+
10+
/**
11+
* Check if the current Node.js version meets the project requirements
12+
*/
13+
function checkNodeVersion() {
14+
const packageJsonPath = path.join(__dirname, '../../package.json');
15+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
16+
17+
const requiredNodeVersion = packageJson.engines?.node;
18+
if (!requiredNodeVersion) {
19+
console.log('No Node.js version requirement found in package.json');
20+
return;
21+
}
22+
23+
const currentNodeVersion = process.version;
24+
console.log(`Current Node.js version: ${currentNodeVersion}`);
25+
console.log(`Required Node.js version: ${requiredNodeVersion}`);
26+
27+
// Extract version number (remove 'v' prefix)
28+
const currentVersion = currentNodeVersion.slice(1);
29+
30+
// Simple version check for >=22.14.0 format
31+
const requiredMatch = requiredNodeVersion.match(/>=(\d+)\.(\d+)\.(\d+)/);
32+
if (!requiredMatch) {
33+
console.warn('Could not parse required Node.js version format');
34+
return;
35+
}
36+
37+
const [, reqMajor, reqMinor, reqPatch] = requiredMatch.map(Number);
38+
const [currentMajor, currentMinor, currentPatch] = currentVersion.split('.').map(Number);
39+
40+
const isVersionValid =
41+
currentMajor > reqMajor ||
42+
(currentMajor === reqMajor && currentMinor > reqMinor) ||
43+
(currentMajor === reqMajor && currentMinor === reqMinor && currentPatch >= reqPatch);
44+
45+
if (!isVersionValid) {
46+
console.error('\n❌ Node.js version requirement not met!');
47+
console.error(`Required: ${requiredNodeVersion}`);
48+
console.error(`Current: ${currentNodeVersion}`);
49+
console.error('\nPlease upgrade your Node.js version to continue.');
50+
console.error('\n📋 Installation Options:');
51+
console.error('\n1. Using Node Version Manager (nvm) - Recommended:');
52+
console.error(' nvm install 22.15.1');
53+
console.error(' nvm use 22.15.1');
54+
console.error('\n2. Manual installation:');
55+
console.error(' Download from: https://nodejs.org/');
56+
console.error(' Install Node.js 22.x or higher');
57+
console.error('\n3. Using package managers:');
58+
console.error(' # Using Homebrew (macOS)');
59+
console.error(' brew install node@22');
60+
console.error(' # Using winget (Windows)');
61+
console.error(' winget install OpenJS.NodeJS');
62+
console.error('\nAfter installation, restart your terminal and try again.');
63+
process.exit(1);
64+
}
65+
66+
console.log('✅ Node.js version requirement satisfied');
67+
}
68+
69+
/**
70+
* Check if the current npm version meets the project requirements
71+
*/
72+
function checkNpmVersion() {
73+
const packageJsonPath = path.join(__dirname, '../../package.json');
74+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
75+
76+
const requiredNpmVersion = packageJson.engines?.npm;
77+
if (!requiredNpmVersion) {
78+
return;
79+
}
80+
81+
try {
82+
const currentNpmVersion = execSync('npm --version', { encoding: 'utf8' }).trim();
83+
console.log(`Current npm version: ${currentNpmVersion}`);
84+
console.log(`Required npm version: ${requiredNpmVersion}`);
85+
86+
// Simple check for >=9.0.0 format
87+
const requiredMatch = requiredNpmVersion.match(/>=(\d+)\.(\d+)\.(\d+)/);
88+
if (!requiredMatch) {
89+
console.warn('Could not parse required npm version format');
90+
return;
91+
}
92+
93+
const [, reqMajor] = requiredMatch.map(Number);
94+
const [currentMajor] = currentNpmVersion.split('.').map(Number);
95+
96+
if (currentMajor >= reqMajor) {
97+
console.log('✅ npm version requirement satisfied');
98+
} else {
99+
console.warn('⚠️ npm version may be outdated');
100+
console.warn(`Consider upgrading npm: npm install -g npm@latest`);
101+
}
102+
} catch (error) {
103+
console.warn('Could not check npm version');
104+
}
105+
}
106+
107+
/**
108+
* Check for GitHub Copilot setup prerequisites
109+
*/
110+
function checkCopilotPrerequisites() {
111+
console.log('\n🤖 GitHub Copilot Development Setup:');
112+
113+
// Check if .env file exists (for tokens)
114+
const envPath = path.join(__dirname, '../../.env');
115+
if (fs.existsSync(envPath)) {
116+
console.log('✅ .env file found (authentication tokens configured)');
117+
} else {
118+
console.log('⚠️ .env file not found');
119+
console.log(' Run: npm run get_token # to set up GitHub OAuth token');
120+
console.log(' Run: npm run get_env # (Microsoft team members only)');
121+
}
122+
123+
// Check for Git LFS
124+
try {
125+
execSync('git lfs version', { stdio: 'pipe' });
126+
console.log('✅ Git LFS is installed');
127+
} catch (error) {
128+
console.log('❌ Git LFS not found');
129+
console.log(' Install from: https://git-lfs.com/');
130+
console.log(' Or use package manager: brew install git-lfs / winget install GitHub.GitLFS');
131+
}
132+
133+
console.log('\n📚 Next Steps:');
134+
console.log('1. Sign up for GitHub Copilot: https://github.com/settings/copilot');
135+
console.log('2. Read setup guide: https://docs.github.com/en/copilot/how-tos/use-copilot-agents/coding-agent/customize-the-agent-environment');
136+
console.log('3. Run: npm run setup # to complete authentication setup');
137+
console.log('4. Start debugging in VS Code with "Launch Copilot Extension - Watch Mode"');
138+
}
139+
140+
function main() {
141+
console.log('🔍 Checking development environment requirements...\n');
142+
checkNodeVersion();
143+
checkNpmVersion();
144+
checkCopilotPrerequisites();
145+
console.log('\n✅ Environment check complete!');
146+
}
147+
148+
main();

0 commit comments

Comments
 (0)