From a7f97bd7291720dccabcd8a8dcdfe9d8aed7f973 Mon Sep 17 00:00:00 2001 From: whyour Date: Wed, 31 May 2023 14:25:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=20spawn=20=E4=B8=BA=20cross-?= =?UTF-8?q?spawn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/cron.ts | 3 ++- back/services/dependence.ts | 2 +- back/services/schedule.ts | 3 ++- back/services/system.ts | 2 +- back/shared/runCron.ts | 2 +- package.json | 2 ++ pnpm-lock.yaml | 16 ++++++++++++---- 7 files changed, 21 insertions(+), 9 deletions(-) diff --git a/back/services/cron.ts b/back/services/cron.ts index 999fba56..5a412fed 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -2,7 +2,7 @@ import { Service, Inject } from 'typedi'; import winston from 'winston'; import config from '../config'; import { Crontab, CrontabModel, CrontabStatus } from '../data/cron'; -import { exec, execSync, spawn } from 'child_process'; +import { exec, execSync } from 'child_process'; import fs from 'fs'; import cron_parser from 'cron-parser'; import { @@ -17,6 +17,7 @@ import path from 'path'; import { TASK_PREFIX, QL_PREFIX } from '../config/const'; import cronClient from '../schedule/client'; import { runCronWithLimit } from '../shared/pLimit'; +import { spawn } from 'cross-spawn'; @Service() export default class CronService { diff --git a/back/services/dependence.ts b/back/services/dependence.ts index bd242278..98f2cbe8 100644 --- a/back/services/dependence.ts +++ b/back/services/dependence.ts @@ -9,7 +9,7 @@ import { unInstallDependenceCommandTypes, DependenceModel, } from '../data/dependence'; -import { spawn } from 'child_process'; +import { spawn } from 'cross-spawn'; import SockService from './sock'; import { FindOptions, Op } from 'sequelize'; import { concurrentRun } from '../config/util'; diff --git a/back/services/schedule.ts b/back/services/schedule.ts index 9f921470..b0723981 100644 --- a/back/services/schedule.ts +++ b/back/services/schedule.ts @@ -1,7 +1,7 @@ import { Service, Inject } from 'typedi'; import winston from 'winston'; import nodeSchedule from 'node-schedule'; -import { ChildProcessWithoutNullStreams, exec, spawn } from 'child_process'; +import { ChildProcessWithoutNullStreams } from 'child_process'; import { ToadScheduler, LongIntervalJob, @@ -10,6 +10,7 @@ import { } from 'toad-scheduler'; import dayjs from 'dayjs'; import { runCronWithLimit } from '../shared/pLimit'; +import { spawn } from 'cross-spawn'; interface ScheduleTaskType { id: number; diff --git a/back/services/system.ts b/back/services/system.ts index d1be3ccf..8bf00a5d 100644 --- a/back/services/system.ts +++ b/back/services/system.ts @@ -6,7 +6,7 @@ import { AuthDataType, AuthInfo, AuthModel, LoginStatus } from '../data/auth'; import { NotificationInfo } from '../data/notify'; import NotificationService from './notify'; import ScheduleService, { TaskCallbacks } from './schedule'; -import { spawn } from 'child_process'; +import { spawn } from 'cross-spawn'; import SockService from './sock'; import got from 'got'; import { diff --git a/back/shared/runCron.ts b/back/shared/runCron.ts index 0ee3587c..771398e1 100644 --- a/back/shared/runCron.ts +++ b/back/shared/runCron.ts @@ -1,4 +1,4 @@ -import { spawn } from "child_process"; +import { spawn } from 'cross-spawn'; import { runCronWithLimit } from "./pLimit"; import Logger from '../loaders/logger'; diff --git a/package.json b/package.json index 45252e9a..d2722147 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "chokidar": "^3.5.3", "cors": "^2.8.5", "cron-parser": "^4.2.1", + "cross-spawn": "^7.0.3", "dayjs": "^1.11.2", "dotenv": "^16.0.0", "express": "^4.17.3", @@ -104,6 +105,7 @@ "@sentry/react": "^7.12.1", "@types/body-parser": "^1.19.2", "@types/cors": "^2.8.12", + "@types/cross-spawn": "^6.0.2", "@types/express": "^4.17.13", "@types/express-jwt": "^6.0.4", "@types/js-yaml": "^4.0.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ee569670..a9858362 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -28,6 +28,9 @@ dependencies: cron-parser: specifier: ^4.2.1 version: 4.8.1 + cross-spawn: + specifier: ^7.0.3 + version: 7.0.3 dayjs: specifier: ^1.11.2 version: 1.11.7 @@ -144,6 +147,9 @@ devDependencies: '@types/cors': specifier: ^2.8.12 version: 2.8.13 + '@types/cross-spawn': + specifier: ^6.0.2 + version: 6.0.2 '@types/express': specifier: ^4.17.13 version: 4.17.17 @@ -4224,6 +4230,12 @@ packages: '@types/node': 17.0.45 dev: true + /@types/cross-spawn@6.0.2: + resolution: {integrity: sha512-KuwNhp3eza+Rhu8IFI5HUXRP0LIhqH5cAjubUvGXXthh4YYBuP2ntwEX+Cz8GJoZUHlKo247wPWOfA9LYEq4cw==} + dependencies: + '@types/node': 17.0.45 + dev: true + /@types/debug@4.1.7: resolution: {integrity: sha512-9AonUzyTjXXhEOa0DnqpzZi6VHlqKMswga9EXjpXnnqxwLtdvPPtlO8evrI5D9S6asFRCQ6v+wpiUKbw+vKqyg==} dependencies: @@ -6847,7 +6859,6 @@ packages: path-key: 3.1.1 shebang-command: 2.0.0 which: 2.0.2 - dev: true /crypto-browserify@3.12.0: resolution: {integrity: sha512-fz4spIh+znjO2VjL+IdhEpRJ3YN6sMzITSBijk6FK2UvTqruSQW+/cCZTSNsMiZNvUeq0CqurF+dAbyiGOY6Wg==} @@ -10989,7 +11000,6 @@ packages: /path-key@3.1.1: resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==} engines: {node: '>=8'} - dev: true /path-key@4.0.0: resolution: {integrity: sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==} @@ -13699,7 +13709,6 @@ packages: engines: {node: '>=8'} dependencies: shebang-regex: 3.0.0 - dev: true /shebang-regex@1.0.0: resolution: {integrity: sha512-wpoSFAxys6b2a2wHZ1XpDSgD7N9iVjg29Ph9uV/uaP9Ex/KXlkTZTeddxDPSYQpgvzKLGJke2UU0AzoGCjNIvQ==} @@ -13709,7 +13718,6 @@ packages: /shebang-regex@3.0.0: resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} engines: {node: '>=8'} - dev: true /shell-quote@1.8.1: resolution: {integrity: sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==}