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
72 changes: 72 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Bug Report
description: Report a bug in lite-server
labels: ["bug"]
body:
- type: markdown
attributes:
value: |
Thanks for reporting a bug! Please fill out the sections below.

- type: textarea
id: description
attributes:
label: Description
description: A clear description of the bug — what happened and what you expected.
placeholder: "When I run lite-server with my bs-config.json, it..."
validations:
required: true

- type: textarea
id: repro
attributes:
label: Steps to reproduce
description: Minimal steps to reproduce the behavior.
value: |
1.
2.
3.
validations:
required: true

- type: input
id: lite-server-version
attributes:
label: lite-server version
placeholder: "e.g., 2.6.1"
validations:
required: true

- type: input
id: node-version
attributes:
label: Node.js version
placeholder: "e.g., 20.10.0"
validations:
required: true

- type: input
id: npm-version
attributes:
label: npm version
placeholder: "e.g., 10.2.3"

- type: input
id: os
attributes:
label: Operating system
placeholder: "e.g., macOS 14.2, Windows 11, Ubuntu 22.04"
validations:
required: true

- type: input
id: browser
attributes:
label: Browser (if applicable)
placeholder: "e.g., Chrome 120, Firefox 121"

- type: textarea
id: config
attributes:
label: BrowserSync config (bs-config.json or bs-config.js)
description: Paste your custom config file contents if you have one.
render: json
37 changes: 37 additions & 0 deletions .github/ISSUE_TEMPLATE/feature-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Feature Request
description: Suggest a new feature or improvement
labels: ["enhancement"]
body:
- type: markdown
attributes:
value: |
Thanks for the suggestion! Please describe your idea below.

- type: textarea
id: problem
attributes:
label: Problem
description: What problem does this feature solve?
placeholder: "I'm always frustrated when..."
validations:
required: true

- type: textarea
id: solution
attributes:
label: Proposed solution
description: How would you like this to work?
validations:
required: true

- type: textarea
id: alternatives
attributes:
label: Alternatives considered
description: Any other approaches you've thought about.

- type: textarea
id: context
attributes:
label: Additional context
description: Any other info, screenshots, or examples.
15 changes: 15 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Description

<!-- What does this PR do? Why is it needed? -->

## Checklist

- [ ] `npm test` passes (ESLint + Mocha)
- [ ] Tests added/updated for new behavior
- [ ] `CHANGELOG.md` updated
- [ ] `README.md` updated (if user-facing behavior changed)
- [ ] No breaking changes (or clearly documented)

## Related Issues

<!-- Fixes #123 -->
57 changes: 57 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copilot Instructions — lite-server

## Project Type

This is a **lightweight npm package** — a development server wrapping BrowserSync for SPAs. Pure JavaScript, no build step, no TypeScript.

## Writing Conventions

### JavaScript

- Use `'use strict'` at the top of every file
- Use single quotes for strings
- Use 2-space indentation
- Use `const` by default; `let` only when reassignment is needed
- Use camelCase for variables and functions
- Use 1TBS brace style (`if (x) {`)
- Max line length: 100 characters
- Use `===` for equality checks (enforced by ESLint `eqeqeq` rule)
- Prefer arrow callbacks (`prefer-arrow-callback` rule)
- Prefer template literals over string concatenation (`prefer-template` rule)
- Semicolons required

### Testing

- Test files live in `test/` with `.spec.js` suffix
- Use Mocha `describe`/`it` blocks
- Use `mockery` for module mocking with `useCleanCache: true`
- Use `sinon` for stubs and spies
- Use Node.js built-in `assert` for assertions (not chai or other libraries)
- Always clean up mockery in `afterEach` with `deregisterAll()` and `disable()`
- Register allowed modules with `mockery.registerAllowable()`

### Project

- No build step — ship raw JavaScript
- Entry point: `index.js` (public API), `bin/lite-server` (CLI)
- Core logic: `lib/lite-server.js`
- Default config: `lib/config-defaults.js`

## Commands

```bash
npm install # Install dependencies
npm test # Run ESLint + Mocha/Istanbul coverage
```

## Maintenance Matrix

| When this changes... | Also update... |
|---|---|
| `lib/lite-server.js` (core server logic) | `test/lite-server.spec.js`, `README.md` (if behavior changed), `CHANGELOG.md` |
| `lib/config-defaults.js` (default config) | `test/config-defaults.spec.js`, `README.md` (if defaults changed), `CHANGELOG.md` |
| `package.json` (dependencies, scripts) | `CHANGELOG.md`, verify `npm test` still passes |
| `bin/lite-server` (CLI entry) | `README.md` (if CLI usage changed), `CHANGELOG.md` |
| `.eslintrc` (lint rules) | Verify `npm test` still passes, `CHANGELOG.md` |
| `index.js` (public API exports) | `README.md` (if API changed), `CHANGELOG.md` |
| New middleware added | `lib/config-defaults.js`, `test/config-defaults.spec.js`, `README.md` |
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: CI

