From 2a204960663d854a85d84772c326bd75fbf40535 Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Sat, 23 May 2015 21:07:33 +1000 Subject: [PATCH 001/118] Removed the PATH_TO_REACT setting and updated to react-render@0.3 --- README.md | 9 --------- example/package.json | 2 +- react/bundle.py | 13 +++++-------- react/conf.py | 3 --- tests/package.json | 2 +- tests/test_bundling.py | 27 +++------------------------ 6 files changed, 10 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 0b38658..88880dc 100644 --- a/README.md +++ b/README.md @@ -269,15 +269,6 @@ translated and bundled assets. Default: `None` -### PATH_TO_REACT - -An import path that will be used when rendering bundled components. - -If not defined, the bundler will default to using js-host's SOURCE_ROOT via -`os.path.join(SOURCE_ROOT, 'node_modules', 'react')`. - -Default: `None` - ### TRANSLATE_TEST When bundling a component with `translate=True`, this JavaScript regex is tested against every file to diff --git a/example/package.json b/example/package.json index 06932c6..d0c027f 100644 --- a/example/package.json +++ b/example/package.json @@ -8,7 +8,7 @@ "marked": "^0.3.3", "node-libs-browser": "^0.5.0", "react": "^0.13.3", - "react-render": "^0.2.4", + "react-render": "^0.3.0", "webpack": "^1.9.6", "webpack-wrapper": "^0.2.2" } diff --git a/react/bundle.py b/react/bundle.py index edc6846..05becf7 100644 --- a/react/bundle.py +++ b/react/bundle.py @@ -9,7 +9,7 @@ from .conf import settings -def bundle_component(path, translate=None, path_to_react=None, devtool=None): +def bundle_component(path, translate=None, devtool=None): if not os.path.isabs(path): abs_path = staticfiles.find(path) if not abs_path: @@ -19,7 +19,7 @@ def bundle_component(path, translate=None, path_to_react=None, devtool=None): if not os.path.exists(path): raise ComponentSourceFileNotFound(path) - config = generate_config_for_component(path, translate=translate, path_to_react=path_to_react, devtool=devtool) + config = generate_config_for_component(path, translate=translate, devtool=devtool) config_file = generate_config_file(config) @@ -44,7 +44,7 @@ def generate_config_file(config): ) -def generate_config_for_component(path, translate=None, path_to_react=None, devtool=None): +def generate_config_for_component(path, translate=None, devtool=None): """ Generates a webpack config object to bundle a component """ @@ -53,9 +53,6 @@ def generate_config_for_component(path, translate=None, path_to_react=None, devt node_modules = os.path.join(js_host_settings.SOURCE_ROOT, 'node_modules') - if path_to_react is None: - path_to_react = settings.PATH_TO_REACT or os.path.join(node_modules, 'react') - config = { 'context': js_path_join(os.path.dirname(path)), 'entry': './{}'.format(os.path.basename(path)), @@ -67,11 +64,11 @@ def generate_config_for_component(path, translate=None, path_to_react=None, devt }, 'externals': [{ 'react': { - 'commonjs2': js_path_join(path_to_react), + 'commonjs2': 'react', 'root': 'React' }, 'react/addons': { - 'commonjs2': js_path_join(path_to_react), + 'commonjs2': 'react', 'root': 'React' } }] diff --git a/react/conf.py b/react/conf.py index e263b4f..016e484 100644 --- a/react/conf.py +++ b/react/conf.py @@ -5,9 +5,6 @@ class Conf(conf.Conf): # The devtool that webpack uses when bundling components DEVTOOL = None - # The default import path used when rendering components - PATH_TO_REACT = None - # A JavaScript regex which is used to test if a file should have the babel # loader run over it TRANSLATE_TEST = '/.jsx?$/' diff --git a/tests/package.json b/tests/package.json index 4aa1fd0..c248bfe 100644 --- a/tests/package.json +++ b/tests/package.json @@ -6,7 +6,7 @@ "js-host": "^0.11.4", "node-libs-browser": "^0.5.0", "react": "^0.13.3", - "react-render": "^0.2.4", + "react-render": "^0.3.0", "webpack": "^1.9.6", "webpack-wrapper": "^0.2.2" } diff --git a/tests/test_bundling.py b/tests/test_bundling.py index 2c2d05f..028a827 100644 --- a/tests/test_bundling.py +++ b/tests/test_bundling.py @@ -27,7 +27,7 @@ def test_can_generate_js_literal_to_join_paths(self): 'path.join.apply(path, ["' + '", "'.join(split_path(Components.HELLO_WORLD_JS)) + '"])' ) - def validate_generated_config(self, config, path, translate=None, path_to_react=None, devtool=None): + def validate_generated_config(self, config, path, translate=None, devtool=None): self.assertIsInstance(config['context'], JS) self.assertEqual( config['context'].content, @@ -67,20 +67,10 @@ def validate_generated_config(self, config, path, translate=None, path_to_react= var ) - path_to_react = path_to_react or os.path.join(TEST_ROOT, 'node_modules', 'react') - - self.assertIsInstance(config['externals'][0]['react']['commonjs2'], JS) - self.assertEqual( - config['externals'][0]['react']['commonjs2'].content, - 'path.join.apply(path, ["' + '", "'.join(split_path(path_to_react)) + '"])' - ) + self.assertEqual(config['externals'][0]['react']['commonjs2'], 'react',) self.assertEqual(config['externals'][0]['react']['root'], 'React') - self.assertIsInstance(config['externals'][0]['react/addons']['commonjs2'], JS) - self.assertEqual( - config['externals'][0]['react/addons']['commonjs2'].content, - 'path.join.apply(path, ["' + '", "'.join(split_path(path_to_react)) + '"])' - ) + self.assertEqual(config['externals'][0]['react/addons']['commonjs2'], 'react') self.assertEqual(config['externals'][0]['react/addons']['root'], 'React') if devtool: @@ -110,17 +100,6 @@ def test_can_generate_a_webpack_config_for_a_js_component_with_a_devtool(self): config = generate_config_for_component(Components.HELLO_WORLD_JS, devtool='eval') self.validate_generated_config(config, Components.HELLO_WORLD_JS, devtool='eval') - def test_can_generate_a_webpack_config_with_a_path_to_react(self): - config = generate_config_for_component( - Components.HELLO_WORLD_JS, - path_to_react='/abs/path/to/node_modules/react' - ) - self.validate_generated_config( - config, - Components.HELLO_WORLD_JS, - path_to_react='/abs/path/to/node_modules/react' - ) - def test_can_generate_a_webpack_config_for_a_jsx_component(self): config = generate_config_for_component(Components.HELLO_WORLD_JSX, translate=True) self.validate_generated_config(config, Components.HELLO_WORLD_JSX, translate=True) From 357d17bf948c7986d3321af31dee61e37acb0576 Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Sun, 24 May 2015 19:47:04 +1000 Subject: [PATCH 002/118] Updated the change log --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bef46b9..9a9ad8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Changelog ========= + +### 0.13.1 (16/5/2015) + +- Fixed a potential path issue in config files +- Replaced the webpack-service dependency with webpack-wrapper. + ### 0.8.0 (26/1/2015) - Boosting render performance by using a dedicated render server. From 78374357185031ebfcc4baea9a13ebf61e0a49bc Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Sun, 28 Jun 2015 21:05:32 +1000 Subject: [PATCH 003/118] Docs --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 88880dc..77094a6 100644 --- a/README.md +++ b/README.md @@ -281,7 +281,9 @@ Running the tests ----------------- ```bash -mkvirtualenv django-react pip install -r requirements.txt +cd tests +npm install +cd .. python runtests.py ``` From ccb39e8e26bcf774b31beb360ff8cc280920170c Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Sun, 28 Jun 2015 21:18:28 +1000 Subject: [PATCH 004/118] Bump js-host --- example/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/package.json b/example/package.json index d0c027f..460b40e 100644 --- a/example/package.json +++ b/example/package.json @@ -4,7 +4,7 @@ "babel-core": "^5.4.3", "babel-loader": "^5.1.0", "jquery": "^2.1.4", - "js-host": "^0.11.4", + "js-host": "^0.12.0", "marked": "^0.3.3", "node-libs-browser": "^0.5.0", "react": "^0.13.3", From 917cd1fbb0d180250ec19542a9d0add3bf17c4b1 Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Sun, 28 Jun 2015 21:18:38 +1000 Subject: [PATCH 005/118] Bump js-host --- tests/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/package.json b/tests/package.json index c248bfe..251a5d3 100644 --- a/tests/package.json +++ b/tests/package.json @@ -3,7 +3,7 @@ "dependencies": { "babel-core": "^5.4.3", "babel-loader": "^5.1.0", - "js-host": "^0.11.4", + "js-host": "^0.12.0", "node-libs-browser": "^0.5.0", "react": "^0.13.3", "react-render": "^0.3.0", From 56aa2713304d206cc6e193adcced6ed6fff8b02f Mon Sep 17 00:00:00 2001 From: Mark Finger Date: Tue, 7 Jul 2015 14:43:22 +1000 Subject: [PATCH 006/118] Removed the js-host and webpack integrations. Mindful of the issues experienced with js-host and the limited workflow offered by the webpack integration, the project is being shifted towards a utility role. Pre-rendering is the only thing that the library will perform. Access to a render server will be opt-in, rather than required. --- example/README.md | 2 +- example/host.config.js | 9 - example/package.json | 2 + example/requirements.txt | 1 - example/static/css/main.css | 15 - example/static/jsx/Comment.jsx | 16 - example/static/jsx/CommentBox.jsx | 58 - example/static/jsx/CommentForm.jsx | 38 - example/static/jsx/CommentList.jsx | 19 - .../vendor/bootstrap/css/bootstrap-theme.css | 476 - .../bootstrap/css/bootstrap-theme.css.map | 1 - .../bootstrap/css/bootstrap-theme.min.css | 5 - .../static/vendor/bootstrap/css/bootstrap.css | 6566 ------ .../vendor/bootstrap/css/bootstrap.css.map | 1 - .../vendor/bootstrap/css/bootstrap.min.css | 5 - .../fonts/glyphicons-halflings-regular.eot | Bin 20127 -> 0 bytes .../fonts/glyphicons-halflings-regular.svg | 288 - .../fonts/glyphicons-halflings-regular.ttf | Bin 45404 -> 0 bytes .../fonts/glyphicons-halflings-regular.woff | Bin 23424 -> 0 bytes .../fonts/glyphicons-halflings-regular.woff2 | Bin 18028 -> 0 bytes .../static/vendor/bootstrap/js/bootstrap.js | 2306 -- .../vendor/bootstrap/js/bootstrap.min.js | 7 - example/static/vendor/bootstrap/js/npm.js | 13 - example/static/vendor/react/react-0.13.1.js | 19541 ---------------- example/templates/index.html | 36 +- package.json | 10 + react/bundle.py | 142 - react/conf.py | 9 +- react/exceptions.py | 6 +- react/render.py | 117 +- react/server.py | 32 + react/templates.py | 12 - tests/__init__.py | 29 +- tests/host.config.js | 11 - tests/package.json | 13 - tests/perf.py | 4 - tests/settings.py | 26 +- tests/test_bundling.py | 193 - tests/test_django_integration.py | 11 +- tests/test_rendering.py | 79 +- tests/test_server.js | 32 + tests/utils.py | 28 - 42 files changed, 144 insertions(+), 30015 deletions(-) delete mode 100644 example/host.config.js delete mode 100644 example/static/css/main.css delete mode 100644 example/static/jsx/Comment.jsx delete mode 100644 example/static/jsx/CommentBox.jsx delete mode 100644 example/static/jsx/CommentForm.jsx delete mode 100644 example/static/jsx/CommentList.jsx delete mode 100644 example/static/vendor/bootstrap/css/bootstrap-theme.css delete mode 100644 example/static/vendor/bootstrap/css/bootstrap-theme.css.map delete mode 100644 example/static/vendor/bootstrap/css/bootstrap-theme.min.css delete mode 100644 example/static/vendor/bootstrap/css/bootstrap.css delete mode 100644 example/static/vendor/bootstrap/css/bootstrap.css.map delete mode 100644 example/static/vendor/bootstrap/css/bootstrap.min.css delete mode 100644 example/static/vendor/bootstrap/fonts/glyphicons-halflings-regular.eot delete mode 100644 example/static/vendor/bootstrap/fonts/glyphicons-halflings-regular.svg delete mode 100644 example/static/vendor/bootstrap/fonts/glyphicons-halflings-regular.ttf delete mode 100644 example/static/vendor/bootstrap/fonts/glyphicons-halflings-regular.woff delete mode 100644 example/static/vendor/bootstrap/fonts/glyphicons-halflings-regular.woff2 delete mode 100644 example/static/vendor/bootstrap/js/bootstrap.js delete mode 100644 example/static/vendor/bootstrap/js/bootstrap.min.js delete mode 100644 example/static/vendor/bootstrap/js/npm.js delete mode 100644 example/static/vendor/react/react-0.13.1.js create mode 100644 package.json delete mode 100644 react/bundle.py create mode 100644 react/server.py delete mode 100644 react/templates.py delete mode 100644 tests/host.config.js delete mode 100644 tests/package.json delete mode 100644 tests/test_bundling.py create mode 100644 tests/test_server.js delete mode 100644 tests/utils.py diff --git a/example/README.md b/example/README.md index 3b61e8c..fc5add6 100644 --- a/example/README.md +++ b/example/README.md @@ -18,4 +18,4 @@ npm install python example.py ``` -And visit [http://127.0.0.1:8000](http://127.0.0.1:8000) +And visit [http://127.0.0.1:5000](http://127.0.0.1:5000) diff --git a/example/host.config.js b/example/host.config.js deleted file mode 100644 index 66cfe60..0000000 --- a/example/host.config.js +++ /dev/null @@ -1,9 +0,0 @@ -var reactRender = require('react-render'); -var webpackWrapper = require('webpack-wrapper'); - -module.exports = { - functions: { - react: reactRender, - webpack: webpackWrapper - } -}; \ No newline at end of file diff --git a/example/package.json b/example/package.json index d0c027f..cd48dbf 100644 --- a/example/package.json +++ b/example/package.json @@ -3,6 +3,8 @@ "dependencies": { "babel-core": "^5.4.3", "babel-loader": "^5.1.0", + "body-parser": "^1.13.2", + "express": "^4.13.1", "jquery": "^2.1.4", "js-host": "^0.11.4", "marked": "^0.3.3", diff --git a/example/requirements.txt b/example/requirements.txt index 9d5b9f8..0ae014d 100644 --- a/example/requirements.txt +++ b/example/requirements.txt @@ -1,3 +1,2 @@ flask==0.10.1 -js-host react \ No newline at end of file diff --git a/example/static/css/main.css b/example/static/css/main.css deleted file mode 100644 index 0a33023..0000000 --- a/example/static/css/main.css +++ /dev/null @@ -1,15 +0,0 @@ -h1 { - border-bottom: 1px solid #ddd; -} - -h2 { - border-bottom: 1px solid #eee; -} - -form label { - display: block; -} - -form button { - margin-left: 5px; -} \ No newline at end of file diff --git a/example/static/jsx/Comment.jsx b/example/static/jsx/Comment.jsx deleted file mode 100644 index 6df14e7..0000000 --- a/example/static/jsx/Comment.jsx +++ /dev/null @@ -1,16 +0,0 @@ -import React from 'react'; -import marked from 'marked'; - -export default React.createClass({ - render() { - var rawMarkup = marked(this.props.text); - return ( -
-

