Skip to content

Commit

Permalink
refactor: update repo
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jun 14, 2024
1 parent 6c0224b commit f516ffe
Show file tree
Hide file tree
Showing 15 changed files with 4,820 additions and 3,535 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

5 changes: 0 additions & 5 deletions .eslintrc

This file was deleted.

25 changes: 25 additions & 0 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: autofix.ci # needed to securely identify the workflow

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

permissions:
contents: read

jobs:
autofix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- run: pnpm install
- run: pnpm lint:fix
- uses: autofix-ci/action@ea32e3a12414e6d3183163c3424a7d7a8631ad84
with:
commit-message: "chore: apply automated updates"
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20
cache: "pnpm"
- run: pnpm install
- run: pnpm lint
- run: pnpm test:types
- run: pnpm build
- run: pnpm vitest --coverage
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.vscode
node_modules
*.log*
.DS_Store
coverage
dist
types
.conf*
.vscode
.DS_Store
.eslintcache
*.log*
*.env*
95 changes: 58 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# ♡ serve-placeholder

> Smart placeholder for missing assets
<!-- automd:badges color=yellow -->

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Github Actions][github-actions-src]][github-actions-href]
[![Codecov][codecov-src]][codecov-href]
[![npm version](https://img.shields.io/npm/v/serve-placeholder?color=yellow)](https://npmjs.com/package/serve-placeholder)
[![npm downloads](https://img.shields.io/npm/dm/serve-placeholder?color=yellow)](https://npmjs.com/package/serve-placeholder)

<!-- /automd -->

Smart placeholder for missing assets

## Why?

Expand All @@ -25,25 +27,35 @@ Instead of indexing invalid URLs with HTML pages, we properly send 404 and the r

Install package:

<!-- automd:pm-install -->

```sh
# ✨ Auto-detect
npx nypm install serve-placeholder

# npm
npm install serve-placeholder

# yarn
yarn install serve-placeholder
yarn add serve-placeholder

# pnpm
pnpm install serve-placeholder

# bun
bun install serve-placeholder
```

<!-- /automd -->

Import:

```js
// ESM
import { servePlaceholder } from 'serve-placeholder'
import { servePlaceholder } from "serve-placeholder";

// CommonJS
const { servePlaceholder } = require('serve-placeholder')
const { servePlaceholder } = require("serve-placeholder");
```

Create and add server middleware between serve-static and router middleware:
Expand All @@ -67,7 +79,7 @@ app.use('/', router)

### `handlers`

A mapping from file extensions to the handler. Extensions should start with *dot* like `.js`.
A mapping from file extensions to the handler. Extensions should start with _dot_ like `.js`.

You can disable any of the handlers by setting the value to `null`

Expand Down Expand Up @@ -108,11 +120,11 @@ Set headers to prevent accidentally caching 404 resources.
When enabled, these headers will be sent:

```js
{
'cache-control': 'no-cache, no-store, must-revalidate',
'expires': '0',
'pragma': 'no-cache'
}
const headers = {
"cache-control": "no-cache, no-store, must-revalidate",
expires: "0",
pragma: "no-cache",
};
```

### `placeholderHeader`
Expand All @@ -125,39 +137,48 @@ Sets an `X-Placeholder` header with value of handler name.

These are [default handlers](./src/defaults.ts). You can override every of them using provided options.

Handler | Extensions | Mime type | Placeholder
-----------|------------------------|--------------------------|-------------------
`default` | any unknown extension | - | -
`css` | `.css` | `text/css` | `/* style not found */`
`html` | `.html`, `.htm` | `text/html` | `<!-- page not found -->`
`js` | `.js` | `application/javascript` | `/* script not found */`
`json` | `.json` | `application/json` | `{}`
`map` | `.map` | `application/json` | [empty sourcemap v3 json]
`plain` | `.txt`, `.text`, `.md` | `text/plain` | [empty]
`image` | `.png`, `.jpg`, `.jpeg`, `.gif`, `.svg`, `.webp`, `.bmp`, `.ico` | `image/gif` | [transparent 1x1 image]
| Handler | Extensions | Mime type | Placeholder |
| --------- | ---------------------------------------------------------------- | ------------------------ | ------------------------- |
| `default` | any unknown extension | - | - |
| `css` | `.css` | `text/css` | `/* style not found */` |
| `html` | `.html`, `.htm` | `text/html` | `<!-- page not found -->` |
| `js` | `.js` | `application/javascript` | `/* script not found */` |
| `json` | `.json` | `application/json` | `{}` |
| `map` | `.map` | `application/json` | [empty sourcemap v3 json] |
| `plain` | `.txt`, `.text`, `.md` | `text/plain` | [empty] |
| `image` | `.png`, `.jpg`, `.jpeg`, `.gif`, `.svg`, `.webp`, `.bmp`, `.ico` | `image/gif` | [transparent 1x1 image] |

## Development

<details>

## 💻 Development
<summary>local development</summary>

- Clone this repository
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable` (use `npm i -g corepack` for Node.js < 16.10)
- Install latest LTS version of [Node.js](https://nodejs.org/en/)
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
- Install dependencies using `pnpm install`
- Run interactive tests using `pnpm dev`

</details>

## License

Made with 💛
<!-- automd:contributors author=pi0 license=MIT -->

Published under the [MIT](https://github.com/unjs/serve-placeholder/blob/main/LICENSE) license.
Made by [@pi0](https://github.com/pi0) and [community](https://github.com/unjs/serve-placeholder/graphs/contributors) 💛
<br><br>
<a href="https://github.com/unjs/serve-placeholder/graphs/contributors">
<img src="https://contrib.rocks/image?repo=unjs/serve-placeholder" />
</a>

Published under [MIT License](./LICENSE).
<!-- /automd -->

<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/serve-placeholder?style=flat-square
[npm-version-href]: https://npmjs.com/package/serve-placeholder
<!-- automd:with-automd -->

[npm-downloads-src]: https://img.shields.io/npm/dm/serve-placeholder?style=flat-square
[npm-downloads-href]: https://npmjs.com/package/serve-placeholder
---

[github-actions-src]: https://img.shields.io/github/actions/workflow/status/unjs/serve-placeholder/ci.yml?style=flat-square&branch=main
[github-actions-href]: https://github.com/unjs/serve-placeholder/actions?query=workflow%3Aci
_🤖 auto updated with [automd](https://automd.unjs.io)_

[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/serve-placeholder/main?style=flat-square
[codecov-href]: https://codecov.io/gh/unjs/serve-placeholder
<!-- /automd -->
19 changes: 19 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.1/schema.json",
"formatter": {
"indentStyle": "space"
},
"files": {
"ignore": []
},
"javascript": {
"formatter": {
"arrowParentheses": "always"
}
},
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
}
}
15 changes: 15 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import unjs from "eslint-config-unjs";

export default unjs({
ignores: [
// ignore paths
],
rules: {
// rule overrides
},
markdown: {
rules: {
// markdown rule overrides
},
},
});
40 changes: 21 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,40 @@
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
}
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"files": ["dist"],
"scripts": {
"build": "unbuild",
"dev": "vitest dev",
"lint": "eslint --ext .ts,.js,.mjs,.cjs .",
"prepack": "unbuild",
"release": "pnpm test && standard-version && git push --follow-tags && pnpm publish",
"test": "pnpm lint && vitest run"
"lint": "eslint . && biome check .",
"lint:fix": "automd && eslint . --fix && biome check --apply .",
"prepack": "pnpm build",
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
"test": "pnpm lint && pnpm test:types && vitest run --coverage",
"test:types": "tsc --noEmit --skipLibCheck"
},
"dependencies": {
"defu": "^6.0.0"
"defu": "^6.1.4"
},
"devDependencies": {
"@nuxtjs/eslint-config-typescript": "latest",
"c8": "^7.11.0",
"eslint": "latest",
"h3": "^0.7.2",
"listhen": "^0.2.8",
"ohmyfetch": "^0.4.15",
"standard-version": "latest",
"typescript": "latest",
"unbuild": "latest",
"vitest": "^0.9.2"
"@biomejs/biome": "^1.7.2",
"@types/node": "^20.12.7",
"@vitest/coverage-v8": "^1.5.3",
"automd": "^0.3.7",
"changelogen": "^0.5.5",
"eslint": "^9.1.1",
"eslint-config-unjs": "^0.3.2",
"jiti": "^1.21.0",
"typescript": "^5.4.5",
"unbuild": "^2.0.0",
"vitest": "^1.5.3"
},
"packageManager": "pnpm@6.32.4"
"packageManager": "pnpm@9.0.6"
}
Loading

0 comments on commit f516ffe

Please sign in to comment.