@markuplint/file-resolver 3.0.0-dev.25 → 3.0.0-dev.290

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 (56) hide show
  1. package/lib/auto-load-rules.js +6 -34
  2. package/lib/config-provider.d.ts +6 -4
  3. package/lib/config-provider.js +128 -78
  4. package/lib/cosmiconfig.js +33 -17
  5. package/lib/index.d.ts +7 -7
  6. package/lib/index.js +6 -9
  7. package/lib/ml-file/get-anonymous-file.d.ts +1 -1
  8. package/lib/ml-file/get-anonymous-file.js +3 -7
  9. package/lib/ml-file/get-file.d.ts +1 -1
  10. package/lib/ml-file/get-file.js +3 -7
  11. package/lib/ml-file/get-files.d.ts +1 -1
  12. package/lib/ml-file/get-files.js +5 -17
  13. package/lib/ml-file/index.d.ts +4 -4
  14. package/lib/ml-file/index.js +3 -6
  15. package/lib/ml-file/ml-file.d.ts +2 -1
  16. package/lib/ml-file/ml-file.js +56 -41
  17. package/lib/resolve-files.d.ts +3 -3
  18. package/lib/resolve-files.js +4 -8
  19. package/lib/resolve-parser.d.ts +2 -2
  20. package/lib/resolve-parser.js +13 -17
  21. package/lib/resolve-plugins.d.ts +1 -1
  22. package/lib/resolve-plugins.js +11 -36
  23. package/lib/resolve-rules.d.ts +2 -3
  24. package/lib/resolve-rules.js +8 -35
  25. package/lib/resolve-specs.js +8 -17
  26. package/lib/types.d.ts +7 -8
  27. package/lib/types.js +1 -2
  28. package/lib/utils.d.ts +0 -2
  29. package/lib/utils.js +6 -17
  30. package/package.json +26 -16
  31. package/__mocks__/markuplint-angular-parser.js +0 -3
  32. package/__mocks__/markuplint-rule-fake.js +0 -1
  33. package/__mocks__/packaged-config.js +0 -3
  34. package/test/fixtures/001/package.json +0 -15
  35. package/test/fixtures/001/target.html +0 -0
  36. package/test/fixtures/002/.markuplintrc.json +0 -52
  37. package/test/fixtures/002/target.html +0 -0
  38. package/test/fixtures/003/.markuplintrc +0 -50
  39. package/test/fixtures/003/dir/target.html +0 -0
  40. package/test/fixtures/004/.markuplintrc +0 -4
  41. package/test/fixtures/004/dir/.markuplintrc +0 -4
  42. package/test/fixtures/004/dir/dir/.markuplintrc +0 -4
  43. package/test/fixtures/004/dir/dir/dir/.markuplintrc +0 -4
  44. package/test/fixtures/004/dir/dir/dir/dir/.markuplintrc +0 -4
  45. package/test/fixtures/004/dir/dir/dir/dir/dir/.markuplintrc +0 -4
  46. package/test/fixtures/004/dir/dir/dir/dir/dir/deep-target.html +0 -0
  47. package/test/fixtures/005/.markuplintrc +0 -4
  48. package/test/fixtures/005/target.html +0 -0
  49. package/test/fixtures/006/.markuplintrc +0 -12
  50. package/test/fixtures/006/target.html +0 -0
  51. package/test/fixtures/007/.markuplintrc +0 -3
  52. package/test/fixtures/007/target.html +0 -0
  53. package/test/plugins/001.js +0 -27
  54. package/test/plugins/002.js +0 -9
  55. package/tsconfig.test.json +0 -3
  56. package/tsconfig.tsbuildinfo +0 -1
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFiles = void 0;
4
- const tslib_1 = require("tslib");
5
- const glob_1 = tslib_1.__importDefault(require("glob"));
6
- const get_file_1 = require("./get-file");
1
+ import { glob } from 'glob';
2
+ import { getFile } from './get-file.js';
7
3
  /**
8
4
  * Get files
9
5
  *
@@ -11,15 +7,7 @@ const get_file_1 = require("./get-file");
11
7
  *
12
8
  * @param filePathOrGlob
13
9
  */
