A JS scrip that automatically generates or merges VS Code launch.json debug configurations based on the scripts defined in your package.json.
in package.json. It supports npm, yarn, or pnpm, with optional script name filtering,
timestamped backups, and a single confirmation prompt when overwriting existing entries.
Features:
- Detects and loads scripts from
package.json - Adds one launch configuration per script
- It supports
npm,yarn, orpnpm - Optionally filters scripts by prefix (e.g.,
dev) - Confirmation prompt before overwriting existing launch configurations
- Automatic timestamped backups of existing
.vscode/launch.jsonfile - Command-line options to skip prompts (--yes) and specify package manager and filter
- Skipping scripts containing "generate-launch" anywhere in their names
Place the script in your project under scripts/ folder:
mkdir -p scriptsThen add the script to scripts/generate-launch-config.js.
Run the script with Node.js from your project root:
node scripts/generate-launch-config.jsOr add it to your package.json scripts for convenience:
"scripts": {
"generate-launch": "node scripts/generate-launch-config.js",
"generate-launch:yes": "node scripts/generate-launch-config.js --yes",
"generate-launch:yarn": "node scripts/generate-launch-config.js --manager yarn --yes",
"generate-launch:dev": "node scripts/generate-launch-config.js --filter dev --yes"
}Then run:
npm run generate-launch| Flag | Description |
|---|---|
--manager <npm|yarn|pnpm> |
Specify package manager: npm (default), yarn, or pnpm |
--filter <prefix> |
Only include scripts starting with the given prefix (e.g. dev) |
--yes |
Automatically confirm overwrites (no prompts) |
Generate all launch configs using npm:
node scripts/generate-launch-config.jsOnly include scripts starting with dev::
node scripts/generate-launch-config.js --filter devUse yarn and skip confirmation prompts:
node scripts/generate-launch-config.js --manager yarn --yes- Existing
launch.jsonis backed up to.vscode/launch.backup.YYYY-MM-DDTHH-MM-SS.json - The script will only prompt once to confirm overwriting multiple configs
- Scripts are translated into VS Code launch configurations like:
{
"type": "node",
"request": "launch",
"name": "npm: dev",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "dev"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"skipFiles": ["<node_internals>/**"]
}- Reads your project's
package.jsonand extracts the scripts section. - Filters out any scripts containing
generate-launchin their names. - Optionally filters scripts by prefix if
--filteris specified. - Loads existing
.vscode/launch.jsonand creates a timestamped backup. - Adds launch configurations for all matched scripts.
- Prompts once if any configs will be overwritten (unless
--yesis used). - Saves the merged configurations back to
.vscode/launch.json.
- Node.js installed
- A valid
package.jsonwith scripts - VS Code workspace with a
.vscode/directory (created automatically if missing)
MIT License
Feel free to open issues or submit pull requests if you'd like to improve this script!