@brighte/platform-core-utils

中文文档
0.1.0发布于 2026/03/31UNLICENSEDTypeScriptESM + CJS近 30 天下载 4076

Shared internal utilities package for Brighte platform teams

原始使用文档
文档目录11 节
  1. Modules
  2. Installation
  3. Pact module
  4. Creating a provider
  5. Building GraphQL interactions
  6. Vitest config
  7. Publishing pacts
  8. CI deploy checks
  9. Development
  10. Versioning and release
  11. Publishing workflows

@brighte/platform-core-utils

A shared internal utilities package for Brighte platform teams.

This package provides reusable helpers and utilities that are common across multiple repositories. It is designed to grow incrementally — each module is lightweight, independently testable, and isolated from unrelated dependencies. Currently includes Pact contract testing utilities, with more modules planned.

Modules

ModuleEntry pointStatusDescription
pact@brighte/platform-core-utils✅ ReadyHelpers for Pact consumer contract testing
pact/config@brighte/platform-core-utils/config✅ ReadyVitest config factory for pact test runs
pact/publish@brighte/platform-core-utils/publish✅ ReadyScript helper to publish pacts to a broker

New modules go in src/<module>/ and are exported from a dedicated subpath if they carry different dependencies. See CLAUDE.md for contribution guidelines.

Installation

npm install --save-dev @brighte/platform-core-utils

@pact-foundation/pact, graphql, and @graphql-typed-document-node/core install automatically as dependencies.

Install peer dependencies for optional features:

# For vitest config (createPactVitestConfig)
npm install --save-dev vitest vite-tsconfig-paths

# For publishing pacts (publishPacts)
npm install --save-dev @pact-foundation/pact-node

Note: Published to npm under the @brighte scope. Ensure your project's .npmrc is configured with the correct auth token.


Pact module

Creating a provider

import { createProvider } from '@brighte/platform-core-utils';

export const provider = createProvider({
  consumer: 'my-app',
  provider: 'api-service',
  logLevel: 'info', // optional, defaults to PACT_LOG_LEVEL env var or 'warn'
  dir: './generated-pacts', // optional, defaults to './generated-pacts'
});

Building GraphQL interactions

import { createGraphqlQueryInteraction } from '@brighte/platform-core-utils';
import { MatchersV3 } from '@pact-foundation/pact';
import { someQuery } from './queries.graphql';

const interaction = createGraphqlQueryInteraction({
  state: 'user with id 123 exists',
  uponReceiving: 'a request for user data',
  query: someQuery,
  variables: { id: '123' },
  responseBody: {
    user: MatchersV3.like({ id: '123', name: 'John Doe' }),
  },
});

Vitest config

// pact/setup/config.ts
import tsconfigPaths from 'vite-tsconfig-paths';
import { defineConfig } from 'vitest/config';
import { createPactVitestConfig } from '@brighte/platform-core-utils/config';

export default defineConfig({ ...createPactVitestConfig(), plugins: [tsconfigPaths()] });

Publishing pacts

// pact/setup/publish.pact.ts
import { publishPacts } from '@brighte/platform-core-utils/publish';

await publishPacts();

CI deploy checks

// pact/setup/can-i-deploy.ts
import { canIDeploy } from '@brighte/platform-core-utils';

const environment = process.env['ENVIRONMENT'];
if (!environment) { console.error('ENVIRONMENT is not set'); process.exit(1); }
canIDeploy({ pacticipant: 'my-app', toEnvironment: environment });
// pact/setup/record-deployment.ts
import { recordDeployment } from '@brighte/platform-core-utils';

const environment = process.env['ENVIRONMENT'];
if (!environment) { console.error('ENVIRONMENT is not set'); process.exit(1); }
recordDeployment({ pacticipant: 'my-app', environment });

For the full pact setup guide see docs/pact.md.


Development

npm install       # install deps
npm run build     # compile CJS + ESM to dist/
npm run lint      # eslint
npm test          # vitest
npm run clean     # remove dist/

Versioning and release

This package uses semantic versioning. Publishing to npm happens automatically on every merge to main.

  1. Bump package.json version (e.g. 1.0.0 → 1.1.0)
  2. Update CHANGELOG.md
  3. Commit and open a PR against main
  4. Once merged, publish.yml runs and publishes to npm

If the version in package.json was not changed, the publish step will skip (no re-publish of an existing version).

Publishing workflows

WorkflowTriggerPurpose
ci.ymlpush / PR to mainbuild, lint, test, circular dep check
publish.ymlmerge to mainpublish stable release to npm
beta.ymlmanual dispatchpublish beta dist-tag

版本与发布记录

@brighte/platform-core-utils 共发布 14 个版本,首次发布于 2026/03/26;过去 12 个月发布了 14 个版本。

版本发布日期距今
0.1.0latest2026/03/317 个月前
0.1.0-beta.a6e7ae3-beta.f2a1324beta2026/03/317 个月前
0.1.0-beta.8e759ff2026/03/277 个月前
0.1.0-beta.458247a2026/03/277 个月前
0.1.0-beta.6844e962026/03/277 个月前
0.1.0-beta.962de632026/03/277 个月前

关于 @brighte/platform-core-utils 的常见问题

@brighte/platform-core-utils 是什么?

Shared internal utilities package for Brighte platform teams

如何安装 @brighte/platform-core-utils?

在项目目录运行 npm install @brighte/platform-core-utils,或使用 pnpm add / yarn add / bun add。

@brighte/platform-core-utils 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@brighte/platform-core-utils 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@brighte/platform-core-utils 可以商用吗?

@brighte/platform-core-utils 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@brighte/platform-core-utils 的下载量有多少?

根据 npm 官方下载统计,@brighte/platform-core-utils 在 2026/10/09 – 2026/11/07 这 30 天内被下载 4,076 次,日均约 136 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@brighte/platform-core-utils 还在维护吗?

最新版本 0.1.0 发布于 2026/03/31(7 个月前);至今共发布 14 个版本,其中过去 12 个月发布了 14 个;首次发布于 2026/03/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。