@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.
Files changed (47) hide show
  1. package/README.md +8 -3
  2. package/lib/auto-load-rules.d.ts +2 -2
  3. package/lib/auto-load-rules.js +2 -2
  4. package/lib/config-provider.d.ts +10 -9
  5. package/lib/config-provider.js +83 -78
  6. package/lib/cosmiconfig.d.ts +13 -7
  7. package/lib/cosmiconfig.js +2 -0
  8. package/lib/ml-file/get-files.js +2 -10
  9. package/lib/ml-file/ml-file.d.ts +20 -20
  10. package/lib/ml-file/ml-file.js +32 -31
  11. package/lib/resolve-files.d.ts +1 -1
  12. package/lib/resolve-parser.d.ts +11 -7
  13. package/lib/resolve-parser.js +10 -8
  14. package/lib/resolve-plugins.d.ts +1 -1
  15. package/lib/resolve-plugins.js +9 -5
  16. package/lib/resolve-rules.d.ts +9 -6
  17. package/lib/resolve-rules.js +1 -1
  18. package/lib/resolve-specs.d.ts +5 -2
  19. package/lib/resolve-specs.js +6 -8
  20. package/lib/types.d.ts +20 -19
  21. package/lib/utils.d.ts +1 -3
  22. package/lib/utils.js +4 -8
  23. package/package.json +19 -13
  24. package/__mocks__/markuplint-angular-parser.js +0 -3
  25. package/__mocks__/markuplint-rule-fake.js +0 -1
  26. package/__mocks__/packaged-config.js +0 -3
  27. package/test/fixtures/001/package.json +0 -15
  28. package/test/fixtures/001/target.html +0 -0
  29. package/test/fixtures/002/.markuplintrc.json +0 -52
  30. package/test/fixtures/002/target.html +0 -0
  31. package/test/fixtures/003/.markuplintrc +0 -50
  32. package/test/fixtures/003/dir/target.html +0 -0
  33. package/test/fixtures/004/.markuplintrc +0 -4
  34. package/test/fixtures/004/dir/.markuplintrc +0 -4
  35. package/test/fixtures/004/dir/dir/.markuplintrc +0 -4
  36. package/test/fixtures/004/dir/dir/dir/.markuplintrc +0 -4
  37. package/test/fixtures/004/dir/dir/dir/dir/.markuplintrc +0 -4
  38. package/test/fixtures/004/dir/dir/dir/dir/dir/.markuplintrc +0 -4
  39. package/test/fixtures/004/dir/dir/dir/dir/dir/deep-target.html +0 -0
  40. package/test/fixtures/005/.markuplintrc +0 -4
  41. package/test/fixtures/005/target.html +0 -0
  42. package/test/fixtures/006/.markuplintrc +0 -12
  43. package/test/fixtures/006/target.html +0 -0
  44. package/test/plugins/001.js +0 -27
  45. package/test/plugins/002.js +0 -9
  46. package/tsconfig.test.json +0 -3
  47. package/tsconfig.tsbuildinfo +0 -1
