Files
test-repo/tests/config/get-prettier.js
T

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

38 lines
904 B
JavaScript
Raw Normal View History

2022-02-12 15:39:16 +08:00
import path from "node:path";
import { pathToFileURL } from "node:url";
2022-02-12 15:39:16 +08:00
2022-05-10 15:43:02 +08:00
function getPrettierInternal() {
2025-12-24 22:57:02 +08:00
if (process.env.TEST_RUNTIME === "browser") {
return import("./browser-prettier/browser-prettier.js");
2025-12-24 22:57:02 +08:00
}
2022-05-10 15:43:02 +08:00
if (process.env.TEST_STANDALONE) {
const entry = new URL("./require-standalone.cjs", import.meta.url);
return import(entry).then((module) => module.default);
}
2022-02-12 15:39:16 +08:00
2022-10-18 10:01:09 +08:00
const { PRETTIER_INSTALLED_DIR } = process.env;
if (PRETTIER_INSTALLED_DIR) {
return import(
pathToFileURL(path.join(PRETTIER_INSTALLED_DIR, "index-proxy.mjs"))
);
}
2022-09-23 09:46:18 +08:00
const entry = pathToFileURL(
path.join(
process.env.PRETTIER_DIR,
process.env.NODE_ENV === "production" ? "index.mjs" : "index.js",
),
);
2022-05-10 15:43:02 +08:00
return import(entry);
}
let promise;
function getPrettier() {
promise = promise ?? getPrettierInternal();
2022-05-10 15:43:02 +08:00
return promise;
}
2022-02-12 15:39:16 +08:00
export default getPrettier;