Skip to content

Commit 19f9181

Browse files
Fix Eleventy plugin error with certain configuration file formats (#1112)
1 parent bd18e06 commit 19f9181

File tree

8 files changed

+63
-1
lines changed

8 files changed

+63
-1
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// biome-ignore lint/suspicious/noRedundantUseStrict: fixture festa
2+
'use strict';
3+
4+
// biome-ignore lint/complexity/useArrowFunction: fixture festa
5+
module.exports = async function (eleventyConfig) {
6+
eleventyConfig.addPassthroughCopy('./src/assets/');
7+
};
8+
9+
module.exports.config = {
10+
dir: {
11+
input: 'src',
12+
data: '_siteData',
13+
},
14+
};

packages/knip/fixtures/plugins/eleventy4/node_modules/@11ty/eleventy/index.js

Whitespace-only changes.

packages/knip/fixtures/plugins/eleventy4/node_modules/@11ty/eleventy/package.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "@plugins/eleventy4",
3+
"scripts": {
4+
"start": "npx @11ty/eleventy --serve",
5+
"build": "npx @11ty/eleventy",
6+
"build:website:watch": "eleventy --serve --port=2023"
7+
},
8+
"devDependencies": {
9+
"@11ty/eleventy": "*"
10+
}
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const data = {
2+
title: 'Eleventy',
3+
};
4+
5+
module.exports = data;

packages/knip/fixtures/plugins/eleventy4/src/assets/index.js

Whitespace-only changes.

packages/knip/src/plugins/eleventy/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const resolveConfig: ResolveConfig<EleventyConfigOrFn> = async (localConfig, opt
2828

2929
const inputDir = localConfig?.dir?.input || defaultEleventyConfig.dir.input;
3030
const dataDir = localConfig?.dir?.data || defaultEleventyConfig.dir.data;
31-
const templateFormats = localConfig.templateFormats || defaultEleventyConfig.templateFormats;
31+
const templateFormats = localConfig?.templateFormats || defaultEleventyConfig.templateFormats;
3232

3333
const exts = DEFAULT_EXTENSIONS.map(extname => extname.slice(1)).join(',');
3434
const copiedEntries = new Set<string>();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { test } from 'bun:test';
2+
import assert from 'node:assert/strict';
3+
import { main } from '../../src/index.js';
4+
import { resolve } from '../../src/util/path.js';
5+
import baseArguments from '../helpers/baseArguments.js';
6+
import baseCounters from '../helpers/baseCounters.js';
7+
8+
const cwd = resolve('fixtures/plugins/eleventy4');
9+
10+
// Uses a config file with default and `config` export. While this is not
11+
// currently supported, this test ensures that an error is not thrown.
12+
test('Find dependencies with the Eleventy plugin (4)', async () => {
13+
const { counters } = await main({
14+
...baseArguments,
15+
cwd,
16+
});
17+
18+
assert.deepEqual(counters, {
19+
...baseCounters,
20+
// One file is found because the `config` export is not used, so the
21+
// default `config.dir.data` directory is used instead.
22+
files: 1,
23+
processed: 3,
24+
total: 3,
25+
});
26+
});

0 commit comments

Comments
 (0)