Files
test-repo/index.js
T
Alexander Kachkaev 7345a38e64 Fix plugin API in globally installed Prettier and introduce optional --plugin-search-dir (#4192)
* Fix plugin API in globally installed Prettier and introduce optional --plugin-search-dir

* Use find-parent-dir instead of find-up and test autoloading (with mocked fn)

* Add two test cases where --plugin-search-dir is not .

* Do not mutate pluginSearchDirs argument in load-plugins.js

* Do not test automatic plugin resolution as mocking of "find-parent-dir" does not work due to rollup

* Document --plugin-search-dir / pluginSearchDirs and improve spacing

* Address @ikatyang's review comments

* Fix require path for third-party

* Undo alphabetic sorting of third-party scripts
2018-05-09 19:17:12 +08:00

65 lines
1.5 KiB
JavaScript

"use strict";
const version = require("./package.json").version;
const core = require("./src/main/core");
const getSupportInfo = require("./src/main/support").getSupportInfo;
const sharedUtil = require("./src/common/util-shared");
const loadPlugins = require("./src/common/load-plugins");
const config = require("./src/config/resolve-config");
const doc = require("./src/doc");
// Luckily `opts` is always the 2nd argument
function withPlugins(fn) {
return function() {
const args = Array.from(arguments);
const opts = args[1] || {};
args[1] = Object.assign({}, opts, {
plugins: loadPlugins(opts.plugins, opts.pluginSearchDirs)
});
return fn.apply(null, args);
};
}
const formatWithCursor = withPlugins(core.formatWithCursor);
module.exports = {
formatWithCursor,
format(text, opts) {
return formatWithCursor(text, opts).formatted;
},
check: function(text, opts) {
try {
const formatted = formatWithCursor(text, opts).formatted;
return formatted === text;
} catch (e) {
return false;
}
},
doc,
resolveConfig: config.resolveConfig,
resolveConfigFile: config.resolveConfigFile,
clearConfigCache: config.clearCache,
getSupportInfo: withPlugins(getSupportInfo),
version,
util: sharedUtil,
/* istanbul ignore next */
__debug: {
parse: withPlugins(core.parse),
formatAST: withPlugins(core.formatAST),
formatDoc: withPlugins(core.formatDoc),
printToDoc: withPlugins(core.printToDoc),
printDocToString: withPlugins(core.printDocToString)
}
};