@markuplint/file-resolver 3.15.0 → 4.0.0-alpha.10

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 (52) hide show
  1. package/LICENSE +1 -1
  2. package/lib/auto-load-rules.d.ts +2 -2
  3. package/lib/auto-load-rules.js +12 -39
  4. package/lib/config-load-error.d.ts +6 -0
  5. package/lib/config-load-error.js +8 -0
  6. package/lib/config-provider.d.ts +14 -11
  7. package/lib/config-provider.js +146 -198
  8. package/lib/cosmiconfig.d.ts +8 -13
  9. package/lib/cosmiconfig.js +25 -33
  10. package/lib/debug.d.ts +3 -0
  11. package/lib/debug.js +2 -0
  12. package/lib/force-import-json-in-module.d.ts +1 -0
  13. package/lib/force-import-json-in-module.js +31 -0
  14. package/lib/general-import.d.ts +1 -0
  15. package/lib/general-import.js +40 -0
  16. package/lib/get-preset.d.ts +2 -0
  17. package/lib/get-preset.js +13 -0
  18. package/lib/index.d.ts +7 -7
  19. package/lib/index.js +6 -9
  20. package/lib/is-plugin-module-name.d.ts +1 -0
  21. package/lib/is-plugin-module-name.js +3 -0
  22. package/lib/is-preset-module-name.d.ts +1 -0
  23. package/lib/is-preset-module-name.js +3 -0
  24. package/lib/ml-file/get-anonymous-file.d.ts +1 -1
  25. package/lib/ml-file/get-anonymous-file.js +3 -7
  26. package/lib/ml-file/get-file.d.ts +1 -1
  27. package/lib/ml-file/get-file.js +3 -7
  28. package/lib/ml-file/get-files.d.ts +2 -2
  29. package/lib/ml-file/get-files.js +7 -9
  30. package/lib/ml-file/index.d.ts +4 -4
  31. package/lib/ml-file/index.js +3 -6
  32. package/lib/ml-file/ml-file.d.ts +22 -22
  33. package/lib/ml-file/ml-file.js +54 -48
  34. package/lib/module-exists.d.ts +1 -0
  35. package/lib/module-exists.js +49 -0
  36. package/lib/path-to-abs-or-name.d.ts +1 -0
  37. package/lib/path-to-abs-or-name.js +38 -0
  38. package/lib/resolve-files.d.ts +3 -3
  39. package/lib/resolve-files.js +4 -8
  40. package/lib/resolve-name-or-abs-path.d.ts +1 -0
  41. package/lib/resolve-name-or-abs-path.js +14 -0
  42. package/lib/resolve-parser.d.ts +7 -11
  43. package/lib/resolve-parser.js +16 -12
  44. package/lib/resolve-plugins.js +24 -56
  45. package/lib/resolve-rules.d.ts +5 -9
  46. package/lib/resolve-rules.js +18 -44
  47. package/lib/resolve-specs.d.ts +2 -5
  48. package/lib/resolve-specs.js +10 -11
  49. package/lib/types.d.ts +18 -20
  50. package/lib/types.js +1 -2
  51. package/lib/utils.js +6 -13
  52. package/package.json +22 -18
