Merge commit '36c66dd290d3ce6eb1ccd310d0c658d4a32bb8eb' as 'repos/effect'
This commit is contained in:
61
repos/effect/scripts/bundle-analyze.sh
Executable file
61
repos/effect/scripts/bundle-analyze.sh
Executable file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Generate bundle composition artifacts for explicitly selected entry files.
|
||||
#
|
||||
# Usage:
|
||||
# scripts/bundle-analyze.sh [--output-dir <dir>] <file...>
|
||||
|
||||
usage() {
|
||||
echo "Usage: scripts/bundle-analyze.sh [--output-dir <dir>] <file...>"
|
||||
}
|
||||
|
||||
OUTPUT_DIR="tmp/bundle-analysis"
|
||||
FILES=()
|
||||
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
-o | --output-dir)
|
||||
if [ "$#" -lt 2 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
OUTPUT_DIR="$2"
|
||||
shift 2
|
||||
;;
|
||||
-h | --help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
FILES+=("$@")
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
echo "Unknown option: $1" >&2
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
FILES+=("$1")
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "${#FILES[@]}" -eq 0 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ROOT="$(git rev-parse --show-toplevel)"
|
||||
|
||||
cd "$ROOT"
|
||||
|
||||
echo "Building current checkout..."
|
||||
pnpm build
|
||||
|
||||
node packages/tools/bundle/src/bin.ts visualize-selected \
|
||||
--output-dir "$OUTPUT_DIR" \
|
||||
"${FILES[@]}"
|
||||
97
repos/effect/scripts/bundle-compare-selected.sh
Executable file
97
repos/effect/scripts/bundle-compare-selected.sh
Executable file
@@ -0,0 +1,97 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Compare bundle size for explicitly selected entry files against a base ref.
|
||||
#
|
||||
# Usage:
|
||||
# scripts/bundle-compare-selected.sh [--base <ref>] [--keep-base] <file...>
|
||||
#
|
||||
# The selected files are copied into the base worktree before measurement so the
|
||||
# report isolates source changes instead of fixture content changes.
|
||||
|
||||
usage() {
|
||||
echo "Usage: scripts/bundle-compare-selected.sh [--base <ref>] [--keep-base] <file...>"
|
||||
}
|
||||
|
||||
BASE_REF="main"
|
||||
KEEP_BASE_WORKTREE=false
|
||||
FILES=()
|
||||
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
-b | --base)
|
||||
if [ "$#" -lt 2 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
BASE_REF="$2"
|
||||
shift 2
|
||||
;;
|
||||
--keep-base)
|
||||
KEEP_BASE_WORKTREE=true
|
||||
shift
|
||||
;;
|
||||
-h | --help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
FILES+=("$@")
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
echo "Unknown option: $1" >&2
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
FILES+=("$1")
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "${#FILES[@]}" -eq 0 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ROOT="$(git rev-parse --show-toplevel)"
|
||||
BASE_DIR="$ROOT/tmp/bundle-base"
|
||||
BASE_STAMP="$BASE_DIR/.bundle-build-stamp"
|
||||
|
||||
cleanup() {
|
||||
if [ "$KEEP_BASE_WORKTREE" = "false" ] && [ -d "$BASE_DIR" ]; then
|
||||
git worktree remove --force "$BASE_DIR"
|
||||
fi
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
cd "$ROOT"
|
||||
|
||||
echo "Building current checkout..."
|
||||
pnpm build
|
||||
|
||||
BASE_COMMIT="$(git rev-parse "$BASE_REF")"
|
||||
|
||||
if [ -d "$BASE_DIR/packages/effect/dist" ] &&
|
||||
[ -f "$BASE_STAMP" ] &&
|
||||
[ "$(git -C "$BASE_DIR" rev-parse HEAD)" = "$BASE_COMMIT" ] &&
|
||||
[ "$(cat "$BASE_STAMP")" = "$BASE_COMMIT" ]; then
|
||||
echo "Reusing built base worktree at $BASE_DIR ($BASE_REF @ ${BASE_COMMIT:0:8})"
|
||||
else
|
||||
if [ -d "$BASE_DIR" ]; then
|
||||
git worktree remove --force "$BASE_DIR"
|
||||
fi
|
||||
echo "Creating base worktree at $BASE_DIR ($BASE_REF @ ${BASE_COMMIT:0:8})"
|
||||
git worktree add --detach "$BASE_DIR" "$BASE_COMMIT"
|
||||
echo "Building base checkout..."
|
||||
(cd "$BASE_DIR" && pnpm install && pnpm build)
|
||||
printf "%s\n" "$BASE_COMMIT" > "$BASE_STAMP"
|
||||
fi
|
||||
|
||||
node packages/tools/bundle/src/bin.ts compare-selected \
|
||||
--base-dir "$BASE_DIR" \
|
||||
"${FILES[@]}"
|
||||
42
repos/effect/scripts/bundle-compare.sh
Executable file
42
repos/effect/scripts/bundle-compare.sh
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Runs the CI bundle-size comparison locally (see the Bundle job in
|
||||
# .github/workflows/check.yml): builds the current checkout, builds the base
|
||||
# ref in a cached git worktree under tmp/, then compares fixture bundle sizes.
|
||||
#
|
||||
# Usage: scripts/bundle-compare.sh [base-ref] (default: main)
|
||||
#
|
||||
# The base worktree is reused across runs while it points at the same commit.
|
||||
# Remove it with: git worktree remove --force tmp/bundle-base
|
||||
|
||||
BASE_REF="${1:-main}"
|
||||
ROOT="$(git rev-parse --show-toplevel)"
|
||||
BASE_DIR="$ROOT/tmp/bundle-base"
|
||||
OUTPUT_PATH="$ROOT/tmp/bundle-stats.txt"
|
||||
|
||||
cd "$ROOT"
|
||||
|
||||
echo "Building current checkout..."
|
||||
pnpm build
|
||||
|
||||
BASE_COMMIT="$(git rev-parse "$BASE_REF")"
|
||||
|
||||
if [ -d "$BASE_DIR/packages/effect/dist" ] && [ "$(git -C "$BASE_DIR" rev-parse HEAD)" = "$BASE_COMMIT" ]; then
|
||||
echo "Reusing built base worktree at $BASE_DIR ($BASE_REF @ ${BASE_COMMIT:0:8})"
|
||||
else
|
||||
if [ -d "$BASE_DIR" ]; then
|
||||
git worktree remove --force "$BASE_DIR"
|
||||
fi
|
||||
echo "Creating base worktree at $BASE_DIR ($BASE_REF @ ${BASE_COMMIT:0:8})"
|
||||
git worktree add --detach "$BASE_DIR" "$BASE_COMMIT"
|
||||
echo "Building base checkout..."
|
||||
(cd "$BASE_DIR" && pnpm install && pnpm build)
|
||||
fi
|
||||
|
||||
node packages/tools/bundle/src/bin.ts compare \
|
||||
--base-dir "$BASE_DIR/packages/tools/bundle/fixtures" \
|
||||
--output-path "$OUTPUT_PATH"
|
||||
|
||||
echo
|
||||
cat "$OUTPUT_PATH"
|
||||
26
repos/effect/scripts/circular.mjs
Normal file
26
repos/effect/scripts/circular.mjs
Normal file
@@ -0,0 +1,26 @@
|
||||
/* oxlint-disable no-undef */
|
||||
import * as glob from "glob"
|
||||
import madge from "madge"
|
||||
|
||||
madge(
|
||||
glob.globSync(["packages/*/src/**/*.ts", "packages/ai/*/src/**/*.ts"], {
|
||||
ignore: [
|
||||
"packages/sql-sqlite-bun/**",
|
||||
"packages/experimental/src/EventLogServer/Cloudflare.ts"
|
||||
]
|
||||
}),
|
||||
{
|
||||
detectiveOptions: {
|
||||
ts: {
|
||||
skipTypeImports: true
|
||||
}
|
||||
}
|
||||
}
|
||||
).then((res) => {
|
||||
const circular = res.circular()
|
||||
if (circular.length) {
|
||||
console.error("Circular dependencies found")
|
||||
console.error(circular)
|
||||
process.exit(1)
|
||||
}
|
||||
})
|
||||
19
repos/effect/scripts/clean.mjs
Normal file
19
repos/effect/scripts/clean.mjs
Normal file
@@ -0,0 +1,19 @@
|
||||
import * as Glob from "glob"
|
||||
import * as Fs from "node:fs"
|
||||
|
||||
const dirs = [".", ...Glob.sync("packages/*/"), ...Glob.sync("packages/sql/*/"), ...Glob.sync("packages/tools/*/"), ...Glob.sync("packages/ai/*/"), ...Glob.sync("packages/atom/*/")]
|
||||
dirs.forEach((pkg) => {
|
||||
const files = [".tsbuildinfo", "tsconfig.tsbuildinfo", "tsconfig.fixtures.tsbuildinfo", "tsconfig.src.tsbuildinfo", "docs", "build", "dist", "coverage"]
|
||||
|
||||
files.forEach((file) => {
|
||||
if (pkg === "." && file === "docs") {
|
||||
return
|
||||
}
|
||||
|
||||
Fs.rmSync(`${pkg}/${file}`, { recursive: true, force: true }, () => {})
|
||||
})
|
||||
})
|
||||
|
||||
Glob.sync("docs/*/").forEach((dir) => {
|
||||
Fs.rmSync(dir, { recursive: true, force: true }, () => {})
|
||||
})
|
||||
22
repos/effect/scripts/codemod.mjs
Normal file
22
repos/effect/scripts/codemod.mjs
Normal file
@@ -0,0 +1,22 @@
|
||||
// @ts-check
|
||||
// Runs the JSDoc placement codemod used before snapshot and release builds.
|
||||
// The transformer keeps exported API docs attached to nested signature/type
|
||||
// nodes that can otherwise lose their leading comments during doc generation.
|
||||
import * as Glob from "glob"
|
||||
import * as Jscodeshift from "jscodeshift/src/Runner.js"
|
||||
import * as Path from "node:path"
|
||||
|
||||
// Look up files in all workspace packages including those nested in
|
||||
// sub-packages (e.g. `packages/ai/openapi`).
|
||||
const pattern = "packages/{*,*/*}/src/**/*.ts"
|
||||
|
||||
const paths = Glob.globSync(pattern, {
|
||||
ignore: ["**/internal/**"]
|
||||
}).map((path) => Path.resolve(path))
|
||||
|
||||
const transformer = Path.resolve("scripts/codemods/jsdoc.ts")
|
||||
|
||||
Jscodeshift.run(transformer, paths, {
|
||||
babel: true,
|
||||
parser: "ts"
|
||||
})
|
||||
79
repos/effect/scripts/codemods/jsdoc.ts
Normal file
79
repos/effect/scripts/codemods/jsdoc.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
import type { TSTypeKind } from "ast-types/gen/kinds"
|
||||
import type * as cs from "jscodeshift"
|
||||
|
||||
//
|
||||
// this is needed to resolve a bug in jscodeshift that
|
||||
// forgets to traverse type parameters in call expressions
|
||||
//
|
||||
declare module "ast-types/gen/namedTypes.js" {
|
||||
namespace namedTypes {
|
||||
interface CallExpression extends TSHasOptionalTypeParameterInstantiation {}
|
||||
}
|
||||
}
|
||||
|
||||
export default function transformer(file: cs.FileInfo, api: cs.API) {
|
||||
const j = api.jscodeshift
|
||||
|
||||
const root = j(file.source)
|
||||
|
||||
root.find(j.ExportNamedDeclaration, {
|
||||
declaration: {
|
||||
type: "VariableDeclaration",
|
||||
declarations: [{
|
||||
type: "VariableDeclarator",
|
||||
id: {
|
||||
type: "Identifier",
|
||||
typeAnnotation: {
|
||||
type: "TSTypeAnnotation",
|
||||
typeAnnotation: {
|
||||
type: "TSTypeLiteral",
|
||||
members: [{ type: "TSCallSignatureDeclaration" }]
|
||||
}
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
}).forEach((path) => {
|
||||
const comments = path.node.comments ?? []
|
||||
j(path).find(j.TSCallSignatureDeclaration).forEach((path) => {
|
||||
// Don't override comments if they already exist
|
||||
if (hasComments(path.node)) return
|
||||
path.node.comments = comments
|
||||
})
|
||||
})
|
||||
|
||||
root.find(j.ExportNamedDeclaration, {
|
||||
declaration: {
|
||||
type: "VariableDeclaration",
|
||||
declarations: [{
|
||||
type: "VariableDeclarator",
|
||||
init: {
|
||||
type: "CallExpression",
|
||||
callee: {
|
||||
type: "Identifier",
|
||||
name: "dual"
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
}).forEach((path) => {
|
||||
const comments = path.node.comments ?? []
|
||||
j(path).find(j.CallExpression).forEach((path) => {
|
||||
path.node.typeParameters?.params.forEach((param) => {
|
||||
// Don't override comments if they already exist
|
||||
if (hasLeadingCommentRanges(param) || hasComments(param)) return
|
||||
param.comments = comments
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return root.toSource()
|
||||
}
|
||||
|
||||
function hasComments(node: cs.Node) {
|
||||
return Array.isArray(node.comments)
|
||||
}
|
||||
|
||||
function hasLeadingCommentRanges(node: TSTypeKind) {
|
||||
return "leadingComments" in node && Array.isArray(node.leadingComments) && node.leadingComments.length > 0
|
||||
}
|
||||
64
repos/effect/scripts/docs.mjs
Normal file
64
repos/effect/scripts/docs.mjs
Normal file
@@ -0,0 +1,64 @@
|
||||
import * as Fs from "node:fs"
|
||||
import * as Path from "node:path"
|
||||
|
||||
function packages() {
|
||||
return Fs.readdirSync("packages")
|
||||
.filter((_) => Fs.existsSync(Path.join("packages", _, "docs/modules")))
|
||||
}
|
||||
|
||||
function pkgName(pkg) {
|
||||
const packageJson = Fs.readFileSync(
|
||||
Path.join("packages", pkg, "package.json")
|
||||
)
|
||||
return JSON.parse(packageJson).name
|
||||
}
|
||||
|
||||
function copyFiles(pkg) {
|
||||
const name = pkgName(pkg)
|
||||
const docs = Path.join("packages", pkg, "docs/modules")
|
||||
const dest = Path.join("docs", pkg)
|
||||
const files = Fs.readdirSync(docs, { withFileTypes: true })
|
||||
|
||||
function handleFiles(root, files) {
|
||||
for (const file of files) {
|
||||
const path = Path.join(docs, root, file.name)
|
||||
const destPath = Path.join(dest, root, file.name)
|
||||
|
||||
if (file.isDirectory()) {
|
||||
Fs.mkdirSync(destPath, { recursive: true })
|
||||
handleFiles(Path.join(root, file.name), Fs.readdirSync(path, { withFileTypes: true }))
|
||||
continue
|
||||
}
|
||||
|
||||
const content = Fs.readFileSync(path, "utf8").replace(
|
||||
/^parent: Modules$/m,
|
||||
`parent: "${name}"`
|
||||
)
|
||||
Fs.writeFileSync(destPath, content)
|
||||
}
|
||||
}
|
||||
|
||||
Fs.rmSync(dest, { recursive: true, force: true })
|
||||
Fs.mkdirSync(dest, { recursive: true })
|
||||
handleFiles("", files)
|
||||
}
|
||||
|
||||
function generateIndex(pkg, order) {
|
||||
const name = pkgName(pkg)
|
||||
const content = `---
|
||||
title: "${name}"
|
||||
has_children: true
|
||||
permalink: /docs/${pkg}
|
||||
nav_order: ${order}
|
||||
---
|
||||
`
|
||||
|
||||
Fs.writeFileSync(Path.join("docs", pkg, "index.md"), content)
|
||||
}
|
||||
|
||||
packages().forEach((pkg, i) => {
|
||||
Fs.rmSync(Path.join("docs", pkg), { recursive: true, force: true })
|
||||
Fs.mkdirSync(Path.join("docs", pkg), { recursive: true })
|
||||
copyFiles(pkg)
|
||||
generateIndex(pkg, i + 2)
|
||||
})
|
||||
14
repos/effect/scripts/package-scalar.mjs
Normal file
14
repos/effect/scripts/package-scalar.mjs
Normal file
@@ -0,0 +1,14 @@
|
||||
/* oxlint-disable no-undef */
|
||||
import * as Fs from "fs/promises"
|
||||
|
||||
const jsBundle = await fetch(
|
||||
"https://cdn.jsdelivr.net/npm/@scalar/api-reference@latest/dist/browser/standalone.min.js"
|
||||
).then((res) => res.text())
|
||||
|
||||
const source = `/* oxlint-disable no-undef */
|
||||
|
||||
/** @internal */
|
||||
export const javascript = ${JSON.stringify(`${jsBundle}`)}
|
||||
`
|
||||
|
||||
await Fs.writeFile("packages/effect/src/unstable/httpapi/internal/httpApiScalar.ts", source)
|
||||
23
repos/effect/scripts/package-swagger.mjs
Normal file
23
repos/effect/scripts/package-swagger.mjs
Normal file
@@ -0,0 +1,23 @@
|
||||
/* oxlint-disable no-undef */
|
||||
import * as Fs from "fs/promises"
|
||||
|
||||
const jsBundle = await fetch(
|
||||
"https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js"
|
||||
).then((res) => res.text())
|
||||
const jsPreset = await fetch(
|
||||
"https://unpkg.com/swagger-ui-dist/swagger-ui-standalone-preset.js"
|
||||
).then((res) => res.text())
|
||||
const css = await fetch(
|
||||
"https://unpkg.com/swagger-ui-dist/swagger-ui.css"
|
||||
).then((res) => res.text())
|
||||
|
||||
const source = `/* oxlint-disable no-undef */
|
||||
|
||||
/** @internal */
|
||||
export const javascript = ${JSON.stringify(`${jsBundle}\n${jsPreset}`)}
|
||||
|
||||
/** @internal */
|
||||
export const css = ${JSON.stringify(css)}
|
||||
`
|
||||
|
||||
await Fs.writeFile("packages/effect/src/unstable/httpapi/internal/httpApiSwagger.ts", source)
|
||||
22
repos/effect/scripts/package.json
Normal file
22
repos/effect/scripts/package.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "scripts",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"effect": "workspace:*",
|
||||
"@effect/platform-bun": "workspace:*",
|
||||
"@effect/platform-node": "workspace:*",
|
||||
"@effect/sql-clickhouse": "workspace:*",
|
||||
"@effect/sql-d1": "workspace:*",
|
||||
"@effect/sql-libsql": "workspace:*",
|
||||
"@effect/sql-mysql2": "workspace:*",
|
||||
"@effect/sql-mssql": "workspace:*",
|
||||
"@effect/sql-pg": "workspace:*",
|
||||
"@effect/sql-sqlite-bun": "workspace:*",
|
||||
"@effect/sql-sqlite-do": "workspace:*",
|
||||
"@effect/sql-sqlite-node": "workspace:*",
|
||||
"@effect/sql-sqlite-react-native": "workspace:*",
|
||||
"@effect/sql-sqlite-wasm": "workspace:*"
|
||||
}
|
||||
}
|
||||
18
repos/effect/scripts/tsconfig.json
Normal file
18
repos/effect/scripts/tsconfig.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/tsconfig",
|
||||
"extends": "../tsconfig.base.json",
|
||||
"include": ["**/*.ts"],
|
||||
"compilerOptions": {
|
||||
"noEmit": true,
|
||||
"declaration": false,
|
||||
"declarationMap": false,
|
||||
"composite": false,
|
||||
"incremental": false,
|
||||
"plugins": [
|
||||
{
|
||||
"name": "@effect/language-service",
|
||||
"namespaceImportPackages": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
9
repos/effect/scripts/version.mjs
Normal file
9
repos/effect/scripts/version.mjs
Normal file
@@ -0,0 +1,9 @@
|
||||
import * as Fs from "node:fs"
|
||||
import Package from "../packages/effect/package.json" with { type: "json" }
|
||||
|
||||
const tpl = Fs.readFileSync("./scripts/version.template.txt").toString("utf8")
|
||||
|
||||
Fs.writeFileSync(
|
||||
"packages/effect/src/internal/version.ts",
|
||||
tpl.replace(/VERSION/g, Package.version)
|
||||
)
|
||||
2
repos/effect/scripts/version.template.txt
Normal file
2
repos/effect/scripts/version.template.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
export const version: version = "VERSION"
|
||||
export type version = "VERSION"
|
||||
24
repos/effect/scripts/worktree-setup.sh
Executable file
24
repos/effect/scripts/worktree-setup.sh
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
# install dependencies
|
||||
direnv allow
|
||||
corepack install
|
||||
pnpm install
|
||||
|
||||
# setup repositories
|
||||
git clone --depth 1 https://github.com/tstyche/tstyche.org.git .repos/tstyche.org
|
||||
|
||||
cat << EOF >> AGENTS.md
|
||||
|
||||
## Learning about "effect" v3
|
||||
|
||||
If you need to learn more about the old version of effect (version 3.x), you can
|
||||
access the "v3" branch.
|
||||
|
||||
## Learning about the "tstyche" testing framework
|
||||
|
||||
If you need to learn more about the "tstyche" testing framework, you can access
|
||||
the website repository here:
|
||||
|
||||
\`.repos/tstyche.org\`
|
||||
EOF
|
||||
Reference in New Issue
Block a user