Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Eleventy data directory as entry pattern #454

Merged
merged 20 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 150 additions & 0 deletions packages/knip/src/plugins/eleventy/helpers.ts
Original file line number Diff line number Diff line change
@@ -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',
},
};
13 changes: 12 additions & 1 deletion packages/knip/src/plugins/eleventy/index.ts
Original file line number Diff line number Diff line change
@@ -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';

Check failure on line 5 in packages/knip/src/plugins/eleventy/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest (Node v18)

`./helpers.js` import should occur before type import of `../../types/plugins.js`

Check failure on line 5 in packages/knip/src/plugins/eleventy/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest (Node v20)

`./helpers.js` import should occur before type import of `../../types/plugins.js`
import type { EleventyConfig } from './types.js';

Check failure on line 6 in packages/knip/src/plugins/eleventy/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest (Node v18)

`./types.js` type import should occur before type import of `../../types/plugins.js`

Check failure on line 6 in packages/knip/src/plugins/eleventy/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest (Node v18)

'EleventyConfig' is defined but never used

Check failure on line 6 in packages/knip/src/plugins/eleventy/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest (Node v20)

`./types.js` type import should occur before type import of `../../types/plugins.js`

Check failure on line 6 in packages/knip/src/plugins/eleventy/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest (Node v20)

'EleventyConfig' is defined but never used
import { join } from '../../util/path.js';

Check failure on line 7 in packages/knip/src/plugins/eleventy/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest (Node v18)

`../../util/path.js` import should occur before import of `../../util/Performance.js`

Check failure on line 7 in packages/knip/src/plugins/eleventy/index.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest (Node v20)

`../../util/path.js` import should occur before import of `../../util/Performance.js`

// https://www.11ty.dev/docs/

Expand All @@ -18,6 +21,14 @@
const findEleventyDependencies: GenericPluginCallback = async (configFilePath, options) => {
const { config } = options;

let localConfig = await load(configFilePath);
if (typeof localConfig === 'function') localConfig = await localConfig(new DummyEleventyConfig());

const result = { ...localConfig, ...defaultEleventyConfig };

// Data directory pattern:
toEntryPattern(`${join(result.dir.input, result.dir.data)}/**/*.js`);
uncenter marked this conversation as resolved.
Show resolved Hide resolved

return config.entry
? config.entry.map(toProductionEntryPattern)
: [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
Expand Down
9 changes: 9 additions & 0 deletions packages/knip/src/plugins/eleventy/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type EleventyConfig = {
dir: {
input: string;
output: string;
includes: string;
layouts: string;
data: string;
};
};
Loading