@@ -0,0 +1,49 @@
1
+ import { createRequire } from 'node:module';
2
+ import { log } from './debug.js';
3
+ const require = createRequire(import.meta.url);
4
+ const mLog = log.extend('module-exists');
5
+ export async function moduleExists(name) {
6
+ try {
7
+ await import(name);
8
+ }
9
+ catch (error) {
10
+ if (
11
+ // @ts-ignore
12
+ 'code' in error &&
13
+ // @ts-ignore
14
+ error.code === 'ERR_IMPORT_ASSERTION_TYPE_MISSING') {
15
+ // It exists, but it is may be a JSON file.
16
+ mLog('Return true, but it caught Error in `import()`: %O', error);
17
+ return true;
18
+ }
19
+ if (error instanceof Error && /^parse failure/i.test(error.message)) {
20
+ // It exists, but it failed to parse.
21
+ mLog('Return true, but it caught Error in `import()`: %O', error);
22
+ return true;
23
+ }
24
+ try {
25
+ require.resolve(name);
26
+ }
27
+ catch (error) {
28
+ if (
29
+ // @ts-ignore
30
+ 'code' in error &&
31
+ // @ts-ignore
32
+ error.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
33
+ // Even if there are issues with the fields,
34
+ // assume that the module exists and return true.
35
+ mLog('Return true, but it caught Error in `require.resolve()`: %O', error);
36
+ return true;
37
+ }
38
+ if (
39
+ // @ts-ignore
40
+ 'code' in error &&
41
+ // @ts-ignore
42
+ error.code === 'MODULE_NOT_FOUND') {
43
+ return false;
44
+ }
45
+ throw error;
46
+ }
47
+ }
48
+ return true;
49
+ }
@@ -0,0 +1 @@
1
+ export declare function relPathToNameOrAbsPath<T extends string | readonly (string | Record<string, unknown>)[] | Readonly<Record<string, unknown>> | undefined>(dir: string, filePath?: T, resolveProps?: readonly string[], resolveKey?: boolean): Promise<T>;
@@ -0,0 +1,38 @@
1
+ import { resolveNameOrAbsPath } from './resolve-name-or-abs-path.js';
2
+ export async function relPathToNameOrAbsPath(dir, filePath, resolveProps, resolveKey = false) {
3
+ if (filePath == null) {
4
+ // @ts-ignore
5
+ return undefined;
6
+ }
7
+ if (typeof filePath === 'string') {
8
+ // @ts-ignore
9
+ return resolveNameOrAbsPath(dir, filePath);
10
+ }
11
+ if (Array.isArray(filePath)) {
12
+ // @ts-ignore
13
+ return Promise.all(filePath.map(fp => relPathToNameOrAbsPath(dir, fp, resolveProps)));
14
+ }
15
+ const res = {};
16
+ for (const [key, fp] of Object.entries(filePath)) {
17
+ let _key = key;
18
+ if (resolveKey) {
19
+ _key = await resolveNameOrAbsPath(dir, key);
20
+ }
21
+ if (typeof fp === 'string') {
22
+ if (!resolveProps) {
23
+ res[_key] = await resolveNameOrAbsPath(dir, fp);
24
+ }
25
+ else if (resolveProps.includes(key)) {
26
+ res[_key] = await resolveNameOrAbsPath(dir, fp);
27
+ }
28
+ else {
29
+ res[_key] = fp;
30
+ }
31
+ }
32
+ else {
33
+ res[_key] = fp;
34
+ }
35
+ }
36
+ // @ts-ignore
37
+ return res;
38
+ }
@@ -1,3 +1,3 @@
1
- import type { MLFile } from './ml-file';
2
- import type { Target } from './types';
3
- export declare function resolveFiles(targetList: readonly Readonly<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>[], ignoreGlob?: string): 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, ignoreGlob) {
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, ignoreGlob);
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;
@@ -0,0 +1 @@
1
+ export declare function resolveNameOrAbsPath(dir: string, pathOrModName: string): Promise<string>;
@@ -0,0 +1,14 @@
1
+ import path from 'node:path';
2
+ import { isPluginModuleName } from './is-plugin-module-name.js';
3
+ import { isPresetModuleName } from './is-preset-module-name.js';
4
+ import { moduleExists } from './module-exists.js';
5
+ export async function resolveNameOrAbsPath(dir, pathOrModName) {
6
+ if ((await moduleExists(pathOrModName)) || isPresetModuleName(pathOrModName) || isPluginModuleName(pathOrModName)) {
7
+ return pathOrModName;
8
+ }
9
+ const bangAndPath = /^(!)(.*)/.exec(pathOrModName) ?? [];
10
+ const bang = bangAndPath[1] ?? '';
11
+ const pathname = bangAndPath[2] ?? pathOrModName;
12
+ const absPath = path.resolve(dir, pathname);
13
+ return bang + absPath;
14
+ }
@@ -1,13 +1,9 @@
1
- import type { MLFile } from './ml-file';
2
- import type { MLMarkupLanguageParser, ParserOptions } from '@markuplint/ml-ast';
1
+ import type { MLFile } from './ml-file/index.js';
2
+ import type { MLMarkupLanguageParser, MLParser, ParserOptions } from '@markuplint/ml-ast';
3
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;
4
+ export declare function resolveParser(file: Readonly<MLFile>, parserConfig?: ParserConfig, parserOptions?: ParserOptions): Promise<{
5
+ parserModName: string;
6
+ parser: MLParser | MLMarkupLanguageParser;
7
+ parserOptions: ParserOptions;
8
+ matched: boolean;
13
9
  }>;