14
- 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(() => []);
23
- return fileList.map(fileName => (0, get_file_1.getFile)(fileName));
10
+ export async function getFiles(filePathOrGlob) {
11
+ const fileList = await glob(filePathOrGlob, {}).catch(() => []);
12
+ return fileList.map(fileName => getFile(fileName));
24
13
  }
25
- exports.getFiles = getFiles;
@@ -1,4 +1,4 @@
1
- export type { MLFile } from './ml-file';
2
- export * from './get-anonymous-file';
3
- export * from './get-file';
4
- export * from './get-files';
1
+ export type { MLFile } from './ml-file.js';
2
+ export * from './get-anonymous-file.js';
3
+ export * from './get-file.js';
4
+ export * from './get-files.js';
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./get-anonymous-file"), exports);
5
- tslib_1.__exportStar(require("./get-file"), exports);
6
- tslib_1.__exportStar(require("./get-files"), exports);
1
+ export * from './get-anonymous-file.js';
2
+ export * from './get-file.js';
3
+ export * from './get-files.js';
@@ -1,4 +1,4 @@
1
- import type { Target } from '../types';
1
+ import type { Target } from '../types.js';
2
2
  export declare class MLFile {
3
3
  #private;
4
4
  constructor(target: Target);
@@ -14,6 +14,7 @@ export declare class MLFile {
14
14
  get path(): string;
15
15
  dirExists(): Promise<boolean>;
16
16
  getCode(): Promise<string>;
17
+ ignored(globPath: string | readonly string[]): any;
17
18
  isExist(): Promise<boolean>;
18
19
  isFile(): Promise<boolean>;
19
20
  matches(globPath: string): boolean;
@@ -1,12 +1,10 @@
1
- "use strict";
2
1
  var _MLFile_basename, _MLFile_code, _MLFile_dirname, _MLFile_stat, _MLFile_type;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.MLFile = void 0;
5
- const tslib_1 = require("tslib");
6
- const fs_1 = require("fs");
7
- const path_1 = tslib_1.__importDefault(require("path"));
8
- const minimatch_1 = tslib_1.__importDefault(require("minimatch"));
9
- class MLFile {
2
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
+ import { promises as fs } from 'node:fs';
4
+ import path from 'node:path';
5
+ import ignore from 'ignore';
6
+ import { minimatch } from 'minimatch';
7
+ export class MLFile {
10
8
  constructor(target) {
11
9
  _MLFile_basename.set(this, void 0);
12
10
  _MLFile_code.set(this, void 0);
@@ -19,25 +17,25 @@ class MLFile {
19
17
  _MLFile_stat.set(this, undefined);
20
18
  _MLFile_type.set(this, void 0);
21
19
  if (typeof target === 'string') {
22
- tslib_1.__classPrivateFieldSet(this, _MLFile_basename, path_1.default.basename(target), "f");
23
- tslib_1.__classPrivateFieldSet(this, _MLFile_dirname, path_1.default.dirname(target), "f");
24
- tslib_1.__classPrivateFieldSet(this, _MLFile_code, null, "f");
25
- tslib_1.__classPrivateFieldSet(this, _MLFile_type, 'file-base', "f");
20
+ __classPrivateFieldSet(this, _MLFile_basename, path.basename(target), "f");
21
+ __classPrivateFieldSet(this, _MLFile_dirname, path.dirname(target), "f");
22
+ __classPrivateFieldSet(this, _MLFile_code, null, "f");
23
+ __classPrivateFieldSet(this, _MLFile_type, 'file-base', "f");
26
24
  return;
27
25
  }
28
- if (!target.workspace && target.name && path_1.default.isAbsolute(target.name)) {
29
- tslib_1.__classPrivateFieldSet(this, _MLFile_basename, path_1.default.basename(target.name), "f");
30
- tslib_1.__classPrivateFieldSet(this, _MLFile_dirname, path_1.default.dirname(target.name), "f");
26
+ if (!target.workspace && target.name && path.isAbsolute(target.name)) {
27
+ __classPrivateFieldSet(this, _MLFile_basename, path.basename(target.name), "f");
28
+ __classPrivateFieldSet(this, _MLFile_dirname, path.dirname(target.name), "f");
31
29
  }
32
30
  else {
33
- tslib_1.__classPrivateFieldSet(this, _MLFile_basename, target.name || '<AnonymousFile>', "f");
34
- tslib_1.__classPrivateFieldSet(this, _MLFile_dirname, target.workspace || process.cwd(), "f");
31
+ __classPrivateFieldSet(this, _MLFile_basename, target.name ?? '<AnonymousFile>', "f");
32
+ __classPrivateFieldSet(this, _MLFile_dirname, target.workspace ?? process.cwd(), "f");
35
33
  }
36
- tslib_1.__classPrivateFieldSet(this, _MLFile_code, target.sourceCode, "f");
37
- tslib_1.__classPrivateFieldSet(this, _MLFile_type, 'code-base', "f");
34
+ __classPrivateFieldSet(this, _MLFile_code, target.sourceCode, "f");
35
+ __classPrivateFieldSet(this, _MLFile_type, 'code-base', "f");
38
36
  }
39
37
  get dirname() {
40
- return tslib_1.__classPrivateFieldGet(this, _MLFile_dirname, "f");
38
+ return __classPrivateFieldGet(this, _MLFile_dirname, "f");
41
39
  }
42
40
  /**
43
41
  * Normalized `MLFile.dirname`
@@ -52,61 +50,68 @@ class MLFile {
52
50
  return pathNormalize(this.path);
53
51
  }
54
52
  get path() {
55
- return path_1.default.resolve(tslib_1.__classPrivateFieldGet(this, _MLFile_dirname, "f"), tslib_1.__classPrivateFieldGet(this, _MLFile_basename, "f"));
53
+ return path.resolve(__classPrivateFieldGet(this, _MLFile_dirname, "f"), __classPrivateFieldGet(this, _MLFile_basename, "f"));
56
54
  }
57
55
  async dirExists() {
58
- return !!(await stat(tslib_1.__classPrivateFieldGet(this, _MLFile_dirname, "f")));
56
+ return !!(await stat(__classPrivateFieldGet(this, _MLFile_dirname, "f")));
59
57
  }
60
58
  async getCode() {
61
- if (tslib_1.__classPrivateFieldGet(this, _MLFile_code, "f") != null) {
62
- return tslib_1.__classPrivateFieldGet(this, _MLFile_code, "f");
59
+ if (__classPrivateFieldGet(this, _MLFile_code, "f") != null) {
60
+ return __classPrivateFieldGet(this, _MLFile_code, "f");
63
61
  }
64
- if (tslib_1.__classPrivateFieldGet(this, _MLFile_type, "f") === 'file-base' && (await this.isExist())) {
62
+ if (__classPrivateFieldGet(this, _MLFile_type, "f") === 'file-base' && (await this.isExist())) {
65
63
  return await this._fetch();
66
64
  }
67
65
  return '';
68
66
  }
67
+ ignored(globPath) {
68
+ globPath = typeof globPath === 'string' ? [globPath] : globPath;
69
+ const normalizedPaths = globPath.map(p => pathNormalize(p, true));
70
+ // @ts-ignore
71
+ const ig = ignore().add(normalizedPaths);
72
+ const ignored = ig.ignores(pathNormalize(this.nPath, true));
73
+ return ignored;
74
+ }
69
75
  async isExist() {
70
- if (tslib_1.__classPrivateFieldGet(this, _MLFile_type, "f") === 'code-base') {
76
+ if (__classPrivateFieldGet(this, _MLFile_type, "f") === 'code-base') {
71
77
  return true;
72
78
  }
73
79
  const stat = await this._stat();
74
80
  return !!stat;
75
81
  }
76
82
  async isFile() {
77
- if (tslib_1.__classPrivateFieldGet(this, _MLFile_type, "f") === 'code-base') {
83
+ if (__classPrivateFieldGet(this, _MLFile_type, "f") === 'code-base') {
78
84
  return true;
79
85
  }
80
86
  const stat = await this._stat();
81
87
  return !!stat && stat.isFile();
82
88
  }
83
89
  matches(globPath) {
84
- return (0, minimatch_1.default)(this.nPath, pathNormalize(globPath));
90
+ return minimatch(this.nPath, pathNormalize(globPath));
85
91
  }
86
92
  setCode(code) {
87
- if (tslib_1.__classPrivateFieldGet(this, _MLFile_type, "f") === 'file-base') {
93
+ if (__classPrivateFieldGet(this, _MLFile_type, "f") === 'file-base') {
88
94
  throw new Error(`This file object is readonly (File-base: ${this.path})`);
89
95
  }
90
- tslib_1.__classPrivateFieldSet(this, _MLFile_code, code, "f");
96
+ __classPrivateFieldSet(this, _MLFile_code, code, "f");
91
97
  }
92
98
  async _fetch() {
93
- const code = await fs_1.promises.readFile(this.path, { encoding: 'utf-8' });
94
- tslib_1.__classPrivateFieldSet(this, _MLFile_code, code, "f");
99
+ const code = await fs.readFile(this.path, { encoding: 'utf-8' });
100
+ __classPrivateFieldSet(this, _MLFile_code, code, "f");
95
101
  return code;
96
102
  }
97
103
  async _stat() {
98
- if (tslib_1.__classPrivateFieldGet(this, _MLFile_stat, "f")) {
99
- return tslib_1.__classPrivateFieldGet(this, _MLFile_stat, "f");
104
+ if (__classPrivateFieldGet(this, _MLFile_stat, "f")) {
105
+ return __classPrivateFieldGet(this, _MLFile_stat, "f");
100
106
  }
101
- tslib_1.__classPrivateFieldSet(this, _MLFile_stat, await stat(this.path), "f");
102
- return tslib_1.__classPrivateFieldGet(this, _MLFile_stat, "f");
107
+ __classPrivateFieldSet(this, _MLFile_stat, await stat(this.path), "f");
108
+ return __classPrivateFieldGet(this, _MLFile_stat, "f");
103
109
  }
104
110
  }
105
- exports.MLFile = MLFile;
106
111
  _MLFile_basename = new WeakMap(), _MLFile_code = new WeakMap(), _MLFile_dirname = new WeakMap(), _MLFile_stat = new WeakMap(), _MLFile_type = new WeakMap();
107
112
  async function stat(filePath) {
108
113
  try {
109
- return await fs_1.promises.stat(filePath);
114
+ return await fs.stat(filePath);
110
115
  }
111
116
  catch (err) {
112
117
  if (
@@ -119,12 +124,22 @@ async function stat(filePath) {
119
124
  throw err;
120
125
  }
121
126
  }
122
- function pathNormalize(filePath) {
127
+ function pathNormalize(filePath, relative = false) {
128
+ const hasBang = filePath.startsWith('!');
129
+ if (hasBang) {
130
+ filePath = filePath.slice(1);
131
+ }
123
132
  // Remove the local disk scheme of Windows OS
124
- if (path_1.default.isAbsolute(filePath)) {
133
+ if (path.isAbsolute(filePath)) {
125
134
  filePath = filePath.replace(/^[a-z]+:/i, '');
135
+ if (relative) {
136
+ filePath = path.relative(path.sep, filePath);
137
+ }
126
138
  }
127
139
  // Replace the separator of Windows OS
128
- filePath = filePath.split(path_1.default.sep).join('/');
140
+ filePath = filePath.split(path.sep).join('/');
141
+ if (hasBang) {
142
+ filePath = `!${filePath}`;
143
+ }
129
144
  return filePath;
130
145
  }
@@ -1,3 +1,3 @@
1
- import type { MLFile } from './ml-file';
2
- import type { Target } from './types';
3
- export declare function resolveFiles(targetList: Target[]): Promise<MLFile[]>;
1
+ import type { MLFile } from './ml-file/index.js';
2
+ import type { Target } from './types.js';
3
+ export declare function resolveFiles(targetList: readonly Readonly<Target>[]): Promise<MLFile[]>;
@@ -1,17 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveFiles = void 0;
4
- const ml_file_1 = require("./ml-file");
5
- async function resolveFiles(targetList) {
1
+ import { getAnonymousFile, getFiles } from './ml-file/index.js';
2
+ export async function resolveFiles(targetList) {
6
3
  const res = [];
7
4
  for (const target of targetList) {
8
5
  if (typeof target === 'string') {
9
- const file = await (0, ml_file_1.getFiles)(target);
6
+ const file = await getFiles(target);
10
7
  res.push(...file);
11
8
  continue;
12
9
  }
13
- res.push((0, ml_file_1.getAnonymousFile)(target.sourceCode, target.workspace, target.name));
10
+ res.push(getAnonymousFile(target.sourceCode, target.workspace, target.name));
14
11
  }
15
12
  return res;
16
13
  }
17
- exports.resolveFiles = resolveFiles;
@@ -1,7 +1,7 @@
1
- import type { MLFile } from './ml-file';
1
+ import type { MLFile } from './ml-file/index.js';
2
2
  import type { MLMarkupLanguageParser, ParserOptions } from '@markuplint/ml-ast';
3
3
  import type { ParserConfig } from '@markuplint/ml-config';
4
- export declare function resolveParser(file: MLFile, parserConfig?: ParserConfig, parserOptions?: ParserOptions): Promise<{
4
+ export declare function resolveParser(file: Readonly<MLFile>, parserConfig?: ParserConfig, parserOptions?: ParserOptions): Promise<{
5
5
  parserModName: string;
6
6
  parser: MLMarkupLanguageParser;
7
7
  parserOptions: ParserOptions;
@@ -1,25 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveParser = void 0;
4
- const tslib_1 = require("tslib");
5
- const path_1 = tslib_1.__importDefault(require("path"));
6
- const utils_1 = require("./utils");
1
+ import path from 'node:path';
2
+ import { toRegexp } from './utils.js';
7
3
  const parsers = new Map();
8
- async function resolveParser(file, parserConfig, parserOptions) {
4
+ export async function resolveParser(file, parserConfig, parserOptions) {
9
5
  parserConfig = {
10
6
  ...parserConfig,
11
7
  '/\\.html?$/i': '@markuplint/html-parser',
12
8
  };
13
- parserOptions = parserOptions || {};
9
+ parserOptions = parserOptions ?? {};
14
10
  let parserModName = '@markuplint/html-parser';
15
11
  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.toRegexp)(pattern))) {
19
- parserModName = parserConfig[pattern];
20
- matched = true;
21
- break;
12
+ for (const pattern of Object.keys(parserConfig)) {
13
+ if (path.basename(file.path).match(toRegexp(pattern))) {
14
+ const modName = parserConfig[pattern];
15
+ if (!modName) {
16
+ continue;
22
17
  }
18
+ parserModName = modName;
19
+ matched = true;
20
+ break;
23
21
  }
24
22
  }
25
23
  const parser = await importParser(parserModName);
@@ -30,13 +28,11 @@ async function resolveParser(file, parserConfig, parserOptions) {
30
28
  matched,
31
29
  };
32
30
  }
33
- exports.resolveParser = resolveParser;
34
31
  async function importParser(parserModName) {
35
- var _a;
36
32
  const entity = parsers.get(parserModName);
37
33
  if (entity) {
38
34
  return entity;
39
35
  }
40
- const parser = await (_a = parserModName, Promise.resolve().then(() => tslib_1.__importStar(require(_a))));
36
+ const parser = await import(parserModName);
41
37
  return parser;
42
38
  }
@@ -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;
@@ -1,31 +1,5 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.cacheClear = exports.resolvePlugins = void 0;
27
1
  const cache = new Map();
28
- async function resolvePlugins(pluginPaths) {
2
+ export async function resolvePlugins(pluginPaths) {
29
3
  if (!pluginPaths) {
30
4
  return [];
31
5
  }
@@ -33,11 +7,9 @@ async function resolvePlugins(pluginPaths) {
33
7
  // Clone
34
8
  return plugins.slice();
35
9
  }
36
- exports.resolvePlugins = resolvePlugins;
37
- function cacheClear() {
10
+ export function cacheClear() {
38
11
  cache.clear();
39
12
  }
40
- exports.cacheClear = cacheClear;
41
13
  async function importPlugin(pluginPath) {
42
14
  const config = getPluginConfig(pluginPath);
43
15
  const cached = cache.get(config.name);
@@ -55,15 +27,19 @@ async function importPlugin(pluginPath) {
55
27
  ...pluginCreator.create(config.settings),
56
28
  };
57
29
  cache.set(plugin.name, plugin);
58
- if (!plugin.name) {
59
- plugin.name = config.name
30
+ let name = plugin.name;
31
+ if (!name) {
32
+ name = config.name
60
33
  .toLowerCase()
61
34
  .replace(/^(?:markuplint-rule-|@markuplint\/rule-)/i, '')
62
35
  .replace(/\s+|\/|\\|\./g, '-');
63
36
  // eslint-disable-next-line no-console
64
- console.info(`The plugin name became "${plugin.name}"`);
37
+ console.info(`The plugin name became "${name}"`);
65
38
  }
66
- return plugin;
39
+ return {
40
+ ...plugin,
41
+ name,
42
+ };
67
43
  }
68
44
  function getPluginConfig(pluginPath) {
69
45
  if (typeof pluginPath === 'string') {
@@ -72,8 +48,7 @@ function getPluginConfig(pluginPath) {
72
48
  return pluginPath;
73
49
  }
74
50
  async function failSafeImport(name) {
75
- var _a;
76
- const res = await (_a = name, Promise.resolve().then(() => __importStar(require(_a)))).catch(e => e);
51
+ const res = await import(name).catch(e => e);
77
52
  if ('code' in res && res === 'MODULE_NOT_FOUND') {
78
53
  return null;
79
54
  }
@@ -1,7 +1,6 @@
1
1
  import type { AnyMLRule, Ruleset, Plugin } from '@markuplint/ml-core';
2
- import { MLRule } from '@markuplint/ml-core';
3
- export declare function resolveRules(plugins: Plugin[], ruleset: Ruleset, importPreset: boolean,
2
+ export declare function resolveRules(plugins: readonly Plugin[], ruleset: Ruleset, importPreset: boolean,
4
3
  /**
5
4
  * @deprecated
6
5
  */
7
- autoLoad: boolean): Promise<AnyMLRule[] | MLRule<any, any>[]>;
6
+ autoLoad: boolean): Promise<Readonly<AnyMLRule>[]>;
@@ -1,33 +1,7 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.resolveRules = void 0;
27
- const ml_core_1 = require("@markuplint/ml-core");
28
- const auto_load_rules_1 = require("./auto-load-rules");
1
+ import { MLRule } from '@markuplint/ml-core';
2
+ import { autoLoadRules } from './auto-load-rules.js';
29
3
  let cachedPresetRules = null;
30
- async function resolveRules(plugins, ruleset, importPreset,
4
+ export async function resolveRules(plugins, ruleset, importPreset,
31
5
  /**
32
6
  * @deprecated
33
7
  */
@@ -38,7 +12,7 @@ autoLoad) {
38
12
  return;
39
13
  }
40
14
  Object.entries(plugin.rules).forEach(([name, seed]) => {
41
- const rule = new ml_core_1.MLRule({
15
+ const rule = new MLRule({
42
16
  name: `${plugin.name}/${name}`,
43
17
  ...seed,
44
18
  });
@@ -46,7 +20,7 @@ autoLoad) {
46
20
  });
47
21
  });
48
22
  if (autoLoad) {
49
- const { rules: additionalRules } = await (0, auto_load_rules_1.autoLoadRules)(ruleset);
23
+ const { rules: additionalRules } = await autoLoadRules(ruleset);
50
24
  additionalRules.forEach(rule => {
51
25
  rules.push(rule);
52
26
  });
@@ -54,16 +28,15 @@ autoLoad) {
54
28
  // Clone
55
29
  return rules.slice();
56
30
  }
57
- exports.resolveRules = resolveRules;
58
31
  async function importPresetRules() {
59
- var _a;
60
32
  if (cachedPresetRules) {
61
33
  return cachedPresetRules.slice();
62
34
  }
63
35
  const modName = '@markuplint/rules';
64
- const presetRules = (await (_a = modName, Promise.resolve().then(() => __importStar(require(_a))))).default;
36
+ const mod = await import(modName);
37
+ const presetRules = mod.default;
65
38
  const ruleList = Object.entries(presetRules).map(([name, seed]) => {
66
- const rule = new ml_core_1.MLRule({
39
+ const rule = new MLRule({
67
40
  name,
68
41
  ...seed,
69
42
  });
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveSpecs = void 0;
4
- const tslib_1 = require("tslib");
5
- const path_1 = tslib_1.__importDefault(require("path"));
6
- const utils_1 = require("./utils");
1
+ import path from 'node:path';
2
+ import { toRegexp } from './utils.js';
7
3
  const caches = new Map();
8
4
  /**
9
5
  * Loading and importing form specs.
@@ -35,7 +31,7 @@ const caches = new Map();
35
31
  * @param specConfig The `spec` property part of the config
36
32
  * @returns
37
33
  */
38
- async function resolveSpecs(filePath, specConfig) {
34
+ export async function resolveSpecs(filePath, specConfig) {
39
35
  const htmlSpec = await importSpecs('@markuplint/html-spec');
40
36
  const extendedSpecs = [];
41
37
  if (specConfig) {
@@ -43,16 +39,13 @@ async function resolveSpecs(filePath, specConfig) {
43
39
  const spec = await importSpecs(specConfig);
44
40
  extendedSpecs.push(spec);
45
41
  }
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
42
  else {
53
43
  for (const pattern of Object.keys(specConfig)) {
54
- if (path_1.default.basename(filePath).match((0, utils_1.toRegexp)(pattern))) {
44
+ if (path.basename(filePath).match(toRegexp(pattern))) {
55
45
  const specModName = specConfig[pattern];
46
+ if (!specModName) {
47
+ continue;
48
+ }
56
49
  const spec = await importSpecs(specModName);
57
50
  extendedSpecs.push(spec);
58
51
  }
@@ -64,9 +57,7 @@ async function resolveSpecs(filePath, specConfig) {
64
57
  schemas,
65
58
  };
66
59
  }
67
- exports.resolveSpecs = resolveSpecs;
68
60
  async function importSpecs(specModName) {
69
- var _a;
70
61
  {
71
62
  // @ts-ignore
72
63
  const spec = caches.get(specModName);
@@ -74,7 +65,7 @@ async function importSpecs(specModName) {
74
65
  return spec;
75
66
  }
76
67
  }
77
- const spec = (await (_a = specModName, Promise.resolve().then(() => tslib_1.__importStar(require(_a))))).default;
68
+ const spec = (await import(specModName)).default;
78
69
  // @ts-ignore
79
70
  caches.set(specModName, spec);
80
71
  return spec;
package/lib/types.d.ts CHANGED
@@ -1,23 +1,22 @@
1
1
  import type { Config } from '@markuplint/ml-config';
2
2
  import type { Plugin } from '@markuplint/ml-core';
3
- export type Nullable<T> = T | null | undefined;
4
3
  export interface ConfigSet {
5
- config: Config;
6
- plugins: Plugin[];
7
- files: Set<string>;
8
- errs: Error[];
4
+ readonly config: Config;
5
+ readonly plugins: readonly Plugin[];
6
+ readonly files: ReadonlySet<string>;
7
+ readonly errs: readonly Readonly<Error>[];
9
8
  }
10
9
  export type Target = string | {
11
10
  /**
12
11
  * Target source code of evaluation
13
12
  */
14
- sourceCode: string;
13
+ readonly sourceCode: string;
15
14
  /**
16
15
  * File names when `sourceCodes`
17
16
  */
18
- name?: string;
17
+ readonly name?: string;
19
18
  /**
20
19
  * Workspace path when `sourceCodes`
21
20
  */
22
- workspace?: string;
21
+ readonly workspace?: string;
23
22
  };
package/lib/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
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,28 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toRegexp = exports.fileExists = exports.uuid = exports.nonNullableFilter = void 0;
4
- const tslib_1 = require("tslib");
5
- const fs_1 = tslib_1.__importDefault(require("fs"));
6
- function nonNullableFilter(item) {
7
- return !!item;
8
- }
9
- exports.nonNullableFilter = nonNullableFilter;
1
+ import fs from 'node:fs';
10
2
  let uuidNum = 0;
11
- function uuid() {
3
+ export function uuid() {
12
4
  const out = `${uuidNum}`;
13
5
  uuidNum++;
14
6
  return out;
15
7
  }
16
- exports.uuid = uuid;
17
- function fileExists(filePath) {
18
- return fs_1.default.existsSync(filePath);
8
+ export function fileExists(filePath) {
9
+ return fs.existsSync(filePath);
19
10
  }
20
- exports.fileExists = fileExists;
21
- function toRegexp(pattern) {
11
+ export function toRegexp(pattern) {
22
12
  const matched = pattern.match(/^\/(.+)\/([ig]*)$/i);
23
- if (matched) {
13
+ if (matched && matched[1]) {
24
14
  return new RegExp(matched[1], matched[2]);
25
15
  }
26
16
  return pattern;
27
17
  }
28
- exports.toRegexp = toRegexp;