Skip to content
This repository has been archived by the owner on Nov 16, 2019. It is now read-only.

Don't always include e.g. the history package #15

Merged
merged 1 commit into from
Nov 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions fstream-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,19 @@ Packer.prototype.readBundledLinks = function () {
}

Packer.prototype.applyIgnores = function (entry, partial, entryObj) {
// package.json files can never be ignored.
if (entry === 'package.json') return true
if (!entryObj || entryObj.type !== 'Directory') {
// 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
// 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
// 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
// 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
Expand Down
48 changes: 35 additions & 13 deletions test/ignores.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ var Packer = require('..')

var pkg = join(__dirname, 'test-package')

var gitDir = join(pkg, '.git')

var elfJS = function () {/*
module.exports = function () {
console.log("i'm a elf")
Expand All @@ -35,26 +33,36 @@ var included = [

test('follows npm package ignoring rules', function (t) {
var subject = new Packer({ path: pkg, type: 'Directory', isDirectory: true })
var seen = {}
subject.on('entry', function (entry) {
t.equal(entry.type, 'File', 'only files in this package')
var filename = entry.basename
t.ok(
included.indexOf(filename) > -1,
filename + ' is included'
)
seen[filename] = true
})
// need to do this so fstream doesn't explode when files are removed from
// under it
subject.on('end', function () { t.end() })
subject.on('end', function () {
included.forEach(function (filename) {
t.ok(
seen[filename],
filename + ' was not excluded'
)
})
t.end()
})
})

test('cleanup', function (t) {
cleanup()
t.end()
// rimraf.sync chokes here for some reason
rimraf(pkg, function () { t.end() })
})

function setup () {
cleanup()
rimraf.sync(pkg)
mkdirp.sync(pkg)
fs.writeFileSync(
join(pkg, 'package.json'),
Expand All @@ -71,25 +79,39 @@ function setup () {
'packaged=false'
)

var build = join(pkg, 'build')
mkdirp.sync(build)
fs.writeFileSync(
join(build, 'config.gypi'),
join(pkg, '.npmignore'),
'.npmignore\ndummy\npackage.json'
)

fs.writeFileSync(
join(pkg, 'dummy'),
'foo'
)

var buildDir = join(pkg, 'build')
mkdirp.sync(buildDir)
fs.writeFileSync(
join(buildDir, 'config.gypi'),
"i_wont_be_included_by_fstream='with any luck'"
)

fs.writeFileSync(
join(build, 'npm-debug.log'),
join(buildDir, 'npm-debug.log'),
'0 lol\n'
)

var gitDir = join(pkg, '.git')
mkdirp.sync(gitDir)
fs.writeFileSync(
join(gitDir, 'gitstub'),
"won't fool git, also won't be included by fstream"
)
}

function cleanup () {
rimraf.sync(pkg)
var historyDir = join(pkg, 'node_modules/history')
mkdirp.sync(historyDir)
fs.writeFileSync(
join(historyDir, 'README.md'),
"please don't include me"
)
}