本文整理汇总了TypeScript中interop-require.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: loadConfig
export function loadConfig(
configFilePath: string,
{ configFileName, moduleResolver }: { configFileName: string; moduleResolver: TextLintModuleResolver }
) {
// if specify Config module, use it
if (configFilePath) {
try {
const modulePath = moduleResolver.resolveConfigPackageName(configFilePath);
return {
config: interopRequire(modulePath),
filePath: modulePath
};
} catch (error) {
// not found config module
}
}
// auto or specify path to config file
const result = rcConfigLoader(configFileName, {
configFileName: configFilePath,
defaultExtension: [".json", ".js", ".yml"]
});
if (result === undefined) {
return {
config: {},
filePath: undefined
};
}
return {
config: result.config,
filePath: result.filePath
};
}
开发者ID:textlint,项目名称:textlint,代码行数:32,代码来源:config-loader.ts
示例2: loadFilterRule
/**
* load filter rule file with `ruleName` and define rule.
* if rule is not found, then throw ReferenceError.
* if already rule is loaded, do not anything.
* @param {string} ruleName
*/
loadFilterRule(ruleName: string) {
/*
Task
- check already define
- resolve package name
- load package
- emit rule
*/
// ignore already defined rule
// ignore rules from rulePaths because avoid ReferenceError is that try to require.
if (isFile(ruleName)) {
const ruleCreator = interopRequire(ruleName);
const ruleEntry = [ruleName, ruleCreator];
this.emit(TextLintModuleLoader.Event.filterRule, ruleEntry);
return;
}
const RULE_NAME_PREFIX = this.config.constructor.FILTER_RULE_NAME_PREFIX;
const prefixMatch = new RegExp(`^${RULE_NAME_PREFIX}`);
const definedRuleName = ruleName.replace(prefixMatch, "");
// ignore plugin's rule
if (isPluginRuleKey(definedRuleName)) {
Logger.warn(`${definedRuleName} is Plugin's rule. This is unknown case, please report issue.`);
return;
}
const pkgPath = this.moduleResolver.resolveFilterRulePackageName(ruleName);
debug("Loading filter rules from %s", pkgPath);
const ruleCreator = interopRequire(pkgPath);
const ruleEntry = [definedRuleName, ruleCreator];
this.emit(TextLintModuleLoader.Event.filterRule, ruleEntry);
}
开发者ID:,项目名称:,代码行数:36,代码来源:
示例3: loadFilterRule
/**
* load filter rule file with `ruleName` and define rule.
* if rule is not found, then throw ReferenceError.
* if already rule is loaded, do not anything.
* @param {string} ruleName
*/
loadFilterRule(ruleName: string) {
/*
Task
- check already define
- resolve package name
- load package
- emit rule
*/
// ignore already defined rule
// ignore rules from rulePaths because avoid ReferenceError is that try to require.
if (isFile(ruleName)) {
const ruleCreator = interopRequire(ruleName);
const ruleEntry = [ruleName, ruleCreator];
this.emit(TextLintModuleLoader.Event.filterRule, ruleEntry);
return;
}
const definedRuleName = normalizeTextlintFilterRuleKey(ruleName);
// ignore plugin's rule
if (isPluginRuleKey(definedRuleName)) {
Logger.warn(`${definedRuleName} is Plugin's rule. This is unknown case, please report issue.`);
return;
}
const pkgPath = this.moduleResolver.resolveFilterRulePackageName(ruleName);
debug("Loading filter rules from %s", pkgPath);
const ruleCreator = interopRequire(pkgPath);
const ruleEntry = [definedRuleName, ruleCreator];
this.emit(TextLintModuleLoader.Event.filterRule, ruleEntry);
}
开发者ID:textlint,项目名称:textlint,代码行数:34,代码来源:textlint-module-loader.ts
示例4: createFormatter
export function createFormatter(formatterConfig: FormatterConfig) {
const formatterName = formatterConfig.formatterName;
debug(`formatterName: ${formatterName}`);
let formatter: (results: TextlintResult[], formatterConfig: FormatterConfig) => string;
let formatterPath;
if (fs.existsSync(formatterName)) {
formatterPath = formatterName;
} else if (fs.existsSync(path.resolve(process.cwd(), formatterName))) {
formatterPath = path.resolve(process.cwd(), formatterName);
} else {
if (isFile(`${path.join(__dirname, "formatters/", formatterName)}.js`)) {
formatterPath = `${path.join(__dirname, "formatters/", formatterName)}.js`;
} else if (isFile(`${path.join(__dirname, "formatters/", formatterName)}.ts`)) {
formatterPath = `${path.join(__dirname, "formatters/", formatterName)}.ts`;
} else {
const pkgPath = tryResolve(`textlint-formatter-${formatterName}`) || tryResolve(formatterName);
if (pkgPath) {
formatterPath = pkgPath;
}
}
}
try {
formatter = interopRequire(formatterPath);
} catch (ex) {
throw new Error(`Could not find formatter ${formatterName}
${ex}`);
}
return function(results: TextlintResult[]) {
return formatter(results, formatterConfig);
};
}
开发者ID:textlint,项目名称:textlint,代码行数:31,代码来源:index.ts
示例5: loadPreset
loadPreset(presetName: string) {
/*
Caution: Rules of preset are defined as following.
{
"rules": {
"preset-gizmo": {
"ruleA": false
}
}
It mean that "ruleA" is defined as "preset-gizmo/ruleA"
*/
const RULE_NAME_PREFIX = this.config.constructor.RULE_NAME_PREFIX;
// Strip **rule** prefix
// textlint-rule-preset-gizmo -> preset-gizmo
const prefixMatch = new RegExp(`^${RULE_NAME_PREFIX}`);
const presetRuleNameWithoutPrefix = presetName.replace(prefixMatch, "");
// ignore plugin's rule
if (isPluginRuleKey(presetRuleNameWithoutPrefix)) {
Logger.warn(`${presetRuleNameWithoutPrefix} is Plugin's rule. This is unknown case, please report issue.`);
return;
}
const pkgPath = this.moduleResolver.resolvePresetPackageName(presetName);
debug("Loading rules from preset: %s", pkgPath);
const preset = interopRequire(pkgPath);
const entities = TextLintModuleMapper.createEntities(preset.rules, presetRuleNameWithoutPrefix);
entities.forEach(entry => {
this.emit(TextLintModuleLoader.Event.rule, entry);
});
}
开发者ID:,项目名称:,代码行数:33,代码来源:
示例6: loadPreset
loadPreset(presetName: string) {
/*
Caution: Rules of preset are defined as following.
{
"rules": {
"preset-gizmo": {
"ruleA": false
}
}
It mean that "ruleA" is defined as "preset-gizmo/ruleA"
*/
const presetRuleNameWithoutPrefix = normalizeTextlintRulePresetKey(presetName);
// ignore plugin's rule
if (isPluginRuleKey(presetRuleNameWithoutPrefix)) {
Logger.warn(`${presetRuleNameWithoutPrefix} is Plugin's rule. This is unknown case, please report issue.`);
return;
}
const pkgPath = this.moduleResolver.resolvePresetPackageName(presetName);
debug("Loading rules from preset: %s", pkgPath);
const preset = interopRequire(pkgPath);
const entities = TextLintModuleMapper.createEntities(preset.rules, presetRuleNameWithoutPrefix);
entities.forEach(entry => {
this.emit(TextLintModuleLoader.Event.rule, entry);
});
}
开发者ID:textlint,项目名称:textlint,代码行数:29,代码来源:textlint-module-loader.ts
示例7: interopRequire
fs.readdirSync(rulesDirAbsolutePath).forEach((file: string) => {
if (path.extname(file) !== extname) {
return;
}
const withoutExt = path.basename(file, extname);
rules[withoutExt] = interopRequire(path.join(rulesDirAbsolutePath, file));
});
开发者ID:textlint,项目名称:textlint,代码行数:7,代码来源:rule-loader.ts
示例8: Error
ruleNames.forEach(ruleName => {
const pkgPath = moduleResolver.resolvePresetPackageName(ruleName);
const preset = interopRequire(pkgPath);
if (!preset.hasOwnProperty("rules")) {
throw new Error(`${ruleName} has not rules`);
}
if (!preset.hasOwnProperty("rulesConfig")) {
throw new Error(`${ruleName} has not rulesConfig`);
}
// set config of <rule> to "<preset>/<rule>"
ObjectAssign(presetRulesConfig, mapRulesConfig(preset.rulesConfig, ruleName));
});
开发者ID:,项目名称:,代码行数:12,代码来源:
示例9: interopRequire
pluginNames.forEach(pluginName => {
const pkgPath = moduleResolver.resolvePluginPackageName(pluginName);
const plugin = interopRequire(pkgPath);
if (!plugin.hasOwnProperty("Processor")) {
return;
}
const Processor = plugin.Processor;
debug(`${pluginName} has Processor`);
assert(
typeof Processor.availableExtensions === "function",
"Processor.availableExtensions() should be implemented"
);
availableExtensions.push(...Processor.availableExtensions());
});
开发者ID:textlint,项目名称:textlint,代码行数:14,代码来源:plugin-loader.ts
示例10: Error
/**
* load rule from plugin name.
* plugin module has `rules` object and define rule with plugin prefix.
* @param {string} pluginName
*/
loadPlugin(pluginName: string) {
const pkgPath = this.moduleResolver.resolvePluginPackageName(pluginName);
debug("Loading rules from plugin: %s", pkgPath);
const plugin = interopRequire(pkgPath);
const pluginNameWithoutPrefix = normalizeTextlintPluginKey(pluginName);
// Notes: plugins not support "rules" and "rulesConfig"
// https://github.com/textlint/textlint/issues/291
if (plugin.hasOwnProperty("rules")) {
throw new Error(`textlint plugins not support "rules" and "rulesConfig".
But ${pluginName} has these filed.
For more details, See https://github.com/textlint/textlint/issues/291`);
}
// register plugin.Processor
if (!plugin.hasOwnProperty("Processor")) {
throw new Error(`textlint plugin should have "Processor".
For more details. See https://github.com/textlint/textlint/blob/master/docs/plugin.md`);
}
const pluginEntry = [pluginNameWithoutPrefix, plugin];
this.emit(TextLintModuleLoader.Event.plugin, pluginEntry);
}
开发者ID:textlint,项目名称:textlint,代码行数:25,代码来源:textlint-module-loader.ts
注:本文中的interop-require.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论