Skip to content

Commit 6a873bc

Browse files
committed
The React codebase is now resolved from the component's path.
This prevents users from being coupled to a particular version of React. Re markfinger#31
1 parent 237081d commit 6a873bc

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

django_react/bundle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ def get_webpack_config(path, translate=None, var=None):
3333
)
3434

3535
return BUNDLE_CONFIG.format(
36+
path_to_resolve=os.path.join(os.path.dirname(__file__), 'services', 'node_modules', 'resolve'),
3637
dir=os.path.dirname(path),
3738
file='./' + os.path.basename(path),
3839
var=var,
39-
path_to_react=os.path.join(os.path.dirname(__file__), 'services', 'node_modules', 'react'),
4040
translate_config=translate_config
4141
)
4242

django_react/services/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"dependencies": {
44
"babel-core": "^5.0.12",
55
"babel-loader": "^5.0.0",
6-
"react": "^0.13.1",
7-
"react-render": "^0.1.0",
6+
"react-render": "^0.2.4",
7+
"resolve": "^1.1.6",
88
"webpack": "^1.8.4"
99
}
1010
}

django_react/templates.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
BUNDLE_CONFIG = \
2-
"""module.exports = {{
2+
"""
3+
var resolve = require('{path_to_resolve}');
4+
5+
module.exports = {{
36
context: '{dir}',
47
entry: '{file}',
58
output: {{
@@ -10,7 +13,7 @@
1013
}},
1114
externals: [{{
1215
'react': {{
13-
commonjs2: '{path_to_react}',
16+
commonjs2: resolve.sync('react', {{basedir: '{dir}'}}),
1417
root: 'React'
1518
}}
1619
}}],

tests/test_functionality.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ def test_can_generate_a_var_from_a_path(self):
5050
def test_can_generate_a_webpack_config_for_a_js_component(self):
5151
config = get_webpack_config(HELLO_WORLD_COMPONENT_JS)
5252
expected = \
53-
"""module.exports = {
53+
"""
54+
var resolve = require('%s');
55+
56+
module.exports = {
5457
context: '%s',
5558
entry: './HelloWorld.js',
5659
output: {
@@ -61,23 +64,27 @@ def test_can_generate_a_webpack_config_for_a_js_component(self):
6164
},
6265
externals: [{
6366
'react': {
64-
commonjs2: '%s',
67+
commonjs2: resolve.sync('react', {basedir: '%s'}),
6568
root: 'React'
6669
}
6770
}],
6871
devtool: 'eval'
6972
};
7073
""" % (
74+
os.path.join(os.path.dirname(django_react.__file__), 'services', 'node_modules', 'resolve'),
75+
os.path.join(os.path.dirname(__file__), 'components'),
7176
os.path.join(os.path.dirname(__file__), 'components'),
72-
os.path.join(os.path.dirname(django_react.__file__), 'services', 'node_modules', 'react'),
7377
)
7478

7579
self.assertEqual(config, expected)
7680

7781
def test_can_generate_a_webpack_config_for_a_jsx_component(self):
7882
config = get_webpack_config(HELLO_WORLD_COMPONENT_JSX, translate=True)
7983
expected = \
80-
"""module.exports = {
84+
"""
85+
var resolve = require('%s');
86+
87+
module.exports = {
8188
context: '%s',
8289
entry: './HelloWorld.jsx',
8390
output: {
@@ -88,7 +95,7 @@ def test_can_generate_a_webpack_config_for_a_jsx_component(self):
8895
},
8996
externals: [{
9097
'react': {
91-
commonjs2: '%s',
98+
commonjs2: resolve.sync('react', {basedir: '%s'}),
9299
root: 'React'
93100
}
94101
}],
@@ -106,8 +113,9 @@ def test_can_generate_a_webpack_config_for_a_jsx_component(self):
106113
107114
};
108115
""" % (
116+
os.path.join(os.path.dirname(django_react.__file__), 'services', 'node_modules', 'resolve'),
117+
os.path.join(os.path.dirname(__file__), 'components'),
109118
os.path.join(os.path.dirname(__file__), 'components'),
110-
os.path.join(os.path.dirname(django_react.__file__), 'services', 'node_modules', 'react'),
111119
os.path.join(os.path.dirname(django_react.__file__), 'services', 'node_modules'),
112120
)
113121
self.assertEqual(config, expected)

0 commit comments

Comments
 (0)