Repository: ProjectEvergreen/greenwood (js)

Issue:
intercept lifecycle for HTML based resource plugins not getting called during static compilation (when `prerender: false`)
## Type of Change
- [ ] New Feature Request
- [ ] Documentation / Website
- [ ] Improvement / Suggestion
- [x] Bug
- [ ] Other (please clarify below)

## Summary
As part of working on #855 , I noticed that the HTML Includes plugin was not running anymore and the [specs were failing unless I had `prerender: true` in my _greenwood.config.js_](https://github.com/ProjectEvergreen/greenwood/pull/857/files#diff-1e34476069d5db6d510e2561553c5c48ad4f9e0c2d7aa8d28563e8c807219d55R4).

## Details
The reason for this looks to be that for [static only build, Greenwood only serves, but never calls the `intercept` lifecycle](https://github.com/ProjectEvergreen/greenwood/blob/v0.21.0/packages/cli/src/lifecycles/prerender.js#L111), which means that the plugin will never get called.  This means that #846 would break too when merged and used in a similar scenario.

Pull request:
handle HTML intercepting for static compilations
<!--
## Submitting a Pull Request
We love contributions and appreciate any help you can offer!
-->

## Related Issue
resolves #858 

## Summary of Changes
1. Added `intercept` logic to `staticCompilation` for when `prerender: false`
1. Covered with "forced" test case (will undo in #857 )

Patch:
diff --git a/packages/cli/src/lifecycles/prerender.js b/packages/cli/src/lifecycles/prerender.js
index 28910717..25204533 100644
--- a/packages/cli/src/lifecycles/prerender.js
+++ b/packages/cli/src/lifecycles/prerender.js
@@ -2,6 +2,31 @@ import { BrowserRunner } from '../lib/browser.js';
 import fs from 'fs';
 import path from 'path';
 
+async function interceptPage(compilation, contents, route) {
+  const headers = {
+    request: { 'accept': 'text/hml', 'content-type': 'text/html' },
+    response: { 'content-type': 'text/html' }
+  };
+  const interceptResources = compilation.config.plugins.filter((plugin) => {
+    return plugin.type === 'resource' && !plugin.isGreenwoodDefaultPlugin;
+  }).map((plugin) => {
+    return plugin.provider(compilation);
+  }).filter((provider) => {
+    return provider.shouldIntercept && provider.intercept;
+  });
+
+  const htmlIntercepted = await interceptResources.reduce(async (htmlPromise, resource) => {
+    const html = (await htmlPromise).body || '';
+    const shouldIntercept = await resource.shouldIntercept(route, html, headers);
+
+    return shouldIntercept
+      ? resource.intercept(route, html, headers)
+      : Promise.resolve(html);
+  }, Promise.resolve(contents));
+
+  return htmlIntercepted;
+}
+
 async function optimizePage(compilation, contents, route, outputPath, outputDir) {
   const optimizeResources = compilation.config.plugins.filter((plugin) => {
     return plugin.type === 'resource';
@@ -108,7 +133,9 @@ async function staticRenderCompilation(compilation) {
   
   await Promise.all(pages.map(async (page) => {
     const { route, outputPath } = page;
-    const response = await htmlResource.serve(route);
+    let response = await htmlResource.serve(route);
+
+    response = await interceptPage(compilation, response, route);
 
     await optimizePage(compilation, response.body, route, outputPath, scratchDir);
 


Test patch:
diff --git a/packages/plugin-include-html/test/cases/build.default-custom-element/greenwood.config.js b/packages/plugin-include-html/test/cases/build.default-custom-element/greenwood.config.js
index a86d4c4e..1b9e18dd 100644
--- a/packages/plugin-include-html/test/cases/build.default-custom-element/greenwood.config.js
+++ b/packages/plugin-include-html/test/cases/build.default-custom-element/greenwood.config.js
@@ -1,6 +1,7 @@
 import { greenwoodPluginIncludeHTML } from '../../../src/index.js';
 
 export default {
+  prerender: false,
   plugins: [
     ...greenwoodPluginIncludeHTML()
   ]
diff --git a/packages/plugin-include-html/test/cases/build.default-link-tag/greenwood.config.js b/packages/plugin-include-html/test/cases/build.default-link-tag/greenwood.config.js
index a86d4c4e..1b9e18dd 100644
--- a/packages/plugin-include-html/test/cases/build.default-link-tag/greenwood.config.js
+++ b/packages/plugin-include-html/test/cases/build.default-link-tag/greenwood.config.js
@@ -1,6 +1,7 @@
 import { greenwoodPluginIncludeHTML } from '../../../src/index.js';
 
 export default {
+  prerender: false,
   plugins: [
     ...greenwoodPluginIncludeHTML()
   ]