Jacky Zhao
2023-08-06 a0d651d64dfd766157324fd86791da2168028cf2
reverse query param hack to re-add sourcemap support
4 files modified
36 ■■■■■ changed files
package-lock.json 10 ●●●●● patch | view | raw | blame | history
package.json 1 ●●●● patch | view | raw | blame | history
quartz/bootstrap-cli.mjs 6 ●●●●● patch | view | raw | blame | history
quartz/build.ts 19 ●●●●● patch | view | raw | blame | history
package-lock.json
@@ -73,6 +73,7 @@
        "@types/node": "^20.1.2",
        "@types/pretty-time": "^1.1.2",
        "@types/serve-handler": "^6.1.1",
        "@types/source-map-support": "^0.5.6",
        "@types/workerpool": "^6.4.0",
        "@types/ws": "^8.5.5",
        "@types/yargs": "^17.0.24",
@@ -1486,6 +1487,15 @@
        "@types/node": "*"
      }
    },
    "node_modules/@types/source-map-support": {
      "version": "0.5.6",
      "resolved": "https://registry.npmjs.org/@types/source-map-support/-/source-map-support-0.5.6.tgz",
      "integrity": "sha512-b2nJ9YyXmkhGaa2b8VLM0kJ04xxwNyijcq12/kDoomCt43qbHBeK2SLNJ9iJmETaAj+bKUT05PQUu3Q66GvLhQ==",
      "dev": true,
      "dependencies": {
        "source-map": "^0.6.0"
      }
    },
    "node_modules/@types/unist": {
      "version": "2.0.6",
      "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.6.tgz",
package.json
@@ -89,6 +89,7 @@
    "@types/node": "^20.1.2",
    "@types/pretty-time": "^1.1.2",
    "@types/serve-handler": "^6.1.1",
    "@types/source-map-support": "^0.5.6",
    "@types/workerpool": "^6.4.0",
    "@types/ws": "^8.5.5",
    "@types/yargs": "^17.0.24",
quartz/bootstrap-cli.mjs
@@ -298,14 +298,15 @@
      outfile: path.join("quartz", cacheFile),
      bundle: true,
      keepNames: true,
      minify: true,
      minifyWhitespace: true,
      minifySyntax: true,
      platform: "node",
      format: "esm",
      jsx: "automatic",
      jsxImportSource: "preact",
      packages: "external",
      metafile: true,
      sourcemap: "inline",
      sourcemap: true,
      sourcesContent: false,
      plugins: [
        sassPlugin({
@@ -374,6 +375,7 @@
      }
      // bypass module cache
      // https://github.com/nodejs/modules/issues/307
      const { default: buildQuartz } = await import(cacheFile + `?update=${randomUUID()}`)
      await buildQuartz(argv, clientRefresh)
      clientRefresh()
quartz/build.ts
@@ -1,4 +1,19 @@
import "source-map-support/register.js"
import sourceMapSupport from "source-map-support"
sourceMapSupport.install({
  retrieveSourceMap(source) {
    // source map hack to get around query param
    // import cache busting
    if (source.includes(".quartz-cache")) {
      let realSource = fileURLToPath(source.split("?", 2)[0] + '.map')
      return {
        map: fs.readFileSync(realSource, 'utf8')
      }
    } else {
      return null
    }
  }
})
import path from "path"
import { PerfTimer } from "./perf"
import { rimraf } from "rimraf"
@@ -14,6 +29,8 @@
import { Argv, BuildCtx } from "./ctx"
import { glob, toPosixPath } from "./glob"
import { trace } from "./trace"
import { fileURLToPath } from "url"
import fs from "fs"
async function buildQuartz(argv: Argv, clientRefresh: () => void) {
  const ctx: BuildCtx = {