diff --git a/.github/workflows/ci-win.yml b/.github/workflows/ci-win.yml index 226c3067..4f8e6ac4 100644 --- a/.github/workflows/ci-win.yml +++ b/.github/workflows/ci-win.yml @@ -25,7 +25,7 @@ jobs: yarn lint - name: Test run: | - yarn test --parallel + yarn test - name: Build run: | yarn clean && yarn build \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e28e38f9..78f99046 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: yarn lint - name: Test run: | - yarn test --parallel + yarn test - name: Build run: | yarn clean && yarn build \ No newline at end of file diff --git a/build.js b/build.js index 1f924d20..e4f99f94 100644 --- a/build.js +++ b/build.js @@ -11,6 +11,7 @@ async function init() { const distRoot = './dist'; const pagesRoot = './docs/pages'; const pages = await fs.readdir(new URL(pagesRoot, import.meta.url)); + const { html } = await renderToString(new URL('./docs/index.js', import.meta.url), false); // await fs.rm(distRoot, { recursive: true, force: true }); // await fs.mkdir('./dist', { recursive: true }); @@ -34,8 +35,6 @@ async function init() { const contentFilter = content.substring(content.indexOf('

wcc

'), content.indexOf('

Overview

') + 17); content = content.replace(contentFilter, ''); } - - const { html } = await renderToString(new URL('./docs/index.js', import.meta.url), false); // const lazyJs = []; // const eagerJs = []; diff --git a/package.json b/package.json index 19b66008..f45ec37b 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "example:ssg": "node ./examples/ssg.js", "example:ssr": "node ./examples/ssr.js", "start": "yarn develop", - "test": "c8 mocha --parallel", + "test": "c8 mocha --parallel", "test:tdd": "yarn test --watch" }, "dependencies": { diff --git a/src/wcc.js b/src/wcc.js index f75f3c2a..c08c4197 100644 --- a/src/wcc.js +++ b/src/wcc.js @@ -7,13 +7,13 @@ import { parseFragment, serialize } from 'parse5'; import fs from 'node:fs/promises'; -const deps = []; +let definitions; async function renderComponentRoots(tree) { for (const node of tree.childNodes) { if (node.tagName && node.tagName.indexOf('-') > 0) { const { tagName } = node; - const { moduleURL } = deps[tagName]; + const { moduleURL } = definitions[tagName]; const elementInstance = await initializeCustomElement(moduleURL, tagName, node.attrs); const shadowRootHtml = elementInstance.getInnerHTML({ includeShadowRoots: true }); @@ -59,7 +59,7 @@ async function registerDependencies(moduleURL) { const tagName = node.expression.arguments[0].value; - deps[tagName] = { + definitions[tagName] = { instanceName: node.expression.arguments[1].name, moduleURL }; @@ -83,7 +83,7 @@ async function initializeCustomElement(elementURL, tagName, attrs = []) { elementInstance.setAttribute(attr.name, attr.value); if (attr.name === 'hydrate') { - deps[tagName].hydrate = attr.value; + definitions[tagName].hydrate = attr.value; } }); @@ -93,6 +93,8 @@ async function initializeCustomElement(elementURL, tagName, attrs = []) { } async function renderToString(elementURL, fragment = true) { + definitions = []; + const elementInstance = await initializeCustomElement(elementURL); const elementHtml = elementInstance.getInnerHTML({ includeShadowRoots: false }); const elementTree = parseFragment(elementHtml); @@ -102,7 +104,7 @@ async function renderToString(elementURL, fragment = true) { return { html: elementInstance.getInnerHTML({ includeShadowRoots: fragment }), - metadata: deps + metadata: definitions }; } diff --git a/test/cases/metadata/metadata.js b/test/cases/metadata/metadata.spec.js similarity index 99% rename from test/cases/metadata/metadata.js rename to test/cases/metadata/metadata.spec.js index 5ea9a3fc..4c2b7902 100644 --- a/test/cases/metadata/metadata.js +++ b/test/cases/metadata/metadata.spec.js @@ -14,7 +14,6 @@ * pages/ * index.js */ - import chai from 'chai'; import { renderToString } from '../../../src/wcc.js'; @@ -26,7 +25,7 @@ describe('Run WCC For ', function() { before(async function() { const { metadata } = await renderToString(new URL('./src/pages/index.js', import.meta.url)); - + assetMetadata = metadata; });