package/README.md CHANGED
@@ -1,13 +1,18 @@
1
1
  # @markuplint/file-resolver
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/%40markuplint%2Ffile-resolver.svg)](https://www.npmjs.com/package/@markuplint/file-resolver)
4
- [![Build Status](https://travis-ci.org/markuplint/markuplint.svg?branch=main)](https://travis-ci.org/markuplint/markuplint)
5
- [![Coverage Status](https://coveralls.io/repos/github/markuplint/markuplint/badge.svg?branch=main)](https://coveralls.io/github/markuplint/markuplint?branch=main)
6
4
 
7
5
  ## Install
8
6
 
9
- ```sh
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>
@@ -3,6 +3,6 @@ import type { Ruleset, AnyMLRule } from '@markuplint/ml-core';
3
3
  * @deprecated
4
4
  */
5
5
  export declare function autoLoadRules(ruleset: Ruleset): Promise<{
6
- rules: AnyMLRule[];
7
- errors: unknown[];
6
+ rules: AnyMLRule[];
7
+ errors: unknown[];
8
8
  }>;
@@ -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(() => __importStar(require(`@markuplint/rule-${ruleName}`)));
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(() => __importStar(require(`markuplint-rule-${ruleName}`)));
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;
@@ -1,13 +1,14 @@
1
1
  import type { MLFile } from './ml-file';
2
- import type { ConfigSet, Nullable } from './types';
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
- #private;
6
- set(config: Config, key?: string): string;
7
- search(targetFile: MLFile): Promise<string | null>;
8
- resolve(targetFile: MLFile, names: Nullable<string>[], cache?: boolean): Promise<ConfigSet>;
9
- private _mergeConfigs;
10
- private _recursiveLoad;
11
- private _load;
12
- private _pathResolve;
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
  }
@@ -1,48 +1,31 @@
1
1
  "use strict";
2
- var _ConfigProvider_store, _ConfigProvider_cache, _ConfigProvider_held, _ConfigProvider_recursiveLoadKeyAndDepth;
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(utils_1.nonNullableFilter);
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 = (_a = plugin === null || plugin === void 0 ? void 0 : plugin.configs) === null || _a === void 0 ? void 0 : _a[name];
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
- if (isMatched) {
60
+ const config = overrides[glob];
61
+ if (isMatched && config) {
85
62
  // Note: Original config disappears
86
- configSet.config = overrides[glob];
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(utils_1.nonNullableFilter);
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) || null;
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 ? (Array.isArray(config.extends) ? config.extends : [config.extends]) : null;
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
- _ConfigProvider_store = new WeakMap(), _ConfigProvider_cache = new WeakMap(), _ConfigProvider_held = new WeakMap(), _ConfigProvider_recursiveLoadKeyAndDepth = new WeakMap();
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(() => tslib_1.__importStar(require(filePath)));
194
- const config = (mod === null || mod === void 0 ? void 0 : mod.default) || null;
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 (isPrefixedName(pathOrModName)) {
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 isPrefixedName(name) {
266
- return /^(?:markuplint|plugin):/.test(name);
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() {
@@ -1,11 +1,17 @@
1
1
  import type { LoaderSync } from 'cosmiconfig';
2
- declare type CosmiConfig = ReturnType<LoaderSync>;
3
- export declare function search<T = CosmiConfig>(dir: string, cacheClear: boolean): Promise<{
4
- filePath: string;
5
- config: T;
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>(filePath: string, cacheClear: boolean): Promise<{
8
- filePath: string;
9
- config: T;
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 {};
@@ -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);
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getFiles = void 0;
4
- const tslib_1 = require("tslib");
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 new Promise((resolve, reject) => {
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;
@@ -1,23 +1,23 @@
1
1
  import type { Target } from '../types';
2
2
  export declare class MLFile {
3
- #private;
4
- constructor(target: Target);
5
- get path(): string;
6
- /**
7
- * Normalized `MLFile.path`
8
- */
9
- get nPath(): string;
10
- get dirname(): string;
11
- /**
12
- * Normalized `MLFile.dirname`
13
- */
14
- get nDirname(): string;
15
- isFile(): Promise<boolean>;
16
- isExist(): Promise<boolean>;
17
- dirExists(): Promise<boolean>;
18
- getCode(): Promise<string>;
19
- setCode(code: string): void;
20
- matches(globPath: string): boolean;
21
- private _fetch;
22
- private _stat;
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
  }
@@ -1,23 +1,24 @@
1
1
  "use strict";
2
- var _MLFile_type, _MLFile_basename, _MLFile_dirname, _MLFile_code, _MLFile_stat;
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 = tslib_1.__importDefault(require("minimatch"));
8
+ const minimatch_1 = require("minimatch");
9
9
  class MLFile {
10
10
  constructor(target) {
11
- _MLFile_type.set(this, void 0);
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 || '<AnonymousFile>', "f");
34
- tslib_1.__classPrivateFieldSet(this, _MLFile_dirname, target.workspace || process.cwd(), "f");
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
- async isFile() {
58
- if (tslib_1.__classPrivateFieldGet(this, _MLFile_type, "f") === 'code-base') {
59
- return true;
60
- }
61
- const stat = await this._stat();
62
- return !!stat && stat.isFile();
49
+ /**
50
+ * Normalized `MLFile.path`
51
+ */
52
+ get nPath() {
53
+ return pathNormalize(this.path);
63
54
  }
64
- async isExist() {
65
- if (tslib_1.__classPrivateFieldGet(this, _MLFile_type, "f") === 'code-base') {
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
- _MLFile_type = new WeakMap(), _MLFile_basename = new WeakMap(), _MLFile_dirname = new WeakMap(), _MLFile_code = new WeakMap(), _MLFile_stat = new WeakMap();
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);
@@ -1,3 +1,3 @@
1
1
  import type { MLFile } from './ml-file';
2
2
  import type { Target } from './types';
3
- export declare function resolveFiles(targetList: Target[]): Promise<MLFile[]>;
3
+ export declare function resolveFiles(targetList: readonly Readonly<Target>[]): Promise<MLFile[]>;
@@ -1,9 +1,13 @@
1
1
  import type { MLFile } from './ml-file';
2
- import type { MLMarkupLanguageParser } from '@markuplint/ml-ast';
3
- import type { ParserConfig, ParserOptions } from '@markuplint/ml-config';
4
- export declare function resolveParser(file: MLFile, parserConfig?: ParserConfig, parserOptions?: ParserOptions): Promise<{
5
- parserModName: string;
6
- parser: MLMarkupLanguageParser;
7
- parserOptions: ParserOptions;
8
- matched: boolean;
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
  }>;
@@ -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
- if (parserConfig) {
17
- for (const pattern of Object.keys(parserConfig)) {
18
- if (path_1.default.basename(file.path).match((0, utils_1.toRegxp)(pattern))) {
19
- parserModName = parserConfig[pattern];
20
- matched = true;
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(() => tslib_1.__importStar(require(parserModName)));
41
+ const parser = await Promise.resolve(`${parserModName}`).then(s => tslib_1.__importStar(require(s)));
40
42
  return parser;
41
43
  }
@@ -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;