Skip to content

Commit

Permalink
feat: support cjs and esm both by tshy
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
  • Loading branch information
fengmk2 committed Feb 3, 2025
1 parent fa296f0 commit 998a6d1
Show file tree
Hide file tree
Showing 22 changed files with 503 additions and 376 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
test/fixtures
node_modules
coverage
__snapshots__
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"
]
}
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ jobs:
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest, macos-latest, windows-latest'
version: '16, 18, 20, 22'
version: '18, 20, 22'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ test/fixtures/**/run
*-lock.yaml
test/fixtures/apps/ts/tsconfig.tsbuildinfo
test/fixtures/apps/ts/**/*.d.ts
.tshy*
.eslintcache
dist
22 changes: 0 additions & 22 deletions app.js

This file was deleted.

17 changes: 0 additions & 17 deletions app/middleware/multipart.js

This file was deleted.

52 changes: 0 additions & 52 deletions config/config.default.js

This file was deleted.

119 changes: 0 additions & 119 deletions index.d.ts

This file was deleted.

108 changes: 71 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"name": "egg-multipart",
"name": "@eggjs/multipart",
"version": "3.5.0",
"publishConfig": {
"access": "public"
},
"eggPlugin": {
"name": "multipart",
"optionalDependencies": [
"schedule"
]
],
"exports": {
"import": "./dist/esm",
"require": "./dist/commonjs",
"typescript": "./src"
}
},
"description": "multipart plugin for egg",
"main": "index.js",
"scripts": {
"lint": "eslint .",
"test": "npm run lint -- --fix && npm run test-local",
"test-local": "egg-bin test --ts false",
"cov": "egg-bin cov --ts false",
"ci": "npm run lint && npm run cov"
},
"repository": {
"type": "git",
"url": "git+https://github.com/eggjs/egg-multipart.git"
"url": "git+https://github.com/eggjs/multipart.git"
},
"keywords": [
"egg",
Expand All @@ -31,38 +31,72 @@
"bugs": {
"url": "https://github.com/eggjs/egg/issues"
},
"homepage": "https://github.com/eggjs/egg-multipart#readme",
"homepage": "https://github.com/eggjs/multipart#readme",
"engines": {
"node": ">= 14.17.0"
"node": ">= 18.19.0"
},
"files": [
"lib",
"app",
"config",
"app.js",
"index.d.ts"
],
"types": "index.d.ts",
"dependencies": {
"co-busboy": "^2.0.0",
"@eggjs/core": "^6.3.1",
"bytes": "^3.1.2",
"co-busboy": "^2.0.1",
"dayjs": "^1.11.5",
"egg-path-matching": "^1.2.0",
"humanize-bytes": "^1.0.1"
"egg-path-matching": "^2.1.0"
},
"devDependencies": {
"@eggjs/tsconfig": "^1.2.0",
"@types/node": "^20.14.2",
"coffee": "^5.4.0",
"egg": "^3.9.0",
"egg-bin": "6",
"egg-mock": "^5.4.0",
"eslint": "^8.23.1",
"eslint-config-egg": "^12",
"@arethetypeswrong/cli": "^0.17.1",
"@eggjs/bin": "7",
"@eggjs/mock": "^6.0.5",
"@eggjs/tsconfig": "1",
"@types/bytes": "^3.1.5",
"@types/mocha": "10",
"@types/node": "22",
"egg": "^4.0.6",
"eslint": "8",
"eslint-config-egg": "14",
"formstream": "^1.5.1",
"is-type-of": "^1.2.1",
"typescript": "5",
"urllib": "3",
"is-type-of": "2",
"path-to-regexp-v8": "npm:path-to-regexp@8",
"rimraf": "6",
"stream-wormhole": "^2.0.1",
"path-to-regexp-v8": "npm:path-to-regexp@8"
}
"tshy": "3",
"tshy-after": "1",
"typescript": "5",
"urllib": "4"
},
"scripts": {
"lint": "eslint --cache src test --ext .ts",
"pretest": "npm run clean && npm run lint -- --fix",
"test": "egg-bin test",
"preci": "npm run clean && npm run lint",
"ci": "egg-bin cov",
"postci": "npm run prepublishOnly && npm run clean",
"clean": "rimraf dist",
"prepublishOnly": "tshy && tshy-after && attw --pack"
},
"type": "module",
"tshy": {
"exports": {
".": "./src/index.ts",
"./package.json": "./package.json"
}
},
"exports": {
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
},
"./package.json": "./package.json"
},
"files": [
"dist",
"src"
],
"types": "./dist/commonjs/index.d.ts",
"main": "./dist/commonjs/index.js"
}
20 changes: 20 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { EggCore, ILifecycleBoot } from '@eggjs/core';
import { normalizeOptions } from './lib/utils.js';

export default class AppBootHook implements ILifecycleBoot {
constructor(private app: EggCore) {}

configWillLoad() {
this.app.config.multipart = normalizeOptions(this.app.config.multipart);
const options = this.app.config.multipart;

this.app.coreLogger.info('[@eggjs/multipart] %s mode enable', options.mode);
if (options.mode === 'file' || options.fileModeMatch) {
this.app.coreLogger.info('[@eggjs/multipart] will save temporary files to %j, cleanup job cron: %j',
options.tmpdir, options.cleanSchedule.cron);
// enable multipart middleware
this.app.config.coreMiddleware.push('multipart');
}
}
}

Loading

0 comments on commit 998a6d1

Please sign in to comment.