chore: tsx (#2329)

* chore: upgrade jest

* fix: eslint

* chore: github action backend test

* fix: import

* chore: export

* fix: test

* chore: install tsx

* chore: type

* chore: replace @koa/multer

* chore: replace ts-node-dev with tsx
This commit is contained in:
ChengLei Shao 2023-07-27 10:29:07 +08:00 committed by GitHub
parent 331147dfaa
commit 0d92e59985
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 110 additions and 21 deletions

View File

@ -18,7 +18,8 @@
"fs-extra": "^11.1.1",
"pm2": "^5.2.0",
"portfinder": "^1.0.28",
"serve": "^13.0.2"
"serve": "^13.0.2",
"tsx": "^3.12.7"
},
"devDependencies": {
"@nocobase/devtools": "0.11.1-alpha.3"

View File

@ -60,8 +60,9 @@ module.exports = (cli) => {
// }
if (server || !client) {
console.log('starting server', serverPort);
const argv = [
'-P',
'--tsconfig',
'./tsconfig.server.json',
'-r',
'tsconfig-paths/register',
@ -74,8 +75,9 @@ module.exports = (cli) => {
if (opts.dbSync) {
argv.push('--db-sync');
}
const runDevServer = () => {
run('ts-node-dev', argv, {
run('tsx', argv, {
env: {
APP_PORT: serverPort,
},
@ -91,6 +93,7 @@ module.exports = (cli) => {
runDevServer();
}
if (client || !server) {
console.log('starting client', 1 * clientPort);
run('umi', ['dev'], {

View File

@ -106,7 +106,7 @@ exports.runInstall = async () => {
if (exports.isDev()) {
const argv = [
'-P',
'--tsconfig',
'./tsconfig.server.json',
'-r',
'tsconfig-paths/register',
@ -114,7 +114,7 @@ exports.runInstall = async () => {
'install',
'-s',
];
await exports.run('ts-node', argv);
await exports.run('tsx', argv);
} else if (isProd()) {
const file = `./packages/${APP_PACKAGE_ROOT}/server/lib/index.js`;
const argv = [file, 'install', '-s'];
@ -127,7 +127,7 @@ exports.runAppCommand = async (command, args = []) => {
if (exports.isDev()) {
const argv = [
'-P',
'--tsconfig',
'./tsconfig.server.json',
'-r',
'tsconfig-paths/register',
@ -135,7 +135,7 @@ exports.runAppCommand = async (command, args = []) => {
command,
...args,
];
await exports.run('ts-node', argv);
await exports.run('tsx', argv);
} else if (isProd()) {
const argv = [`./packages/${APP_PACKAGE_ROOT}/server/lib/index.js`, command, ...args];
await exports.run('node', argv);

View File

@ -11,6 +11,7 @@
"deepmerge": "^4.2.2",
"flat-to-nested": "^1.1.1",
"graphlib": "^2.1.8",
"multer": "^1.4.5-lts.1",
"object-path": "^0.11.8"
},
"peerDependencies": {

View File

@ -8,6 +8,7 @@ export * from './date';
export * from './dayjs';
export * from './forEach';
export * from './json-templates';
export * from './koa-multer';
export * from './merge';
export * from './mixin';
export * from './mixin/AsyncEmitter';
@ -19,4 +20,3 @@ export * from './requireModule';
export * from './toposort';
export * from './uid';
export { dayjs, lodash };

View File

@ -0,0 +1,58 @@
import originalMulter from 'multer';
function multer(options?) {
const m = originalMulter(options) as any;
makePromise(m, 'any');
makePromise(m, 'array');
makePromise(m, 'fields');
makePromise(m, 'none');
makePromise(m, 'single');
return m;
}
function makePromise(multer, name) {
if (!multer[name]) return;
const fn = multer[name];
multer[name] = function (...args) {
const middleware: any = Reflect.apply(fn, this, args);
return async (ctx, next) => {
await new Promise((resolve, reject) => {
middleware(ctx.req, ctx.res, (err) => {
if (err) return reject(err);
if ('request' in ctx) {
if (ctx.req.body) {
ctx.request.body = ctx.req.body;
delete ctx.req.body;
}
if (ctx.req.file) {
ctx.request.file = ctx.req.file;
ctx.file = ctx.req.file;
delete ctx.req.file;
}
if (ctx.req.files) {
ctx.request.files = ctx.req.files;
ctx.files = ctx.req.files;
delete ctx.req.files;
}
}
resolve(ctx);
});
});
return next();
};
};
}
multer.diskStorage = originalMulter.diskStorage;
multer.memoryStorage = originalMulter.memoryStorage;
export { multer as koaMulter };

View File

@ -2,13 +2,13 @@ import { Plugin } from '@nocobase/server';
import addDumpCommand from './commands/dump-command';
import addRestoreCommand from './commands/restore-command';
import zhCN from './locale/zh-CN';
import dumpAction from './actions/dump-action';
import { getPackageContent, restoreAction } from './actions/restore-action';
import getDictAction from './actions/get-dict-action';
import dumpableCollections from './actions/dumpable-collections-action';
import multer from '@koa/multer';
import { koaMulter as multer } from '@nocobase/utils';
import * as os from 'os';
import dumpAction from './actions/dump-action';
import dumpableCollections from './actions/dumpable-collections-action';
import getDictAction from './actions/get-dict-action';
import { getPackageContent, restoreAction } from './actions/restore-action';
import zhCN from './locale/zh-CN';
export default class Duplicator extends Plugin {
beforeLoad() {

View File

@ -1,5 +1,5 @@
import multer from '@koa/multer';
import actions, { Context, Next } from '@nocobase/actions';
import { Context, Next } from '@nocobase/actions';
import { koaMulter as multer } from '@nocobase/utils';
import path from 'path';
import { DEFAULT_MAX_FILE_SIZE, FILE_FIELD_NAME, LIMIT_FILES } from '../constants';

View File

@ -1,5 +1,5 @@
import multer from '@koa/multer';
import { Context, Next } from '@nocobase/actions';
import { koaMulter as multer } from '@nocobase/utils';
export async function importMiddleware(ctx: Context, next: Next) {
if (ctx.action.actionName !== 'importXlsx') {

View File

@ -4935,7 +4935,7 @@
"@remix-run/router@1.7.2":
version "1.7.2"
resolved "https://registry.npmjs.org/@remix-run/router/-/router-1.7.2.tgz#cba1cf0a04bc04cb66027c51fa600e9cbc388bc8"
resolved "https://registry.yarnpkg.com/@remix-run/router/-/router-1.7.2.tgz#cba1cf0a04bc04cb66027c51fa600e9cbc388bc8"
integrity sha512-7Lcn7IqGMV+vizMPoEl5F0XDshcdDYtMI6uJLQdQz5CfZAwy3vvGKYSUk789qndt5dEC4HfSjviSYlSoHGL2+A==
"@restart/hooks@^0.4.7":
@ -8571,6 +8571,13 @@ busboy@^0.2.11:
dicer "0.2.5"
readable-stream "1.1.x"
busboy@^1.0.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/busboy/-/busboy-1.6.0.tgz#966ea36a9502e43cdb9146962523b92f531f6893"
integrity sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==
dependencies:
streamsearch "^1.1.0"
byline@^5.0.0:
version "5.0.0"
resolved "https://registry.npmmirror.com/byline/-/byline-5.0.0.tgz#741c5216468eadc457b03410118ad77de8c1ddb1"
@ -17659,6 +17666,19 @@ multer@^1.4.2:
type-is "^1.6.4"
xtend "^4.0.0"
multer@^1.4.5-lts.1:
version "1.4.5-lts.1"
resolved "https://registry.yarnpkg.com/multer/-/multer-1.4.5-lts.1.tgz#803e24ad1984f58edffbc79f56e305aec5cfd1ac"
integrity sha512-ywPWvcDMeH+z9gQq5qYHCCy+ethsk4goepZ45GLD63fOu0YcNecQxi64nDs3qluZB+murG3/D4dJ7+dGctcCQQ==
dependencies:
append-field "^1.0.0"
busboy "^1.0.0"
concat-stream "^1.5.2"
mkdirp "^0.5.4"
object-assign "^4.1.1"
type-is "^1.6.4"
xtend "^4.0.0"
multimatch@^4.0.0:
version "4.0.0"
resolved "https://registry.npmmirror.com/multimatch/-/multimatch-4.0.0.tgz#8c3c0f6e3e8449ada0af3dd29efb491a375191b3"
@ -21133,7 +21153,7 @@ react-router-dom@6.3.0, react-router-dom@^6.11.2:
react-router@6.14.1, react-router@6.3.0, react-router@^6.11.2:
version "6.14.2"
resolved "https://registry.npmjs.org/react-router/-/react-router-6.14.2.tgz#1f60994d8c369de7b8ba7a78d8f7ec23df76b300"
resolved "https://registry.yarnpkg.com/react-router/-/react-router-6.14.2.tgz#1f60994d8c369de7b8ba7a78d8f7ec23df76b300"
integrity sha512-09Zss2dE2z+T1D03IheqAFtK4UzQyX8nFPWx6jkwdYzGLXd5ie06A6ezS2fO6zJfEb/SpG6UocN2O1hfD+2urQ==
dependencies:
"@remix-run/router" "1.7.2"
@ -22923,6 +22943,11 @@ streamsearch@0.1.2:
version "0.1.2"
resolved "https://registry.npmmirror.com/streamsearch/-/streamsearch-0.1.2.tgz#808b9d0e56fc273d809ba57338e929919a1a9f1a"
streamsearch@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764"
integrity sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==
strict-uri-encode@^2.0.0:
version "2.0.0"
resolved "https://registry.npmmirror.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546"
@ -23916,9 +23941,10 @@ tsutils@^3.21.0:
dependencies:
tslib "^1.8.1"
tsx@^3.12.2:
tsx@^3.12.2, tsx@^3.12.7:
version "3.12.7"
resolved "https://registry.npmmirror.com/tsx/-/tsx-3.12.7.tgz#b3b8b0fc79afc8260d1e14f9e995616c859a91e9"
resolved "https://registry.yarnpkg.com/tsx/-/tsx-3.12.7.tgz#b3b8b0fc79afc8260d1e14f9e995616c859a91e9"
integrity sha512-C2Ip+jPmqKd1GWVQDvz/Eyc6QJbGfE7NrR3fx5BpEHMZsEHoIxHL1j+lKdGobr8ovEyqeNkPLSKp6SCSOt7gmw==
dependencies:
"@esbuild-kit/cjs-loader" "^2.4.2"
"@esbuild-kit/core-utils" "^3.0.0"