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

specify ignore file #4

Open
popomore opened this issue Jan 11, 2015 · 9 comments
Open

specify ignore file #4

popomore opened this issue Jan 11, 2015 · 9 comments

Comments

@popomore
Copy link
Contributor

Can you support this?

@popomore
Copy link
Contributor Author

Any idea?

@timoxley
Copy link
Owner

hm, it will use the same rules used to build the package. You can ignore things via .npmignore. Does that help?

@popomore
Copy link
Contributor Author

I know that, I use another package manager named spm, and the ignore file is .spmignore, but the mechanics is same.

I just want to use .spmignore as ignore file

pkgfiles --file .spmignore

@timoxley
Copy link
Owner

Ok, I see. This isn't quite as simple as it might seem.

So pkgfiles uses pkgresolve to extract the exact version of fstream-npm used by the current version of npm installed globally:

// https://github.com/timoxley/pkgfiles/blob/91ffeb90f5653f3b6dca7e5b1035b0464479b642/index.js#L12
resolve('fstream-npm').fromGlobal('npm', 

it then uses this version of fstream-npm to figure out which files are included.

fstream-ignore is a package used by fstream-npm to filter out ignored files and I note that spm does use fstream-ignore, presumably to filter files in the same way: https://github.com/spmjs/spm/blob/5baa225cf7f5d693d34afdbe89d7d60f480d03b0/package.json#L39-L40

The tricky part is that the fstream-ignore within spm isn't guaranteed to be the same version of fstream-ignore that would be picked up by pkgfiles from the global npm, nor is fstream-ignore guaranteed to be configured or used in the same way. fstream-npm also does a bunch of additional filtering:

  // package.json files can never be ignored.
  if (entry === "package.json") return true

  // readme files should never be ignored.
  if (entry.match(/^readme(\.[^\.]*)$/i)) return true

  // license files should never be ignored.
  if (entry.match(/^(license|licence)(\.[^\.]*)?$/i)) return true

  // changelogs should never be ignored.
  if (entry.match(/^(changes|changelog|history)(\.[^\.]*)?$/i)) return true

  // special rules.  see below.
  if (entry === "node_modules" && this.packageRoot) return true

  // some files are *never* allowed under any circumstances
  if (entry === ".git" ||
      entry === ".lock-wscript" ||
      entry.match(/^\.wafpickle-[0-9]+$/) ||
      entry === "CVS" ||
      entry === ".svn" ||
      entry === ".hg" ||
      entry.match(/^\..*\.swp$/) ||
      entry === ".DS_Store" ||
      entry.match(/^\._/) ||
      entry === "npm-debug.log"
    ) {
    return false
  }

https://github.com/npm/fstream-npm/blob/4a95e1903f93dc122320349bb55e367ddd08ad6b/fstream-npm.js#L89-L118

This is mirrored in spm, but not quite exactly:

  // some files are *never* allowed under any circumstances
  if (entry === '.git' ||
      entry === '.lock-wscript' ||
      entry.match(/^\.wafpickle-[0-9]+$/) ||
      entry === 'CVS' ||
      entry === '.svn' ||
      entry === '.hg' ||
      entry.match(/^\..*\.swp$/) ||
      entry === '.DS_Store' ||
      entry.match(/^\._/)
    ) {
    return false;
  }

  // package.json should be **allways** included
  if (entry === 'package.json') {
    return true;
  }

https://github.com/spmjs/spm/blob/50fcec87e03fb7749d8b3f963a2d1d96064df22e/lib/utils/tar.js#L109-L129

@timoxley
Copy link
Owner

In summary, I could pretty easily allow the ignore file to be configured but pkgfiles is not guaranteed to produce the same set of files which would be included in an spm bundle.

@popomore
Copy link
Contributor Author

OK, it doesn't matter. Giving the option is enough.

@timoxley
Copy link
Owner

If spm used fstream-npm instead of this copy-pasted code from fstream-npm, then this could work perfectly. I'd just need to make the pkgresolve target configurable. i.e. set it up so it looks for fstream-npm inside the global spm

@timoxley
Copy link
Owner

i.e. seems like it could be a good idea to use fstream-npm anyway… or if there was an fstream-spm that fulfilled the same role.

@popomore
Copy link
Contributor Author

That's a good idea. I will review this old code, it should use fstream-npm.

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

No branches or pull requests

2 participants