Remove the dynamic `require()` call in the standalone bundle (#5612)
* Remove the dynamic `require()` call in the standalone bundle * Liiiint * Just use `replaceStrings` * Reword error messagemaster
parent
5e89969a9e
commit
b74f94d6dd
|
@ -95,6 +95,7 @@ function getRollupConfig(bundle) {
|
|||
};
|
||||
|
||||
const replaceStrings = {
|
||||
"process.env.PRETTIER_TARGET": JSON.stringify(bundle.target),
|
||||
"process.env.NODE_ENV": JSON.stringify("production")
|
||||
};
|
||||
if (bundle.target === "universal") {
|
||||
|
|
|
@ -42,16 +42,26 @@ function resolveParser(opts, parsers) {
|
|||
if (parsers.hasOwnProperty(opts.parser)) {
|
||||
return parsers[opts.parser];
|
||||
}
|
||||
try {
|
||||
return {
|
||||
parse: eval("require")(path.resolve(process.cwd(), opts.parser)),
|
||||
astFormat: "estree",
|
||||
locStart,
|
||||
locEnd
|
||||
};
|
||||
} catch (err) {
|
||||
/* istanbul ignore next */
|
||||
throw new ConfigError(`Couldn't resolve parser "${opts.parser}"`);
|
||||
|
||||
/* istanbul ignore next */
|
||||
if (process.env.PRETTIER_TARGET === "universal") {
|
||||
throw new ConfigError(
|
||||
`Couldn't resolve parser "${
|
||||
opts.parser
|
||||
}". Parsers must be explicitly added to the standalone bundle.`
|
||||
);
|
||||
} else {
|
||||
try {
|
||||
return {
|
||||
parse: eval("require")(path.resolve(process.cwd(), opts.parser)),
|
||||
astFormat: "estree",
|
||||
locStart,
|
||||
locEnd
|
||||
};
|
||||
} catch (err) {
|
||||
/* istanbul ignore next */
|
||||
throw new ConfigError(`Couldn't resolve parser "${opts.parser}"`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue