html-validate 8.26.0 → 8.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@ require('ajv');
7
7
  require('./elements.js');
8
8
  require('@sidvind/better-ajv-errors');
9
9
  require('./utils/natural-join.js');
10
- require('fs');
10
+ require('node:fs');
11
11
  require('kleur');
12
12
  require('@html-validate/stylish');
13
13
  require('semver');
@@ -163,17 +163,14 @@ class FileSystemConfigLoader extends core.ConfigLoader {
163
163
  getConfigFor(filename, configOverride) {
164
164
  const override = this.loadFromObject(configOverride ?? {});
165
165
  if (override.isRootFound()) {
166
- override.init();
167
166
  return override.resolve();
168
167
  }
169
168
  if (this.globalConfig.isRootFound()) {
170
169
  const merged2 = this.globalConfig.merge(this.resolvers, override);
171
- merged2.init();
172
170
  return merged2.resolve();
173
171
  }
174
172
  const config = this.fromFilename(filename);
175
173
  const merged = config ? config.merge(this.resolvers, override) : this.globalConfig.merge(this.resolvers, override);
176
- merged.init();
177
174
  return merged.resolve();
178
175
  }
179
176
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"core-nodejs.js","sources":["../../src/utils/require-uncached.ts","../../src/config/resolver/nodejs/determine-root-dir.ts","../../src/config/resolver/nodejs/expand-relative-path.ts","../../src/config/resolver/nodejs/cjs-resolver.ts","../../src/config/loaders/file-system.ts","../../src/utils/compatibility-check.nodejs.ts"],"sourcesContent":["/**\n * Similar to `require(..)` but removes the cached copy first.\n */\nexport function requireUncached(require: NodeJS.Require, moduleId: string): unknown {\n\tconst filename = require.resolve(moduleId);\n\n\t/* remove references from the parent module to prevent memory leak */\n\tconst m = require.cache[filename];\n\tif (m?.parent) {\n\t\tconst { parent } = m;\n\t\tfor (let i = parent.children.length - 1; i >= 0; i--) {\n\t\t\tif (parent.children[i].id === filename) {\n\t\t\t\tparent.children.splice(i, 1);\n\t\t\t}\n\t\t}\n\t}\n\n\t/* remove old module from cache */\n\t/* eslint-disable-next-line @typescript-eslint/no-dynamic-delete -- needed to perform its function */\n\tdelete require.cache[filename];\n\n\t/* eslint-disable-next-line import/no-dynamic-require, security/detect-non-literal-require -- as expected but should be moved to upcoming resolver class */\n\treturn require(filename);\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\n\nlet cachedRootDir: string | null = null;\n\ninterface FSLike {\n\texistsSync(path: string): boolean;\n}\n\n/**\n * @internal\n */\nexport function determineRootDirImpl(intial: string, fs: FSLike): string {\n\t/* try to locate package.json */\n\tlet current = intial;\n\n\t// eslint-disable-next-line no-constant-condition, @typescript-eslint/no-unnecessary-condition -- break outs when filesystem is traversed\n\twhile (true) {\n\t\tconst search = path.join(current, \"package.json\");\n\t\tif (fs.existsSync(search)) {\n\t\t\treturn current;\n\t\t}\n\n\t\t/* get the parent directory */\n\t\tconst child = current;\n\t\tcurrent = path.dirname(current);\n\n\t\t/* stop if this is the root directory */\n\t\tif (current === child) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\t/* default to working directory if no package.json is found */\n\treturn intial;\n}\n\n/**\n * Try to determine root directory based on the location of the closest\n * `package.json`. Fallbacks on `process.cwd()` if no package.json was found.\n *\n * @internal\n */\n/* istanbul ignore next: cached version of determineRootDirImpl, no need to test */\nexport function determineRootDir(): string {\n\tif (cachedRootDir === null) {\n\t\tcachedRootDir = determineRootDirImpl(process.cwd(), fs);\n\t}\n\treturn cachedRootDir;\n}\n","import path from \"node:path\";\n\n/**\n * @internal\n */\nexport function expandRelativePath<T>(value: string | T, { cwd }: { cwd: string }): string | T {\n\tif (typeof value === \"string\" && value.startsWith(\".\")) {\n\t\treturn path.normalize(path.join(cwd, value));\n\t} else {\n\t\treturn value;\n\t}\n}\n","import path from \"node:path\";\nimport { type MetaDataTable } from \"../../../meta\";\nimport { type Plugin } from \"../../../plugin\";\nimport { legacyRequire } from \"../../../resolve\";\nimport { type Transformer } from \"../../../transform\";\nimport { requireUncached } from \"../../../utils\";\nimport { type ConfigData } from \"../../config-data\";\nimport { ConfigError } from \"../../error\";\nimport { type Resolver, type ResolverOptions } from \"../resolver\";\nimport { determineRootDir } from \"./determine-root-dir\";\nimport { expandRelativePath } from \"./expand-relative-path\";\n\n/**\n * @internal\n */\nexport interface RequireError extends Error {\n\tcode: string;\n}\n\nfunction isRequireError(error: unknown): error is RequireError {\n\treturn Boolean(error && typeof error === \"object\" && \"code\" in error);\n}\n\nfunction isTransformer(value: Transformer | Plugin): value is Transformer {\n\treturn typeof value === \"function\";\n}\n\n/**\n * CommonJS resolver.\n *\n * @public\n * @since 8.8.0\n */\nexport type CommonJSResolver = Required<Resolver>;\n\n/**\n * CommonJS resolver.\n *\n * @public\n * @deprecated Deprecated alias for [[CommonJSResolver]].\n * @since 8.0.0\n */\nexport type NodeJSResolver = Required<Resolver>;\n\n/**\n * Create a new resolver for NodeJS packages using `require(..)`.\n *\n * If the module name contains `<rootDir>` (e.g. `<rootDir/foo`) it will be\n * expanded relative to the root directory either explicitly set by the\n * `rootDir` parameter or determined automatically by the closest `package.json`\n * file (starting at the current working directory).\n *\n * @public\n * @since 8.8.0\n */\nexport function cjsResolver(options: { rootDir?: string } = {}): CommonJSResolver {\n\tconst rootDir = options.rootDir ?? determineRootDir();\n\n\tfunction internalRequire<T = unknown>(id: string, { cache }: ResolverOptions): T | null {\n\t\tconst moduleName = id.replace(\"<rootDir>\", rootDir);\n\t\ttry {\n\t\t\t/* istanbul ignore else: the tests only runs the cached versions to get\n\t\t\t * unmodified access to `require`, the implementation of `requireUncached`\n\t\t\t * is assumed to be tested elsewhere */\n\t\t\tif (cache) {\n\t\t\t\treturn legacyRequire(moduleName) as T;\n\t\t\t} else {\n\t\t\t\treturn requireUncached(legacyRequire, moduleName) as T;\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\tif (isRequireError(err) && err.code === \"MODULE_NOT_FOUND\") {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\treturn {\n\t\tname: \"nodejs-resolver\",\n\n\t\tresolveElements(id: string, options: ResolverOptions): MetaDataTable | null {\n\t\t\treturn internalRequire(id, options);\n\t\t},\n\n\t\tresolveConfig(id: string, options: ResolverOptions): ConfigData | null {\n\t\t\tconst configData = internalRequire<ConfigData>(id, options);\n\t\t\tif (!configData) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\t/* expand any relative paths */\n\t\t\tconst cwd = path.dirname(id);\n\t\t\tconst expand = <T>(value: string | T): string | T => expandRelativePath(value, { cwd });\n\n\t\t\tif (Array.isArray(configData.elements)) {\n\t\t\t\tconfigData.elements = configData.elements.map(expand);\n\t\t\t}\n\n\t\t\tif (Array.isArray(configData.extends)) {\n\t\t\t\tconfigData.extends = configData.extends.map(expand);\n\t\t\t}\n\n\t\t\tif (Array.isArray(configData.plugins)) {\n\t\t\t\tconfigData.plugins = configData.plugins.map(expand);\n\t\t\t}\n\n\t\t\treturn configData;\n\t\t},\n\n\t\tresolvePlugin(id: string, options: ResolverOptions): Plugin | null {\n\t\t\treturn internalRequire<Plugin>(id, options);\n\t\t},\n\n\t\tresolveTransformer(id: string, options: ResolverOptions): Transformer | null {\n\t\t\tconst mod = internalRequire<Transformer | Plugin>(id, options);\n\t\t\tif (!mod) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tif (isTransformer(mod)) {\n\t\t\t\treturn mod;\n\t\t\t}\n\n\t\t\t/* this is not a proper transformer, is it a plugin exposing a transformer? */\n\t\t\tif (mod.transformer) {\n\t\t\t\tthrow new ConfigError(\n\t\t\t\t\t`Module \"${id}\" is not a valid transformer. This looks like a plugin, did you forget to load the plugin first?`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthrow new ConfigError(`Module \"${id}\" is not a valid transformer.`);\n\t\t},\n\t};\n}\n\n/**\n * Create a new resolver for NodeJS packages using `require(..)`.\n *\n * If the module name contains `<rootDir>` (e.g. `<rootDir/foo`) it will be\n * expanded relative to the root directory either explicitly set by the\n * `rootDir` parameter or determined automatically by the closest `package.json`\n * file (starting at the current working directory).\n *\n * @public\n * @deprecated Deprecated alias for [[commonjsResolver]].\n * @since 8.0.0\n */\n/* istanbul ignore next -- deprecated alias */\nexport function nodejsResolver(options: { rootDir?: string } = {}): NodeJSResolver {\n\treturn cjsResolver(options);\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { Config } from \"../config\";\nimport { type ConfigData } from \"../config-data\";\nimport { ConfigLoader } from \"../config-loader\";\nimport { type ResolvedConfig } from \"../resolved-config\";\nimport { type Resolver } from \"../resolver\";\nimport { type FSLike, cjsResolver } from \"../resolver/nodejs\";\n\n/**\n * Options for [[FileSystemConfigLoader]].\n *\n * @public\n */\nexport interface FileSystemConfigLoaderOptions {\n\t/** An implementation of `fs` as needed by [[FileSystemConfigLoader]] */\n\tfs: FSLike;\n}\n\n/**\n * @internal\n */\nfunction findConfigurationFiles(fs: FSLike, directory: string): string[] {\n\treturn [\"json\", \"cjs\", \"js\"]\n\t\t.map((extension) => path.join(directory, `.htmlvalidate.${extension}`))\n\t\t.filter((filePath) => fs.existsSync(filePath));\n}\n\nconst defaultResolvers: Resolver[] = [cjsResolver()];\n\ntype ConstructorParametersDefault = [ConfigData?, Partial<FileSystemConfigLoaderOptions>?];\ntype ConstructorParametersResolver = [\n\tResolver[],\n\tConfigData?,\n\tPartial<FileSystemConfigLoaderOptions>?,\n];\ntype ConstructorParameters = ConstructorParametersDefault | ConstructorParametersResolver;\n\nfunction hasResolver(value: ConstructorParameters): value is ConstructorParametersResolver {\n\treturn Array.isArray(value[0]);\n}\n\n/**\n * Loads configuration by traversing filesystem.\n *\n * Configuration is read from three sources and in the following order:\n *\n * 1. Global configuration passed to constructor.\n * 2. Configuration files found when traversing the directory structure.\n * 3. Override passed to this function.\n *\n * The following configuration filenames are searched:\n *\n * - `.htmlvalidate.json`\n * - `.htmlvalidate.js`\n * - `.htmlvalidate.cjs`\n *\n * Global configuration is used when no configuration file is found. The\n * result is always merged with override if present.\n *\n * The `root` property set to `true` affects the configuration as following:\n *\n * 1. If set in override the override is returned as-is.\n * 2. If set in the global config the override is merged into global and\n * returned. No configuration files are searched.\n * 3. Setting `root` in configuration file only stops directory traversal.\n *\n * @public\n */\nexport class FileSystemConfigLoader extends ConfigLoader {\n\tprotected cache: Map<string, Config | null>;\n\tprivate fs: FSLike;\n\n\t/**\n\t * Create a filesystem configuration loader with default resolvers.\n\t *\n\t * @param fs - `fs` implementation,\n\t * @param config - Global configuration.\n\t * @param configFactory - Optional configuration factory.\n\t */\n\tpublic constructor(config?: ConfigData, options?: Partial<FileSystemConfigLoaderOptions>);\n\n\t/**\n\t * Create a filesystem configuration loader with custom resolvers.\n\t *\n\t * @param fs - `fs` implementation,\n\t * @param resolvers - Resolvers to use.\n\t * @param config - Global configuration.\n\t * @param configFactory - Optional configuration factory.\n\t */\n\tpublic constructor(\n\t\tresolvers: Resolver[],\n\t\tconfig?: ConfigData,\n\t\toptions?: Partial<FileSystemConfigLoaderOptions>,\n\t);\n\n\tpublic constructor(...args: ConstructorParameters) {\n\t\tif (hasResolver(args)) {\n\t\t\t/* istanbul ignore next */\n\t\t\tconst [resolvers, config, options = {}] = args;\n\t\t\tsuper(resolvers, config);\n\t\t\tthis.fs = /* istanbul ignore next */ options.fs ?? fs;\n\t\t} else {\n\t\t\t/* istanbul ignore next */\n\t\t\tconst [config, options = {}] = args;\n\t\t\tsuper(defaultResolvers, config);\n\t\t\tthis.fs = /* istanbul ignore next */ options.fs ?? fs;\n\t\t}\n\t\tthis.cache = new Map();\n\t}\n\n\t/**\n\t * Get configuration for given filename.\n\t *\n\t * @param filename - Filename to get configuration for.\n\t * @param configOverride - Configuration to merge final result with.\n\t */\n\tpublic override getConfigFor(filename: string, configOverride?: ConfigData): ResolvedConfig {\n\t\t/* special case when the overridden configuration is marked as root, should\n\t\t * not try to load any more configuration files */\n\t\tconst override = this.loadFromObject(configOverride ?? {});\n\t\tif (override.isRootFound()) {\n\t\t\toverride.init();\n\t\t\treturn override.resolve();\n\t\t}\n\n\t\t/* special case when the global configuration is marked as root, should not\n\t\t * try to load and more configuration files */\n\t\tif (this.globalConfig.isRootFound()) {\n\t\t\tconst merged = this.globalConfig.merge(this.resolvers, override);\n\t\t\tmerged.init();\n\t\t\treturn merged.resolve();\n\t\t}\n\n\t\tconst config = this.fromFilename(filename);\n\t\tconst merged = config\n\t\t\t? config.merge(this.resolvers, override)\n\t\t\t: this.globalConfig.merge(this.resolvers, override);\n\t\tmerged.init();\n\t\treturn merged.resolve();\n\t}\n\n\t/**\n\t * Flush configuration cache.\n\t *\n\t * @param filename - If given only the cache for that file is flushed.\n\t */\n\tpublic override flushCache(filename?: string): void {\n\t\tif (filename) {\n\t\t\tthis.cache.delete(filename);\n\t\t} else {\n\t\t\tthis.cache.clear();\n\t\t}\n\t}\n\n\t/**\n\t * Load raw configuration from directory traversal.\n\t *\n\t * This configuration is not merged with global configuration and may return\n\t * `null` if no configuration files are found.\n\t */\n\tpublic fromFilename(filename: string): Config | null {\n\t\tif (filename === \"inline\") {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst cache = this.cache.get(filename);\n\t\tif (cache) {\n\t\t\treturn cache;\n\t\t}\n\n\t\tlet found = false;\n\t\tlet current = path.resolve(path.dirname(filename));\n\t\tlet config = this.empty();\n\n\t\t// eslint-disable-next-line no-constant-condition, @typescript-eslint/no-unnecessary-condition -- it will break out when filesystem is traversed\n\t\twhile (true) {\n\t\t\t/* search configuration files in current directory */\n\t\t\tfor (const configFile of findConfigurationFiles(this.fs, current)) {\n\t\t\t\tconst local = this.loadFromFile(configFile);\n\t\t\t\tfound = true;\n\t\t\t\tconfig = local.merge(this.resolvers, config);\n\t\t\t}\n\n\t\t\t/* stop if a configuration with \"root\" is set to true */\n\t\t\tif (config.isRootFound()) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t/* get the parent directory */\n\t\t\tconst child = current;\n\t\t\tcurrent = path.dirname(current);\n\n\t\t\t/* stop if this is the root directory */\n\t\t\tif (current === child) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\t/* no config was found by loader, return null and let caller decide what to do */\n\t\tif (!found) {\n\t\t\tthis.cache.set(filename, null);\n\t\t\treturn null;\n\t\t}\n\n\t\tthis.cache.set(filename, config);\n\t\treturn config;\n\t}\n\n\t/**\n\t * @internal For testing only\n\t */\n\tpublic _getInternalCache(): Map<string, Config | null> {\n\t\treturn this.cache;\n\t}\n\n\tprotected defaultConfig(): Config {\n\t\treturn Config.defaultConfig();\n\t}\n}\n","import kleur from \"kleur\";\nimport { version } from \"../generated/package\";\nimport { type CompatibilityOptions, compatibilityCheckImpl } from \"./compatibility-check\";\n\nconst defaults: CompatibilityOptions = {\n\tsilent: false,\n\tversion,\n\tlogger(text: string): void {\n\t\t/* eslint-disable-next-line no-console -- expected to log */\n\t\tconsole.error(kleur.red(text));\n\t},\n};\n\n/**\n * Tests if plugin is compatible with html-validate library. Unless the `silent`\n * option is used a warning is displayed on the console.\n *\n * @public\n * @since v5.0.0\n * @param name - Name of plugin\n * @param declared - What library versions the plugin support (e.g. declared peerDependencies)\n * @returns - `true` if version is compatible\n */\nexport function compatibilityCheck(\n\tname: string,\n\tdeclared: string,\n\toptions?: Partial<CompatibilityOptions>,\n): boolean {\n\treturn compatibilityCheckImpl(name, declared, {\n\t\t...defaults,\n\t\t...options,\n\t});\n}\n"],"names":["fs","path","options","ConfigError","ConfigLoader","merged","Config","version","kleur","compatibilityCheckImpl"],"mappings":";;;;;;;;;;;;;AAGgB,SAAA,eAAA,CAAgB,SAAyB,QAA2B,EAAA;AACnF,EAAM,MAAA,QAAA,GAAW,OAAQ,CAAA,OAAA,CAAQ,QAAQ,CAAA;AAGzC,EAAM,MAAA,CAAA,GAAI,OAAQ,CAAA,KAAA,CAAM,QAAQ,CAAA;AAChC,EAAA,IAAI,uBAAG,MAAQ,EAAA;AACd,IAAM,MAAA,EAAE,QAAW,GAAA,CAAA;AACnB,IAAA,KAAA,IAAS,IAAI,MAAO,CAAA,QAAA,CAAS,SAAS,CAAG,EAAA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AA,OAAOK,YAAO,aAAc,EAAA;AAAA;AAE9B;;ACvNA,MAAM,QAAiC,GAAA;AAAA,EACtC,MAAQ,EAAA,KAAA;AAAA,WACRC,YAAA;AAAA,EACA,OAAO,IAAoB,EAAA;AAE1B,IAAA,OAAA,CAAQ,KAAM,CAAAC,sBAAA,CAAM,GAAI,CAAA,IAAI,CAAC,CAAA;AAAA;AAE/B,CAAA;AAYgB,SAAA,kBAAA,CACf,IACA,EAAA,QAAA,EACA,OACU,EAAA;AACV,EAAO,OAAAC,2BAAA,CAAuB,MAAM,QAAU,EAAA;AAAA,IAC7C,GAAG,QAAA;AAAA,IACH,GAAG;AAAA,GACH,CAAA;AACF;;;;;;;;"}
1
+ {"version":3,"file":"core-nodejs.js","sources":["../../src/utils/require-uncached.ts","../../src/config/resolver/nodejs/determine-root-dir.ts","../../src/config/resolver/nodejs/expand-relative-path.ts","../../src/config/resolver/nodejs/cjs-resolver.ts","../../src/config/loaders/file-system.ts","../../src/utils/compatibility-check.nodejs.ts"],"sourcesContent":["/**\n * Similar to `require(..)` but removes the cached copy first.\n */\nexport function requireUncached(require: NodeJS.Require, moduleId: string): unknown {\n\tconst filename = require.resolve(moduleId);\n\n\t/* remove references from the parent module to prevent memory leak */\n\tconst m = require.cache[filename];\n\tif (m?.parent) {\n\t\tconst { parent } = m;\n\t\tfor (let i = parent.children.length - 1; i >= 0; i--) {\n\t\t\tif (parent.children[i].id === filename) {\n\t\t\t\tparent.children.splice(i, 1);\n\t\t\t}\n\t\t}\n\t}\n\n\t/* remove old module from cache */\n\t/* eslint-disable-next-line @typescript-eslint/no-dynamic-delete -- needed to perform its function */\n\tdelete require.cache[filename];\n\n\t/* eslint-disable-next-line import/no-dynamic-require, security/detect-non-literal-require -- as expected but should be moved to upcoming resolver class */\n\treturn require(filename);\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\n\nlet cachedRootDir: string | null = null;\n\ninterface FSLike {\n\texistsSync(path: string): boolean;\n}\n\n/**\n * @internal\n */\nexport function determineRootDirImpl(intial: string, fs: FSLike): string {\n\t/* try to locate package.json */\n\tlet current = intial;\n\n\t// eslint-disable-next-line no-constant-condition, @typescript-eslint/no-unnecessary-condition -- break outs when filesystem is traversed\n\twhile (true) {\n\t\tconst search = path.join(current, \"package.json\");\n\t\tif (fs.existsSync(search)) {\n\t\t\treturn current;\n\t\t}\n\n\t\t/* get the parent directory */\n\t\tconst child = current;\n\t\tcurrent = path.dirname(current);\n\n\t\t/* stop if this is the root directory */\n\t\tif (current === child) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\t/* default to working directory if no package.json is found */\n\treturn intial;\n}\n\n/**\n * Try to determine root directory based on the location of the closest\n * `package.json`. Fallbacks on `process.cwd()` if no package.json was found.\n *\n * @internal\n */\n/* istanbul ignore next: cached version of determineRootDirImpl, no need to test */\nexport function determineRootDir(): string {\n\tif (cachedRootDir === null) {\n\t\tcachedRootDir = determineRootDirImpl(process.cwd(), fs);\n\t}\n\treturn cachedRootDir;\n}\n","import path from \"node:path\";\n\n/**\n * @internal\n */\nexport function expandRelativePath<T>(value: string | T, { cwd }: { cwd: string }): string | T {\n\tif (typeof value === \"string\" && value.startsWith(\".\")) {\n\t\treturn path.normalize(path.join(cwd, value));\n\t} else {\n\t\treturn value;\n\t}\n}\n","import path from \"node:path\";\nimport { type MetaDataTable } from \"../../../meta\";\nimport { type Plugin } from \"../../../plugin\";\nimport { legacyRequire } from \"../../../resolve\";\nimport { type Transformer } from \"../../../transform\";\nimport { requireUncached } from \"../../../utils\";\nimport { type ConfigData } from \"../../config-data\";\nimport { ConfigError } from \"../../error\";\nimport { type Resolver, type ResolverOptions } from \"../resolver\";\nimport { determineRootDir } from \"./determine-root-dir\";\nimport { expandRelativePath } from \"./expand-relative-path\";\n\n/**\n * @internal\n */\nexport interface RequireError extends Error {\n\tcode: string;\n}\n\nfunction isRequireError(error: unknown): error is RequireError {\n\treturn Boolean(error && typeof error === \"object\" && \"code\" in error);\n}\n\nfunction isTransformer(value: Transformer | Plugin): value is Transformer {\n\treturn typeof value === \"function\";\n}\n\n/**\n * CommonJS resolver.\n *\n * @public\n * @since 8.8.0\n */\nexport type CommonJSResolver = Required<Resolver>;\n\n/**\n * CommonJS resolver.\n *\n * @public\n * @deprecated Deprecated alias for [[CommonJSResolver]].\n * @since 8.0.0\n */\nexport type NodeJSResolver = Required<Resolver>;\n\n/**\n * Create a new resolver for NodeJS packages using `require(..)`.\n *\n * If the module name contains `<rootDir>` (e.g. `<rootDir/foo`) it will be\n * expanded relative to the root directory either explicitly set by the\n * `rootDir` parameter or determined automatically by the closest `package.json`\n * file (starting at the current working directory).\n *\n * @public\n * @since 8.8.0\n */\nexport function cjsResolver(options: { rootDir?: string } = {}): CommonJSResolver {\n\tconst rootDir = options.rootDir ?? determineRootDir();\n\n\tfunction internalRequire<T = unknown>(id: string, { cache }: ResolverOptions): T | null {\n\t\tconst moduleName = id.replace(\"<rootDir>\", rootDir);\n\t\ttry {\n\t\t\t/* istanbul ignore else: the tests only runs the cached versions to get\n\t\t\t * unmodified access to `require`, the implementation of `requireUncached`\n\t\t\t * is assumed to be tested elsewhere */\n\t\t\tif (cache) {\n\t\t\t\treturn legacyRequire(moduleName) as T;\n\t\t\t} else {\n\t\t\t\treturn requireUncached(legacyRequire, moduleName) as T;\n\t\t\t}\n\t\t} catch (err: unknown) {\n\t\t\tif (isRequireError(err) && err.code === \"MODULE_NOT_FOUND\") {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\treturn {\n\t\tname: \"nodejs-resolver\",\n\n\t\tresolveElements(id: string, options: ResolverOptions): MetaDataTable | null {\n\t\t\treturn internalRequire(id, options);\n\t\t},\n\n\t\tresolveConfig(id: string, options: ResolverOptions): ConfigData | null {\n\t\t\tconst configData = internalRequire<ConfigData>(id, options);\n\t\t\tif (!configData) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\t/* expand any relative paths */\n\t\t\tconst cwd = path.dirname(id);\n\t\t\tconst expand = <T>(value: string | T): string | T => expandRelativePath(value, { cwd });\n\n\t\t\tif (Array.isArray(configData.elements)) {\n\t\t\t\tconfigData.elements = configData.elements.map(expand);\n\t\t\t}\n\n\t\t\tif (Array.isArray(configData.extends)) {\n\t\t\t\tconfigData.extends = configData.extends.map(expand);\n\t\t\t}\n\n\t\t\tif (Array.isArray(configData.plugins)) {\n\t\t\t\tconfigData.plugins = configData.plugins.map(expand);\n\t\t\t}\n\n\t\t\treturn configData;\n\t\t},\n\n\t\tresolvePlugin(id: string, options: ResolverOptions): Plugin | null {\n\t\t\treturn internalRequire<Plugin>(id, options);\n\t\t},\n\n\t\tresolveTransformer(id: string, options: ResolverOptions): Transformer | null {\n\t\t\tconst mod = internalRequire<Transformer | Plugin>(id, options);\n\t\t\tif (!mod) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tif (isTransformer(mod)) {\n\t\t\t\treturn mod;\n\t\t\t}\n\n\t\t\t/* this is not a proper transformer, is it a plugin exposing a transformer? */\n\t\t\tif (mod.transformer) {\n\t\t\t\tthrow new ConfigError(\n\t\t\t\t\t`Module \"${id}\" is not a valid transformer. This looks like a plugin, did you forget to load the plugin first?`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthrow new ConfigError(`Module \"${id}\" is not a valid transformer.`);\n\t\t},\n\t};\n}\n\n/**\n * Create a new resolver for NodeJS packages using `require(..)`.\n *\n * If the module name contains `<rootDir>` (e.g. `<rootDir/foo`) it will be\n * expanded relative to the root directory either explicitly set by the\n * `rootDir` parameter or determined automatically by the closest `package.json`\n * file (starting at the current working directory).\n *\n * @public\n * @deprecated Deprecated alias for [[commonjsResolver]].\n * @since 8.0.0\n */\n/* istanbul ignore next -- deprecated alias */\nexport function nodejsResolver(options: { rootDir?: string } = {}): NodeJSResolver {\n\treturn cjsResolver(options);\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { Config } from \"../config\";\nimport { type ConfigData } from \"../config-data\";\nimport { ConfigLoader } from \"../config-loader\";\nimport { type ResolvedConfig } from \"../resolved-config\";\nimport { type Resolver } from \"../resolver\";\nimport { type FSLike, cjsResolver } from \"../resolver/nodejs\";\n\n/**\n * Options for [[FileSystemConfigLoader]].\n *\n * @public\n */\nexport interface FileSystemConfigLoaderOptions {\n\t/** An implementation of `fs` as needed by [[FileSystemConfigLoader]] */\n\tfs: FSLike;\n}\n\n/**\n * @internal\n */\nfunction findConfigurationFiles(fs: FSLike, directory: string): string[] {\n\treturn [\"json\", \"cjs\", \"js\"]\n\t\t.map((extension) => path.join(directory, `.htmlvalidate.${extension}`))\n\t\t.filter((filePath) => fs.existsSync(filePath));\n}\n\nconst defaultResolvers: Resolver[] = [cjsResolver()];\n\ntype ConstructorParametersDefault = [ConfigData?, Partial<FileSystemConfigLoaderOptions>?];\ntype ConstructorParametersResolver = [\n\tResolver[],\n\tConfigData?,\n\tPartial<FileSystemConfigLoaderOptions>?,\n];\ntype ConstructorParameters = ConstructorParametersDefault | ConstructorParametersResolver;\n\nfunction hasResolver(value: ConstructorParameters): value is ConstructorParametersResolver {\n\treturn Array.isArray(value[0]);\n}\n\n/**\n * Loads configuration by traversing filesystem.\n *\n * Configuration is read from three sources and in the following order:\n *\n * 1. Global configuration passed to constructor.\n * 2. Configuration files found when traversing the directory structure.\n * 3. Override passed to this function.\n *\n * The following configuration filenames are searched:\n *\n * - `.htmlvalidate.json`\n * - `.htmlvalidate.js`\n * - `.htmlvalidate.cjs`\n *\n * Global configuration is used when no configuration file is found. The\n * result is always merged with override if present.\n *\n * The `root` property set to `true` affects the configuration as following:\n *\n * 1. If set in override the override is returned as-is.\n * 2. If set in the global config the override is merged into global and\n * returned. No configuration files are searched.\n * 3. Setting `root` in configuration file only stops directory traversal.\n *\n * @public\n */\nexport class FileSystemConfigLoader extends ConfigLoader {\n\tprotected cache: Map<string, Config | null>;\n\tprivate fs: FSLike;\n\n\t/**\n\t * Create a filesystem configuration loader with default resolvers.\n\t *\n\t * @param fs - `fs` implementation,\n\t * @param config - Global configuration.\n\t * @param configFactory - Optional configuration factory.\n\t */\n\tpublic constructor(config?: ConfigData, options?: Partial<FileSystemConfigLoaderOptions>);\n\n\t/**\n\t * Create a filesystem configuration loader with custom resolvers.\n\t *\n\t * @param fs - `fs` implementation,\n\t * @param resolvers - Resolvers to use.\n\t * @param config - Global configuration.\n\t * @param configFactory - Optional configuration factory.\n\t */\n\tpublic constructor(\n\t\tresolvers: Resolver[],\n\t\tconfig?: ConfigData,\n\t\toptions?: Partial<FileSystemConfigLoaderOptions>,\n\t);\n\n\tpublic constructor(...args: ConstructorParameters) {\n\t\tif (hasResolver(args)) {\n\t\t\t/* istanbul ignore next */\n\t\t\tconst [resolvers, config, options = {}] = args;\n\t\t\tsuper(resolvers, config);\n\t\t\tthis.fs = /* istanbul ignore next */ options.fs ?? fs;\n\t\t} else {\n\t\t\t/* istanbul ignore next */\n\t\t\tconst [config, options = {}] = args;\n\t\t\tsuper(defaultResolvers, config);\n\t\t\tthis.fs = /* istanbul ignore next */ options.fs ?? fs;\n\t\t}\n\t\tthis.cache = new Map();\n\t}\n\n\t/**\n\t * Get configuration for given filename.\n\t *\n\t * @param filename - Filename to get configuration for.\n\t * @param configOverride - Configuration to merge final result with.\n\t */\n\tpublic override getConfigFor(filename: string, configOverride?: ConfigData): ResolvedConfig {\n\t\t/* special case when the overridden configuration is marked as root, should\n\t\t * not try to load any more configuration files */\n\t\tconst override = this.loadFromObject(configOverride ?? {});\n\t\tif (override.isRootFound()) {\n\t\t\treturn override.resolve();\n\t\t}\n\n\t\t/* special case when the global configuration is marked as root, should not\n\t\t * try to load and more configuration files */\n\t\tif (this.globalConfig.isRootFound()) {\n\t\t\tconst merged = this.globalConfig.merge(this.resolvers, override);\n\t\t\treturn merged.resolve();\n\t\t}\n\n\t\tconst config = this.fromFilename(filename);\n\t\tconst merged = config\n\t\t\t? config.merge(this.resolvers, override)\n\t\t\t: this.globalConfig.merge(this.resolvers, override);\n\t\treturn merged.resolve();\n\t}\n\n\t/**\n\t * Flush configuration cache.\n\t *\n\t * @param filename - If given only the cache for that file is flushed.\n\t */\n\tpublic override flushCache(filename?: string): void {\n\t\tif (filename) {\n\t\t\tthis.cache.delete(filename);\n\t\t} else {\n\t\t\tthis.cache.clear();\n\t\t}\n\t}\n\n\t/**\n\t * Load raw configuration from directory traversal.\n\t *\n\t * This configuration is not merged with global configuration and may return\n\t * `null` if no configuration files are found.\n\t */\n\tpublic fromFilename(filename: string): Config | null {\n\t\tif (filename === \"inline\") {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst cache = this.cache.get(filename);\n\t\tif (cache) {\n\t\t\treturn cache;\n\t\t}\n\n\t\tlet found = false;\n\t\tlet current = path.resolve(path.dirname(filename));\n\t\tlet config = this.empty();\n\n\t\t// eslint-disable-next-line no-constant-condition, @typescript-eslint/no-unnecessary-condition -- it will break out when filesystem is traversed\n\t\twhile (true) {\n\t\t\t/* search configuration files in current directory */\n\t\t\tfor (const configFile of findConfigurationFiles(this.fs, current)) {\n\t\t\t\tconst local = this.loadFromFile(configFile);\n\t\t\t\tfound = true;\n\t\t\t\tconfig = local.merge(this.resolvers, config);\n\t\t\t}\n\n\t\t\t/* stop if a configuration with \"root\" is set to true */\n\t\t\tif (config.isRootFound()) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t/* get the parent directory */\n\t\t\tconst child = current;\n\t\t\tcurrent = path.dirname(current);\n\n\t\t\t/* stop if this is the root directory */\n\t\t\tif (current === child) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\t/* no config was found by loader, return null and let caller decide what to do */\n\t\tif (!found) {\n\t\t\tthis.cache.set(filename, null);\n\t\t\treturn null;\n\t\t}\n\n\t\tthis.cache.set(filename, config);\n\t\treturn config;\n\t}\n\n\t/**\n\t * @internal For testing only\n\t */\n\tpublic _getInternalCache(): Map<string, Config | null> {\n\t\treturn this.cache;\n\t}\n\n\tprotected defaultConfig(): Config {\n\t\treturn Config.defaultConfig();\n\t}\n}\n","import kleur from \"kleur\";\nimport { version } from \"../generated/package\";\nimport { type CompatibilityOptions, compatibilityCheckImpl } from \"./compatibility-check\";\n\nconst defaults: CompatibilityOptions = {\n\tsilent: false,\n\tversion,\n\tlogger(text: string): void {\n\t\t/* eslint-disable-next-line no-console -- expected to log */\n\t\tconsole.error(kleur.red(text));\n\t},\n};\n\n/**\n * Tests if plugin is compatible with html-validate library. Unless the `silent`\n * option is used a warning is displayed on the console.\n *\n * @public\n * @since v5.0.0\n * @param name - Name of plugin\n * @param declared - What library versions the plugin support (e.g. declared peerDependencies)\n * @returns - `true` if version is compatible\n */\nexport function compatibilityCheck(\n\tname: string,\n\tdeclared: string,\n\toptions?: Partial<CompatibilityOptions>,\n): boolean {\n\treturn compatibilityCheckImpl(name, declared, {\n\t\t...defaults,\n\t\t...options,\n\t});\n}\n"],"names":["fs","path","options","ConfigError","ConfigLoader","merged","Config","version","kleur","compatibilityCheckImpl"],"mappings":";;;;;;;;;;;;;AAGgB,SAAA,eAAA,CAAgB,SAAyB,QAA2B,EAAA;AACnF,EAAM,MAAA,QAAA,GAAW,OAAQ,CAAA,OAAA,CAAQ,QAAQ,CAAA;AAGzC,EAAM,MAAA,CAAA,GAAI,OAAQ,CAAA,KAAA,CAAM,QAAQ,CAAA;AAChC,EAAA,IAAI,uBAAG,MAAQ,EAAA;AACd,IAAM,MAAA,EAAE,QAAW,GAAA,CAAA;AACnB,IAAA,KAAA,IAAS,IAAI,MAAO,CAAA,QAAA,CAAS,SAAS,CAAG,EAAA,CAAA,IAAK,GAAG,CAAK,EAAA,EAAA;AACrD,MAAA,IAAI,MAAO,CAAA,QAAA,CAAS,CAAC,CAAA,CAAE,OAAO,QAAU,EAAA;AACvC,QAAO,MAAA,CAAA,QAAA,CAAS,MAAO,CAAA,CAAA,EAAG,CAAC,CAAA;AAAA;AAC5B;AACD;AAKD,EAAO,OAAA,OAAA,CAAQ,MAAM,QAAQ,CAAA;AAG7B,EAAA,OAAO,QAAQ,QAAQ,CAAA;A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G;AAAA,GACH,CAAA;AACF;;;;;;;;"}
package/dist/cjs/core.js CHANGED
@@ -4,7 +4,7 @@ var Ajv = require('ajv');
4
4
  var elements = require('./elements.js');
