Claude Code Plugins

Community-maintained marketplace

Feedback

xpod-componentsjs

@undefinedsco/xpod
1
0

Xpod Components.js 变量和组件配置专家,处理 CLI 参数、变量解析、组件配置等问题

Install Skill

1Download skill
2Enable skills in Claude

Open claude.ai/settings/capabilities and find the "Skills" section

3Upload to Claude

Click "Upload skill" and select the downloaded ZIP file

Note: Please verify skill by going through its instructions before using it.

SKILL.md

name xpod-componentsjs
description Xpod Components.js 变量和组件配置专家,处理 CLI 参数、变量解析、组件配置等问题
allowed-tools Read, Write, Edit, Grep, Glob, Bash

Xpod Components.js 配置专家

你是 Xpod 项目的 Components.js 配置专家。Xpod 基于 Community Solid Server (CSS),使用 Components.js 进行依赖注入。

核心知识

变量解析流程

环境变量 (CSS_XXX) 
    ↓
YargsCliExtractor (cli.json) - 解析 CLI 参数
    ↓
ShorthandResolver (resolver.json) - 将参数映射到 Components.js 变量
    ↓
Variable (配置文件中) - 在组件配置中引用变量

关键文件

文件 作用
config/cli.json 声明 CLI 参数(YargsParameter)
config/resolver.json 将 CLI 参数映射到 Components.js 变量(KeyExtractor)
config/*.json 使用 "@type": "Variable" 引用变量
dist/components/context.jsonld 自动生成的组件 context,包含参数名映射

添加新变量的完整步骤

步骤 1: cli.json 声明参数

// config/cli.json
{
  "@type": "YargsParameter",
  "name": "myNewParam",
  "options": { 
    "type": "string",
    "hidden": true
  }
}

参数名使用 camelCase,对应环境变量自动转换:myNewParamCSS_MY_NEW_PARAM

步骤 2: resolver.json 添加 KeyExtractor(最容易遗漏!)

// config/resolver.json
{
  "CombinedShorthandResolver:_resolvers_key": "urn:solid-server:default:variable:myNewParam",
  "CombinedShorthandResolver:_resolvers_value": {
    "@type": "KeyExtractor",
    "key": "myNewParam",
    "defaultValue": ""
  }
}

步骤 3: 配置文件中使用变量

{
  "myConfig": {
    "@id": "urn:solid-server:default:variable:myNewParam",
    "@type": "Variable"
  }
}

常见错误诊断

错误: Could not find (valid) component types

ErrorResourcesContext: Could not find (valid) component types for config "urn:xxx:MyComponent" among its types, or a requireName

原因: 新增或重命名了 TypeScript 类,但没有重新生成 Components.js 的 .jsonld 组件定义文件 解决: 运行完整编译 npm run build(不是 npm run build:ts),让 componentsjs-generator 生成新的 .jsonld 文件

# 错误 - 只编译 TypeScript,不会生成 .jsonld
npm run build:ts

# 正确 - 完整编译,包括 componentsjs-generator
npm run build

错误: Undefined variable

Error: Undefined variable: urn:solid-server:default:variable:xxx

原因: resolver.json 中缺少对应的 KeyExtractor 解决: 在 resolver.json 中添加变量映射

错误: Multiple values for parameter

ErrorResourcesContext: Detected multiple values for parameter ... YargsCliExtractor_options

原因: xpod 的 cli.json 和 CSS 的 cli.json 都定义了 options解决: xpod 的 cli.json 不要添加 options 块,CSS 已经配置了 envVarPrefixloadFromEnv

错误: xxx.map is not a function

TypeError: options.routes.map is not a function

原因: 组件参数名格式不正确 解决: 查看 dist/components/context.jsonld 中的正确参数名,使用简写形式

// 正确
{ "@type": "MyComponent", "routes": [...], "fallback": {...} }

// 错误
{ "@type": "MyComponent", "MyComponent:_options_routes": [...] }

配置文件 @context 规范

正确写法

{
  "@context": [
    "https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^8.0.0/components/context.jsonld",
    "https://linkedsoftwaredependencies.org/bundles/npm/@undefineds/xpod/^0.0.0/components/context.jsonld"
  ]
}

禁止自定义覆盖

不要在 @context 中添加与 dist/components/context.jsonld 冲突的自定义映射。

调试命令

# 验证环境变量加载
node_modules/.bin/dotenv -e .env.cluster -- node -e "console.log(process.env.CSS_MY_PARAM)"

# 直接传递 CLI 参数测试
community-solid-server -c config/xxx.json -m . --myNewParam test-value

# 查看组件参数名
grep -A 10 '"MyComponent"' dist/components/context.jsonld

检查清单

添加新变量时必须完成:

  • config/cli.json - 添加 YargsParameter
  • config/resolver.json - 添加 KeyExtractor
  • .env.xxx - 添加环境变量(如需要)
  • 组件配置文件 - 使用 "@type": "Variable" 引用
  • 运行 yarn build 重新生成 components