@markuplint/file-resolver 5.1.0 → 5.1.1
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 +7 -0
- package/lib/config-provider.js +1 -1
- package/lib/get-preset.d.ts +10 -1
- package/lib/get-preset.js +25 -5
- package/package.json +11 -11
- package/lib/force-import-json-in-module.d.ts +0 -1
- package/lib/force-import-json-in-module.js +0 -27
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
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.1.1](https://github.com/markuplint/markuplint/compare/v5.1.0...v5.1.1) (2026-10-09)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **file-resolver:** import preset JSON with a type attribute ([92cf368](https://github.com/markuplint/markuplint/commit/92cf368fceaaf64a324b9d719d10b4fa37ac776e))
|
|
11
|
+
- **file-resolver:** throw ConfigLoadError when a preset cannot be loaded ([cf51090](https://github.com/markuplint/markuplint/commit/cf510906400b3150c2693a85cd75877227b85419))
|
|
12
|
+
|
|
6
13
|
# [5.1.0](https://github.com/markuplint/markuplint/compare/v5.0.1...v5.1.0) (2026-10-08)
|
|
7
14
|
|
|
8
15
|
### Features
|
package/lib/config-provider.js
CHANGED
|
@@ -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;
|
package/lib/get-preset.d.ts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
import type { Config } from '@markuplint/ml-config';
|
|
2
|
-
|
|
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 {
|
|
1
|
+
import { ConfigLoadError } from '@markuplint/shared';
|
|
2
|
+
import { log } from './debug.js';
|
|
2
3
|
const cache = new Map();
|
|
3
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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.
|
|
3
|
+
"version": "5.1.1",
|
|
4
4
|
"description": "The file resolver of markuplint",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,15 +34,15 @@
|
|
|
34
34
|
"@types/node": "24.13.3"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@markuplint/html-parser": "5.1.
|
|
38
|
-
"@markuplint/ml-ast": "5.1.
|
|
39
|
-
"@markuplint/ml-config": "5.1.
|
|
40
|
-
"@markuplint/ml-core": "5.1.
|
|
41
|
-
"@markuplint/ml-spec": "5.1.
|
|
42
|
-
"@markuplint/parser-utils": "5.1.
|
|
43
|
-
"@markuplint/pretenders": "5.1.
|
|
44
|
-
"@markuplint/selector": "5.1.
|
|
45
|
-
"@markuplint/shared": "5.1.
|
|
37
|
+
"@markuplint/html-parser": "5.1.1",
|
|
38
|
+
"@markuplint/ml-ast": "5.1.1",
|
|
39
|
+
"@markuplint/ml-config": "5.1.1",
|
|
40
|
+
"@markuplint/ml-core": "5.1.1",
|
|
41
|
+
"@markuplint/ml-spec": "5.1.1",
|
|
42
|
+
"@markuplint/parser-utils": "5.1.1",
|
|
43
|
+
"@markuplint/pretenders": "5.1.1",
|
|
44
|
+
"@markuplint/selector": "5.1.1",
|
|
45
|
+
"@markuplint/shared": "5.1.1",
|
|
46
46
|
"cosmiconfig": "9.0.1",
|
|
47
47
|
"debug": "4.4.3",
|
|
48
48
|
"glob": "13.0.6",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"jsonc": "2.0.0",
|
|
52
52
|
"minimatch": "10.2.5"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "a940c8526e971d590d97395ce924910221208820"
|
|
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
|
-
}
|