From 55b4dd366ddfebc3837634d41af165b7091879cb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Jul 2024 08:13:25 +0000 Subject: [PATCH 1/3] chore(deps): bump @fastify/busboy from 2.1.1 to 3.0.0 (#535) Bumps [@fastify/busboy](https://github.com/fastify/busboy) from 2.1.1 to 3.0.0. - [Release notes](https://github.com/fastify/busboy/releases) - [Changelog](https://github.com/fastify/busboy/blob/master/CHANGELOG.md) - [Commits](https://github.com/fastify/busboy/compare/v2.1.1...v3.0.0) --- updated-dependencies: - dependency-name: "@fastify/busboy" dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7da838ea..d2f78a4f 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "type": "commonjs", "types": "types/index.d.ts", "dependencies": { - "@fastify/busboy": "^2.1.0", + "@fastify/busboy": "^3.0.0", "@fastify/deepmerge": "^2.0.0", "@fastify/error": "^4.0.0", "fastify-plugin": "^4.0.0", From 7f7076888a2af16e2e27be16f5f4657c0d341de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Sun, 28 Jan 2024 10:38:02 +0100 Subject: [PATCH 2/3] update for Fastify v5 (#505) --- .github/workflows/ci.yml | 2 +- .gitignore | 3 +++ index.js | 13 +++++------- package.json | 33 ++++++++++++++++------------- test/multipart-big-stream.test.js | 2 +- test/multipart-http2.test.js | 2 +- test/multipart-small-stream.test.js | 2 +- test/multipart.test.js | 2 +- 8 files changed, 31 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b002766..ad3ab6bf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ on: jobs: test: - uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3 + uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4.0.0 with: license-check: true lint: true diff --git a/.gitignore b/.gitignore index 2b6aed4e..0b0a9873 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,9 @@ lib-cov coverage *.lcov +# .tap output +.tap + # nyc test coverage .nyc_output diff --git a/index.js b/index.js index ef42f033..a72acb78 100644 --- a/index.js +++ b/index.js @@ -7,12 +7,11 @@ const { createWriteStream } = require('node:fs') const { unlink } = require('node:fs/promises') const path = require('node:path') const { generateId } = require('./lib/generateId') -const util = require('node:util') const createError = require('@fastify/error') -const sendToWormhole = require('stream-wormhole') +const { sendToWormhole } = require('stream-wormhole') const deepmergeAll = require('@fastify/deepmerge')({ all: true }) -const { PassThrough, pipeline, Readable } = require('node:stream') -const pump = util.promisify(pipeline) +const { PassThrough, Readable } = require('node:stream') +const { pipeline: pump } = require('node:stream/promises') const secureJSON = require('secure-json-parse') const kMultipart = Symbol('multipart') @@ -96,7 +95,6 @@ function fastifyMultipart (fastify, options, done) { const field = req.body[key] /* Don't modify the body if a field doesn't have a value or an attached buffer */ - /* istanbul ignore else */ if (field.value !== undefined) { body[key] = field.value } else if (field._buf) { @@ -501,10 +499,10 @@ function fastifyMultipart (fastify, options, done) { const filepath = this.tmpUploads[i] try { await unlink(filepath) - } catch (error) { - /* istanbul ignore next */ + } /* c8 ignore start */ catch (error) { this.log.error(error, 'Could not delete file') } + /* c8 ignore stop */ } } @@ -513,7 +511,6 @@ function fastifyMultipart (fastify, options, done) { let part while ((part = await parts()) != null) { /* Only return a part if the file property exists */ - /* istanbul ignore else */ if (part.file) { return part } diff --git a/package.json b/package.json index d2f78a4f..72138ffa 100644 --- a/package.json +++ b/package.json @@ -9,30 +9,33 @@ "@fastify/busboy": "^3.0.0", "@fastify/deepmerge": "^2.0.0", "@fastify/error": "^4.0.0", - "fastify-plugin": "^4.0.0", - "secure-json-parse": "^2.4.0", - "stream-wormhole": "^1.1.0" + "fastify-plugin": "^4.5.1", + "secure-json-parse": "^2.7.0", + "stream-wormhole": "^2.0.1" }, "devDependencies": { - "@fastify/pre-commit": "^2.0.2", - "@fastify/swagger": "^8.10.1", - "@fastify/swagger-ui": "^4.0.0", - "@types/node": "^20.1.0", - "@typescript-eslint/eslint-plugin": "^7.1.0", - "@typescript-eslint/parser": "^7.1.0", + "@fastify/pre-commit": "^2.1.0", + "@fastify/swagger": "^8.14.0", + "@fastify/swagger-ui": "^2.1.0", + "@types/node": "^20.11.6", + "@typescript-eslint/eslint-plugin": "^6.19.1", + "@typescript-eslint/parser": "^6.19.1", "benchmark": "^2.1.4", "climem": "^2.0.0", "concat-stream": "^2.0.0", - "eslint": "^8.20.0", - "fastify": "^4.0.0", + "eslint": "^8.56.0", + "eslint-plugin-import": "^2.29.1", + "eslint-plugin-n": "^16.6.2", + "eslint-plugin-promise": "^6.1.1", + "fastify": "^4.25.2", "form-data": "^4.0.0", "h2url": "^0.2.0", "noop-stream": "^0.1.0", "pump": "^3.0.0", - "readable-stream": "^4.5.1", + "readable-stream": "^4.5.2", "snazzy": "^9.0.0", - "standard": "^17.0.0", - "tap": "^16.0.0", + "standard": "^17.1.0", + "tap": "^18.6.1", "tsd": "^0.31.0" }, "scripts": { @@ -45,7 +48,7 @@ "start": "CLIMEM=8999 node -r climem ./examples/example", "test": "npm run test:unit && npm run test:typescript", "test:typescript": "tsd", - "test:unit": "tap -t 90" + "test:unit": "tap -t 120" }, "repository": { "type": "git", diff --git a/test/multipart-big-stream.test.js b/test/multipart-big-stream.test.js index c77260f2..d57ff566 100644 --- a/test/multipart-big-stream.test.js +++ b/test/multipart-big-stream.test.js @@ -7,7 +7,7 @@ const multipart = require('..') const http = require('node:http') const crypto = require('node:crypto') const { Readable } = require('readable-stream') -const sendToWormhole = require('stream-wormhole') +const { sendToWormhole } = require('stream-wormhole') const EventEmitter = require('node:events') const { once } = EventEmitter diff --git a/test/multipart-http2.test.js b/test/multipart-http2.test.js index 832670d0..8685a54f 100644 --- a/test/multipart-http2.test.js +++ b/test/multipart-http2.test.js @@ -7,7 +7,7 @@ const multipart = require('..') const h2url = require('h2url') const path = require('node:path') const fs = require('node:fs') -const sendToWormhole = require('stream-wormhole') +const { sendToWormhole } = require('stream-wormhole') const filePath = path.join(__dirname, '../README.md') diff --git a/test/multipart-small-stream.test.js b/test/multipart-small-stream.test.js index 958c4805..daa6e5c6 100644 --- a/test/multipart-small-stream.test.js +++ b/test/multipart-small-stream.test.js @@ -8,7 +8,7 @@ const http = require('node:http') const path = require('node:path') const fs = require('node:fs') const EventEmitter = require('node:events') -const sendToWormhole = require('stream-wormhole') +const { sendToWormhole } = require('stream-wormhole') const { once } = EventEmitter const filePath = path.join(__dirname, '../README.md') diff --git a/test/multipart.test.js b/test/multipart.test.js index 1f2f8d41..655c68c9 100644 --- a/test/multipart.test.js +++ b/test/multipart.test.js @@ -12,7 +12,7 @@ const concat = require('concat-stream') const stream = require('node:stream') const { once } = require('node:events') const pump = util.promisify(stream.pipeline) -const sendToWormhole = require('stream-wormhole') +const { sendToWormhole } = require('stream-wormhole') const filePath = path.join(__dirname, '../README.md') From 49a525df158edc0fa7224b41edf360290b38621a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Thu, 7 Mar 2024 10:28:47 +0100 Subject: [PATCH 3/3] fix: make sure the handler resolves in all cases (#507) * fix error in processing file * fix error in processing file * add test * fix close * fix test * lint * revert change * Revert "revert change" This reverts commit 17ec56cac8ee3ae40633480883c0f774f4761401. * node 14 :( * node 14 :( * add file * use filePath * delete foo * revert change * remove console.log * add test number * increase timeout * try fixing the error * try fixing the error * try reverting? * Revert "try reverting?" This reverts commit 35aca1e9b9ac97cc5e3e84c5b89d819e8cc32737. * 90 * fix error * fix error * let request aborted destroy the file * simplify * simplify * ci --- test/multipart.test.js | 49 +----------------------------------------- 1 file changed, 1 insertion(+), 48 deletions(-) diff --git a/test/multipart.test.js b/test/multipart.test.js index 655c68c9..34117cd4 100644 --- a/test/multipart.test.js +++ b/test/multipart.test.js @@ -635,7 +635,7 @@ test('should not miss fields if part handler takes much time than formdata parsi t.pass('res ended successfully') }) -test('should not freeze when error is thrown during processing', { skip: process.versions.node.startsWith('14') }, async function (t) { +test('should not freeze when error is thrown during processing', async function (t) { t.plan(2) const app = Fastify() @@ -689,50 +689,3 @@ test('should not freeze when error is thrown during processing', { skip: process await app.close() }) - -const hasGlobalFormData = typeof globalThis.FormData === 'function' - -test('no formData', { skip: !hasGlobalFormData }, function (t) { - t.plan(6) - const fastify = Fastify() - t.teardown(fastify.close.bind(fastify)) - - fastify.register(multipart) - - fastify.post('/', async function (req, reply) { - await t.rejects(req.formData()) - - for await (const part of req.parts()) { - t.equal(part.type, 'field') - t.equal(part.fieldname, 'hello') - t.equal(part.value, 'world') - } - - reply.code(200).send() - }) - - fastify.listen({ port: 0 }, async function () { - // request - const form = new FormData() - const opts = { - protocol: 'http:', - hostname: 'localhost', - port: fastify.server.address().port, - path: '/', - headers: form.getHeaders(), - method: 'POST' - } - - const req = http.request(opts, (res) => { - t.equal(res.statusCode, 200) - // consume all data without processing - res.resume() - res.on('end', () => { - t.pass('res ended successfully') - }) - }) - form.append('hello', 'world') - - form.pipe(req) - }) -})