@markuplint/file-resolver 3.0.0-alpha.66 → 3.0.0-dev.176
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/README.md +8 -3
- package/lib/auto-load-rules.d.ts +2 -2
- package/lib/auto-load-rules.js +2 -2
- package/lib/config-provider.d.ts +10 -9
- package/lib/config-provider.js +83 -78
- package/lib/cosmiconfig.d.ts +13 -7
- package/lib/cosmiconfig.js +2 -0
- package/lib/ml-file/get-files.js +2 -10
- package/lib/ml-file/ml-file.d.ts +20 -20
- package/lib/ml-file/ml-file.js +32 -31
- package/lib/resolve-files.d.ts +1 -1
- package/lib/resolve-parser.d.ts +11 -7
- package/lib/resolve-parser.js +10 -8
- package/lib/resolve-plugins.d.ts +1 -1
- package/lib/resolve-plugins.js +9 -5
- package/lib/resolve-rules.d.ts +9 -6
- package/lib/resolve-rules.js +1 -1
- package/lib/resolve-specs.d.ts +5 -2
- package/lib/resolve-specs.js +6 -8
- package/lib/types.d.ts +20 -19
- package/lib/utils.d.ts +1 -3
- package/lib/utils.js +4 -8
- package/package.json +19 -13
- package/__mocks__/markuplint-angular-parser.js +0 -3
- package/__mocks__/markuplint-rule-fake.js +0 -1
- package/__mocks__/packaged-config.js +0 -3
- package/test/fixtures/001/package.json +0 -15
- package/test/fixtures/001/target.html +0 -0
- package/test/fixtures/002/.markuplintrc.json +0 -52
- package/test/fixtures/002/target.html +0 -0
- package/test/fixtures/003/.markuplintrc +0 -50
- package/test/fixtures/003/dir/target.html +0 -0
- package/test/fixtures/004/.markuplintrc +0 -4
- package/test/fixtures/004/dir/.markuplintrc +0 -4
- package/test/fixtures/004/dir/dir/.markuplintrc +0 -4
- package/test/fixtures/004/dir/dir/dir/.markuplintrc +0 -4
- package/test/fixtures/004/dir/dir/dir/dir/.markuplintrc +0 -4
- package/test/fixtures/004/dir/dir/dir/dir/dir/.markuplintrc +0 -4
- package/test/fixtures/004/dir/dir/dir/dir/dir/deep-target.html +0 -0
- package/test/fixtures/005/.markuplintrc +0 -4
- package/test/fixtures/005/target.html +0 -0
- package/test/fixtures/006/.markuplintrc +0 -12
- package/test/fixtures/006/target.html +0 -0
- package/test/plugins/001.js +0 -27
- package/test/plugins/002.js +0 -9
- package/tsconfig.test.json +0 -3
- package/tsconfig.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
# @markuplint/file-resolver
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@markuplint/file-resolver)
|
|
4
|
-
[](https://travis-ci.org/markuplint/markuplint)
|
|
5
|
-
[](https://coveralls.io/github/markuplint/markuplint?branch=main)
|
|
6
4
|
|
|
7
5
|
## Install
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
[`markuplint`](https://www.npmjs.com/package/markuplint) package includes this package.
|
|
8
|
+
|
|
9
|
+
<details>
|
|
10
|
+
<summary>If you are installing purposely, how below:</summary>
|
|
11
|
+
|
|
12
|
+
```shell
|
|
10
13
|
$ npm install @markuplint/file-resolver
|
|
11
14
|
|
|
12
15
|
$ yarn add @markuplint/file-resolver
|
|
13
16
|
```
|
|
17
|
+
|
|
18
|
+
</details>
|
package/lib/auto-load-rules.d.ts
CHANGED
package/lib/auto-load-rules.js
CHANGED
|
@@ -40,7 +40,7 @@ async function autoLoadRules(ruleset) {
|
|
|
40
40
|
}
|
|
41
41
|
let seed = null;
|
|
42
42
|
try {
|
|
43
|
-
const _module = await Promise.resolve().then(
|
|
43
|
+
const _module = await Promise.resolve(`${`@markuplint/rule-${ruleName}`}`).then(s => __importStar(require(s)));
|
|
44
44
|
seed = _module.default;
|
|
45
45
|
if (!(seed && 'defaultValue' in seed && 'defaultOptions' in seed && 'verify' in seed)) {
|
|
46
46
|
seed = null;
|
|
@@ -59,7 +59,7 @@ async function autoLoadRules(ruleset) {
|
|
|
59
59
|
continue;
|
|
60
60
|
}
|
|
61
61
|
try {
|
|
62
|
-
const _module = await Promise.resolve().then(
|
|
62
|
+
const _module = await Promise.resolve(`${`markuplint-rule-${ruleName}`}`).then(s => __importStar(require(s)));
|
|
63
63
|
seed = _module.default;
|
|
64
64
|
if (!(seed && 'defaultValue' in seed && 'defaultOptions' in seed && 'verify' in seed)) {
|
|
65
65
|
seed = null;
|
package/lib/config-provider.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
#private;
|
|
7
|
+
resolve(targetFile: Readonly<MLFile>, names: readonly Nullable<string>[], cache?: boolean): Promise<ConfigSet>;
|
|
8
|
+
search(targetFile: Readonly<MLFile>): Promise<string | null>;
|
|
9
|
+
set(config: Config, key?: string): string;
|
|
10
|
+
private _load;
|
|
11
|
+
private _mergeConfigs;
|
|
12
|
+
private _pathResolve;
|
|
13
|
+
private _recursiveLoad;
|
|
13
14
|
}
|
package/lib/config-provider.js
CHANGED
|
@@ -1,48 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
2
|
+
var _ConfigProvider_cache, _ConfigProvider_held, _ConfigProvider_recursiveLoadKeyAndDepth, _ConfigProvider_store;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.ConfigProvider = void 0;
|
|
5
5
|
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");
|
|
12
13
|
const KEY_SEPARATOR = '__ML_CONFIG_MERGE__';
|
|
13
14
|
class ConfigProvider {
|
|
14
15
|
constructor() {
|
|
15
|
-
_ConfigProvider_store.set(this, new Map());
|
|
16
16
|
_ConfigProvider_cache.set(this, new Map());
|
|
17
17
|
_ConfigProvider_held.set(this, new Set());
|
|
18
18
|
_ConfigProvider_recursiveLoadKeyAndDepth.set(this, new Map());
|
|
19
|
-
|
|
20
|
-
set(config, key) {
|
|
21
|
-
key = key || (0, utils_1.uuid)();
|
|
22
|
-
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").set(key, config);
|
|
23
|
-
return key;
|
|
24
|
-
}
|
|
25
|
-
async search(targetFile) {
|
|
26
|
-
if (!(await targetFile.dirExists())) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
const res = await (0, cosmiconfig_1.search)(targetFile.path, false);
|
|
30
|
-
if (!res) {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
const { filePath, config } = res;
|
|
34
|
-
const pathResolvedConfig = this._pathResolve(config, filePath);
|
|
35
|
-
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").set(filePath, pathResolvedConfig);
|
|
36
|
-
return filePath;
|
|
19
|
+
_ConfigProvider_store.set(this, new Map());
|
|
37
20
|
}
|
|
38
21
|
async resolve(targetFile, names, cache = true) {
|
|
39
|
-
var _a;
|
|
22
|
+
var _a, _b;
|
|
40
23
|
if (!cache) {
|
|
41
24
|
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").clear();
|
|
42
25
|
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_cache, "f").clear();
|
|
43
26
|
(0, resolve_plugins_1.cacheClear)();
|
|
44
27
|
}
|
|
45
|
-
const keys = names.filter(
|
|
28
|
+
const keys = names.filter(shared_1.nonNullableFilter);
|
|
46
29
|
const key = keys.join(KEY_SEPARATOR);
|
|
47
30
|
const currentConfig = tslib_1.__classPrivateFieldGet(this, _ConfigProvider_cache, "f").get(key);
|
|
48
31
|
if (currentConfig) {
|
|
@@ -50,21 +33,14 @@ class ConfigProvider {
|
|
|
50
33
|
}
|
|
51
34
|
let configSet = await this._mergeConfigs(keys, cache);
|
|
52
35
|
const plugins = await (0, resolve_plugins_1.resolvePlugins)(configSet.config.plugins);
|
|
53
|
-
if (tslib_1.__classPrivateFieldGet(this, _ConfigProvider_held, "f").size) {
|
|
36
|
+
if (tslib_1.__classPrivateFieldGet(this, _ConfigProvider_held, "f").size > 0) {
|
|
54
37
|
const extendHelds = Array.from(tslib_1.__classPrivateFieldGet(this, _ConfigProvider_held, "f").values());
|
|
55
38
|
for (const held of extendHelds) {
|
|
56
|
-
const [, prefix, namespace, name] = held.match(/^([a-z]+:)([^/]+)(?:\/(.+))?$/)
|
|
39
|
+
const [, prefix, namespace, name] = (_a = held.match(/^([a-z]+:)([^/]+)(?:\/(.+))?$/)) !== null && _a !== void 0 ? _a : [];
|
|
57
40
|
switch (prefix) {
|
|
58
41
|
case 'plugin:': {
|
|
59
42
|
const plugin = plugins.find(plugin => plugin.name === namespace);
|
|
60
|
-
const config = (
|
|
61
|
-
if (config) {
|
|
62
|
-
this.set(config, held);
|
|
63
|
-
}
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
case 'markuplint:': {
|
|
67
|
-
const config = await (0, ml_core_1.getPreset)(namespace);
|
|
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 : ''];
|
|
68
44
|
if (config) {
|
|
69
45
|
this.set(config, held);
|
|
70
46
|
}
|
|
@@ -81,9 +57,10 @@ class ConfigProvider {
|
|
|
81
57
|
const globs = Object.keys(overrides);
|
|
82
58
|
for (const glob of globs) {
|
|
83
59
|
const isMatched = targetFile.matches(glob);
|
|
84
|
-
|
|
60
|
+
const config = overrides[glob];
|
|
61
|
+
if (isMatched && config) {
|
|
85
62
|
// Note: Original config disappears
|
|
86
|
-
configSet.config =
|
|
63
|
+
configSet.config = config;
|
|
87
64
|
}
|
|
88
65
|
}
|
|
89
66
|
}
|
|
@@ -94,6 +71,52 @@ class ConfigProvider {
|
|
|
94
71
|
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_cache, "f").set(key, result);
|
|
95
72
|
return result;
|
|
96
73
|
}
|
|
74
|
+
async search(targetFile) {
|
|
75
|
+
if (!(await targetFile.dirExists())) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
const res = await (0, cosmiconfig_1.search)(targetFile.path, false);
|
|
79
|
+
if (!res) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
const { filePath, config } = res;
|
|
83
|
+
const pathResolvedConfig = this._pathResolve(config, filePath);
|
|
84
|
+
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").set(filePath, pathResolvedConfig);
|
|
85
|
+
return filePath;
|
|
86
|
+
}
|
|
87
|
+
set(config, key) {
|
|
88
|
+
key = key !== null && key !== void 0 ? key : (0, utils_1.uuid)();
|
|
89
|
+
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").set(key, config);
|
|
90
|
+
return key;
|
|
91
|
+
}
|
|
92
|
+
async _load(filePath, cache) {
|
|
93
|
+
var _a;
|
|
94
|
+
const entity = tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").get(filePath);
|
|
95
|
+
if (entity) {
|
|
96
|
+
return entity;
|
|
97
|
+
}
|
|
98
|
+
if (isPreset(filePath)) {
|
|
99
|
+
const [, name] = (_a = filePath.match(/^markuplint:(.+)$/i)) !== null && _a !== void 0 ? _a : [];
|
|
100
|
+
const config = await (0, ml_core_1.getPreset)(name !== null && name !== void 0 ? name : filePath);
|
|
101
|
+
const pathResolvedConfig = this._pathResolve(config, filePath);
|
|
102
|
+
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").set(filePath, pathResolvedConfig);
|
|
103
|
+
return pathResolvedConfig;
|
|
104
|
+
}
|
|
105
|
+
if (isPlugin(filePath)) {
|
|
106
|
+
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_held, "f").add(filePath);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
if (!moduleExists(filePath) && !path_1.default.isAbsolute(filePath)) {
|
|
110
|
+
throw new TypeError(`${filePath} is not an absolute path`);
|
|
111
|
+
}
|
|
112
|
+
const config = await load(filePath, cache);
|
|
113
|
+
if (!config) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
const pathResolvedConfig = this._pathResolve(config, filePath);
|
|
117
|
+
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").set(filePath, pathResolvedConfig);
|
|
118
|
+
return pathResolvedConfig;
|
|
119
|
+
}
|
|
97
120
|
async _mergeConfigs(keys, cache) {
|
|
98
121
|
const resolvedKeys = new Set();
|
|
99
122
|
const errs = [];
|
|
@@ -109,7 +132,7 @@ class ConfigProvider {
|
|
|
109
132
|
}
|
|
110
133
|
const configs = Array.from(resolvedKeys)
|
|
111
134
|
.map(name => tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").get(name))
|
|
112
|
-
.filter(
|
|
135
|
+
.filter(shared_1.nonNullableFilter);
|
|
113
136
|
let resultConfig = {};
|
|
114
137
|
for (const config of configs) {
|
|
115
138
|
resultConfig = (0, ml_config_1.mergeConfig)(resultConfig, config);
|
|
@@ -120,7 +143,20 @@ class ConfigProvider {
|
|
|
120
143
|
errs,
|
|
121
144
|
};
|
|
122
145
|
}
|
|
146
|
+
_pathResolve(config, filePath) {
|
|
147
|
+
const dir = path_1.default.dirname(filePath);
|
|
148
|
+
return {
|
|
149
|
+
...config,
|
|
150
|
+
extends: pathResolve(dir, config.extends),
|
|
151
|
+
plugins: pathResolve(dir, config.plugins, ['name']),
|
|
152
|
+
parser: pathResolve(dir, config.parser),
|
|
153
|
+
specs: pathResolve(dir, config.specs),
|
|
154
|
+
excludeFiles: pathResolve(dir, config.excludeFiles),
|
|
155
|
+
overrides: pathResolve(dir, config.overrides, undefined, true),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
123
158
|
async _recursiveLoad(key, cache, depth = 1) {
|
|
159
|
+
var _a;
|
|
124
160
|
const stack = new Set();
|
|
125
161
|
const errs = [];
|
|
126
162
|
const ancestorDepth = tslib_1.__classPrivateFieldGet(this, _ConfigProvider_recursiveLoadKeyAndDepth, "f").get(key);
|
|
@@ -131,14 +167,14 @@ class ConfigProvider {
|
|
|
131
167
|
};
|
|
132
168
|
}
|
|
133
169
|
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_recursiveLoadKeyAndDepth, "f").set(key, depth);
|
|
134
|
-
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;
|
|
135
171
|
if (!config) {
|
|
136
172
|
config = await this._load(key, cache);
|
|
137
173
|
}
|
|
138
174
|
if (!config) {
|
|
139
175
|
return { stack, errs: null };
|
|
140
176
|
}
|
|
141
|
-
const depKeys = config.extends ? (
|
|
177
|
+
const depKeys = config.extends !== null ? (0, shared_1.toNoEmptyStringArrayFromStringOrArray)(config.extends) : null;
|
|
142
178
|
if (depKeys) {
|
|
143
179
|
for (const depKey of depKeys) {
|
|
144
180
|
const keys = await this._recursiveLoad(depKey, cache, depth + 1);
|
|
@@ -153,45 +189,14 @@ class ConfigProvider {
|
|
|
153
189
|
stack.add(key);
|
|
154
190
|
return { stack, errs };
|
|
155
191
|
}
|
|
156
|
-
async _load(filePath, cache) {
|
|
157
|
-
const entity = tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").get(filePath);
|
|
158
|
-
if (entity) {
|
|
159
|
-
return entity;
|
|
160
|
-
}
|
|
161
|
-
if (isPrefixedName(filePath)) {
|
|
162
|
-
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_held, "f").add(filePath);
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
if (!moduleExists(filePath) && !path_1.default.isAbsolute(filePath)) {
|
|
166
|
-
throw new TypeError(`${filePath} is not an absolute path`);
|
|
167
|
-
}
|
|
168
|
-
const config = await load(filePath, cache);
|
|
169
|
-
if (!config) {
|
|
170
|
-
return null;
|
|
171
|
-
}
|
|
172
|
-
const pathResolvedConfig = this._pathResolve(config, filePath);
|
|
173
|
-
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").set(filePath, pathResolvedConfig);
|
|
174
|
-
return pathResolvedConfig;
|
|
175
|
-
}
|
|
176
|
-
_pathResolve(config, filePath) {
|
|
177
|
-
const dir = path_1.default.dirname(filePath);
|
|
178
|
-
return {
|
|
179
|
-
...config,
|
|
180
|
-
extends: pathResolve(dir, config.extends),
|
|
181
|
-
plugins: pathResolve(dir, config.plugins, ['name']),
|
|
182
|
-
parser: pathResolve(dir, config.parser),
|
|
183
|
-
specs: pathResolve(dir, config.specs),
|
|
184
|
-
excludeFiles: pathResolve(dir, config.excludeFiles),
|
|
185
|
-
overrides: pathResolve(dir, config.overrides, undefined, true),
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
192
|
}
|
|
189
193
|
exports.ConfigProvider = ConfigProvider;
|
|
190
|
-
|
|
194
|
+
_ConfigProvider_cache = new WeakMap(), _ConfigProvider_held = new WeakMap(), _ConfigProvider_recursiveLoadKeyAndDepth = new WeakMap(), _ConfigProvider_store = new WeakMap();
|
|
191
195
|
async function load(filePath, cache) {
|
|
196
|
+
var _a;
|
|
192
197
|
if (!(0, utils_1.fileExists)(filePath) && moduleExists(filePath)) {
|
|
193
|
-
const mod = await Promise.resolve().then(
|
|
194
|
-
const config = (mod === null || mod === void 0 ? void 0 : mod.default)
|
|
198
|
+
const mod = await Promise.resolve(`${filePath}`).then(s => tslib_1.__importStar(require(s)));
|
|
199
|
+
const config = (_a = mod === null || mod === void 0 ? void 0 : mod.default) !== null && _a !== void 0 ? _a : null;
|
|
195
200
|
return config;
|
|
196
201
|
}
|
|
197
202
|
const res = await (0, cosmiconfig_1.load)(filePath, !cache);
|
|
@@ -238,10 +243,7 @@ function pathResolve(dir, filePath, resolveProps, resolveKey = false) {
|
|
|
238
243
|
return res;
|
|
239
244
|
}
|
|
240
245
|
function resolve(dir, pathOrModName) {
|
|
241
|
-
if (
|
|
242
|
-
return pathOrModName;
|
|
243
|
-
}
|
|
244
|
-
if (moduleExists(pathOrModName)) {
|
|
246
|
+
if (moduleExists(pathOrModName) || isPreset(pathOrModName) || isPlugin(pathOrModName)) {
|
|
245
247
|
return pathOrModName;
|
|
246
248
|
}
|
|
247
249
|
return path_1.default.resolve(dir, pathOrModName);
|
|
@@ -262,8 +264,11 @@ function moduleExists(name) {
|
|
|
262
264
|
}
|
|
263
265
|
return true;
|
|
264
266
|
}
|
|
265
|
-
function
|
|
266
|
-
return /^
|
|
267
|
+
function isPreset(name) {
|
|
268
|
+
return /^markuplint:/i.test(name);
|
|
269
|
+
}
|
|
270
|
+
function isPlugin(name) {
|
|
271
|
+
return /^plugin:/i.test(name);
|
|
267
272
|
}
|
|
268
273
|
class CircularReferenceError extends ReferenceError {
|
|
269
274
|
constructor() {
|
package/lib/cosmiconfig.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { LoaderSync } from 'cosmiconfig';
|
|
2
|
-
|
|
3
|
-
export declare function search<T = CosmiConfig>(
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
type CosmiConfig = ReturnType<LoaderSync>;
|
|
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/cosmiconfig.js
CHANGED
|
@@ -4,9 +4,11 @@ exports.load = exports.search = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
6
6
|
const cosmiconfig_1 = require("cosmiconfig");
|
|
7
|
+
const cosmiconfig_typescript_loader_1 = require("cosmiconfig-typescript-loader");
|
|
7
8
|
const jsonc_1 = require("jsonc");
|
|
8
9
|
const explorer = (0, cosmiconfig_1.cosmiconfig)('markuplint', {
|
|
9
10
|
loaders: {
|
|
11
|
+
'.ts': (0, cosmiconfig_typescript_loader_1.TypeScriptLoader)(),
|
|
10
12
|
noExt: ((path, content) => {
|
|
11
13
|
try {
|
|
12
14
|
return jsonc_1.jsonc.parse(content);
|
package/lib/ml-file/get-files.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getFiles = void 0;
|
|
4
|
-
const
|
|
5
|
-
const glob_1 = tslib_1.__importDefault(require("glob"));
|
|
4
|
+
const glob_1 = require("glob");
|
|
6
5
|
const get_file_1 = require("./get-file");
|
|
7
6
|
/**
|
|
8
7
|
* Get files
|
|
@@ -12,14 +11,7 @@ const get_file_1 = require("./get-file");
|
|
|
12
11
|
* @param filePathOrGlob
|
|
13
12
|
*/
|
|
14
13
|
async function getFiles(filePathOrGlob) {
|
|
15
|
-
const fileList = await
|
|
16
|
-
(0, glob_1.default)(filePathOrGlob, {}, (err, matches) => {
|
|
17
|
-
if (err) {
|
|
18
|
-
reject(err);
|
|
19
|
-
}
|
|
20
|
-
resolve(matches);
|
|
21
|
-
});
|
|
22
|
-
}).catch(() => []);
|
|
14
|
+
const fileList = await (0, glob_1.glob)(filePathOrGlob, {}).catch(() => []);
|
|
23
15
|
return fileList.map(fileName => (0, get_file_1.getFile)(fileName));
|
|
24
16
|
}
|
|
25
17
|
exports.getFiles = getFiles;
|
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
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
2
|
+
var _MLFile_basename, _MLFile_code, _MLFile_dirname, _MLFile_stat, _MLFile_type;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.MLFile = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const fs_1 = require("fs");
|
|
7
7
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
8
|
-
const minimatch_1 =
|
|
8
|
+
const minimatch_1 = require("minimatch");
|
|
9
9
|
class MLFile {
|
|
10
10
|
constructor(target) {
|
|
11
|
-
|
|
11
|
+
var _a, _b;
|
|
12
12
|
_MLFile_basename.set(this, void 0);
|
|
13
|
-
_MLFile_dirname.set(this, void 0);
|
|
14
13
|
_MLFile_code.set(this, void 0);
|
|
14
|
+
_MLFile_dirname.set(this, void 0);
|
|
15
15
|
/**
|
|
16
16
|
* - `Stats`: Exists
|
|
17
17
|
* - `null`: Not exists
|
|
18
18
|
* - `undefined`: Doesn't read yet
|
|
19
19
|
*/
|
|
20
20
|
_MLFile_stat.set(this, undefined);
|
|
21
|
+
_MLFile_type.set(this, void 0);
|
|
21
22
|
if (typeof target === 'string') {
|
|
22
23
|
tslib_1.__classPrivateFieldSet(this, _MLFile_basename, path_1.default.basename(target), "f");
|
|
23
24
|
tslib_1.__classPrivateFieldSet(this, _MLFile_dirname, path_1.default.dirname(target), "f");
|
|
@@ -30,21 +31,12 @@ 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");
|
|
38
39
|
}
|
|
39
|
-
get path() {
|
|
40
|
-
return path_1.default.resolve(tslib_1.__classPrivateFieldGet(this, _MLFile_dirname, "f"), tslib_1.__classPrivateFieldGet(this, _MLFile_basename, "f"));
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Normalized `MLFile.path`
|
|
44
|
-
*/
|
|
45
|
-
get nPath() {
|
|
46
|
-
return pathNormalize(this.path);
|
|
47
|
-
}
|
|
48
40
|
get dirname() {
|
|
49
41
|
return tslib_1.__classPrivateFieldGet(this, _MLFile_dirname, "f");
|
|
50
42
|
}
|
|
@@ -54,19 +46,14 @@ class MLFile {
|
|
|
54
46
|
get nDirname() {
|
|
55
47
|
return pathNormalize(this.dirname);
|
|
56
48
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return !!stat && stat.isFile();
|
|
49
|
+
/**
|
|
50
|
+
* Normalized `MLFile.path`
|
|
51
|
+
*/
|
|
52
|
+
get nPath() {
|
|
53
|
+
return pathNormalize(this.path);
|
|
63
54
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
const stat = await this._stat();
|
|
69
|
-
return !!stat;
|
|
55
|
+
get path() {
|
|
56
|
+
return path_1.default.resolve(tslib_1.__classPrivateFieldGet(this, _MLFile_dirname, "f"), tslib_1.__classPrivateFieldGet(this, _MLFile_basename, "f"));
|
|
70
57
|
}
|
|
71
58
|
async dirExists() {
|
|
72
59
|
return !!(await stat(tslib_1.__classPrivateFieldGet(this, _MLFile_dirname, "f")));
|
|
@@ -80,15 +67,29 @@ class MLFile {
|
|
|
80
67
|
}
|
|
81
68
|
return '';
|
|
82
69
|
}
|
|
70
|
+
async isExist() {
|
|
71
|
+
if (tslib_1.__classPrivateFieldGet(this, _MLFile_type, "f") === 'code-base') {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
const stat = await this._stat();
|
|
75
|
+
return !!stat;
|
|
76
|
+
}
|
|
77
|
+
async isFile() {
|
|
78
|
+
if (tslib_1.__classPrivateFieldGet(this, _MLFile_type, "f") === 'code-base') {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
const stat = await this._stat();
|
|
82
|
+
return !!stat && stat.isFile();
|
|
83
|
+
}
|
|
84
|
+
matches(globPath) {
|
|
85
|
+
return (0, minimatch_1.minimatch)(this.nPath, pathNormalize(globPath));
|
|
86
|
+
}
|
|
83
87
|
setCode(code) {
|
|
84
88
|
if (tslib_1.__classPrivateFieldGet(this, _MLFile_type, "f") === 'file-base') {
|
|
85
89
|
throw new Error(`This file object is readonly (File-base: ${this.path})`);
|
|
86
90
|
}
|
|
87
91
|
tslib_1.__classPrivateFieldSet(this, _MLFile_code, code, "f");
|
|
88
92
|
}
|
|
89
|
-
matches(globPath) {
|
|
90
|
-
return (0, minimatch_1.default)(this.nPath, pathNormalize(globPath));
|
|
91
|
-
}
|
|
92
93
|
async _fetch() {
|
|
93
94
|
const code = await fs_1.promises.readFile(this.path, { encoding: 'utf-8' });
|
|
94
95
|
tslib_1.__classPrivateFieldSet(this, _MLFile_code, code, "f");
|
|
@@ -103,7 +104,7 @@ class MLFile {
|
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
exports.MLFile = MLFile;
|
|
106
|
-
|
|
107
|
+
_MLFile_basename = new WeakMap(), _MLFile_code = new WeakMap(), _MLFile_dirname = new WeakMap(), _MLFile_stat = new WeakMap(), _MLFile_type = new WeakMap();
|
|
107
108
|
async function stat(filePath) {
|
|
108
109
|
try {
|
|
109
110
|
return await fs_1.promises.stat(filePath);
|
package/lib/resolve-files.d.ts
CHANGED
package/lib/resolve-parser.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { MLFile } from './ml-file';
|
|
2
|
-
import type { MLMarkupLanguageParser } from '@markuplint/ml-ast';
|
|
3
|
-
import type { ParserConfig
|
|
4
|
-
export declare function resolveParser(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import type { MLMarkupLanguageParser, ParserOptions } from '@markuplint/ml-ast';
|
|
3
|
+
import type { ParserConfig } from '@markuplint/ml-config';
|
|
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,16 +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
|
-
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;
|
|
22
21
|
}
|
|
22
|
+
parserModName = modName;
|
|
23
|
+
matched = true;
|
|
24
|
+
break;
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
const parser = await importParser(parserModName);
|
|
@@ -36,6 +38,6 @@ async function importParser(parserModName) {
|
|
|
36
38
|
if (entity) {
|
|
37
39
|
return entity;
|
|
38
40
|
}
|
|
39
|
-
const parser = await Promise.resolve().then(
|
|
41
|
+
const parser = await Promise.resolve(`${parserModName}`).then(s => tslib_1.__importStar(require(s)));
|
|
40
42
|
return parser;
|
|
41
43
|
}
|
package/lib/resolve-plugins.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { PluginConfig } from '@markuplint/ml-config';
|
|
2
2
|
import type { Plugin } from '@markuplint/ml-core';
|
|
3
|
-
export declare function resolvePlugins(pluginPaths?: (string | PluginConfig)[]): Promise<Plugin[]>;
|
|
3
|
+
export declare function resolvePlugins(pluginPaths?: readonly (string | PluginConfig)[]): Promise<Plugin[]>;
|
|
4
4
|
export declare function cacheClear(): void;
|