Repository: ProjectEvergreen/wcc (js)

Issue:
gracefully and accurately handle "empty" entry points and dependency files that don't `export` a custom element
## Summary
As observed / reported in https://github.com/ProjectEvergreen/greenwood/issues/1185, WCC checks every file it process as part of `initializeCustomElement` looking for custom element definitions, naturally.  However, in the Greenwood case, all code / chunks related to rendering out SSR HTML might not always be cleanly provided as only having an `export default Foo extends HTMLElement`.

This leads to cases where WCC will [log out to the console and "silently" fail by returning an empty `HTMLElement`](https://github.com/ProjectEvergreen/wcc/blob/0.9.0/src/wcc.js#L161)
```js
if (element) {
  // ...

  return elementInstance;
} else {
  console.debug('No custom element class found for this file');
  return new HTMLElement();
}
```

We should not be so noisy in reporting and instead only rely on our warning for missing custom element definitions.


## Details

Seems related to #85 but instead of just successfully failing, and to accomplish a middle ground here and not completely lose out on error miessaging / feedback to users, `renderToString` makes the assumption the entry point is a custom element, relying on the default `HTMLElement` being returned by `initializeCustomElement`
```js
async function renderToString(elementURL, wrappingEntryTag = true, props = {}) {
  // ...
  const elementInstance = await initializeCustomElement(elementURL, undefined, undefined, definitions, isEntry, props);

  const elementHtml = elementInstance.shadowRoot
    ? elementInstance.getInnerHTML({ includeShadowRoots: true })
    : elementInstance.innerHTML;
   
  //....
}
```

We should probably at least add a check here and just return `undefined` and then show the warning.

Pull request:
enhancement/issue 124 refactor handling and logging for entry points and dependencies with no custom element `export`
<!--
## Submitting a Pull Request
We love contributions and appreciate any help you can offer!
-->

## Related Issue
resolves #124 

## Summary of Changes
1. Don't log out when checking for custom elements in `initializeCustomElement `
1. Add logging if `renderToString` entry point is not a custom element
1. Updated no export spec

Patch:
diff --git a/src/wcc.js b/src/wcc.js
index f9b3998..887e0b6 100644
--- a/src/wcc.js
+++ b/src/wcc.js
@@ -158,9 +158,6 @@ async function initializeCustomElement(elementURL, tagName, attrs = [], definiti
     await elementInstance.connectedCallback();
   
     return elementInstance;
-  } else {
-    console.debug('No custom element class found for this file');
-    return new HTMLElement();
   }
 }
 
@@ -169,18 +166,25 @@ async function renderToString(elementURL, wrappingEntryTag = true, props = {}) {
   const elementTagName = wrappingEntryTag && await getTagName(elementURL);
   const isEntry = !!elementTagName;
   const elementInstance = await initializeCustomElement(elementURL, undefined, undefined, definitions, isEntry, props);
-
-  const elementHtml = elementInstance.shadowRoot
-    ? elementInstance.getInnerHTML({ includeShadowRoots: true })
-    : elementInstance.innerHTML;
-  const elementTree = getParse(elementHtml)(elementHtml);
-  const finalTree = await renderComponentRoots(elementTree, definitions);
-  const html = wrappingEntryTag && elementTagName ? `
-      <${elementTagName}>
-        ${serialize(finalTree)}
-      </${elementTagName}>
-    `
-    : serialize(finalTree);
+  let html;
+
+  // in case the entry point isn't valid
+  if (elementInstance) {
+    const elementHtml = elementInstance.shadowRoot
+      ? elementInstance.getInnerHTML({ includeShadowRoots: true })
+      : elementInstance.innerHTML;
+    const elementTree = getParse(elementHtml)(elementHtml);
+    const finalTree = await renderComponentRoots(elementTree, definitions);
+
+    html = wrappingEntryTag && elementTagName ? `
+        <${elementTagName}>
+          ${serialize(finalTree)}
+        </${elementTagName}>
+      `
+      : serialize(finalTree);
+  } else {
+    console.warn('WARNING: No custom element class found for this entry point.');
+  }
 
   return {
     html,


Test patch:
diff --git a/test/cases/no-export/no-export.spec.js b/test/cases/no-export/no-export.spec.js
index bb3e153..d3257ca 100644
--- a/test/cases/no-export/no-export.spec.js
+++ b/test/cases/no-export/no-export.spec.js
@@ -18,16 +18,22 @@ const expect = chai.expect;
 describe('Run WCC For ', function() {
   const LABEL = 'Single Custom Element with no default export';
   let rawHtml;
+  let meta;
 
   before(async function() {
-    const { html } = await renderToString(new URL('./src/no-export.js', import.meta.url));
+    const { html, metadata } = await renderToString(new URL('./src/no-export.js', import.meta.url));
 
     rawHtml = html;
+    meta = metadata;
   });
 
   describe(LABEL, function() {
     it('should not throw an error', function() {
-      expect(rawHtml).to.equal('');
+      expect(rawHtml).to.equal(undefined);
+    });
+
+    it('should not have any definition', function() {
+      expect(meta.length).to.equal(0);
     });
   });