ProcessChangeRequest will determine which type of change request is required for computation of the request file
(filePath string, opts *ChangeRequestOpts)
| 76 | |
| 77 | // ProcessChangeRequest will determine which type of change request is required for computation of the request file |
| 78 | func (s *devSession) DoFileChangeRequest(filePath string, opts *ChangeRequestOpts) error { |
| 79 | // if this file has been recently processed (specified by the timeout flag), do not process it. |
| 80 | if !s.ChangeRequest.IsWithinRage(filePath, opts.SafeFileTimeout) { |
| 81 | return parseerror.FromError(ErrFileTooRecentlyProcessed, filePath) |
| 82 | } |
| 83 | |
| 84 | // file detected in the orbit output, we don't want to process any of these EVER |
| 85 | if strings.Contains(filePath, ".orbit") { |
| 86 | return nil |
| 87 | } |
| 88 | |
| 89 | // root components aka "pages" are searched, if it is not |
| 90 | // null we can assume that the bundle is not a before identified page |
| 91 | root := s.RootComponents[filePath] |
| 92 | |
| 93 | // determine if the bundle is currently active in the browser |
| 94 | // if so recompute the bundle and send refresh signal back to browser |
| 95 | if root != nil && opts.HotReload.IsActiveBundle(root.BundleKey()) { |
| 96 | err := s.DirectFileChangeRequest(filePath, root, opts) |
| 97 | if err != nil { |
| 98 | return parseerror.FromError(err, filePath) |
| 99 | } |
| 100 | |
| 101 | err = opts.HotReload.ReloadSignal() |
| 102 | if err != nil { |
| 103 | return parseerror.FromError(err, filePath) |
| 104 | } |
| 105 | |
| 106 | // no need to continue, root file has already been processed. |
| 107 | return nil |
| 108 | } |
| 109 | |
| 110 | // determine if the change request is a new page, and attempt to build it |
| 111 | // TODO(guy) magic string : "pages" allow support for this keyword from a flag |
| 112 | if strings.Contains(filePath, "pages/") { |
| 113 | err := s.NewPageFileChangeRequest(context.Background(), filePath) |
| 114 | |
| 115 | if err != nil { |
| 116 | return parseerror.FromError(err, filePath) |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | // determine if the source exists as a page dependency, if so, recompute and send refresh signal |
| 121 | sources := s.SourceMap.FindRoot(filePath) |
| 122 | if len(sources) > 0 { |
| 123 | // component is not root, we need to find in which tree(s) the component exists & execute |
| 124 | // a repack for each of those components & their dependent branches. |
| 125 | err := s.IndirectFileChangeRequest(sources, filePath, opts) |
| 126 | if err != nil { |
| 127 | return parseerror.FromError(err, filePath) |
| 128 | } |
| 129 | |
| 130 | err = opts.HotReload.ReloadSignal() |
| 131 | if err != nil { |
| 132 | return parseerror.FromError(err, filePath) |
| 133 | } |
| 134 | } |
| 135 |