@markuplint/file-resolver 3.2.0 → 3.3.1
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.
- package/lib/auto-load-rules.d.ts +2 -2
- package/lib/config-provider.d.ts +8 -8
- package/lib/cosmiconfig.d.ts +12 -6
- package/lib/ml-file/ml-file.d.ts +20 -20
- package/lib/pretender-provider.d.ts +22 -0
- package/lib/pretender-provider.js +146 -0
- package/lib/resolve-parser.d.ts +9 -5
- package/lib/resolve-pretenders.d.ts +1 -4
- package/lib/resolve-pretenders.js +3 -38
- package/lib/resolve-rules.d.ts +9 -5
- package/lib/resolve-specs.d.ts +5 -2
- package/lib/types.d.ts +20 -18
- package/lib/watcher.d.ts +15 -0
- package/lib/watcher.js +64 -0
- package/package.json +10 -7
package/lib/auto-load-rules.d.ts
CHANGED
package/lib/config-provider.d.ts
CHANGED
|
@@ -2,12 +2,12 @@ import type { MLFile } from './ml-file';
|
|
|
2
2
|
import type { ConfigSet, Nullable } from './types';
|
|
3
3
|
import type { Config } from '@markuplint/ml-config';
|
|
4
4
|
export declare class ConfigProvider {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
#private;
|
|
6
|
+
resolve(targetFile: MLFile, names: Nullable<string>[], cache?: boolean): Promise<ConfigSet>;
|
|
7
|
+
search(targetFile: MLFile): Promise<string | null>;
|
|
8
|
+
set(config: Config, key?: string): string;
|
|
9
|
+
private _load;
|
|
10
|
+
private _mergeConfigs;
|
|
11
|
+
private _pathResolve;
|
|
12
|
+
private _recursiveLoad;
|
|
13
13
|
}
|
package/lib/cosmiconfig.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { LoaderSync } from 'cosmiconfig';
|
|
2
2
|
type CosmiConfig = ReturnType<LoaderSync>;
|
|
3
|
-
export declare function search<T = CosmiConfig>(
|
|
4
|
-
|
|
5
|
-
|
|
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>(
|
|
8
|
-
|
|
9
|
-
|
|
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 {};
|
package/lib/ml-file/ml-file.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import type { Target } from '../types';
|
|
2
2
|
export declare class MLFile {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { OptimizedConfig, Pretender } from '@markuplint/ml-config';
|
|
2
|
+
type PretendersConfig = OptimizedConfig['pretenders'];
|
|
3
|
+
type PretenderWatchCallback = (pretenders: Pretender[]) => void;
|
|
4
|
+
export declare class PretenderProvider {
|
|
5
|
+
#private;
|
|
6
|
+
getPretenders(): Promise<Pretender[]>;
|
|
7
|
+
setConfig(config: PretendersConfig): Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* Stops watching.
|
|
10
|
+
* It does nothing if it is not in watching mode or it doesn't have scanning files.
|
|
11
|
+
*/
|
|
12
|
+
unwatch(): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Starts watching related files.
|
|
15
|
+
* It passes the results of pretenders to callback every file changed.
|
|
16
|
+
* It requires calling `setConfig` method in advance before calling this.
|
|
17
|
+
*
|
|
18
|
+
* @param callback
|
|
19
|
+
*/
|
|
20
|
+
watch(callback: PretenderWatchCallback): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _PretenderProvider_staticData, _PretenderProvider_scanners, _PretenderProvider_watchCallback, _Scanner_cache, _Scanner_options, _Scanner_watcher;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.PretenderProvider = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const cache_1 = require("@markuplint/cache");
|
|
7
|
+
const watcher_1 = require("./watcher");
|
|
8
|
+
const DIDNT_SPECIFY_CONFIG_ERROR_MSG = 'Cannot return pretenders because it did not specify the configuration yet. It might be the wrong order to call this method';
|
|
9
|
+
class PretenderProvider {
|
|
10
|
+
constructor() {
|
|
11
|
+
_PretenderProvider_staticData.set(this, null);
|
|
12
|
+
_PretenderProvider_scanners.set(this, []);
|
|
13
|
+
_PretenderProvider_watchCallback.set(this, null);
|
|
14
|
+
}
|
|
15
|
+
async getPretenders() {
|
|
16
|
+
if (!tslib_1.__classPrivateFieldGet(this, _PretenderProvider_staticData, "f")) {
|
|
17
|
+
throw new ReferenceError(DIDNT_SPECIFY_CONFIG_ERROR_MSG);
|
|
18
|
+
}
|
|
19
|
+
const result = [...tslib_1.__classPrivateFieldGet(this, _PretenderProvider_staticData, "f")];
|
|
20
|
+
for (const scanner of tslib_1.__classPrivateFieldGet(this, _PretenderProvider_scanners, "f")) {
|
|
21
|
+
const pretenders = await scanner.scan();
|
|
22
|
+
result.push(...pretenders);
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
async setConfig(config) {
|
|
27
|
+
const [data, scanConfig] = await resolvePretendersConfig(config);
|
|
28
|
+
tslib_1.__classPrivateFieldSet(this, _PretenderProvider_staticData, data, "f");
|
|
29
|
+
if (scanConfig) {
|
|
30
|
+
for (const scan of scanConfig) {
|
|
31
|
+
if (scan.type === 'jsx') {
|
|
32
|
+
const { jsxScanner } = await Promise.resolve().then(() => tslib_1.__importStar(require('@markuplint/pretenders/lib/jsx')));
|
|
33
|
+
const scanner = new Scanner(scan.type, scan.files, jsxScanner, scan.options);
|
|
34
|
+
tslib_1.__classPrivateFieldGet(this, _PretenderProvider_scanners, "f").push(scanner);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// It regards to be enabled watch mode if it has `#watchCallback`.
|
|
39
|
+
// And call the watch method then add the callback to each scanner.
|
|
40
|
+
if (tslib_1.__classPrivateFieldGet(this, _PretenderProvider_watchCallback, "f")) {
|
|
41
|
+
await this.watch(tslib_1.__classPrivateFieldGet(this, _PretenderProvider_watchCallback, "f"));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Stops watching.
|
|
46
|
+
* It does nothing if it is not in watching mode or it doesn't have scanning files.
|
|
47
|
+
*/
|
|
48
|
+
async unwatch() {
|
|
49
|
+
for (const scanner of tslib_1.__classPrivateFieldGet(this, _PretenderProvider_scanners, "f")) {
|
|
50
|
+
await scanner.unwatch();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Starts watching related files.
|
|
55
|
+
* It passes the results of pretenders to callback every file changed.
|
|
56
|
+
* It requires calling `setConfig` method in advance before calling this.
|
|
57
|
+
*
|
|
58
|
+
* @param callback
|
|
59
|
+
*/
|
|
60
|
+
async watch(callback) {
|
|
61
|
+
tslib_1.__classPrivateFieldSet(this, _PretenderProvider_watchCallback, callback, "f");
|
|
62
|
+
for (const scanner of tslib_1.__classPrivateFieldGet(this, _PretenderProvider_scanners, "f")) {
|
|
63
|
+
await scanner.watch(async () => {
|
|
64
|
+
var _a;
|
|
65
|
+
if (!tslib_1.__classPrivateFieldGet(this, _PretenderProvider_staticData, "f")) {
|
|
66
|
+
throw new ReferenceError(DIDNT_SPECIFY_CONFIG_ERROR_MSG);
|
|
67
|
+
}
|
|
68
|
+
const allPretenders = await this.getPretenders();
|
|
69
|
+
(_a = tslib_1.__classPrivateFieldGet(this, _PretenderProvider_watchCallback, "f")) === null || _a === void 0 ? void 0 : _a.call(this, allPretenders);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.PretenderProvider = PretenderProvider;
|
|
75
|
+
_PretenderProvider_staticData = new WeakMap(), _PretenderProvider_scanners = new WeakMap(), _PretenderProvider_watchCallback = new WeakMap();
|
|
76
|
+
class Scanner {
|
|
77
|
+
constructor(type, glob, method, options) {
|
|
78
|
+
_Scanner_cache.set(this, void 0);
|
|
79
|
+
_Scanner_options.set(this, void 0);
|
|
80
|
+
_Scanner_watcher.set(this, null);
|
|
81
|
+
tslib_1.__classPrivateFieldSet(this, _Scanner_options, options, "f");
|
|
82
|
+
tslib_1.__classPrivateFieldSet(this, _Scanner_cache, new cache_1.Cache(type, glob, files => {
|
|
83
|
+
return method(Array.from(files), options);
|
|
84
|
+
}), "f");
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Scans component files.
|
|
88
|
+
*
|
|
89
|
+
* @param newFileList
|
|
90
|
+
* @returns
|
|
91
|
+
*/
|
|
92
|
+
async scan() {
|
|
93
|
+
const pretenders = await tslib_1.__classPrivateFieldGet(this, _Scanner_cache, "f").get();
|
|
94
|
+
return pretenders;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Stops watching.
|
|
98
|
+
* It does nothing if it is not in watching mode.
|
|
99
|
+
*/
|
|
100
|
+
async unwatch() {
|
|
101
|
+
var _a;
|
|
102
|
+
await ((_a = tslib_1.__classPrivateFieldGet(this, _Scanner_watcher, "f")) === null || _a === void 0 ? void 0 : _a.close());
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Starts watching related files.
|
|
106
|
+
* It passes the results of pretenders to callback every file changed.
|
|
107
|
+
*
|
|
108
|
+
* @param callback
|
|
109
|
+
*/
|
|
110
|
+
async watch(callback) {
|
|
111
|
+
tslib_1.__classPrivateFieldSet(this, _Scanner_watcher, await watcher_1.Watcher.create(tslib_1.__classPrivateFieldGet(this, _Scanner_cache, "f").glob, tslib_1.__classPrivateFieldGet(this, _Scanner_options, "f")), "f");
|
|
112
|
+
tslib_1.__classPrivateFieldGet(this, _Scanner_watcher, "f").addChangeListener(async (file, type) => {
|
|
113
|
+
const pretenders = type === 'unlink' ? await tslib_1.__classPrivateFieldGet(this, _Scanner_cache, "f").delete(file) : await tslib_1.__classPrivateFieldGet(this, _Scanner_cache, "f").update(file);
|
|
114
|
+
if (!pretenders) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
callback();
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
_Scanner_cache = new WeakMap(), _Scanner_options = new WeakMap(), _Scanner_watcher = new WeakMap();
|
|
122
|
+
function resolvePretendersConfig(config) {
|
|
123
|
+
if (!config) {
|
|
124
|
+
return Promise.resolve([[], []]);
|
|
125
|
+
}
|
|
126
|
+
const data = [];
|
|
127
|
+
if (config.files) {
|
|
128
|
+
for (const file of config.files) {
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
130
|
+
const pretenderFile = require(file);
|
|
131
|
+
data.push(...pretenderFile.data);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// Experimental
|
|
135
|
+
if (config.imports) {
|
|
136
|
+
for (const module of config.imports) {
|
|
137
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
138
|
+
const pretenderFile = require(`${module}/pretenders.json`);
|
|
139
|
+
data.push(...pretenderFile.data);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (config.data) {
|
|
143
|
+
data.push(...config.data);
|
|
144
|
+
}
|
|
145
|
+
return Promise.resolve([data, config.scan]);
|
|
146
|
+
}
|
package/lib/resolve-parser.d.ts
CHANGED
|
@@ -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(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
export declare function resolveParser(
|
|
5
|
+
file: MLFile,
|
|
6
|
+
parserConfig?: ParserConfig,
|
|
7
|
+
parserOptions?: ParserOptions,
|
|
8
|
+
): Promise<{
|
|
9
|
+
parserModName: string;
|
|
10
|
+
parser: MLMarkupLanguageParser;
|
|
11
|
+
parserOptions: ParserOptions;
|
|
12
|
+
matched: boolean;
|
|
9
13
|
}>;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import type { OptimizedConfig, Pretender } from '@markuplint/ml-config';
|
|
2
|
-
import { PretenderScanner } from '@markuplint/pretenders';
|
|
3
2
|
type PretendersConfig = OptimizedConfig['pretenders'];
|
|
4
|
-
export declare function resolvePretenders(
|
|
5
|
-
config: PretendersConfig,
|
|
6
|
-
): Promise<[data: Pretender[], scanners: PretenderScanner[]]>;
|
|
3
|
+
export declare function resolvePretenders(config: PretendersConfig): Promise<Pretender[]>;
|
|
7
4
|
export {};
|
|
@@ -1,37 +1,11 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.resolvePretenders = void 0;
|
|
27
|
-
const pretenders_1 = require("@markuplint/pretenders");
|
|
28
|
-
const utils_1 = require("./utils");
|
|
29
4
|
async function resolvePretenders(config) {
|
|
30
5
|
if (!config) {
|
|
31
|
-
return [
|
|
6
|
+
return [];
|
|
32
7
|
}
|
|
33
8
|
const data = [];
|
|
34
|
-
const scanners = [];
|
|
35
9
|
if (config.files) {
|
|
36
10
|
for (const file of config.files) {
|
|
37
11
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
@@ -50,16 +24,7 @@ async function resolvePretenders(config) {
|
|
|
50
24
|
if (config.data) {
|
|
51
25
|
data.push(...config.data);
|
|
52
26
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (scan.type === 'jsx') {
|
|
56
|
-
const { scanJSX } = await Promise.resolve().then(() => __importStar(require('@markuplint/pretenders/lib/jsx')));
|
|
57
|
-
const files = await (0, utils_1.asyncGlob)(scan.files);
|
|
58
|
-
const scanner = new pretenders_1.PretenderScanner(files, scan.options, scanJSX);
|
|
59
|
-
scanners.push(scanner);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return [data, scanners];
|
|
27
|
+
// It wraps `Promise` currently due to needing to use `import()` someday.
|
|
28
|
+
return await Promise.resolve(data);
|
|
64
29
|
}
|
|
65
30
|
exports.resolvePretenders = resolvePretenders;
|
package/lib/resolve-rules.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { AnyMLRule, Ruleset, Plugin } from '@markuplint/ml-core';
|
|
2
2
|
import { MLRule } from '@markuplint/ml-core';
|
|
3
|
-
export declare function resolveRules(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export declare function resolveRules(
|
|
4
|
+
plugins: Plugin[],
|
|
5
|
+
ruleset: Ruleset,
|
|
6
|
+
importPreset: boolean,
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated
|
|
9
|
+
*/
|
|
10
|
+
autoLoad: boolean,
|
|
11
|
+
): Promise<AnyMLRule[] | MLRule<any, any>[]>;
|
package/lib/resolve-specs.d.ts
CHANGED
|
@@ -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(
|
|
34
|
-
|
|
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
|
@@ -2,22 +2,24 @@ import type { Config } from '@markuplint/ml-config';
|
|
|
2
2
|
import type { Plugin } from '@markuplint/ml-core';
|
|
3
3
|
export type Nullable<T> = T | null | undefined;
|
|
4
4
|
export interface ConfigSet {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
config: Config;
|
|
6
|
+
plugins: Plugin[];
|
|
7
|
+
files: Set<string>;
|
|
8
|
+
errs: Error[];
|
|
9
9
|
}
|
|
10
|
-
export type Target =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
10
|
+
export type Target =
|
|
11
|
+
| string
|
|
12
|
+
| {
|
|
13
|
+
/**
|
|
14
|
+
* Target source code of evaluation
|
|
15
|
+
*/
|
|
16
|
+
sourceCode: string;
|
|
17
|
+
/**
|
|
18
|
+
* File names when `sourceCodes`
|
|
19
|
+
*/
|
|
20
|
+
name?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Workspace path when `sourceCodes`
|
|
23
|
+
*/
|
|
24
|
+
workspace?: string;
|
|
25
|
+
};
|
package/lib/watcher.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type Options = {
|
|
2
|
+
cwd?: string;
|
|
3
|
+
};
|
|
4
|
+
type ChangeListener = (this: Watcher, filePath: string, type: 'change' | 'add' | 'unlink') => void;
|
|
5
|
+
export declare class Watcher {
|
|
6
|
+
#private;
|
|
7
|
+
static create(pattern: string, options?: Options): Promise<Watcher>;
|
|
8
|
+
private constructor();
|
|
9
|
+
get files(): string[];
|
|
10
|
+
addChangeListener(changeListener: ChangeListener): void;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
private onEvent;
|
|
13
|
+
private update;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
package/lib/watcher.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _Watcher_changeListener, _Watcher_cwd, _Watcher_filesObserver;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Watcher = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
7
|
+
const chokidar_1 = require("chokidar");
|
|
8
|
+
const watcherOptions = {
|
|
9
|
+
persistent: true,
|
|
10
|
+
ignored: ['**/.git/**/*', '**/node_modules/**/*'],
|
|
11
|
+
};
|
|
12
|
+
class Watcher {
|
|
13
|
+
static async create(pattern, options) {
|
|
14
|
+
const watcher = new Watcher(options);
|
|
15
|
+
await watcher.update(pattern);
|
|
16
|
+
return watcher;
|
|
17
|
+
}
|
|
18
|
+
constructor(options) {
|
|
19
|
+
var _a;
|
|
20
|
+
_Watcher_changeListener.set(this, null);
|
|
21
|
+
_Watcher_cwd.set(this, void 0);
|
|
22
|
+
_Watcher_filesObserver.set(this, new chokidar_1.FSWatcher(watcherOptions));
|
|
23
|
+
tslib_1.__classPrivateFieldSet(this, _Watcher_cwd, (_a = options === null || options === void 0 ? void 0 : options.cwd) !== null && _a !== void 0 ? _a : process.cwd(), "f");
|
|
24
|
+
}
|
|
25
|
+
get files() {
|
|
26
|
+
return Object.entries(tslib_1.__classPrivateFieldGet(this, _Watcher_filesObserver, "f").getWatched())
|
|
27
|
+
.map(([dir, files]) => files.map(file => node_path_1.default.join(dir, file)))
|
|
28
|
+
.flat()
|
|
29
|
+
.sort();
|
|
30
|
+
}
|
|
31
|
+
addChangeListener(changeListener) {
|
|
32
|
+
tslib_1.__classPrivateFieldSet(this, _Watcher_changeListener, changeListener, "f");
|
|
33
|
+
}
|
|
34
|
+
async close() {
|
|
35
|
+
await tslib_1.__classPrivateFieldGet(this, _Watcher_filesObserver, "f").close();
|
|
36
|
+
}
|
|
37
|
+
onEvent(eventName, filePath) {
|
|
38
|
+
var _a;
|
|
39
|
+
switch (eventName) {
|
|
40
|
+
case 'change':
|
|
41
|
+
case 'add':
|
|
42
|
+
case 'unlink':
|
|
43
|
+
(_a = tslib_1.__classPrivateFieldGet(this, _Watcher_changeListener, "f")) === null || _a === void 0 ? void 0 : _a.call(this, filePath, eventName);
|
|
44
|
+
break;
|
|
45
|
+
default:
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async update(pattern) {
|
|
50
|
+
const absPattern = node_path_1.default.isAbsolute(pattern) ? pattern : node_path_1.default.resolve(tslib_1.__classPrivateFieldGet(this, _Watcher_cwd, "f"), pattern);
|
|
51
|
+
await tslib_1.__classPrivateFieldGet(this, _Watcher_filesObserver, "f").close();
|
|
52
|
+
tslib_1.__classPrivateFieldGet(this, _Watcher_filesObserver, "f").add(absPattern);
|
|
53
|
+
return new Promise(resolve => {
|
|
54
|
+
const onReady = () => {
|
|
55
|
+
tslib_1.__classPrivateFieldGet(this, _Watcher_filesObserver, "f").on('all', this.onEvent.bind(this));
|
|
56
|
+
tslib_1.__classPrivateFieldGet(this, _Watcher_filesObserver, "f").off('ready', onReady);
|
|
57
|
+
resolve();
|
|
58
|
+
};
|
|
59
|
+
tslib_1.__classPrivateFieldGet(this, _Watcher_filesObserver, "f").on('ready', onReady);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.Watcher = Watcher;
|
|
64
|
+
_Watcher_changeListener = new WeakMap(), _Watcher_cwd = new WeakMap(), _Watcher_filesObserver = new WeakMap();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/file-resolver",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.1",
|
|
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>",
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
"publishConfig": {
|
|
12
12
|
"access": "public"
|
|
13
13
|
},
|
|
14
|
+
"typedoc": {
|
|
15
|
+
"entryPoint": "./src/index.ts"
|
|
16
|
+
},
|
|
14
17
|
"scripts": {
|
|
15
18
|
"build": "tsc",
|
|
16
19
|
"clean": "tsc --build --clean"
|
|
@@ -21,16 +24,16 @@
|
|
|
21
24
|
"@types/node": "latest"
|
|
22
25
|
},
|
|
23
26
|
"dependencies": {
|
|
24
|
-
"@markuplint/html-parser": "3.
|
|
25
|
-
"@markuplint/ml-ast": "3.0.0
|
|
26
|
-
"@markuplint/ml-config": "3.
|
|
27
|
-
"@markuplint/ml-core": "3.
|
|
28
|
-
"@markuplint/ml-spec": "3.
|
|
27
|
+
"@markuplint/html-parser": "3.3.1",
|
|
28
|
+
"@markuplint/ml-ast": "3.0.0",
|
|
29
|
+
"@markuplint/ml-config": "3.3.0",
|
|
30
|
+
"@markuplint/ml-core": "3.3.1",
|
|
31
|
+
"@markuplint/ml-spec": "3.3.0",
|
|
29
32
|
"cosmiconfig": "^8.0.0",
|
|
30
33
|
"glob": "^8.0.3",
|
|
31
34
|
"jsonc": "^2.0.0",
|
|
32
35
|
"minimatch": "^5.1.1",
|
|
33
36
|
"tslib": "^2.4.1"
|
|
34
37
|
},
|
|
35
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "f19e7de726cf01d53342bc5513c30da75d28da63"
|
|
36
39
|
}
|