Add React.version
getConfig needs to be a function because grunt.config.data.pkg.version isn't available at the time that grunt/config/jsx/jsx.js is required. Test Plan: grunt build, grunt lint, grunt test all work. After building, both react.js and react.min.js contain the version number.
Ben Alpert committed
Jul 16, 2013 at 20:38 UTC
5fd4467bf76b89b76df8bf909922f92e4fd07f7c
7 files changed
+44
-24
grunt/config/jsx/debug.json
deleted
-6
@@ -1,6 +0,0 @@
1
-{
2
- "debug": true,
3
- "constants": {
4
- "__DEV__": true
5
- }
6
-}
grunt/config/jsx/jsx.js
+35
-4
@@ -1,13 +1,25 @@
1
'use strict';
2
3
+var grunt = require('grunt');
4
+
5
var rootIDs = [
6
"React",
7
"ReactTransitionGroup"
8
];
9
10
+var getDebugConfig = function() {
11
+ return {
12
+ "debug": true,
13
+ "constants": {
14
+ "__VERSION__": grunt.config.data.pkg.version,
15
+ "__DEV__": true
16
+ }
17
+ };
18
+};
19
+
20
var debug = {
21
rootIDs: rootIDs,
10
- configFile: "grunt/config/jsx/debug.json",
22
+ getConfig: getDebugConfig,
23
sourceDir: "src",
24
outputDir: "build/modules"
25
};
@@ -16,7 +28,7 @@ var jasmine = {
28
rootIDs: [
29
"all"
30
],
19
- configFile: debug.configFile,
31
+ getConfig: getDebugConfig,
32
sourceDir: "vendor/jasmine",
33
outputDir: "build/jasmine"
34
};
@@ -26,18 +38,37 @@ var test = {
38
"test/all.js",
39
"**/__tests__/*.js"
40
]),
29
- configFile: "grunt/config/jsx/test.json",
41
+ getConfig: function() {
42
+ return {
43
+ "debug": true,
44
+ "mocking": true,
45
+ "constants": {
46
+ "__VERSION__": grunt.config.data.pkg.version,
47
+ "__DEV__": true
48
+ }
49
+ };
50
+ },
51
sourceDir: "src",
52
outputDir: "build/modules"
53
};
54
55
+
56
var release = {
57
rootIDs: rootIDs,
36
- configFile: "grunt/config/jsx/release.json",
58
+ getConfig: function() {
59
+ return {
60
+ "debug": false,
61
+ "constants": {
62
+ "__VERSION__": grunt.config.data.pkg.version,
63
+ "__DEV__": false
64
+ }
65
+ };
66
+ },
67
sourceDir: "src",
68
outputDir: "build/modules"
69
};
70
71
+
72
module.exports = {
73
debug: debug,
74
jasmine: jasmine,
grunt/config/jsx/release.json
deleted
-6
@@ -1,6 +0,0 @@
1
-{
2
- "debug": false,
3
- "constants": {
4
- "__DEV__": false
5
- }
6
-}
grunt/config/jsx/test.json
deleted
-7
@@ -1,7 +0,0 @@
1
-{
2
- "debug": true,
3
- "mocking": true,
4
- "constants": {
5
- "__DEV__": true
6
- }
7
-}
grunt/tasks/jsx.js
+4
-1
@@ -24,7 +24,7 @@ module.exports = function() {
24
});
25
26
args.push.apply(args, rootIDs);
27
- args.push("--config", config.configFile);
27
+ args.push("--config" /* from stdin */);
28
29
var child = spawn({
30
cmd: "bin/jsx-internal",
@@ -38,6 +38,9 @@ module.exports = function() {
38
}
39
});
40
41
+ child.stdin.write(JSON.stringify(config.getConfig()));
42
+ child.stdin.end();
43
+
44
child.stdout.pipe(process.stdout);
45
child.stderr.pipe(process.stderr);
46
};
src/.jshintrc
+1
@@ -19,6 +19,7 @@
19
"unused": "vars",
20
21
"globals": {
22
+ "__VERSION__": false,
23
"__DEV__": false,
24
"require": false,
25
"module": false,
src/core/React.js
+4
@@ -50,4 +50,8 @@ var React = {
50
isValidComponent: ReactComponent.isValidComponent
51
};
52
53
+// Version exists only in the open-source version of React, not in Facebook's
54
+// internal version.
55
+React.version = __VERSION__;
56
+
57
module.exports = React;