@markuplint/file-resolver
Advanced tools
Comparing version 3.0.0-dev.186 to 3.0.0-dev.290
@@ -6,4 +6,4 @@ import type { Ruleset, AnyMLRule } from '@markuplint/ml-core'; | ||
export declare function autoLoadRules(ruleset: Ruleset): Promise<{ | ||
rules: AnyMLRule[]; | ||
errors: unknown[]; | ||
rules: AnyMLRule[]; | ||
errors: unknown[]; | ||
}>; |
@@ -1,28 +0,2 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.autoLoadRules = void 0; | ||
const ml_core_1 = require("@markuplint/ml-core"); | ||
import { MLRule } from '@markuplint/ml-core'; | ||
const cache = new Map(); | ||
@@ -32,3 +6,3 @@ /** | ||
*/ | ||
async function autoLoadRules(ruleset) { | ||
export async function autoLoadRules(ruleset) { | ||
const rules = []; | ||
@@ -44,3 +18,3 @@ const errors = []; | ||
try { | ||
const _module = await Promise.resolve(`${`@markuplint/rule-${ruleName}`}`).then(s => __importStar(require(s))); | ||
const _module = await import(`@markuplint/rule-${ruleName}`); | ||
seed = _module.default; | ||
@@ -55,3 +29,3 @@ if (!(seed && 'defaultValue' in seed && 'defaultOptions' in seed && 'verify' in seed)) { | ||
if (seed) { | ||
const rule = new ml_core_1.MLRule({ | ||
const rule = new MLRule({ | ||
name: ruleName, | ||
@@ -65,3 +39,3 @@ ...seed, | ||
try { | ||
const _module = await Promise.resolve(`${`markuplint-rule-${ruleName}`}`).then(s => __importStar(require(s))); | ||
const _module = await import(`markuplint-rule-${ruleName}`); | ||
seed = _module.default; | ||
@@ -76,3 +50,3 @@ if (!(seed && 'defaultValue' in seed && 'defaultOptions' in seed && 'verify' in seed)) { | ||
if (seed) { | ||
const rule = new ml_core_1.MLRule({ | ||
const rule = new MLRule({ | ||
name: ruleName, | ||
@@ -93,2 +67,1 @@ ...seed, | ||
} | ||
exports.autoLoadRules = autoLoadRules; |
@@ -1,14 +0,15 @@ | ||
import type { MLFile } from './ml-file'; | ||
import type { ConfigSet } from './types'; | ||
import type { MLFile } from './ml-file/index.js'; | ||
import type { ConfigSet } from './types.js'; | ||
import type { Config } from '@markuplint/ml-config'; | ||
import type { Nullable } from '@markuplint/shared'; | ||
export declare class ConfigProvider { | ||
#private; | ||
resolve(targetFile: Readonly<MLFile>, names: readonly Nullable<string>[], cache?: boolean): Promise<ConfigSet>; | ||
search(targetFile: Readonly<MLFile>): Promise<string | null>; | ||
set(config: Config, key?: string): string; | ||
private _load; | ||
private _mergeConfigs; | ||
private _pathResolve; | ||
private _recursiveLoad; | ||
#private; | ||
resolve(targetFile: Readonly<MLFile>, names: readonly Nullable<string>[], cache?: boolean): Promise<ConfigSet>; | ||
search(targetFile: Readonly<MLFile>): Promise<string | null>; | ||
set(config: Config, key?: string): string; | ||
private _load; | ||
private _mergeConfigs; | ||
private _pathResolve; | ||
private _recursiveLoad; | ||
private _validateConfig; | ||
} |
@@ -1,15 +0,16 @@ | ||
"use strict"; | ||
var _ConfigProvider_cache, _ConfigProvider_held, _ConfigProvider_recursiveLoadKeyAndDepth, _ConfigProvider_store; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ConfigProvider = void 0; | ||
const tslib_1 = require("tslib"); | ||
const path_1 = tslib_1.__importDefault(require("path")); | ||
const ml_config_1 = require("@markuplint/ml-config"); | ||
const ml_core_1 = require("@markuplint/ml-core"); | ||
const shared_1 = require("@markuplint/shared"); | ||
const cosmiconfig_1 = require("./cosmiconfig"); | ||
const resolve_plugins_1 = require("./resolve-plugins"); | ||
const utils_1 = require("./utils"); | ||
import { __classPrivateFieldGet } from "tslib"; | ||
import { createRequire } from 'node:module'; | ||
import path from 'node:path'; | ||
import { mergeConfig } from '@markuplint/ml-config'; | ||
import { getPreset } from '@markuplint/ml-core'; | ||
import { ConfigParserError } from '@markuplint/parser-utils'; | ||
import { InvalidSelectorError, createSelector } from '@markuplint/selector'; | ||
import { nonNullableFilter, toNoEmptyStringArrayFromStringOrArray } from '@markuplint/shared'; | ||
import { load as loadConfig, search } from './cosmiconfig.js'; | ||
import { cacheClear, resolvePlugins } from './resolve-plugins.js'; | ||
import { fileExists, uuid } from './utils.js'; | ||
const require = createRequire(import.meta.url); | ||
const KEY_SEPARATOR = '__ML_CONFIG_MERGE__'; | ||
class ConfigProvider { | ||
export class ConfigProvider { | ||
constructor() { | ||
@@ -22,11 +23,10 @@ _ConfigProvider_cache.set(this, new Map()); | ||
async resolve(targetFile, names, cache = true) { | ||
var _a, _b; | ||
if (!cache) { | ||
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").clear(); | ||
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_cache, "f").clear(); | ||
(0, resolve_plugins_1.cacheClear)(); | ||
__classPrivateFieldGet(this, _ConfigProvider_store, "f").clear(); | ||
__classPrivateFieldGet(this, _ConfigProvider_cache, "f").clear(); | ||
cacheClear(); | ||
} | ||
const keys = names.filter(shared_1.nonNullableFilter); | ||
const keys = names.filter(nonNullableFilter); | ||
const key = keys.join(KEY_SEPARATOR); | ||
const currentConfig = tslib_1.__classPrivateFieldGet(this, _ConfigProvider_cache, "f").get(key); | ||
const currentConfig = __classPrivateFieldGet(this, _ConfigProvider_cache, "f").get(key); | ||
if (currentConfig) { | ||
@@ -36,11 +36,19 @@ return currentConfig; | ||
let configSet = await this._mergeConfigs(keys, cache); | ||
const plugins = await (0, resolve_plugins_1.resolvePlugins)(configSet.config.plugins); | ||
if (tslib_1.__classPrivateFieldGet(this, _ConfigProvider_held, "f").size > 0) { | ||
const extendHelds = Array.from(tslib_1.__classPrivateFieldGet(this, _ConfigProvider_held, "f").values()); | ||
const filePath = Array.from(configSet.files).reverse()[0]; | ||
if (!filePath) { | ||
throw new ConfigParserError('Config file not found', { | ||
filePath: targetFile.path, | ||
}); | ||
} | ||
const errors = this._validateConfig(configSet.config, filePath); | ||
configSet.errs.push(...errors); | ||
const plugins = await resolvePlugins(configSet.config.plugins); | ||
if (__classPrivateFieldGet(this, _ConfigProvider_held, "f").size > 0) { | ||
const extendHelds = Array.from(__classPrivateFieldGet(this, _ConfigProvider_held, "f").values()); | ||
for (const held of extendHelds) { | ||
const [, prefix, namespace, name] = (_a = held.match(/^([a-z]+:)([^/]+)(?:\/(.+))?$/)) !== null && _a !== void 0 ? _a : []; | ||
const [, prefix, namespace, name] = held.match(/^([a-z]+:)([^/]+)(?:\/(.+))?$/) ?? []; | ||
switch (prefix) { | ||
case 'plugin:': { | ||
const plugin = plugins.find(plugin => plugin.name === namespace); | ||
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 : '']; | ||
const config = plugin?.configs?.[name ?? '']; | ||
if (config) { | ||
@@ -54,3 +62,3 @@ this.set(config, held); | ||
configSet = await this._mergeConfigs([...keys, ...extendHelds], cache); | ||
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_held, "f").clear(); | ||
__classPrivateFieldGet(this, _ConfigProvider_held, "f").clear(); | ||
} | ||
@@ -74,3 +82,3 @@ // Resolves `overrides` | ||
}; | ||
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_cache, "f").set(key, result); | ||
__classPrivateFieldGet(this, _ConfigProvider_cache, "f").set(key, result); | ||
return result; | ||
@@ -82,3 +90,3 @@ } | ||
} | ||
const res = await (0, cosmiconfig_1.search)(targetFile.path, false); | ||
const res = await search(targetFile.path, false); | ||
if (!res) { | ||
@@ -88,14 +96,13 @@ return null; | ||
const { filePath, config } = res; | ||
const pathResolvedConfig = this._pathResolve(config, filePath); | ||
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").set(filePath, pathResolvedConfig); | ||
const pathResolvedConfig = await this._pathResolve(config, filePath); | ||
__classPrivateFieldGet(this, _ConfigProvider_store, "f").set(filePath, pathResolvedConfig); | ||
return filePath; | ||
} | ||
set(config, key) { | ||
key = key !== null && key !== void 0 ? key : (0, utils_1.uuid)(); | ||
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").set(key, config); | ||
key = key ?? uuid(); | ||
__classPrivateFieldGet(this, _ConfigProvider_store, "f").set(key, config); | ||
return key; | ||
} | ||
async _load(filePath, cache) { | ||
var _a; | ||
const entity = tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").get(filePath); | ||
const entity = __classPrivateFieldGet(this, _ConfigProvider_store, "f").get(filePath); | ||
if (entity) { | ||
@@ -105,13 +112,13 @@ return entity; | ||
if (isPreset(filePath)) { | ||
const [, name] = (_a = filePath.match(/^markuplint:(.+)$/i)) !== null && _a !== void 0 ? _a : []; | ||
const config = await (0, ml_core_1.getPreset)(name !== null && name !== void 0 ? name : filePath); | ||
const pathResolvedConfig = this._pathResolve(config, filePath); | ||
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").set(filePath, pathResolvedConfig); | ||
const [, name] = filePath.match(/^markuplint:(.+)$/i) ?? []; | ||
const config = await getPreset(name ?? filePath); | ||
const pathResolvedConfig = await this._pathResolve(config, filePath); | ||
__classPrivateFieldGet(this, _ConfigProvider_store, "f").set(filePath, pathResolvedConfig); | ||
return pathResolvedConfig; | ||
} | ||
if (isPlugin(filePath)) { | ||
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_held, "f").add(filePath); | ||
__classPrivateFieldGet(this, _ConfigProvider_held, "f").add(filePath); | ||
return null; | ||
} | ||
if (!moduleExists(filePath) && !path_1.default.isAbsolute(filePath)) { | ||
if (!(await moduleExists(filePath)) && !path.isAbsolute(filePath)) { | ||
throw new TypeError(`${filePath} is not an absolute path`); | ||
@@ -123,4 +130,4 @@ } | ||
} | ||
const pathResolvedConfig = this._pathResolve(config, filePath); | ||
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").set(filePath, pathResolvedConfig); | ||
const pathResolvedConfig = await this._pathResolve(config, filePath); | ||
__classPrivateFieldGet(this, _ConfigProvider_store, "f").set(filePath, pathResolvedConfig); | ||
return pathResolvedConfig; | ||
@@ -132,3 +139,3 @@ } | ||
for (const key of keys) { | ||
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_recursiveLoadKeyAndDepth, "f").clear(); | ||
__classPrivateFieldGet(this, _ConfigProvider_recursiveLoadKeyAndDepth, "f").clear(); | ||
const keySet = await this._recursiveLoad(key, cache); | ||
@@ -143,7 +150,7 @@ for (const k of keySet.stack) { | ||
const configs = Array.from(resolvedKeys) | ||
.map(name => tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").get(name)) | ||
.filter(shared_1.nonNullableFilter); | ||
.map(name => __classPrivateFieldGet(this, _ConfigProvider_store, "f").get(name)) | ||
.filter(nonNullableFilter); | ||
let resultConfig = {}; | ||
for (const config of configs) { | ||
resultConfig = (0, ml_config_1.mergeConfig)(resultConfig, config); | ||
resultConfig = mergeConfig(resultConfig, config); | ||
} | ||
@@ -156,19 +163,18 @@ return { | ||
} | ||
_pathResolve(config, filePath) { | ||
const dir = path_1.default.dirname(filePath); | ||
async _pathResolve(config, filePath) { | ||
const dir = path.dirname(filePath); | ||
return { | ||
...config, | ||
extends: pathResolve(dir, config.extends), | ||
plugins: pathResolve(dir, config.plugins, ['name']), | ||
parser: pathResolve(dir, config.parser), | ||
specs: pathResolve(dir, config.specs), | ||
excludeFiles: pathResolve(dir, config.excludeFiles), | ||
overrides: pathResolve(dir, config.overrides, undefined, true), | ||
extends: await pathResolve(dir, config.extends), | ||
plugins: await pathResolve(dir, config.plugins, ['name']), | ||
parser: await pathResolve(dir, config.parser), | ||
specs: await pathResolve(dir, config.specs), | ||
excludeFiles: await pathResolve(dir, config.excludeFiles), | ||
overrides: await pathResolve(dir, config.overrides, undefined, true), | ||
}; | ||
} | ||
async _recursiveLoad(key, cache, depth = 1) { | ||
var _a; | ||
const stack = new Set(); | ||
const errs = []; | ||
const ancestorDepth = tslib_1.__classPrivateFieldGet(this, _ConfigProvider_recursiveLoadKeyAndDepth, "f").get(key); | ||
const ancestorDepth = __classPrivateFieldGet(this, _ConfigProvider_recursiveLoadKeyAndDepth, "f").get(key); | ||
if (ancestorDepth != null && ancestorDepth < depth) { | ||
@@ -180,4 +186,4 @@ return { | ||
} | ||
tslib_1.__classPrivateFieldGet(this, _ConfigProvider_recursiveLoadKeyAndDepth, "f").set(key, depth); | ||
let config = (_a = tslib_1.__classPrivateFieldGet(this, _ConfigProvider_store, "f").get(key)) !== null && _a !== void 0 ? _a : null; | ||
__classPrivateFieldGet(this, _ConfigProvider_recursiveLoadKeyAndDepth, "f").set(key, depth); | ||
let config = __classPrivateFieldGet(this, _ConfigProvider_store, "f").get(key) ?? null; | ||
if (!config) { | ||
@@ -189,3 +195,3 @@ config = await this._load(key, cache); | ||
} | ||
const depKeys = config.extends !== null ? (0, shared_1.toNoEmptyStringArrayFromStringOrArray)(config.extends) : null; | ||
const depKeys = config.extends !== null ? toNoEmptyStringArrayFromStringOrArray(config.extends) : null; | ||
if (depKeys) { | ||
@@ -205,13 +211,30 @@ for (const depKey of depKeys) { | ||
} | ||
_validateConfig(config, filePath) { | ||
const errors = []; | ||
config.nodeRules?.forEach(rule => { | ||
if (rule.selector) { | ||
try { | ||
createSelector(rule.selector); | ||
} | ||
catch (error) { | ||
if (error instanceof InvalidSelectorError) { | ||
errors.push(new ConfigParserError(error.message, { | ||
filePath, | ||
raw: rule.selector, | ||
})); | ||
} | ||
} | ||
} | ||
}); | ||
return errors; | ||
} | ||
} | ||
exports.ConfigProvider = ConfigProvider; | ||
_ConfigProvider_cache = new WeakMap(), _ConfigProvider_held = new WeakMap(), _ConfigProvider_recursiveLoadKeyAndDepth = new WeakMap(), _ConfigProvider_store = new WeakMap(); | ||
async function load(filePath, cache) { | ||
var _a; | ||
if (!(0, utils_1.fileExists)(filePath) && moduleExists(filePath)) { | ||
const mod = await Promise.resolve(`${filePath}`).then(s => tslib_1.__importStar(require(s))); | ||
const config = (_a = mod === null || mod === void 0 ? void 0 : mod.default) !== null && _a !== void 0 ? _a : null; | ||
if (!fileExists(filePath) && (await moduleExists(filePath))) { | ||
const mod = await import(filePath); | ||
const config = mod?.default ?? null; | ||
return config; | ||
} | ||
const res = await (0, cosmiconfig_1.load)(filePath, !cache); | ||
const res = await loadConfig(filePath, !cache); | ||
if (!res) { | ||
@@ -222,3 +245,3 @@ return null; | ||
} | ||
function pathResolve(dir, filePath, resolveProps, resolveKey = false) { | ||
async function pathResolve(dir, filePath, resolveProps, resolveKey = false) { | ||
if (filePath == null) { | ||
@@ -234,3 +257,3 @@ // @ts-ignore | ||
// @ts-ignore | ||
return filePath.map(fp => pathResolve(dir, fp, resolveProps)); | ||
return Promise.all(filePath.map(fp => pathResolve(dir, fp, resolveProps))); | ||
} | ||
@@ -241,10 +264,10 @@ const res = {}; | ||
if (resolveKey) { | ||
_key = resolve(dir, key); | ||
_key = await resolve(dir, key); | ||
} | ||
if (typeof fp === 'string') { | ||
if (!resolveProps) { | ||
res[_key] = resolve(dir, fp); | ||
res[_key] = await resolve(dir, fp); | ||
} | ||
else if (resolveProps.includes(key)) { | ||
res[_key] = resolve(dir, fp); | ||
res[_key] = await resolve(dir, fp); | ||
} | ||
@@ -262,21 +285,44 @@ else { | ||
} | ||
function resolve(dir, pathOrModName) { | ||
if (moduleExists(pathOrModName) || isPreset(pathOrModName) || isPlugin(pathOrModName)) { | ||
async function resolve(dir, pathOrModName) { | ||
if ((await moduleExists(pathOrModName)) || isPreset(pathOrModName) || isPlugin(pathOrModName)) { | ||
return pathOrModName; | ||
} | ||
return path_1.default.resolve(dir, pathOrModName); | ||
const bangAndPath = /^(!)(.*)/.exec(pathOrModName) ?? []; | ||
const bang = bangAndPath[1] ?? ''; | ||
const pathname = bangAndPath[2] ?? pathOrModName; | ||
const absPath = path.resolve(dir, pathname); | ||
return bang + absPath; | ||
} | ||
function moduleExists(name) { | ||
async function moduleExists(name) { | ||
try { | ||
require.resolve(name); | ||
await import(name); | ||
} | ||
catch (err) { | ||
if ( | ||
// @ts-ignore | ||
'code' in err && | ||
if (err instanceof Error) { | ||
if (/^Parse failure/i.test(err.message)) { | ||
return true; | ||
} | ||
} | ||
try { | ||
require.resolve(name); | ||
} | ||
catch (err) { | ||
if ( | ||
// @ts-ignore | ||
err.code === 'MODULE_NOT_FOUND') { | ||
return false; | ||
'code' in err && | ||
// @ts-ignore | ||
err.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') { | ||
// Even if there are issues with the fields, | ||
// assume that the module exists and return true. | ||
return true; | ||
} | ||
if ( | ||
// @ts-ignore | ||
'code' in err && | ||
// @ts-ignore | ||
err.code === 'MODULE_NOT_FOUND') { | ||
return false; | ||
} | ||
throw err; | ||
} | ||
throw err; | ||
} | ||
@@ -283,0 +329,0 @@ return true; |
import type { LoaderSync } from 'cosmiconfig'; | ||
type CosmiConfig = ReturnType<LoaderSync>; | ||
export declare function search<T = CosmiConfig>( | ||
dir: string, | ||
cacheClear: boolean, | ||
): Promise<{ | ||
filePath: string; | ||
config: T; | ||
export declare function search<T = CosmiConfig>(dir: string, cacheClear: boolean): Promise<{ | ||
filePath: string; | ||
config: T; | ||
} | null>; | ||
export declare function load<T = CosmiConfig>( | ||
filePath: string, | ||
cacheClear: boolean, | ||
): Promise<{ | ||
filePath: string; | ||
config: T; | ||
export declare function load<T = CosmiConfig>(filePath: string, cacheClear: boolean): Promise<{ | ||
filePath: string; | ||
config: T; | ||
} | null>; | ||
export {}; |
@@ -1,19 +0,14 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.load = exports.search = void 0; | ||
const tslib_1 = require("tslib"); | ||
const path_1 = tslib_1.__importDefault(require("path")); | ||
const cosmiconfig_1 = require("cosmiconfig"); | ||
const cosmiconfig_typescript_loader_1 = require("cosmiconfig-typescript-loader"); | ||
const jsonc_1 = require("jsonc"); | ||
const explorer = (0, cosmiconfig_1.cosmiconfig)('markuplint', { | ||
import path from 'node:path'; | ||
import { ConfigParserError } from '@markuplint/parser-utils'; | ||
import { cosmiconfig, defaultLoaders } from 'cosmiconfig'; | ||
import { jsonc } from 'jsonc'; | ||
const explorer = cosmiconfig('markuplint', { | ||
loaders: { | ||
'.ts': (0, cosmiconfig_typescript_loader_1.TypeScriptLoader)(), | ||
noExt: ((path, content) => { | ||
try { | ||
return jsonc_1.jsonc.parse(content); | ||
return jsonc.parse(content); | ||
} | ||
catch (error) { | ||
if (error instanceof Error && error.name === 'JSONError') { | ||
return cosmiconfig_1.defaultLoaders['noExt'](path, content); | ||
return defaultLoaders['noExt'](path, content); | ||
} | ||
@@ -25,8 +20,8 @@ throw error; | ||
}); | ||
async function search(dir, cacheClear) { | ||
export async function search(dir, cacheClear) { | ||
if (cacheClear) { | ||
explorer.clearCaches(); | ||
} | ||
dir = path_1.default.dirname(dir); | ||
const result = await explorer.search(dir); | ||
dir = path.dirname(dir); | ||
const result = await explorer.search(dir).catch(cacheConfigError(dir)); | ||
if (!result || result.isEmpty) { | ||
@@ -40,8 +35,7 @@ return null; | ||
} | ||
exports.search = search; | ||
async function load(filePath, cacheClear) { | ||
export async function load(filePath, cacheClear) { | ||
if (cacheClear) { | ||
explorer.clearCaches(); | ||
} | ||
const result = await explorer.load(filePath); | ||
const result = await explorer.load(filePath).catch(cacheConfigError(filePath)); | ||
if (!result || result.isEmpty) { | ||
@@ -55,2 +49,22 @@ return null; | ||
} | ||
exports.load = load; | ||
class ConfigLoadError extends Error { | ||
constructor(message, filePath) { | ||
super(message + ` in ${filePath}`); | ||
this.name = 'ConfigLoadError'; | ||
} | ||
} | ||
function cacheConfigError(fileOrDirPath) { | ||
return (reason) => { | ||
if (reason instanceof Error) { | ||
switch (reason.name) { | ||
case 'YAMLException': | ||
throw new ConfigParserError(reason.message, { | ||
// @ts-ignore | ||
filePath: reason.filepath ?? fileOrDirPath, | ||
}); | ||
} | ||
throw new ConfigLoadError(reason.message, fileOrDirPath); | ||
} | ||
throw reason; | ||
}; | ||
} |
@@ -1,7 +0,7 @@ | ||
export type { MLFile } from './ml-file'; | ||
export * from './config-provider'; | ||
export * from './resolve-files'; | ||
export * from './resolve-parser'; | ||
export * from './resolve-rules'; | ||
export * from './resolve-specs'; | ||
export * from './types'; | ||
export type { MLFile } from './ml-file/index.js'; | ||
export * from './config-provider.js'; | ||
export * from './resolve-files.js'; | ||
export * from './resolve-parser.js'; | ||
export * from './resolve-rules.js'; | ||
export * from './resolve-specs.js'; | ||
export * from './types.js'; |
@@ -1,9 +0,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./config-provider"), exports); | ||
tslib_1.__exportStar(require("./resolve-files"), exports); | ||
tslib_1.__exportStar(require("./resolve-parser"), exports); | ||
tslib_1.__exportStar(require("./resolve-rules"), exports); | ||
tslib_1.__exportStar(require("./resolve-specs"), exports); | ||
tslib_1.__exportStar(require("./types"), exports); | ||
export * from './config-provider.js'; | ||
export * from './resolve-files.js'; | ||
export * from './resolve-parser.js'; | ||
export * from './resolve-rules.js'; | ||
export * from './resolve-specs.js'; | ||
export * from './types.js'; |
@@ -1,2 +0,2 @@ | ||
import { MLFile } from './ml-file'; | ||
import { MLFile } from './ml-file.js'; | ||
export declare function getAnonymousFile(context: string, workspace?: string, name?: string): MLFile; |
@@ -1,7 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getAnonymousFile = void 0; | ||
const ml_file_1 = require("./ml-file"); | ||
function getAnonymousFile(context, workspace, name) { | ||
const file = new ml_file_1.MLFile({ | ||
import { MLFile } from './ml-file.js'; | ||
export function getAnonymousFile(context, workspace, name) { | ||
const file = new MLFile({ | ||
sourceCode: context, | ||
@@ -13,2 +10,1 @@ workspace, | ||
} | ||
exports.getAnonymousFile = getAnonymousFile; |
@@ -1,2 +0,2 @@ | ||
import { MLFile } from './ml-file'; | ||
import { MLFile } from './ml-file.js'; | ||
export declare function getFile(filePath: string): MLFile; |
@@ -1,9 +0,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getFile = void 0; | ||
const ml_file_1 = require("./ml-file"); | ||
function getFile(filePath) { | ||
const file = new ml_file_1.MLFile(filePath); | ||
import { MLFile } from './ml-file.js'; | ||
export function getFile(filePath) { | ||
const file = new MLFile(filePath); | ||
return file; | ||
} | ||
exports.getFile = getFile; |
@@ -1,2 +0,2 @@ | ||
import type { MLFile } from './ml-file'; | ||
import type { MLFile } from './ml-file.js'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Get files |
@@ -1,6 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getFiles = void 0; | ||
const glob_1 = require("glob"); | ||
const get_file_1 = require("./get-file"); | ||
import { glob } from 'glob'; | ||
import { getFile } from './get-file.js'; | ||
/** | ||
@@ -13,6 +10,5 @@ * Get files | ||
*/ | ||
async function getFiles(filePathOrGlob) { | ||
const fileList = await (0, glob_1.glob)(filePathOrGlob, {}).catch(() => []); | ||
return fileList.map(fileName => (0, get_file_1.getFile)(fileName)); | ||
export async function getFiles(filePathOrGlob) { | ||
const fileList = await glob(filePathOrGlob, {}).catch(() => []); | ||
return fileList.map(fileName => getFile(fileName)); | ||
} | ||
exports.getFiles = getFiles; |
@@ -1,4 +0,4 @@ | ||
export type { MLFile } from './ml-file'; | ||
export * from './get-anonymous-file'; | ||
export * from './get-file'; | ||
export * from './get-files'; | ||
export type { MLFile } from './ml-file.js'; | ||
export * from './get-anonymous-file.js'; | ||
export * from './get-file.js'; | ||
export * from './get-files.js'; |
@@ -1,6 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./get-anonymous-file"), exports); | ||
tslib_1.__exportStar(require("./get-file"), exports); | ||
tslib_1.__exportStar(require("./get-files"), exports); | ||
export * from './get-anonymous-file.js'; | ||
export * from './get-file.js'; | ||
export * from './get-files.js'; |
@@ -1,23 +0,24 @@ | ||
import type { Target } from '../types'; | ||
import type { Target } from '../types.js'; | ||
export declare class MLFile { | ||
#private; | ||
constructor(target: Target); | ||
get dirname(): string; | ||
/** | ||
* Normalized `MLFile.dirname` | ||
*/ | ||
get nDirname(): string; | ||
/** | ||
* Normalized `MLFile.path` | ||
*/ | ||
get nPath(): string; | ||
get path(): string; | ||
dirExists(): Promise<boolean>; | ||
getCode(): Promise<string>; | ||
isExist(): Promise<boolean>; | ||
isFile(): Promise<boolean>; | ||
matches(globPath: string): boolean; | ||
setCode(code: string): void; | ||
private _fetch; | ||
private _stat; | ||
#private; | ||
constructor(target: Target); | ||
get dirname(): string; | ||
/** | ||
* Normalized `MLFile.dirname` | ||
*/ | ||
get nDirname(): string; | ||
/** | ||
* Normalized `MLFile.path` | ||
*/ | ||
get nPath(): string; | ||
get path(): string; | ||
dirExists(): Promise<boolean>; | ||
getCode(): Promise<string>; | ||
ignored(globPath: string | readonly string[]): any; | ||
isExist(): Promise<boolean>; | ||
isFile(): Promise<boolean>; | ||
matches(globPath: string): boolean; | ||
setCode(code: string): void; | ||
private _fetch; | ||
private _stat; | ||
} |
@@ -1,12 +0,9 @@ | ||
"use strict"; | ||
var _MLFile_basename, _MLFile_code, _MLFile_dirname, _MLFile_stat, _MLFile_type; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MLFile = void 0; | ||
const tslib_1 = require("tslib"); | ||
const fs_1 = require("fs"); | ||
const path_1 = tslib_1.__importDefault(require("path")); | ||
const minimatch_1 = require("minimatch"); | ||
class MLFile { | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { promises as fs } from 'node:fs'; | ||
import path from 'node:path'; | ||
import ignore from 'ignore'; | ||
import { minimatch } from 'minimatch'; | ||
export class MLFile { | ||
constructor(target) { | ||
var _a, _b; | ||
_MLFile_basename.set(this, void 0); | ||
@@ -23,21 +20,21 @@ _MLFile_code.set(this, void 0); | ||
if (typeof target === 'string') { | ||
tslib_1.__classPrivateFieldSet(this, _MLFile_basename, path_1.default.basename(target), "f"); | ||
tslib_1.__classPrivateFieldSet(this, _MLFile_dirname, path_1.default.dirname(target), "f"); | ||
tslib_1.__classPrivateFieldSet(this, _MLFile_code, null, "f"); | ||
tslib_1.__classPrivateFieldSet(this, _MLFile_type, 'file-base', "f"); | ||
__classPrivateFieldSet(this, _MLFile_basename, path.basename(target), "f"); | ||
__classPrivateFieldSet(this, _MLFile_dirname, path.dirname(target), "f"); | ||
__classPrivateFieldSet(this, _MLFile_code, null, "f"); | ||
__classPrivateFieldSet(this, _MLFile_type, 'file-base', "f"); | ||
return; | ||
} | ||
if (!target.workspace && target.name && path_1.default.isAbsolute(target.name)) { | ||
tslib_1.__classPrivateFieldSet(this, _MLFile_basename, path_1.default.basename(target.name), "f"); | ||
tslib_1.__classPrivateFieldSet(this, _MLFile_dirname, path_1.default.dirname(target.name), "f"); | ||
if (!target.workspace && target.name && path.isAbsolute(target.name)) { | ||
__classPrivateFieldSet(this, _MLFile_basename, path.basename(target.name), "f"); | ||
__classPrivateFieldSet(this, _MLFile_dirname, path.dirname(target.name), "f"); | ||
} | ||
else { | ||
tslib_1.__classPrivateFieldSet(this, _MLFile_basename, (_a = target.name) !== null && _a !== void 0 ? _a : '<AnonymousFile>', "f"); | ||
tslib_1.__classPrivateFieldSet(this, _MLFile_dirname, (_b = target.workspace) !== null && _b !== void 0 ? _b : process.cwd(), "f"); | ||
__classPrivateFieldSet(this, _MLFile_basename, target.name ?? '<AnonymousFile>', "f"); | ||
__classPrivateFieldSet(this, _MLFile_dirname, target.workspace ?? process.cwd(), "f"); | ||
} | ||
tslib_1.__classPrivateFieldSet(this, _MLFile_code, target.sourceCode, "f"); | ||
tslib_1.__classPrivateFieldSet(this, _MLFile_type, 'code-base', "f"); | ||
__classPrivateFieldSet(this, _MLFile_code, target.sourceCode, "f"); | ||
__classPrivateFieldSet(this, _MLFile_type, 'code-base', "f"); | ||
} | ||
get dirname() { | ||
return tslib_1.__classPrivateFieldGet(this, _MLFile_dirname, "f"); | ||
return __classPrivateFieldGet(this, _MLFile_dirname, "f"); | ||
} | ||
@@ -57,12 +54,12 @@ /** | ||
get path() { | ||
return path_1.default.resolve(tslib_1.__classPrivateFieldGet(this, _MLFile_dirname, "f"), tslib_1.__classPrivateFieldGet(this, _MLFile_basename, "f")); | ||
return path.resolve(__classPrivateFieldGet(this, _MLFile_dirname, "f"), __classPrivateFieldGet(this, _MLFile_basename, "f")); | ||
} | ||
async dirExists() { | ||
return !!(await stat(tslib_1.__classPrivateFieldGet(this, _MLFile_dirname, "f"))); | ||
return !!(await stat(__classPrivateFieldGet(this, _MLFile_dirname, "f"))); | ||
} | ||
async getCode() { | ||
if (tslib_1.__classPrivateFieldGet(this, _MLFile_code, "f") != null) { | ||
return tslib_1.__classPrivateFieldGet(this, _MLFile_code, "f"); | ||
if (__classPrivateFieldGet(this, _MLFile_code, "f") != null) { | ||
return __classPrivateFieldGet(this, _MLFile_code, "f"); | ||
} | ||
if (tslib_1.__classPrivateFieldGet(this, _MLFile_type, "f") === 'file-base' && (await this.isExist())) { | ||
if (__classPrivateFieldGet(this, _MLFile_type, "f") === 'file-base' && (await this.isExist())) { | ||
return await this._fetch(); | ||
@@ -72,4 +69,12 @@ } | ||
} | ||
ignored(globPath) { | ||
globPath = typeof globPath === 'string' ? [globPath] : globPath; | ||
const normalizedPaths = globPath.map(p => pathNormalize(p, true)); | ||
// @ts-ignore | ||
const ig = ignore().add(normalizedPaths); | ||
const ignored = ig.ignores(pathNormalize(this.nPath, true)); | ||
return ignored; | ||
} | ||
async isExist() { | ||
if (tslib_1.__classPrivateFieldGet(this, _MLFile_type, "f") === 'code-base') { | ||
if (__classPrivateFieldGet(this, _MLFile_type, "f") === 'code-base') { | ||
return true; | ||
@@ -81,3 +86,3 @@ } | ||
async isFile() { | ||
if (tslib_1.__classPrivateFieldGet(this, _MLFile_type, "f") === 'code-base') { | ||
if (__classPrivateFieldGet(this, _MLFile_type, "f") === 'code-base') { | ||
return true; | ||
@@ -89,28 +94,27 @@ } | ||
matches(globPath) { | ||
return (0, minimatch_1.minimatch)(this.nPath, pathNormalize(globPath)); | ||
return minimatch(this.nPath, pathNormalize(globPath)); | ||
} | ||
setCode(code) { | ||
if (tslib_1.__classPrivateFieldGet(this, _MLFile_type, "f") === 'file-base') { | ||
if (__classPrivateFieldGet(this, _MLFile_type, "f") === 'file-base') { | ||
throw new Error(`This file object is readonly (File-base: ${this.path})`); | ||
} | ||
tslib_1.__classPrivateFieldSet(this, _MLFile_code, code, "f"); | ||
__classPrivateFieldSet(this, _MLFile_code, code, "f"); | ||
} | ||
async _fetch() { | ||
const code = await fs_1.promises.readFile(this.path, { encoding: 'utf-8' }); | ||
tslib_1.__classPrivateFieldSet(this, _MLFile_code, code, "f"); | ||
const code = await fs.readFile(this.path, { encoding: 'utf-8' }); | ||
__classPrivateFieldSet(this, _MLFile_code, code, "f"); | ||
return code; | ||
} | ||
async _stat() { | ||
if (tslib_1.__classPrivateFieldGet(this, _MLFile_stat, "f")) { | ||
return tslib_1.__classPrivateFieldGet(this, _MLFile_stat, "f"); | ||
if (__classPrivateFieldGet(this, _MLFile_stat, "f")) { | ||
return __classPrivateFieldGet(this, _MLFile_stat, "f"); | ||
} | ||
tslib_1.__classPrivateFieldSet(this, _MLFile_stat, await stat(this.path), "f"); | ||
return tslib_1.__classPrivateFieldGet(this, _MLFile_stat, "f"); | ||
__classPrivateFieldSet(this, _MLFile_stat, await stat(this.path), "f"); | ||
return __classPrivateFieldGet(this, _MLFile_stat, "f"); | ||
} | ||
} | ||
exports.MLFile = MLFile; | ||
_MLFile_basename = new WeakMap(), _MLFile_code = new WeakMap(), _MLFile_dirname = new WeakMap(), _MLFile_stat = new WeakMap(), _MLFile_type = new WeakMap(); | ||
async function stat(filePath) { | ||
try { | ||
return await fs_1.promises.stat(filePath); | ||
return await fs.stat(filePath); | ||
} | ||
@@ -128,10 +132,20 @@ catch (err) { | ||
} | ||
function pathNormalize(filePath) { | ||
function pathNormalize(filePath, relative = false) { | ||
const hasBang = filePath.startsWith('!'); | ||
if (hasBang) { | ||
filePath = filePath.slice(1); | ||
} | ||
// Remove the local disk scheme of Windows OS | ||
if (path_1.default.isAbsolute(filePath)) { | ||
if (path.isAbsolute(filePath)) { | ||
filePath = filePath.replace(/^[a-z]+:/i, ''); | ||
if (relative) { | ||
filePath = path.relative(path.sep, filePath); | ||
} | ||
} | ||
// Replace the separator of Windows OS | ||
filePath = filePath.split(path_1.default.sep).join('/'); | ||
filePath = filePath.split(path.sep).join('/'); | ||
if (hasBang) { | ||
filePath = `!${filePath}`; | ||
} | ||
return filePath; | ||
} |
@@ -1,3 +0,3 @@ | ||
import type { MLFile } from './ml-file'; | ||
import type { Target } from './types'; | ||
import type { MLFile } from './ml-file/index.js'; | ||
import type { Target } from './types.js'; | ||
export declare function resolveFiles(targetList: readonly Readonly<Target>[]): Promise<MLFile[]>; |
@@ -1,17 +0,13 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolveFiles = void 0; | ||
const ml_file_1 = require("./ml-file"); | ||
async function resolveFiles(targetList) { | ||
import { getAnonymousFile, getFiles } from './ml-file/index.js'; | ||
export async function resolveFiles(targetList) { | ||
const res = []; | ||
for (const target of targetList) { | ||
if (typeof target === 'string') { | ||
const file = await (0, ml_file_1.getFiles)(target); | ||
const file = await getFiles(target); | ||
res.push(...file); | ||
continue; | ||
} | ||
res.push((0, ml_file_1.getAnonymousFile)(target.sourceCode, target.workspace, target.name)); | ||
res.push(getAnonymousFile(target.sourceCode, target.workspace, target.name)); | ||
} | ||
return res; | ||
} | ||
exports.resolveFiles = resolveFiles; |
@@ -1,13 +0,9 @@ | ||
import type { MLFile } from './ml-file'; | ||
import type { MLFile } from './ml-file/index.js'; | ||
import type { MLMarkupLanguageParser, ParserOptions } from '@markuplint/ml-ast'; | ||
import type { ParserConfig } from '@markuplint/ml-config'; | ||
export declare function resolveParser( | ||
file: Readonly<MLFile>, | ||
parserConfig?: ParserConfig, | ||
parserOptions?: ParserOptions, | ||
): Promise<{ | ||
parserModName: string; | ||
parser: MLMarkupLanguageParser; | ||
parserOptions: ParserOptions; | ||
matched: boolean; | ||
export declare function resolveParser(file: Readonly<MLFile>, parserConfig?: ParserConfig, parserOptions?: ParserOptions): Promise<{ | ||
parserModName: string; | ||
parser: MLMarkupLanguageParser; | ||
parserOptions: ParserOptions; | ||
matched: boolean; | ||
}>; |
@@ -1,9 +0,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolveParser = void 0; | ||
const tslib_1 = require("tslib"); | ||
const path_1 = tslib_1.__importDefault(require("path")); | ||
const utils_1 = require("./utils"); | ||
import path from 'node:path'; | ||
import { toRegexp } from './utils.js'; | ||
const parsers = new Map(); | ||
async function resolveParser(file, parserConfig, parserOptions) { | ||
export async function resolveParser(file, parserConfig, parserOptions) { | ||
parserConfig = { | ||
@@ -13,7 +9,7 @@ ...parserConfig, | ||
}; | ||
parserOptions = parserOptions !== null && parserOptions !== void 0 ? parserOptions : {}; | ||
parserOptions = parserOptions ?? {}; | ||
let parserModName = '@markuplint/html-parser'; | ||
let matched = false; | ||
for (const pattern of Object.keys(parserConfig)) { | ||
if (path_1.default.basename(file.path).match((0, utils_1.toRegexp)(pattern))) { | ||
if (path.basename(file.path).match(toRegexp(pattern))) { | ||
const modName = parserConfig[pattern]; | ||
@@ -36,3 +32,2 @@ if (!modName) { | ||
} | ||
exports.resolveParser = resolveParser; | ||
async function importParser(parserModName) { | ||
@@ -43,4 +38,4 @@ const entity = parsers.get(parserModName); | ||
} | ||
const parser = await Promise.resolve(`${parserModName}`).then(s => tslib_1.__importStar(require(s))); | ||
const parser = await import(parserModName); | ||
return parser; | ||
} |
@@ -1,29 +0,3 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.cacheClear = exports.resolvePlugins = void 0; | ||
const cache = new Map(); | ||
async function resolvePlugins(pluginPaths) { | ||
export async function resolvePlugins(pluginPaths) { | ||
if (!pluginPaths) { | ||
@@ -36,7 +10,5 @@ return []; | ||
} | ||
exports.resolvePlugins = resolvePlugins; | ||
function cacheClear() { | ||
export function cacheClear() { | ||
cache.clear(); | ||
} | ||
exports.cacheClear = cacheClear; | ||
async function importPlugin(pluginPath) { | ||
@@ -80,3 +52,3 @@ const config = getPluginConfig(pluginPath); | ||
async function failSafeImport(name) { | ||
const res = await Promise.resolve(`${name}`).then(s => __importStar(require(s))).catch(e => e); | ||
const res = await import(name).catch(e => e); | ||
if ('code' in res && res === 'MODULE_NOT_FOUND') { | ||
@@ -83,0 +55,0 @@ return null; |
import type { AnyMLRule, Ruleset, Plugin } from '@markuplint/ml-core'; | ||
export declare function resolveRules( | ||
plugins: readonly Plugin[], | ||
ruleset: Ruleset, | ||
importPreset: boolean, | ||
/** | ||
* @deprecated | ||
*/ | ||
autoLoad: boolean, | ||
): Promise<Readonly<AnyMLRule>[]>; | ||
export declare function resolveRules(plugins: readonly Plugin[], ruleset: Ruleset, importPreset: boolean, | ||
/** | ||
* @deprecated | ||
*/ | ||
autoLoad: boolean): Promise<Readonly<AnyMLRule>[]>; |
@@ -1,31 +0,5 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolveRules = void 0; | ||
const ml_core_1 = require("@markuplint/ml-core"); | ||
const auto_load_rules_1 = require("./auto-load-rules"); | ||
import { MLRule } from '@markuplint/ml-core'; | ||
import { autoLoadRules } from './auto-load-rules.js'; | ||
let cachedPresetRules = null; | ||
async function resolveRules(plugins, ruleset, importPreset, | ||
export async function resolveRules(plugins, ruleset, importPreset, | ||
/** | ||
@@ -41,3 +15,3 @@ * @deprecated | ||
Object.entries(plugin.rules).forEach(([name, seed]) => { | ||
const rule = new ml_core_1.MLRule({ | ||
const rule = new MLRule({ | ||
name: `${plugin.name}/${name}`, | ||
@@ -50,3 +24,3 @@ ...seed, | ||
if (autoLoad) { | ||
const { rules: additionalRules } = await (0, auto_load_rules_1.autoLoadRules)(ruleset); | ||
const { rules: additionalRules } = await autoLoadRules(ruleset); | ||
additionalRules.forEach(rule => { | ||
@@ -59,3 +33,2 @@ rules.push(rule); | ||
} | ||
exports.resolveRules = resolveRules; | ||
async function importPresetRules() { | ||
@@ -66,5 +39,6 @@ if (cachedPresetRules) { | ||
const modName = '@markuplint/rules'; | ||
const presetRules = (await Promise.resolve(`${modName}`).then(s => __importStar(require(s)))).default; | ||
const mod = await import(modName); | ||
const presetRules = mod.default; | ||
const ruleList = Object.entries(presetRules).map(([name, seed]) => { | ||
const rule = new ml_core_1.MLRule({ | ||
const rule = new MLRule({ | ||
name, | ||
@@ -71,0 +45,0 @@ ...seed, |
@@ -33,7 +33,4 @@ import type { SpecConfig } from '@markuplint/ml-config'; | ||
*/ | ||
export declare function resolveSpecs( | ||
filePath: string, | ||
specConfig?: SpecConfig, | ||
): Promise<{ | ||
schemas: readonly [MLMLSpec, ...ExtendedSpec[]]; | ||
export declare function resolveSpecs(filePath: string, specConfig?: SpecConfig): Promise<{ | ||
schemas: readonly [MLMLSpec, ...ExtendedSpec[]]; | ||
}>; |
@@ -1,7 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolveSpecs = void 0; | ||
const tslib_1 = require("tslib"); | ||
const path_1 = tslib_1.__importDefault(require("path")); | ||
const utils_1 = require("./utils"); | ||
import path from 'node:path'; | ||
import { toRegexp } from './utils.js'; | ||
const caches = new Map(); | ||
@@ -38,3 +34,3 @@ /** | ||
*/ | ||
async function resolveSpecs(filePath, specConfig) { | ||
export async function resolveSpecs(filePath, specConfig) { | ||
const htmlSpec = await importSpecs('@markuplint/html-spec'); | ||
@@ -49,3 +45,3 @@ const extendedSpecs = []; | ||
for (const pattern of Object.keys(specConfig)) { | ||
if (path_1.default.basename(filePath).match((0, utils_1.toRegexp)(pattern))) { | ||
if (path.basename(filePath).match(toRegexp(pattern))) { | ||
const specModName = specConfig[pattern]; | ||
@@ -66,3 +62,2 @@ if (!specModName) { | ||
} | ||
exports.resolveSpecs = resolveSpecs; | ||
async function importSpecs(specModName) { | ||
@@ -76,3 +71,3 @@ { | ||
} | ||
const spec = (await Promise.resolve(`${specModName}`).then(s => tslib_1.__importStar(require(s)))).default; | ||
const spec = (await import(specModName)).default; | ||
// @ts-ignore | ||
@@ -79,0 +74,0 @@ caches.set(specModName, spec); |
import type { Config } from '@markuplint/ml-config'; | ||
import type { Plugin } from '@markuplint/ml-core'; | ||
export interface ConfigSet { | ||
readonly config: Config; | ||
readonly plugins: readonly Plugin[]; | ||
readonly files: ReadonlySet<string>; | ||
readonly errs: readonly Readonly<Error>[]; | ||
readonly config: Config; | ||
readonly plugins: readonly Plugin[]; | ||
readonly files: ReadonlySet<string>; | ||
readonly errs: readonly Readonly<Error>[]; | ||
} | ||
export type Target = | ||
| string | ||
| { | ||
/** | ||
* Target source code of evaluation | ||
*/ | ||
readonly sourceCode: string; | ||
/** | ||
* File names when `sourceCodes` | ||
*/ | ||
readonly name?: string; | ||
/** | ||
* Workspace path when `sourceCodes` | ||
*/ | ||
readonly workspace?: string; | ||
}; | ||
export type Target = string | { | ||
/** | ||
* Target source code of evaluation | ||
*/ | ||
readonly sourceCode: string; | ||
/** | ||
* File names when `sourceCodes` | ||
*/ | ||
readonly name?: string; | ||
/** | ||
* Workspace path when `sourceCodes` | ||
*/ | ||
readonly workspace?: string; | ||
}; |
@@ -1,2 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; |
@@ -1,8 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toRegexp = exports.fileExists = exports.uuid = void 0; | ||
const tslib_1 = require("tslib"); | ||
const fs_1 = tslib_1.__importDefault(require("fs")); | ||
import fs from 'node:fs'; | ||
let uuidNum = 0; | ||
function uuid() { | ||
export function uuid() { | ||
const out = `${uuidNum}`; | ||
@@ -12,8 +8,6 @@ uuidNum++; | ||
} | ||
exports.uuid = uuid; | ||
function fileExists(filePath) { | ||
return fs_1.default.existsSync(filePath); | ||
export function fileExists(filePath) { | ||
return fs.existsSync(filePath); | ||
} | ||
exports.fileExists = fileExists; | ||
function toRegexp(pattern) { | ||
export function toRegexp(pattern) { | ||
const matched = pattern.match(/^\/(.+)\/([ig]*)$/i); | ||
@@ -25,2 +19,1 @@ if (matched && matched[1]) { | ||
} | ||
exports.toRegexp = toRegexp; |
{ | ||
"name": "@markuplint/file-resolver", | ||
"version": "3.0.0-dev.186+37ceba57", | ||
"version": "3.0.0-dev.290+af676442", | ||
"description": "The file resolver of markuplint", | ||
@@ -9,4 +9,9 @@ "repository": "git@github.com:markuplint/markuplint.git", | ||
"private": false, | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"import": "./lib/index.js" | ||
} | ||
}, | ||
"types": "./lib/index.d.ts", | ||
"publishConfig": { | ||
@@ -23,20 +28,21 @@ "access": "public" | ||
"devDependencies": { | ||
"@types/node": "18.16.3" | ||
"@types/node": "20.8.3" | ||
}, | ||
"dependencies": { | ||
"@markuplint/html-parser": "3.0.0-dev.186+37ceba57", | ||
"@markuplint/ml-ast": "3.0.0-dev.186+37ceba57", | ||
"@markuplint/ml-config": "3.0.0-dev.186+37ceba57", | ||
"@markuplint/ml-core": "3.0.0-dev.186+37ceba57", | ||
"@markuplint/ml-spec": "3.0.0-dev.186+37ceba57", | ||
"@markuplint/shared": "3.6.1-dev.3156+37ceba57", | ||
"@types/cosmiconfig": "^6.0.0", | ||
"cosmiconfig": "^8.0.0", | ||
"cosmiconfig-typescript-loader": "^4.3.0", | ||
"glob": "^10.2.2", | ||
"@markuplint/html-parser": "3.0.0-dev.290+af676442", | ||
"@markuplint/ml-ast": "3.0.0-dev.290+af676442", | ||
"@markuplint/ml-config": "3.0.0-dev.290+af676442", | ||
"@markuplint/ml-core": "3.0.0-dev.290+af676442", | ||
"@markuplint/ml-spec": "3.0.0-dev.290+af676442", | ||
"@markuplint/parser-utils": "3.0.0-dev.290+af676442", | ||
"@markuplint/selector": "3.0.0-dev.290+af676442", | ||
"@markuplint/shared": "4.0.0-dev.3580+af676442", | ||
"cosmiconfig": "^8.3.6", | ||
"glob": "^10.3.6", | ||
"ignore": "^5.2.4", | ||
"jsonc": "^2.0.0", | ||
"minimatch": "^9.0.0", | ||
"tslib": "^2.4.1" | ||
"minimatch": "^9.0.3", | ||
"tslib": "^2.6.2" | ||
}, | ||
"gitHead": "37ceba578aff49e0326c5e374cef3da6be303b25" | ||
"gitHead": "af6764422feecb56d1d84659028f53daf685bb78" | ||
} |
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
2
Yes
36964
14
1042
+ Addedignore@^5.2.4
+ Addedignore@5.3.2(transitive)
- Removed@types/cosmiconfig@^6.0.0
- Removedcosmiconfig-typescript-loader@^4.3.0
- Removed@cspotcode/source-map-support@0.8.1(transitive)
- Removed@jridgewell/resolve-uri@3.1.2(transitive)
- Removed@jridgewell/sourcemap-codec@1.5.0(transitive)
- Removed@jridgewell/trace-mapping@0.3.9(transitive)
- Removed@tsconfig/node10@1.0.11(transitive)
- Removed@tsconfig/node12@1.0.11(transitive)
- Removed@tsconfig/node14@1.0.3(transitive)
- Removed@tsconfig/node16@1.0.4(transitive)
- Removed@types/cosmiconfig@6.0.3(transitive)
- Removed@types/node@22.13.5(transitive)
- Removedacorn@8.14.0(transitive)
- Removedacorn-walk@8.3.4(transitive)
- Removedarg@4.1.3(transitive)
- Removedcosmiconfig-typescript-loader@4.4.0(transitive)
- Removedcreate-require@1.1.1(transitive)
- Removeddiff@4.0.2(transitive)
- Removedmake-error@1.3.6(transitive)
- Removedts-node@10.9.2(transitive)
- Removedtypescript@5.7.3(transitive)
- Removedundici-types@6.20.0(transitive)
- Removedv8-compile-cache-lib@3.0.1(transitive)
- Removedyn@3.1.1(transitive)
Updatedcosmiconfig@^8.3.6
Updatedglob@^10.3.6
Updatedminimatch@^9.0.3
Updatedtslib@^2.6.2