{"id":30948243,"url":"https://github.com/refinist/distpkg","last_synced_at":"2025-09-11T02:04:47.611Z","repository":{"id":312845912,"uuid":"1040468357","full_name":"refinist/distpkg","owner":"refinist","description":"Post-build tool that generates minimal package.json in dist/ and re-installs deps to ensure bundled code runs correctly","archived":false,"fork":false,"pushed_at":"2025-09-09T13:07:21.000Z","size":217,"stargazers_count":2,"open_issues_count":3,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-09T16:31:30.453Z","etag":null,"topics":["build-tool","bun","bundler","cli","dependencies","deployment","dist","docker","node","package-json","post-build","secondary-install","typescript"],"latest_commit_sha":null,"homepage":"https://npmjs.com/distpkg","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/refinist.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-19T03:07:17.000Z","updated_at":"2025-09-03T07:56:15.000Z","dependencies_parsed_at":"2025-09-02T11:33:20.501Z","dependency_job_id":"452854bd-0f8a-4bed-a931-e9c944902671","html_url":"https://github.com/refinist/distpkg","commit_stats":null,"previous_names":["refinist/distpkg"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/refinist/distpkg","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/refinist%2Fdistpkg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/refinist%2Fdistpkg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/refinist%2Fdistpkg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/refinist%2Fdistpkg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/refinist","download_url":"https://codeload.github.com/refinist/distpkg/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/refinist%2Fdistpkg/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274563672,"owners_count":25308458,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-11T02:00:13.660Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["build-tool","bun","bundler","cli","dependencies","deployment","dist","docker","node","package-json","post-build","secondary-install","typescript"],"created_at":"2025-09-11T02:02:20.396Z","updated_at":"2025-09-11T02:04:47.605Z","avatar_url":"https://github.com/refinist.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003edistpkg\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\u003ca href=\"./README.zh-CN.md\" target=\"_blank\"\u003e中文文档\u003c/a\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://npmjs.com/package/distpkg\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/distpkg.svg?colorA=f9f0e1\u0026colorB=000000\" /\u003e\u003c/a\u003e \u003ca href=\"https://github.com/refinist/distpkg/actions/workflows/unit-test.yml\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/refinist/distpkg/unit-test.yml?colorA=f9f0e1\u0026colorB=000000\u0026label=Unit%20Test\" /\u003e\u003c/a\u003e \u003ca href=\"https://codecov.io/github/refinist/distpkg\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/codecov/c/github/refinist/distpkg?colorA=f9f0e1\u0026colorB=000000\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://deepwiki.com/refinist/distpkg\" target=\"_blank\"\u003e\u003cimg src=\"https://deepwiki.com/badge.svg\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nA tool for post-build projects (generally used after bundling into a single file with \u003cimg src=\"https://github.com/user-attachments/assets/50282090-adfd-4ddb-9e27-c30753c6b161\" alt=\"Bun\" width=18 style=\"vertical-align: middle;\" /\u003e (bun) or node, etc.), which generates a minimal package.json in the dist directory. Then, by running install again in the dist directory, it ensures that the final code can execute correctly.\n\n\u003cp\u003e\u003cimg src=\"./legend.png\" alt=\"Legend\" width=\"100%\" style=\"border-radius: 12px;\"/\u003e\u003c/p\u003e\n\n## Why do we need to install again?\n\nBecause some packages may depend on the current environment, or some packages may only determine at runtime that they need to load their dependencies (which might be installed directly in `node_modules/some-package`). Therefore, we need to extract these \"special\" packages separately. For example, put foo in the dependencies of dist/package.json, so that by running install again in the dist directory, we can ensure the code executes correctly!\n\n## Why bundle? 🤨\n\n[Why bundle?](https://bun.sh/docs/bundler#why-bundle) Let's read this article together. This is Bun's summary, and although it focuses more on frontend applications, in my opinion, bundling definitely brings benefits: 1. Easier to publish 2. Smaller package size 3. More convenient for handling obfuscation and similar logic.\n\n## Features\n\n- 🚀 **Fast and Simple**: Quickly generate dist/package.json\n- 📦 **Flexible Configuration**: Support both CLI options and config files\n- 🔧 **Customizable**: Choose which package.json fields to include\n- 🌟 **TypeScript Support**: Full TypeScript support with type definitions\n- 📝 **Auto Sorting**: Automatically sort package.json fields, perfect for OCD\n- ✅ **100% Test Coverage**: Project stability and reliability guaranteed\n- \u003cimg src=\"https://github.com/user-attachments/assets/50282090-adfd-4ddb-9e27-c30753c6b161\" alt=\"Bun\" width=18 style=\"vertical-align: middle;\" /\u003e **Bun Perfect Integration**: Optimized for Bun single-file bundling, seamless integration\n\n## Installation\n\n```bash\n\n# pnpm\npnpm add -D distpkg\n\n# bun\nbun add -D distpkg\n\n# npm\nnpm install -D distpkg\n\n# yarn\nyarn add -D distpkg\n```\n\n## Quick Start\n\n### Basic Usage (Only 2 Steps)\n\n1. Configure scripts in package.json\n\n```json\n{\n  \"scripts\": {\n    \"build\": \"pnpm run build:project \u0026\u0026 distpkg\",\n    \"build:project\": \"your build command\"\n  }\n}\n```\n\n2. Configure distpkg.config.ts\n\n```typescript\n// distpkg.config.ts\nimport { defineConfig } from 'distpkg';\n\nexport default defineConfig({\n  packageJson: {\n    dependencies: {\n      foo: '^1.0.0'\n      /* more dependencies */\n    }\n  }\n});\n```\n\n\u003e [!TIP]\n\u003e When building your project, you should exclude the foo package, such as `\"build\": \"bun build src/index.ts --target bun --outdir=dist --bytecode --minify --external foo\"`\n\n## CLI Options\n\n```\nUsage:\n  $ distpkg [...package-keys]\n\nCommands:\n  [...package-keys]  Keys to copy from project package.json to dist/package.json\n\nFor more info, run any command with the `--help` flag:\n  $ distpkg --help\n\nOptions:\n  -c, --config \u003cfilename\u003e  Use a custom config file\n  -d, --out-dir \u003cdir\u003e      Output directory (default: dist)\n  --cwd \u003cdir\u003e              Working directory (default: process.cwd())\n  -s, --sort               Sort package.json (default: true)\n  -h, --help               Display this message\n  -v, --version            Display version number\n```\n\n### Programmatic Usage\n\n```typescript\nimport { build } from 'distpkg';\n\n// your build js\n// ...\nconst result = await build({\n  /* ... */\n});\nif (!result.success) {\n  console.error('Build failed with errors:', result.message);\n}\n```\n\n## Docker Deployment\n\nWith this tool, our project best practices should be as follows (personal opinion only):\n\ninstall -\u003e build -\u003e cd dist -\u003e install -\u003e package into image -\u003e deploy to docker -\u003e deploy successfully and start service\n\n## License\n\n[MIT](./LICENSE)\n\nCopyright (c) 2025-present, Zhifeng (Jeff) Wang\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frefinist%2Fdistpkg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frefinist%2Fdistpkg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frefinist%2Fdistpkg/lists"}