Skip to content

Commit

Permalink
feat: drop uuid dependency (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Dec 18, 2022
1 parent f930ac0 commit b8bb895
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 103 deletions.
21 changes: 0 additions & 21 deletions .autod.conf.js

This file was deleted.

51 changes: 11 additions & 40 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -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'
17 changes: 17 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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`
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/extend/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);

Expand Down
28 changes: 9 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -35,7 +33,7 @@
},
"homepage": "https://github.com/eggjs/egg-multipart#readme",
"engines": {
"node": ">= 14.0.0"
"node": ">= 14.17.0"
},
"files": [
"lib",
Expand All @@ -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"
}
}
19 changes: 2 additions & 17 deletions test/fixtures/apps/ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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": ["../../../../"]
}
}
}
}
4 changes: 1 addition & 3 deletions test/ts.test.js
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down

0 comments on commit b8bb895

Please sign in to comment.