diff --git a/.autod.conf.js b/.autod.conf.js deleted file mode 100644 index 9e69f0c..0000000 --- a/.autod.conf.js +++ /dev/null @@ -1,21 +0,0 @@ -'use strict'; - -module.exports = { - write: true, - prefix: '^', - test: [ - 'test', - 'benchmark', - ], - devdep: [ - 'autod', - 'egg', - 'egg-ci', - 'egg-bin', - 'eslint', - 'eslint-config-egg' - ], - exclude: [ - './test/fixtures', - ], -} diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index d874499..5c216b8 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -1,47 +1,18 @@ -# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions - -name: Node.js CI +name: CI on: push: - branches: - - main - - master + branches: [ master ] + pull_request: - branches: - - main - - master - schedule: - - cron: '0 2 * * *' + branches: [ master ] + workflow_dispatch: {} jobs: - build: - runs-on: ${{ matrix.os }} - - strategy: - fail-fast: false - matrix: - node-version: [14, 16, 18] - os: [ubuntu-latest, windows-latest, macos-latest] - - steps: - - name: Checkout Git Source - uses: actions/checkout@v2 - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - - name: Install Dependencies - run: npm i - - - name: Continuous Integration - run: npm run ci - - - name: Code Coverage - uses: codecov/codecov-action@v1 - with: - token: ${{ secrets.CODECOV_TOKEN }} + Job: + name: Node.js + uses: artusjs/github-actions/.github/workflows/node-test.yml@v1 + with: + os: 'ubuntu-latest, macos-latest, windows-latest' + version: '14, 16, 18' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..1612587 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,17 @@ +name: Release + +on: + push: + branches: [ master ] + + workflow_dispatch: {} + +jobs: + release: + name: Node.js + uses: artusjs/github-actions/.github/workflows/node-release.yml@v1 + secrets: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + GIT_TOKEN: ${{ secrets.GIT_TOKEN }} + with: + checkTest: false diff --git a/.gitignore b/.gitignore index ff8678d..e113fad 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ test/fixtures/**/run .DS_Store *-lock.json *-lock.yaml +test/fixtures/apps/ts/tsconfig.tsbuildinfo +test/fixtures/apps/ts/**/*.d.ts diff --git a/README.md b/README.md index 05c793e..529f9c1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # egg-multipart [![NPM version][npm-image]][npm-url] +[![Node.js CI](https://github.com/eggjs/egg-multipart/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/egg-multipart/actions/workflows/nodejs.yml) [![Test coverage][codecov-image]][codecov-url] [![Known Vulnerabilities][snyk-image]][snyk-url] [![npm download][download-image]][download-url] @@ -265,6 +266,7 @@ const { Controller } = require('egg'); const fs = require('fs'); const stream = require('stream'); const util = require('util'); +const { randomUUID } = require('crypto'); const pipeline = util.promisify(stream.pipeline); module.exports = class UploadController extends Controller { @@ -293,7 +295,7 @@ module.exports = class UploadController extends Controller { // 3. or just consume it with another for await // WARNING: You should almost never use the origin filename as it could contain malicious input. - const targetPath = path.join(os.tmpdir(), uuid.v4() + path.extname(filename)); + const targetPath = path.join(os.tmpdir(), randomUUID() + path.extname(filename)); await pipeline(part, createWriteStream(targetPath)); // use `pipeline` not `pipe` } } diff --git a/app/extend/context.js b/app/extend/context.js index e101df0..c53ed8c 100644 --- a/app/extend/context.js +++ b/app/extend/context.js @@ -2,7 +2,7 @@ const assert = require('assert'); const path = require('path'); -const uuid = require('uuid'); +const { randomUUID } = require('crypto'); const parse = require('co-busboy'); const fs = require('fs').promises; const { createWriteStream } = require('fs'); @@ -153,7 +153,7 @@ module.exports = { } // write to tmp file - const filepath = path.join(storedir, uuid.v4() + path.extname(filename)); + const filepath = path.join(storedir, randomUUID() + path.extname(filename)); const target = createWriteStream(filepath); await pipeline(part, target); diff --git a/package.json b/package.json index 19671c0..28144e7 100644 --- a/package.json +++ b/package.json @@ -10,13 +10,11 @@ "description": "multipart plugin for egg", "main": "index.js", "scripts": { - "autod": "autod", "lint": "eslint .", "test": "npm run lint -- --fix && npm run test-local", - "test-local": "egg-bin test", - "cov": "egg-bin cov --c8-report", - "ci": "egg-bin pkgfiles && npm run lint && npm run cov", - "pkgfiles": "egg-bin pkgfiles" + "test-local": "egg-bin test --full-trace", + "cov": "egg-bin cov --full-trace", + "ci": "npm run lint && npm run cov" }, "repository": { "type": "git", @@ -35,7 +33,7 @@ }, "homepage": "https://github.com/eggjs/egg-multipart#readme", "engines": { - "node": ">= 14.0.0" + "node": ">= 14.17.0" }, "files": [ "lib", @@ -45,33 +43,25 @@ "index.d.ts" ], "types": "index.d.ts", - "ci": { - "version": "14, 16, 18", - "license": { - "year": 2017 - } - }, "dependencies": { "co-busboy": "^2.0.0", "dayjs": "^1.11.5", "egg-path-matching": "^1.0.1", "humanize-bytes": "^1.0.1", - "stream-wormhole": "^1.1.0", - "uuid": "^8.3.2" + "stream-wormhole": "^1.1.0" }, "devDependencies": { + "@eggjs/tsconfig": "^1.2.0", "@types/node": "^14.18.29", - "autod": "^3.1.2", "coffee": "^5.4.0", - "egg": "^3.1.0", + "egg": "^3.9.0", "egg-bin": "^5.2.0", - "egg-ci": "^2.1.0", - "egg-mock": "^4.2.1", + "egg-mock": "^5.4.0", "eslint": "^8.23.1", "eslint-config-egg": "^12", "formstream": "^1.1.1", "is-type-of": "^1.2.1", "typescript": "^4.8.3", - "urllib": "^2.38.1" + "urllib": "^2.40.0" } } diff --git a/test/fixtures/apps/ts/tsconfig.json b/test/fixtures/apps/ts/tsconfig.json index d825782..5eeecd9 100644 --- a/test/fixtures/apps/ts/tsconfig.json +++ b/test/fixtures/apps/ts/tsconfig.json @@ -1,24 +1,9 @@ { + "extends": "@eggjs/tsconfig", "compilerOptions": { - "strict": true, - "target": "es2017", - "module": "commonjs", - "moduleResolution": "node", - "noImplicitAny": false, - "allowSyntheticDefaultImports": true, - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "pretty": true, - "noEmitOnError": false, - "noUnusedLocals": true, - "noUnusedParameters": true, - "allowUnreachableCode": false, - "allowUnusedLabels": false, - "strictPropertyInitialization": false, - "noFallthroughCasesInSwitch": true, "baseUrl": "./", "paths": { "egg-multipart": ["../../../../"] } } -} \ No newline at end of file +} diff --git a/test/ts.test.js b/test/ts.test.js index 0744a7e..5b1cdd5 100644 --- a/test/ts.test.js +++ b/test/ts.test.js @@ -1,11 +1,9 @@ -'use strict'; - const assert = require('assert'); const formstream = require('formstream'); const urllib = require('urllib'); const path = require('path'); const mock = require('egg-mock'); -const fs = require('fs').promises; +const fs = require('fs/promises'); const coffee = require('coffee'); describe('test/ts.test.js', () => {