Fix Windows agent harness links in postinstall (#304392)

* Fix Windows agent harness links in postinstall

* Update build/npm/postinstall.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Benjamin Christopher Simmonds
2026-03-24 09:57:28 +01:00
committed by GitHub
parent 7674c073de
commit bb77888173

View File

@@ -182,6 +182,32 @@ function clearInheritedNpmrcConfig(dir: string, env: NodeJS.ProcessEnv): void {
}
}
function ensureAgentHarnessLink(sourceRelativePath: string, linkPath: string): 'existing' | 'junction' | 'symlink' | 'hard link' {
if (fs.existsSync(linkPath)) {
return 'existing';
}
const sourcePath = path.resolve(path.dirname(linkPath), sourceRelativePath);
const isDirectory = fs.statSync(sourcePath).isDirectory();
try {
if (process.platform === 'win32' && isDirectory) {
fs.symlinkSync(sourcePath, linkPath, 'junction');
return 'junction';
}
fs.symlinkSync(sourceRelativePath, linkPath, isDirectory ? 'dir' : 'file');
return 'symlink';
} catch (error) {
if (process.platform === 'win32' && !isDirectory && (error as NodeJS.ErrnoException).code === 'EPERM') {
fs.linkSync(sourcePath, linkPath);
return 'hard link';
}
throw error;
}
}
async function runWithConcurrency(tasks: (() => Promise<void>)[], concurrency: number): Promise<void> {
const errors: Error[] = [];
let index = 0;
@@ -294,15 +320,15 @@ async function main() {
fs.mkdirSync(claudeDir, { recursive: true });
const claudeMdLink = path.join(claudeDir, 'CLAUDE.md');
if (!fs.existsSync(claudeMdLink)) {
fs.symlinkSync(path.join('..', '.github', 'copilot-instructions.md'), claudeMdLink);
log('.', 'Symlinked .claude/CLAUDE.md -> .github/copilot-instructions.md');
const claudeMdLinkType = ensureAgentHarnessLink(path.join('..', '.github', 'copilot-instructions.md'), claudeMdLink);
if (claudeMdLinkType !== 'existing') {
log('.', `Created ${claudeMdLinkType} .claude/CLAUDE.md -> .github/copilot-instructions.md`);
}
const claudeSkillsLink = path.join(claudeDir, 'skills');
if (!fs.existsSync(claudeSkillsLink)) {
fs.symlinkSync(path.join('..', '.agents', 'skills'), claudeSkillsLink);
log('.', 'Symlinked .claude/skills -> .agents/skills');
const claudeSkillsLinkType = ensureAgentHarnessLink(path.join('..', '.agents', 'skills'), claudeSkillsLink);
if (claudeSkillsLinkType !== 'existing') {
log('.', `Created ${claudeSkillsLinkType} .claude/skills -> .agents/skills`);
}
// Temporary: patch @github/copilot-sdk session.js to fix ESM import