Skip to content

Commit

Permalink
clean up console logs and track TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Jun 25, 2023
1 parent f1103b8 commit e2b7067
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 19 deletions.
7 changes: 5 additions & 2 deletions packages/cli/src/config/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ function greenwoodSyncPageResourceBundlesPlugin(compilation) {

// TODO could we use this instead?
// https://github.com/rollup/rollup/blob/v2.79.1/docs/05-plugin-development.md#resolveimportmeta
// https://github.com/ProjectEvergreen/greenwood/issues/1087
function greenwoodPatchSsrPagesEntryPointRuntimeImport() {
return {
name: 'greenwood-patch-ssr-pages-entry-point-runtime-import',
Expand Down Expand Up @@ -217,7 +218,7 @@ const getRollupConfigForApis = async (compilation) => {
.map(api => normalizePathnameForWindows(new URL(`.${api.path}`, userWorkspace)));

// TODO should routes and APIs have chunks?
// https://github.com/ProjectEvergreen/greenwood/issues/1008
// https://github.com/ProjectEvergreen/greenwood/issues/1118
return [{
input,
output: {
Expand All @@ -238,7 +239,7 @@ const getRollupConfigForSsr = async (compilation, input) => {
const { outputDir } = compilation.context;

// TODO should routes and APIs have chunks?
// https://github.com/ProjectEvergreen/greenwood/issues/1008
// https://github.com/ProjectEvergreen/greenwood/issues/1118
return [{
input,
output: {
Expand All @@ -250,6 +251,7 @@ const getRollupConfigForSsr = async (compilation, input) => {
greenwoodJsonLoader(),
// TODO let this through for lit to enable nodeResolve({ preferBuiltins: true })
// https://github.com/lit/lit/issues/449
// https://github.com/ProjectEvergreen/greenwood/issues/1118
nodeResolve({
preferBuiltins: true
}),
Expand All @@ -267,6 +269,7 @@ const getRollupConfigForSsr = async (compilation, input) => {
// Error: the string "Circular dependency: ../../../../../node_modules/@lit-labs/ssr/lib/render-lit-html.js ->
// ../../../../../node_modules/@lit-labs/ssr/lib/lit-element-renderer.js -> ../../../../../node_modules/@lit-labs/ssr/lib/render-lit-html.js\n" was thrown, throw an Error :)
// https://github.com/lit/lit/issues/449
// https://github.com/ProjectEvergreen/greenwood/issues/1118
break;
default:
// otherwise, log all warnings from rollup
Expand Down
3 changes: 0 additions & 3 deletions packages/cli/src/lib/execute-route-module.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { renderToString, renderFromHTML } from 'wc-compiler';

// TODO simplify this API signature (lot of things could be combined)
// - route, label and id could just be the current page
// - scripts is already part of the compilation
async function executeRouteModule({ moduleUrl, compilation, page = {}, prerender = false, htmlContents = null, scripts = [] }) {
const data = {
template: null,
Expand Down
13 changes: 1 addition & 12 deletions packages/cli/src/lifecycles/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,26 +197,16 @@ async function bundleSsrPages(compilation) {
const entryFileUrl = new URL(`./_${filename}`, scratchDir);
const moduleUrl = new URL(`./${filename}`, pagesDir);
// TODO getTemplate has to be static (for now?)
// const { getTemplate = null } = await import(new URL(`./${filename}`, pagesDir));
// https://github.com/ProjectEvergreen/greenwood/issues/955
const data = await executeRouteModule({ moduleUrl, compilation, page, prerender: false, htmlContents: null, scripts: [] });
let staticHtml = '';

staticHtml = data.template ? data.template : await getPageTemplate(staticHtml, compilation.context, template, []);
// console.log('+ page template', { staticHtml });

staticHtml = await getAppTemplate(staticHtml, compilation.context, imports, [], false, title);
// console.log('+ app template', { staticHtml });

staticHtml = await getUserScripts(staticHtml, compilation.context);
// console.log('+ user scripts', { staticHtml });

// TODO do we want to use http:// here for optimizer?
staticHtml = await (await htmlOptimizer.optimize(new URL(`http://localhost:8080${route}`), new Response(staticHtml))).text();
// console.log('+ optimizer', { staticHtml });

// better way to write out this inline code?
// TODO does executeRouteModule need to get bundled?
// TODO do we need to bundle this too since we reference executeModuleUrl.href directly?
await fs.writeFile(entryFileUrl, `
import { executeRouteModule } from '${normalizePathnameForWindows(executeModuleUrl)}';
Expand Down Expand Up @@ -246,7 +236,6 @@ async function bundleSsrPages(compilation) {

const [rollupConfig] = await getRollupConfigForSsr(compilation, input);

// TODO do we need templates anymore?
if (rollupConfig.input.length > 0) {
const bundle = await rollup(rollupConfig);
await bundle.write(rollupConfig.output);
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/lifecycles/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ async function preRenderCompilationWorker(compilation, workerPrerender) {

console.info('pages to generate', `\n ${pages.map(page => page.route).join('\n ')}`);

console.log({ workerPrerender });
const pool = new WorkerPool(os.cpus().length, new URL('../lib/ssr-route-worker.js', import.meta.url));

for (const page of pages) {
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/plugins/resource/plugin-standard-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ class StandardHtmlResource extends ResourceInterface {
}

async shouldOptimize(url, response) {
// TOOD should be .indexOf(this.contentType) === 0
return response.headers.get('Content-Type').indexOf(this.contentType) >= 0;
}

Expand Down

0 comments on commit e2b7067

Please sign in to comment.