fix(plugins): recognise .\ and ..\ local plugin sources (Windows spelling)

This commit is contained in:
saberzero1 committed 2026-11-09 18:11:49 +01:00
1 parent e7da9cebf4
commit f5ef8f738d
5 files changed
+59 -2

No files matched your search

@@ -0,0 +1,5 @@
---
"@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".
+4
View File
@@ -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
+26 -1
View File
@@ -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)
}
})
})
+20 -1
View File
@@ -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/)
})
+4
View File
@@ -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