@@ -1,20 +1,18 @@
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 { generalImport } from './general-import.js';
3
+ import { toRegexp } from './utils.js';
7
4
  const parsers = new Map();
8
- async function resolveParser(file, parserConfig, parserOptions) {
5
+ export async function resolveParser(file, parserConfig, parserOptions) {
9
6
  parserConfig = {
10
7
  ...parserConfig,
11
8
  '/\\.html?$/i': '@markuplint/html-parser',
12
9
  };
13
- parserOptions = parserOptions !== null && parserOptions !== void 0 ? parserOptions : {};
10
+ parserOptions = parserOptions ?? {};
14
11
  let parserModName = '@markuplint/html-parser';
15
12
  let matched = false;
16
13
  for (const pattern of Object.keys(parserConfig)) {
17
- if (path_1.default.basename(file.path).match((0, utils_1.toRegexp)(pattern))) {
14
+ // eslint-disable-next-line unicorn/prefer-regexp-test
15
+ if (path.basename(file.path).match(toRegexp(pattern))) {
18
16
  const modName = parserConfig[pattern];
19
17
  if (!modName) {
20
18
  continue;
@@ -32,12 +30,18 @@ async function resolveParser(file, parserConfig, parserOptions) {
32
30
  matched,
33
31
  };
34
32
  }
35
- exports.resolveParser = resolveParser;
36
33
  async function importParser(parserModName) {
37
34
  const entity = parsers.get(parserModName);
38
35
  if (entity) {
39
36
  return entity;
40
37
  }
41
- const parser = await Promise.resolve(`${parserModName}`).then(s => tslib_1.__importStar(require(s)));
42
- return parser;
38
+ const parserMod = await generalImport(parserModName);
39
+ if (!parserMod) {
40
+ throw new Error(`Parser module "${parserModName}" is not found.`);
41
+ }
42
+ // TODO: To be dropped in v5
43
+ if (!('parser' in parserMod)) {
44
+ return parserMod;
45
+ }
46
+ return parserMod.parser;
43
47
  }
@@ -1,73 +1,48 @@
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;
1
+ import { log } from './debug.js';
2
+ import { generalImport } from './general-import.js';
3
+ const pLog = log.extend('resolve-plugins');
27
4
  const cache = new Map();
28
- async function resolvePlugins(pluginPaths) {
5
+ export async function resolvePlugins(pluginPaths) {
29
6
  if (!pluginPaths) {
30
7
  return [];
31
8
  }
32
9
  const plugins = await Promise.all(pluginPaths.map(p => importPlugin(p)));
33
10
  // Clone
34
- return plugins.slice();
11
+ return [...plugins];
35
12
  }
36
- exports.resolvePlugins = resolvePlugins;
37
- function cacheClear() {
13
+ export function cacheClear() {
38
14
  cache.clear();
39
15
  }
40
- exports.cacheClear = cacheClear;
41
16
  async function importPlugin(pluginPath) {
42
17
  const config = getPluginConfig(pluginPath);
43
18
  const cached = cache.get(config.name);
44
19
  if (cached) {
20
+ pLog('Return from cache: %s', config.name);
45
21
  return cached;
46
22
  }
47
- const pluginCreator = await failSafeImport(config.name);
48
- if (!pluginCreator) {
49
- return {
50
- name: config.name,
23
+ const pluginCreator = await generalImport(config.name);
24
+ let name = config.name;
25
+ let plugin = null;
26
+ if (typeof pluginCreator?.create === 'function' || pluginCreator?.name) {
27
+ plugin = {
28
+ name: pluginCreator.name,
29
+ ...pluginCreator.create(config.settings),
51
30
  };
31
+ name = plugin.name ?? name;
52
32
  }
53
- const plugin = {
54
- name: pluginCreator.name,
55
- ...pluginCreator.create(config.settings),
56
- };
57
- cache.set(plugin.name, plugin);
58
- let name = plugin.name;
59
- if (!name) {
60
- name = config.name
61
- .toLowerCase()
62
- .replace(/^(?:markuplint-rule-|@markuplint\/rule-)/i, '')
63
- .replace(/\s+|\/|\\|\./g, '-');
64
- // eslint-disable-next-line no-console
65
- console.info(`The plugin name became "${name}"`);
33
+ else if (pluginCreator) {
34
+ pLog('Invalid plugin: %s', config.name);
66
35
  }
67
- return {
36
+ name = name
37
+ .toLowerCase()
38
+ .replace(/^(?:markuplint-rule-|@markuplint\/rule-)/i, '')
39
+ .replaceAll(/\s+|[./\\]/g, '-');
40
+ const result = {
68
41
  ...plugin,
69
42
  name,
70
43
  };
44
+ cache.set(name, result);
45
+ return result;
71
46
  }
72
47
  function getPluginConfig(pluginPath) {
73
48
  if (typeof pluginPath === 'string') {
@@ -75,10 +50,3 @@ function getPluginConfig(pluginPath) {
75
50
  }
76
51
  return pluginPath;
77
52
  }
78
- async function failSafeImport(name) {
79
- const res = await Promise.resolve(`${name}`).then(s => __importStar(require(s))).catch(e => e);
80
- if ('code' in res && res === 'MODULE_NOT_FOUND') {
81
- return null;
82
- }
83
- return res.default;
84
- }
@@ -1,10 +1,6 @@
1
1
  import type { AnyMLRule, Ruleset, Plugin } from '@markuplint/ml-core';
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>[]>;
2
+ export declare function resolveRules(plugins: readonly Plugin[], ruleset: Ruleset, importPreset: boolean,
3
+ /**
4
+ * @deprecated
5
+ */
6
+ autoLoad: boolean): Promise<Readonly<AnyMLRule>[]>;
@@ -1,68 +1,42 @@
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
  */
34
8
  autoLoad) {
35
9
  const rules = importPreset ? await importPresetRules() : [];
36
- plugins.forEach(plugin => {
10
+ for (const plugin of plugins) {
37
11
  if (!plugin.rules) {
38
- return;
12
+ continue;
39
13
  }
40
- Object.entries(plugin.rules).forEach(([name, seed]) => {
41
- const rule = new ml_core_1.MLRule({
14
+ for (const [name, seed] of Object.entries(plugin.rules)) {
15
+ const rule = new MLRule({
42
16
  name: `${plugin.name}/${name}`,
43
17
  ...seed,
44
18
  });
45
19
  rules.push(rule);
46
- });
47
- });
20
+ }
21
+ }
48
22
  if (autoLoad) {
49
- const { rules: additionalRules } = await (0, auto_load_rules_1.autoLoadRules)(ruleset);
50
- additionalRules.forEach(rule => {
23
+ const { rules: additionalRules } = await autoLoadRules(ruleset);
24
+ for (const rule of additionalRules) {
51
25
  rules.push(rule);
52
- });
26
+ }
53
27
  }
54
28
  // Clone
55
- return rules.slice();
29
+ return [...rules];
56
30
  }
57
- exports.resolveRules = resolveRules;
58
31
  async function importPresetRules() {
59
32
  if (cachedPresetRules) {
60
- return cachedPresetRules.slice();
33
+ return [...cachedPresetRules];
61
34
  }
62
35
  const modName = '@markuplint/rules';
63
- const presetRules = (await Promise.resolve(`${modName}`).then(s => __importStar(require(s)))).default;
36
+ const mod = await import(modName);
37
+ const presetRules = mod.default;
64
38
  const ruleList = Object.entries(presetRules).map(([name, seed]) => {
65
- const rule = new ml_core_1.MLRule({
39
+ const rule = new MLRule({
66
40
  name,
67
41
  ...seed,
68
42
  });
@@ -70,5 +44,5 @@ async function importPresetRules() {
70
44
  });
71
45
  cachedPresetRules = ruleList;
72
46
  // Clone
73
- return ruleList.slice();
47
+ return [...ruleList];
74
48
  }
@@ -30,9 +30,6 @@ 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
- filePath: string,
35
- specConfig?: SpecConfig,
36
- ): Promise<{
37
- schemas: readonly [MLMLSpec, ...ExtendedSpec[]];
33
+ export declare function resolveSpecs(filePath: string, specConfig?: SpecConfig): Promise<{
34
+ schemas: readonly [MLMLSpec, ...ExtendedSpec[]];
38
35
  }>;
@@ -1,9 +1,6 @@
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 { generalImport } from './general-import.js';
3
+ import { toRegexp } from './utils.js';
7
4
  const caches = new Map();
8
5
  /**
9
6
  * Loading and importing form specs.
@@ -35,7 +32,7 @@ const caches = new Map();
35
32
  * @param specConfig The `spec` property part of the config
36
33
  * @returns
37
34
  */
38
- async function resolveSpecs(filePath, specConfig) {
35
+ export async function resolveSpecs(filePath, specConfig) {
39
36
  const htmlSpec = await importSpecs('@markuplint/html-spec');
40
37
  const extendedSpecs = [];
41
38
  if (specConfig) {
@@ -45,7 +42,8 @@ async function resolveSpecs(filePath, specConfig) {
45
42
  }
46
43
  else {
47
44
  for (const pattern of Object.keys(specConfig)) {
48
- if (path_1.default.basename(filePath).match((0, utils_1.toRegexp)(pattern))) {
45
+ // eslint-disable-next-line unicorn/prefer-regexp-test
46
+ if (path.basename(filePath).match(toRegexp(pattern))) {
49
47
  const specModName = specConfig[pattern];
50
48
  if (!specModName) {
51
49
  continue;
@@ -61,7 +59,6 @@ async function resolveSpecs(filePath, specConfig) {
61
59
  schemas,
62
60
  };
63
61
  }
64
- exports.resolveSpecs = resolveSpecs;
65
62
  async function importSpecs(specModName) {
66
63
  {
67
64
  // @ts-ignore
@@ -70,8 +67,10 @@ async function importSpecs(specModName) {
70
67
  return spec;
71
68
  }
72
69
  }
73
- const spec = (await Promise.resolve(`${specModName}`).then(s => tslib_1.__importStar(require(s)))).default;
74
- // @ts-ignore
70
+ const spec = await generalImport(specModName);
71
+ if (!spec) {
72
+ throw new Error(`Spec "${specModName}" is not found.`);
73
+ }
75
74
  caches.set(specModName, spec);
76
75
  return spec;
77
76
  }
package/lib/types.d.ts CHANGED
@@ -1,24 +1,22 @@
1
1
  import type { Config } from '@markuplint/ml-config';
2
2
  import type { Plugin } from '@markuplint/ml-core';
3
3
  export interface ConfigSet {
4
- readonly config: Config;
5
- readonly plugins: readonly Plugin[];
6
- readonly files: ReadonlySet<string>;
7
- 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>[];
8
8
  }
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
- };
9
+ export type Target = string | {
10
+ /**
11
+ * Target source code of evaluation
12
+ */
13
+ readonly sourceCode: string;
14
+ /**
15
+ * File names when `sourceCodes`
16
+ */
17
+ readonly name?: string;
18
+ /**
19
+ * Workspace path when `sourceCodes`
20
+ */
21
+ readonly workspace?: string;
22
+ };
package/lib/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/lib/utils.js CHANGED
@@ -1,24 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toRegexp = exports.fileExists = exports.uuid = void 0;
4
- const tslib_1 = require("tslib");
5
- const fs_1 = tslib_1.__importDefault(require("fs"));
1
+ import fs from 'node:fs';
6
2
  let uuidNum = 0;
7
- function uuid() {
3
+ export function uuid() {
8
4
  const out = `${uuidNum}`;
9
5
  uuidNum++;
10
6
  return out;
11
7
  }
12
- exports.uuid = uuid;
13
- function fileExists(filePath) {
14
- return fs_1.default.existsSync(filePath);
8
+ export function fileExists(filePath) {
9
+ return fs.existsSync(filePath);
15
10
  }
16
- exports.fileExists = fileExists;
17
- function toRegexp(pattern) {
18
- const matched = pattern.match(/^\/(.+)\/([ig]*)$/i);
11
+ export function toRegexp(pattern) {
12
+ const matched = pattern.match(/^\/(.+)\/([gi]*)$/i);
19
13
  if (matched && matched[1]) {
20
14
  return new RegExp(matched[1], matched[2]);
21
15
  }
22
16
  return pattern;
23
17
  }
24
- exports.toRegexp = toRegexp;
package/package.json CHANGED
@@ -1,13 +1,18 @@
1
1
  {
2
2
  "name": "@markuplint/file-resolver",
3
- "version": "3.15.0",
3
+ "version": "4.0.0-alpha.10",
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>",
7
7
  "license": "MIT",
8
8
  "private": false,
9
- "main": "lib/index.js",
10
- "types": "lib/index.d.ts",
9
+ "type": "module",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./lib/index.js"
13
+ }
14
+ },
15
+ "types": "./lib/index.d.ts",
11
16
  "publishConfig": {
12
17
  "access": "public"
13
18
  },
@@ -19,24 +24,23 @@
19
24
  "clean": "tsc --build --clean"
20
25
  },
21
26
  "devDependencies": {
22
- "@types/node": "20.10.0"
27
+ "@types/node": "20.11.10"
23
28
  },
24
29
  "dependencies": {
25
- "@markuplint/html-parser": "3.13.0",
26
- "@markuplint/ml-ast": "3.2.0",
27
- "@markuplint/ml-config": "3.14.0",
28
- "@markuplint/ml-core": "3.15.0",
29
- "@markuplint/ml-spec": "3.14.0",
30
- "@markuplint/parser-utils": "3.13.0",
31
- "@markuplint/selector": "3.14.0",
32
- "@markuplint/shared": "3.8.0",
33
- "cosmiconfig": "^8.3.6",
34
- "cosmiconfig-typescript-loader": "^5.0.0",
35
- "glob": "^10.3.10",
30
+ "@markuplint/html-parser": "4.0.0-alpha.10",
31
+ "@markuplint/ml-ast": "4.0.0-alpha.10",
32
+ "@markuplint/ml-config": "4.0.0-alpha.10",
33
+ "@markuplint/ml-core": "4.0.0-alpha.10",
34
+ "@markuplint/ml-spec": "4.0.0-alpha.10",
35
+ "@markuplint/parser-utils": "4.0.0-alpha.10",
36
+ "@markuplint/selector": "4.0.0-alpha.10",
37
+ "@markuplint/shared": "4.0.0-alpha.10",
38
+ "cosmiconfig": "^9.0.0",
39
+ "debug": "^4.3.4",
40
+ "glob": "^10.3.6",
36
41
  "ignore": "^5.3.0",
37
42
  "jsonc": "^2.0.0",
38
- "minimatch": "^9.0.3",
39
- "tslib": "^2.6.2"
43
+ "minimatch": "^9.0.3"
40
44
  },
41
- "gitHead": "b37b749d7ac0f9e6cbd022ee7031bc020c6677d3"
45
+ "gitHead": "b41153ea665aa8f091daf6114a06047f4ccb8350"
42
46
  }