{"data":{"slug":"discovered-5134e9381695651664b1293e9d2e8748893ceae4227ac2c8","title":"Build Artifacts","summary":"Ensure build scripts produce correct and complete artifacts by enforcing strict checks on inputs, size, and file lists, and verifying artifacts against the source tree. The deliverable is a validated build output that matches the project manifest and includes all required files.","url":"https:\/\/skillshunter.net\/skills\/discovered-5134e9381695651664b1293e9d2e8748893ceae4227ac2c8","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/discovered-5134e9381695651664b1293e9d2e8748893ceae4227ac2c8","markdown_url":"https:\/\/skillshunter.net\/skills\/discovered-5134e9381695651664b1293e9d2e8748893ceae4227ac2c8.md","download_url":"https:\/\/skillshunter.net\/skills\/discovered-5134e9381695651664b1293e9d2e8748893ceae4227ac2c8\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before running the build script, ensure that all required files are present and that the file list (`DIST_FILES`) is derived from the entrypoints or explicitly checked against them. The first deliverable is a validated build output that matches the project manifest and includes all required files.","instructions":"---\nname: shipping-build-artifacts\ndescription: Make the build step a real gate on what you actually distribute \u2014 build scripts that warn and exit 0 on a missing input, size checks with only an upper bound, hand-maintained file lists that drift from the entrypoints they must cover, committed bundles that go stale when only the source changes, GNU-only shell in release scripts that aborts on the other OS, and verification that runs against the source tree instead of the artifact. Use when writing or reviewing a build\/package script, a `dist\/` copy step, a release workflow that uploads a zip or installer, or a committed compiled asset.\n---\n\n# Shipping Build Artifacts\n\nLint, type-check, and tests run against the source tree. What users install is a\n*different* set of bytes \u2014 assembled by a script that most gates never look at,\nthen uploaded by a workflow that trusts whatever the script left behind. Every\nfailure below ships a broken or stale artifact under fully green CI.\n\n## A script that warns and exits 0 is not a gate\n\nThe shape is universal: a declared list of inputs, a copy loop, a friendly\nwarning when one is missing.\n\n```js\nfor (const f of DIST_FILES) {\n  if (!fs.existsSync(f)) {\n    console.warn(`Warning: ${f} not found, skipping`);   \/\/ build \"succeeds\"\n    continue;\n  }\n  fs.copyFileSync(f, path.join(\"dist\", f));\n}\n```\n\nMove one required file aside and the script prints a line nobody reads, exits 0,\nand produces a `dist\/` without it. Nothing downstream notices: the test job ran\nagainst the source tree, and the release job zips `dist\/` and attaches it to a\npublic release. The artifact is wholly non-functional \u2014 the entrypoint imports a\nfile that isn't there \u2014 and the failure is discovered by users.\n\n```js\nconst missing = DIST_FILES.filter((f) => !fs.existsSync(f));\nif (missing.length) {\n  console.error(`Missing build inputs: ${missing.join(\", \")}`);\n  process.exit(1);\n}\n```\n\nThe rule: inside a build script, `warn` may only describe something the artifact\nsurvives without. If you cannot say what still works when that file is absent, it\nis an error and the process must exit non-zero.\n\n## Bound the artifact size on *both* sides\n\nA packaging check with only a ceiling \u2014 \"fail if the zip exceeds 500 KB\" \u2014 is a\ncost guard, not a correctness one. A build that silently dropped half its files\nis *smaller*, so it passes the only check that exists.\n\n```js\nassert(bytes < 500 * 1024, \"package too large\");\nassert(bytes > 20 * 1024, \"package suspiciously small \u2014 inputs likely missing\");\nassert(entries.length === DIST_FILES.length, \"package entry count mismatch\");\n```\n\nBetter still, assert on contents rather than a proxy: list the archive's entries\nand compare against the set the entrypoints require.\n\n## Derive the file list, or check it against the entrypoints\n\n`DIST_FILES` \u2014 like a build backend's `only-include`, or a hand-written\n`package_data` \u2014 is a *second* copy of \"what this app is made of.\" The first copy\nis the manifest, the entry HTML, and the import graph. They drift in one\ndirection: someone adds `utils.js`, references it from the popup, and forgets the\ncopy list. The build stays green and the feature is dead in the packaged app.\n\nEither derive the list (bundle from the real entrypoints), or add a check that\nevery path referenced by the manifest and by `<script src>` \/ `importScripts`\nexists in `dist\/` after the build. A hand-maintained allowlist with no such check\nis a bug scheduled for a future commit.\n\nThe same rule covers any place dependency or asset metadata is restated by hand \u2014\na standalone launcher script whose inline dependency header duplicates the\nproject manifest's `dependencies`, for instance. If duplication is unavoidable,\nadd a test that normalizes both lists and compares them, so drift fails in CI\ninstead of at a user's install.\n\n## Committed build outputs go stale silently\n\nWhen a compiled or minified bundle is committed and served directly, *the bundle\nis the program* and its source is a comment until someone rebuilds. Editing only\nthe source ships nothing; the page keeps serving the previous bundle, and no test\nor linter says a word.\n\n- Rebuild in CI and `diff` against the committed output; fail on drift.\n- Pin the builder to an exact version \u2014 the diff is only meaningful if the output\n  is byte-deterministic.\n- Confirm that determinism once across the environments people actually use\n  (native toolchain vs. container image), so the check is runnable locally too.\n\n```bash\nnpx -y esbuild@0.24.2 src\/app.jsx --jsx=transform --minify --outfile=\/tmp\/app.js\ndiff \/tmp\/app.js web\/app.js\n```\n\nRebuild and commit the output in the **same commit** as the source change. A\n\"rebuild bundles\" follow-up commit means every commit in between shipped code\nthat does not match its source.\n\n## Release scripts run on an OS you didn't write them on\n\nBuild scripts are written on a developer machine and executed on the runner.\nGNU-only tooling is the usual break, and `set -e` turns it into a total abort on\na line that merely reads a version number:\n\n```bash\n# Breaks under BSD grep (macOS): -P \/ lookbehind are GNU extensions.\nVERSION=$(grep -Po '(?<=^version = \")[^\"]+' pyproject.toml)\n```\n\nRead structured metadata with a parser instead of a regex, and prefer a runtime\nyou already depend on:\n\n```bash\nVERSION=$(python -c 'import tomllib;print(tomllib.load(open(\"pyproject.toml\",\"rb\"))[\"project\"][\"version\"])')\nVERSION=$(jq -r .version package.json)\n```\n\nThen pin it with a test: the version the build script extracts must equal the\nversion declared in the project manifest. Without that, the failure mode is a\nrelease tagged `v1.4.0` whose artifact reports `1.3.2`, and nothing in the\npipeline disagrees.\n\n## Verify the artifact, then publish \u2014 in that order, in that job\n\nAttaching a file to a public release, pushing a tag, or uploading to a registry\nare the least reversible steps in the project. The verification must sit between\nthe build and the upload, in the same job. A separate green \"test\" job proves\nnothing about the artifact: it ran against the source tree.\n\nMinimum ordering:\n\n1. Build.\n2. List every entry in the artifact and assert the entrypoints are present.\n3. Install or load it **from a directory the source tree is not on the load path\n   of**, and exercise one real symbol or command \u2014 not merely that a top-level\n   name resolves.\n4. Only then upload.\n\nStep 3 is the one that gets skipped, and it is the only step that distinguishes\n\"the archive has files in it\" from \"the thing runs.\" Run it somewhere else on\ndisk, or it passes against the sources and proves nothing.\n\n## Checklist\n\n```\nBuild script:\n- [ ] Missing declared input \u2192 non-zero exit, not a warning\n- [ ] Size assertions have a floor as well as a ceiling\n- [ ] File list is derived, or checked against manifest\/entry-HTML references\n- [ ] Duplicated dependency metadata has a drift test\n- [ ] No GNU-only flags (grep -P, sed -i'' semantics) in scripts CI also runs\n- [ ] Version extracted with a parser, and asserted equal to the declared version\n\nCommitted build outputs:\n- [ ] CI rebuilds and diffs; drift fails\n- [ ] Builder pinned to an exact version; output confirmed deterministic\n- [ ] Output committed alongside the source change, not in a follow-up\n\nRelease:\n- [ ] Artifact contents listed and asserted before upload\n- [ ] Artifact installed\/loaded from outside the repo and exercised\n- [ ] Verification runs in the same job as the upload, before it\n```\n\n## Note for this repository (ffmpeg-skill)\n\n`package.json`'s `\"files\"` list is the equivalent of `DIST_FILES` here \u2014 it must\nlist exactly what ships (`bin\/`, `scripts\/`, `templates\/`, `mcp\/`, the shipped\n`references\/*.md` files one by one, `docs\/contract.md`, `SKILL.md`, `README.md`,\n`LICENSE`), and `.claude\/` (this file included) must NEVER appear\nin it. `npm publish --dry-run` is the \"list every entry and assert the\nentrypoints are present\" step (step 2 above) \u2014 run it before every publish, and\nwatch for stray `__pycache__`\/`.pyc` files sneaking into the tarball from a\nlocal test run (this actually happened once this session and was caught by\nexactly this check). The \"install from outside the repo and exercise a\nsymbol\" step is `npm run release-check` (`tests\/release_check.sh`): it packs\nthe tarball, installs from it into a temp HOME, and asks the installed copy\nfor its contract, its MCP tool list and `doctor`.\n\nSource: [wdm0006\/python-skills](https:\/\/github.com\/wdm0006\/python-skills) (MIT).\n","use_cases":["Writing or reviewing a build\/package script","Implementing a `dist\/` copy step","Creating a release workflow that uploads a zip or installer","Validating committed compiled assets"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/kajisho5\/ffmpeg-skill\/blob\/daae28ea4fe27223932392be07206798423c0f8b\/.claude\/skills\/build-artifacts\/SKILL.md","source_commit":"daae28ea4fe27223932392be07206798423c0f8b","license":null,"version":null,"listing_approved_at":"2026-11-28","created_at":"2026-11-28T08:11:02.000000Z","updated_at":"2026-11-28T18:37:53.000000Z","seo_title":"Build Artifacts with Strict Validation","seo_description":"Ensure your build scripts produce correct and complete artifacts by enforcing strict checks on inputs, size, and file lists, and verifying artifacts against the source.","seo_keywords":["build script validation","artifact verification","dist file check","build gate","package size check","entrypoint file list","build output validation"]}}