- {this.props.author} -

- -
- ); - } -}); \ No newline at end of file diff --git a/example/static/jsx/CommentBox.jsx b/example/static/jsx/CommentBox.jsx deleted file mode 100644 index c5bf0b3..0000000 --- a/example/static/jsx/CommentBox.jsx +++ /dev/null @@ -1,58 +0,0 @@ -import React from 'react'; -import $ from 'jquery'; -import CommentList from './CommentList.jsx'; -import CommentForm from './CommentForm.jsx'; - -export default React.createClass({ - getInitialState() { - return {comments: this.props.comments}; - }, - handleCommentSubmit(comment) { - var comments = this.state.comments; - comments.push(comment); - this.setState({comments: comments}, () => { - this.postComment(comment); - }); - }, - postComment(comment) { - $.ajax({ - url: this.props.url, - type: 'POST', - dataType: 'json', - data: comment, - success: (data) => { - this.setState({comments: data.comments}); - }, - error: (xhr, status, err) => { - console.error(this.props.url, status, err.toString()); - } - }); - }, - getComments() { - $.ajax({ - url: this.props.url, - dataType: 'json', - success: (data) => { - this.setState({comments: data.comments}); - }, - error: (xhr, status, err) => { - console.error(this.props.url, status, err.toString()); - }, - complete: this.pollForNewComments - }); - }, - pollForNewComments() { - setTimeout(this.getComments, this.props.pollInterval); - }, - componentDidMount() { - this.pollForNewComments(); - }, - render() { - return ( -
- - -
- ); - } -}); \ No newline at end of file diff --git a/example/static/jsx/CommentForm.jsx b/example/static/jsx/CommentForm.jsx deleted file mode 100644 index 1c657f2..0000000 --- a/example/static/jsx/CommentForm.jsx +++ /dev/null @@ -1,38 +0,0 @@ -import React from 'react'; - -export default React.createClass({ - handleSubmit(e) { - e.preventDefault(); - var author = this.refs.author.getDOMNode().value.trim(); - var text = this.refs.text.getDOMNode().value.trim(); - if (!text || !author) { - return; - } - this.props.onCommentSubmit({author: author, text: text}); - this.refs.author.getDOMNode().value = ''; - this.refs.text.getDOMNode().value = ''; - }, - render() { - return ( -
-

Submit a comment

-
- -
-
-