Skip to content

Commit e488661

Browse files
committed
a variety of updates
- remove nyc output from npm package - add pathsToRegex helper - fix getOutputPath bug and test
1 parent 28369d8 commit e488661

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ test
33
contributing.md
44
.editorconfig
55
.travis.yml
6+
.nyc_output

lib/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ module.exports = class SpikeUtils {
4141
*/
4242
getOutputPath (f) {
4343
let file = new File(this.conf.context, f)
44+
file = new File(this.conf.output.path, file.relative)
4445

4546
this.conf.spike.dumpDirs.forEach((d) => {
4647
const re = new RegExp(`^${d}\\${path.sep}`)
@@ -142,6 +143,17 @@ module.exports = class SpikeUtils {
142143
return micromatch.apply(micromatch, arguments)
143144
}
144145

146+
/**
147+
* Converts an array of paths to a regex that matches those paths. Useful for
148+
* when you need to add a loader that only matches specific files.
149+
*/
150+
pathsToRegex (paths) {
151+
if (!paths.length) { return new RegExp('^.^') }
152+
return new RegExp(paths.map((p, i) => {
153+
return p.replace(/\//g, '\\/')
154+
}).join('|'))
155+
}
156+
145157
/**
146158
* Given a loader context, resolves the path of the current file and returns
147159
* a `File` object containing both the absolute and relative paths.

test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test.cb('EVERYTHING WORKS', (t) => {
2727
plugin.on('isFileIgnored', (r) => { t.truthy(r) })
2828
plugin.on('matchGlobs', (r) => { t.truthy(r.length === 2) })
2929
plugin.on('getOutputPath', (p) => {
30-
t.truthy(p.relative, 'index.txt')
30+
t.truthy(p.relative === 'index.txt')
3131
t.truthy(p.absolute.match('public'))
3232
})
3333

0 commit comments

Comments
 (0)