Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add { relative: ... } support for replacements configuration option #46

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions src/aliasify.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ getReplacement = (file, aliases, regexps) ->
return false
else if typeof regexps[key] == "function"
return regexps[key](file, key, re)
else if regexps[key]? and regexps[key].relative?
return { relative: file.replace(re, regexps[key].relative) }
else
return file.replace(re, regexps[key])

Expand Down
8 changes: 8 additions & 0 deletions test/test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ describe "aliasify", ->
_ = require("underscore");
""")

it "should correctly transform a file-relative regexp replacement", (done) ->
process.chdir testWithRelativeConfigDir
jsFile = path.resolve __dirname, "../testFixtures/regexTestWithFileRelativeConfig/src/index.js"
transformTools.runTransform aliasify, jsFile, (err, result) ->
return done err if err
assert.equal result, "d3 = require('../shims/d3.js');"
done()

it "should work if there are no regexes and no aliases", ->
runTestWithConfig {
aliases: null
Expand Down
7 changes: 7 additions & 0 deletions testFixtures/regexTestWithFileRelativeConfig/config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
replacements: {
"(.*)": {
relative: "../shims/$1.js"
}
}
}
3 changes: 3 additions & 0 deletions testFixtures/regexTestWithFileRelativeConfig/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"aliasify": "./config/config.js"
}
1 change: 1 addition & 0 deletions testFixtures/regexTestWithFileRelativeConfig/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d3 = require("d3");