Skip to content

Commit 2b73a7b

Browse files
WIP shoelace integration
1 parent a7bb2ab commit 2b73a7b

File tree

10 files changed

+4519
-30
lines changed

10 files changed

+4519
-30
lines changed

package-lock.json

Lines changed: 4305 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"start": "pnpm run serve"
2828
},
2929
"dependencies": {
30+
"@shoelace-style/shoelace": "^2.18.0",
3031
"lit": "^3.1.0"
3132
},
3233
"devDependencies": {

patches/@greenwood__cli.patch

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,99 @@ index a92bb3d29496a453f1714e5cd32d1800c94844be..ded1034c929edc462ab547dc9b16ca8c
405405
- walkModule
406406
+ mergeImportMap
407407
};
408+
diff --git a/src/config/rollup.config.js b/src/config/rollup.config.js
409+
index b0bad6bfd8f9331812ded9c266d51ea8bb2584f1..08ff1eb71aaf338075b66e55f008fbafc25b4b85 100644
410+
--- a/src/config/rollup.config.js
411+
+++ b/src/config/rollup.config.js
412+
@@ -141,6 +141,7 @@ function greenwoodSyncPageResourceBundlesPlugin(compilation) {
413+
}
414+
}
415+
416+
+ console.log({ resourceKey, facadeModuleId });
417+
if (resourceKey === facadeModuleId) {
418+
const { fileName } = bundles[bundle];
419+
const { rawAttributes, contents } = resource;
420+
@@ -587,6 +588,7 @@ function greenwoodSyncImportAttributes(compilation) {
421+
422+
const getRollupConfigForBrowserScripts = async (compilation) => {
423+
const { outputDir } = compilation.context;
424+
+ console.log('?????', compilation.resources.values())
425+
const input = [...compilation.resources.values()]
426+
.filter(resource => resource.type === 'script')
427+
.map(resource => normalizePathnameForWindows(resource.sourcePathURL));
428+
diff --git a/src/lib/resource-utils.js b/src/lib/resource-utils.js
429+
index 6a78e464785b6dc11e909acf64f66db975e77909..d4c5ac967a4dcf126b4cf9c85d5d3615ebde03d8 100644
430+
--- a/src/lib/resource-utils.js
431+
+++ b/src/lib/resource-utils.js
432+
@@ -2,17 +2,39 @@ import fs from 'fs/promises';
433+
import { hashString } from './hashing-utils.js';
434+
import htmlparser from 'node-html-parser';
435+
436+
+function getPackageNameFromSrc(src) {
437+
+ const s = src.replace('/node_modules/', '');
438+
+ const pieces = s.split('/');
439+
+ let name;
440+
+
441+
+ console.log({ pieces });
442+
+ if (s.startsWith('@')) {
443+
+ name = `${pieces[0]}/${pieces[1]}`;
444+
+ } else {
445+
+ name = pieces[0];
446+
+ }
447+
+
448+
+ console.log({ name });
449+
+
450+
+ return name;
451+
+}
452+
async function modelResource(context, type, src = undefined, contents = undefined, optimizationAttr = undefined, rawAttributes = undefined) {
453+
const { projectDirectory, scratchDir, userWorkspace } = context;
454+
const extension = type === 'script' ? 'js' : 'css';
455+
let sourcePathURL;
456+
457+
if (src) {
458+
- sourcePathURL = src.startsWith('/node_modules')
459+
- ? new URL(`.${src}`, projectDirectory)
460+
- : src.startsWith('/')
461+
+ if (src.startsWith('/node_modules')) {
462+
+ const name = getPackageNameFromSrc(src);
463+
+ const resolved = import.meta.resolve(name);
464+
+
465+
+ sourcePathURL = new URL(resolved);
466+
+ console.log('modelResource', { name, resolved, sourcePathURL });
467+
+ } else {
468+
+ sourcePathURL = src.startsWith('/')
469+
? new URL(`.${src}`, userWorkspace)
470+
: new URL(`./${src.replace(/\.\.\//g, '').replace('./', '')}`, userWorkspace);
471+
+ }
472+
473+
contents = await fs.readFile(sourcePathURL, 'utf-8');
474+
} else {
475+
@@ -112,6 +134,7 @@ async function resolveForRelativeUrl(url, rootUrl) {
476+
}
477+
478+
async function trackResourcesForRoute(html, compilation, route) {
479+
+ console.log('trackResourcesForRoute', { route });
480+
const { context } = compilation;
481+
const root = htmlparser.parse(html, {
482+
script: true,
483+
@@ -163,6 +186,7 @@ async function trackResourcesForRoute(html, compilation, route) {
484+
485+
compilation.graph.find(page => page.route === route).resources = resources.map(resource => resource.sourcePathURL.pathname);
486+
487+
+ console.log('$$$', { resources });
488+
return resources;
489+
}
490+
491+
diff --git a/src/lifecycles/bundle.js b/src/lifecycles/bundle.js
492+
index 814d1b9462c02530f81a7bec1d393f6609c5a9b9..992f239c76643748119d53cef7b809b22623de8b 100644
493+
--- a/src/lifecycles/bundle.js
494+
+++ b/src/lifecycles/bundle.js
495+
@@ -332,6 +332,8 @@ async function bundleScriptResources(compilation) {
496+
// https://rollupjs.org/guide/en/#differences-to-the-javascript-api
497+
const [rollupConfig] = await getRollupConfigForBrowserScripts(compilation);
498+
499+
+ console.log({ rollupConfig });
500+
+
501+
if (rollupConfig.input.length !== 0) {
502+
const bundle = await rollup(rollupConfig);
503+
await bundle.write(rollupConfig.output);

pnpm-lock.yaml

Lines changed: 102 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/card.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class Card extends LitElement {
7676
<div>
7777
<h3>${title}</h3>
7878
<img src="${thumbnail}" alt="${title}" loading="lazy" width="100%">
79-
<button @click="${this.selectItem}">View Item Details</button>
79+
<sl-button variant="neutral" @click="${this.selectItem}">View Item Details</sl-button>
8080
</div>
8181
`;
8282
}

src/components/modal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class Modal extends LitElement {
5656
}
5757

5858
firstUpdated() {
59-
const button = this.shadowRoot.querySelector('button')
59+
const button = this.shadowRoot.querySelector('sl-button')
6060
const dialog = this.shadowRoot.querySelector('dialog');
6161

6262
button.addEventListener("click", () => dialog.close());
@@ -68,7 +68,7 @@ export class Modal extends LitElement {
6868
return html`
6969
<dialog>
7070
<h3 id="content">${content}</h3>
71-
<button autofocus>Close</button>
71+
<sl-button variant="neutral" autofocus>Close</sl-button>
7272
</dialog>
7373
`;
7474
}

src/layouts/app.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
<link rel="shortcut icon" href="/favicon.ico"/>
99
<link rel="icon" href="/favicon.ico"/>
1010

11-
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro">
12-
<link rel="stylesheet" href="../styles/main.css">
11+
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro"/>
12+
<link rel="stylesheet" href="/node_modules/@shoelace-style/shoelace/dist/themes/light.css" />
13+
<link rel="stylesheet" href="../styles/main.css"/>
14+
15+
<script type="module" src="/node_modules/@shoelace-style/shoelace/dist/shoelace.js"></script>
1316
<script type="module" src="../components/card.js"></script>
1417
<script type="module" src="../components/modal.js"></script>
1518
</head>

0 commit comments

Comments
 (0)