Inspect package contents before distribution
Quick answer
npm pack creates or previews a package archive. Inspecting what would be distributed helps avoid missing build outputs and accidentally including private material.
Tooling examples
Example 1. Context: projects/npm-lab. Run in a fresh prepared fixture copy; see its README. Local check available; consult validation evidence for what was asserted.
npm pack --workspace=@lesson/units --dry-run --json --ignore-scriptsExpected observation: Planned files include index.js and package.json, not internal.js.
Example 2. Context: projects/npm-lab. Run in a fresh prepared fixture copy; see its README. Local check available; consult validation evidence for what was asserted.
npm pack --workspace=@lesson/units --json --ignore-scriptsExpected observation: A local tarball is created; no package is published.
How the tooling works
The units package declares a files allowlist for its public implementation. npm pack --dry-run --json reports the planned archive; npm has special rules for some metadata files. The package is private in the lab and no publish action is required. Test a consumer using the packed artifact rather than only importing a workspace. A pack list is not a secret scanner; verify contents and scan independently. Run pack in a reviewed local project because lifecycle hooks may execute unless disabled.
Common mistakes
Do not treat a .gitignore file as a guarantee that sensitive files cannot enter a package. Review the actual archive.
Practice
Preview units, confirm index.js exists and internal.js is omitted, then generate the archive locally and inspect it without publishing.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Inspect package contents before distribution — Knowledge Check
Assess tooling contracts, diagnostic reasoning and transfer to a project.
Which npm command previews the files intended for a package archive?
What does the files field primarily control?
Why test a packed package separately from a workspace?
In Inspect package contents before distribution, what is the expected observation for example 1 in its documented setup? npm pack --workspace=@lesson/units --dry-run --json --ignore-scripts
In Inspect package contents before distribution, what is the expected observation for example 2 in its documented setup? npm pack --workspace=@lesson/units --json --ignore-scripts