feat: plugins workspace with @green-tea/jwt #1

Merged
chrnx merged 4 commits from feature/scaffold-jwt into develop 2026-09-18 04:20:49 +00:00
10 changed files with 3103 additions and 0 deletions
Showing only changes of commit efffaebb96 - Show all commits

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
#!/bin/sh
# Pre-commit gate. Auto-fixes formatting and lint on staged TypeScript, re-stages it, then enforces lint
# and the complexity gate. Enabled by the `prepare` script (`git config core.hooksPath .githooks`).
set -e
staged=$(git diff --cached --name-only --diff-filter=ACM -- 'packages/*.ts' 'test/*.ts')
if [ -n "$staged" ]; then
echo "$staged" | xargs npx prettier --write
echo "$staged" | xargs npx eslint --fix
echo "$staged" | xargs git add
fi
npm run lint
npm run complexity:check
+4
View File
@@ -0,0 +1,4 @@
# The @green-tea scope resolves from Verdaccio while core 26.9.0-beta.2 exists only there. The token is
# not here: it comes from ~/.npmrc locally and from the NPM_AUTH secret in CI. Plan B3 removes this line
# when the packages move to a core published on npm.
@green-tea:registry=https://npm.svc.zoit.services/
+8
View File
@@ -0,0 +1,8 @@
{
"printWidth": 120,
"tabWidth": 2,
"singleQuote": true,
"semi": true,
"trailingComma": "all",
"arrowParens": "always"
}
+9
View File
@@ -0,0 +1,9 @@
{
"workspace": [],
"nodeModulesDir": "manual",
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"lint": { "exclude": ["node_modules"] }
}
+43
View File
@@ -0,0 +1,43 @@
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import stylistic from '@stylistic/eslint-plugin';
export default tseslint.config(
{ ignores: ['dist', 'node_modules', 'coverage'] },
js.configs.recommended,
...tseslint.configs.recommended,
{
plugins: { '@stylistic': stylistic },
rules: {
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
'@stylistic/padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: 'multiline-block-like', next: '*' },
{ blankLine: 'always', prev: '*', next: 'multiline-block-like' },
],
},
},
{
// Rule 8 of the convention. A value import of core makes the published plugin need core at
// runtime, and no semver range accepts next month's CalVer beta — not even `*` — so every
// install would warn. Tests are exempt: they drive the real createApp on purpose.
files: ['packages/*/src/**/*.ts'],
rules: {
'no-restricted-imports': 'off',
'@typescript-eslint/no-restricted-imports': [
'error',
{
paths: [
{
name: '@green-tea/core',
message: 'Plugins import core as types only: `import type { … } from "@green-tea/core"`.',
allowTypeImports: true,
},
],
},
],
'no-console': 'error',
},
},
);
+2880
View File
File diff suppressed because it is too large. Load diff
+33
View File
@@ -0,0 +1,33 @@
{
"name": "green-tea-plugins",
"private": true,
"license": "MIT",
"type": "module",
"workspaces": ["packages/*"],
"engines": {
"node": ">=22"
},
"scripts": {
"lint": "eslint --no-error-on-unmatched-pattern packages test",
"format": "prettier --write \"packages/*/{src,test}/**/*.ts\" \"test/**/*.ts\"",
"format:check": "prettier --check \"packages/*/{src,test}/**/*.ts\" \"test/**/*.ts\"",
"complexity:check": "node scripts/check-complexity.mjs",
"typecheck": "tsc --noEmit -p tsconfig.json",
"test": "node --import tsx --test test/*.test.ts packages/*/test/*.test.ts",
"test:deno": "node scripts/run-runtime.mjs deno",
"test:bun": "node scripts/run-runtime.mjs bun",
"test:edge": "node scripts/run-runtime.mjs workerd",
"prepare": "git config core.hooksPath .githooks || true"
},
"devDependencies": {
"@eslint/js": "^9.39.5",
"@stylistic/eslint-plugin": "^5.10.0",
"@types/node": "^22.0.0",
"cognitive-complexity-ts": "^0.8.2",
"eslint": "^9.39.5",
"prettier": "^3.9.6",
"tsx": "^4.23.5",
"typescript": "^5.5.0",
"typescript-eslint": "^8.70.0"
}
}
+53
View File
@@ -0,0 +1,53 @@
#!/usr/bin/env node
// Cognitive-complexity gate over every package's src. Fails (exit 1) if any named function exceeds the
// threshold. Same gate as core's, walked per package because ccts-json takes one directory.
import { execSync } from 'node:child_process';
import { existsSync, readdirSync } from 'node:fs';
const THRESHOLD = 25;
function scores(dir) {
try {
return execSync(`npx ccts-json ${dir}`, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
} catch (error) {
return error.stdout?.toString() ?? '';
}
}
const offenders = [];
function walk(node, dir) {
if (!node || typeof node !== 'object') return;
if (node.kind === 'function' && node.name && node.score > THRESHOLD) {
offenders.push({ score: node.score, name: `${dir}: ${node.name}` });
}
for (const [key, value] of Object.entries(node)) {
if (key === 'inner' && Array.isArray(value)) value.forEach((child) => walk(child, dir));
else if (value && typeof value === 'object') walk(value, dir);
}
}
const dirs = readdirSync('packages')
.map((name) => `packages/${name}/src`)
.filter((dir) => existsSync(dir));
for (const dir of dirs) {
const raw = scores(dir);
if (!raw.trim()) {
console.error(`check-complexity: no output from ccts-json for ${dir}`);
process.exit(2);
}
walk(JSON.parse(raw), dir);
}
if (offenders.length) {
offenders.sort((a, b) => b.score - a.score);
console.error(`\n✖ cognitive complexity: ${offenders.length} function(s) over ${THRESHOLD}\n`);
for (const o of offenders) console.error(` ${String(o.score).padStart(4)} ${o.name}`);
console.error('\nExtract helpers to bring them under the threshold. The threshold is not raised.\n');
process.exit(1);
}
console.log(`✓ cognitive complexity: every function ≤ ${THRESHOLD} (${dirs.length} package(s))`);
+41
View File
@@ -0,0 +1,41 @@
#!/usr/bin/env node
// Runs the contract tests of every package whose `engines` declares <runtime>, on that runtime.
// `engines` is the one declaration (convention rule 9): a package that does not claim a runtime is not
// tested on it, and a package that claims one cannot skip it.
//
// Usage: node scripts/run-runtime.mjs <deno|bun|workerd>
import { spawnSync } from 'node:child_process';
import { readdirSync, readFileSync } from 'node:fs';
const COMMANDS = {
deno: (dirs) => ['deno', ['test', '--allow-all', '--no-check', ...dirs.map((dir) => `packages/${dir}/test/`)]],
bun: (dirs) => ['bun', ['test', ...dirs.map((dir) => `./packages/${dir}/test/`)]],
};
const runtime = process.argv[2];
if (!(runtime in COMMANDS) && runtime !== 'workerd') {
console.error('usage: run-runtime.mjs <deno|bun|workerd>');
process.exit(2);
}
const declares = (dir) => {
const { engines = {} } = JSON.parse(readFileSync(`packages/${dir}/package.json`, 'utf8'));
return runtime in engines;
};
const dirs = readdirSync('packages').filter(declares);
if (dirs.length === 0) {
console.log(`no package declares ${runtime}; nothing to run`);
process.exit(0);
}
// There is no workerd harness for plugins yet (spec, section 4). A package that declares workerd must
// not pass CI by having nothing run against it — copy core's test/edge harness first.
if (runtime === 'workerd') {
console.error(`${dirs.join(', ')} declare workerd, and there is no workerd harness yet.`);
process.exit(1);
}
const [command, args] = COMMANDS[runtime](dirs);
const { status } = spawnSync(command, args, { stdio: 'inherit' });
process.exit(status ?? 1);
+18
View File
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "es2022",
"module": "preserve",
"moduleResolution": "bundler",
"lib": ["es2022"],
"types": ["node"],
"strict": true,
"noEmit": true,
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"skipLibCheck": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"forceConsistentCasingInFileNames": true
},
"include": ["packages/*/src", "packages/*/test", "test"]
}