feat: support npm scoped package specifiers for plugins
Plugins can now be referenced as "@quartz-community/<name>" in quartz.config.yaml and via 'quartz plugin add'. The npm path skips git installation and resolves from node_modules. Changes: - gitLoader.ts: detect @scope/name as npm package in parsePluginSource() - config-loader.ts: skip git install for npm packages, read manifests from node_modules via createRequire - install-plugins.ts: filter npm packages from prebuild, fallback to YAML config parsing to avoid loading full quartz.ts - plugin-data.js: npm detection in CLI parseGitSource() - plugin-git-handlers.js: npm install path in handlePluginAdd() - package.json: add missing hast-util-from-html dependency
This commit is contained in:
@@ -190,6 +190,11 @@ export function parseGitSource(source) {
|
||||
typeof source === "object" && source.name ? source.name : path.basename(parsed, ".git")
|
||||
return { name, url: parsed, ref, subdir }
|
||||
}
|
||||
// Handle npm scoped packages
|
||||
if (typeof url === "string" && url.startsWith("@") && url.includes("/") && !url.includes(":")) {
|
||||
const name = typeof source === "object" && source.name ? source.name : url
|
||||
return { name, url: "", npmPackage: true, subdir }
|
||||
}
|
||||
throw new Error(`Cannot parse plugin source: ${formatSource(source)}`)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import fs from "fs"
|
||||
import path from "path"
|
||||
import os from "os"
|
||||
import { exec as execCb } from "child_process"
|
||||
import { exec as execCb, execSync } from "child_process"
|
||||
import { styleText, promisify } from "util"
|
||||
import {
|
||||
readPluginsJson,
|
||||
@@ -1190,6 +1190,15 @@ export async function handlePluginAdd(
|
||||
for (const source of sources) {
|
||||
try {
|
||||
const parsed = parseGitSource(source)
|
||||
if (parsed.npmPackage) {
|
||||
const name = nameOverride ?? parsed.name
|
||||
console.log(styleText("cyan", `→ Installing ${name} from npm...`))
|
||||
execSync(`npm install ${parsed.name}`, { cwd: process.cwd(), stdio: "inherit" })
|
||||
const configSource = nameOverride ? { repo: parsed.name, name: nameOverride } : parsed.name
|
||||
const pluginDir = path.join(process.cwd(), "node_modules", ...parsed.name.split("/"))
|
||||
addedPlugins.push({ name, pluginDir, source: parsed.name, configSource })
|
||||
continue
|
||||
}
|
||||
const name = nameOverride ?? parsed.name
|
||||
const url = parsed.url
|
||||
const ref = parsed.ref
|
||||
|
||||
Reference in New Issue
Block a user