pkg
Copilot instructions930 starsChanged 6 months agoMITView on GitHub
This is a TypeScript-based Node.js project that packages Node.js applications into standalone executables. The project is maintained by the yao-pkg organization and is a fork of the original vercel/pkg project. IMPORTANT: This repository is yao-pkg/pkg, a fork of the original vercel/pkg (which is ARCHIVED and read-only). pkg is a command-line tool that: Before running tests or making changes, always build the project: This compiles TypeScript from lib/ to lib-es5/ using the TypeScript compiler. For continuous development with auto-rebuild: CRITICAL: Follow…
- Commits and pushes
We split this copilot-instructions.md into the rules it gives an agent
48 rules. About 1 is common, 23 are distinctive, and 24 are very specific to this project.
≈1
Common · estimate
Many files like this have a rule of this kind.
≈23
Distinctive · estimate
This author's own choices. Worth a look.
24
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 11
When using gh pr create, always specify the correct repository
- Distinctive: line 40
Before running tests or making changes, always build the project:
- Very specific: line 58
Run yarn lint to check both code style and ESLint rules
- Very specific: line 59
Run yarn fix to automatically fix formatting and linting issues
- Distinctive: line 60
All changes must pass CI checks (linting, building, and tests)
- Distinctive: line 66
Clean test artifacts: Remove any test-generated output files (executables, binaries) before staging changes
- Very specific: line 67
Test artifacts typically include: *.exe, *-linux, *-macos, *-win.exe in test directories
- Distinctive: line 68
Check staged files with git status and remove any test outputs
- Very specific: line 72
ALWAYS run yarn lint before committing
- Common: line 74
NEVER commit or push with lint errors present
- Distinctive: line 79
Wait for explicit user approval before running git commit and git push
- Distinctive: line 80
Do NOT commit or push without user confirmation
- Very specific: line 83
Use: feat:, fix:, refactor:, test:, chore:, docs:
- Very specific: line 92
Run yarn lint:style to check formatting
- Very specific: line 99
Run yarn lint:code to check for linting issues
- Distinctive: line 143
When adding new tests:
- Very specific: line 145
Create a directory named test-XX-descriptive-name/
- Very specific: line 146
Create a main.js file that uses the test utilities
- Very specific: line 147
Use utils.pkg.sync() to invoke pkg within the test
- Distinctive: line 148
Verify output files are created correctly
- Very specific: line 171
Source files: All TypeScript files should be in lib/ directory
- Very specific: line 172
No direct editing: Never edit files in lib-es5/ directly
- Distinctive: line 183
Runtime dependencies: Keep minimal, as they affect all packaged apps
- Distinctive: line 186
Always use exact or caret ranges for dependencies
- Distinctive: line 206
Follow conventional commits format:
- Very specific: line 220
Use __dirname or __filename for files packaged in the snapshot
- Very specific: line 221
Use process.cwd() for runtime filesystem access
- Very specific: line 227
Must match the Node.js version specified in --target
- Very specific: line 229
Add .node files to assets if not detected automatically
- Very specific: line 234
Use --no-bytecode to disable bytecode compilation for cross-arch builds
- Distinctive: line 235
Consider using QEMU for emulation on Linux
- Distinctive: line 242
Check existing dictionary files for examples
- Distinctive: line 246
Read existing code: Look at similar functionality before implementing new features
- Distinctive: line 247
Add tests: Every new feature or bug fix should include a test
- Very specific: line 248
Update documentation: Update the docs site (docs-site/) as needed — guides live under docs-site/guide/, development notes in …
- Distinctive: line 249
Check CI: Ensure all CI checks pass before requesting review
- Distinctive: line 250
Small PRs: Keep pull requests focused and reasonably sized
- Distinctive: line 252
Test cross-platform: Test on Linux, macOS, and Windows when possible
- Very specific: line 266
Use codesign or ldid for signing
- Very specific: line 272
Consider post-processing with resedit for custom metadata
- Distinctive: line 286
Discussions: Use GitHub Discussions for questions
- Distinctive: line 295
NEVER commit without user approval: Always show changes with git status --short, present a summary, and wait for explicit user confirmation …
- Very specific: line 296
ALWAYS check lint before committing: Run yarn lint before every commit and fix all issues - NEVER commit with lint errors
- Very specific: line 297
Clean test artifacts before staging: Remove any test-generated executables (*.exe, *-linux, *-macos, *-win.exe) from test directories …
- Very specific: line 298
Always build before testing: Run yarn build before running any tests
- Distinctive: line 302
Maintain test numbering: When adding tests, choose appropriate test number (XX in test-XX-name)
- Distinctive: line 303
Check existing dictionary files: Before adding new package support, review existing dictionary files for patterns
- Distinctive: line 305
Cross-platform testing: When possible, verify changes work on Linux, macOS, and Windows
≈ “Common” is an estimate: at least 1 in 5 of the 3,669 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
GitHub Copilot Instructions for pkg
This is a TypeScript-based Node.js project that packages Node.js applications into standalone executables. The project is maintained by the yao-pkg organization and is a fork of the original vercel/pkg project.
CRITICAL: Repository and PR Guidelines
IMPORTANT: This repository is yao-pkg/pkg, a fork of the original vercel/pkg (which is ARCHIVED and read-only).
- ✅ ALWAYS create PRs against
yao-pkg/pkg(this fork) - ❌ NEVER create PRs against
vercel/pkg(the upstream is archived and cannot accept PRs) - When using
gh pr create, always specify the correct repository - The upstream
vercel/pkgshould be completely ignored for PR creation purposes
Project Overview
pkg is a command-line tool that:
- Packages Node.js projects into executables for multiple platforms (Linux, macOS, Windows)
- Supports multiple Node.js versions (node20, node22, etc.)
- Uses virtual filesystem to bundle application files
- Compiles JavaScript to V8 bytecode for distribution
- Supports native addons (.node files)
- Provides compression options (Brotli, GZip)
Repository Structure
lib/: TypeScript source code for the main packaging logiclib-es5/: Compiled JavaScript output (generated, do not edit directly)prelude/: Bootstrap code injected into packaged executablesdictionary/: Package-specific configuration files for known npm packagestest/: Comprehensive test suite with numbered test directoriesexamples/: Example projects demonstrating pkg usageplans/: Implementation plans and design documents.github/workflows/: CI/CD configuration using GitHub Actions
Development Workflow
Building
Before running tests or making changes, always build the project:
yarn buildThis compiles TypeScript from lib/ to lib-es5/ using the TypeScript compiler.
For continuous development with auto-rebuild:
yarn startCode Standards
Required Before Each Commit
- Run
yarn lintto check both code style and ESLint rules - Run
yarn fixto automatically fix formatting and linting issues - All changes must pass CI checks (linting, building, and tests)
Commit and Push Workflow
CRITICAL: Follow this workflow for ALL commits and pushes:
- Clean test artifacts: Remove any test-generated output files (executables, binaries) before staging changes
- Test artifacts typically include:
*.exe,*-linux,*-macos,*-win.exein test directories - Check staged files with
git statusand remove any test outputs - These files may remain if a test failed before cleanup
- Test artifacts typically include:
- Verify no lint issues:
- ALWAYS run
yarn lintbefore committing - Fix all linting errors with
yarn fixor manually - NEVER commit or push with lint errors present
- ALWAYS run
- Request approval before commit/push:
- Show the user what files will be committed (
git status --short) - Present a summary of changes made
- Wait for explicit user approval before running
git commitandgit push - Do NOT commit or push without user confirmation
- Show the user what files will be committed (
- Commit with conventional commits format:
- Use:
feat:,fix:,refactor:,test:,chore:,docs: - Include detailed commit message explaining changes
- Use:
This workflow ensures code quality, prevents accidental commits of test artifacts, and gives the user control over what gets committed to the repository.
Formatting
- Uses Prettier for code formatting
- Single quotes for strings (configured in package.json)
- Run
yarn lint:styleto check formatting - Format files with:
prettier -w "{lib,prelude,test}/**/*.{ts,js}"
Linting
- Uses ESLint with TypeScript support
- Configuration:
eslint-config-airbnb-typescriptandeslint-config-prettier - Run
yarn lint:codeto check for linting issues - Console statements are disallowed in production code (lint error), but allowed in test files and scripts
Testing
The test suite is extensive and organized in numbered directories:
# Build first (required for e2e)
yarn build
# Fast in-process unit suite (node:test + esbuild-register, ~1s, no build)
yarn test:unit
yarn test:unit:watch
# Run all tests
yarn test
# Run tests for specific Node.js version
yarn test:20 # Test with Node.js 20
yarn test:22 # Test with Node.js 22
yarn test:host # Test with host Node.js version
# Run specific test pattern
node test/test.js node20 no-npm test-50-*
# Coverage (c8; include lib/**, merged unit + e2e into coverage/lcov.info)
yarn coverage:unit
yarn coverage:e2e
yarn coverageTest Organization
test/unit/*.test.ts— in-process unit suite on Node's built-innode:testrunner. Importslib/*.tsdirectly viaesbuild-register(no build required).test/test-XX-*/main.js— e2e suite: each directory spawns the pkg CLI and asserts on produced binaries. XX indicates execution order.- Tests use
utils.jsfor common testing utilities. - Special tests:
test-79-npm/: Tests integration with popular npm packages (only-npm)test-42-fetch-all/: Verifies patches exist for all Node.js versionstest-46-multi-arch/: Tests cross-compilation for multiple architectures
Writing Tests
When adding new tests:
- Create a directory named
test-XX-descriptive-name/ - Create a
main.jsfile that uses the test utilities - Use
utils.pkg.sync()to invoke pkg within the test - Verify output files are created correctly
- Clean up using
utils.filesAfter()
Example test structure:
#!/usr/bin/env node
'use strict';
const assert = require('assert');
const utils = require('../utils.js');
assert(!module.parent);
assert(__dirname === process.cwd());
// Test implementation hereTypeScript Guidelines
- Strict mode: The project uses TypeScript strict mode
- Target: ES2017 (check tsconfig.json)
- Module system: CommonJS (not ES modules)
- Type definitions: Include type definitions for all public APIs
- Source files: All TypeScript files should be in
lib/directory - No direct editing: Never edit files in
lib-es5/directly
Key Files and Conventions
lib/index.js: Main entry point for the pkg APIlib/bin.js: CLI entry pointprelude/bootstrap.js: Code injected into every packaged executabledictionary/*.js: Special handling for specific npm packages
Dependencies
- Runtime dependencies: Keep minimal, as they affect all packaged apps
- Native modules: Be aware of
.nodefile handling and extraction - pkg-fetch dependency: Used to download pre-compiled Node.js binaries
- Always use exact or caret ranges for dependencies
Release Process
The project uses release-it with conventional commits:
yarn releaseThis interactive process:
- Runs linting checks
- Generates changelog using conventional commits
- Creates a git tag with format
v${version} - Pushes to GitHub and creates a release
- Publishes to npm under
@yao-pkg/pkg
Commit Message Format
Follow conventional commits format:
feat: description- New featuresfix: description- Bug fixesrefactor: description- Code refactoringtest: description- Test additionschore: description- Maintenance tasksdocs: description- Documentation changes
Common Issues and Gotchas
Virtual Filesystem
- Packaged apps have files at
/snapshot/prefix (orC:\snapshot\on Windows) - Use
__dirnameor__filenamefor files packaged in the snapshot - Use
process.cwd()for runtime filesystem access - Path handling differs between packaged and non-packaged execution
Native Addons
- Native addons are extracted to
$HOME/.cache/pkg/at runtime - Must match the Node.js version specified in
--target linuxstatictarget cannot load native bindings- Add
.nodefiles toassetsif not detected automatically
Cross-Compilation
- Bytecode generation requires running target architecture binary
- Use
--no-bytecodeto disable bytecode compilation for cross-arch builds - Consider using QEMU for emulation on Linux
- macOS arm64 can build x64 using Rosetta 2
ESM Support
- ESM modules require
--options experimental-require-module(Node.js < 22.12.0) - Some packages may need special handling in dictionary files
- Check existing dictionary files for examples
Best Practices for Contributing
- Read existing code: Look at similar functionality before implementing new features
- Add tests: Every new feature or bug fix should include a test
- Update documentation: Update the docs site (
docs-site/) as needed — guides live underdocs-site/guide/, development notes indocs-site/development.md, architecture indocs-site/architecture.md - Check CI: Ensure all CI checks pass before requesting review
- Small PRs: Keep pull requests focused and reasonably sized
- Follow patterns: Match existing code style and patterns
- Test cross-platform: Test on Linux, macOS, and Windows when possible
Platform-Specific Considerations
Linux
- Supports both dynamic and static linking
linuxstatictarget for maximum portability- Configure binfmt with QEMU for cross-arch testing
macOS
arm64support is experimental- Code signing required for arm64 binaries
- Use
codesignorldidfor signing
Windows
.exeextension required- Native modules must match target architecture
- Consider post-processing with
reseditfor custom metadata
CI/CD
The project uses GitHub Actions workflows:
- ci.yml: Runs linting and builds on multiple Node.js versions and OS platforms
- test.yml: Reusable workflow for running tests
- Matrix strategy tests: Node.js 20.x, 22.x on ubuntu-latest, windows-latest, macos-latest
- Linting only runs on ubuntu-latest with Node.js 20.x
Support and Resources
- Issues: Report bugs and feature requests on GitHub
- Discussions: Use GitHub Discussions for questions
- Documentation: See the docs site at https://yao-pkg.github.io/pkg/ (sources in
docs-site/) - Development Guide: See
docs-site/development.md(published at https://yao-pkg.github.io/pkg/development) - Related Projects:
- pkg-fetch - Pre-compiled Node.js binaries
- pkg-binaries - Binaries for unsupported architectures
Important Notes for Copilot Coding Agent
- NEVER commit without user approval: Always show changes with
git status --short, present a summary, and wait for explicit user confirmation before runninggit commitorgit push - ALWAYS check lint before committing: Run
yarn lintbefore every commit and fix all issues - NEVER commit with lint errors - Clean test artifacts before staging: Remove any test-generated executables (
*.exe,*-linux,*-macos,*-win.exe) from test directories before committing - Always build before testing: Run
yarn buildbefore running any tests - Use correct Node.js version: The project requires Node.js >= 20.0.0
- Use Yarn for package management: This project uses
yarn, notnpm, for dependency management - Respect TypeScript compilation: Edit
lib/*.tsfiles, notlib-es5/*.jsfiles - Maintain test numbering: When adding tests, choose appropriate test number (XX in test-XX-name)
- Check existing dictionary files: Before adding new package support, review existing dictionary files for patterns
- Preserve backward compatibility: This tool is widely used; breaking changes need careful consideration
- Cross-platform testing: When possible, verify changes work on Linux, macOS, and Windows
- Native addon handling: Be extra careful with changes affecting native addon loading and extraction
- Snapshot filesystem: Changes to virtual filesystem handling require thorough testing
- Performance matters: Packaging time and executable size are important metrics
- Implementation plans: Store all implementation plans and design documents in the
plans/directory
Git Workflow
- Default branch:
main - Branch protection: Requires passing CI checks
- Tag format:
v${version}(e.g., v6.10.0) - Commit style: Conventional commits for changelog generation
Where files are headingNew Copilot instructions files have more rules about branches and pull requests, and fewer about code style.
Of the Copilot instructions files we read, the 2,297 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository4 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- performances-compareSkill
- pkg-debugSkill
- pkg-xcompile-testSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

