Skip to content

Commit

Permalink
feat: support cjs and esm both by tshy (#26)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: drop Node.js < 18.19.0 support

part of eggjs/egg#3644

eggjs/egg#5257

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
	- Updated package to `@eggjs/static`
	- Enhanced TypeScript support
	- Improved static file serving configuration

- **Chores**
	- Updated GitHub Actions workflows
	- Modernized project configuration
	- Updated Node.js version support to 18.19.0, 20, and 22

- **Documentation**
	- Updated README with new package details
	- Simplified changelog and documentation

- **Refactor**
	- Migrated from CommonJS to ES modules
	- Restructured project file organization

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
fengmk2 authored Jan 12, 2025
1 parent b8a2a0f commit ab7d6fb
Show file tree
Hide file tree
Showing 23 changed files with 428 additions and 276 deletions.
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "eslint-config-egg"
"extends": [
"eslint-config-egg/typescript",
"eslint-config-egg/lib/rules/enforce-node-prefix"
]
}
24 changes: 0 additions & 24 deletions .github/PULL_REQUEST_TEMPLATE.md

This file was deleted.

10 changes: 4 additions & 6 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ name: CI
on:
push:
branches: [ master ]

pull_request:
branches: [ master ]

workflow_dispatch: {}

jobs:
Job:
name: Node.js
uses: artusjs/github-actions/.github/workflows/node-test.yml@v1
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest, windows-latest'
version: '14, 16, 18'
version: '18.19.0, 20, 22'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
23 changes: 23 additions & 0 deletions .github/workflows/pkg.pr.new.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish Any Commit
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

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

- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm install

- name: Build
run: npm run prepublishOnly --if-present

- run: npx pkg-pr-new publish
7 changes: 2 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
name: Release

on:
push:
branches: [ master ]

workflow_dispatch: {}

jobs:
release:
name: Node.js
uses: artusjs/github-actions/.github/workflows/node-release.yml@v1
uses: eggjs/github-actions/.github/workflows/node-release.yml@master
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
with:
checkTest: false
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ logs/
npm-debug.log
node_modules/
coverage/
run/
test/fixtures/**/run
.DS_Store
.tshy*
.eslintcache
dist
package-lock.json
.package-lock.json
73 changes: 73 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,76 @@
### Features