5
5
  var betterAjvErrors = require('@sidvind/better-ajv-errors');
6
6
  var utils_naturalJoin = require('./utils/natural-join.js');
7
- var fs = require('fs');
7
+ var fs = require('node:fs');
8
8
  var kleur = require('kleur');
9
9
  var stylish$1 = require('@html-validate/stylish');
10
10
  var semver = require('semver');
@@ -10572,10 +10572,6 @@ var configurationSchema = {
10572
10572
  properties: properties
10573
10573
  };
10574
10574
 
10575
- const TRANSFORMER_API = {
10576
- VERSION: 1
10577
- };
10578
-
10579
10575
  var defaultConfig = {};
10580
10576
 
10581
10577
  const config$5 = {
@@ -10782,6 +10778,99 @@ const presets = {
10782
10778
  "html-validate:a17y": config$5
10783
10779
  };
10784
10780
 
10781
+ function getNamedTransformerFromPlugin(name, plugins, pluginName, key) {
10782
+ const plugin = plugins.find((cur) => cur.name === pluginName);
10783
+ if (!plugin) {
10784
+ throw new ConfigError(`No plugin named "${pluginName}" has been loaded`);
10785
+ }
10786
+ if (!plugin.transformer) {
10787
+ throw new ConfigError(`Plugin does not expose any transformers`);
10788
+ }
10789
+ if (typeof plugin.transformer === "function") {
10790
+ throw new ConfigError(
10791
+ `Transformer "${name}" refers to named transformer but plugin exposes only unnamed, use "${pluginName}" instead.`
10792
+ );
10793
+ }
10794
+ const transformer = plugin.transformer[key];
10795
+ if (!transformer) {
10796
+ throw new ConfigError(`Plugin "${pluginName}" does not expose a transformer named "${key}".`);
10797
+ }
10798
+ return transformer;
10799
+ }
10800
+
10801
+ function getTransformerFromModule(resolvers, name) {
10802
+ return resolveTransformer(resolvers, name, { cache: true });
10803
+ }
10804
+
10805
+ function getUnnamedTransformerFromPlugin(name, plugin) {
10806
+ if (!plugin.transformer) {
10807
+ throw new ConfigError(`Plugin does not expose any transformers`);
10808
+ }
10809
+ if (typeof plugin.transformer !== "function") {
10810
+ if (plugin.transformer.default) {
10811
+ return plugin.transformer.default;
10812
+ }
10813
+ throw new ConfigError(
10814
+ `Transformer "${name}" refers to unnamed transformer but plugin exposes only named.`
10815
+ );
10816
+ }
10817
+ return plugin.transformer;
10818
+ }
10819
+
10820
+ const TRANSFORMER_API = {
10821
+ VERSION: 1
10822
+ };
10823
+
10824
+ function validateTransformer(transformer) {
10825
+ const version = transformer.api ?? 0;
10826
+ if (version !== TRANSFORMER_API.VERSION) {
10827
+ throw new ConfigError(
10828
+ `Transformer uses API version ${String(version)} but only version ${String(TRANSFORMER_API.VERSION)} is supported`
10829
+ );
10830
+ }
10831
+ }
10832
+ function loadTransformerFunction(resolvers, name, plugins) {
10833
+ const match = name.match(/(.*):(.*)/);
10834
+ if (match) {
10835
+ const [, pluginName, key] = match;
10836
+ const transformer2 = getNamedTransformerFromPlugin(name, plugins, pluginName, key);
10837
+ validateTransformer(transformer2);
10838
+ return transformer2;
10839
+ }
10840
+ const plugin = plugins.find((cur) => cur.name === name);
10841
+ if (plugin) {
10842
+ const transformer2 = getUnnamedTransformerFromPlugin(name, plugin);
10843
+ validateTransformer(transformer2);
10844
+ return transformer2;
10845
+ }
10846
+ const transformer = getTransformerFromModule(resolvers, name);
10847
+ validateTransformer(transformer);
10848
+ return transformer;
10849
+ }
10850
+ function getTransformerFunction(resolvers, name, plugins) {
10851
+ try {
10852
+ const transformer = loadTransformerFunction(resolvers, name, plugins);
10853
+ validateTransformer(transformer);
10854
+ return transformer;
10855
+ } catch (err) {
10856
+ if (err instanceof ConfigError) {
10857
+ throw new ConfigError(`Failed to load transformer "${name}": ${err.message}`, err);
10858
+ } else {
10859
+ throw new ConfigError(`Failed to load transformer "${name}"`, ensureError(err));
10860
+ }
10861
+ }
10862
+ }
10863
+ function getCachedTransformerFunction(cache, resolvers, name, plugins) {
10864
+ const cached = cache.get(name);
10865
+ if (cached) {
10866
+ return cached;
10867
+ } else {
10868
+ const transformer = getTransformerFunction(resolvers, name, plugins);
10869
+ cache.set(name, transformer);
10870
+ return transformer;
10871
+ }
10872
+ }
10873
+
10785
10874
  class ResolvedConfig {
10786
10875
  /**
10787
10876
  * @internal
@@ -10791,6 +10880,7 @@ class ResolvedConfig {
10791
10880
  this.plugins = plugins;
10792
10881
  this.rules = rules;
10793
10882
  this.transformers = transformers;
10883
+ this.cache = /* @__PURE__ */ new Map();
10794
10884
  this.original = original;
10795
10885
  }
10796
10886
  /**
@@ -10814,48 +10904,48 @@ class ResolvedConfig {
10814
10904
  *
10815
10905
  * When transforming zero or more new sources will be generated.
10816
10906
  *
10907
+ * @internal
10817
10908
  * @param source - Current source to transform.
10818
10909
  * @param filename - If set it is the filename used to match
10819
10910
  * transformer. Default is to use filename from source.
10820
10911
  * @returns A list of transformed sources ready for validation.
10821
10912
  */
10822
- transformSource(source, filename) {
10913
+ transformSource(resolvers, source, filename) {
10823
10914
  const transformer = this.findTransformer(filename ?? source.filename);
10824
10915
  const context = {
10825
10916
  hasChain: (filename2) => {
10826
10917
  return !!this.findTransformer(filename2);
10827
10918
  },
10828
10919
  chain: (source2, filename2) => {
10829
- return this.transformSource(source2, filename2);
10920
+ return this.transformSource(resolvers, source2, filename2);
10830
10921
  }
10831
10922
  };
10832
- if (transformer) {
10833
- try {
10834
- return Array.from(transformer.fn.call(context, source), (cur) => {
10835
- cur.transformedBy ??= [];
10836
- cur.transformedBy.push(transformer.name);
10837
- return cur;
10838
- });
10839
- } catch (err) {
10840
- const message = err instanceof Error ? err.message : String(err);
10841
- throw new NestedError(
10842
- `When transforming "${source.filename}": ${message}`,
10843
- ensureError(err)
10844
- );
10845
- }
10846
- } else {
10923
+ if (!transformer) {
10847
10924
  return [source];
10848
10925
  }
10926
+ const fn = getCachedTransformerFunction(this.cache, resolvers, transformer.name, this.plugins);
10927
+ try {
10928
+ const transformedSources = Array.from(fn.call(context, source));
10929
+ for (const source2 of transformedSources) {
10930
+ source2.transformedBy ??= [];
10931
+ source2.transformedBy.push(transformer.name);
10932
+ }
10933
+ return transformedSources;
10934
+ } catch (err) {
10935
+ const message = err instanceof Error ? err.message : String(err);
10936
+ throw new NestedError(`When transforming "${source.filename}": ${message}`, ensureError(err));
10937
+ }
10849
10938
  }
10850
10939
  /**
10851
10940
  * Wrapper around [[transformSource]] which reads a file before passing it
10852
10941
  * as-is to transformSource.
10853
10942
  *
10943
+ * @internal
10854
10944
  * @param filename - Filename to transform (according to configured
10855
10945
  * transformations)
10856
10946
  * @returns A list of transformed sources ready for validation.
10857
10947
  */
10858
- transformFilename(filename) {
10948
+ transformFilename(resolvers, filename) {
10859
10949
  const stdin = 0;
10860
10950
  const src = filename !== "/dev/stdin" ? filename : stdin;
10861
10951
  const data = fs__default.default.readFileSync(src, { encoding: "utf8" });
@@ -10867,10 +10957,12 @@ class ResolvedConfig {
10867
10957
  offset: 0,
10868
10958
  originalData: data
10869
10959
  };
10870
- return this.transformSource(source);
10960
+ return this.transformSource(resolvers, source);
10871
10961
  }
10872
10962
  /**
10873
10963
  * Returns true if a transformer matches given filename.
10964
+ *
10965
+ * @public
10874
10966
  */
10875
10967
  canTransform(filename) {
10876
10968
  const entry = this.findTransformer(filename);
@@ -10989,6 +11081,12 @@ function toArray(value) {
10989
11081
  return [value];
10990
11082
  }
10991
11083
  }
11084
+ function transformerEntries(transform) {
11085
+ return Object.entries(transform).map(([pattern, name]) => {
11086
+ const regex = new RegExp(pattern);
11087
+ return { pattern: regex, name };
11088
+ });
11089
+ }
10992
11090
  class Config {
10993
11091
  /**
10994
11092
  * @internal
@@ -11003,10 +11101,10 @@ class Config {
11003
11101
  };
11004
11102
  this.config = mergeInternal(initial, options);
11005
11103
  this.configurations = /* @__PURE__ */ new Map();
11006
- this.initialized = false;
11007
11104
  this.resolvers = toArray(resolvers);
11008
11105
  this.metaTable = null;
11009
11106
  this.plugins = [];
11107
+ this.transformers = transformerEntries(this.config.transform ?? {});
11010
11108
  }
11011
11109
  /**
11012
11110
  * Create a new blank configuration. See also `Config.defaultConfig()`.
@@ -11089,19 +11187,10 @@ class Config {
11089
11187
  return instance;
11090
11188
  }
11091
11189
  /**
11092
- * Initialize plugins, transforms etc.
11093
- *
11094
- * Must be called before trying to use config. Can safely be called multiple
11095
- * times.
11096
- *
11097
11190
  * @public
11191
+ * @deprecated Not needed any longer, this is a dummy noop method.
11098
11192
  */
11099
11193
  init() {
11100
- if (this.initialized) {
11101
- return;
11102
- }
11103
- this.transformers = this.precompileTransformers(this.config.transform ?? {});
11104
- this.initialized = true;
11105
11194
  }
11106
11195
  /**
11107
11196
  * Returns true if this configuration is marked as "root".
@@ -11214,6 +11303,14 @@ class Config {
11214
11303
  getPlugins() {
11215
11304
  return this.plugins;
11216
11305
  }
11306
+ /**
11307
+ * Get all configured transformers.
11308
+ *
11309
+ * @internal
11310
+ */
11311
+ getTransformers() {
11312
+ return this.transformers;
11313
+ }
11217
11314
  loadPlugins(plugins) {
11218
11315
  return plugins.map((moduleName, index) => {
11219
11316
  if (typeof moduleName !== "string") {
@@ -11297,99 +11394,6 @@ class Config {
11297
11394
  transformers: this.transformers
11298
11395
  };
11299
11396
  }
11300
- precompileTransformers(transform) {
11301
- return Object.entries(transform).map(([pattern, name]) => {
11302
- try {
11303
- const fn = this.getTransformFunction(name);
11304
- const version = fn.api ?? 0;
11305
- if (version !== TRANSFORMER_API.VERSION) {
11306
- throw new ConfigError(
11307
- `Transformer uses API version ${String(version)} but only version ${String(TRANSFORMER_API.VERSION)} is supported`
11308
- );
11309
- }
11310
- return {
11311
- // eslint-disable-next-line security/detect-non-literal-regexp -- expected to be a regexp
11312
- pattern: new RegExp(pattern),
11313
- name,
11314
- fn
11315
- };
11316
- } catch (err) {
11317
- if (err instanceof ConfigError) {
11318
- throw new ConfigError(`Failed to load transformer "${name}": ${err.message}`, err);
11319
- } else {
11320
- throw new ConfigError(`Failed to load transformer "${name}"`, ensureError(err));
11321
- }
11322
- }
11323
- });
11324
- }
11325
- /**
11326
- * Get transformation function requested by configuration.
11327
- *
11328
- * Searches:
11329
- *
11330
- * - Named transformers from plugins.
11331
- * - Unnamed transformer from plugin.
11332
- * - Standalone modules (local or node_modules)
11333
- *
11334
- * @param name - Key from configuration
11335
- */
11336
- getTransformFunction(name) {
11337
- const match = name.match(/(.*):(.*)/);
11338
- if (match) {
11339
- const [, pluginName, key] = match;
11340
- return this.getNamedTransformerFromPlugin(name, pluginName, key);
11341
- }
11342
- const plugin = this.plugins.find((cur) => cur.name === name);
11343
- if (plugin) {
11344
- return this.getUnnamedTransformerFromPlugin(name, plugin);
11345
- }
11346
- return this.getTransformerFromModule(name);
11347
- }
11348
- /**
11349
- * @param name - Original name from configuration
11350
- * @param pluginName - Name of plugin
11351
- * @param key - Name of transform (from plugin)
11352
- */
11353
- getNamedTransformerFromPlugin(name, pluginName, key) {
11354
- const plugin = this.plugins.find((cur) => cur.name === pluginName);
11355
- if (!plugin) {
11356
- throw new ConfigError(`No plugin named "${pluginName}" has been loaded`);
11357
- }
11358
- if (!plugin.transformer) {
11359
- throw new ConfigError(`Plugin does not expose any transformer`);
11360
- }
11361
- if (typeof plugin.transformer === "function") {
11362
- throw new ConfigError(
11363
- `Transformer "${name}" refers to named transformer but plugin exposes only unnamed, use "${pluginName}" instead.`
11364
- );
11365
- }
11366
- const transformer = plugin.transformer[key];
11367
- if (!transformer) {
11368
- throw new ConfigError(`Plugin "${pluginName}" does not expose a transformer named "${key}".`);
11369
- }
11370
- return transformer;
11371
- }
11372
- /**
11373
- * @param name - Original name from configuration
11374
- * @param plugin - Plugin instance
11375
- */
11376
- getUnnamedTransformerFromPlugin(name, plugin) {
11377
- if (!plugin.transformer) {
11378
- throw new ConfigError(`Plugin does not expose any transformer`);
11379
- }
11380
- if (typeof plugin.transformer !== "function") {
11381
- if (plugin.transformer.default) {
11382
- return plugin.transformer.default;
11383
- }
11384
- throw new ConfigError(
11385
- `Transformer "${name}" refers to unnamed transformer but plugin exposes only named.`
11386
- );
11387
- }
11388
- return plugin.transformer;
11389
- }
11390
- getTransformerFromModule(name) {
11391
- return resolveTransformer(this.resolvers, name, { cache: true });
11392
- }
11393
11397
  }
11394
11398
 
11395
11399
  class ConfigLoader {
@@ -11407,6 +11411,12 @@ class ConfigLoader {
11407
11411
  configData ? this.loadFromObject(configData) : this.defaultConfig()
11408
11412
  );
11409
11413
  }
11414
+ /**
11415
+ * @internal
11416
+ */
11417
+ getResolvers() {
11418
+ return this.resolvers;
11419
+ }
11410
11420
  /**
11411
11421
  * @internal For testing only
11412
11422
  */
@@ -12590,11 +12600,9 @@ class StaticConfigLoader extends ConfigLoader {
12590
12600
  getConfigFor(_handle, configOverride) {
12591
12601
  const override = this.loadFromObject(configOverride ?? {});
12592
12602
  if (override.isRootFound()) {
12593
- override.init();
12594
12603
  return override.resolve();
12595
12604
  }
12596
12605
  const merged = this.globalConfig.merge(this.resolvers, override);
12597
- merged.init();
12598
12606
  return merged.resolve();
12599
12607
  }
12600
12608
  flushCache() {
@@ -12664,7 +12672,8 @@ class HtmlValidate {
12664
12672
  async validateSource(input, configOverride) {
12665
12673
  const source = normalizeSource(input);
12666
12674
  const config = await this.getConfigFor(source.filename, configOverride);
12667
- const transformedSource = config.transformSource(source);
12675
+ const resolvers = this.configLoader.getResolvers();
12676
+ const transformedSource = config.transformSource(resolvers, source);
12668
12677
  const engine = new Engine(config, Parser);
12669
12678
  return engine.lint(transformedSource);
12670
12679
  }
@@ -12678,7 +12687,8 @@ class HtmlValidate {
12678
12687
  validateSourceSync(input, configOverride) {
12679
12688
  const source = normalizeSource(input);
12680
12689
  const config = this.getConfigForSync(source.filename, configOverride);
12681
- const transformedSource = config.transformSource(source);
12690
+ const resolvers = this.configLoader.getResolvers();
12691
+ const transformedSource = config.transformSource(resolvers, source);
12682
12692
  const engine = new Engine(config, Parser);
12683
12693
  return engine.lint(transformedSource);
12684
12694
  }
@@ -12691,7 +12701,8 @@ class HtmlValidate {
12691
12701
  */
12692
12702
  async validateFile(filename) {
12693
12703
  const config = await this.getConfigFor(filename);
12694
- const source = config.transformFilename(filename);
12704
+ const resolvers = this.configLoader.getResolvers();
12705
+ const source = config.transformFilename(resolvers, filename);
12695
12706
  const engine = new Engine(config, Parser);
12696
12707
  return Promise.resolve(engine.lint(source));
12697
12708
  }
@@ -12704,7 +12715,8 @@ class HtmlValidate {
12704
12715
  */
12705
12716
  validateFileSync(filename) {
12706
12717
  const config = this.getConfigForSync(filename);
12707
- const source = config.transformFilename(filename);
12718
+ const resolvers = this.configLoader.getResolvers();
12719
+ const source = config.transformFilename(resolvers, filename);
12708
12720
  const engine = new Engine(config, Parser);
12709
12721
  return engine.lint(source);
12710
12722
  }
@@ -12772,7 +12784,8 @@ class HtmlValidate {
12772
12784
  */
12773
12785
  dumpTokens(filename) {
12774
12786
  const config = this.getConfigForSync(filename);
12775
- const source = config.transformFilename(filename);
12787
+ const resolvers = this.configLoader.getResolvers();
12788
+ const source = config.transformFilename(resolvers, filename);
12776
12789
  const engine = new Engine(config, Parser);
12777
12790
  return engine.dumpTokens(source);
12778
12791
  }
@@ -12787,7 +12800,8 @@ class HtmlValidate {
12787
12800
  */
12788
12801
  dumpEvents(filename) {
12789
12802
  const config = this.getConfigForSync(filename);
12790
- const source = config.transformFilename(filename);
12803
+ const resolvers = this.configLoader.getResolvers();
12804
+ const source = config.transformFilename(resolvers, filename);
12791
12805
  const engine = new Engine(config, Parser);
12792
12806
  return engine.dumpEvents(source);
12793
12807
  }
@@ -12802,7 +12816,8 @@ class HtmlValidate {
12802
12816
  */
12803
12817
  dumpTree(filename) {
12804
12818
  const config = this.getConfigForSync(filename);
12805
- const source = config.transformFilename(filename);
12819
+ const resolvers = this.configLoader.getResolvers();
12820
+ const source = config.transformFilename(resolvers, filename);
12806
12821
  const engine = new Engine(config, Parser);
12807
12822
  return engine.dumpTree(source);
12808
12823
  }
@@ -12817,7 +12832,8 @@ class HtmlValidate {
12817
12832
  */
12818
12833
  dumpSource(filename) {
12819
12834
  const config = this.getConfigForSync(filename);
12820
- const sources = config.transformFilename(filename);
12835
+ const resolvers = this.configLoader.getResolvers();
12836
+ const sources = config.transformFilename(resolvers, filename);
12821
12837
  return sources.reduce((result, source) => {
12822
12838
  const line = String(source.line);
12823
12839
  const column = String(source.column);
@@ -13012,7 +13028,7 @@ class HtmlValidate {
13012
13028
  }
13013
13029
 
13014
13030
  const name = "html-validate";
13015
- const version = "8.25.1";
13031
+ const version = "8.26.0";
13016
13032
  const bugs = "https://gitlab.com/html-validate/html-validate/issues/new";
13017
13033
 
13018
13034
  function definePlugin(plugin) {