Skip to content

Commit

Permalink
post rebase tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed May 19, 2024
1 parent 66819d9 commit 8a09351
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 37 deletions.
33 changes: 8 additions & 25 deletions packages/cli/src/lifecycles/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,37 +225,19 @@ async function bundleSsrPages(compilation, optimizePlugins) {
// }).map((plugin) => {
// return plugin.provider(compilation);
// });
const { context, config } = compilation;
const ssrPages = compilation.graph.filter(page => page.isSSR && !page.prerender);
const ssrPrerenderPagesRouteMapper = {};
const input = [];

if (!compilation.config.prerender && ssrPages.length > 0) {
const { executeModuleUrl } = compilation.config.plugins.find(plugin => plugin.type === 'renderer').provider();
if (!config.prerender && ssrPages.length > 0) {
const { executeModuleUrl } = config.plugins.find(plugin => plugin.type === 'renderer').provider();
const { executeRouteModule } = await import(executeModuleUrl);
const { pagesDir, scratchDir } = compilation.context;
const { pagesDir, scratchDir } = context;

// one pass to generate initial static HTML and to track all combined static resources across layouts
// and before we optimize so that all bundled assets can tracked up front
// would be nice to see if this can be done in a single pass though...
// <<<<<<< HEAD
// for (const page of compilation.graph) {
// if (page.isSSR && !page.prerender) {
// const { filename, imports, route, layout, title } = page;
// const entryFileUrl = new URL(`./${filename}`, scratchDir);
// const moduleUrl = new URL(`./${filename}`, pagesDir);
// const request = new Request(moduleUrl);
// // TODO getLayout has to be static (for now?)
// // https://github.com/ProjectEvergreen/greenwood/issues/955
// const data = await executeRouteModule({ moduleUrl, compilation, page, prerender: false, htmlContents: null, scripts: [], request });
// const pagesPathDiff = compilation.context.pagesDir.pathname.replace(compilation.context.projectDirectory.pathname, '');

// let staticHtml = '';

// staticHtml = data.layout ? data.layout : await getPageLayout(staticHtml, compilation.context, layout, []);
// staticHtml = await getAppLayout(staticHtml, compilation.context, imports, [], false, title);
// staticHtml = await getUserScripts(staticHtml, compilation);
// staticHtml = await (await interceptPage(new URL(`http://localhost:8080${route}`), new Request(new URL(`http://localhost:8080${route}`)), getPluginInstances(compilation), staticHtml)).text();
// =======
for (const page of ssrPages) {
const { filename, imports, route, layout, title } = page;
const moduleUrl = new URL(`./${filename}`, pagesDir);
Expand All @@ -266,7 +248,7 @@ async function bundleSsrPages(compilation, optimizePlugins) {
let staticHtml = '';

staticHtml = data.layout ? data.layout : await getPageLayout(staticHtml, compilation.context, layout, []);
staticHtml = await getAppLayout(staticHtml, compilation.context, imports, [], false, title);
staticHtml = await getAppLayout(staticHtml, context, imports, [], false, title);
staticHtml = await getUserScripts(staticHtml, compilation);
staticHtml = await (await interceptPage(new URL(`http://localhost:8080${route}`), new Request(new URL(`http://localhost:8080${route}`)), getPluginInstances(compilation), staticHtml)).text();

Expand All @@ -283,8 +265,9 @@ async function bundleSsrPages(compilation, optimizePlugins) {
// second pass to link all bundled assets to their resources before optimizing and generating SSR bundles
for (const page of ssrPages) {
const { filename, route } = page;
const entryFileUrl = new URL(`./_${filename}`, scratchDir);
const htmlOptimizer = compilation.config.plugins.find(plugin => plugin.name === 'plugin-standard-html').provider(compilation);
const entryFileUrl = new URL(`./${filename}`, scratchDir);
const htmlOptimizer = config.plugins.find(plugin => plugin.name === 'plugin-standard-html').provider(compilation);
const pagesPathDiff = context.pagesDir.pathname.replace(context.projectDirectory.pathname, '');

let staticHtml = ssrPrerenderPagesRouteMapper[route];
staticHtml = await (await htmlOptimizer.optimize(new URL(`http://localhost:8080${route}`), new Response(staticHtml))).text();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('Build Greenwood With: ', function() {
});

it('should have one top level <app-header> tag with a <layout> with an open shadowroot', function() {
const header = dom.window.document.querySelectorAll('app-header template[shadowroot="open"]');
const header = dom.window.document.querySelectorAll('app-header template[shadowrootmode="open"]');
const headerContentsDom = new JSDOM(header[0].innerHTML);
const heading = headerContentsDom.window.document.querySelectorAll('h1');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,8 @@
* greeting.js
* pages/
* artists.js
<<<<<<< HEAD
* users.js (isolation = false)
* templates/
=======
* users.js
* layouts/
>>>>>>> 65d3fd43 (rename templates directory to layouts)
* app.html
*/
import chai from 'chai';
Expand Down Expand Up @@ -200,11 +195,7 @@ describe('Serve Greenwood With: ', function() {
usersPageDom = new JSDOM(usersPageHtml);
});

<<<<<<< HEAD
describe('Serve command with HTML route response using getBody, getTemplate and getFrontmatter for the artists page', function() {
=======
describe('Serve command with HTML route response using getBody, getLayout and getFrontmatter', function() {
>>>>>>> 65d3fd43 (rename templates directory to layouts)
describe('Serve command with HTML route response using getBody, getLayout and getFrontmatter for the artists page', function() {

it('should return a 200 status', function() {
expect(response.status).to.equal(200);
Expand Down
2 changes: 1 addition & 1 deletion www/pages/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default {
plugins: [],
workspace: new URL('./src/', import.meta.url),
pagesDirectory: 'pages', // e.g. src/pages
layoutsDirectory: 'layouts' // e.g. src/layouts
layoutsDirectory: 'layouts', // e.g. src/layouts
isolation: false
};
```
Expand Down

0 comments on commit 8a09351

Please sign in to comment.