Skip to content

Instantly share code, notes, and snippets.

@isaacs
Last active October 13, 2019 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/062fe5ebc6d9623f15603de5fa6018a0 to your computer and use it in GitHub Desktop.
Save isaacs/062fe5ebc6d9623f15603de5fa6018a0 to your computer and use it in GitHub Desktop.

Here's a puzzle to noodle on:

Let's say package.json contains this:

{
  "files": [
    "lib",
    "!lib/one",
    "lib/two"
  ]
}

Files in lib/ are: .npmignore, one, two, tre

The file at lib/.npmignore contains:

two

Which files will be included in the package?

  • 🅰️: lib/two, lib/tre, package.json
  • 🅱️: lib/tre, lib/.npmignore, package.json

(Please don't look it up, the point of the exercise is to gauge expectations.)

@isaacs
Copy link
Author

isaacs commented Oct 9, 2019

Argument for 🅰️:

The package.json file specifies what files are to be included. This supersedes any ignore files found throughout the tree.

Argument for 🅱️:

There's an ignore file right there! It says to ignore two, so two should be ignored.

@isaacs
Copy link
Author

isaacs commented Oct 11, 2019

@PatrickQuintal
Copy link

I'm somewhat leaning towards 🅰️ for a slightly different reason.

I don't publish NPM packages, so I suppose my opinion doesn't matter too much, but I read files array "sequentially" and being processed in the following;

  1. We include lib, its a directory, its got an ignore file, lets do (all files) then subtract the .npmignore.
  2. Specifically remove a file.
  3. Specifically include a file, its a file. So lets ignore the .npmignore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment