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

Commit 0458457

Browse files
committed
Don't always include e.g. the history package
1 parent 31b1e28 commit 0458457

File tree

2 files changed

+45
-21
lines changed

2 files changed

+45
-21
lines changed

fstream-npm.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,19 @@ Packer.prototype.readBundledLinks = function () {
8989
}
9090

9191
Packer.prototype.applyIgnores = function (entry, partial, entryObj) {
92-
// package.json files can never be ignored.
93-
if (entry === 'package.json') return true
92+
if (!entryObj || entryObj.type !== 'Directory') {
93+
// package.json files can never be ignored.
94+
if (entry === 'package.json') return true
9495

95-
// readme files should never be ignored.
96-
if (entry.match(/^readme(\.[^\.]*)$/i)) return true
96+
// readme files should never be ignored.
97+
if (entry.match(/^readme(\.[^\.]*)$/i)) return true
9798

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

101-
// changelogs should never be ignored.
102-
if (entry.match(/^(changes|changelog|history)(\.[^\.]*)?$/i)) return true
102+
// changelogs should never be ignored.
103+
if (entry.match(/^(changes|changelog|history)(\.[^\.]*)?$/i)) return true
104+
}
103105

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

test/ignores.js

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ var Packer = require('..')
99

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

12-
var gitDir = join(pkg, '.git')
13-
1412
var elfJS = function () {/*
1513
module.exports = function () {
1614
console.log("i'm a elf")
@@ -35,26 +33,36 @@ var included = [
3533

3634
test('follows npm package ignoring rules', function (t) {
3735
var subject = new Packer({ path: pkg, type: 'Directory', isDirectory: true })
36+
var seen = {}
3837
subject.on('entry', function (entry) {
3938
t.equal(entry.type, 'File', 'only files in this package')
4039
var filename = entry.basename
4140
t.ok(
4241
included.indexOf(filename) > -1,
4342
filename + ' is included'
4443
)
44+
seen[filename] = true
4545
})
4646
// need to do this so fstream doesn't explode when files are removed from
4747
// under it
48-
subject.on('end', function () { t.end() })
48+
subject.on('end', function () {
49+
included.forEach(function (filename) {
50+
t.ok(
51+
seen[filename],
52+
filename + ' was not excluded'
53+
)
54+
})
55+
t.end()
56+
})
4957
})
5058

5159
test('cleanup', function (t) {
52-
cleanup()
53-
t.end()
60+
// rimraf.sync chokes here for some reason
61+
rimraf(pkg, function () { t.end() })
5462
})
5563

5664
function setup () {
57-
cleanup()
65+
rimraf.sync(pkg)
5866
mkdirp.sync(pkg)
5967
fs.writeFileSync(
6068
join(pkg, 'package.json'),
@@ -71,25 +79,39 @@ function setup () {
7179
'packaged=false'
7280
)
7381

74-
var build = join(pkg, 'build')
75-
mkdirp.sync(build)
7682
fs.writeFileSync(
77-
join(build, 'config.gypi'),
83+
join(pkg, '.npmignore'),
84+
'.npmignore\ndummy\npackage.json'
85+
)
86+
87+
fs.writeFileSync(
88+
join(pkg, 'dummy'),
89+
'foo'
90+
)
91+
92+
var buildDir = join(pkg, 'build')
93+
mkdirp.sync(buildDir)
94+
fs.writeFileSync(
95+
join(buildDir, 'config.gypi'),
7896
"i_wont_be_included_by_fstream='with any luck'"
7997
)
8098

8199
fs.writeFileSync(
82-
join(build, 'npm-debug.log'),
100+
join(buildDir, 'npm-debug.log'),
83101
'0 lol\n'
84102
)
85103

104+
var gitDir = join(pkg, '.git')
86105
mkdirp.sync(gitDir)
87106
fs.writeFileSync(
88107
join(gitDir, 'gitstub'),
89108
"won't fool git, also won't be included by fstream"
90109
)
91-
}
92110

93-
function cleanup () {
94-
rimraf.sync(pkg)
111+
var historyDir = join(pkg, 'node_modules/history')
112+
mkdirp.sync(historyDir)
113+
fs.writeFileSync(
114+
join(historyDir, 'README.md'),
115+
"please don't include me"
116+
)
95117
}

0 commit comments

Comments
 (0)