mirror of
https://github.com/jackyzha0/quartz
synced 2026-11-27 22:14:40 +01:00
feat(cli): upgrade shows release notes and runs the new version's checks; skip built-in plugins in install/restore; bug report asks for quartz info
This commit is contained in:
10 files changed
+283
-27
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@jackyzha0/quartz": minor
|
||||
---
|
||||
|
||||
`npx quartz upgrade` shows the release notes of every version between the old and the new Quartz, then runs the new version's checks: it restores plugins, runs `plugin doctor` (plugin entries that are built in now, plugins that don't support the new version …) and lists plugin updates. Plugin install/restore skip plugins that are built into Quartz now, and `plugin doctor --fix` also removes their unused lockfile pins.
|
||||
@@ -28,13 +28,19 @@ You can help speed up fixing the problem by either
|
||||
1. providing a simple reproduction
|
||||
2. linking to your Quartz repository where the problem can be observed
|
||||
|
||||
**Desktop (please complete the following information):**
|
||||
**Quartz info**
|
||||
Run `npx quartz info` in your Quartz folder and paste its output here. It lists your Quartz version, Node/npm/OS and every plugin with its version — no content or site URL is included.
|
||||
|
||||
- Quartz Version: [e.g. v4.1.2]
|
||||
- `node` Version: [e.g. v18.16]
|
||||
- `npm` version: [e.g. v10.1.0]
|
||||
- OS: [e.g. iOS]
|
||||
- Browser [e.g. chrome, safari]
|
||||
```
|
||||
Paste the output of `npx quartz info` here
|
||||
```
|
||||
|
||||
(Quartz older than 5.1 doesn't have `npx quartz info`: give the Quartz version from `package.json` and the output of `git log -1 --format=%h`, plus your `node` and `npm` versions and OS.)
|
||||
|
||||
**Browser** (for display problems): [e.g. Firefox 140, Safari on iOS 18]
|
||||
|
||||
**Build output**
|
||||
If the build failed or printed warnings, paste the full output of `npx quartz build`, including the summary at the end.
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
+1
-1
@@ -158,7 +158,7 @@ npx quartz plugin doctor --fix # move settings of plugins that are now bui
|
||||
- broken local plugin symlinks and plugins without a built entry point (`dist/`)
|
||||
- option typos and type mismatches, and declared plugin dependencies that are missing or disabled
|
||||
- plugins that don't support your Quartz version (their `quartzVersion`, see [[versioning#Plugin compatibility]])
|
||||
- entries for plugins that are now [[built-in processing|built into Quartz]] (`crawl-links`, `remove-draft`, `content-index`); `--fix` moves their options into `configuration` and keeps your comments
|
||||
- entries for plugins that are now [[built-in processing|built into Quartz]] (`crawl-links`, `remove-draft`, `content-index`); `--fix` moves their options into `configuration` (keeping your comments) and removes their now unused pins from `quartz.lock.json`
|
||||
- lockfile entries that are no longer configured (clean up with `prune`)
|
||||
|
||||
It exits with status 1 when it finds errors, so it can run as a CI check.
|
||||
|
||||
+7
-4
@@ -16,10 +16,13 @@ When you run `npx quartz upgrade`, Quartz performs the following steps:
|
||||
|
||||
1. **Backs up your content** — your content folder is cached locally to prevent data loss.
|
||||
2. **Pulls the latest Quartz code** — fetches and merges from the official upstream repository (`upstream/v5`) using Git.
|
||||
3. **Shows version changes** — displays the version transition (e.g., `v5.0.0 → v5.1.0`) or confirms you're already up to date.
|
||||
4. **Updates dependencies** — runs `npm install` to ensure all packages match the new version.
|
||||
5. **Restores plugins** — reinstalls plugins from `quartz.lock.json` to ensure compatibility.
|
||||
6. **Checks plugin compatibility** — verifies that installed plugins are compatible with the new Quartz version.
|
||||
3. **Updates dependencies** — runs `npm install` to ensure all packages match the new version.
|
||||
4. **Shows what changed** — the version transition (e.g. `5.0.0 → 5.1.0`) and the release notes of every version in between, from `CHANGELOG.md`. Between releases it says how many commits were pulled.
|
||||
5. **Restores plugins** — reinstalls plugins from `quartz.lock.json`. Plugins that are now [[built-in processing|built into Quartz]] are skipped.
|
||||
6. **Checks your config and plugins** — runs [[cli/plugin#doctor|`npx quartz plugin doctor`]] for the new version: plugin entries that are built in now (fix with `npx quartz plugin doctor --fix`), plugins that don't support the new Quartz version, lockfile and install problems.
|
||||
7. **Checks for plugin updates** — lists plugins with newer versions available.
|
||||
|
||||
Steps 4–7 run the code of the version you upgraded _to_, so the checks know about that version's changes. (Upgrading _from_ a Quartz older than 5.1 still runs the older steps once.)
|
||||
|
||||
## Handling Conflicts
|
||||
|
||||
|
||||
@@ -140,6 +140,8 @@ export function migrateBuiltinEntries(input) {
|
||||
* source), the configuration key to point the user to; otherwise undefined.
|
||||
*/
|
||||
export function builtinKeyFor(nameOrSource) {
|
||||
// object sources: { repo: "github:quartz-community/crawl-links", … }
|
||||
if (typeof nameOrSource?.repo === "string") nameOrSource = nameOrSource.repo
|
||||
if (typeof nameOrSource !== "string") return undefined
|
||||
const name = officialPluginName(nameOrSource) ?? nameOrSource
|
||||
return ABSORBED[name]?.key
|
||||
@@ -149,6 +151,7 @@ export function builtinKeyFor(nameOrSource) {
|
||||
export function builtinMessage(nameOrSource) {
|
||||
const key = builtinKeyFor(nameOrSource)
|
||||
if (!key) return undefined
|
||||
if (typeof nameOrSource?.repo === "string") nameOrSource = nameOrSource.repo
|
||||
const name = officialPluginName(nameOrSource) ?? nameOrSource
|
||||
const toggle = key === "drafts" ? "publish: true" : "enabled: false"
|
||||
return (
|
||||
|
||||
@@ -129,6 +129,12 @@ describe("built-in helpers", () => {
|
||||
assert.strictEqual(builtinKeyFor("@quartz-community/content-index"), "contentIndex")
|
||||
assert.strictEqual(builtinKeyFor("graph"), undefined)
|
||||
assert.match(builtinMessage("remove-draft"), /configuration\.drafts.*publish: true/)
|
||||
assert.strictEqual(builtinKeyFor({ repo: "github:quartz-community/crawl-links" }), "links")
|
||||
assert.match(
|
||||
builtinMessage({ repo: "github:quartz-community/crawl-links" }),
|
||||
/^crawl-links is built into Quartz/,
|
||||
)
|
||||
assert.strictEqual(builtinKeyFor({ repo: "github:me/crawl-links-fork" }), undefined)
|
||||
})
|
||||
|
||||
test("describeBuiltins reflects configuration", () => {
|
||||
|
||||
+31
-14
@@ -9,6 +9,7 @@ import { rm } from "fs/promises"
|
||||
import chokidar from "chokidar"
|
||||
import prettyBytes from "pretty-bytes"
|
||||
import { execSync, spawnSync } from "child_process"
|
||||
import { pathToFileURL } from "url"
|
||||
import http from "http"
|
||||
import serveHandler from "serve-handler"
|
||||
import { WebSocketServer } from "ws"
|
||||
@@ -618,6 +619,7 @@ export async function handleBuild(argv) {
|
||||
export async function handleUpgrade(argv) {
|
||||
const contentFolder = resolveContentPath(argv.directory)
|
||||
console.log(`\n${styleText(["bgGreen", "black"], ` Quartz v${version} `)} \n`)
|
||||
const fromCommit = describeQuartzCheckout().commit
|
||||
console.log("Backing up your content")
|
||||
execSync(`git remote show upstream || git remote add upstream ${QUARTZ_SOURCE_REPO}`)
|
||||
await stashContentFolder(contentFolder)
|
||||
@@ -672,15 +674,6 @@ export async function handleUpgrade(argv) {
|
||||
|
||||
await popContentFolder(contentFolder)
|
||||
|
||||
// Read the new version after pulling
|
||||
const newPkg = JSON.parse(fs.readFileSync("./package.json").toString())
|
||||
const newVersion = newPkg.version
|
||||
if (newVersion !== version) {
|
||||
console.log(styleText("cyan", `Upgraded Quartz: v${version} → v${newVersion}`))
|
||||
} else {
|
||||
console.log(styleText("gray", `Quartz is already up to date (v${version})`))
|
||||
}
|
||||
|
||||
console.log("Ensuring dependencies are up to date")
|
||||
|
||||
/*
|
||||
@@ -710,11 +703,35 @@ export async function handleUpgrade(argv) {
|
||||
)
|
||||
}
|
||||
|
||||
console.log("Restoring plugins from lockfile...")
|
||||
await handlePluginRestore()
|
||||
|
||||
console.log("Checking plugin compatibility...")
|
||||
await handlePluginCheck()
|
||||
// Finish with the *new* code (release notes, plugin restore, doctor) — see cli/upgrade.js.
|
||||
// This process is still running the Quartz that was checked out before the pull.
|
||||
const finishScript = path.resolve("quartz/cli/upgrade.js")
|
||||
if (fs.existsSync(finishScript)) {
|
||||
const script =
|
||||
`import(${JSON.stringify(pathToFileURL(finishScript).href)})` +
|
||||
`.then((m) => m.finishUpgrade(${JSON.stringify({ fromVersion: version, fromCommit })}))` +
|
||||
`.catch((err) => { console.error(err); process.exitCode = 1 })`
|
||||
const res = spawnSync(process.execPath, ["--input-type=module", "-e", script], {
|
||||
stdio: "inherit",
|
||||
timeout: 15 * 60 * 1000,
|
||||
})
|
||||
if (res.status !== 0) {
|
||||
console.log(
|
||||
styleText("yellow", "Some checks reported problems (see above).") +
|
||||
" Run `npx quartz plugin doctor` after fixing them.",
|
||||
)
|
||||
process.exitCode = 1
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// Upgraded to a Quartz without cli/upgrade.js (e.g. a downgrade): use this version's steps.
|
||||
const newVersion = JSON.parse(fs.readFileSync("./package.json").toString()).version
|
||||
console.log(styleText("cyan", `Quartz v${version} → v${newVersion}`))
|
||||
console.log("Restoring plugins from lockfile...")
|
||||
await handlePluginRestore()
|
||||
console.log("Checking plugin compatibility...")
|
||||
await handlePluginCheck()
|
||||
}
|
||||
|
||||
console.log(styleText("green", "Done!"))
|
||||
}
|
||||
|
||||
@@ -510,8 +510,22 @@ export async function handlePluginInstallUnified({
|
||||
|
||||
const resolvedConcurrency = Math.max(1, concurrencyOption ?? os.cpus().length)
|
||||
|
||||
const pluginsJson = readPluginsJson()
|
||||
// Plugins that are built into core now (crawl-links, remove-draft, content-index) are never
|
||||
// cloned or built, even if the config or the lockfile still lists them.
|
||||
const rawPluginsJson = readPluginsJson()
|
||||
const pluginsJson = rawPluginsJson && {
|
||||
...rawPluginsJson,
|
||||
plugins: (rawPluginsJson.plugins ?? []).filter((entry) => !builtinMessage(entry.source)),
|
||||
}
|
||||
let lockfile = readLockfile()
|
||||
if (lockfile) {
|
||||
lockfile = {
|
||||
...lockfile,
|
||||
plugins: Object.fromEntries(
|
||||
Object.entries(lockfile.plugins ?? {}).filter(([name]) => !builtinMessage(name)),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
if (!fromConfig && !lockfile) {
|
||||
const gitEntries = (pluginsJson?.plugins ?? []).filter((entry) => {
|
||||
@@ -2523,6 +2537,25 @@ export async function handlePluginDoctor({ verbose = false, fix = false } = {})
|
||||
"Restore it from git, or delete it and run 'npx quartz plugin install'.",
|
||||
)
|
||||
}
|
||||
// Pins of plugins that are built into core now are unused (never installed or loaded).
|
||||
const builtinPins = Object.keys(lockfile?.plugins ?? {}).filter((name) => builtinMessage(name))
|
||||
if (builtinPins.length > 0 && fix) {
|
||||
for (const name of builtinPins) delete lockfile.plugins[name]
|
||||
writeLockfile(lockfile)
|
||||
console.log(
|
||||
styleText(
|
||||
"green",
|
||||
`✓ Removed unused quartz.lock.json pins (built in now): ${builtinPins.join(", ")}`,
|
||||
),
|
||||
)
|
||||
} else if (builtinPins.length > 0) {
|
||||
report(
|
||||
"warning",
|
||||
"quartz.lock.json",
|
||||
`pins plugins that are built into Quartz now (unused): ${builtinPins.join(", ")}`,
|
||||
"Run 'npx quartz plugin doctor --fix' to remove them.",
|
||||
)
|
||||
}
|
||||
|
||||
const seen = new Map()
|
||||
const enabledSources = new Map()
|
||||
@@ -2708,7 +2741,9 @@ export async function handlePluginDoctor({ verbose = false, fix = false } = {})
|
||||
}
|
||||
}),
|
||||
)
|
||||
const orphans = Object.keys(lockfile.plugins).filter((n) => !configured.has(n))
|
||||
const orphans = Object.keys(lockfile.plugins).filter(
|
||||
(n) => !configured.has(n) && !builtinPins.includes(n),
|
||||
)
|
||||
if (orphans.length > 0) {
|
||||
report(
|
||||
"warning",
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* The part of `npx quartz upgrade` that runs after the new Quartz has been pulled.
|
||||
*
|
||||
* `handleUpgrade` is executed by the *old* Quartz (the code that was checked out when the command
|
||||
* started). After `git pull` + `npm i` it runs `finishUpgrade` from the freshly pulled code in a new
|
||||
* Node process, so the checks below are always the ones of the version being upgraded to — e.g. its
|
||||
* `plugin doctor` knows about plugins that became built-ins and new plugin version requirements.
|
||||
*/
|
||||
import fs from "node:fs"
|
||||
import path from "node:path"
|
||||
import { execFileSync } from "node:child_process"
|
||||
import { styleText } from "node:util"
|
||||
import semver from "semver"
|
||||
import { describeQuartzCheckout, formatQuartzVersion, readQuartzVersion } from "./compat.js"
|
||||
|
||||
const RELEASES_URL = "https://github.com/jackyzha0/quartz/releases"
|
||||
|
||||
/**
|
||||
* Sections of a changesets CHANGELOG.md ("## 5.1.0" headings) for versions after `from` up to and
|
||||
* including `to`, newest first.
|
||||
*/
|
||||
export function changelogSections(markdown, from, to) {
|
||||
const sections = []
|
||||
let current
|
||||
for (const line of markdown.split("\n")) {
|
||||
const heading = line.match(/^## (\S+)\s*$/)
|
||||
if (heading) {
|
||||
current = semver.valid(heading[1]) ? { version: heading[1], lines: [] } : undefined
|
||||
if (current) sections.push(current)
|
||||
continue
|
||||
}
|
||||
current?.lines.push(line)
|
||||
}
|
||||
return sections
|
||||
.filter(
|
||||
(s) =>
|
||||
(!from || !semver.valid(from) || semver.gt(s.version, from)) &&
|
||||
(!to || !semver.valid(to) || semver.lte(s.version, to)),
|
||||
)
|
||||
.sort((a, b) => semver.rcompare(a.version, b.version))
|
||||
.map((s) => ({ version: s.version, body: s.lines.join("\n").trim() }))
|
||||
}
|
||||
|
||||
/** Changelog sections as terminal text, cut off after `maxLines` with a link to the releases. */
|
||||
export function formatChangelog(sections, { maxLines = 60 } = {}) {
|
||||
const lines = []
|
||||
for (const s of sections) {
|
||||
lines.push(styleText("bold", `Quartz ${s.version}`), ...s.body.split("\n"), "")
|
||||
}
|
||||
if (lines.length > maxLines) {
|
||||
return [
|
||||
...lines.slice(0, maxLines),
|
||||
styleText("gray", `… see the full release notes: ${RELEASES_URL}`),
|
||||
].join("\n")
|
||||
}
|
||||
return lines.join("\n").trimEnd()
|
||||
}
|
||||
|
||||
function commitsSince(commit, root) {
|
||||
if (!commit) return undefined
|
||||
try {
|
||||
const out = execFileSync("git", ["rev-list", "--count", `${commit}..HEAD`], {
|
||||
cwd: root,
|
||||
encoding: "utf8",
|
||||
timeout: 5000,
|
||||
stdio: ["ignore", "pipe", "ignore"],
|
||||
})
|
||||
return Number(out.trim())
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
/** What changed between the old and the new checkout, plus the release notes in between. */
|
||||
export function describeUpgrade({ fromVersion, fromCommit, root = process.cwd() }) {
|
||||
const toVersion = readQuartzVersion(root)
|
||||
const display = formatQuartzVersion(toVersion, describeQuartzCheckout(root))
|
||||
const lines = []
|
||||
if (fromVersion && toVersion && fromVersion !== toVersion) {
|
||||
lines.push(styleText("cyan", `Upgraded Quartz ${fromVersion} → ${display}`))
|
||||
let markdown = ""
|
||||
try {
|
||||
markdown = fs.readFileSync(path.join(root, "CHANGELOG.md"), "utf8")
|
||||
} catch {}
|
||||
const sections = changelogSections(markdown, fromVersion, toVersion)
|
||||
if (sections.length > 0) {
|
||||
lines.push("", formatChangelog(sections), "")
|
||||
} else {
|
||||
lines.push(styleText("gray", `Release notes: ${RELEASES_URL}`))
|
||||
}
|
||||
} else {
|
||||
const count = commitsSince(fromCommit, root)
|
||||
lines.push(
|
||||
count
|
||||
? styleText(
|
||||
"cyan",
|
||||
`Pulled ${count} new commit${count === 1 ? "" : "s"} — Quartz ${display} (not released yet; changes are listed in .changeset/)`,
|
||||
)
|
||||
: styleText("gray", `Quartz is already up to date (${display})`),
|
||||
)
|
||||
}
|
||||
return lines.join("\n")
|
||||
}
|
||||
|
||||
/** Run by `npx quartz upgrade` from the newly pulled code (see top of file). */
|
||||
export async function finishUpgrade({ fromVersion, fromCommit } = {}) {
|
||||
console.log(describeUpgrade({ fromVersion, fromCommit }))
|
||||
|
||||
const { handlePluginRestore, handlePluginDoctor, handlePluginCheck } =
|
||||
await import("./plugin-git-handlers.js")
|
||||
console.log()
|
||||
await handlePluginRestore()
|
||||
|
||||
console.log("\nChecking your config and plugins against this Quartz version...")
|
||||
await handlePluginDoctor()
|
||||
|
||||
console.log("\nChecking for plugin updates...")
|
||||
await handlePluginCheck()
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import test, { describe } from "node:test"
|
||||
import assert from "node:assert"
|
||||
import { changelogSections, formatChangelog } from "./upgrade.js"
|
||||
|
||||
const CHANGELOG = `# @jackyzha0/quartz
|
||||
|
||||
## 5.2.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- abc1234: Something new
|
||||
|
||||
## 5.1.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- def5678: A fix
|
||||
|
||||
## 5.1.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- Built-in processing
|
||||
|
||||
## 5.0.0
|
||||
|
||||
- Plugin system
|
||||
`
|
||||
|
||||
describe("changelogSections", () => {
|
||||
test("returns the versions after `from` up to `to`, newest first", () => {
|
||||
const sections = changelogSections(CHANGELOG, "5.1.0", "5.2.0")
|
||||
assert.deepStrictEqual(
|
||||
sections.map((s) => s.version),
|
||||
["5.2.0", "5.1.1"],
|
||||
)
|
||||
assert.match(sections[1].body, /### Patch Changes\n\n- def5678: A fix/)
|
||||
})
|
||||
|
||||
test("skipping several releases includes all of them; nothing newer than `to`", () => {
|
||||
assert.deepStrictEqual(
|
||||
changelogSections(CHANGELOG, "5.0.0", "5.1.1").map((s) => s.version),
|
||||
["5.1.1", "5.1.0"],
|
||||
)
|
||||
})
|
||||
|
||||
test("no changelog or same version → nothing", () => {
|
||||
assert.deepStrictEqual(changelogSections("", "5.0.0", "5.1.0"), [])
|
||||
assert.deepStrictEqual(changelogSections(CHANGELOG, "5.2.0", "5.2.0"), [])
|
||||
})
|
||||
})
|
||||
|
||||
describe("formatChangelog", () => {
|
||||
test("cuts long notes off with a link to the releases", () => {
|
||||
const text = formatChangelog(changelogSections(CHANGELOG, "5.0.0", "5.2.0"), {
|
||||
maxLines: 5,
|
||||
}).replace(/\x1b\[[0-9;]*m/g, "")
|
||||
assert.strictEqual(text.split("\n").length, 6)
|
||||
assert.match(text, /^Quartz 5\.2\.0/)
|
||||
assert.match(text, /github\.com\/jackyzha0\/quartz\/releases$/)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user