Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI

on:
push:
branches:
- main
- master
pull_request:

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.20.0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Run tests
run: pnpm test
31 changes: 31 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Repository Guidelines

## Project Structure & Module Organization
- `src/` hosts all TypeScript sources (`index.ts`, `prebundle.ts`, helpers, shared `types.ts`); export public symbols through `src/index.ts`.
- `dist/` holds `rslib` output and must stay generated-only, while `compiled/` stores bundled dependencies produced by the CLI; never edit either manually.
- `bin.js` is the CAC-based CLI entry; root configs (`prebundle.config.ts`, `rslib.config.ts`, `tsconfig.json`) govern build targets and should evolve together.
- `tests/` contains `@rstest/core` suites plus fixture configs under `tests/fixtures/` used to exercise the CLI.

## Build, Test, and Development Commands
- `pnpm install` respects `pnpm-lock.yaml`; mixing package managers is forbidden to avoid dependency drift.
- `pnpm dev` runs `rslib build --watch` for tight feedback while hacking on `src/`.
- `pnpm build` generates production artifacts and doubles as a pre-publish smoke test; run it before every PR or release.
- `pnpm test` triggers `pnpm build && rstest`, which runs the CLI integration suite.
- `pnpm prebundle [pkg1 pkg2 ...] --config path/to/config` executes the CLI for all configured dependencies or a filtered subset; use `--config` to point at custom fixtures.
- `pnpm bump` wraps `npx bumpp` for releases; only call after `dist/` and configs are committed.

## Coding Style & Naming Conventions
- The repo is pure ESM (`type: module`), so keep relative imports with explicit `.js` extensions that mirror emitted files.
- Apply `Prettier` defaults (2-space indent, single quotes, trailing commas) before committing; configure your editor to format on save.
- Prefer `camelCase` for functions, `PascalCase` for types/interfaces, and SCREAMING_SNAKE_CASE for constants stored in `constant.ts`.
- Keep modules focused; common utilities belong in `helper.ts`, and shared configuration goes through `src/types.ts` for better type inference.

## Testing Guidelines
- Automated coverage uses `@rstest/core` in `tests/prebundle.test.ts` to snapshot bundled output and execute the emitted modules; add new cases there or create additional suites under `tests/`.
- Prefer end-to-end checks that run `bin.js --config <fixture>` so the CLI path stays covered across platforms.
- When adding manual validation steps (e.g., testing new dependencies), document the exact `pnpm prebundle ...` invocation and observed artifacts in the PR description.

## Commit & Pull Request Guidelines
- Follow Conventional Commits mirroring existing history (`feat:`, `fix(deps):`, `chore:`); add scopes like `feat(cli):` when touching a specific module.
- Each PR should describe the motivation, list the commands you ran (`pnpm build`, `pnpm prebundle commander`, etc.), and reference related issues.
- Separate mechanical refactors from behavior changes to keep diffs reviewable, and ensure CI or manual checks are linked before requesting review.
26 changes: 25 additions & 1 deletion bin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
#!/usr/bin/env node
import cac from 'cac';
import { createRequire } from 'node:module';
import { run } from './dist/index.js';

run();
const require = createRequire(import.meta.url);
const pkg = require('./package.json');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use import here

Copy link
Member Author

@fi3ework fi3ework Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that means we need to either use import attributes (node 20 required, not friendly to node 18 users), or a build process to replace the version from bin. 🤔 i think require is somehow acceptable here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get 👌


const cli = cac('prebundle');

cli
.command('[...packages]', 'Prebundle configured dependencies')
.option('--config <path>', 'Path to a custom config file')
.action(async (packages = [], options) => {
try {
await run({
config: options.config,
packages,
});
} catch (error) {
console.error(error);
process.exitCode = 1;
}
});

cli.help();
cli.version(pkg.version);
cli.parse();
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,24 @@
"dev": "rslib build --watch",
"prebundle": "node ./bin.js",
"prepare": "npm run build",
"bump": "npx bumpp"
"bump": "npx bumpp",
"test": "rstest"
},
"dependencies": {
"cac": "^6.7.14",
"@vercel/ncc": "0.38.4",
"prettier": "^3.6.2",
"rollup": "^4.52.5",
"rollup-plugin-dts": "^6.2.3",
"terser": "^5.44.0"
},
"devDependencies": {
"@astrojs/sitemap": "^3.6.0",
"@rslib/core": "0.17.0",
"@rstest/core": "^0.6.5",
"@types/fs-extra": "^11.0.4",
"@types/node": "22.18.13",
"chalk": "^5.6.2",
"fast-glob": "^3.3.3",
"fs-extra": "^11.3.2",
"rslog": "^1.3.0",
Expand Down
Loading