Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
yarn lint
- name: Test
run: |
yarn test --parallel
yarn test
- name: Build
run: |
yarn clean && yarn build
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
yarn lint
- name: Test
run: |
yarn test --parallel
yarn test
- name: Build
run: |
yarn clean && yarn build
3 changes: 1 addition & 2 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -34,8 +35,6 @@ async function init() {
const contentFilter = content.substring(content.indexOf('<h1>wcc</h1>'), content.indexOf('<h2>Overview</h2>') + 17);
content = content.replace(contentFilter, '');
}

const { html } = await renderToString(new URL('./docs/index.js', import.meta.url), false);

// const lazyJs = [];
// const eagerJs = [];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
12 changes: 7 additions & 5 deletions src/wcc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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
};
Expand All @@ -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;
}
});

Expand All @@ -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);
Expand All @@ -102,7 +104,7 @@ async function renderToString(elementURL, fragment = true) {

return {
html: elementInstance.getInnerHTML({ includeShadowRoots: fragment }),
metadata: deps
metadata: definitions
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* pages/
* index.js
*/

import chai from 'chai';
import { renderToString } from '../../../src/wcc.js';

Expand All @@ -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;
});

Expand Down