From 54d327119e6cd73e7dd377a36afd9043f114a407 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 17 Jan 2024 06:43:20 -0500 Subject: [PATCH 01/20] Add dummy userConfig class, load config, add default config --- packages/knip/src/plugins/eleventy/helpers.ts | 150 ++++++++++++++++++ packages/knip/src/plugins/eleventy/index.ts | 9 +- packages/knip/src/plugins/eleventy/types.ts | 9 ++ 3 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 packages/knip/src/plugins/eleventy/helpers.ts create mode 100644 packages/knip/src/plugins/eleventy/types.ts diff --git a/packages/knip/src/plugins/eleventy/helpers.ts b/packages/knip/src/plugins/eleventy/helpers.ts new file mode 100644 index 000000000..16a6312c1 --- /dev/null +++ b/packages/knip/src/plugins/eleventy/helpers.ts @@ -0,0 +1,150 @@ +import type { EleventyConfig } from "./types.js"; + +export class DummyEleventyConfig { + constructor() {}; + _getUniqueId() {}; + reset() {}; + versionCheck() {}; + on() {}; + emit() {}; + _enablePluginExecution() {}; + addMarkdownHighlighter() {}; + addLiquidTag() {}; + addLiquidFilter() {}; + addNunjucksAsyncFilter() {}; + addNunjucksFilter() {}; + addHandlebarsHelper() {}; + addFilter() {}; + addAsyncFilter() {}; + getFilter() {}; + addNunjucksTag() {}; + addGlobalData() {}; + addNunjucksGlobal() {}; + addTransform() {}; + addLinter() {}; + addLayoutAlias() {}; + setLayoutResolution() {}; + enableLayoutResolution() {}; + getCollections() {}; + addCollection() {}; + addPlugin() {}; + _getPluginName() {}; + _executePlugin() {}; + getNamespacedName() {}; + namespace() {}; + addPassthroughCopy() {}; + _normalizeTemplateFormats() {}; + setTemplateFormats() {}; + addTemplateFormats() {}; + setLibrary() {}; + amendLibrary() {}; + setPugOptions() {}; + setLiquidOptions() {}; + setNunjucksEnvironmentOptions() {}; + setNunjucksPrecompiledTemplates() {}; + setEjsOptions() {}; + setDynamicPermalinks() {}; + setUseGitIgnore() {}; + addShortcode() {}; + addAsyncShortcode() {}; + addNunjucksAsyncShortcode() {}; + addNunjucksShortcode() {}; + addLiquidShortcode() {}; + addHandlebarsShortcode() {}; + addPairedShortcode() {}; + addPairedAsyncShortcode() {}; + addPairedNunjucksAsyncShortcode() {}; + addPairedNunjucksShortcode() {}; + addPairedLiquidShortcode() {}; + addPairedHandlebarsShortcode() {}; + addJavaScriptFunction() {}; + setDataDeepMerge() {}; + isDataDeepMergeModified() {}; + addWatchTarget() {}; + setWatchJavaScriptDependencies() {}; + setServerOptions() {}; + setBrowserSyncConfig() {}; + setChokidarConfig() {}; + setWatchThrottleWaitTime() {}; + setFrontMatterParsingOptions() {}; + setQuietMode() {}; + addExtension() {}; + addDataExtension() {}; + setUseTemplateCache() {}; + setPrecompiledCollections() {}; + setServerPassthroughCopyBehavior() {}; + addUrlTransform() {}; + setDataFileSuffixes() {}; + setDataFileBaseName() {}; + getMergingConfigObject() {}; + + _uniqueId = {}; + events = {}; + benchmarkManager = {}; + benchmarks = {}; + collections = {}; + precompiledCollections = {}; + templateFormats = {}; + liquidOptions = {}; + liquidTags = {}; + liquidFilters = {}; + liquidShortcodes = {}; + liquidPairedShortcodes = {}; + nunjucksEnvironmentOptions = {}; + nunjucksPrecompiledTemplates = {}; + nunjucksFilters = {}; + nunjucksAsyncFilters = {}; + nunjucksTags = {}; + nunjucksGlobals = {}; + nunjucksShortcodes = {}; + nunjucksAsyncShortcodes = {}; + nunjucksPairedShortcodes = {}; + nunjucksAsyncPairedShortcodes = {}; + javascriptFunctions = {}; + markdownHighlighter = null; + libraryOverrides = {}; + passthroughCopies = {}; + layoutAliases = {}; + layoutResolution = true; + linters = {}; + transforms = {}; + activeNamespace = ""; + DateTime = {}; + dynamicPermalinks = true; + useGitIgnore = true; + ignores = new Set(); + watchIgnores = new Set(); + dataDeepMerge = true; + extensionMap = new Set(); + watchJavaScriptDependencies = true; + additionalWatchTargets = []; + serverOptions = {}; + globalData = {}; + chokidarConfig = {}; + watchThrottleWaitTime = 0; + dataExtensions = new Map(); + quietMode = false; + plugins = []; + _pluginExecution = false; + useTemplateCache = true; + dataFilterSelectors = new Set(); + libraryAmendments = {}; + serverPassthroughCopyBehavior = ""; + urlTransforms = []; + dataFileSuffixesOverride = false; + dataFileDirBaseNameOverride = false; + frontMatterParsingOptions = { + engines: {} + }; + templateFormatsAdded = {}; +} + +export const defaultEleventyConfig: EleventyConfig = { + dir: { + input: ".", + output: "_site", + includes: "_includes", + layouts: "_includes", + data: "_data" + } +} \ No newline at end of file diff --git a/packages/knip/src/plugins/eleventy/index.ts b/packages/knip/src/plugins/eleventy/index.ts index 7f5bb9576..c70f0d401 100644 --- a/packages/knip/src/plugins/eleventy/index.ts +++ b/packages/knip/src/plugins/eleventy/index.ts @@ -1,7 +1,10 @@ import { timerify } from '../../util/Performance.js'; -import { hasDependency } from '../../util/plugin.js'; +import { hasDependency, load } from '../../util/plugin.js'; import { toEntryPattern, toProductionEntryPattern } from '../../util/protocols.js'; import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js'; +import { DummyEleventyConfig, defaultEleventyConfig } from './helpers.js'; +import type { EleventyConfig } from './types.js'; +import { join } from '../../util/path.js'; // https://www.11ty.dev/docs/ @@ -18,6 +21,10 @@ const PRODUCTION_ENTRY_FILE_PATTERNS = ['posts/**/*.11tydata.js', '_data/**/*.{j const findEleventyDependencies: GenericPluginCallback = async (configFilePath, options) => { const { config } = options; + const localConfig: ((arg0: DummyEleventyConfig) => Promise) = await load(configFilePath); + + const result = { ...(await localConfig(new DummyEleventyConfig())), ...defaultEleventyConfig } + return config.entry ? config.entry.map(toProductionEntryPattern) : [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)]; diff --git a/packages/knip/src/plugins/eleventy/types.ts b/packages/knip/src/plugins/eleventy/types.ts new file mode 100644 index 000000000..d4ab7d5fc --- /dev/null +++ b/packages/knip/src/plugins/eleventy/types.ts @@ -0,0 +1,9 @@ +export type EleventyConfig = { + dir: { + input: string, + output: string, + includes: string, + layouts: string, + data: string, + }, +} \ No newline at end of file From 975eb7c1dd72a9d82d8a89c0cd9d661ec81e303b Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 17 Jan 2024 06:44:39 -0500 Subject: [PATCH 02/20] Format --- packages/knip/src/plugins/eleventy/helpers.ts | 288 +++++++++--------- packages/knip/src/plugins/eleventy/index.ts | 4 +- packages/knip/src/plugins/eleventy/types.ts | 16 +- 3 files changed, 154 insertions(+), 154 deletions(-) diff --git a/packages/knip/src/plugins/eleventy/helpers.ts b/packages/knip/src/plugins/eleventy/helpers.ts index 16a6312c1..68e0f5a39 100644 --- a/packages/knip/src/plugins/eleventy/helpers.ts +++ b/packages/knip/src/plugins/eleventy/helpers.ts @@ -1,150 +1,150 @@ -import type { EleventyConfig } from "./types.js"; +import type { EleventyConfig } from './types.js'; export class DummyEleventyConfig { - constructor() {}; - _getUniqueId() {}; - reset() {}; - versionCheck() {}; - on() {}; - emit() {}; - _enablePluginExecution() {}; - addMarkdownHighlighter() {}; - addLiquidTag() {}; - addLiquidFilter() {}; - addNunjucksAsyncFilter() {}; - addNunjucksFilter() {}; - addHandlebarsHelper() {}; - addFilter() {}; - addAsyncFilter() {}; - getFilter() {}; - addNunjucksTag() {}; - addGlobalData() {}; - addNunjucksGlobal() {}; - addTransform() {}; - addLinter() {}; - addLayoutAlias() {}; - setLayoutResolution() {}; - enableLayoutResolution() {}; - getCollections() {}; - addCollection() {}; - addPlugin() {}; - _getPluginName() {}; - _executePlugin() {}; - getNamespacedName() {}; - namespace() {}; - addPassthroughCopy() {}; - _normalizeTemplateFormats() {}; - setTemplateFormats() {}; - addTemplateFormats() {}; - setLibrary() {}; - amendLibrary() {}; - setPugOptions() {}; - setLiquidOptions() {}; - setNunjucksEnvironmentOptions() {}; - setNunjucksPrecompiledTemplates() {}; - setEjsOptions() {}; - setDynamicPermalinks() {}; - setUseGitIgnore() {}; - addShortcode() {}; - addAsyncShortcode() {}; - addNunjucksAsyncShortcode() {}; - addNunjucksShortcode() {}; - addLiquidShortcode() {}; - addHandlebarsShortcode() {}; - addPairedShortcode() {}; - addPairedAsyncShortcode() {}; - addPairedNunjucksAsyncShortcode() {}; - addPairedNunjucksShortcode() {}; - addPairedLiquidShortcode() {}; - addPairedHandlebarsShortcode() {}; - addJavaScriptFunction() {}; - setDataDeepMerge() {}; - isDataDeepMergeModified() {}; - addWatchTarget() {}; - setWatchJavaScriptDependencies() {}; - setServerOptions() {}; - setBrowserSyncConfig() {}; - setChokidarConfig() {}; - setWatchThrottleWaitTime() {}; - setFrontMatterParsingOptions() {}; - setQuietMode() {}; - addExtension() {}; - addDataExtension() {}; - setUseTemplateCache() {}; - setPrecompiledCollections() {}; - setServerPassthroughCopyBehavior() {}; - addUrlTransform() {}; - setDataFileSuffixes() {}; - setDataFileBaseName() {}; - getMergingConfigObject() {}; + constructor() {} + _getUniqueId() {} + reset() {} + versionCheck() {} + on() {} + emit() {} + _enablePluginExecution() {} + addMarkdownHighlighter() {} + addLiquidTag() {} + addLiquidFilter() {} + addNunjucksAsyncFilter() {} + addNunjucksFilter() {} + addHandlebarsHelper() {} + addFilter() {} + addAsyncFilter() {} + getFilter() {} + addNunjucksTag() {} + addGlobalData() {} + addNunjucksGlobal() {} + addTransform() {} + addLinter() {} + addLayoutAlias() {} + setLayoutResolution() {} + enableLayoutResolution() {} + getCollections() {} + addCollection() {} + addPlugin() {} + _getPluginName() {} + _executePlugin() {} + getNamespacedName() {} + namespace() {} + addPassthroughCopy() {} + _normalizeTemplateFormats() {} + setTemplateFormats() {} + addTemplateFormats() {} + setLibrary() {} + amendLibrary() {} + setPugOptions() {} + setLiquidOptions() {} + setNunjucksEnvironmentOptions() {} + setNunjucksPrecompiledTemplates() {} + setEjsOptions() {} + setDynamicPermalinks() {} + setUseGitIgnore() {} + addShortcode() {} + addAsyncShortcode() {} + addNunjucksAsyncShortcode() {} + addNunjucksShortcode() {} + addLiquidShortcode() {} + addHandlebarsShortcode() {} + addPairedShortcode() {} + addPairedAsyncShortcode() {} + addPairedNunjucksAsyncShortcode() {} + addPairedNunjucksShortcode() {} + addPairedLiquidShortcode() {} + addPairedHandlebarsShortcode() {} + addJavaScriptFunction() {} + setDataDeepMerge() {} + isDataDeepMergeModified() {} + addWatchTarget() {} + setWatchJavaScriptDependencies() {} + setServerOptions() {} + setBrowserSyncConfig() {} + setChokidarConfig() {} + setWatchThrottleWaitTime() {} + setFrontMatterParsingOptions() {} + setQuietMode() {} + addExtension() {} + addDataExtension() {} + setUseTemplateCache() {} + setPrecompiledCollections() {} + setServerPassthroughCopyBehavior() {} + addUrlTransform() {} + setDataFileSuffixes() {} + setDataFileBaseName() {} + getMergingConfigObject() {} - _uniqueId = {}; - events = {}; - benchmarkManager = {}; - benchmarks = {}; - collections = {}; - precompiledCollections = {}; - templateFormats = {}; - liquidOptions = {}; - liquidTags = {}; - liquidFilters = {}; - liquidShortcodes = {}; - liquidPairedShortcodes = {}; - nunjucksEnvironmentOptions = {}; - nunjucksPrecompiledTemplates = {}; - nunjucksFilters = {}; - nunjucksAsyncFilters = {}; - nunjucksTags = {}; - nunjucksGlobals = {}; - nunjucksShortcodes = {}; - nunjucksAsyncShortcodes = {}; - nunjucksPairedShortcodes = {}; - nunjucksAsyncPairedShortcodes = {}; - javascriptFunctions = {}; - markdownHighlighter = null; - libraryOverrides = {}; - passthroughCopies = {}; - layoutAliases = {}; - layoutResolution = true; - linters = {}; - transforms = {}; - activeNamespace = ""; - DateTime = {}; - dynamicPermalinks = true; - useGitIgnore = true; - ignores = new Set(); - watchIgnores = new Set(); - dataDeepMerge = true; - extensionMap = new Set(); - watchJavaScriptDependencies = true; - additionalWatchTargets = []; - serverOptions = {}; - globalData = {}; - chokidarConfig = {}; - watchThrottleWaitTime = 0; - dataExtensions = new Map(); - quietMode = false; - plugins = []; - _pluginExecution = false; - useTemplateCache = true; - dataFilterSelectors = new Set(); - libraryAmendments = {}; - serverPassthroughCopyBehavior = ""; - urlTransforms = []; - dataFileSuffixesOverride = false; - dataFileDirBaseNameOverride = false; - frontMatterParsingOptions = { - engines: {} - }; - templateFormatsAdded = {}; + _uniqueId = {}; + events = {}; + benchmarkManager = {}; + benchmarks = {}; + collections = {}; + precompiledCollections = {}; + templateFormats = {}; + liquidOptions = {}; + liquidTags = {}; + liquidFilters = {}; + liquidShortcodes = {}; + liquidPairedShortcodes = {}; + nunjucksEnvironmentOptions = {}; + nunjucksPrecompiledTemplates = {}; + nunjucksFilters = {}; + nunjucksAsyncFilters = {}; + nunjucksTags = {}; + nunjucksGlobals = {}; + nunjucksShortcodes = {}; + nunjucksAsyncShortcodes = {}; + nunjucksPairedShortcodes = {}; + nunjucksAsyncPairedShortcodes = {}; + javascriptFunctions = {}; + markdownHighlighter = null; + libraryOverrides = {}; + passthroughCopies = {}; + layoutAliases = {}; + layoutResolution = true; + linters = {}; + transforms = {}; + activeNamespace = ''; + DateTime = {}; + dynamicPermalinks = true; + useGitIgnore = true; + ignores = new Set(); + watchIgnores = new Set(); + dataDeepMerge = true; + extensionMap = new Set(); + watchJavaScriptDependencies = true; + additionalWatchTargets = []; + serverOptions = {}; + globalData = {}; + chokidarConfig = {}; + watchThrottleWaitTime = 0; + dataExtensions = new Map(); + quietMode = false; + plugins = []; + _pluginExecution = false; + useTemplateCache = true; + dataFilterSelectors = new Set(); + libraryAmendments = {}; + serverPassthroughCopyBehavior = ''; + urlTransforms = []; + dataFileSuffixesOverride = false; + dataFileDirBaseNameOverride = false; + frontMatterParsingOptions = { + engines: {}, + }; + templateFormatsAdded = {}; } export const defaultEleventyConfig: EleventyConfig = { - dir: { - input: ".", - output: "_site", - includes: "_includes", - layouts: "_includes", - data: "_data" - } -} \ No newline at end of file + dir: { + input: '.', + output: '_site', + includes: '_includes', + layouts: '_includes', + data: '_data', + }, +}; diff --git a/packages/knip/src/plugins/eleventy/index.ts b/packages/knip/src/plugins/eleventy/index.ts index c70f0d401..36472850a 100644 --- a/packages/knip/src/plugins/eleventy/index.ts +++ b/packages/knip/src/plugins/eleventy/index.ts @@ -21,9 +21,9 @@ const PRODUCTION_ENTRY_FILE_PATTERNS = ['posts/**/*.11tydata.js', '_data/**/*.{j const findEleventyDependencies: GenericPluginCallback = async (configFilePath, options) => { const { config } = options; - const localConfig: ((arg0: DummyEleventyConfig) => Promise) = await load(configFilePath); + const localConfig: (arg0: DummyEleventyConfig) => Promise = await load(configFilePath); - const result = { ...(await localConfig(new DummyEleventyConfig())), ...defaultEleventyConfig } + const result = { ...(await localConfig(new DummyEleventyConfig())), ...defaultEleventyConfig }; return config.entry ? config.entry.map(toProductionEntryPattern) diff --git a/packages/knip/src/plugins/eleventy/types.ts b/packages/knip/src/plugins/eleventy/types.ts index d4ab7d5fc..f9eadd849 100644 --- a/packages/knip/src/plugins/eleventy/types.ts +++ b/packages/knip/src/plugins/eleventy/types.ts @@ -1,9 +1,9 @@ export type EleventyConfig = { - dir: { - input: string, - output: string, - includes: string, - layouts: string, - data: string, - }, -} \ No newline at end of file + dir: { + input: string; + output: string; + includes: string; + layouts: string; + data: string; + }; +}; From 3626c9516dbbfc8f69a190d44998125d67fd91be Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 17 Jan 2024 06:48:47 -0500 Subject: [PATCH 03/20] Check if is function, create pattern --- packages/knip/src/plugins/eleventy/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/knip/src/plugins/eleventy/index.ts b/packages/knip/src/plugins/eleventy/index.ts index 36472850a..9c3307571 100644 --- a/packages/knip/src/plugins/eleventy/index.ts +++ b/packages/knip/src/plugins/eleventy/index.ts @@ -21,9 +21,13 @@ const PRODUCTION_ENTRY_FILE_PATTERNS = ['posts/**/*.11tydata.js', '_data/**/*.{j const findEleventyDependencies: GenericPluginCallback = async (configFilePath, options) => { const { config } = options; - const localConfig: (arg0: DummyEleventyConfig) => Promise = await load(configFilePath); + let localConfig = await load(configFilePath); + if (typeof localConfig === 'function') localConfig = await localConfig(new DummyEleventyConfig()); - const result = { ...(await localConfig(new DummyEleventyConfig())), ...defaultEleventyConfig }; + const result = { ...localConfig, ...defaultEleventyConfig }; + + // Data directory pattern: + toEntryPattern(`${join(result.dir.input, result.dir.data)}/**/*.js`); return config.entry ? config.entry.map(toProductionEntryPattern) From bc4bec3441dc48c2174b72bfd9b354e6cb3d1899 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 17 Jan 2024 06:51:03 -0500 Subject: [PATCH 04/20] Add links to sources for dummy and default values --- packages/knip/src/plugins/eleventy/helpers.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/knip/src/plugins/eleventy/helpers.ts b/packages/knip/src/plugins/eleventy/helpers.ts index 68e0f5a39..373043ed6 100644 --- a/packages/knip/src/plugins/eleventy/helpers.ts +++ b/packages/knip/src/plugins/eleventy/helpers.ts @@ -1,5 +1,6 @@ import type { EleventyConfig } from './types.js'; +// https://github.com/11ty/eleventy/blob/main/src/UserConfig.js export class DummyEleventyConfig { constructor() {} _getUniqueId() {} @@ -139,6 +140,7 @@ export class DummyEleventyConfig { templateFormatsAdded = {}; } +// https://www.11ty.dev/docs/config/#configuration-options export const defaultEleventyConfig: EleventyConfig = { dir: { input: '.', From bdf67b88632715ba19a72a95dd46d2f60deb7c29 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 17 Jan 2024 07:08:30 -0500 Subject: [PATCH 05/20] Join paths instead of concat --- packages/knip/src/plugins/eleventy/index.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/knip/src/plugins/eleventy/index.ts b/packages/knip/src/plugins/eleventy/index.ts index 9c3307571..7bffbfdd7 100644 --- a/packages/knip/src/plugins/eleventy/index.ts +++ b/packages/knip/src/plugins/eleventy/index.ts @@ -23,11 +23,10 @@ const findEleventyDependencies: GenericPluginCallback = async (configFilePath, o let localConfig = await load(configFilePath); if (typeof localConfig === 'function') localConfig = await localConfig(new DummyEleventyConfig()); - - const result = { ...localConfig, ...defaultEleventyConfig }; + localConfig = { ...localConfig, ...defaultEleventyConfig }; // Data directory pattern: - toEntryPattern(`${join(result.dir.input, result.dir.data)}/**/*.js`); + toEntryPattern(join(localConfig.dir.input, localConfig.dir.data, '**/*.js')); return config.entry ? config.entry.map(toProductionEntryPattern) From 45dec032269eeea69099411999fbe3511c239cc4 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 17 Jan 2024 07:19:30 -0500 Subject: [PATCH 06/20] Remove production entry patterns, return new entry patterns --- packages/knip/src/plugins/eleventy/index.ts | 22 ++++++++++----------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/knip/src/plugins/eleventy/index.ts b/packages/knip/src/plugins/eleventy/index.ts index 7bffbfdd7..c6debf225 100644 --- a/packages/knip/src/plugins/eleventy/index.ts +++ b/packages/knip/src/plugins/eleventy/index.ts @@ -1,10 +1,9 @@ +import { join } from '../../util/path.js'; import { timerify } from '../../util/Performance.js'; import { hasDependency, load } from '../../util/plugin.js'; -import { toEntryPattern, toProductionEntryPattern } from '../../util/protocols.js'; -import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js'; +import { toEntryPattern } from '../../util/protocols.js'; import { DummyEleventyConfig, defaultEleventyConfig } from './helpers.js'; -import type { EleventyConfig } from './types.js'; -import { join } from '../../util/path.js'; +import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js'; // https://www.11ty.dev/docs/ @@ -16,8 +15,6 @@ const isEnabled: IsPluginEnabledCallback = ({ dependencies }) => hasDependency(d const ENTRY_FILE_PATTERNS = ['.eleventy.js', 'eleventy.config.{js,cjs}']; -const PRODUCTION_ENTRY_FILE_PATTERNS = ['posts/**/*.11tydata.js', '_data/**/*.{js,cjs,mjs}']; - const findEleventyDependencies: GenericPluginCallback = async (configFilePath, options) => { const { config } = options; @@ -25,12 +22,13 @@ const findEleventyDependencies: GenericPluginCallback = async (configFilePath, o if (typeof localConfig === 'function') localConfig = await localConfig(new DummyEleventyConfig()); localConfig = { ...localConfig, ...defaultEleventyConfig }; - // Data directory pattern: - toEntryPattern(join(localConfig.dir.input, localConfig.dir.data, '**/*.js')); - - return config.entry - ? config.entry.map(toProductionEntryPattern) - : [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)]; + return ( + config?.entry ?? [ + join(localConfig.dir.input, localConfig.dir.data, '**/*.js'), + join(localConfig.dir.input, '**/*.11tydata.js'), + ] ?? + ENTRY_FILE_PATTERNS + ).map(toEntryPattern); }; const findDependencies = timerify(findEleventyDependencies); From 49210a56ebc417e9d0b9f4ed6c01d0480b3f5181 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 17 Jan 2024 07:21:37 -0500 Subject: [PATCH 07/20] Remove export --- packages/knip/src/plugins/eleventy/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/knip/src/plugins/eleventy/index.ts b/packages/knip/src/plugins/eleventy/index.ts index c6debf225..fcfcf742e 100644 --- a/packages/knip/src/plugins/eleventy/index.ts +++ b/packages/knip/src/plugins/eleventy/index.ts @@ -38,6 +38,5 @@ export default { ENABLERS, isEnabled, ENTRY_FILE_PATTERNS, - PRODUCTION_ENTRY_FILE_PATTERNS, findDependencies, }; From aec6e374136d148c5448c299679978f087f30305 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 17 Jan 2024 07:26:42 -0500 Subject: [PATCH 08/20] Support templateFormats --- packages/knip/src/plugins/eleventy/helpers.ts | 1 + packages/knip/src/plugins/eleventy/index.ts | 4 ++++ packages/knip/src/plugins/eleventy/types.ts | 1 + 3 files changed, 6 insertions(+) diff --git a/packages/knip/src/plugins/eleventy/helpers.ts b/packages/knip/src/plugins/eleventy/helpers.ts index 373043ed6..4ea002a6a 100644 --- a/packages/knip/src/plugins/eleventy/helpers.ts +++ b/packages/knip/src/plugins/eleventy/helpers.ts @@ -149,4 +149,5 @@ export const defaultEleventyConfig: EleventyConfig = { layouts: '_includes', data: '_data', }, + templateFormats: 'html,liquid,ejs,md,hbs,mustache,haml,pug,njk,11ty.js', }; diff --git a/packages/knip/src/plugins/eleventy/index.ts b/packages/knip/src/plugins/eleventy/index.ts index fcfcf742e..b323855f5 100644 --- a/packages/knip/src/plugins/eleventy/index.ts +++ b/packages/knip/src/plugins/eleventy/index.ts @@ -25,6 +25,10 @@ const findEleventyDependencies: GenericPluginCallback = async (configFilePath, o return ( config?.entry ?? [ join(localConfig.dir.input, localConfig.dir.data, '**/*.js'), + join( + localConfig.dir.input, + `**/*.{${typeof localConfig.templateFormats === 'string' ? localConfig.templateFormats : localConfig.templateFormats.join(',')}}` + ), join(localConfig.dir.input, '**/*.11tydata.js'), ] ?? ENTRY_FILE_PATTERNS diff --git a/packages/knip/src/plugins/eleventy/types.ts b/packages/knip/src/plugins/eleventy/types.ts index f9eadd849..6d109f3b6 100644 --- a/packages/knip/src/plugins/eleventy/types.ts +++ b/packages/knip/src/plugins/eleventy/types.ts @@ -6,4 +6,5 @@ export type EleventyConfig = { layouts: string; data: string; }; + templateFormats: string | string[]; }; From 92470075be332472d9f3aaef0b1f8016f072a7a4 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 17 Jan 2024 07:54:35 -0500 Subject: [PATCH 09/20] Update test --- packages/knip/test/plugins/eleventy.test.ts | 25 +++++++++------------ 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/knip/test/plugins/eleventy.test.ts b/packages/knip/test/plugins/eleventy.test.ts index fe6302b6e..7ac93c891 100644 --- a/packages/knip/test/plugins/eleventy.test.ts +++ b/packages/knip/test/plugins/eleventy.test.ts @@ -1,21 +1,18 @@ import assert from 'node:assert/strict'; import test from 'node:test'; -import { main } from '../../src/index.js'; -import { resolve } from '../../src/util/path.js'; -import baseArguments from '../helpers/baseArguments.js'; -import baseCounters from '../helpers/baseCounters.js'; +import { default as eleventy } from '../../src/plugins/eleventy/index.js'; +import { resolve, join } from '../../src/util/path.js'; +import { getManifest, pluginConfig as config } from '../helpers/index.js'; const cwd = resolve('fixtures/plugins/eleventy'); +const manifest = getManifest(cwd); test('Find dependencies in Eleventy configuration', async () => { - const { counters } = await main({ - ...baseArguments, - cwd, - }); - - assert.deepEqual(counters, { - ...baseCounters, - processed: 2, - total: 2, - }); + const configFilePath = join(cwd, 'eleventy.config.cjs'); + const dependencies = await eleventy.findDependencies(configFilePath, { manifest, config }); + assert.deepEqual(dependencies, [ + 'entry:_data/**/*.js', + 'entry:**/*.{html,liquid,ejs,md,hbs,mustache,haml,pug,njk,11ty.js}', + 'entry:**/*.11tydata.js', + ]); }); From 03417dd7daaf4072ca48fe61539e31c380755aab Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 17 Jan 2024 09:40:25 -0500 Subject: [PATCH 10/20] Fix merging with default config, add proper types --- packages/knip/src/plugins/eleventy/index.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/knip/src/plugins/eleventy/index.ts b/packages/knip/src/plugins/eleventy/index.ts index b323855f5..f4683bbfc 100644 --- a/packages/knip/src/plugins/eleventy/index.ts +++ b/packages/knip/src/plugins/eleventy/index.ts @@ -3,6 +3,7 @@ import { timerify } from '../../util/Performance.js'; import { hasDependency, load } from '../../util/plugin.js'; import { toEntryPattern } from '../../util/protocols.js'; import { DummyEleventyConfig, defaultEleventyConfig } from './helpers.js'; +import type { EleventyConfig } from './types.js'; import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js'; // https://www.11ty.dev/docs/ @@ -18,18 +19,20 @@ const ENTRY_FILE_PATTERNS = ['.eleventy.js', 'eleventy.config.{js,cjs}']; const findEleventyDependencies: GenericPluginCallback = async (configFilePath, options) => { const { config } = options; - let localConfig = await load(configFilePath); + let localConfig = (await load(configFilePath)) as + | Partial + | ((arg: DummyEleventyConfig) => Promise>); if (typeof localConfig === 'function') localConfig = await localConfig(new DummyEleventyConfig()); - localConfig = { ...localConfig, ...defaultEleventyConfig }; + + const inputDir = localConfig?.dir?.input || defaultEleventyConfig.dir.input; + const dataDir = localConfig?.dir?.data || defaultEleventyConfig.dir.data; + const templateFormats = localConfig.templateFormats || defaultEleventyConfig.templateFormats; return ( config?.entry ?? [ - join(localConfig.dir.input, localConfig.dir.data, '**/*.js'), - join( - localConfig.dir.input, - `**/*.{${typeof localConfig.templateFormats === 'string' ? localConfig.templateFormats : localConfig.templateFormats.join(',')}}` - ), - join(localConfig.dir.input, '**/*.11tydata.js'), + join(inputDir, dataDir, '**/*.js'), + join(inputDir, `**/*.{${typeof templateFormats === 'string' ? templateFormats : templateFormats.join(',')}}`), + join(inputDir, '**/*.11tydata.js'), ] ?? ENTRY_FILE_PATTERNS ).map(toEntryPattern); From 8d6eba75094f4e5da06c597560d9cea49d11a3f5 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 17 Jan 2024 09:40:38 -0500 Subject: [PATCH 11/20] Remove unneeded templateFormats --- packages/knip/src/plugins/eleventy/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/knip/src/plugins/eleventy/helpers.ts b/packages/knip/src/plugins/eleventy/helpers.ts index 4ea002a6a..7425652c5 100644 --- a/packages/knip/src/plugins/eleventy/helpers.ts +++ b/packages/knip/src/plugins/eleventy/helpers.ts @@ -149,5 +149,5 @@ export const defaultEleventyConfig: EleventyConfig = { layouts: '_includes', data: '_data', }, - templateFormats: 'html,liquid,ejs,md,hbs,mustache,haml,pug,njk,11ty.js', + templateFormats: '11ty.js', }; From e1077292f410f0d1becd6a4a37dad80b8b039fcd Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 17 Jan 2024 10:01:57 -0500 Subject: [PATCH 12/20] Add new dynamic test and fixture, update old one to be static --- .../plugins/eleventy/eleventy.config.cjs | 9 +-- .../eleventy/eleventy.config.dynamic.cjs | 57 +++++++++++++++++++ packages/knip/test/plugins/eleventy.test.ts | 12 +++- 3 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 packages/knip/fixtures/plugins/eleventy/eleventy.config.dynamic.cjs diff --git a/packages/knip/fixtures/plugins/eleventy/eleventy.config.cjs b/packages/knip/fixtures/plugins/eleventy/eleventy.config.cjs index b8824232e..24b2ea532 100644 --- a/packages/knip/fixtures/plugins/eleventy/eleventy.config.cjs +++ b/packages/knip/fixtures/plugins/eleventy/eleventy.config.cjs @@ -1,7 +1,4 @@ -module.exports = (_config) => { - return { - htmlTemplateEngine: 'njk', - markdownTemplateEngine: 'njk', - templateFormats: ['njk'], - }; +module.exports = { + htmlTemplateEngine: 'njk', + markdownTemplateEngine: 'njk', }; diff --git a/packages/knip/fixtures/plugins/eleventy/eleventy.config.dynamic.cjs b/packages/knip/fixtures/plugins/eleventy/eleventy.config.dynamic.cjs new file mode 100644 index 000000000..63a0781fd --- /dev/null +++ b/packages/knip/fixtures/plugins/eleventy/eleventy.config.dynamic.cjs @@ -0,0 +1,57 @@ +// Stripped down version of https://github.com/11ty/eleventy-base-blog/blob/main/eleventy.config.js. +module.exports = function (eleventyConfig) { + eleventyConfig.addPassthroughCopy({ + './public/': '/', + './node_modules/prismjs/themes/prism-okaidia.css': '/css/prism-okaidia.css', + }); + eleventyConfig.addWatchTarget('content/**/*.{svg,webp,png,jpeg}'); + eleventyConfig.addPlugin(); + eleventyConfig.addPlugin(); + eleventyConfig.addPlugin(); + eleventyConfig.addPlugin(undefined, { + preAttributes: { tabindex: 0 }, + }); + eleventyConfig.addPlugin(); + eleventyConfig.addPlugin(); + eleventyConfig.addPlugin(); + eleventyConfig.addFilter('readableDate', (dateObj, format, zone) => {}); + eleventyConfig.addFilter('htmlDateString', dateObj => {}); + eleventyConfig.addFilter('head', (array, n) => { + if (!Array.isArray(array) || array.length === 0) { + return []; + } + if (n < 0) { + return array.slice(n); + } + + return array.slice(0, n); + }); + eleventyConfig.addFilter('min', (...numbers) => { + return Math.min.apply(null, numbers); + }); + eleventyConfig.addFilter('getAllTags', collection => { + let tagSet = new Set(); + for (let item of collection) { + (item.data.tags || []).forEach(tag => tagSet.add(tag)); + } + return Array.from(tagSet); + }); + eleventyConfig.addFilter('filterTagList', function filterTagList(tags) { + return (tags || []).filter(tag => ['all', 'nav', 'post', 'posts'].indexOf(tag) === -1); + }); + eleventyConfig.amendLibrary('md', mdLib => { + eleventyConfig.getFilter('slugify'); + }); + return { + templateFormats: ['md', 'njk', 'html', 'liquid'], + markdownTemplateEngine: 'njk', + htmlTemplateEngine: 'njk', + dir: { + input: 'content', + includes: '../_includes', + data: '../_data', + output: '_site', + }, + pathPrefix: '/', + }; +}; diff --git a/packages/knip/test/plugins/eleventy.test.ts b/packages/knip/test/plugins/eleventy.test.ts index 7ac93c891..ae76d3ca7 100644 --- a/packages/knip/test/plugins/eleventy.test.ts +++ b/packages/knip/test/plugins/eleventy.test.ts @@ -7,12 +7,18 @@ import { getManifest, pluginConfig as config } from '../helpers/index.js'; const cwd = resolve('fixtures/plugins/eleventy'); const manifest = getManifest(cwd); -test('Find dependencies in Eleventy configuration', async () => { +test('Find dependencies in Eleventy configuration (static)', async () => { const configFilePath = join(cwd, 'eleventy.config.cjs'); const dependencies = await eleventy.findDependencies(configFilePath, { manifest, config }); + assert.deepEqual(dependencies, ['entry:_data/**/*.js', 'entry:**/*.{11ty.js}', 'entry:**/*.11tydata.js']); +}); + +test('Find dependencies in Eleventy configuration (dynamic)', async () => { + const configFilePath = join(cwd, 'eleventy.config.dynamic.cjs'); + const dependencies = await eleventy.findDependencies(configFilePath, { manifest, config }); assert.deepEqual(dependencies, [ 'entry:_data/**/*.js', - 'entry:**/*.{html,liquid,ejs,md,hbs,mustache,haml,pug,njk,11ty.js}', - 'entry:**/*.11tydata.js', + 'entry:content/**/*.{md,njk,html,liquid}', + 'entry:content/**/*.11tydata.js', ]); }); From fed70165f10c586559c8cf274a7917621dffeb9f Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 17 Jan 2024 10:11:31 -0500 Subject: [PATCH 13/20] Update comment --- .../knip/fixtures/plugins/eleventy/eleventy.config.dynamic.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/knip/fixtures/plugins/eleventy/eleventy.config.dynamic.cjs b/packages/knip/fixtures/plugins/eleventy/eleventy.config.dynamic.cjs index 63a0781fd..5c9ef3266 100644 --- a/packages/knip/fixtures/plugins/eleventy/eleventy.config.dynamic.cjs +++ b/packages/knip/fixtures/plugins/eleventy/eleventy.config.dynamic.cjs @@ -1,4 +1,4 @@ -// Stripped down version of https://github.com/11ty/eleventy-base-blog/blob/main/eleventy.config.js. +// https://github.com/11ty/eleventy-base-blog/blob/main/eleventy.config.js module.exports = function (eleventyConfig) { eleventyConfig.addPassthroughCopy({ './public/': '/', From 489255e3cd5257d62a782a8a2e0198c8b6ba3624 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 17 Jan 2024 10:13:34 -0500 Subject: [PATCH 14/20] Return if no config --- packages/knip/src/plugins/eleventy/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/knip/src/plugins/eleventy/index.ts b/packages/knip/src/plugins/eleventy/index.ts index f4683bbfc..85c693bb3 100644 --- a/packages/knip/src/plugins/eleventy/index.ts +++ b/packages/knip/src/plugins/eleventy/index.ts @@ -22,6 +22,7 @@ const findEleventyDependencies: GenericPluginCallback = async (configFilePath, o let localConfig = (await load(configFilePath)) as | Partial | ((arg: DummyEleventyConfig) => Promise>); + if (!localConfig) return []; if (typeof localConfig === 'function') localConfig = await localConfig(new DummyEleventyConfig()); const inputDir = localConfig?.dir?.input || defaultEleventyConfig.dir.input; From 5ed85f12c9510b02adf32b2cee79ad4847535957 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 17 Jan 2024 10:17:20 -0500 Subject: [PATCH 15/20] Add back improved PRODUCTION_ENTRY_FILE_PATTERNS --- packages/knip/src/plugins/eleventy/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/knip/src/plugins/eleventy/index.ts b/packages/knip/src/plugins/eleventy/index.ts index 85c693bb3..735f7bd99 100644 --- a/packages/knip/src/plugins/eleventy/index.ts +++ b/packages/knip/src/plugins/eleventy/index.ts @@ -16,6 +16,10 @@ const isEnabled: IsPluginEnabledCallback = ({ dependencies }) => hasDependency(d const ENTRY_FILE_PATTERNS = ['.eleventy.js', 'eleventy.config.{js,cjs}']; +const PRODUCTION_ENTRY_FILE_PATTERNS = ['**/*.11tydata.js', '_data/**/*.{js,cjs,mjs}'] + .map(pattern => [`src/${pattern}`, `content/${pattern}`]) + .flat(); + const findEleventyDependencies: GenericPluginCallback = async (configFilePath, options) => { const { config } = options; @@ -46,5 +50,6 @@ export default { ENABLERS, isEnabled, ENTRY_FILE_PATTERNS, + PRODUCTION_ENTRY_FILE_PATTERNS, findDependencies, }; From a00ad707d766f38a548c058235de227881d9f110 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 17 Jan 2024 13:54:16 -0500 Subject: [PATCH 16/20] Default to production entry file patterns --- packages/knip/src/plugins/eleventy/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/knip/src/plugins/eleventy/index.ts b/packages/knip/src/plugins/eleventy/index.ts index 735f7bd99..d349e323a 100644 --- a/packages/knip/src/plugins/eleventy/index.ts +++ b/packages/knip/src/plugins/eleventy/index.ts @@ -1,7 +1,7 @@ import { join } from '../../util/path.js'; import { timerify } from '../../util/Performance.js'; import { hasDependency, load } from '../../util/plugin.js'; -import { toEntryPattern } from '../../util/protocols.js'; +import { toEntryPattern, toProductionEntryPattern } from '../../util/protocols.js'; import { DummyEleventyConfig, defaultEleventyConfig } from './helpers.js'; import type { EleventyConfig } from './types.js'; import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js'; @@ -26,7 +26,7 @@ const findEleventyDependencies: GenericPluginCallback = async (configFilePath, o let localConfig = (await load(configFilePath)) as | Partial | ((arg: DummyEleventyConfig) => Promise>); - if (!localConfig) return []; + if (!localConfig) return PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern); if (typeof localConfig === 'function') localConfig = await localConfig(new DummyEleventyConfig()); const inputDir = localConfig?.dir?.input || defaultEleventyConfig.dir.input; From 96747fac13e7179ca818944983686a1637da8ef0 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:22:32 -0500 Subject: [PATCH 17/20] Consider config.entry in early return --- packages/knip/src/plugins/eleventy/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/knip/src/plugins/eleventy/index.ts b/packages/knip/src/plugins/eleventy/index.ts index d349e323a..91c12a9d3 100644 --- a/packages/knip/src/plugins/eleventy/index.ts +++ b/packages/knip/src/plugins/eleventy/index.ts @@ -26,7 +26,10 @@ const findEleventyDependencies: GenericPluginCallback = async (configFilePath, o let localConfig = (await load(configFilePath)) as | Partial | ((arg: DummyEleventyConfig) => Promise>); - if (!localConfig) return PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern); + if (!localConfig) + return config.entry + ? config.entry.map(toProductionEntryPattern) + : PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern); if (typeof localConfig === 'function') localConfig = await localConfig(new DummyEleventyConfig()); const inputDir = localConfig?.dir?.input || defaultEleventyConfig.dir.input; From 837035379f7cac407416d58a463529680a73e4f7 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:23:24 -0500 Subject: [PATCH 18/20] Remove extra nullish operator thingy --- packages/knip/src/plugins/eleventy/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/knip/src/plugins/eleventy/index.ts b/packages/knip/src/plugins/eleventy/index.ts index 91c12a9d3..4ccb311aa 100644 --- a/packages/knip/src/plugins/eleventy/index.ts +++ b/packages/knip/src/plugins/eleventy/index.ts @@ -41,8 +41,7 @@ const findEleventyDependencies: GenericPluginCallback = async (configFilePath, o join(inputDir, dataDir, '**/*.js'), join(inputDir, `**/*.{${typeof templateFormats === 'string' ? templateFormats : templateFormats.join(',')}}`), join(inputDir, '**/*.11tydata.js'), - ] ?? - ENTRY_FILE_PATTERNS + ] ).map(toEntryPattern); }; From e3cdeb1cbcc76472b543a2db95415d6fa4d06888 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:26:02 -0500 Subject: [PATCH 19/20] Use CONFIG_FILE_PATTERNS instead --- packages/knip/src/plugins/eleventy/index.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/knip/src/plugins/eleventy/index.ts b/packages/knip/src/plugins/eleventy/index.ts index 4ccb311aa..9957fd42f 100644 --- a/packages/knip/src/plugins/eleventy/index.ts +++ b/packages/knip/src/plugins/eleventy/index.ts @@ -14,12 +14,16 @@ const ENABLERS = ['@11ty/eleventy']; const isEnabled: IsPluginEnabledCallback = ({ dependencies }) => hasDependency(dependencies, ENABLERS); -const ENTRY_FILE_PATTERNS = ['.eleventy.js', 'eleventy.config.{js,cjs}']; +const CONFIG_FILE_PATTERNS: string[] = ['.eleventy.js', 'eleventy.config.{js,cjs}']; -const PRODUCTION_ENTRY_FILE_PATTERNS = ['**/*.11tydata.js', '_data/**/*.{js,cjs,mjs}'] +const ENTRY_FILE_PATTERNS: string[] = []; + +const PRODUCTION_ENTRY_FILE_PATTERNS: string[] = ['**/*.11tydata.js', '_data/**/*.{js,cjs,mjs}'] .map(pattern => [`src/${pattern}`, `content/${pattern}`]) .flat(); +const PROJECT_FILE_PATTERNS: string[] = []; + const findEleventyDependencies: GenericPluginCallback = async (configFilePath, options) => { const { config } = options; @@ -51,7 +55,9 @@ export default { NAME, ENABLERS, isEnabled, + CONFIG_FILE_PATTERNS, ENTRY_FILE_PATTERNS, PRODUCTION_ENTRY_FILE_PATTERNS, + PROJECT_FILE_PATTERNS, findDependencies, }; From 67ef6ffc0ee0e592abdf2303c65aecd2a93312de Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Thu, 18 Jan 2024 06:44:21 -0500 Subject: [PATCH 20/20] fix: revert change to PRODUCTION_ENTRY_FILE_PATTERNS --- packages/knip/src/plugins/eleventy/index.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/knip/src/plugins/eleventy/index.ts b/packages/knip/src/plugins/eleventy/index.ts index 9957fd42f..09c16acba 100644 --- a/packages/knip/src/plugins/eleventy/index.ts +++ b/packages/knip/src/plugins/eleventy/index.ts @@ -18,9 +18,7 @@ const CONFIG_FILE_PATTERNS: string[] = ['.eleventy.js', 'eleventy.config.{js,cjs const ENTRY_FILE_PATTERNS: string[] = []; -const PRODUCTION_ENTRY_FILE_PATTERNS: string[] = ['**/*.11tydata.js', '_data/**/*.{js,cjs,mjs}'] - .map(pattern => [`src/${pattern}`, `content/${pattern}`]) - .flat(); +const PRODUCTION_ENTRY_FILE_PATTERNS: string[] = ['posts/**/*.11tydata.js', '_data/**/*.{js,cjs,mjs}']; const PROJECT_FILE_PATTERNS: string[] = [];