Skip to content

Commit 6e0ed17

Browse files
committed
Fix #6: issue with relative paths
Transforms specified in package.json were being resolved relative to the current file, as oppoosed to relative to the package.json file. This would cause the resolve to fail on files not in the root directory if the transform was specified as a relative file.
1 parent 85dc6ab commit 6e0ed17

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

fixtures/relative/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const regl = require('regl/lib/util/check')
2+
3+
console.log(regl)

fixtures/relative/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "fixture",
3+
"version": "1.0.0",
4+
"browserify": {
5+
"transform": [
6+
"brfs"
7+
]
8+
}
9+
}

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function loader (source) {
4343
}
4444

4545
resolve(name, {
46-
basedir: dirname
46+
basedir: pkgDir
4747
}, function (err, name) {
4848
if (err) return next(err)
4949

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
"devDependencies": {
2222
"brfs": "^1.4.2",
2323
"npm-which": "^2.0.0",
24+
"regl": "^1.3.0",
2425
"standard": "^5.4.1",
2526
"tap-spec": "^4.1.1",
2627
"tape": "^4.4.0",
2728
"through2": "^2.0.0",
28-
"webpack": "^1.12.9"
29+
"webpack": "^2.2.1"
2930
},
3031
"scripts": {
3132
"test": "node test.js | tspec",

test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,33 @@ test('ify-loader', function (t) {
3939
})
4040
})
4141

42+
test('relative transforms', function (t) {
43+
const wpack = which.sync('webpack', { cwd: __dirname })
44+
const input = path.join(__dirname, 'fixtures', 'relative', 'index.js')
45+
const output = path.join(__dirname, 'fixtures', 'relative', 'bundle.js')
46+
47+
t.plan(2)
48+
49+
try {
50+
fs.unlinkSync(output)
51+
} catch (e) {}
52+
53+
spawn(wpack, [
54+
input,
55+
output,
56+
'--module-bind', 'js=' + __dirname
57+
], {
58+
stdio: ['pipe', 'pipe', 2]
59+
}).once('exit', function (code) {
60+
t.doesNotThrow(function () {
61+
fs.statSync(output)
62+
}, 'bundle.js was created')
63+
fs.unlinkSync(output)
64+
65+
t.ok(!code, 'exit code was 0')
66+
})
67+
})
68+
4269
test('error handling', function (t) {
4370
const wpack = which.sync('webpack', { cwd: __dirname })
4471
const input = path.join(__dirname, 'fixtures', 'errors', 'index.js')

0 commit comments

Comments
 (0)