reverse query param hack to re-add sourcemap support

This commit is contained in:
Jacky Zhao 2023-08-05 17:53:29 -07:00
parent 6d2291bbf1
commit cf18b99937
4 changed files with 33 additions and 3 deletions

10
package-lock.json generated
View File

@ -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",

View File

@ -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",

View File

@ -298,14 +298,15 @@ See the [documentation](https://quartz.jzhao.xyz) for how to get started.
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 @@ See the [documentation](https://quartz.jzhao.xyz) for how to get started.
}
// bypass module cache
// https://github.com/nodejs/modules/issues/307
const { default: buildQuartz } = await import(cacheFile + `?update=${randomUUID()}`)
await buildQuartz(argv, clientRefresh)
clientRefresh()

View File

@ -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 { ProcessedContent } from "./plugins/vfile"
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 = {