@markuplint/file-resolver 3.5.0 → 3.6.0

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