@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
@@ -1,34 +1,34 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.load = exports.search = void 0;
4
- const tslib_1 = require("tslib");
5
- const path_1 = tslib_1.__importDefault(require("path"));
6
- const parser_utils_1 = require("@markuplint/parser-utils");
7
- const cosmiconfig_1 = require("cosmiconfig");
8
- const cosmiconfig_typescript_loader_1 = require("cosmiconfig-typescript-loader");
9
- const jsonc_1 = require("jsonc");
10
- const explorer = (0, cosmiconfig_1.cosmiconfig)('markuplint', {
1
+ import path from 'node:path';
2
+ import { ConfigParserError } from '@markuplint/parser-utils';
3
+ import { cosmiconfig, defaultLoaders } from 'cosmiconfig';
4
+ import { jsonc } from 'jsonc';
5
+ import { ConfigLoadError } from './config-load-error.js';
6
+ import { log } from './debug.js';
7
+ const searchLog = log.extend('search');
8
+ const explorer = cosmiconfig('markuplint', {
11
9
  loaders: {
12
- '.ts': (0, cosmiconfig_typescript_loader_1.TypeScriptLoader)(),
13
10
  noExt: ((path, content) => {
14
11
  try {
15
- return jsonc_1.jsonc.parse(content);
12
+ return jsonc.parse(content);
16
13
  }
17
14
  catch (error) {
18
15
  if (error instanceof Error && error.name === 'JSONError') {
19
- return cosmiconfig_1.defaultLoaders['noExt'](path, content);
16
+ return defaultLoaders['noExt'](path, content);
20
17
  }
21
18
  throw error;
22
19
  }
23
20
  }),
24
21
  },
22
+ searchStrategy: 'project',
25
23
  });
26
- async function search(dir, cacheClear) {
24
+ export async function search(filePath, cacheClear) {
27
25
  if (cacheClear) {
28
26
  explorer.clearCaches();
29
27
  }
30
- dir = path_1.default.dirname(dir);
31
- const result = await explorer.search(dir).catch(cacheConfigError(dir));
28
+ const dir = path.dirname(filePath);
29
+ searchLog('Search dir: %s', dir);
30
+ const result = await explorer.search(dir).catch(cacheConfigError(dir, filePath));
31
+ searchLog('Search result: %O', result);
32
32
  if (!result || result.isEmpty) {
33
33
  return null;
34
34
  }
@@ -37,39 +37,31 @@ async function search(dir, cacheClear) {
37
37
  config: result.config,
38
38
  };
39
39
  }
40
- exports.search = search;
41
- async function load(filePath, cacheClear) {
40
+ export async function load(filePath, cacheClear, referrer) {
42
41
  if (cacheClear) {
43
42
  explorer.clearCaches();
44
43
  }
45
- const result = await explorer.load(filePath).catch(cacheConfigError(filePath));
44
+ const result = await explorer.load(filePath).catch(cacheConfigError(filePath, referrer));
46
45
  if (!result || result.isEmpty) {
47
- return null;
46
+ return new ConfigLoadError('Config file is empty', filePath, referrer);
48
47
  }
49
48
  return {
50
49
  filePath: result.filepath,
51
50
  config: result.config,
52
51
  };
53
52
  }
54
- exports.load = load;
55
- class ConfigLoadError extends Error {
56
- constructor(message, filePath) {
57
- super(message + ` in ${filePath}`);
58
- this.name = 'ConfigLoadError';
59
- }
60
- }
61
- function cacheConfigError(fileOrDirPath) {
53
+ function cacheConfigError(fileOrDirPath, referrer) {
62
54
  return (reason) => {
63
- var _a;
64
55
  if (reason instanceof Error) {
65
56
  switch (reason.name) {
66
- case 'YAMLException':
67
- throw new parser_utils_1.ConfigParserError(reason.message, {
57
+ case 'YAMLException': {
58
+ throw new ConfigParserError(reason.message, {
68
59
  // @ts-ignore
69
- filePath: (_a = reason.filepath) !== null && _a !== void 0 ? _a : fileOrDirPath,
60
+ filePath: reason.filepath ?? fileOrDirPath,
70
61
  });
62
+ }
71
63
  }
72
- throw new ConfigLoadError(reason.message, fileOrDirPath);
64
+ throw new ConfigLoadError(reason.message, fileOrDirPath, referrer);
73
65
  }
74
66
  throw reason;
75
67
  };
package/lib/debug.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import debug from 'debug';
2
+ export type Log = debug.Debugger;
3
+ export declare const log: debug.Debugger;
package/lib/debug.js ADDED
@@ -0,0 +1,2 @@
1
+ import debug from 'debug';
2
+ export const log = debug('ml-fr');
@@ -0,0 +1 @@
1
+ export declare function forceImportJsonInModule(modPath: string): Promise<any>;
@@ -0,0 +1,31 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { log } from './debug.js';
4
+ const fLog = log.extend('force-import-json-in-module');
5
+ export async function forceImportJsonInModule(modPath) {
6
+ const error = await import(modPath).catch(error => error);
7
+ if (error instanceof Error) {
8
+ fLog('Error in forceImportJsonInModule: %O', error);
9
+ if (!('code' in error)) {
10
+ throw error;
11
+ }
12
+ if (error.code !== 'ERR_IMPORT_ASSERTION_TYPE_MISSING') {
13
+ throw error;
14
+ }
15
+ const searchPath = /module\s"([^"]+)"\sneeds/i.exec(error.message);
16
+ const absPath = searchPath?.[1] ?? null;
17
+ fLog('Extract path: %s', absPath);
18
+ if (!absPath) {
19
+ throw error;
20
+ }
21
+ const normalizePath = absPath
22
+ .replace(/^file:\/\//, '')
23
+ .replaceAll('/', path.sep)
24
+ // Windows
25
+ .replace(/^[/\\][a-z]:/i, '');
26
+ fLog('Find JSON file path: %s', normalizePath);
27
+ const fileContent = await readFile(normalizePath, { encoding: 'utf8' });
28
+ return JSON.parse(fileContent);
29
+ }
30
+ return error.default ?? error;
31
+ }
@@ -0,0 +1 @@
1
+ export declare function generalImport<T>(name: string): Promise<T | null>;
@@ -0,0 +1,40 @@
1
+ import { createRequire } from 'node:module';
2
+ import { log } from './debug.js';
3
+ const gLog = log.extend('general-import');
4
+ const cache = new Map();
5
+ const require = createRequire(import.meta.url);
6
+ export async function generalImport(name) {
7
+ if (cache.has(name)) {
8
+ return cache.get(name);
9
+ }
10
+ try {
11
+ const imported = await import(name);
12
+ const mod = imported?.default ?? imported ?? null;
13
+ cache.set(name, mod);
14
+ return mod;
15
+ }
16
+ catch (error) {
17
+ if (
18
+ // @ts-ignore
19
+ 'code' in error &&
20
+ // @ts-ignore
21
+ error.code === 'ERR_IMPORT_ASSERTION_TYPE_MISSING') {
22
+ try {
23
+ const mod = require(name) ?? null;
24
+ cache.set(name, mod);
25
+ return mod;
26
+ }
27
+ catch (error) {
28
+ if (error instanceof Error && /^parse failure/i.test(error.message)) {
29
+ gLog('Error in `createRequire(import.meta.url)()`: %O', error);
30
+ cache.set(name, null);
31
+ return null;
32
+ }
33
+ gLog('Error in generalImport: %O', error);
34
+ }
35
+ }
36
+ gLog('Error in `import()`: %O', error);
37
+ cache.set(name, null);
38
+ return null;
39
+ }
40
+ }
@@ -0,0 +1,2 @@
1
+ import type { Config } from '@markuplint/ml-config';
2
+ export declare function getPreset(name: string): Promise<Config>;
@@ -0,0 +1,13 @@
1
+ import { forceImportJsonInModule } from './force-import-json-in-module.js';
2
+ const cache = new Map();
3
+ export async function getPreset(name) {
4
+ if (cache.has(name)) {
5
+ return cache.get(name);
6
+ }
7
+ const json = await forceImportJsonInModule(`@markuplint/config-presets/preset.${name}.json`);
8
+ if (json instanceof Error) {
9
+ throw new ReferenceError(`Preset markuplint:${name} is not found`);
10
+ }
11
+ cache.set(name, json);
12
+ return json;
13
+ }
package/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export type { MLFile } from './ml-file';
2
- export * from './config-provider';
3
- export * from './resolve-files';
4
- export * from './resolve-parser';
5
- export * from './resolve-rules';
6
- export * from './resolve-specs';
7
- export * from './types';
1
+ export type { MLFile } from './ml-file/index.js';
2
+ export * from './config-provider.js';
3
+ export * from './resolve-files.js';
4
+ export * from './resolve-parser.js';
5
+ export * from './resolve-rules.js';
6
+ export * from './resolve-specs.js';
7
+ export * from './types.js';
package/lib/index.js CHANGED
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./config-provider"), exports);
5
- tslib_1.__exportStar(require("./resolve-files"), exports);
6
- tslib_1.__exportStar(require("./resolve-parser"), exports);
7
- tslib_1.__exportStar(require("./resolve-rules"), exports);
8
- tslib_1.__exportStar(require("./resolve-specs"), exports);
9
- tslib_1.__exportStar(require("./types"), exports);
1
+ export * from './config-provider.js';
2
+ export * from './resolve-files.js';
3
+ export * from './resolve-parser.js';
4
+ export * from './resolve-rules.js';
5
+ export * from './resolve-specs.js';
6
+ export * from './types.js';
@@ -0,0 +1 @@
1
+ export declare function isPluginModuleName(name: string): boolean;
@@ -0,0 +1,3 @@
1
+ export function isPluginModuleName(name) {
2
+ return /^plugin:/i.test(name);
3
+ }
@@ -0,0 +1 @@
1
+ export declare function isPresetModuleName(name: string): boolean;
@@ -0,0 +1,3 @@
1
+ export function isPresetModuleName(name) {
2
+ return /^markuplint:/i.test(name);
3
+ }
@@ -1,2 +1,2 @@
1
- import { MLFile } from './ml-file';
1
+ import { MLFile } from './ml-file.js';
2
2
  export declare function getAnonymousFile(context: string, workspace?: string, name?: string): MLFile;
@@ -1,13 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAnonymousFile = void 0;
4
- const ml_file_1 = require("./ml-file");
5
- function getAnonymousFile(context, workspace, name) {
6
- const file = new ml_file_1.MLFile({
1
+ import { MLFile } from './ml-file.js';
2
+ export function getAnonymousFile(context, workspace, name) {
3
+ const file = new MLFile({
7
4
  sourceCode: context,
8
5
  workspace,
9
6
  name,
10
7
  });
11
8
  return file;
12
9
  }
13
- exports.getAnonymousFile = getAnonymousFile;
@@ -1,2 +1,2 @@
1
- import { MLFile } from './ml-file';
1
+ import { MLFile } from './ml-file.js';
2
2
  export declare function getFile(filePath: string): MLFile;
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFile = void 0;
4
- const ml_file_1 = require("./ml-file");
5
- function getFile(filePath) {
6
- const file = new ml_file_1.MLFile(filePath);
1
+ import { MLFile } from './ml-file.js';
2
+ export function getFile(filePath) {
3
+ const file = new MLFile(filePath);
7
4
  return file;
8
5
  }
9
- exports.getFile = getFile;
@@ -1,4 +1,4 @@
1
- import type { MLFile } from './ml-file';
1
+ import type { MLFile } from './ml-file.js';
2
2
  /**
3
3
  * Get files
4
4
  *
@@ -6,4 +6,4 @@ import type { MLFile } from './ml-file';
6
6
  *
7
7
  * @param filePathOrGlob
8
8
  */
9
- export declare function getFiles(filePathOrGlob: string): Promise<MLFile[]>;
9
+ export declare function getFiles(filePathOrGlob: string, ignoreGlob?: string): Promise<MLFile[]>;
@@ -1,8 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFiles = void 0;
4
- const glob_1 = require("glob");
5
- const get_file_1 = require("./get-file");
1
+ import { glob } from 'glob';
2
+ import { minimatch } from 'minimatch';
3
+ import { getFile } from './get-file.js';
6
4
  /**
7
5
  * Get files
8
6
  *
@@ -10,8 +8,8 @@ const get_file_1 = require("./get-file");
10
8
  *
11
9
  * @param filePathOrGlob
12
10
  */
13
- async function getFiles(filePathOrGlob) {
14
- const fileList = await (0, glob_1.glob)(filePathOrGlob, {}).catch(() => []);
15
- return fileList.map(fileName => (0, get_file_1.getFile)(fileName));
11
+ export async function getFiles(filePathOrGlob, ignoreGlob) {
12
+ const fileList = await glob(filePathOrGlob, {}).catch(() => []);
13
+ const filtered = fileList.filter(fileName => !minimatch(fileName, ignoreGlob ?? ''));
14
+ return filtered.map(fileName => getFile(fileName));
16
15
  }
17
- 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,24 +1,24 @@
1
- import type { Target } from '../types';
1
+ import type { Target } from '../types.js';
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
- ignored(globPath: string | readonly string[]): boolean;
18
- isExist(): Promise<boolean>;
19
- isFile(): Promise<boolean>;
20
- matches(globPath: string): boolean;
21
- setCode(code: string): void;
22
- private _fetch;
23
- 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
+ ignored(globPath: string | readonly string[]): any;
18
+ isExist(): Promise<boolean>;
19
+ isFile(): Promise<boolean>;
20
+ matches(globPath: string): boolean;
21
+ setCode(code: string): void;
22
+ private _fetch;
23
+ private _stat;
24
24
  }
@@ -1,15 +1,21 @@
1
- "use strict";
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
2
12
  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 ignore_1 = tslib_1.__importDefault(require("ignore"));
9
- const minimatch_1 = require("minimatch");
10
- class MLFile {
13
+ import { promises as fs } from 'node:fs';
14
+ import path from 'node:path';
15
+ import ignore from 'ignore';
16
+ import { minimatch } from 'minimatch';
17
+ export class MLFile {
11
18
  constructor(target) {
12
- var _a, _b;
13
19
  _MLFile_basename.set(this, void 0);
14
20
  _MLFile_code.set(this, void 0);
15
21
  _MLFile_dirname.set(this, void 0);
@@ -21,25 +27,25 @@ class MLFile {
21
27
  _MLFile_stat.set(this, undefined);
22
28
  _MLFile_type.set(this, void 0);
23
29
  if (typeof target === 'string') {
24
- tslib_1.__classPrivateFieldSet(this, _MLFile_basename, path_1.default.basename(target), "f");
25
- tslib_1.__classPrivateFieldSet(this, _MLFile_dirname, path_1.default.dirname(target), "f");
26
- tslib_1.__classPrivateFieldSet(this, _MLFile_code, null, "f");
27
- tslib_1.__classPrivateFieldSet(this, _MLFile_type, 'file-base', "f");
30
+ __classPrivateFieldSet(this, _MLFile_basename, path.basename(target), "f");
31
+ __classPrivateFieldSet(this, _MLFile_dirname, path.dirname(target), "f");
32
+ __classPrivateFieldSet(this, _MLFile_code, null, "f");
33
+ __classPrivateFieldSet(this, _MLFile_type, 'file-base', "f");
28
34
  return;
29
35
  }
30
- if (!target.workspace && target.name && path_1.default.isAbsolute(target.name)) {
31
- tslib_1.__classPrivateFieldSet(this, _MLFile_basename, path_1.default.basename(target.name), "f");
32
- tslib_1.__classPrivateFieldSet(this, _MLFile_dirname, path_1.default.dirname(target.name), "f");
36
+ if (!target.workspace && target.name && path.isAbsolute(target.name)) {
37
+ __classPrivateFieldSet(this, _MLFile_basename, path.basename(target.name), "f");
38
+ __classPrivateFieldSet(this, _MLFile_dirname, path.dirname(target.name), "f");
33
39
  }
34
40
  else {
35
- tslib_1.__classPrivateFieldSet(this, _MLFile_basename, (_a = target.name) !== null && _a !== void 0 ? _a : '<AnonymousFile>', "f");
36
- tslib_1.__classPrivateFieldSet(this, _MLFile_dirname, (_b = target.workspace) !== null && _b !== void 0 ? _b : process.cwd(), "f");
41
+ __classPrivateFieldSet(this, _MLFile_basename, target.name ?? '<AnonymousFile>', "f");
42
+ __classPrivateFieldSet(this, _MLFile_dirname, target.workspace ?? process.cwd(), "f");
37
43
  }
38
- tslib_1.__classPrivateFieldSet(this, _MLFile_code, target.sourceCode, "f");
39
- tslib_1.__classPrivateFieldSet(this, _MLFile_type, 'code-base', "f");
44
+ __classPrivateFieldSet(this, _MLFile_code, target.sourceCode, "f");
45
+ __classPrivateFieldSet(this, _MLFile_type, 'code-base', "f");
40
46
  }
41
47
  get dirname() {
42
- return tslib_1.__classPrivateFieldGet(this, _MLFile_dirname, "f");
48
+ return __classPrivateFieldGet(this, _MLFile_dirname, "f");
43
49
  }
44
50
  /**
45
51
  * Normalized `MLFile.dirname`
@@ -54,16 +60,16 @@ class MLFile {
54
60
  return pathNormalize(this.path);
55
61
  }
56
62
  get path() {
57
- return path_1.default.resolve(tslib_1.__classPrivateFieldGet(this, _MLFile_dirname, "f"), tslib_1.__classPrivateFieldGet(this, _MLFile_basename, "f"));
63
+ return path.resolve(__classPrivateFieldGet(this, _MLFile_dirname, "f"), __classPrivateFieldGet(this, _MLFile_basename, "f"));
58
64
  }
59
65
  async dirExists() {
60
- return !!(await stat(tslib_1.__classPrivateFieldGet(this, _MLFile_dirname, "f")));
66
+ return !!(await stat(__classPrivateFieldGet(this, _MLFile_dirname, "f")));
61
67
  }
62
68
  async getCode() {
63
- if (tslib_1.__classPrivateFieldGet(this, _MLFile_code, "f") != null) {
64
- return tslib_1.__classPrivateFieldGet(this, _MLFile_code, "f");
69
+ if (__classPrivateFieldGet(this, _MLFile_code, "f") != null) {
70
+ return __classPrivateFieldGet(this, _MLFile_code, "f");
65
71
  }
66
- if (tslib_1.__classPrivateFieldGet(this, _MLFile_type, "f") === 'file-base' && (await this.isExist())) {
72
+ if (__classPrivateFieldGet(this, _MLFile_type, "f") === 'file-base' && (await this.isExist())) {
67
73
  return await this._fetch();
68
74
  }
69
75
  return '';
@@ -71,61 +77,61 @@ class MLFile {
71
77
  ignored(globPath) {
72
78
  globPath = typeof globPath === 'string' ? [globPath] : globPath;
73
79
  const normalizedPaths = globPath.map(p => pathNormalize(p, true));
74
- const ig = (0, ignore_1.default)().add(normalizedPaths);
80
+ // @ts-ignore
81
+ const ig = ignore().add(normalizedPaths);
75
82
  const ignored = ig.ignores(pathNormalize(this.nPath, true));
76
83
  return ignored;
77
84
  }
78
85
  async isExist() {
79
- if (tslib_1.__classPrivateFieldGet(this, _MLFile_type, "f") === 'code-base') {
86
+ if (__classPrivateFieldGet(this, _MLFile_type, "f") === 'code-base') {
80
87
  return true;
81
88
  }
82
89
  const stat = await this._stat();
83
90
  return !!stat;
84
91
  }
85
92
  async isFile() {
86
- if (tslib_1.__classPrivateFieldGet(this, _MLFile_type, "f") === 'code-base') {
93
+ if (__classPrivateFieldGet(this, _MLFile_type, "f") === 'code-base') {
87
94
  return true;
88
95
  }
89
96
  const stat = await this._stat();
90
97
  return !!stat && stat.isFile();
91
98
  }
92
99
  matches(globPath) {
93
- return (0, minimatch_1.minimatch)(this.nPath, pathNormalize(globPath));
100
+ return minimatch(this.nPath, pathNormalize(globPath));
94
101
  }
95
102
  setCode(code) {
96
- if (tslib_1.__classPrivateFieldGet(this, _MLFile_type, "f") === 'file-base') {
103
+ if (__classPrivateFieldGet(this, _MLFile_type, "f") === 'file-base') {
97
104
  throw new Error(`This file object is readonly (File-base: ${this.path})`);
98
105
  }
99
- tslib_1.__classPrivateFieldSet(this, _MLFile_code, code, "f");
106
+ __classPrivateFieldSet(this, _MLFile_code, code, "f");
100
107
  }
101
108
  async _fetch() {
102
- const code = await fs_1.promises.readFile(this.path, { encoding: 'utf-8' });
103
- tslib_1.__classPrivateFieldSet(this, _MLFile_code, code, "f");
109
+ const code = await fs.readFile(this.path, { encoding: 'utf8' });
110
+ __classPrivateFieldSet(this, _MLFile_code, code, "f");
104
111
  return code;
105
112
  }
106
113
  async _stat() {
107
- if (tslib_1.__classPrivateFieldGet(this, _MLFile_stat, "f")) {
108
- return tslib_1.__classPrivateFieldGet(this, _MLFile_stat, "f");
114
+ if (__classPrivateFieldGet(this, _MLFile_stat, "f")) {
115
+ return __classPrivateFieldGet(this, _MLFile_stat, "f");
109
116
  }
110
- tslib_1.__classPrivateFieldSet(this, _MLFile_stat, await stat(this.path), "f");
111
- return tslib_1.__classPrivateFieldGet(this, _MLFile_stat, "f");
117
+ __classPrivateFieldSet(this, _MLFile_stat, await stat(this.path), "f");
118
+ return __classPrivateFieldGet(this, _MLFile_stat, "f");
112
119
  }
113
120
  }
114
- exports.MLFile = MLFile;
115
121
  _MLFile_basename = new WeakMap(), _MLFile_code = new WeakMap(), _MLFile_dirname = new WeakMap(), _MLFile_stat = new WeakMap(), _MLFile_type = new WeakMap();
116
122
  async function stat(filePath) {
117
123
  try {
118
- return await fs_1.promises.stat(filePath);
124
+ return await fs.stat(filePath);
119
125
  }
120
- catch (err) {
126
+ catch (error) {
121
127
  if (
122
128
  // @ts-ignore
123
- 'code' in err &&
129
+ 'code' in error &&
124
130
  // @ts-ignore
125
- err.code === 'ENOENT') {
131
+ error.code === 'ENOENT') {
126
132
  return null;
127
133
  }
128
- throw err;
134
+ throw error;
129
135
  }
130
136
  }
131
137
  function pathNormalize(filePath, relative = false) {
@@ -134,14 +140,14 @@ function pathNormalize(filePath, relative = false) {
134
140
  filePath = filePath.slice(1);
135
141
  }
136
142
  // Remove the local disk scheme of Windows OS
137
- if (path_1.default.isAbsolute(filePath)) {
143
+ if (path.isAbsolute(filePath)) {
138
144
  filePath = filePath.replace(/^[a-z]+:/i, '');
139
145
  if (relative) {
140
- filePath = path_1.default.relative(path_1.default.sep, filePath);
146
+ filePath = path.relative(path.sep, filePath);
141
147
  }
142
148
  }
143
149
  // Replace the separator of Windows OS
144
- filePath = filePath.split(path_1.default.sep).join('/');
150
+ filePath = filePath.split(path.sep).join('/');
145
151
  if (hasBang) {
146
152
  filePath = `!${filePath}`;
147
153
  }
@@ -0,0 +1 @@
1
+ export declare function moduleExists(name: string): Promise<boolean>;