@@ -3,6 +3,7 @@ var execFile = require('child_process').execFile
3
3
var path = require ( 'path' )
4
4
var getOptions = require ( 'loader-utils' ) . getOptions
5
5
var defaults = require ( 'lodash.defaults' )
6
+ var util = require ( 'util' )
6
7
7
8
function pushAll ( dest , src ) {
8
9
Array . prototype . push . apply ( dest , src )
@@ -74,16 +75,27 @@ function transformSource (runner, config, source, map, callback) {
74
75
runner . arguments . concat (
75
76
runnerPath ,
76
77
ioDelimiter ,
77
- config . engine ,
78
- config . timeout
78
+ config . engine
79
79
) ,
80
+ { timeout : config . timeoutMs } ,
80
81
function ( error , stdout , stderr ) {
81
82
// Output is delimited to filter out unwanted warnings or other output
82
83
// that we don't want in our files.
83
84
var sourceRegex = new RegExp ( ioDelimiter + '([\\s\\S]+)' + ioDelimiter )
84
85
var matches = stdout . match ( sourceRegex )
85
86
var transformedSource = matches && matches [ 1 ]
86
- callback ( error , transformedSource , map )
87
+ if ( error && error . signal === 'SIGTERM' ) {
88
+ if ( config . timeoutMs ) {
89
+ callback ( new Error (
90
+ 'rails-erb-loader took longer than the specified ' + config . timeoutMs +
91
+ 'ms timeout'
92
+ ) )
93
+ } else {
94
+ callback ( error )
95
+ }
96
+ } else {
97
+ callback ( error , transformedSource , map )
98
+ }
87
99
}
88
100
)
89
101
child . stdin . on ( 'error' , function ( error ) {
@@ -132,6 +144,17 @@ function addDependencies (loader, paths, callback) {
132
144
} )
133
145
}
134
146
147
+ var setTimeoutMsFromTimeoutInPlace = util . deprecate ( function ( config ) {
148
+ if ( config . timeoutMs != null ) {
149
+ throw new TypeError (
150
+ 'Both options `timeout` and `timeoutMs` were set -- please just use ' +
151
+ '`timeoutMs`'
152
+ )
153
+ }
154
+ config . timeoutMs = config . timeout * 1000
155
+ delete config . timeout
156
+ } , 'rails-erb-loader `timeout` option is deprecated in favor of `timeoutMs`' )
157
+
135
158
module . exports = function railsErbLoader ( source , map ) {
136
159
var loader = this
137
160
@@ -144,10 +167,13 @@ module.exports = function railsErbLoader (source, map) {
144
167
var config = defaults ( { } , getOptions ( loader ) , {
145
168
dependenciesRoot : 'app' ,
146
169
runner : './bin/rails runner' ,
147
- engine : 'erb' ,
148
- timeout : 0
170
+ engine : 'erb'
149
171
} )
150
172
173
+ if ( config . timeout !== undefined ) {
174
+ setTimeoutMsFromTimeoutInPlace ( config )
175
+ }
176
+
151
177
// Dependencies are only useful in development, so don't bother searching the
152
178
// file for them otherwise.
153
179
var dependencies = process . env . NODE_ENV === 'development'
0 commit comments