From a0d651d64dfd766157324fd86791da2168028cf2 Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Sat, 5 Aug 2023 17:53:29 -0700 Subject: [PATCH] reverse query param hack to re-add sourcemap support --- package-lock.json | 10 ++++++++++ package.json | 1 + quartz/bootstrap-cli.mjs | 6 ++++-- quartz/build.ts | 19 ++++++++++++++++++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index e1122dd..f8eb5a4 100644 --- a/package-lock.json +++ b/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", diff --git a/package.json b/package.json index f5e3ab8..0d5e7a0 100644 --- a/package.json +++ b/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", diff --git a/quartz/bootstrap-cli.mjs b/quartz/bootstrap-cli.mjs index d550aea..8b9bea9 100755 --- a/quartz/bootstrap-cli.mjs +++ b/quartz/bootstrap-cli.mjs @@ -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() diff --git a/quartz/build.ts b/quartz/build.ts index b395f73..9f38882 100644 --- a/quartz/build.ts +++ b/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 { 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 = {