Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yarn pack does not honor globs in "files" option of package.json #3336

Closed
jrop opened this issue May 5, 2017 · 8 comments
Closed

yarn pack does not honor globs in "files" option of package.json #3336

jrop opened this issue May 5, 2017 · 8 comments
Labels

Comments

@jrop
Copy link
Contributor

jrop commented May 5, 2017

Do you want to request a feature or report a bug? bug

What is the current behavior?

My package.json "files" option specifies globs as entries:

  "files": [
    "config/**/*.js",
    "lib/**/*.js"
  ]

When I run yarn pack it produces a .tgz file with the following entries:

package
package/.gitignore
package/config/.gitignore
package/files/.gitignore
package/package.json

However, when I run npm pack, it packs the following files instead:

package/package.json
package/lib/file1.js
package/lib/file2.js
package/lib/index.js
package/config/index.js
package/config/config1.js
package/config/config2.js

If the current behavior is a bug, please provide the steps to reproduce.
See above

What is the expected behavior?
See the npm pack output

Please mention your node.js, yarn and operating system version.
node: v7.7.3
yarn: v0.23.4
OS: macOS Sierra 10.12.2

@jrop jrop changed the title Yarn pack does not honor globs in "files" option of package.json yarn pack does not honor globs in "files" option of package.json May 5, 2017
@jrop
Copy link
Contributor Author

jrop commented May 5, 2017

Keeping notes for myself:

yarn pack eventually calls: this line with the following filters:

[ { base: '.',
    isNegation: true,
    regex: /^(?:\/(?=.)package\.json)$/i },
  { base: '.',
    isNegation: true,
    regex: /^(?:\/(?=.)readme[^\/]*?)$/i },
  { base: '.',
    isNegation: true,
    regex: /^(?:\/(?!\.)(?=.)(?:license|licence)+[^\/]*?)$/i },
  { base: '.',
    isNegation: true,
    regex: /^(?:\/(?!\.)(?=.)(?:changes|changelog|history)+[^\/]*?)$/i },
  { base: '.',
    isNegation: false,
    regex: /^(?:(?!\.)(?=.)[^\/]*?)$/i },
  { base: '.', isNegation: false, regex: /^(?:(?=.)\.[^\/]*?)$/i },
  { base: '.',
    isNegation: true,
    regex: /^(?:(?=.)config\/(?:(?!(?:\/|^)\.).)*?\/(?!\.)(?=.)[^\/]*?\.js)$/i },
  { base: '.',
    isNegation: true,
    regex: /^(?:(?=.)lib\/(?:(?!(?:\/|^)\.).)*?\/(?!\.)(?=.)[^\/]*?\.js)$/i },
  { base: '.',
    isNegation: false,
    regex: /^(?:\/(?=.)node_modules)$/i },
  { base: 'files',
    isNegation: true,
    regex: /^(?:(?=.)\.gitignore)$/i },
  { base: 'files',
    isNegation: false,
    regex: /^(?:(?!\.)(?=.)[^\/]*?)$/i } ]

@jrop
Copy link
Contributor Author

jrop commented May 5, 2017

More notes: it ends up calling to here with the following context:

filter = { base: '.',
  isNegation: true,
  regex: /^(?:(?=.)lib\/(?:(?!(?:\/|^)\.).)*?\/(?!\.)(?=.)[^\/]*?\.js)$/i }
basename = 'myfile.js'
loc = 'lib/myfile.js'
// matchesFilter(...) returns false in this case

@jrop
Copy link
Contributor Author

jrop commented May 5, 2017

So this is effectively console.logging filters from pack.js:

Ignore list:

!/package.json
!/readme*
!/+(license|licence)*
!/+(changes|changelog|history)*
*
.*
!config/**/*.js
!lib/**/*.js
/lib/
/node_modules/
!.gitignore

@jrop
Copy link
Contributor Author

jrop commented May 5, 2017

Interesting:

const mm = require('minimatch')
const loc = 'lib/sftp.js'
const re = mm.makeRe('lib/**/*.js', {nocase: true})

re.test(loc) // => false
mm(loc, 'lib/**/*.js', {nocase: true}) // => true

minimatch version: 3.0.3

@jrop
Copy link
Contributor Author

jrop commented May 6, 2017

See this line (#648) in minimatch.js

@bestander
Copy link
Member

Send a PR with tests please :)

@jrop
Copy link
Contributor Author

jrop commented May 12, 2017

@bestander I have a PR here: /pull/3339, and per your request I have added a fixture + a test that tests this. I am having trouble getting the tests to pass: sometimes an async timeout error is thrown. Is that normal?

@bestander
Copy link
Member

Yeah, I am ashamed that our tests are flaky sometimes.
Just don't have time to make them more robust.

lovelypuppy0607 added a commit to lovelypuppy0607/yarn that referenced this issue May 11, 2023
* Switch to micromatch: fixes yarnpkg/yarn#3336

* Trim patterns before generating RegExp
Test suite now passes

* Add test + test fixtures to test micromatch

* Oops.  Actually add the fixtures to Git this time

* Update yarn.lock

reverted registry change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants