/// <summary>
        /// Loads any user-provided scripts. Only scripts that don't need JSX transformation can
        /// run immediately here. JSX files are loaded in ReactEnvironment.
        /// </summary>
        /// <param name="engine">Engine to load scripts into</param>
        private void LoadUserScripts(IJsEngine engine)
        {
            if (_config.ReactAppBuildPath != null)
            {
                var manifest = ReactAppAssetManifest.LoadManifest(_config, _fileSystem, _cache, useCacheRead: false);
                foreach (var file in manifest.Entrypoints?.Where(x => x != null && x.EndsWith(".js")))
                {
                    if (_config.AllowJavaScriptPrecompilation &&
                        engine.TryExecuteFileWithPrecompilation(_cache, _fileSystem, file))
                    {
                        // Do nothing.
                    }
                    else
                    {
                        engine.ExecuteFile(_fileSystem, file);
                    }
                }
            }

            foreach (var file in _config.ScriptsWithoutTransform)
            {
                try
                {
                    if (_config.AllowJavaScriptPrecompilation &&
                        engine.TryExecuteFileWithPrecompilation(_cache, _fileSystem, file))
                    {
                        // Do nothing.
                    }
                    else
                    {
                        engine.ExecuteFile(_fileSystem, file);
                    }
                }
                catch (JsException ex)
                {
                    // We can't simply rethrow the exception here, as it's possible this is running
                    // on a background thread (ie. as a response to a file changing). If we did
                    // throw the exception here, it would terminate the entire process. Instead,
                    // save the exception, and then just rethrow it later when getting the engine.
                    _scriptLoadException = new ReactScriptLoadException(string.Format(
                                                                            "Error while loading \"{0}\": {1}",
                                                                            file,
                                                                            ex.Message
                                                                            ), ex);
                }
                catch (IOException ex)
                {
                    _scriptLoadException = new ReactScriptLoadException(ex.Message, ex);
                }
            }
        }
Example #2
0
 private ReactAppAssetManifest GetAppManifest() => ReactAppAssetManifest.LoadManifest(_config, _fileSystem, _cache, useCacheRead: true);