Skip to content

Commit

Permalink
[labs/eleventy-plugin-lit] Fix transform for when outputPath is false (
Browse files Browse the repository at this point in the history
  • Loading branch information
p-ob authored Jun 27, 2022
1 parent 0c9ee0e commit da4e097
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/tame-stingrays-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lit-labs/eleventy-plugin-lit': patch
---

Fix transform breakage in situations where `outputPath` is false (e.g. setting `permalink: false` or using the serverless plugin).
8 changes: 4 additions & 4 deletions packages/labs/eleventy-plugin-lit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ function configureWorker(

eleventyConfig.addTransform(
'render-lit',
async (content: string, outputPath: string) => {
if (!outputPath.endsWith('.html')) {
async (content: string, outputPath: string | false) => {
if (outputPath && !outputPath.endsWith('.html')) {
return content;
}

Expand Down Expand Up @@ -180,8 +180,8 @@ ${reset}`

eleventyConfig.addTransform(
'render-lit',
async (content: string, outputPath: string) => {
if (!outputPath.endsWith('.html')) {
async (content: string, outputPath: string | false) => {
if (outputPath && !outputPath.endsWith('.html')) {
return content;
}

Expand Down
34 changes: 31 additions & 3 deletions packages/labs/eleventy-plugin-lit/src/test/eleventy-plugin-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const tempRoot = pathlib.resolve(__dirname, '__temp');
* Normalizes indentation and leading/trailing newlines.
*/
const normalize = (s: string) => stripIndent(s).trim() + '\n';
const sleep = (ms: number) =>
new Promise<void>((resolve) => setTimeout(() => resolve(), ms));

/**
* Utilities for managing a temporary filesystem and running Eleventy.
Expand Down Expand Up @@ -302,7 +304,7 @@ modes.forEach((mode) => {
<my-container>
<my-content></my-content>
</my-container>
# Heading 2
<my-container></my-container>
`,
Expand All @@ -321,14 +323,14 @@ modes.forEach((mode) => {
// js
'js/my-element.js': `
import { html, LitElement } from 'lit';
class MyContainer extends LitElement {
render() {
return html\`<slot></slot>\`;
}
}
customElements.define('my-container', MyContainer);
class MyContent extends LitElement {
render() {
return html\`<b>shadow content</b>\`;
Expand Down Expand Up @@ -534,6 +536,32 @@ modes.forEach((mode) => {
);
}
});

test('template files with `permalink: false` in frontmatter', async ({
rig,
}) => {
await rig.write({
...myElementDefinitionAndConfig,
// md
'index.md': `
---
permalink: false
---
# Heading
<my-element></my-element>
`,
});

const {kill, done} = rig.exec(baseCommandToExec);
const timeout = 10_000;
await Promise.race([
done.then(({code}) => assert.equal(code, 0)),
sleep(timeout).then(() => {
kill(/* SIGINT */ 2);
assert.not(true, `11ty process didn't exit in ${timeout}ms.`);
}),
]);
});
});

test.run();

0 comments on commit da4e097

Please sign in to comment.