npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ruovea/codingrule

v1.0.6

Published

编码规则模块(源码包,Vue 3 插件化依赖注入)

Readme

@ruovea/codingrule

编码规则模块,以 pnpm 源码包 形式提供给各宿主项目复用。

  • 不打 dist、不发 npm——exports 直指 ./src/*,由宿主 Vite 编译
  • 依赖注入解耦——request / auth / i18n 由宿主装配时注入
  • 零侵入——包内不含 /@/ 等宿主别名引用,可独立运行,不绑定特定宿主

一、目录结构

src/
├─ index.ts          # 入口:导出 CodingRulePlugin + API + 类型
├─ plugin.ts         # Vue install(校验必填项 / provide / mergeLocaleMessage)
├─ context.ts        # InjectionKey + useCodingRuleContext()
├─ types.ts          # CodingRulePluginOptions
├─ routes.ts         # 1 条静态路由(可选使用)
├─ api/
│  ├─ index.ts       # 8 个 API 函数
│  ├─ http.ts        # request 注入点
│  ├─ endpoints.ts   # URL 前缀(可覆盖)
│  └─ codingRule.ts  # 编码规则 CRUD + 生成流水号
├─ i18n/locales/     # 6 语言(en / fr-fr / ja-jp / vi-vn / zh-cn / zh-tw)
└─ views/codingRule/
   ├─ index.vue                        # 编码规则列表页
   └─ component/editCodingRule.vue     # 新增/编辑弹窗(含规则明细内联编辑)

二、宿主接入

2.1 安装

宿主 package.jsonlink: 协议指向本仓库:

{
  "dependencies": {
    "@ruovea/codingrule": "link:../../codingrule-module/packages/codingrule"
  }
}
cd <codingrule-module 目录> && pnpm install   # 包内依赖
cd <宿主> && pnpm install                      # 建立 link

2.2 装配插件

// plugins/codingrule.ts
import type { App } from 'vue';
import { CodingRulePlugin } from '@ruovea/codingrule';
import request from '/@/utils/request';
import { auth } from '/@/utils/authFunction';
import { i18n } from '/@/i18n/index';

export function setupCodingRule(app: App) {
  app.use(CodingRulePlugin, {
    request: request as any,
    auth,
    i18n: i18n as any,
  });
}
// main.ts
import { setupCodingRule } from '/@/plugins/codingrule';
// ... app.use(pinia) 之后
setupCodingRule(app);

三、CodingRulePluginOptions 说明

| 字段 | 必填 | 说明 | |---|---|---| | request | ✅ | 宿主 axios 实例(已配 baseURL / token / 拦截器) | | auth | ➖ | (code: string) => boolean,按钮权限校验,缺省 () => true | | i18n | ➖ | 宿主 vue-i18n 实例(用于 mergeLocaleMessage) | | endpoints | ➖ | 覆盖 API URL 前缀(见下方 Endpoints 章节) | | registerI18n | ➖ | 是否自动 merge i18n,默认 true |

与 article 模块不同,codingrule 无需注入宿主组件,所有 UI 均使用 element-plus 自包含。

i18n 注入约定

包内视图使用 message.codingrule.xxx / message.router.codingRule 格式的 key。插件 merge 时同时注册到顶层和 message 层,兼容宿主两级结构。


四、Endpoints 说明

interface CodingRuleEndpoints {
  basCodingRulePages:       '/BasCodingRule/Pages'
  basCodingRuleData:        '/BasCodingRule/Data'
  basCodingRuleList:        '/BasCodingRule/List'
  basCodingRuleAdd:         '/BasCodingRule/AddData'
  basCodingRuleUpdate:      '/BasCodingRule/UpdateData'
  basCodingRuleDelete:      '/BasCodingRule/DeleteData'
  basCodingRuleDeleteBatch: '/BasCodingRule/DeleteBatch'
  basCodingRuleSN:          '/BasCodingRule/SN'
}

五、权限编码清单

| 编码 | 位置 | 说明 | |---|---|---| | codingrule:pages | 编码规则列表 | 查询按钮 | | codingrule:add | 编码规则列表 | 新增按钮 | | codingrule:edit | 编码规则列表 | 编辑按钮 | | codingrule:delete | 编码规则列表 | 删除按钮 |


六、路由

| path | name | keepAlive | 说明 | |---|---|---|---| | /business/codingRule | codingRule | ✅ | 编码规则列表 |

路由 meta.title 使用硬编码中文 '编码规则',菜单国际化通过包内 locale 文件的 router.codingRule 键实现(插件 merge 后 t('router.codingRule') 可命中)。


七、Vite 预构建排除

⚠️ 宿主 vite.config.tsoptimizeDeps.exclude 必须包含 @ruovea/codingrule,否则会出现"页面进入即报『查询失败』、但 Network 面板无任何请求"的诡异现象。

现象

  • 列表页一打开就 ElMessage.error('查询失败')
  • 浏览器 DevTools Network 面板没有发出任何 HTTP 请求
  • 控制台抛出 [@ruovea/codingrule] request 未注入,请先 install 插件

根因

本包是 pnpm 源码包,package.jsonexports../api 都指向 ./src/*。若不排除预构建,Vite 会把主入口 @ruovea/codingrule 预打包成 node_modules/.vite/deps/@ruovea_codingrule.js,但 ./api 子路径仍走源码 src/api/index.tssrc/api/http.ts。两端各持一份模块级 _request

  • main.tssetupCodingrule(app)CodingRulePlugin.install__setRequest(request) 写入的是预构建产物里的 _request
  • 视图层 import { apiBasCodingRulePagesPost } from '@ruovea/codingrule/api' 拿到的是源码 http.ts_request,永远是 undefined
  • 视图调 apiBasCodingRulePagesPost(params)http() → throw → catch → ElMessage.error('查询失败'),全程不进 axios,所以无网络请求。

修复

宿主 vite.config.ts

optimizeDeps: {
    exclude: ['vue-demi', '@ruovea/codingrule'],
},

改完清除 Vite 预构建缓存后重启 dev:

rm -rf Web/node_modules/.vite/deps
pnpm dev

验证

重启后进入"编码规则"菜单,DevTools Network 应能看到 GET /BasCodingRule/Pages?... 请求,列表正常渲染。


八、License

MIT