Skip to content

Commit a9e8e6f

Browse files
committed
refactor: update package details and README for migration to pillarjs/send
- I also run the npm run lint:fix command, and I remove all the t.plan calls since that functionality is only available in newer versions of Node.js, and we need to keep Node 18 as the minimum.
1 parent 2c5a5f2 commit a9e8e6f

15 files changed

+194
-296
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
run: npm install
6363

6464
- name: Run tests
65-
run: npm run test-ci
65+
run: npm run test:ci
6666

6767
- name: Upload code coverage
6868
uses: actions/upload-artifact@v5

README.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
# @fastify/send
1+
# send
22

3-
[![CI](https://github.com/fastify/send/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/send/actions/workflows/ci.yml)
4-
[![NPM version](https://img.shields.io/npm/v/@fastify/send.svg?style=flat)](https://www.npmjs.com/package/@fastify/send)
5-
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)
3+
[![NPM Version][npm-version-image]][npm-url]
4+
[![NPM Downloads][npm-downloads-image]][npm-url]
5+
[![CI][github-actions-ci-image]][github-actions-ci-url]
6+
[![Test Coverage][coveralls-image]][coveralls-url]
67

78
Send is a library for streaming files from the file system as an HTTP response
89
supporting partial responses (Ranges), conditional-GET negotiation (If-Match,
@@ -17,7 +18,7 @@ This is a [Node.js](https://nodejs.org/en/) module available through the
1718
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
1819

1920
```bash
20-
$ npm install @fastify/send
21+
$ npm install send
2122
```
2223

2324
### TypeScript
@@ -32,7 +33,7 @@ $ npm install -D @types/mime@3
3233
## API
3334

3435
```js
35-
const send = require('@fastify/send')
36+
const send = require('send')
3637
```
3738

3839
### send(req, path, [options])
@@ -208,7 +209,7 @@ given directory as the top-level. For example, a request
208209
```js
209210
const http = require('node:http')
210211
const parseUrl = require('parseurl')
211-
const send = require('@fastify/send')
212+
const send = require('send')
212213

213214
const server = http.createServer(async function onRequest (req, res) {
214215
const { statusCode, headers, stream } = await send(req, parseUrl(req).pathname, { root: '/www/public' })
@@ -224,7 +225,7 @@ server.listen(3000)
224225
```js
225226
const http = require('node:http')
226227
const parseUrl = require('parseurl')
227-
const send = require('@fastify/send')
228+
const send = require('send')
228229

229230
// Default unknown types to text/plain
230231
send.mime.default_type = 'text/plain'
@@ -252,7 +253,7 @@ custom function to render a listing of a directory.
252253
const http = require('node:http')
253254
const fs = require('node:fs')
254255
const parseUrl = require('parseurl')
255-
const send = require('@fastify/send')
256+
const send = require('send')
256257

257258
// Transfer arbitrary files from within /www/example.com/public/*
258259
// with a custom handler for directory listing
@@ -278,7 +279,7 @@ server.listen(3000)
278279
```js
279280
const http = require('node:http')
280281
const parseUrl = require('parseurl')
281-
const send = require('@fastify/send')
282+
const send = require('send')
282283

283284
const server = http.createServer(async function onRequest (req, res) {
284285
// transfer arbitrary files from within
@@ -314,4 +315,14 @@ server.listen(3000)
314315
315316
## License
316317
317-
Licensed under [MIT](./LICENSE).
318+
[MIT](LICENSE)
319+
320+
[coveralls-image]: https://badgen.net/coveralls/c/github/pillarjs/send/master
321+
[coveralls-url]: https://coveralls.io/r/pillarjs/send?branch=master
322+
[github-actions-ci-image]: https://badgen.net/github/checks/pillarjs/send/master?label=linux
323+
[github-actions-ci-url]: https://github.com/pillarjs/send/actions/workflows/ci.yml
324+
[node-image]: https://badgen.net/npm/node/send
325+
[node-url]: https://nodejs.org/en/download/
326+
[npm-downloads-image]: https://badgen.net/npm/dm/send
327+
[npm-url]: https://npmjs.org/package/send
328+
[npm-version-image]: https://badgen.net/npm/v/send

package.json

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "@fastify/send",
2+
"name": "send",
33
"description": "Better streaming static file server with Range and conditional-GET support",
4-
"version": "4.1.0",
4+
"version": "1.2.1",
55
"author": "TJ Holowaychuk <tj@vision-media.ca>",
66
"contributors": [
77
"Douglas Christopher Wilson <doug@somethingdoug.com>",
@@ -24,25 +24,25 @@
2424
"main": "index.js",
2525
"type": "commonjs",
2626
"types": "types/index.d.ts",
27+
"files": [
28+
"LICENSE",
29+
"index.js",
30+
"lib/",
31+
"types"
32+
],
2733
"license": "MIT",
2834
"repository": {
2935
"type": "git",
30-
"url": "git+https://github.com/fastify/send.git"
36+
"url": "git+https://github.com/pillarjs/send.git"
3137
},
3238
"bugs": {
33-
"url": "https://github.com/fastify/send/issues"
39+
"url": "https://github.com/pillarjs/send/issues"
40+
},
41+
"homepage": "https://github.com/pillarjs/send#readme",
42+
"funding": {
43+
"type": "opencollective",
44+
"url": "https://opencollective.com/express"
3445
},
35-
"homepage": "https://github.com/fastify/send#readme",
36-
"funding": [
37-
{
38-
"type": "github",
39-
"url": "https://github.com/sponsors/fastify"
40-
},
41-
{
42-
"type": "opencollective",
43-
"url": "https://opencollective.com/fastify"
44-
}
45-
],
4646
"keywords": [
4747
"static",
4848
"file",
@@ -69,8 +69,12 @@
6969
"lint": "eslint",
7070
"lint:fix": "eslint --fix",
7171
"test": "npm run test:unit && npm run test:typescript",
72+
"test:ci": "c8 --reporter=lcovonly --reporter=text npm test",
7273
"test:coverage": "c8 --reporter html node --test",
7374
"test:typescript": "tsd",
7475
"test:unit": "c8 --100 node --test"
76+
},
77+
"engines": {
78+
"node": ">= 18"
7579
}
7680
}

scripts/version-history.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict'
22

3-
var fs = require('fs')
4-
var path = require('path')
3+
const fs = require('fs')
4+
const path = require('path')
55

6-
var HISTORY_FILE_PATH = path.join(__dirname, '..', 'HISTORY.md')
7-
var MD_HEADER_REGEXP = /^====*$/
8-
var VERSION = process.env.npm_package_version
9-
var VERSION_PLACEHOLDER_REGEXP = /^(?:unreleased|(\d+\.)+x)$/
6+
const HISTORY_FILE_PATH = path.join(__dirname, '..', 'HISTORY.md')
7+
const MD_HEADER_REGEXP = /^====*$/
8+
const VERSION = process.env.npm_package_version
9+
const VERSION_PLACEHOLDER_REGEXP = /^(?:unreleased|(\d+\.)+x)$/
1010

11-
var historyFileLines = fs.readFileSync(HISTORY_FILE_PATH, 'utf-8').split('\n')
11+
const historyFileLines = fs.readFileSync(HISTORY_FILE_PATH, 'utf-8').split('\n')
1212

1313
if (!MD_HEADER_REGEXP.test(historyFileLines[1])) {
1414
console.error('Missing header in HISTORY.md')
@@ -21,7 +21,7 @@ if (!VERSION_PLACEHOLDER_REGEXP.test(historyFileLines[0])) {
2121
}
2222

2323
if (historyFileLines[0].indexOf('x') !== -1) {
24-
var versionCheckRegExp = new RegExp('^' + historyFileLines[0].replace('x', '.+') + '$')
24+
const versionCheckRegExp = new RegExp('^' + historyFileLines[0].replace('x', '.+') + '$')
2525

2626
if (!versionCheckRegExp.test(VERSION)) {
2727
console.error('Version %s does not match placeholder %s', VERSION, historyFileLines[0])
@@ -35,25 +35,25 @@ historyFileLines[1] = repeat('=', historyFileLines[0].length)
3535
fs.writeFileSync(HISTORY_FILE_PATH, historyFileLines.join('\n'))
3636

3737
function getLocaleDate () {
38-
var now = new Date()
38+
const now = new Date()
3939

4040
return zeroPad(now.getFullYear(), 4) + '-' +
4141
zeroPad(now.getMonth() + 1, 2) + '-' +
4242
zeroPad(now.getDate(), 2)
4343
}
4444

4545
function repeat (str, length) {
46-
var out = ''
46+
let out = ''
4747

48-
for (var i = 0; i < length; i++) {
48+
for (let i = 0; i < length; i++) {
4949
out += str
5050
}
5151

5252
return out
5353
}
5454

5555
function zeroPad (number, length) {
56-
var num = number.toString()
56+
let num = number.toString()
5757

5858
while (num.length < length) {
5959
num = '0' + num

test/collapseLeadingSlashes.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const { test } = require('node:test')
4+
const assert = require('node:assert')
45
const { collapseLeadingSlashes } = require('../lib/collapseLeadingSlashes')
56

67
test('collapseLeadingSlashes', function (t) {
@@ -14,9 +15,8 @@ test('collapseLeadingSlashes', function (t) {
1415
['//./text/json', '/./text/json'],
1516
['///./text/json', '/./text/json']
1617
]
17-
t.plan(testCases.length)
1818

1919
for (const testCase of testCases) {
20-
t.assert.deepStrictEqual(collapseLeadingSlashes(testCase[0]), testCase[1])
20+
assert.deepStrictEqual(collapseLeadingSlashes(testCase[0]), testCase[1])
2121
}
2222
})

test/containsDotFile.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const { test } = require('node:test')
4+
const assert = require('node:assert')
45
const { containsDotFile } = require('../lib/containsDotFile')
56

67
test('containsDotFile', function (t) {
@@ -10,9 +11,8 @@ test('containsDotFile', function (t) {
1011
['index.html', false],
1112
['./index.html', false]
1213
]
13-
t.plan(testCases.length)
1414

1515
for (const testCase of testCases) {
16-
t.assert.deepStrictEqual(containsDotFile(testCase[0].split('/')), testCase[1], testCase[0])
16+
assert.deepStrictEqual(containsDotFile(testCase[0].split('/')), testCase[1], testCase[0])
1717
}
1818
})

test/isUtf8MimeType.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const { test } = require('node:test')
4+
const assert = require('node:assert')
45
const { isUtf8MimeType } = require('../lib/isUtf8MimeType')
56

67
test('isUtf8MimeType', function (t) {
@@ -14,9 +15,8 @@ test('isUtf8MimeType', function (t) {
1415
['text/html', true],
1516
['image/png', false]
1617
]
17-
t.plan(testCases.length)
1818

1919
for (const testCase of testCases) {
20-
t.assert.deepStrictEqual(isUtf8MimeType(testCase[0], 'test'), testCase[1])
20+
assert.deepStrictEqual(isUtf8MimeType(testCase[0], 'test'), testCase[1])
2121
}
2222
})

test/mime.test.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
'use strict'
22

3-
const { test } = require('node:test')
3+
const { test, before } = require('node:test')
44
const path = require('node:path')
55
const request = require('supertest')
6+
const assert = require('node:assert')
67
const send = require('..')
78
const { shouldNotHaveHeader, createServer } = require('./utils')
89

910
const fixtures = path.join(__dirname, 'fixtures')
1011

1112
test('send.mime', async function (t) {
12-
t.plan(2)
13-
1413
await t.test('should be exposed', function (t) {
15-
t.plan(1)
16-
t.assert.ok(send.mime)
14+
assert.ok(send.mime)
1715
})
1816

1917
await t.test('.default_type', async function (t) {
20-
t.plan(3)
21-
22-
t.before(() => {
18+
before(() => {
2319
this.default_type = send.mime.default_type
2420
})
2521

@@ -37,7 +33,6 @@ test('send.mime', async function (t) {
3733
})
3834

3935
await t.test('should not add Content-Type for undefined default', async function (t) {
40-
t.plan(1)
4136
send.mime.default_type = undefined
4237

4338
await request(createServer({ root: fixtures }))

test/normalizeList.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const { test } = require('node:test')
4+
const assert = require('node:assert')
45
const { normalizeList } = require('../lib/normalizeList')
56

67
test('normalizeList', function (t) {
@@ -16,13 +17,12 @@ test('normalizeList', function (t) {
1617
[1, new TypeError('test must be array of strings or false')],
1718
[[1], new TypeError('test must be array of strings or false')]
1819
]
19-
t.plan(testCases.length)
2020

2121
for (const testCase of testCases) {
2222
if (testCase[1] instanceof Error) {
23-
t.assert.throws(() => normalizeList(testCase[0], 'test'), testCase[1])
23+
assert.throws(() => normalizeList(testCase[0], 'test'), testCase[1])
2424
} else {
25-
t.assert.deepStrictEqual(normalizeList(testCase[0], 'test'), testCase[1])
25+
assert.deepStrictEqual(normalizeList(testCase[0], 'test'), testCase[1])
2626
}
2727
}
2828
})

0 commit comments

Comments
 (0)