@markuplint/file-resolver 5.1.0 → 5.2.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,19 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [5.2.0](https://github.com/markuplint/markuplint/compare/v5.1.1...v5.2.0) (2026-10-13)
7
+
8
+ ### Bug Fixes
9
+
10
+ - use caret ranges for third-party dependencies of published packages ([5fb5d2e](https://github.com/markuplint/markuplint/commit/5fb5d2ee81eaeea45fe7256a40dd41c95ff0d672))
11
+
12
+ ## [5.1.1](https://github.com/markuplint/markuplint/compare/v5.1.0...v5.1.1) (2026-10-09)
13
+
14
+ ### Bug Fixes
15
+
16
+ - **file-resolver:** import preset JSON with a type attribute ([92cf368](https://github.com/markuplint/markuplint/commit/92cf368fceaaf64a324b9d719d10b4fa37ac776e))
17
+ - **file-resolver:** throw ConfigLoadError when a preset cannot be loaded ([cf51090](https://github.com/markuplint/markuplint/commit/cf510906400b3150c2693a85cd75877227b85419))
18
+
6
19
  # [5.1.0](https://github.com/markuplint/markuplint/compare/v5.0.1...v5.1.0) (2026-10-08)
7
20
 
8
21
  ### Features
@@ -325,7 +325,7 @@ export class ConfigProvider {
325
325
  }
326
326
  if (isPresetModuleName(filePath)) {
327
327
  const [, name] = filePath.match(/^markuplint:(.+)$/i) ?? [];
328
- const config = await getPreset(name ?? filePath);
328
+ const config = await getPreset(name ?? filePath, referrer);
329
329
  const pathResolvedConfig = await this.#pathResolve(config, filePath);
330
330
  this.#store.set(filePath, pathResolvedConfig);
331
331
  return pathResolvedConfig;
@@ -1,2 +1,11 @@
1
1
  import type { Config } from '@markuplint/ml-config';
2
- export declare function getPreset(name: string): Promise<Config>;
2
+ /**
3
+ * Loads a built-in preset (`markuplint:<name>`).
4
+ *
5
+ * @param name - The preset name without the `markuplint:` prefix
6
+ * @param referrer - The config that asked for the preset, named in the error message
7
+ * @throws {ConfigLoadError} The preset cannot be imported. It is a failure to
8
+ * load a config (Tier 2), not a bug in markuplint: a name the user mistyped
9
+ * and a runtime that rejects the import both end here.
10
+ */
11
+ export declare function getPreset(name: string, referrer?: string): Promise<Config>;
package/lib/get-preset.js CHANGED
@@ -1,13 +1,33 @@
1
- import { forceImportJsonInModule } from './force-import-json-in-module.js';
1
+ import { ConfigLoadError } from '@markuplint/shared';
2
+ import { log } from './debug.js';
2
3
  const cache = new Map();
3
- export async function getPreset(name) {
4
+ const pLog = log.extend('get-preset');
5
+ /**
6
+ * Loads a built-in preset (`markuplint:<name>`).
7
+ *
8
+ * @param name - The preset name without the `markuplint:` prefix
9
+ * @param referrer - The config that asked for the preset, named in the error message
10
+ * @throws {ConfigLoadError} The preset cannot be imported. It is a failure to
11
+ * load a config (Tier 2), not a bug in markuplint: a name the user mistyped
12
+ * and a runtime that rejects the import both end here.
13
+ */
14
+ export async function getPreset(name, referrer = '<unknown>') {
4
15
  if (cache.has(name)) {
5
16
  return cache.get(name);
6
17
  }
7
- const json = await forceImportJsonInModule(`@markuplint/config-presets/preset.${name}.json`);
8
- if (json instanceof Error) {
9
- throw new ReferenceError(`Preset markuplint:${name} is not found`);
18
+ // NOTE: `isFatalError()` is intentionally NOT applied at this catch. What
19
+ // `import()` throws for an unloadable JSON module differs by runtime
20
+ // (Node.js, Deno and Bun use different classes and codes), and a
21
+ // `SyntaxError` or `TypeError` here may come from the module loader rather
22
+ // than from markuplint's own code. The cause goes to the debug log.
23
+ const imported = await import(`@markuplint/config-presets/preset.${name}.json`, {
24
+ with: { type: 'json' },
25
+ }).catch((error) => error);
26
+ if (imported instanceof Error) {
27
+ pLog('Error in getPreset: %O', imported);
28
+ throw new ConfigLoadError(`Preset markuplint:${name} is not found`, `markuplint:${name}`, referrer);
10
29
  }
30
+ const json = imported.default ?? imported;
11
31
  cache.set(name, json);
12
32
  return json;
13
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/file-resolver",
3
- "version": "5.1.0",
3
+ "version": "5.2.0",
4
4
  "description": "The file resolver of markuplint",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,25 +31,25 @@
31
31
  "clean": "tsc --build --clean"
32
32
  },
33
33
  "devDependencies": {
34
- "@types/node": "24.13.3"
34
+ "@types/node": "24.19.1"
35
35
  },
36
36
  "dependencies": {
37
- "@markuplint/html-parser": "5.1.0",
38
- "@markuplint/ml-ast": "5.1.0",
39
- "@markuplint/ml-config": "5.1.0",
40
- "@markuplint/ml-core": "5.1.0",
41
- "@markuplint/ml-spec": "5.1.0",
42
- "@markuplint/parser-utils": "5.1.0",
43
- "@markuplint/pretenders": "5.1.0",
44
- "@markuplint/selector": "5.1.0",
45
- "@markuplint/shared": "5.1.0",
46
- "cosmiconfig": "9.0.1",
47
- "debug": "4.4.3",
48
- "glob": "13.0.6",
49
- "ignore": "7.0.5",
50
- "import-meta-resolve": "4.2.0",
51
- "jsonc": "2.0.0",
52
- "minimatch": "10.2.5"
53
- },
54
- "gitHead": "3a061784a8211034ad0c1cbd64798c0213414f65"
37
+ "@markuplint/html-parser": "5.2.0",
38
+ "@markuplint/ml-ast": "5.1.1",
39
+ "@markuplint/ml-config": "5.2.0",
40
+ "@markuplint/ml-core": "5.2.0",
41
+ "@markuplint/ml-spec": "5.2.0",
42
+ "@markuplint/parser-utils": "5.2.0",
43
+ "@markuplint/pretenders": "5.2.0",
44
+ "@markuplint/selector": "5.2.0",
45
+ "@markuplint/shared": "5.2.0",
46
+ "cosmiconfig": "^9.0.2",
47
+ "debug": "^4.4.3",
48
+ "glob": "^13.0.6",
49
+ "ignore": "^7.0.12",
50
+ "import-meta-resolve": "^4.2.0",
51
+ "jsonc": "^2.0.0",
52
+ "minimatch": "^10.2.6"
53
+ },
54
+ "gitHead": "d8b2feab77c9c862513615bea6b80d2817431878"
55
55
  }
@@ -1 +0,0 @@
1
- export declare function forceImportJsonInModule(modPath: string): Promise<any>;
@@ -1,27 +0,0 @@
1
- import { readFile } from 'node:fs/promises';
2
- import { log } from './debug.js';
3
- import { fromFileURL } from './path-utils.js';
4
- const fLog = log.extend('force-import-json-in-module');
5
- export async function forceImportJsonInModule(modPath) {
6
- const error = await import(modPath).catch(error => error);
7
- if (error instanceof Error) {
8
- fLog('Error in forceImportJsonInModule: %O', error);
9
- if (!('code' in error)) {
10
- return error;
11
- }
12
- if (error.code !== 'ERR_IMPORT_ASSERTION_TYPE_MISSING' && error.code !== 'ERR_IMPORT_ATTRIBUTE_MISSING') {
13
- return error;
14
- }
15
- const searchPath = /module\s"([^"]+)"\sneeds/i.exec(error.message);
16
- const absPath = searchPath?.[1] ?? null;
17
- fLog('Extract path: %s', absPath);
18
- if (!absPath) {
19
- return error;
20
- }
21
- const normalizePath = absPath.startsWith('file:') ? fromFileURL(absPath) : absPath;
22
- fLog('Find JSON file path: %s', normalizePath);
23
- const fileContent = await readFile(normalizePath, { encoding: 'utf8' });
24
- return JSON.parse(fileContent);
25
- }
26
- return error.default ?? error;
27
- }