@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/lib/resolve-plugins.js
CHANGED
|
@@ -55,15 +55,19 @@ async function importPlugin(pluginPath) {
|
|
|
55
55
|
...pluginCreator.create(config.settings),
|
|
56
56
|
};
|
|
57
57
|
cache.set(plugin.name, plugin);
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
let name = plugin.name;
|
|
59
|
+
if (!name) {
|
|
60
|
+
name = config.name
|
|
60
61
|
.toLowerCase()
|
|
61
62
|
.replace(/^(?:markuplint-rule-|@markuplint\/rule-)/i, '')
|
|
62
63
|
.replace(/\s+|\/|\\|\./g, '-');
|
|
63
64
|
// eslint-disable-next-line no-console
|
|
64
|
-
console.info(`The plugin name became "${
|
|
65
|
+
console.info(`The plugin name became "${name}"`);
|
|
65
66
|
}
|
|
66
|
-
return
|
|
67
|
+
return {
|
|
68
|
+
...plugin,
|
|
69
|
+
name,
|
|
70
|
+
};
|
|
67
71
|
}
|
|
68
72
|
function getPluginConfig(pluginPath) {
|
|
69
73
|
if (typeof pluginPath === 'string') {
|
|
@@ -72,7 +76,7 @@ function getPluginConfig(pluginPath) {
|
|
|
72
76
|
return pluginPath;
|
|
73
77
|
}
|
|
74
78
|
async function failSafeImport(name) {
|
|
75
|
-
const res = await Promise.resolve().then(
|
|
79
|
+
const res = await Promise.resolve(`${name}`).then(s => __importStar(require(s))).catch(e => e);
|
|
76
80
|
if ('code' in res && res === 'MODULE_NOT_FOUND') {
|
|
77
81
|
return null;
|
|
78
82
|
}
|
package/lib/resolve-rules.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { AnyMLRule, Ruleset, Plugin } from '@markuplint/ml-core';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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-rules.js
CHANGED
|
@@ -60,7 +60,7 @@ async function importPresetRules() {
|
|
|
60
60
|
return cachedPresetRules.slice();
|
|
61
61
|
}
|
|
62
62
|
const modName = '@markuplint/rules';
|
|
63
|
-
const presetRules = (await Promise.resolve().then(
|
|
63
|
+
const presetRules = (await Promise.resolve(`${modName}`).then(s => __importStar(require(s)))).default;
|
|
64
64
|
const ruleList = Object.entries(presetRules).map(([name, seed]) => {
|
|
65
65
|
const rule = new ml_core_1.MLRule({
|
|
66
66
|
name,
|
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/resolve-specs.js
CHANGED
|
@@ -43,16 +43,13 @@ async function resolveSpecs(filePath, specConfig) {
|
|
|
43
43
|
const spec = await importSpecs(specConfig);
|
|
44
44
|
extendedSpecs.push(spec);
|
|
45
45
|
}
|
|
46
|
-
else if (Array.isArray(specConfig)) {
|
|
47
|
-
for (const specModName of specConfig) {
|
|
48
|
-
const spec = await importSpecs(specModName);
|
|
49
|
-
extendedSpecs.push(spec);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
46
|
else {
|
|
53
47
|
for (const pattern of Object.keys(specConfig)) {
|
|
54
|
-
if (path_1.default.basename(filePath).match((0, utils_1.
|
|
48
|
+
if (path_1.default.basename(filePath).match((0, utils_1.toRegexp)(pattern))) {
|
|
55
49
|
const specModName = specConfig[pattern];
|
|
50
|
+
if (!specModName) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
56
53
|
const spec = await importSpecs(specModName);
|
|
57
54
|
extendedSpecs.push(spec);
|
|
58
55
|
}
|
|
@@ -73,7 +70,8 @@ async function importSpecs(specModName) {
|
|
|
73
70
|
return spec;
|
|
74
71
|
}
|
|
75
72
|
}
|
|
76
|
-
const spec = (await Promise.resolve().then(
|
|
73
|
+
const spec = (await Promise.resolve(`${specModName}`).then(s => tslib_1.__importStar(require(s)))).default;
|
|
74
|
+
// @ts-ignore
|
|
77
75
|
caches.set(specModName, spec);
|
|
78
76
|
return spec;
|
|
79
77
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import type { Config } from '@markuplint/ml-config';
|
|
2
2
|
import type { Plugin } from '@markuplint/ml-core';
|
|
3
|
-
export declare type Nullable<T> = T | null | undefined;
|
|
4
3
|
export interface ConfigSet {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
readonly config: Config;
|
|
5
|
+
readonly plugins: readonly Plugin[];
|
|
6
|
+
readonly files: ReadonlySet<string>;
|
|
7
|
+
readonly errs: readonly Readonly<Error>[];
|
|
9
8
|
}
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
9
|
+
export type Target =
|
|
10
|
+
| string
|
|
11
|
+
| {
|
|
12
|
+
/**
|
|
13
|
+
* Target source code of evaluation
|
|
14
|
+
*/
|
|
15
|
+
readonly sourceCode: string;
|
|
16
|
+
/**
|
|
17
|
+
* File names when `sourceCodes`
|
|
18
|
+
*/
|
|
19
|
+
readonly name?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Workspace path when `sourceCodes`
|
|
22
|
+
*/
|
|
23
|
+
readonly workspace?: string;
|
|
24
|
+
};
|
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
|
-
export declare function
|
|
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.
|
|
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}`;
|
|
@@ -18,11 +14,11 @@ function fileExists(filePath) {
|
|
|
18
14
|
return fs_1.default.existsSync(filePath);
|
|
19
15
|
}
|
|
20
16
|
exports.fileExists = fileExists;
|
|
21
|
-
function
|
|
17
|
+
function toRegexp(pattern) {
|
|
22
18
|
const matched = pattern.match(/^\/(.+)\/([ig]*)$/i);
|
|
23
|
-
if (matched) {
|
|
19
|
+
if (matched && matched[1]) {
|
|
24
20
|
return new RegExp(matched[1], matched[2]);
|
|
25
21
|
}
|
|
26
22
|
return pattern;
|
|
27
23
|
}
|
|
28
|
-
exports.
|
|
24
|
+
exports.toRegexp = toRegexp;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/file-resolver",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-dev.176+f6ad62e9",
|
|
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>",
|
|
@@ -11,25 +11,31 @@
|
|
|
11
11
|
"publishConfig": {
|
|
12
12
|
"access": "public"
|
|
13
13
|
},
|
|
14
|
+
"typedoc": {
|
|
15
|
+
"entryPoint": "./src/index.ts"
|
|
16
|
+
},
|
|
14
17
|
"scripts": {
|
|
15
18
|
"build": "tsc",
|
|
16
19
|
"clean": "tsc --build --clean"
|
|
17
20
|
},
|
|
18
21
|
"devDependencies": {
|
|
19
|
-
"@types/
|
|
20
|
-
"@types/glob": "^7.2.0",
|
|
21
|
-
"@types/node": "^17.0.16"
|
|
22
|
+
"@types/node": "18.16.3"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"@markuplint/
|
|
25
|
-
"@markuplint/ml-
|
|
26
|
-
"@markuplint/ml-
|
|
27
|
-
"@markuplint/ml-
|
|
28
|
-
"
|
|
29
|
-
"
|
|
25
|
+
"@markuplint/html-parser": "3.0.0-dev.176+f6ad62e9",
|
|
26
|
+
"@markuplint/ml-ast": "3.0.0-dev.176+f6ad62e9",
|
|
27
|
+
"@markuplint/ml-config": "3.0.0-dev.176+f6ad62e9",
|
|
28
|
+
"@markuplint/ml-core": "3.0.0-dev.176+f6ad62e9",
|
|
29
|
+
"@markuplint/ml-spec": "3.0.0-dev.176+f6ad62e9",
|
|
30
|
+
"@markuplint/shared": "3.5.1-dev.3129+f6ad62e9",
|
|
31
|
+
"@types/cosmiconfig": "^6.0.0",
|
|
32
|
+
"@types/glob": "^8.0.0",
|
|
33
|
+
"cosmiconfig": "^8.0.0",
|
|
34
|
+
"cosmiconfig-typescript-loader": "^4.3.0",
|
|
35
|
+
"glob": "^10.2.2",
|
|
30
36
|
"jsonc": "^2.0.0",
|
|
31
|
-
"minimatch": "^
|
|
32
|
-
"tslib": "^2.
|
|
37
|
+
"minimatch": "^9.0.0",
|
|
38
|
+
"tslib": "^2.4.1"
|
|
33
39
|
},
|
|
34
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "f6ad62e992e1569be4067f1e90d2d6017a658f57"
|
|
35
41
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = {};
|
|
File without changes
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../001/package.json",
|
|
3
|
-
"dummy2": false,
|
|
4
|
-
"key": "002/.markuplintrc.json",
|
|
5
|
-
"plugins": [
|
|
6
|
-
{
|
|
7
|
-
"name": "@markuplint/file-resolver",
|
|
8
|
-
"foo": "002"
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"name": "b",
|
|
12
|
-
"foo": "002"
|
|
13
|
-
}
|
|
14
|
-
],
|
|
15
|
-
"rules": {
|
|
16
|
-
"rule__enabled": true,
|
|
17
|
-
"rule__disabled": false,
|
|
18
|
-
"rule__custom-setting": {
|
|
19
|
-
"severity": "error",
|
|
20
|
-
"value": "VALUE"
|
|
21
|
-
},
|
|
22
|
-
"rule__custom-setting-with-detail-option": {
|
|
23
|
-
"value": "VALUE",
|
|
24
|
-
"option": {
|
|
25
|
-
"OPTIONAL_PROP": "OPTIONAL_VALUE"
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
"rule__custom-setting2": {
|
|
29
|
-
"severity": "error",
|
|
30
|
-
"value": "VALUE"
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
"nodeRules": [
|
|
34
|
-
{
|
|
35
|
-
"selector": "div",
|
|
36
|
-
"rules": {
|
|
37
|
-
"rule__disable-for-div-tag": false
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
],
|
|
41
|
-
"childNodeRules": [
|
|
42
|
-
{
|
|
43
|
-
"selector": "[data-attr^=\"value\"]",
|
|
44
|
-
"inheritance": true,
|
|
45
|
-
"rules": {
|
|
46
|
-
"rule__overwrite-setting-of-selector-matched-element": {
|
|
47
|
-
"value": "OVERWROTE_VALUE"
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
]
|
|
52
|
-
}
|
|
File without changes
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": ["plugin:foo/bar-config", "../002/.markuplintrc.json", "markuplint:___test"],
|
|
3
|
-
"dummy2": true,
|
|
4
|
-
"key": "003/.markuplintrc",
|
|
5
|
-
"key2": "001-2.js",
|
|
6
|
-
"plugins": ["../../plugins/001.js"],
|
|
7
|
-
"rules": {
|
|
8
|
-
"rule__enabled": false,
|
|
9
|
-
"rule__disabled": true,
|
|
10
|
-
"rule__custom-setting": {
|
|
11
|
-
"severity": "error",
|
|
12
|
-
"value": "CHANGED_VALUE"
|
|
13
|
-
},
|
|
14
|
-
"rule__custom-setting-with-detail-option": {
|
|
15
|
-
"value": "VALUE",
|
|
16
|
-
"option": {
|
|
17
|
-
"OPTIONAL_PROP": "CHANGED_OPTIONAL_VALUE"
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"rule__custom-setting2": false,
|
|
21
|
-
"additional_rule": {
|
|
22
|
-
"value": "VALUE"
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
"nodeRules": [
|
|
26
|
-
{
|
|
27
|
-
"selector": "div",
|
|
28
|
-
"rules": {
|
|
29
|
-
"rule__disable-for-div-tag": true
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"selector": "a",
|
|
34
|
-
"rules": {
|
|
35
|
-
"rule__enble-for-a-tag": true
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
],
|
|
39
|
-
"childNodeRules": [
|
|
40
|
-
{
|
|
41
|
-
"selector": "[data-attr^=\"value\"]",
|
|
42
|
-
"inheritance": false,
|
|
43
|
-
"rules": {
|
|
44
|
-
"rule__overwrite-setting-of-selector-matched-element": {
|
|
45
|
-
"value": "OVERWROTE_VALUE"
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
]
|
|
50
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/test/plugins/001.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
2
|
-
const { createPlugin } = require('@markuplint/ml-core');
|
|
3
|
-
|
|
4
|
-
module.exports = createPlugin({
|
|
5
|
-
name: 'foo',
|
|
6
|
-
create(settings) {
|
|
7
|
-
return {
|
|
8
|
-
rules: {
|
|
9
|
-
bar: {
|
|
10
|
-
verify: async () => [],
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
configs: {
|
|
14
|
-
'bar-config': {
|
|
15
|
-
key: '001.js',
|
|
16
|
-
key2: '001-2.js',
|
|
17
|
-
rules: {
|
|
18
|
-
xxx: 'yyy',
|
|
19
|
-
zzz: {
|
|
20
|
-
severity: 'error',
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
},
|
|
27
|
-
});
|
package/test/plugins/002.js
DELETED
package/tsconfig.test.json
DELETED