Update runPrettier so that it will still work if we ever switch to ESM
This commit is contained in:
parent
947efe8d63
commit
bc396bc41b
@ -52,10 +52,26 @@ export async function getPrettier(): Promise<PrettierAndConfigHash> {
|
|||||||
// So we do a sketchy eval to bypass ncc.
|
// So we do a sketchy eval to bypass ncc.
|
||||||
// We make sure to only do that when linking, otherwise we import properly.
|
// We make sure to only do that when linking, otherwise we import properly.
|
||||||
if (readThisNpmPackageVersion().startsWith("0.0.0")) {
|
if (readThisNpmPackageVersion().startsWith("0.0.0")) {
|
||||||
eval(
|
const prettierDirPath = pathResolve(
|
||||||
`${symToStr({ prettier })} = require("${pathResolve(pathJoin(getNodeModulesBinDirPath({ packageJsonFilePath: undefined }), "..", "prettier"))}")`
|
pathJoin(
|
||||||
|
getNodeModulesBinDirPath({ packageJsonFilePath: undefined }),
|
||||||
|
"..",
|
||||||
|
"prettier"
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const isCJS = typeof module !== "undefined" && module.exports;
|
||||||
|
|
||||||
|
if (isCJS) {
|
||||||
|
eval(`${symToStr({ prettier })} = require("${prettierDirPath}")`);
|
||||||
|
} else {
|
||||||
|
prettier = await new Promise(_resolve => {
|
||||||
|
eval(
|
||||||
|
`import("file:///${pathJoin(prettierDirPath, "index.mjs").replace(/\\/g, "/")}").then(prettier => _resolve(prettier))`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
assert(!is<undefined>(prettier));
|
assert(!is<undefined>(prettier));
|
||||||
|
|
||||||
break import_prettier;
|
break import_prettier;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user