From b717fdf168e8fedfae718380b237bc112db0d7e2 Mon Sep 17 00:00:00 2001 From: Owen Buckley Date: Sat, 2 Jul 2022 21:01:07 -0400 Subject: [PATCH 01/21] puppeteer renderer plugin and migrate resource plugin --- greenwood.config.js | 4 +- packages/cli/package.json | 9 --- .../plugins/resource/plugin-standard-html.js | 3 - packages/plugin-renderer-puppeteer/README.md | 3 + .../plugin-renderer-puppeteer/package.json | 32 +++++++++++ .../plugin-renderer-puppeteer/src/index.js | 57 +++++++++++++++++++ 6 files changed, 95 insertions(+), 13 deletions(-) create mode 100644 packages/plugin-renderer-puppeteer/README.md create mode 100644 packages/plugin-renderer-puppeteer/package.json create mode 100644 packages/plugin-renderer-puppeteer/src/index.js diff --git a/greenwood.config.js b/greenwood.config.js index a87785498..e913c0891 100644 --- a/greenwood.config.js +++ b/greenwood.config.js @@ -4,6 +4,7 @@ import { greenwoodPluginImportCss } from '@greenwood/plugin-import-css'; import { greenwoodPluginImportJson } from '@greenwood/plugin-import-json'; import { greenwoodPluginPolyfills } from '@greenwood/plugin-polyfills'; import { greenwoodPluginPostCss } from '@greenwood/plugin-postcss'; +import { greenwoodPluginRendererPuppeteer } from '@greenwood/plugin-renderer-puppeteer'; import rollupPluginAnalyzer from 'rollup-plugin-analyzer'; import { fileURLToPath, URL } from 'url'; @@ -33,7 +34,8 @@ export default { ]; } }, - ...greenwoodPluginIncludeHTML() + ...greenwoodPluginIncludeHTML(), + ...greenwoodPluginRendererPuppeteer() ], markdown: { plugins: [ diff --git a/packages/cli/package.json b/packages/cli/package.json index 668f18b6d..ba6a82cca 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -23,18 +23,9 @@ "publishConfig": { "access": "public" }, - "peerDependencies": { - "puppeteer": "^13.5.2" - }, - "peerDependenciesMeta": { - "puppeteer": { - "optional": true - } - }, "dependencies": { "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-replace": "^2.3.4", - "@webcomponents/webcomponentsjs": "^2.6.0", "acorn": "^8.0.1", "acorn-walk": "^8.0.0", "commander": "^2.20.0", diff --git a/packages/cli/src/plugins/resource/plugin-standard-html.js b/packages/cli/src/plugins/resource/plugin-standard-html.js index 289784400..0195e4227 100644 --- a/packages/cli/src/plugins/resource/plugin-standard-html.js +++ b/packages/cli/src/plugins/resource/plugin-standard-html.js @@ -263,7 +263,6 @@ const getAppTemplate = (contents, templatesDir, customImports = [], contextPlugi }; const getUserScripts = (contents, context) => { - // polyfill chromium for WC support // https://lit.dev/docs/tools/requirements/#polyfills if (process.env.__GWD_COMMAND__ === 'build') { // eslint-disable-line no-underscore-dangle const { projectDirectory, userWorkspace } = context; @@ -280,7 +279,6 @@ const getUserScripts = (contents, context) => { contents = contents.replace('', ` ${litPolyfill} - `); } return contents; @@ -507,7 +505,6 @@ class StandardHtmlResource extends ResourceInterface { let contents = hasHead[0]; contents = contents.replace(/ + `); + + return Promise.resolve({ body }); + } + + async shouldOptimize(url = '', body, headers = {}) { + return Promise.resolve(path.extname(url) === '.html' || (headers.request && headers.request['content-type'].indexOf(this.contentType) >= 0)); + } + + async optimize(url, body) { + return new Promise((resolve, reject) => { + try { + const hasHead = body.match(/\(.*)<\/head>/s); + + if (hasHead && hasHead.length > 0) { + body = body.replace(/ - `); - - return Promise.resolve({ body }); - } - - async shouldOptimize(url = '', body, headers = {}) { - return Promise.resolve(path.extname(url) === '.html' || (headers.request && headers.request['content-type'].indexOf(this.contentType) >= 0)); - } - - async optimize(url, body) { - return new Promise((resolve, reject) => { - try { - const hasHead = body.match(/\(.*)<\/head>/s); - - if (hasHead && hasHead.length > 0) { - body = body.replace(/ + `); + + return Promise.resolve({ body }); + } + + async shouldOptimize(url = '', body, headers = {}) { + return Promise.resolve(path.extname(url) === '.html' || (headers.request && headers.request['content-type'].indexOf(this.contentType) >= 0)); + } + + async optimize(url, body) { + return new Promise((resolve, reject) => { + try { + const hasHead = body.match(/\(.*)<\/head>/s); + + if (hasHead && hasHead.length > 0) { + body = body.replace(/ + + + + + + + + \ No newline at end of file diff --git a/test/smoke-test.js b/test/smoke-test.js index 348383fe7..3ce3b5722 100644 --- a/test/smoke-test.js +++ b/test/smoke-test.js @@ -66,7 +66,6 @@ function commonIndexSpecs(dom, html, label) { expect(tagsMatch('link', html)).to.be.equal(true); }); - // note: one will always be present when using puppeteer it('should have matching opening and closing tag in the ', function() { it('should have one