1
1
'use strict' ;
2
2
3
+ var path = require ( 'path' ) ;
4
+
3
5
var babel = require ( 'babel' ) ;
4
6
var coffee = require ( 'coffee-script' ) ;
5
7
@@ -19,15 +21,16 @@ var babelPluginDEV = require('fbjs/scripts/babel/dev-expression');
19
21
var babelPluginModules = require ( 'fbjs/scripts/babel/rewrite-modules' ) ;
20
22
21
23
module . exports = {
22
- process : function ( src , path ) {
23
- if ( path . match ( / \. c o f f e e $ / ) ) {
24
+ process : function ( src , filePath ) {
25
+ if ( filePath . match ( / \. c o f f e e $ / ) ) {
24
26
return coffee . compile ( src , { 'bare' : true } ) ;
25
27
}
26
- if ( path . match ( / \. t s $ / ) && ! path . match ( / \. d \. t s $ / ) ) {
27
- return ts . compile ( src , path ) ;
28
+ if ( filePath . match ( / \. t s $ / ) && ! filePath . match ( / \. d \. t s $ / ) ) {
29
+ return ts . compile ( src , filePath ) ;
28
30
}
29
31
// TODO: make sure this stays in sync with gulpfile
30
- if ( ! path . match ( / \/ n o d e _ m o d u l e s \/ / ) && ! path . match ( / \/ t h i r d _ p a r t y \/ / ) ) {
32
+ if ( ! filePath . match ( / \/ n o d e _ m o d u l e s \/ / ) &&
33
+ ! filePath . match ( / \/ t h i r d _ p a r t y \/ / ) ) {
31
34
var rv = babel . transform ( src , {
32
35
nonStandard : true ,
33
36
blacklist : [
@@ -38,11 +41,26 @@ module.exports = {
38
41
'es7.trailingFunctionCommas' ,
39
42
] ,
40
43
plugins : [ babelPluginDEV , babelPluginModules ] ,
41
- ignore : [ 'third_party' ] ,
42
- filename : path ,
44
+ filename : filePath ,
43
45
retainLines : true ,
44
46
_moduleMap : moduleMap ,
45
47
} ) . code ;
48
+
49
+ // hax to turn fbjs/lib/foo into /path/to/node_modules/fbjs/lib/foo
50
+ // because jest is slooow with node_modules paths (facebook/jest#465)
51
+ rv = rv . replace (
52
+ / r e q u i r e \( ' ( f b j s \/ l i b \/ .+ ) ' \) / g,
53
+ function ( call , arg ) {
54
+ return (
55
+ 'require(' +
56
+ JSON . stringify (
57
+ path . join ( __dirname , '../../node_modules' , arg )
58
+ ) +
59
+ ')'
60
+ ) ;
61
+ }
62
+ ) ;
63
+
46
64
return rv ;
47
65
}
48
66
return src ;
0 commit comments