关闭 Quartz v5 编译时提示的 direct-eval 警告

升级 Quartz v5 编译时会因为使用的插件 note-properties 用到的 gray-matter 库包含 eval 而产生一个 direct-eval 的 warning。

$ node ./quartz/bootstrap-cli.mjs "build"
 
 Quartz v5.0.0
 
Cleaned output directory `public` in 851μs
Found 226 input files from `content` in 17ms
[WARNING] Using direct eval with a bundler is not recommended and may cause problems [direct-eval]
 
    .quartz/plugins/note-properties/dist/index.js:3117:17:
      3117 │           return eval(str) || {};
~~~~
 
  You can read more about direct eval and bundling here: https://esbuild.github.io/link/direct-eval
 

这里记录关闭它的方法,因为目前 v5 版本尝试关过但没关全。变动比较小,不打算提 PR

项目中有好几处调用 esbuild 的入口,大部分在 cli/handlers.js 中,那里本来就有 logOverride,我还纳闷为什么不生效。调试确定在其他地方还有,加上就好

quartz/processors/parse.ts
async function transpileWorkerScript() {
  // transpile worker script
  const cacheFile = "./.quartz-cache/transpiled-worker.mjs"
  const fp = "./quartz/worker.ts"
  return esbuild.build({
    entryPoints: [fp],
    outfile: path.join(QUARTZ, cacheFile),
    bundle: true,
    keepNames: true,
    platform: "node",
    format: "esm",
    packages: "external",
    sourcemap: true,
    sourcesContent: false,
    logOverride: {
      "direct-eval": "silent",
    },