Skip to content

Commit

Permalink
Use an allowlist-based .npmignore file (#250)
Browse files Browse the repository at this point in the history
Reconcile the package.json "files" field and .npmignore into the
.npmignore file. Like package.json "files", an allowlist approach is
used by first ignoring everything (with `/*`) and then listing the
patterns that should be published using inverted patterns using the
leading `!`. After, filter out nested paths for tests to avoid
publishing such unnecessary files.
Note that the leading "**/" for tests is necessary as otherwise test
files would still be published (this was manually verified).

The previous approach, using both "files" and .npmignore, does not work
and only the "files" value was respected (this can be seen from the
files present in v4.2.0). It appears only one of the two can be used,
though I was unable to find a statement in the npm docs that say this
explicitly.

An alternative to the approach taken here would be to increase the
specificity of file patterns in the "files" array to avoid including
test files.
  • Loading branch information
ericcornelissen committed May 24, 2023
1 parent 11b774d commit 19eba12
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
17 changes: 15 additions & 2 deletions .npmignore
@@ -1,3 +1,16 @@
__tests__/
__stories__/
# Ignore everything...
/*

# Except what needs to be published
!/src
!/lib
!register.js
!package.json
!CHANGELOG.md
!LICENSE
!README.md

# Unless it's tests
**/__tests__/
**/__stories__/
*.test.{js,ts,tsx}
9 changes: 0 additions & 9 deletions package.json
Expand Up @@ -7,15 +7,6 @@
"author": "Jonas Kello",
"license": "MIT",
"repository": "https://github.com/dividab/tsconfig-paths",
"files": [
"/src",
"/lib",
"register.js",
"package.json",
"CHANGELOG.md",
"LICENSE",
"README.md"
],
"engines": {
"node": ">=6"
},
Expand Down

0 comments on commit 19eba12

Please sign in to comment.