Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade website to lit@2 #611

Merged
merged 19 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"lint:css": "stylelint \"./www/**/*.js\", \"./www/**/*.css\"",
"lint": "ls-lint && yarn lint:js && yarn lint:ts && yarn lint:css"
},
"resolutions": {
"lit": "^2.0.0"
},
"devDependencies": {
"@ls-lint/ls-lint": "^1.9.2",
"@typescript-eslint/eslint-plugin": "^4.28.2",
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dependencies": {
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-replace": "^2.3.4",
"@webcomponents/webcomponentsjs": "^2.4.4",
"@webcomponents/webcomponentsjs": "^2.6.0",
"acorn": "^8.0.1",
"acorn-walk": "^8.0.0",
"commander": "^2.20.0",
Expand All @@ -50,12 +50,12 @@
},
"devDependencies": {
"@babel/runtime": "^7.10.4",
"@lion/button": "~0.12.0",
"@lion/calendar": "~0.15.0",
"@lion/button": "^0.14.3",
"@lion/calendar": "^0.16.5",
"@mapbox/rehype-prism": "^0.5.0",
"@types/trusted-types": "^2.0.2",
"lit-element": "^2.4.0",
"lit-redux-router": "^0.17.1",
"lit": "^2.0.0",
"lit-redux-router": "~0.20.0",
"lodash-es": "^4.17.20",
"postcss-nested": "^4.1.2",
"pwa-helpers": "^0.9.1",
Expand Down
20 changes: 17 additions & 3 deletions packages/cli/src/plugins/resource/plugin-standard-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,24 @@ const getAppTemplate = (contents, templatesDir, customImports = [], contextPlugi
return appTemplateContents;
};

const getUserScripts = (contents) => {
// polyfill chromium for WCs support
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;
const dependencies = fs.existsSync(path.join(userWorkspace, 'package.json')) // handle monorepos first
? JSON.parse(fs.readFileSync(path.join(userWorkspace, 'package.json'), 'utf-8')).dependencies
: fs.existsSync(path.join(projectDirectory, 'package.json'))
? JSON.parse(fs.readFileSync(path.join(projectDirectory, 'package.json'), 'utf-8')).dependencies
: {};

const litPolyfill = dependencies && dependencies.lit
? '<script src="/node_modules/lit/polyfill-support.js"></script>\n'
: '';

contents = contents.replace('<head>', `
<head>
${litPolyfill}
<script src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
`);
}
Expand Down Expand Up @@ -353,7 +366,7 @@ class StandardHtmlResource extends ResourceInterface {
}

body = getAppTemplate(body, userTemplatesDir, customImports, contextPlugins);
body = getUserScripts(body, customImports);
body = getUserScripts(body, this.compilation.context);
body = getMetaContent(normalizedUrl.replace(/\\/g, '/'), config, body);

if (processedMarkdown) {
Expand Down Expand Up @@ -404,6 +417,7 @@ class StandardHtmlResource extends ResourceInterface {
if (hasHead && hasHead.length > 0) {
let contents = hasHead[0];

contents = contents.replace(/<script src="(.*lit\/polyfill-support.js)"><\/script>/, '');
contents = contents.replace(/<script src="(.*webcomponents-bundle.js)"><\/script>/, '');
contents = contents.replace(/<script type="importmap-shim">.*?<\/script>/s, '');
contents = contents.replace(/<script defer="" src="(.*es-module-shims.js)"><\/script>/, '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,64 @@ describe('Build Greenwood With: ', function() {
describe(LABEL, function() {

before(async function() {
const litElementLibs = await getDependencyFiles(
`${process.cwd()}/node_modules/lit-element/lib/*.js`,
`${outputPath}/node_modules/lit-element/lib/`
const lit = await getDependencyFiles(
`${process.cwd()}/node_modules/lit/*.js`,
`${outputPath}/node_modules/lit/`
);
const litDecorators = await getDependencyFiles(
`${process.cwd()}/node_modules/lit/decorators/*.js`,
`${outputPath}/node_modules/lit/decorators/`
);
const litDirectives = await getDependencyFiles(
`${process.cwd()}/node_modules/lit/directives/*.js`,
`${outputPath}/node_modules/lit/directives/`
);
const litPackageJson = await getDependencyFiles(
`${process.cwd()}/node_modules/lit/package.json`,
`${outputPath}/node_modules/lit/`
);
const litElement = await getDependencyFiles(
`${process.cwd()}/node_modules/lit-element/lit-element.js`,
`${process.cwd()}/node_modules/lit-element/*.js`,
`${outputPath}/node_modules/lit-element/`
);
const litElementPackageJson = await getDependencyFiles(
`${process.cwd()}/node_modules/lit-element/package.json`,
`${outputPath}/node_modules/lit-element/`
);
const litElementDecorators = await getDependencyFiles(
`${process.cwd()}/node_modules/lit-element/decorators/*.js`,
`${outputPath}/node_modules/lit-element/decorators/`
);
const litHtml = await getDependencyFiles(
`${process.cwd()}/node_modules/lit-html/lit-html.js`,
`${process.cwd()}/node_modules/lit-html/*.js`,
`${outputPath}/node_modules/lit-html/`
);
const litHtmlPackageJson = await getDependencyFiles(
`${process.cwd()}/node_modules/lit-html/package.json`,
`${outputPath}/node_modules/lit-html/`
);
const litHtmlLibs = await getDependencyFiles(
`${process.cwd()}/node_modules/lit-html/lib/*.js`,
`${outputPath}/node_modules/lit-html/lib/`
);
const litHtmlDirectives = await getDependencyFiles(
`${process.cwd()}/node_modules/lit-html/directives/*.js`,
`${process.cwd()}/node_modules/lit-html/directives/*.js`,
`${outputPath}/node_modules/lit-html/directives/`
);
// lit-html has a dependency on this
// https://github.com/lit/lit/blob/main/packages/lit-html/package.json#L82
const trustedTypes = await getDependencyFiles(
`${process.cwd()}/node_modules/@types/trusted-types/package.json`,
`${outputPath}/node_modules/@types/trusted-types/`
);
const litReactiveElement = await getDependencyFiles(
`${process.cwd()}/node_modules/@lit/reactive-element/*.js`,
`${outputPath}/node_modules/@lit/reactive-element/`
);
const litReactiveElementDecorators = await getDependencyFiles(
`${process.cwd()}/node_modules/@lit/reactive-element/decorators/*.js`,
`${outputPath}/node_modules/@lit/reactive-element/decorators/`
);
const litReactiveElementPackageJson = await getDependencyFiles(
`${process.cwd()}/node_modules/@lit/reactive-element/package.json`,
`${outputPath}/node_modules/@lit/reactive-element/`
);
const litReduxRouterPackageJson = await getDependencyFiles(
`${process.cwd()}/node_modules/lit-redux-router/package.json`,
`${outputPath}/node_modules/lit-redux-router/`
Expand Down Expand Up @@ -147,13 +177,20 @@ describe('Build Greenwood With: ', function() {

await runner.setup(outputPath, [
...getSetupFiles(outputPath),
...litElementLibs,
...litElement,
...lit,
...litPackageJson,
...litDirectives,
...litDecorators,
...litElementPackageJson,
...litElement,
...litElementDecorators,
...litHtmlPackageJson,
...litHtml,
...litHtmlLibs,
...litHtmlDirectives,
...trustedTypes,
...litReactiveElement,
...litReactiveElementDecorators,
...litReactiveElementPackageJson,
...litReduxRouterPackageJson,
...litReduxRouter,
...litReduxRouterLibs,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/test/cases/build.config.mode-spa/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dependencies": {
"lit-element": "^2.4.0",
"lit-redux-router": "^0.17.1",
"lit": "^2.0.0",
"lit-redux-router": "~0.20.0",
"pwa-helpers": "^0.9.1",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { css, html, LitElement } from 'lit-element';
import { css, html, LitElement } from 'lit';

class FooterComponent extends LitElement {

Expand Down
6 changes: 3 additions & 3 deletions packages/cli/test/cases/build.config.mode-spa/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { html, LitElement } from 'lit-element';
import { html, LitElement } from 'lit';
import { connectRouter } from 'lit-redux-router';
import { applyMiddleware, createStore, compose, combineReducers } from 'redux';
import { lazyReducerEnhancer } from 'pwa-helpers';
Expand All @@ -16,12 +16,12 @@ class MyApp extends LitElement {
<div class="app-content">
<lit-route
path="/"
component="app-home"
component="app-route-home"
.resolve="${() => import('./routes/home.js')}"
></lit-route>
<lit-route
path="/about"
component="app-about"
component="app-route-about"
.resolve="${() => import('./routes/about.js')}"
></lit-route>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { html, LitElement } from 'lit-element';
import { html, LitElement } from 'lit';

class AppAbout extends LitElement {
render() {
return html`<h1>About</h1>`;
}
}

customElements.define('app-about', AppAbout);
customElements.define('app-route-about', AppAbout);
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { html, LitElement } from 'lit-element';
import { html, LitElement } from 'lit';

class AppHome extends LitElement {
render() {
return html`<h1>Home</h1>`;
}
}

customElements.define('app-home', AppHome);
customElements.define('app-route-home', AppHome);
Loading