html-validate 8.22.0 → 9.0.0-rc.2

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.
@@ -162,19 +162,13 @@ class FileSystemConfigLoader extends core.ConfigLoader {
162
162
  */
163
163
  getConfigFor(filename, configOverride) {
164
164
  const override = this.loadFromObject(configOverride ?? {});
165
- if (override.isRootFound()) {
166
- override.init();
167
- return override.resolve();
168
- }
169
- if (this.globalConfig.isRootFound()) {
170
- const merged2 = this.globalConfig.merge(this.resolvers, override);
171
- merged2.init();
172
- return merged2.resolve();
165
+ if (core.isThenable(override)) {
166
+ return override.then((override2) => {
167
+ return this._resolveAsync(filename, override2);
168
+ });
169
+ } else {
170
+ return this._resolveSync(filename, override);
173
171
  }
174
- const config = this.fromFilename(filename);
175
- const merged = config ? config.merge(this.resolvers, override) : this.globalConfig.merge(this.resolvers, override);
176
- merged.init();
177
- return merged.resolve();
178
172
  }
179
173
  /**
180
174
  * Flush configuration cache.
@@ -208,6 +202,9 @@ class FileSystemConfigLoader extends core.ConfigLoader {
208
202
  while (true) {
209
203
  for (const configFile of findConfigurationFiles(this.fs, current)) {
210
204
  const local = this.loadFromFile(configFile);
205
+ if (core.isThenable(local)) {
206
+ return this.fromFilenameAsync(filename);
207
+ }
211
208
  found = true;
212
209
  config = local.merge(this.resolvers, config);
213
210
  }
@@ -227,6 +224,80 @@ class FileSystemConfigLoader extends core.ConfigLoader {
227
224
  this.cache.set(filename, config);
228
225
  return config;
229
226
  }
227
+ /**
228
+ * Async version of [[fromFilename]].
229
+ *
230
+ * @internal
231
+ */
232
+ async fromFilenameAsync(filename) {
233
+ if (filename === "inline") {
234
+ return null;
235
+ }
236
+ const cache = this.cache.get(filename);
237
+ if (cache) {
238
+ return cache;
239
+ }
240
+ let found = false;
241
+ let current = path__default.default.resolve(path__default.default.dirname(filename));
242
+ let config = this.empty();
243
+ while (true) {
244
+ for (const configFile of findConfigurationFiles(this.fs, current)) {
245
+ const local = await this.loadFromFile(configFile);
246
+ found = true;
247
+ config = local.merge(this.resolvers, config);
248
+ }
249
+ if (config.isRootFound()) {
250
+ break;
251
+ }
252
+ const child = current;
253
+ current = path__default.default.dirname(current);
254
+ if (current === child) {
255
+ break;
256
+ }
257
+ }
258
+ if (!found) {
259
+ this.cache.set(filename, null);
260
+ return null;
261
+ }
262
+ this.cache.set(filename, config);
263
+ return config;
264
+ }
265
+ _mergeSync(globalConfig, override, config) {
266
+ const merged = config ? config.merge(this.resolvers, override) : globalConfig.merge(this.resolvers, override);
267
+ merged.init();
268
+ return merged.resolve();
269
+ }
270
+ _resolveSync(filename, override) {
271
+ if (override.isRootFound()) {
272
+ override.init();
273
+ return override.resolve();
274
+ }
275
+ const globalConfig = this.getGlobalConfigSync();
276
+ if (globalConfig.isRootFound()) {
277
+ const merged = globalConfig.merge(this.resolvers, override);
278
+ merged.init();
279
+ return merged.resolve();
280
+ }
281
+ const config = this.fromFilename(filename);
282
+ if (core.isThenable(config)) {
283
+ throw new core.UserError("Cannot load async config from sync function");
284
+ }
285
+ return this._mergeSync(globalConfig, override, config);
286
+ }
287
+ async _resolveAsync(filename, override) {
288
+ if (override.isRootFound()) {
289
+ override.init();
290
+ return override.resolve();
291
+ }
292
+ const globalConfig = await this.getGlobalConfig();
293
+ if (globalConfig.isRootFound()) {
294
+ const merged = globalConfig.merge(this.resolvers, override);
295
+ merged.init();
296
+ return merged.resolve();
297
+ }
298
+ const config = await this.fromFilenameAsync(filename);
299
+ return this._mergeSync(globalConfig, override, config);
300
+ }
230
301
  /**
231
302
  * @internal For testing only
232
303
  */
@@ -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,CA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,OAAA,CAAQ,KAAM,CAAAC,sBAAA,CAAM,GAAI,CAAA,IAAI,CAAC,CAAA,CAAA;AAAA,GAC9B;AACD,CAAA,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,OAAA;AAAA,GACH,CAAA,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\";\nimport { isThenable } from \"../../utils\";\nimport { UserError } from \"../../error\";\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(\n\t\tfilename: string,\n\t\tconfigOverride?: ConfigData,\n\t): ResolvedConfig | Promise<ResolvedConfig> {\n\t\tconst override = this.loadFromObject(configOverride ?? {});\n\t\tif (isThenable(override)) {\n\t\t\treturn override.then((override) => {\n\t\t\t\treturn this._resolveAsync(filename, override);\n\t\t\t});\n\t\t} else {\n\t\t\treturn this._resolveSync(filename, override);\n\t\t}\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 | Promise<Config | null> | 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\n\t\t\t\t/* if the loader returns an async config we exit out of the synchronous\n\t\t\t\t * processing and enter the async method so we can resolve any promises\n\t\t\t\t * as we go */\n\t\t\t\tif (isThenable(local)) {\n\t\t\t\t\treturn this.fromFilenameAsync(filename);\n\t\t\t\t}\n\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 * Async version of [[fromFilename]].\n\t *\n\t * @internal\n\t */\n\tpublic async fromFilenameAsync(filename: string): Promise<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 = await 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\tprivate _mergeSync(\n\t\tglobalConfig: Config,\n\t\toverride: Config,\n\t\tconfig: Config | null,\n\t): ResolvedConfig {\n\t\tconst merged = config\n\t\t\t? config.merge(this.resolvers, override)\n\t\t\t: globalConfig.merge(this.resolvers, override);\n\t\tmerged.init();\n\t\treturn merged.resolve();\n\t}\n\n\tprivate _resolveSync(filename: string, override: Config): ResolvedConfig {\n\t\tif (override.isRootFound()) {\n\t\t\toverride.init();\n\t\t\treturn override.resolve();\n\t\t}\n\n\t\tconst globalConfig = this.getGlobalConfigSync();\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 (globalConfig.isRootFound()) {\n\t\t\tconst merged = 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\tif (isThenable(config)) {\n\t\t\tthrow new UserError(\"Cannot load async config from sync function\");\n\t\t}\n\n\t\treturn this._mergeSync(globalConfig, override, config);\n\t}\n\n\tprivate async _resolveAsync(filename: string, override: Config): Promise<ResolvedConfig> {\n\t\tif (override.isRootFound()) {\n\t\t\toverride.init();\n\t\t\treturn override.resolve();\n\t\t}\n\n\t\tconst globalConfig = await this.getGlobalConfig();\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 (globalConfig.isRootFound()) {\n\t\t\tconst merged = globalConfig.merge(this.resolvers, override);\n\t\t\tmerged.init();\n\t\t\treturn merged.resolve();\n\t\t}\n\n\t\tconst config = await this.fromFilenameAsync(filename);\n\t\treturn this._mergeSync(globalConfig, override, 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 | Promise<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","isThenable","override","UserError","Config","version","kleur","compatibilityCheckImpl"],"mappings":";;;;;;;;;;;;;AAGgB,SAAA,eAAA,CAAgB,SAAyB,QAA2B,EAA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Ac,EAAA,QAAA,EAAU,MAAM,CAAA,CAAA;AAAA,GACtD;AAAA;AAAA;AAAA;AAAA,EAKO,iBAAgD,GAAA;AACtD,IAAA,OAAO,IAAK,CAAA,KAAA,CAAA;AAAA,GACb;AAAA,EAEU,aAA0C,GAAA;AACnD,IAAA,OAAOC,YAAO,aAAc,EAAA,CAAA;AAAA,GAC7B;AACD;;ACnUA,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,CAAA;AAAA,GAC9B;AACD,CAAA,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,OAAA;AAAA,GACH,CAAA,CAAA;AACF;;;;;;;;"}
package/dist/cjs/core.js CHANGED
@@ -10785,7 +10785,7 @@ function resolveTransformer(resolvers, id, options) {
10785
10785
  function staticResolver(map = {}) {
10786
10786
  const { elements = {}, configs = {}, plugins = {}, transformers = {} } = map;
10787
10787
  return {
10788
- name: "static-qresolver",
10788
+ name: "static-resolver",
10789
10789
  addElements(id, value) {
10790
10790
  elements[id] = value;
10791
10791
  },
@@ -10860,7 +10860,7 @@ class Config {
10860
10860
  * Create a new blank configuration. See also `Config.defaultConfig()`.
10861
10861
  */
10862
10862
  static empty() {
10863
- return Config.create([], {
10863
+ return new Config([], {
10864
10864
  extends: [],
10865
10865
  rules: {},
10866
10866
  plugins: [],
@@ -10919,7 +10919,7 @@ class Config {
10919
10919
  * Load a default configuration object.
10920
10920
  */
10921
10921
  static defaultConfig() {
10922
- return Config.create([], defaultConfig);
10922
+ return new Config([], defaultConfig);
10923
10923
  }
10924
10924
  /**
10925
10925
  * @internal
@@ -10929,12 +10929,20 @@ class Config {
10929
10929
  instance.plugins = instance.loadPlugins(instance.config.plugins ?? []);
10930
10930
  instance.configurations = instance.loadConfigurations(instance.plugins);
10931
10931
  instance.extendMeta(instance.plugins);
10932
- instance.config = instance.extendConfig(instance.config.extends ?? []);
10933
- instance.config.extends = [];
10934
- if (options.rules) {
10935
- instance.config = mergeInternal(instance.config, { rules: options.rules });
10932
+ const update = (extendedConfig2) => {
10933
+ instance.config = extendedConfig2;
10934
+ instance.config.extends = [];
10935
+ if (options.rules) {
10936
+ instance.config = mergeInternal(instance.config, { rules: options.rules });
10937
+ }
10938
+ return instance;
10939
+ };
10940
+ const extendedConfig = instance.extendConfig(instance.config.extends ?? []);
10941
+ if (isThenable(extendedConfig)) {
10942
+ return extendedConfig.then((extended) => update(extended));
10943
+ } else {
10944
+ return update(extendedConfig);
10936
10945
  }
10937
- return instance;
10938
10946
  }
10939
10947
  /**
10940
10948
  * Initialize plugins, transforms etc.
@@ -10965,7 +10973,11 @@ class Config {
10965
10973
  * @param rhs - Configuration to merge with this one.
10966
10974
  */
10967
10975
  merge(resolvers, rhs) {
10968
- return Config.create(resolvers, mergeInternal(this.config, rhs.config));
10976
+ const instance = new Config(resolvers, mergeInternal(this.config, rhs.config));
10977
+ instance.plugins = instance.loadPlugins(instance.config.plugins ?? []);
10978
+ instance.configurations = instance.loadConfigurations(instance.plugins);
10979
+ instance.extendMeta(instance.plugins);
10980
+ return instance;
10969
10981
  }
10970
10982
  extendConfig(entries) {
10971
10983
  if (entries.length === 0) {
@@ -10977,7 +10989,28 @@ class Config {
10977
10989
  if (this.configurations.has(entry)) {
10978
10990
  extended = this.configurations.get(entry);
10979
10991
  } else {
10980
- extended = Config.fromFile(this.resolvers, entry).config;
10992
+ const loadedConfig = Config.fromFile(this.resolvers, entry);
10993
+ if (isThenable(loadedConfig)) {
10994
+ return this.extendConfigAsync(entries);
10995
+ }
10996
+ extended = loadedConfig.config;
10997
+ }
10998
+ base = mergeInternal(base, extended);
10999
+ }
11000
+ return mergeInternal(base, this.config);
11001
+ }
11002
+ async extendConfigAsync(entries) {
11003
+ if (entries.length === 0) {
11004
+ return this.config;
11005
+ }
11006
+ let base = {};
11007
+ for (const entry of entries) {
11008
+ let extended;
11009
+ if (this.configurations.has(entry)) {
11010
+ extended = this.configurations.get(entry);
11011
+ } else {
11012
+ const loadedConfig = await Config.fromFile(this.resolvers, entry);
11013
+ extended = loadedConfig.config;
10981
11014
  }
10982
11015
  base = mergeInternal(base, extended);
10983
11016
  }
@@ -11241,26 +11274,86 @@ class Config {
11241
11274
  }
11242
11275
 
11243
11276
  class ConfigLoader {
11244
- constructor(resolvers, config) {
11245
- const defaults = Config.empty();
11277
+ /**
11278
+ * Create a new ConfigLoader.
11279
+ *
11280
+ * @param resolvers - Sorted list of resolvers to use (in order).
11281
+ * @param configData - Default configuration (which all configurations will inherit from).
11282
+ */
11283
+ constructor(resolvers, configData) {
11246
11284
  this.resolvers = resolvers;
11247
- this.globalConfig = defaults.merge(
11248
- this.resolvers,
11249
- config ? this.loadFromObject(config) : this.defaultConfig()
11250
- );
11285
+ this._configData = configData;
11286
+ this._globalConfig = null;
11287
+ }
11288
+ /**
11289
+ * Set a new default configuration on this loader. Resets cached global
11290
+ * configuration.
11291
+ *
11292
+ * @internal
11293
+ */
11294
+ setConfigData(configData) {
11295
+ this._configData = configData;
11296
+ this._globalConfig = null;
11297
+ }
11298
+ /**
11299
+ * Get the global configuration.
11300
+ *
11301
+ * @returns A promise resolving to the global configuration.
11302
+ */
11303
+ getGlobalConfig() {
11304
+ if (this._globalConfig) {
11305
+ return this._globalConfig;
11306
+ }
11307
+ const defaults = Config.empty();
11308
+ const config = this._configData ? this.loadFromObject(this._configData) : this.defaultConfig();
11309
+ if (isThenable(config)) {
11310
+ return config.then((config2) => {
11311
+ this._globalConfig = defaults.merge(this.resolvers, config2);
11312
+ return this._globalConfig;
11313
+ });
11314
+ } else {
11315
+ this._globalConfig = defaults.merge(this.resolvers, config);
11316
+ return this._globalConfig;
11317
+ }
11318
+ }
11319
+ /**
11320
+ * Get the global configuration.
11321
+ *
11322
+ * The synchronous version does not support async resolvers.
11323
+ *
11324
+ * @returns The global configuration.
11325
+ */
11326
+ getGlobalConfigSync() {
11327
+ if (this._globalConfig) {
11328
+ return this._globalConfig;
11329
+ }
11330
+ const defaults = Config.empty();
11331
+ const config = this._configData ? this.loadFromObject(this._configData) : this.defaultConfig();
11332
+ if (isThenable(config)) {
11333
+ throw new UserError("Cannot load async config from sync function");
11334
+ }
11335
+ this._globalConfig = defaults.merge(this.resolvers, config);
11336
+ return this._globalConfig;
11251
11337
  }
11252
11338
  /**
11253
11339
  * @internal For testing only
11254
11340
  */
11255
- _getGlobalConfig() {
11256
- return this.globalConfig.get();
11341
+ async _getGlobalConfig() {
11342
+ const config = await this.getGlobalConfig();
11343
+ return config.get();
11257
11344
  }
11258
11345
  empty() {
11259
11346
  return Config.empty();
11260
11347
  }
11348
+ /**
11349
+ * Load configuration from object.
11350
+ */
11261
11351
  loadFromObject(options, filename) {
11262
11352
  return Config.fromObject(this.resolvers, options, filename);
11263
11353
  }
11354
+ /**
11355
+ * Load configuration from filename.
11356
+ */
11264
11357
  loadFromFile(filename) {
11265
11358
  return Config.fromFile(this.resolvers, filename);
11266
11359
  }
@@ -12413,20 +12506,16 @@ class StaticConfigLoader extends ConfigLoader {
12413
12506
  * @since 8.20.0
12414
12507
  * @param config - New configuration to use.
12415
12508
  */
12416
- /* istanbul ignore next -- not testing setters/getters */
12417
12509
  setConfig(config) {
12418
- const defaults = Config.empty();
12419
- this.globalConfig = defaults.merge(this.resolvers, this.loadFromObject(config));
12510
+ this.setConfigData(config);
12420
12511
  }
12421
12512
  getConfigFor(_handle, configOverride) {
12422
12513
  const override = this.loadFromObject(configOverride ?? {});
12423
- if (override.isRootFound()) {
12424
- override.init();
12425
- return override.resolve();
12514
+ if (isThenable(override)) {
12515
+ return override.then((override2) => this._resolveConfig(override2));
12516
+ } else {
12517
+ return this._resolveConfig(override);
12426
12518
  }
12427
- const merged = this.globalConfig.merge(this.resolvers, override);
12428
- merged.init();
12429
- return merged.resolve();
12430
12519
  }
12431
12520
  flushCache() {
12432
12521
  }
@@ -12436,6 +12525,24 @@ class StaticConfigLoader extends ConfigLoader {
12436
12525
  elements: ["html5"]
12437
12526
  });
12438
12527
  }
12528
+ _resolveConfig(override) {
12529
+ if (override.isRootFound()) {
12530
+ override.init();
12531
+ return override.resolve();
12532
+ }
12533
+ const globalConfig = this.getGlobalConfig();
12534
+ if (isThenable(globalConfig)) {
12535
+ return globalConfig.then((globalConfig2) => {
12536
+ const merged = globalConfig2.merge(this.resolvers, override);
12537
+ merged.init();
12538
+ return merged.resolve();
12539
+ });
12540
+ } else {
12541
+ const merged = globalConfig.merge(this.resolvers, override);
12542
+ merged.init();
12543
+ return merged.resolve();
12544
+ }
12545
+ }
12439
12546
  }
12440
12547
 
12441
12548
  function isSourceHooks(value) {
@@ -12805,7 +12912,11 @@ class HtmlValidate {
12805
12912
  * @param configOverride - Configuration to apply last.
12806
12913
  */
12807
12914
  getConfigForSync(filename, configOverride) {
12808
- return this.configLoader.getConfigFor(filename, configOverride);
12915
+ const config = this.configLoader.getConfigFor(filename, configOverride);
12916
+ if (isThenable(config)) {
12917
+ throw new UserError("Cannot use asynchronous config loader with synchronous api");
12918
+ }
12919
+ return config;
12809
12920
  }
12810
12921
  /**
12811
12922
  * Get current configuration loader.
@@ -12843,7 +12954,7 @@ class HtmlValidate {
12843
12954
  }
12844
12955
 
12845
12956
  const name = "html-validate";
12846
- const version = "8.22.0";
12957
+ const version = "9.0.0-rc.2";
12847
12958
  const bugs = "https://gitlab.com/html-validate/html-validate/issues/new";
12848
12959
 
12849
12960
  function definePlugin(plugin) {
@@ -13839,6 +13950,7 @@ exports.definePlugin = definePlugin;
13839
13950
  exports.ensureError = ensureError;
13840
13951
  exports.getFormatter = getFormatter;
13841
13952
  exports.ignore = ignore$1;
13953
+ exports.isThenable = isThenable;
13842
13954
  exports.keywordPatternMatcher = keywordPatternMatcher;
13843
13955
  exports.name = name;
13844
13956
  exports.ruleExists = ruleExists;