Shared runtime helpers for the Epub Knowledge package ecosystem.
After public testing is complete and this package is published to the public NPM registry, install it directly from NPM with no extra registry configuration or auth token:
pnpm:
pnpm add @epubknowledge/commonyarn:
yarn add @epubknowledge/commonnpm:
npm install @epubknowledge/commonRequires Node.js >= 22.0.0.
This package is published to the GitHub Package Registry, so consuming repos must be configured to read the @epubknowledge scope from https://npm.pkg.github.com.
Add this to the consuming repo's .npmrc:
@epubknowledge:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}Commit the file, but never commit the token itself.
If the consuming repo uses Yarn Berry (v2+), add the equivalent to .yarnrc.yml:
npmScopes:
epubknowledge:
npmRegistryServer: 'https://npm.pkg.github.com'
npmAuthToken: '${GITHUB_TOKEN}'The token needs read:packages. If the org uses SSO, the token must also be authorized for epubknowledge.
Local development:
export GITHUB_TOKEN=ghp_your_token_hereGitHub Actions:
permissions:
contents: read
packages: read
steps:
- run: npm install
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}pnpm:
pnpm add @epubknowledge/commonyarn:
yarn add @epubknowledge/commonnpm:
npm install @epubknowledge/commonImport from the documented subpath exports only. There is currently no root barrel export, so prefer paths like @epubknowledge/common/dir.
@epubknowledge/common/constants(internal) — exported for use by other@epubknowledgepackages only; may change without notice between minor versions; external consumers should not depend on it@epubknowledge/common/dir@epubknowledge/common/epub@epubknowledge/common/file@epubknowledge/common/misc@epubknowledge/common/objectSetup@epubknowledge/common/paths@epubknowledge/common/resetMemory@epubknowledge/common/tmp@epubknowledge/common/types@epubknowledge/common/zip
import { isDir, verifyBookDir } from '@epubknowledge/common/dir'
import { fileExists } from '@epubknowledge/common/file'
if (isDir('./book') && fileExists('./book/chapter.xhtml')) {
console.log(verifyBookDir('./book'))
}No separate @types package is needed. This package ships its own declaration files, so TypeScript consumers can use the same import paths as JavaScript consumers and import type for type-only imports.
import { epubMove } from '@epubknowledge/common/epub'
import type { EpubObj, EpubMoveResult } from '@epubknowledge/common/types'
export async function moveBook(book: EpubObj): Promise<EpubMoveResult> {
return epubMove(book)
}TypeScript consumers should use modern package resolution (moduleResolution: 'bundler', 'node16', or 'nodenext') so package subpath exports resolve cleanly.
The repo plan for publishing and verifying consumer installs lives in docs/importing.md.
npm test
npm run test:coverage
npm run buildCreate a .env file in the project root to configure the tmp directory:
TMP_DIR=/path/to/your/tmpIf TMP_DIR is missing, the tmp module creates a system tmp directory for the current run. It only writes that path back to .env when create(..., true) is used and the .env file already exists.