Skip to content

Commit 02bbf76

Browse files
WIP shoelace integration
1 parent 7135a50 commit 02bbf76

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
@@ -361,3 +361,99 @@ index a92bb3d29496a453f1714e5cd32d1800c94844be..68fd30e718f5493b426b88bc8e6aa137
361361
- walkModule
362362
+ mergeImportMap
363363
};
364+
diff --git a/src/config/rollup.config.js b/src/config/rollup.config.js
365+
index b0bad6bfd8f9331812ded9c266d51ea8bb2584f1..08ff1eb71aaf338075b66e55f008fbafc25b4b85 100644
366+
--- a/src/config/rollup.config.js
367+
+++ b/src/config/rollup.config.js
368+
@@ -141,6 +141,7 @@ function greenwoodSyncPageResourceBundlesPlugin(compilation) {
369+
}
370+
}
371+
372+
+ console.log({ resourceKey, facadeModuleId });
373+
if (resourceKey === facadeModuleId) {
374+
const { fileName } = bundles[bundle];
375+
const { rawAttributes, contents } = resource;
376+
@@ -587,6 +588,7 @@ function greenwoodSyncImportAttributes(compilation) {
377+
378+
const getRollupConfigForBrowserScripts = async (compilation) => {
379+
const { outputDir } = compilation.context;
380+
+ console.log('?????', compilation.resources.values())
381+
const input = [...compilation.resources.values()]
382+
.filter(resource => resource.type === 'script')
383+
.map(resource => normalizePathnameForWindows(resource.sourcePathURL));
384+
diff --git a/src/lib/resource-utils.js b/src/lib/resource-utils.js
385+
index 6a78e464785b6dc11e909acf64f66db975e77909..d4c5ac967a4dcf126b4cf9c85d5d3615ebde03d8 100644
386+
--- a/src/lib/resource-utils.js
387+
+++ b/src/lib/resource-utils.js
388+
@@ -2,17 +2,39 @@ import fs from 'fs/promises';
389+
import { hashString } from './hashing-utils.js';
390+
import htmlparser from 'node-html-parser';
391+
392+
+function getPackageNameFromSrc(src) {
393+
+ const s = src.replace('/node_modules/', '');
394+
+ const pieces = s.split('/');
395+
+ let name;
396+
+
397+
+ console.log({ pieces });
398+
+ if (s.startsWith('@')) {
399+
+ name = `${pieces[0]}/${pieces[1]}`;
400+
+ } else {
401+
+ name = pieces[0];
402+
+ }
403+
+
404+
+ console.log({ name });
405+
+
406+
+ return name;
407+
+}
408+
async function modelResource(context, type, src = undefined, contents = undefined, optimizationAttr = undefined, rawAttributes = undefined) {
409+
const { projectDirectory, scratchDir, userWorkspace } = context;
410+
const extension = type === 'script' ? 'js' : 'css';
411+
let sourcePathURL;
412+
413+
if (src) {
414+
- sourcePathURL = src.startsWith('/node_modules')
415+
- ? new URL(`.${src}`, projectDirectory)
416+
- : src.startsWith('/')
417+
+ if (src.startsWith('/node_modules')) {
418+
+ const name = getPackageNameFromSrc(src);
419+
+ const resolved = import.meta.resolve(name);
420+
+
421+
+ sourcePathURL = new URL(resolved);
422+
+ console.log('modelResource', { name, resolved, sourcePathURL });
423+
+ } else {
424+
+ sourcePathURL = src.startsWith('/')
425+
? new URL(`.${src}`, userWorkspace)
426+
: new URL(`./${src.replace(/\.\.\//g, '').replace('./', '')}`, userWorkspace);
427+
+ }
428+
429+
contents = await fs.readFile(sourcePathURL, 'utf-8');
430+
} else {
431+
@@ -112,6 +134,7 @@ async function resolveForRelativeUrl(url, rootUrl) {
432+
}
433+
434+
async function trackResourcesForRoute(html, compilation, route) {
435+
+ console.log('trackResourcesForRoute', { route });
436+
const { context } = compilation;
437+
const root = htmlparser.parse(html, {
438+
script: true,
439+
@@ -163,6 +186,7 @@ async function trackResourcesForRoute(html, compilation, route) {
440+
441+
compilation.graph.find(page => page.route === route).resources = resources.map(resource => resource.sourcePathURL.pathname);
442+
443+
+ console.log('$$$', { resources });
444+
return resources;
445+
}
446+
447+
diff --git a/src/lifecycles/bundle.js b/src/lifecycles/bundle.js
448+
index 814d1b9462c02530f81a7bec1d393f6609c5a9b9..992f239c76643748119d53cef7b809b22623de8b 100644
449+
--- a/src/lifecycles/bundle.js
450+
+++ b/src/lifecycles/bundle.js
451+
@@ -332,6 +332,8 @@ async function bundleScriptResources(compilation) {
452+
// https://rollupjs.org/guide/en/#differences-to-the-javascript-api
453+
const [rollupConfig] = await getRollupConfigForBrowserScripts(compilation);
454+
455+
+ console.log({ rollupConfig });
456+
+
457+
if (rollupConfig.input.length !== 0) {
458+
const bundle = await rollup(rollupConfig);
459+
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)