@markuplint/file-resolver 3.5.0 → 3.6.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/lib/auto-load-rules.d.ts +2 -2
- package/lib/config-provider.d.ts +2 -1
- package/lib/config-provider.js +15 -11
- package/lib/cosmiconfig.d.ts +12 -6
- package/lib/ml-file/ml-file.d.ts +20 -20
- package/lib/ml-file/ml-file.js +3 -2
- package/lib/resolve-parser.d.ts +9 -5
- package/lib/resolve-parser.js +9 -11
- package/lib/resolve-rules.d.ts +9 -5
- package/lib/resolve-specs.d.ts +5 -2
- package/lib/types.d.ts +0 -1
- package/lib/utils.d.ts +0 -2
- package/lib/utils.js +1 -5
- package/package.json +7 -6
package/lib/auto-load-rules.d.ts
CHANGED
package/lib/config-provider.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { MLFile } from './ml-file';
|
|
2
|
-
import type { ConfigSet
|
|
2
|
+
import type { ConfigSet } from './types';
|
|
3
3
|
import type { Config } from '@markuplint/ml-config';
|
|
4
|
+
import type { Nullable } from '@markuplint/shared';
|
|
4
5
|
export declare class ConfigProvider {
|
|
5
6
|
#private;
|
|
6
7
|
resolve(targetFile: Readonly<MLFile>, names: readonly Nullable<string>[], cache?: boolean): Promise<ConfigSet>;
|
package/lib/config-provider.js
CHANGED
|
@@ -6,6 +6,7 @@ const tslib_1 = require("tslib");
|
|
|
6
6
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
7
|
const ml_config_1 = require("@markuplint/ml-config");
|
|
8
8
|
const ml_core_1 = require("@markuplint/ml-core");
|
|
9
|
+
const shared_1 = require("@markuplint/shared");
|
|
9
10
|
const cosmiconfig_1 = require("./cosmiconfig");
|
|
10
11
|
const resolve_plugins_1 = require("./resolve-plugins");
|
|
11
12
|
const utils_1 = require("./utils");
|
|
@@ -18,13 +19,13 @@ class ConfigProvider {
|
|
|
18
19
|
_ConfigProvider_store.set(this, new Map());
|
|
19
20
|
}
|
|
20
21
|
async resolve(targetFile, names, cache = true) {
|
|
21
|
-
var _a;
|
|
22
|
+
var _a, _b;
|
|
22
23
|
if (!cache) {
|
|
23
24
|
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").clear();
|
|
24
25
|
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_cache, "f").clear();
|
|
25
26
|
(0, resolve_plugins_1.cacheClear)();
|
|
26
27
|
}
|
|
27
|
-
const keys = names.filter(
|
|
28
|
+
const keys = names.filter(shared_1.nonNullableFilter);
|
|
28
29
|
const key = keys.join(KEY_SEPARATOR);
|
|
29
30
|
const currentConfig = tslib_1.__classPrivateFieldGet(this, _ConfigProvider_cache, "f").get(key);
|
|
30
31
|
if (currentConfig) {
|
|
@@ -32,14 +33,14 @@ class ConfigProvider {
|
|
|
32
33
|
}
|
|
33
34
|
let configSet = await this._mergeConfigs(keys, cache);
|
|
34
35
|
const plugins = await (0, resolve_plugins_1.resolvePlugins)(configSet.config.plugins);
|
|
35
|
-
if (tslib_1.__classPrivateFieldGet(this, _ConfigProvider_held, "f").size) {
|
|
36
|
+
if (tslib_1.__classPrivateFieldGet(this, _ConfigProvider_held, "f").size > 0) {
|
|
36
37
|
const extendHelds = Array.from(tslib_1.__classPrivateFieldGet(this, _ConfigProvider_held, "f").values());
|
|
37
38
|
for (const held of extendHelds) {
|
|
38
|
-
const [, prefix, namespace, name] = held.match(/^([a-z]+:)([^/]+)(?:\/(.+))?$/)
|
|
39
|
+
const [, prefix, namespace, name] = (_a = held.match(/^([a-z]+:)([^/]+)(?:\/(.+))?$/)) !== null && _a !== void 0 ? _a : [];
|
|
39
40
|
switch (prefix) {
|
|
40
41
|
case 'plugin:': {
|
|
41
42
|
const plugin = plugins.find(plugin => plugin.name === namespace);
|
|
42
|
-
const config =
|
|
43
|
+
const config = (_b = plugin === null || plugin === void 0 ? void 0 : plugin.configs) === null || _b === void 0 ? void 0 : _b[name !== null && name !== void 0 ? name : ''];
|
|
43
44
|
if (config) {
|
|
44
45
|
this.set(config, held);
|
|
45
46
|
}
|
|
@@ -84,17 +85,18 @@ class ConfigProvider {
|
|
|
84
85
|
return filePath;
|
|
85
86
|
}
|
|
86
87
|
set(config, key) {
|
|
87
|
-
key = key
|
|
88
|
+
key = key !== null && key !== void 0 ? key : (0, utils_1.uuid)();
|
|
88
89
|
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").set(key, config);
|
|
89
90
|
return key;
|
|
90
91
|
}
|
|
91
92
|
async _load(filePath, cache) {
|
|
93
|
+
var _a;
|
|
92
94
|
const entity = tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").get(filePath);
|
|
93
95
|
if (entity) {
|
|
94
96
|
return entity;
|
|
95
97
|
}
|
|
96
98
|
if (isPreset(filePath)) {
|
|
97
|
-
const [, name] = filePath.match(/^markuplint:(.+)$/i)
|
|
99
|
+
const [, name] = (_a = filePath.match(/^markuplint:(.+)$/i)) !== null && _a !== void 0 ? _a : [];
|
|
98
100
|
const config = await (0, ml_core_1.getPreset)(name !== null && name !== void 0 ? name : filePath);
|
|
99
101
|
const pathResolvedConfig = this._pathResolve(config, filePath);
|
|
100
102
|
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").set(filePath, pathResolvedConfig);
|
|
@@ -130,7 +132,7 @@ class ConfigProvider {
|
|
|
130
132
|
}
|
|
131
133
|
const configs = Array.from(resolvedKeys)
|
|
132
134
|
.map(name => tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").get(name))
|
|
133
|
-
.filter(
|
|
135
|
+
.filter(shared_1.nonNullableFilter);
|
|
134
136
|
let resultConfig = {};
|
|
135
137
|
for (const config of configs) {
|
|
136
138
|
resultConfig = (0, ml_config_1.mergeConfig)(resultConfig, config);
|
|
@@ -154,6 +156,7 @@ class ConfigProvider {
|
|
|
154
156
|
};
|
|
155
157
|
}
|
|
156
158
|
async _recursiveLoad(key, cache, depth = 1) {
|
|
159
|
+
var _a;
|
|
157
160
|
const stack = new Set();
|
|
158
161
|
const errs = [];
|
|
159
162
|
const ancestorDepth = tslib_1.__classPrivateFieldGet(this, _ConfigProvider_recursiveLoadKeyAndDepth, "f").get(key);
|
|
@@ -164,14 +167,14 @@ class ConfigProvider {
|
|
|
164
167
|
};
|
|
165
168
|
}
|
|
166
169
|
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_recursiveLoadKeyAndDepth, "f").set(key, depth);
|
|
167
|
-
let config = tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").get(key)
|
|
170
|
+
let config = (_a = tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").get(key)) !== null && _a !== void 0 ? _a : null;
|
|
168
171
|
if (!config) {
|
|
169
172
|
config = await this._load(key, cache);
|
|
170
173
|
}
|
|
171
174
|
if (!config) {
|
|
172
175
|
return { stack, errs: null };
|
|
173
176
|
}
|
|
174
|
-
const depKeys = config.extends ? (
|
|
177
|
+
const depKeys = config.extends !== null ? (0, shared_1.toNoEmptyStringArrayFromStringOrArray)(config.extends) : null;
|
|
175
178
|
if (depKeys) {
|
|
176
179
|
for (const depKey of depKeys) {
|
|
177
180
|
const keys = await this._recursiveLoad(depKey, cache, depth + 1);
|
|
@@ -190,9 +193,10 @@ class ConfigProvider {
|
|
|
190
193
|
exports.ConfigProvider = ConfigProvider;
|
|
191
194
|
_ConfigProvider_cache = new WeakMap(), _ConfigProvider_held = new WeakMap(), _ConfigProvider_recursiveLoadKeyAndDepth = new WeakMap(), _ConfigProvider_store = new WeakMap();
|
|
192
195
|
async function load(filePath, cache) {
|
|
196
|
+
var _a;
|
|
193
197
|
if (!(0, utils_1.fileExists)(filePath) && moduleExists(filePath)) {
|
|
194
198
|
const mod = await Promise.resolve(`${filePath}`).then(s => tslib_1.__importStar(require(s)));
|
|
195
|
-
const config = (mod === null || mod === void 0 ? void 0 : mod.default)
|
|
199
|
+
const config = (_a = mod === null || mod === void 0 ? void 0 : mod.default) !== null && _a !== void 0 ? _a : null;
|
|
196
200
|
return config;
|
|
197
201
|
}
|
|
198
202
|
const res = await (0, cosmiconfig_1.load)(filePath, !cache);
|
package/lib/cosmiconfig.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { LoaderSync } from 'cosmiconfig';
|
|
2
2
|
type CosmiConfig = ReturnType<LoaderSync>;
|
|
3
|
-
export declare function search<T = CosmiConfig>(
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export declare function search<T = CosmiConfig>(
|
|
4
|
+
dir: string,
|
|
5
|
+
cacheClear: boolean,
|
|
6
|
+
): Promise<{
|
|
7
|
+
filePath: string;
|
|
8
|
+
config: T;
|
|
6
9
|
} | null>;
|
|
7
|
-
export declare function load<T = CosmiConfig>(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
export declare function load<T = CosmiConfig>(
|
|
11
|
+
filePath: string,
|
|
12
|
+
cacheClear: boolean,
|
|
13
|
+
): Promise<{
|
|
14
|
+
filePath: string;
|
|
15
|
+
config: T;
|
|
10
16
|
} | null>;
|
|
11
17
|
export {};
|
package/lib/ml-file/ml-file.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import type { Target } from '../types';
|
|
2
2
|
export declare class MLFile {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
3
|
+
#private;
|
|
4
|
+
constructor(target: Target);
|
|
5
|
+
get dirname(): string;
|
|
6
|
+
/**
|
|
7
|
+
* Normalized `MLFile.dirname`
|
|
8
|
+
*/
|
|
9
|
+
get nDirname(): string;
|
|
10
|
+
/**
|
|
11
|
+
* Normalized `MLFile.path`
|
|
12
|
+
*/
|
|
13
|
+
get nPath(): string;
|
|
14
|
+
get path(): string;
|
|
15
|
+
dirExists(): Promise<boolean>;
|
|
16
|
+
getCode(): Promise<string>;
|
|
17
|
+
isExist(): Promise<boolean>;
|
|
18
|
+
isFile(): Promise<boolean>;
|
|
19
|
+
matches(globPath: string): boolean;
|
|
20
|
+
setCode(code: string): void;
|
|
21
|
+
private _fetch;
|
|
22
|
+
private _stat;
|
|
23
23
|
}
|
package/lib/ml-file/ml-file.js
CHANGED
|
@@ -8,6 +8,7 @@ const path_1 = tslib_1.__importDefault(require("path"));
|
|
|
8
8
|
const minimatch_1 = tslib_1.__importDefault(require("minimatch"));
|
|
9
9
|
class MLFile {
|
|
10
10
|
constructor(target) {
|
|
11
|
+
var _a, _b;
|
|
11
12
|
_MLFile_basename.set(this, void 0);
|
|
12
13
|
_MLFile_code.set(this, void 0);
|
|
13
14
|
_MLFile_dirname.set(this, void 0);
|
|
@@ -30,8 +31,8 @@ class MLFile {
|
|
|
30
31
|
tslib_1.__classPrivateFieldSet(this, _MLFile_dirname, path_1.default.dirname(target.name), "f");
|
|
31
32
|
}
|
|
32
33
|
else {
|
|
33
|
-
tslib_1.__classPrivateFieldSet(this, _MLFile_basename, target.name
|
|
34
|
-
tslib_1.__classPrivateFieldSet(this, _MLFile_dirname, target.workspace
|
|
34
|
+
tslib_1.__classPrivateFieldSet(this, _MLFile_basename, (_a = target.name) !== null && _a !== void 0 ? _a : '<AnonymousFile>', "f");
|
|
35
|
+
tslib_1.__classPrivateFieldSet(this, _MLFile_dirname, (_b = target.workspace) !== null && _b !== void 0 ? _b : process.cwd(), "f");
|
|
35
36
|
}
|
|
36
37
|
tslib_1.__classPrivateFieldSet(this, _MLFile_code, target.sourceCode, "f");
|
|
37
38
|
tslib_1.__classPrivateFieldSet(this, _MLFile_type, 'code-base', "f");
|
package/lib/resolve-parser.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { MLFile } from './ml-file';
|
|
2
2
|
import type { MLMarkupLanguageParser, ParserOptions } from '@markuplint/ml-ast';
|
|
3
3
|
import type { ParserConfig } from '@markuplint/ml-config';
|
|
4
|
-
export declare function resolveParser(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
export declare function resolveParser(
|
|
5
|
+
file: Readonly<MLFile>,
|
|
6
|
+
parserConfig?: ParserConfig,
|
|
7
|
+
parserOptions?: ParserOptions,
|
|
8
|
+
): Promise<{
|
|
9
|
+
parserModName: string;
|
|
10
|
+
parser: MLMarkupLanguageParser;
|
|
11
|
+
parserOptions: ParserOptions;
|
|
12
|
+
matched: boolean;
|
|
9
13
|
}>;
|
package/lib/resolve-parser.js
CHANGED
|
@@ -10,20 +10,18 @@ async function resolveParser(file, parserConfig, parserOptions) {
|
|
|
10
10
|
...parserConfig,
|
|
11
11
|
'/\\.html?$/i': '@markuplint/html-parser',
|
|
12
12
|
};
|
|
13
|
-
parserOptions = parserOptions
|
|
13
|
+
parserOptions = parserOptions !== null && parserOptions !== void 0 ? parserOptions : {};
|
|
14
14
|
let parserModName = '@markuplint/html-parser';
|
|
15
15
|
let matched = false;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
parserModName = modName;
|
|
24
|
-
matched = true;
|
|
25
|
-
break;
|
|
16
|
+
for (const pattern of Object.keys(parserConfig)) {
|
|
17
|
+
if (path_1.default.basename(file.path).match((0, utils_1.toRegexp)(pattern))) {
|
|
18
|
+
const modName = parserConfig[pattern];
|
|
19
|
+
if (!modName) {
|
|
20
|
+
continue;
|
|
26
21
|
}
|
|
22
|
+
parserModName = modName;
|
|
23
|
+
matched = true;
|
|
24
|
+
break;
|
|
27
25
|
}
|
|
28
26
|
}
|
|
29
27
|
const parser = await importParser(parserModName);
|
package/lib/resolve-rules.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { AnyMLRule, Ruleset, Plugin } from '@markuplint/ml-core';
|
|
2
|
-
export declare function resolveRules(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
export declare function resolveRules(
|
|
3
|
+
plugins: readonly Plugin[],
|
|
4
|
+
ruleset: Ruleset,
|
|
5
|
+
importPreset: boolean,
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated
|
|
8
|
+
*/
|
|
9
|
+
autoLoad: boolean,
|
|
10
|
+
): Promise<Readonly<AnyMLRule>[]>;
|
package/lib/resolve-specs.d.ts
CHANGED
|
@@ -30,6 +30,9 @@ import type { ExtendedSpec, MLMLSpec } from '@markuplint/ml-spec';
|
|
|
30
30
|
* @param specConfig The `spec` property part of the config
|
|
31
31
|
* @returns
|
|
32
32
|
*/
|
|
33
|
-
export declare function resolveSpecs(
|
|
34
|
-
|
|
33
|
+
export declare function resolveSpecs(
|
|
34
|
+
filePath: string,
|
|
35
|
+
specConfig?: SpecConfig,
|
|
36
|
+
): Promise<{
|
|
37
|
+
schemas: readonly [MLMLSpec, ...ExtendedSpec[]];
|
|
35
38
|
}>;
|
package/lib/types.d.ts
CHANGED
package/lib/utils.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { Nullable } from './types';
|
|
2
|
-
export declare function nonNullableFilter<T>(item: Nullable<T>): item is T;
|
|
3
1
|
export declare function uuid(): string;
|
|
4
2
|
export declare function fileExists(filePath: string): boolean;
|
|
5
3
|
export declare function toRegexp(pattern: string): string | RegExp;
|
package/lib/utils.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toRegexp = exports.fileExists = exports.uuid =
|
|
3
|
+
exports.toRegexp = exports.fileExists = exports.uuid = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
6
|
-
function nonNullableFilter(item) {
|
|
7
|
-
return !!item;
|
|
8
|
-
}
|
|
9
|
-
exports.nonNullableFilter = nonNullableFilter;
|
|
10
6
|
let uuidNum = 0;
|
|
11
7
|
function uuid() {
|
|
12
8
|
const out = `${uuidNum}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/file-resolver",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.1",
|
|
4
4
|
"description": "The file resolver of markuplint",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -24,16 +24,17 @@
|
|
|
24
24
|
"@types/node": "latest"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@markuplint/html-parser": "3.
|
|
27
|
+
"@markuplint/html-parser": "3.6.1",
|
|
28
28
|
"@markuplint/ml-ast": "3.1.0",
|
|
29
|
-
"@markuplint/ml-config": "3.
|
|
30
|
-
"@markuplint/ml-core": "3.
|
|
31
|
-
"@markuplint/ml-spec": "3.
|
|
29
|
+
"@markuplint/ml-config": "3.6.1",
|
|
30
|
+
"@markuplint/ml-core": "3.6.1",
|
|
31
|
+
"@markuplint/ml-spec": "3.6.1",
|
|
32
|
+
"@markuplint/shared": "3.5.0",
|
|
32
33
|
"cosmiconfig": "^8.0.0",
|
|
33
34
|
"glob": "^8.0.3",
|
|
34
35
|
"jsonc": "^2.0.0",
|
|
35
36
|
"minimatch": "^5.1.1",
|
|
36
37
|
"tslib": "^2.4.1"
|
|
37
38
|
},
|
|
38
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "3cdf5a088b2da03773d5d4461d0e65ec32290a00"
|
|
39
40
|
}
|