From 19eba1295fdcef278ce3fbad0d4b4e894128d3fe Mon Sep 17 00:00:00 2001 From: Eric Cornelissen Date: Wed, 24 May 2023 08:37:56 +0200 Subject: [PATCH] Use an allowlist-based .npmignore file (#250) 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. --- .npmignore | 17 +++++++++++++++-- package.json | 9 --------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.npmignore b/.npmignore index 4f9a830..8456796 100644 --- a/.npmignore +++ b/.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} diff --git a/package.json b/package.json index f8d76f5..e08f4fa 100644 --- a/package.json +++ b/package.json @@ -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" },