Files
test-repo/src/index.cjs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-09-23 09:46:18 +08:00
"use strict";
const prettierPromise = import("./index.js");
const functionNames = [
"formatWithCursor",
"format",
"check",
"resolveConfig",
"resolveConfigFile",
"clearConfigCache",
"getFileInfo",
"getSupportInfo",
];
const prettier = Object.create(null);
for (const name of functionNames) {
2022-10-26 10:55:37 +08:00
prettier[name] = async (...args) => {
const prettier = await prettierPromise;
return prettier[name](...args);
2022-09-23 09:46:18 +08:00
};
}
2022-10-26 10:55:37 +08:00
const debugApiFunctionNames = [
"parse",
"formatAST",
"formatDoc",
"printToDoc",
"printDocToString",
];
const debugApis = Object.create(null);
for (const name of debugApiFunctionNames) {
debugApis[name] = async (...args) => {
const prettier = await prettierPromise;
return prettier.__debug[name](...args);
};
}
prettier.__debug = debugApis;
2022-09-27 11:13:44 +08:00
if (process.env.NODE_ENV === "production") {
2023-02-13 10:17:39 +08:00
prettier.util = require("./utils/public.js");
prettier.doc = require("./document/public.js");
2022-09-27 11:13:44 +08:00
} else {
Object.defineProperties(prettier, {
util: {
get() {
try {
return require("./utils/public.js");
} catch {
// No op
}
2022-09-27 11:13:44 +08:00
throw new Error(
"prettier.util is not available in development CommonJS version",
);
},
},
doc: {
get() {
try {
return require("./document/public.js");
} catch {
// No op
}
2022-09-27 11:13:44 +08:00
throw new Error(
"prettier.doc is not available in development CommonJS version",
);
},
},
});
}
prettier.version = require("./main/version.evaluate.cjs");
2022-09-23 09:46:18 +08:00
module.exports = prettier;