on:
pull_request:
branches: [main]
push:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18, 20]
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"

- run: npm install

- run: npm test
16 changes: 16 additions & 0 deletions .github/workflows/copilot-setup-steps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Copilot Setup Steps"

on: workflow_dispatch

jobs:
copilot-setup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"

- run: npm install
85 changes: 85 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# AI-Ready Repo — Agent Guide

## Project Overview

**lite-server** is a lightweight development-only Node.js server that wraps [BrowserSync](https://www.browsersync.io/) to serve SPAs. It provides browser auto-refresh, CSS injection via sockets, and HTML5 History API fallback routing so deep links work during development.

## Repository Structure

```
lite-server/
├── bin/lite-server # CLI entry point
├── lib/
│ ├── config-defaults.js # Default BrowserSync configuration
│ └── lite-server.js # Core server logic — config loading, merging, BrowserSync init
├── index.js # Public API entry point (exports server + defaults)
├── test/
│ ├── config-defaults.spec.js # Unit tests for default config
│ └── lite-server.spec.js # Unit tests for core server logic
├── .eslintrc # ESLint configuration (strict rule set)
├── package.json # npm metadata, dependencies, scripts
├── CHANGELOG.md # Version history
├── README.md # Usage docs, configuration guide, contributing
└── LICENSE # MIT
```

## Tech Stack

| Area | Tool |
|------|------|
| Runtime | Node.js |
| Package manager | npm |
| Core dependency | BrowserSync |
| Linting | ESLint (strict config in `.eslintrc`) |
| Testing | Mocha + Istanbul (coverage) |
| Mocking | Mockery + Sinon |
| Assertions | Node.js built-in `assert` |

## Build & Run

There is no build step. This is a pure JavaScript package.

```bash
# Install dependencies
npm install

# Run linting + tests with coverage
npm test
```

The `npm test` command runs:

1. `eslint *.js lib/*.js` — lint all source files
2. `istanbul cover _mocha -- -R spec` — run Mocha tests with Istanbul coverage

## How It Works

1. **CLI** (`bin/lite-server`) — sets process title and calls the server function
2. **Server** (`lib/lite-server.js`) — parses CLI args with `minimist`, loads the user's `bs-config.{js|json}` overrides, deep-merges with defaults using `lodash.merge`, and starts BrowserSync
3. **Defaults** (`lib/config-defaults.js`) — provides sensible BrowserSync defaults: file watching for `*.{html,htm,css,js}`, `connect-logger` middleware, and `connect-history-api-fallback` middleware
4. **Public API** (`index.js`) — exports `{ server, defaults }` for programmatic use

## Key Patterns

- **Config merging** — uses `lodash.merge()` to deep-merge user overrides with defaults
- **Middleware array** — uses `lodash.compact()` to remove `null` entries (allows users to disable specific middleware by index)
- **Function configs** — `bs-config.js` can export a function that receives the BrowserSync instance
- **Strict linting** — `.eslintrc` enforces `'use strict'`, single quotes, 2-space indent, camelCase, max line length 100
- **Test isolation** — uses `mockery` to mock `require()` calls; each test enables/disables mockery in `beforeEach`/`afterEach`

## Adding a Feature

1. Create a feature branch: `git checkout -b feat/my-feature`
2. Modify or add source files in `lib/`
3. Add or update tests in `test/` using the Mockery + Sinon pattern
4. Run `npm test` to ensure lint + tests pass
5. Update `CHANGELOG.md` with your changes
6. Submit a pull request against `main`

## Common Pitfalls

- **Mockery cleanup** — always call `mockery.deregisterAll()` and `mockery.disable()` in `afterEach` to avoid test pollution
- **`useCleanCache: true`** — required when using mockery so the module cache doesn't bleed between tests
- **Middleware overrides** — `lodash.merge` merges objects by key, so array-like objects `{ 0: null }` set specific middleware slots to `null`
- **No TypeScript** — this is plain JavaScript with `'use strict'` directives; don't add TS files
- **No build step** — don't add bundlers or compilers; the package ships raw JS
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Lightweight _development only_ node server that serves a web app, opens it in the browser, refreshes when html or javascript change, injects CSS changes using sockets, and has a fallback page when a route is not found.

[![AI-Ready](https://img.shields.io/badge/AI--Ready-Full-green?logo=githubcopilot)](https://github.com/johnpapa/ai-ready)
[![Dependency Status](https://david-dm.org/johnpapa/lite-server.svg)](https://david-dm.org/johnpapa/lite-server)
[![npm version](https://badge.fury.io/js/lite-server.svg)](http://badge.fury.io/js/lite-server)
[![Build Status](https://travis-ci.org/johnpapa/lite-server.svg?branch=main)](https://travis-ci.org/johnpapa/lite-server) [![Greenkeeper badge](https://badges.greenkeeper.io/johnpapa/lite-server.svg)](https://greenkeeper.io/)
Expand Down
Loading