Repository: ProjectEvergreen/greenwood (js)

Issue:
inline optimization is leaving behind tracking markers for inline `<script>` tags
## Type of Change
- [ ] New Feature Request
- [ ] Documentation / Website
- [ ] Improvement / Suggestion
- [x] Bug
- [ ] Other (please clarify below)

## Summary
Noticed in [one of our specs](https://github.com/ProjectEvergreen/greenwood/blob/v0.18.0/packages/cli/test/cases/build.config.optimization-inline/build.config-optimization-inline.spec.js#L123) that that the `console.log` marker we use when tracking inline `<script>` tags was not getting properly cleaned up.

<img width="740" alt="greenwood-rollup-marker-in-sourcecode" src="https://user-images.githubusercontent.com/895923/139597194-b67ed304-8ece-47a6-b82c-4ad8f9309f4e.png">

## Details
Basically we had something like this in our test
```html
<script type="module">
  class Bar {
  }
  
  export Bar;
</script>
```

And the output in the HTML was (minified of course)
```html
<script type="module">
  class Bar {
  }
  
  export Bar;
  
  console.log('xxxxx-scratch-xxxxx');
</script>
```

We definitely don't want that `console` in there 😨 

Pull request:
improve inline optimization marker cleanup for inline `<script>` tags
<!--
## Submitting a Pull Request
We love contributions and appreciate any help you can offer!
-->

## Related Issue
resolves #784 

## Summary of Changes
1. Handle marker cleanup for inline `<script>` tag
1. Update spec

Patch:
diff --git a/packages/cli/src/config/rollup.config.js b/packages/cli/src/config/rollup.config.js
index 48502bda..f772a12b 100644
--- a/packages/cli/src/config/rollup.config.js
+++ b/packages/cli/src/config/rollup.config.js
@@ -451,7 +451,8 @@ function greenwoodHtmlPlugin(compilation) {
                     if (id === marker) {
                       const cleaned = bundledSource
                         .replace(new RegExp(`,${markerExp};\n`), '')
-                        .replace(new RegExp(`${markerExp};\n`), '');
+                        .replace(new RegExp(`${markerExp};\n`), '')
+                        .replace(new RegExp(`${markerExp};`), '');
 
                       html = html.replace(scriptTag.rawText, cleaned);
                       scratchFiles[innerBundleId] = true;


Test patch:
diff --git a/packages/cli/test/cases/build.config.optimization-inline/build.config-optimization-inline.spec.js b/packages/cli/test/cases/build.config.optimization-inline/build.config-optimization-inline.spec.js
index 882c9b1f..a1eec744 100644
--- a/packages/cli/test/cases/build.config.optimization-inline/build.config-optimization-inline.spec.js
+++ b/packages/cli/test/cases/build.config.optimization-inline/build.config-optimization-inline.spec.js
@@ -120,7 +120,7 @@ describe('Build Greenwood With: ', function() {
 
           expect(scriptTag.type).to.be.equal('module');
           // eslint-disable-next-line max-len
-          expect(scriptTag.textContent).to.be.contain('class t extends HTMLElement{constructor(){super(),this.list=[]}find(t){this.list.findIndex(e=>new RegExp(`^${t}$`).test(e.route))}}console.log("644668726-scratch");export{t as Baz};');
+          expect(scriptTag.textContent).to.be.contain('class t extends HTMLElement{constructor(){super(),this.list=[]}find(t){this.list.findIndex(e=>new RegExp(`^${t}$`).test(e.route))}}export{t as Baz};');
         });
       });