|
9 | 9 | using System.Collections.Generic; |
10 | 10 | using System.Diagnostics; |
11 | 11 | using System.IO; |
| 12 | +using System.Linq; |
12 | 13 | using System.Reflection; |
13 | 14 | using System.Text; |
14 | 15 | using System.Threading; |
@@ -130,7 +131,41 @@ IReactIdGenerator reactIdGenerator |
130 | 131 | _babelTransformer = new Lazy<IBabel>(() => |
131 | 132 | new Babel(this, _cache, _fileSystem, _fileCacheHash, _config) |
132 | 133 | ); |
133 | | - _lazyEngine = new Lazy<INodeJsEngine>(() => _config.NodeJsEngine()); |
| 134 | + _lazyEngine = new Lazy<INodeJsEngine>(() => |
| 135 | + { |
| 136 | + var allFiles = _config.Scripts |
| 137 | + .Concat(_config.ScriptsWithoutTransform) |
| 138 | + .Select(_fileSystem.MapPath); |
| 139 | + |
| 140 | + var nodeInstance = _config.CreateNodeJsInstance(); |
| 141 | + |
| 142 | + LoadUserScripts(nodeInstance); |
| 143 | + |
| 144 | + return nodeInstance; |
| 145 | + }); |
| 146 | + } |
| 147 | + |
| 148 | + |
| 149 | + /// <summary> |
| 150 | + /// Loads any user-provided scripts. Only scripts that don't need JSX transformation can |
| 151 | + /// run immediately here. JSX files are loaded in ReactEnvironment. |
| 152 | + /// </summary> |
| 153 | + /// <param name="engine">Engine to load scripts into</param> |
| 154 | + private void LoadUserScripts(INodeJsEngine engine) |
| 155 | + { |
| 156 | + foreach (var file in _config.ScriptsWithoutTransform) |
| 157 | + { |
| 158 | + try |
| 159 | + { |
| 160 | + engine.ExecuteFile(_fileSystem, file); |
| 161 | + } |
| 162 | + catch (NodeJsException ex) |
| 163 | + { |
| 164 | + } |
| 165 | + catch (IOException ex) |
| 166 | + { |
| 167 | + } |
| 168 | + } |
134 | 169 | } |
135 | 170 |
|
136 | 171 | /// <summary> |
@@ -168,7 +203,7 @@ public virtual string Version |
168 | 203 | /// </summary> |
169 | 204 | protected virtual void EnsureUserScriptsLoaded() |
170 | 205 | { |
171 | | - // Scripts already loaded into this environment, don't load them again |
| 206 | + // Scripts already loaded into this environment, don't load them agai n |
172 | 207 | if (Engine.HasVariable(USER_SCRIPTS_LOADED_KEY) || _config == null) |
173 | 208 | { |
174 | 209 | return; |
@@ -303,13 +338,6 @@ public virtual string GetInitJavaScript(bool clientOnly = false) |
303 | 338 | /// <returns>JavaScript for all components</returns> |
304 | 339 | public virtual void GetInitJavaScript(TextWriter writer, bool clientOnly = false) |
305 | 340 | { |
306 | | - // Propagate any server-side console.log calls to corresponding client-side calls. |
307 | | - if (!clientOnly && _components.Count != 0) |
308 | | - { |
309 | | - var consoleCalls = Execute<string>("console.getCalls()"); |
310 | | - writer.Write(consoleCalls); |
311 | | - } |
312 | | - |
313 | 341 | foreach (var component in _components) |
314 | 342 | { |
315 | 343 | if (!component.ServerOnly) |
|
0 commit comments