Skip to content

Commit

Permalink
remove filePathFromLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
jescalan committed Jan 10, 2017
1 parent 41db697 commit c74f6f0
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 34 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ With it initialized, you can use any of the following functions:
- `util.pathsToRegex(paths)` - given an array of file paths, builds a regex that will match only those paths
- `util.modifyOutputPath(file, outPath)` - Given an absolute or relative (to the project root) path to a file that's being processed by spike, changes the output path to absolute or relative (recommended) path provided. Recommended to use in the `emit` plugin stage.

And some static methods:
- `SpikeUtils.filePathFromLoader(loaderContext)` - pass `this` inside a loader and it will return a file object with the absolute and relative paths to the current file being processed.

For more details on any given function, check out the source! I would never say this for any other library, but this is only one simple file, with fairly small functions that are extremely thoroughly documented, so I think it's worth jumping in.

### License & Contributing
Expand Down
11 changes: 0 additions & 11 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,4 @@ module.exports = class SpikeUtils {
return p.replace(/\//g, '\\/')
}).join('|'))
}

/**
* Given a loader context, resolves the path of the current file and returns
* a `File` object containing both the absolute and relative paths.
* @param {Object} context - `this` from a webpack loader
* @return {File} file object containing absolute and relative paths
*/
static filePathFromLoader (loaderContext) {
const f = url.parse(loaderContext.request.split('!').slice(-1)[0]).pathname
return new File(loaderContext.options.context, f)
}
}
14 changes: 1 addition & 13 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const path = require('path')
const fs = require('fs')
const Spike = require('spike-core')
const TestPlugin = require('./plugin')
const EventEmitter = require('events')

const fixtures = path.join(__dirname, 'fixtures')

Expand All @@ -12,9 +11,8 @@ test.cb('EVERYTHING WORKS', (t) => {
const plugin = new TestPlugin({
injectFile: path.join(fixturePath, 'views/index.txt')
})
const loaderEmitter = new EventEmitter()

t.plan(12)
t.plan(10)

plugin.on('addFilesAsWebpackEntries', (comp) => {
const mod = comp.modules.find((m) => m.rawRequest === './views/index.txt')
Expand All @@ -36,19 +34,9 @@ test.cb('EVERYTHING WORKS', (t) => {
t.falsy(p.absolute.match('public'))
})

loaderEmitter.on('filePathFromLoader', (f) => {
t.regex(f.absolute, /basic\/views\/index.txt/)
t.truthy(f.relative === 'views/index.txt')
})

const project = new Spike({
root: fixturePath,
entry: { main: ['./entry.js'] },
resolveLoader: { alias: { test: path.join(__dirname, 'loader.js') } },
module: {
loaders: [{ test: /\.txt$/, loader: 'source!test', skipSpikeProcessing: true }]
},
loaderEmitter: loaderEmitter,
ignore: ['**/views/ignoreme.txt'],
plugins: [plugin],
devtool: 'source-map'
Expand Down
7 changes: 0 additions & 7 deletions test/loader.js

This file was deleted.

0 comments on commit c74f6f0

Please sign in to comment.