mirror of
https://github.com/jackyzha0/quartz
synced 2026-11-30 22:44:41 +01:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d255c3a0b | ||
|
|
f5ef8f738d | ||
|
|
e7da9cebf4 | ||
|
|
28581e8e54 | ||
|
|
4ff86a7809 | ||
|
|
0f294f7139 |
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@jackyzha0/quartz": patch
|
||||
---
|
||||
|
||||
On Windows, regenerating `.quartz/plugins/index.ts` (`npm run install-plugins`, which also runs before every `npm run build`) no longer skips npm plugins with "dist/index.d.ts could not be found", which left exports such as `ExternalPlugin.Explorer` undefined. The package's location was read from a `file:` URL's pathname (`/C:/…`), which is not a Windows path.
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
"@jackyzha0/quartz": patch
|
||||
---
|
||||
|
||||
A local plugin source written with Windows separators (`.\my-plugin`, `..\plugins\my-plugin`) is recognised as a local path. Before, it was read as a git or npm source and failed with "Expected github:owner/repo".
|
||||
|
||||
Pretty links shorten link text the same way on every OS: Windows also cut it at a backslash (`[[a\b]]` showed `b`).
|
||||
@@ -264,6 +264,10 @@ export function isLocalSource(source) {
|
||||
if (url.startsWith("./") || url.startsWith("../") || url.startsWith("/")) {
|
||||
return true
|
||||
}
|
||||
// Windows relative paths (.\plugin, ..\plugin)
|
||||
if (url.startsWith(".\\") || url.startsWith("..\\")) {
|
||||
return true
|
||||
}
|
||||
// Windows absolute paths (e.g. C:\ or D:/)
|
||||
if (/^[A-Za-z]:[\\/]/.test(url)) {
|
||||
return true
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import test, { describe } from "node:test"
|
||||
import assert from "node:assert"
|
||||
import YAML from "yaml"
|
||||
import { stringifyConfigYaml, parseGitSource, extractPluginName } from "./plugin-data.js"
|
||||
import {
|
||||
stringifyConfigYaml,
|
||||
parseGitSource,
|
||||
extractPluginName,
|
||||
isLocalSource,
|
||||
} from "./plugin-data.js"
|
||||
|
||||
const ORIGINAL = `# yaml-language-server: $schema=./quartz/plugins/quartz-plugins.schema.json
|
||||
configuration:
|
||||
@@ -92,3 +97,23 @@ describe("parseGitSource", () => {
|
||||
assert.throws(() => parseGitSource("github:onlyowner"), /Expected github:owner\/repo/)
|
||||
})
|
||||
})
|
||||
|
||||
describe("isLocalSource", () => {
|
||||
test("recognises local paths in POSIX and Windows spellings", () => {
|
||||
for (const source of [
|
||||
"./p",
|
||||
"../p",
|
||||
"/p",
|
||||
".\\p",
|
||||
"..\\a\\p",
|
||||
"C:\\a\\p",
|
||||
"D:/p",
|
||||
{ repo: ".\\p" },
|
||||
]) {
|
||||
assert.ok(isLocalSource(source), JSON.stringify(source))
|
||||
}
|
||||
for (const source of ["github:a/b", "a/b", "https://github.com/a/b.git"]) {
|
||||
assert.ok(!isLocalSource(source), source)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
import fs from "node:fs"
|
||||
import path from "node:path"
|
||||
import { fileURLToPath } from "node:url"
|
||||
import { styleText } from "node:util"
|
||||
import { isIdentifier, jsString } from "./subprocess.js"
|
||||
|
||||
@@ -135,8 +136,8 @@ export function collectPluginExports({ pluginsDir, npmPackages = [], verbose = f
|
||||
for (const pkg of npmPackages) {
|
||||
let distIndex
|
||||
try {
|
||||
const pkgJson = new URL(import.meta.resolve(`${pkg}/package.json`)).pathname
|
||||
distIndex = path.join(path.dirname(decodeURIComponent(pkgJson)), "dist", "index.d.ts")
|
||||
const pkgJson = fileURLToPath(import.meta.resolve(`${pkg}/package.json`))
|
||||
distIndex = path.join(path.dirname(pkgJson), "dist", "index.d.ts")
|
||||
} catch {
|
||||
if (verbose) console.log(styleText("yellow", `⚠`), `Skipping npm package ${pkg}: not found`)
|
||||
continue
|
||||
|
||||
@@ -46,6 +46,20 @@ function fakeSite() {
|
||||
}
|
||||
|
||||
describe("plugin index", () => {
|
||||
// npm plugins are found through import.meta.resolve, which returns a file: URL. Its pathname
|
||||
// is not a path on Windows (`/C:/…`), so every npm plugin was skipped there (#2616).
|
||||
test("npm plugins are found through their package.json", () => {
|
||||
const pluginsDir = fs.mkdtempSync(path.join(os.tmpdir(), "quartz-plugin-index-npm-"))
|
||||
const entry = collectPluginExports({
|
||||
pluginsDir,
|
||||
npmPackages: ["@quartz-community/explorer"],
|
||||
}).get("quartz-community__explorer")
|
||||
assert.ok(entry, "@quartz-community/explorer was skipped")
|
||||
assert.ok(entry.overridable.includes("Explorer"))
|
||||
assert.strictEqual(entry.importPath, "@quartz-community/explorer")
|
||||
fs.rmSync(pluginsDir, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
test("component constructors re-exported from a sub-module are wrapped (#2565)", () => {
|
||||
const { root, pluginsDir } = fakeSite()
|
||||
const entry = collectPluginExports({ pluginsDir }).get("my-widget")!
|
||||
|
||||
@@ -4,7 +4,7 @@ import { unified } from "unified"
|
||||
import remarkParse from "remark-parse"
|
||||
import remarkRehype from "remark-rehype"
|
||||
import { VFile } from "vfile"
|
||||
import { Element, Root } from "hast"
|
||||
import { Element, Root, Text } from "hast"
|
||||
import { visit } from "unist-util-visit"
|
||||
import { BUILTINS, instantiateBuiltins, officialPluginName, planBuiltins, PlanInput } from "."
|
||||
import {
|
||||
@@ -396,6 +396,17 @@ describe("links built-in", () => {
|
||||
)
|
||||
})
|
||||
|
||||
test("pretty links keep the last /-separated part of the link text, on every OS", () => {
|
||||
const { els } = run([a("folder/note"), a("a\\b")], "page", { prettyLinks: true }, [
|
||||
"folder/note",
|
||||
"a\\b",
|
||||
])
|
||||
assert.deepStrictEqual(
|
||||
els.filter((e) => e.tagName === "a").map((e) => (e.children[0] as Text).value),
|
||||
["note", "a\\b"],
|
||||
)
|
||||
})
|
||||
|
||||
test("disableBrokenWikilinks adds a broken class to missing targets", () => {
|
||||
const { els } = run([a("missing")], "page", { disableBrokenWikilinks: true }, ["page"])
|
||||
assert.ok((els[0].properties.className as string[]).includes("broken"))
|
||||
|
||||
@@ -166,7 +166,8 @@ export const Links: QuartzTransformerPlugin<LinksConfig> = (userOpts) => {
|
||||
!textChild.value.startsWith("#") &&
|
||||
!classes.includes("alias")
|
||||
) {
|
||||
textChild.value = path.basename(textChild.value)
|
||||
// link text is not an OS path: path.posix, or Windows would also cut at a backslash
|
||||
textChild.value = path.posix.basename(textChild.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import assert from "node:assert"
|
||||
import fs from "fs"
|
||||
import os from "os"
|
||||
import path from "path"
|
||||
import { parsePluginSource, readLockedCommit } from "./gitLoader"
|
||||
import { isLocalSource, parsePluginSource, readLockedCommit } from "./gitLoader"
|
||||
|
||||
describe("parsePluginSource", () => {
|
||||
test("owner/repo shorthand supports #ref", () => {
|
||||
@@ -13,6 +13,25 @@ describe("parsePluginSource", () => {
|
||||
assert.strictEqual(spec.ref, "dev")
|
||||
})
|
||||
|
||||
test("local sources are recognised in POSIX and Windows spellings", () => {
|
||||
for (const source of [
|
||||
"./plugin",
|
||||
"../plugin",
|
||||
"/abs/plugin",
|
||||
".\\plugin",
|
||||
"..\\plugins\\x",
|
||||
"C:\\sites\\plugin",
|
||||
"D:/plugin",
|
||||
{ repo: ".\\plugin" },
|
||||
]) {
|
||||
assert.ok(isLocalSource(source), JSON.stringify(source))
|
||||
}
|
||||
for (const source of ["github:a/b", "a/b", "https://github.com/a/b.git", "@scope/pkg"]) {
|
||||
assert.ok(!isLocalSource(source), source)
|
||||
}
|
||||
assert.strictEqual(parsePluginSource(".\\plugin").local, true)
|
||||
})
|
||||
|
||||
test("unknown sources get an explanatory error", () => {
|
||||
assert.throws(() => parsePluginSource("explorer"), /Expected github:owner\/repo/)
|
||||
})
|
||||
|
||||
@@ -111,6 +111,10 @@ export function isLocalSource(source: PluginSource): boolean {
|
||||
if (source.startsWith("./") || source.startsWith("../") || source.startsWith("/")) {
|
||||
return true
|
||||
}
|
||||
// Windows relative paths (.\plugin, ..\plugin)
|
||||
if (source.startsWith(".\\") || source.startsWith("..\\")) {
|
||||
return true
|
||||
}
|
||||
// Windows absolute paths (e.g. C:\ or D:/)
|
||||
if (/^[A-Za-z]:[\\/]/.test(source)) {
|
||||
return true
|
||||
|
||||
Reference in new issue
Block a user