* add contributors ([3bf1ba1](https://github.com/eggjs/egg-static/commit/3bf1ba1b6bafd4b1a61b9fb0438c4ec07939af37))

---


2.2.0 / 2019-02-15
==================

**features**
* [[`7a4b927`](http://github.com/eggjs/egg-static/commit/7a4b927e53670af89005fde057c838825fe96a30)] - feat: add options.dir for support multi folder serve. (#17) (仙森 <<[email protected]>>)

2.1.1 / 2018-05-02
==================

**fixes**
* [[`a55f7ad`](http://github.com/eggjs/egg-static/commit/a55f7ad50ab880f3114bf12910f5f64e1d4da941)] - fix: range only work with static prefix url (#15) (Yiyu He <<[email protected]>>)

2.1.0 / 2018-01-10
==================

**features**
* [[`cd35dea`](http://github.com/eggjs/egg-static/commit/cd35dea2ccf98dc7fed7d36a25f5555f3712eb8f)] - feat: add range support (#13) (HelloYou <<[email protected]>>)

**others**
* [[`93a56c1`](http://github.com/eggjs/egg-static/commit/93a56c1af60c69cd814d33696224a7f044034da6)] - docs: fix confusion for option:prefix (#12) (Airyland <<[email protected]>>)

2.0.0 / 2017-11-09
==================

**others**
* [[`bc2d05c`](http://github.com/eggjs/egg-static/commit/bc2d05c10fe6aabc3e0190a20866dd45f4134dda)] - refactor: upgrade dependencies and support egg@2 (#11) (Yiyu He <<[email protected]>>)
* [[`779e4fa`](http://github.com/eggjs/egg-static/commit/779e4fa7d171fa7e1c51c902e9b47be9632cb35d)] - docs: update usage (#10) (TZ | 天猪 <<[email protected]>>)

1.4.1 / 2017-06-04
==================

* docs: fix License url (#9)

1.4.0 / 2017-06-01
==================

* feat: use lru to store files (#8)

1.3.0 / 2017-03-25
==================

* feat: add support multiple directory (#7)

1.2.0 / 2017-02-21
==================

* deps: upgrade koa-static-cache to 4.x (#6)
* chore: upgrade deps and fix test (#5)

1.1.0 / 2017-01-13
==================

* feat: default lazyload (#4)
* docs: note for koa-static-cache (#3)

1.0.0 / 2016-11-02
==================

* test: add node v7 (#2)

0.1.0 / 2016-07-18
==================

* test: add tests (#1)

0.0.2 / 2016-07-15
==================

* init
70 changes: 0 additions & 70 deletions History.md

This file was deleted.

53 changes: 28 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
# egg-static
# @eggjs/static

[![NPM version][npm-image]][npm-url]
[![Node.js CI](https://github.com/eggjs/static/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/static/actions/workflows/nodejs.yml)
[![Test coverage][codecov-image]][codecov-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]
[![Node.js Version](https://img.shields.io/node/v/@eggjs/static.svg?style=flat)](https://nodejs.org/en/download/)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)

[npm-image]: https://img.shields.io/npm/v/egg-static.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-static
[codecov-image]: https://codecov.io/github/eggjs/egg-static/coverage.svg?branch=master
[codecov-url]: https://codecov.io/github/eggjs/egg-static?branch=master
[download-image]: https://img.shields.io/npm/dm/egg-static.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-static
[npm-image]: https://img.shields.io/npm/v/@eggjs/static.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@eggjs/static
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/static.svg?style=flat-square
[codecov-url]: https://codecov.io/github/eggjs/static?branch=master
[snyk-image]: https://snyk.io/test/npm/@eggjs/static/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/@eggjs/static
[download-image]: https://img.shields.io/npm/dm/@eggjs/static.svg?style=flat-square
[download-url]: https://npmjs.org/package/@eggjs/static

Static server plugin for egg, base on [koa-static-cache](https://github.com/koajs/static-cache).
Static server plugin for egg, base on [@eggjs/koa-static-cache](https://github.com/eggjs/koa-static-cache).

## Install

`egg-static` is a plugin that has been built-in for egg. It is enabled by default.
`@eggjs/static` is a plugin that has been built-in for egg. It is enabled by default.

## Configuration

egg-static support all configurations in [koa-static-cache](https://github.com/koajs/static-cache). and with default configurations below:
`@eggjs/static` support all configurations in [@eggjs/koa-static-cache](https://github.com/eggjs/koa-static-cache).
And with default configurations below:

- prefix: `'/public/'`
- dir: `path.join(appInfo.baseDir, 'app/public')`
Expand All @@ -28,20 +35,22 @@ egg-static support all configurations in [koa-static-cache](https://github.com/k
- maxAge: `31536000` in prod env, `0` in other envs
- buffer: `true` in prod env, `false` in other envs

`egg-static` provides one more option:
`@eggjs/static` provides one more option:

- maxFiles: the maximum value of cache items, only effective when dynamic is true, default is `1000`.

**All static files in `$baseDir/app/public` can be visited with prefix `/public`, and all the files are lazy loaded.**

- In non-production environment, assets won't be cached, your modification can take effect immediately.
- In production environment, `egg-static` will cache the assets after visited, you need to restart the process to update the assets.
- In production environment, `@eggjs/static` will cache the assets after visited, you need to restart the process to update the assets.
- Dir default is `$baseDir/app/public` but you can also define **multiple directory** by use `dir: [dir1, dir2, ...]` or `dir: [dir1, { prefix: '/static2', dir: dir2 }]`, static server will use all these directories.

```js
// {app_root}/config/config.default.js
exports.static = {
// maxAge: 31536000,
```ts
// {app_root}/config/config.default.ts
export default {
static: {
// maxAge: 31536000,
},
};
```

Expand All @@ -51,16 +60,10 @@ Please open an issue [here](https://github.com/eggjs/egg/issues).

## License

[MIT](https://github.com/eggjs/egg-static/blob/master/LICENSE)

<!-- GITCONTRIBUTOR_START -->
[MIT](LICENSE)

## Contributors

|[<img src="https://avatars.githubusercontent.com/u/985607?v=4" width="100px;"/><br/><sub><b>dead-horse</b></sub>](https://github.com/dead-horse)<br/>|[<img src="https://avatars.githubusercontent.com/u/156269?v=4" width="100px;"/><br/><sub><b>fengmk2</b></sub>](https://github.com/fengmk2)<br/>|[<img src="https://avatars.githubusercontent.com/u/227713?v=4" width="100px;"/><br/><sub><b>atian25</b></sub>](https://github.com/atian25)<br/>|[<img src="https://avatars.githubusercontent.com/u/360661?v=4" width="100px;"/><br/><sub><b>popomore</b></sub>](https://github.com/popomore)<br/>|[<img src="https://avatars.githubusercontent.com/u/2127199?v=4" width="100px;"/><br/><sub><b>okoala</b></sub>](https://github.com/okoala)<br/>|[<img src="https://avatars.githubusercontent.com/u/559179?v=4" width="100px;"/><br/><sub><b>airyland</b></sub>](https://github.com/airyland)<br/>|
| :---: | :---: | :---: | :---: | :---: | :---: |
[<img src="https://avatars.githubusercontent.com/u/1798364?v=4" width="100px;"/><br/><sub><b>helloyou2012</b></sub>](https://github.com/helloyou2012)<br/>|[<img src="https://avatars.githubusercontent.com/u/8816730?v=4" width="100px;"/><br/><sub><b>maxming2333</b></sub>](https://github.com/maxming2333)<br/>

This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Sun Feb 12 2023 17:38:47 GMT+0800`.
[![Contributors](https://contrib.rocks/image?repo=eggjs/static)](https://github.com/eggjs/static/graphs/contributors)

<!-- GITCONTRIBUTOR_END -->
Made with [contributors-img](https://contrib.rocks).
11 changes: 0 additions & 11 deletions app.js

This file was deleted.

Loading

0 comments on commit ab7d6fb

Please sign in to comment.