Skip to content

Commit 18eb4a6

Browse files
committed
fix(transitioner): catch whitespaces properly
1 parent a26b6fd commit 18eb4a6

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/transitions/try-require.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ var installed = false;
77
var removedGlobals = {
88
'dbm is not defined': globalHandler,
99
'async is not defined': globalHandler,
10+
'Cannot find module \'db-migrate\'': missingDBMigrate,
1011
'Cannot find module \'async\'': installAsync
1112
};
1213

14+
function missingDBMigrate(migration, retry) {
15+
16+
return globalHandler(migration.path, retry);
17+
}
18+
1319
function installAsync(migration, retry) {
1420

1521
var cmd = [ 'install', '--save', 'async' ];
@@ -29,18 +35,22 @@ function installAsync(migration, retry) {
2935
}
3036

3137
function globalHandler(migration, retry) {
32-
3338
var data = fs.readFileSync(migration, 'utf8');
3439
data = data.replace(
35-
/^dbm = dbm \|\| require\(\s+'db-migrate'\s+\)/m,
40+
/^dbm = dbm \|\| require\((?!\s)?'db-migrate'(?!\s)?\)/m,
41+
'var dbm'
42+
);
43+
44+
data = data.replace(
45+
/^var dbm = global\.dbm \|\| require\((?!\s)?'db-migrate'(?!\s)?\)/m,
3646
'var dbm'
3747
);
3848

3949
if(data.indexOf('async = async || require') !== -1) {
4050

4151
handled = true;
4252
data = data.replace(
43-
/^async = async \|\| require\(\s+'async'\s+\)/m,
53+
/^async = async \|\| require\((?!\s)?'async'(?!\s)?\)/m,
4454
'var async = require( \'async\' )'
4555
);
4656
}

0 commit comments

Comments
 (0)