npm / npm-packlist

Walk through a folder and figure out what goes in an npm package
ISC License
110 stars 32 forks source link

[BUG/QUESTION] since npm 9.x some files[] globs undermatch #152

Open 43081j opened 1 year ago

43081j commented 1 year ago

Is there an existing issue for this?

Current Behavior

Given this:

{
  "files": [
    "lib/(!test)"
  ]
}

and a tree like this:

- lib
  - main.js
  - foo.js
  - utils
    - foo-util.js
  - test
    - main_test.js
    - foo_test.js
    - utils
      - foo-util_test.js

before the hefty refactor that happened around npm 9 (in npm-packlist), that glob would result in this:

- lib
  - main.js
  - foo.js
  - utils
    - foo-util.js

After the refactor, this is the resulting packed tree:

- lib
  - main.js

meaning the glob was ignored really (since ${main} is enforceably included).

it can be solved by changing the files array to this:

{
  "files": [
    "lib/",
    "!lib/test/"
  ]
}

which im fine with, but it does mean you've introduced a breaking change which i can't see in the changelog (could be me being blind though).

can you clarify if this is a bug or intentional? and close this if it is the latter, with an explanation if you can

Expected Behavior

glob is respected

Steps To Reproduce

N/A

Environment

tido64 commented 1 year ago

Furthermore, given the following rules:

  "files": [
    "/*.{gradle,js,md,podspec,rb}",
    "/android/**/*.gradle",
    "/android/app/lint.xml",
    "/android/app/src",
    "!/android/app/src/test",
    "/android/support/src",
    "/common",
    "/example/_gitignore",
    "/example/android/gradle*",
    "/example/windows/_gitignore",
    "/example/{metro,react-native}.config.js",
    "/ios",
    "/macos",
    "/plugins",
    "/schema.json",
    "/scripts/*.js",
    "/scripts/apply-config-plugins.mjs",
    "/scripts/config-plugins/**/*.mjs",
    "/windows/*.{js,props}",
    "/windows/ReactTestApp"
  ],

I am seeing it include/exclude random files (before/after):

image

/example/android/gradle* no longer matches example/android/gradle/wrapper/gradle-wrapper.jar and example/android/gradle/wrapper/gradle-wrapper.properties. Instead, it includes random files under example/ that aren't even mentioned.

tido64 commented 1 year ago

@fritzy: Sorry for the random ping but do you happen to know who could take a look at this?

tido64 commented 1 year ago

It also looks like the content of npm pack differs from running npm-packlist manually:

-rw-r--r--  0 0      0         145 26 okt  1985 package/example/_gitignore
-rw-r--r--  0 0      0         342 26 okt  1985 package/example/windows/_gitignore
-rwxr-xr-x  0 0      0        8188 26 okt  1985 package/example/android/gradlew
-rw-r--r--  0 0      0        2747 26 okt  1985 package/example/android/gradlew.bat
-rw-r--r--  0 0      0         616 26 okt  1985 package/example/android/build.gradle
-rw-r--r--  0 0      0         246 26 okt  1985 package/example/android/settings.gradle
-rw-r--r--  0 0      0       60756 26 okt  1985 package/example/android/gradle/wrapper/gradle-wrapper.jar
-rw-r--r--  0 0      0        5165 26 okt  1985 package/example/App.js
-rw-r--r--  0 0      0          77 26 okt  1985 package/example/babel.config.js
-rw-r--r--  0 0      0         180 26 okt  1985 package/example/index.js
-rw-r--r--  0 0      0        1315 26 okt  1985 package/example/metro.config.js
-rw-r--r--  0 0      0         458 26 okt  1985 package/example/react-native.config.js
-rw-r--r--  0 0      0         802 26 okt  1985 package/example/Example-Tests.podspec
-rw-r--r--  0 0      0         202 26 okt  1985 package/example/android/gradle/wrapper/gradle-wrapper.properties
-rw-r--r--  0 0      0        1885 26 okt  1985 package/example/android/gradle.properties

I couldn't get npm-packlist@7 to run (apparently because bin was removed), but here's the output of 6:

example/_gitignore
example/windows/_gitignore
example/android/gradlew
example/android/gradlew.bat
example/android/gradle/wrapper/gradle-wrapper.jar
example/metro.config.js
example/react-native.config.js
example/android/gradle/wrapper/gradle-wrapper.properties
example/android/gradle.properties

I still don't understand where the extra files are coming from…

@lukekarrys: Maybe you have an idea of what's going on here?

lukekarrys commented 1 year ago

Possibly related to https://github.com/npm/cli/issues/6164. And if not, still worth investigating both issues together I think.