mirror of
https://github.com/langgenius/dify.git
synced 2026-06-08 09:27:39 +08:00
chore: workspace lint (#35331)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import { spawn, type ChildProcess } from 'node:child_process'
|
||||
import type { ChildProcess } from 'node:child_process'
|
||||
import { spawn } from 'node:child_process'
|
||||
import { createHash } from 'node:crypto'
|
||||
import { access, copyFile, readFile, writeFile } from 'node:fs/promises'
|
||||
import net from 'node:net'
|
||||
@ -48,7 +49,8 @@ const formatCommand = (command: string, args: string[]) => [command, ...args].jo
|
||||
|
||||
export const isMainModule = (metaUrl: string) => {
|
||||
const entrypoint = process.argv[1]
|
||||
if (!entrypoint) return false
|
||||
if (!entrypoint)
|
||||
return false
|
||||
|
||||
return pathToFileURL(entrypoint).href === metaUrl
|
||||
}
|
||||
@ -107,7 +109,8 @@ export const runCommandOrThrow = async (options: RunCommandOptions) => {
|
||||
|
||||
const forwardSignalsToChild = (childProcess: ChildProcess) => {
|
||||
const handleSignal = (signal: NodeJS.Signals) => {
|
||||
if (childProcess.exitCode === null) childProcess.kill(signal)
|
||||
if (childProcess.exitCode === null)
|
||||
childProcess.kill(signal)
|
||||
}
|
||||
|
||||
const onSigint = () => handleSignal('SIGINT')
|
||||
@ -152,7 +155,8 @@ export const runForegroundProcess = async ({
|
||||
export const ensureFileExists = async (filePath: string, exampleFilePath: string) => {
|
||||
try {
|
||||
await access(filePath)
|
||||
} catch {
|
||||
}
|
||||
catch {
|
||||
await copyFile(exampleFilePath, filePath)
|
||||
}
|
||||
}
|
||||
@ -162,9 +166,10 @@ export const ensureLineInFile = async (filePath: string, line: string) => {
|
||||
const lines = fileContent.split(/\r?\n/)
|
||||
const assignmentPrefix = line.includes('=') ? `${line.slice(0, line.indexOf('='))}=` : null
|
||||
|
||||
if (lines.includes(line)) return
|
||||
if (lines.includes(line))
|
||||
return
|
||||
|
||||
if (assignmentPrefix && lines.some((existingLine) => existingLine.startsWith(assignmentPrefix)))
|
||||
if (assignmentPrefix && lines.some(existingLine => existingLine.startsWith(assignmentPrefix)))
|
||||
return
|
||||
|
||||
const normalizedContent = fileContent.endsWith('\n') ? fileContent : `${fileContent}\n`
|
||||
@ -187,16 +192,16 @@ export const readSimpleDotenv = async (filePath: string) => {
|
||||
const fileContent = await readFile(filePath, 'utf8')
|
||||
const entries = fileContent
|
||||
.split(/\r?\n/)
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line && !line.startsWith('#'))
|
||||
.map(line => line.trim())
|
||||
.filter(line => line && !line.startsWith('#'))
|
||||
.map<[string, string]>((line) => {
|
||||
const separatorIndex = line.indexOf('=')
|
||||
const key = separatorIndex === -1 ? line : line.slice(0, separatorIndex).trim()
|
||||
const rawValue = separatorIndex === -1 ? '' : line.slice(separatorIndex + 1).trim()
|
||||
|
||||
if (
|
||||
(rawValue.startsWith('"') && rawValue.endsWith('"')) ||
|
||||
(rawValue.startsWith("'") && rawValue.endsWith("'"))
|
||||
(rawValue.startsWith('"') && rawValue.endsWith('"'))
|
||||
|| (rawValue.startsWith('\'') && rawValue.endsWith('\''))
|
||||
) {
|
||||
return [key, rawValue.slice(1, -1)]
|
||||
}
|
||||
@ -221,7 +226,8 @@ export const waitForCondition = async ({
|
||||
const deadline = Date.now() + timeoutMs
|
||||
|
||||
while (Date.now() < deadline) {
|
||||
if (await check()) return
|
||||
if (await check())
|
||||
return
|
||||
|
||||
await sleep(intervalMs)
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { mkdir, rm } from 'node:fs/promises'
|
||||
import path from 'node:path'
|
||||
import { startLoggedProcess, stopManagedProcess, waitForUrl } from '../support/process'
|
||||
import { startWebServer, stopWebServer } from '../support/web-server'
|
||||
import { waitForUrl, startLoggedProcess, stopManagedProcess } from '../support/process'
|
||||
import { apiURL, baseURL, reuseExistingWebServer } from '../test-env'
|
||||
import { e2eDir, isMainModule, runCommand } from './common'
|
||||
import { resetState, startMiddleware, stopMiddleware } from './setup'
|
||||
@ -40,16 +40,18 @@ const parseArgs = (argv: string[]): RunOptions => {
|
||||
}
|
||||
|
||||
const hasCustomTags = (forwardArgs: string[]) =>
|
||||
forwardArgs.some((arg) => arg === '--tags' || arg.startsWith('--tags='))
|
||||
forwardArgs.some(arg => arg === '--tags' || arg.startsWith('--tags='))
|
||||
|
||||
const main = async () => {
|
||||
const { forwardArgs, full, headed } = parseArgs(process.argv.slice(2))
|
||||
const startMiddlewareForRun = full
|
||||
const resetStateForRun = full
|
||||
|
||||
if (resetStateForRun) await resetState()
|
||||
if (resetStateForRun)
|
||||
await resetState()
|
||||
|
||||
if (startMiddlewareForRun) await startMiddleware()
|
||||
if (startMiddlewareForRun)
|
||||
await startMiddleware()
|
||||
|
||||
const cucumberReportDir = path.join(e2eDir, 'cucumber-report')
|
||||
const logDir = path.join(e2eDir, '.logs')
|
||||
@ -75,7 +77,8 @@ const main = async () => {
|
||||
if (startMiddlewareForRun) {
|
||||
try {
|
||||
await stopMiddleware()
|
||||
} catch {
|
||||
}
|
||||
catch {
|
||||
// Cleanup should continue even if middleware shutdown fails.
|
||||
}
|
||||
}
|
||||
@ -97,7 +100,8 @@ const main = async () => {
|
||||
try {
|
||||
try {
|
||||
await waitForUrl(`${apiURL}/health`, 180_000, 1_000)
|
||||
} catch {
|
||||
}
|
||||
catch {
|
||||
throw new Error(`API did not become ready at ${apiURL}/health.`)
|
||||
}
|
||||
|
||||
@ -133,7 +137,8 @@ const main = async () => {
|
||||
})
|
||||
|
||||
process.exitCode = result.exitCode
|
||||
} finally {
|
||||
}
|
||||
finally {
|
||||
process.off('SIGINT', onTerminate)
|
||||
process.off('SIGTERM', onTerminate)
|
||||
await cleanup()
|
||||
|
||||
@ -5,8 +5,8 @@ import {
|
||||
apiDir,
|
||||
apiEnvExampleFile,
|
||||
dockerDir,
|
||||
e2eWebEnvOverrides,
|
||||
e2eDir,
|
||||
e2eWebEnvOverrides,
|
||||
ensureFileExists,
|
||||
ensureLineInFile,
|
||||
getWebEnvLocalHash,
|
||||
@ -79,7 +79,8 @@ const getContainerHealth = async (containerId: string) => {
|
||||
stdio: 'pipe',
|
||||
})
|
||||
|
||||
if (result.exitCode !== 0) return ''
|
||||
if (result.exitCode !== 0)
|
||||
return ''
|
||||
|
||||
return result.stdout.trim()
|
||||
}
|
||||
@ -105,7 +106,8 @@ const waitForDependency = async ({
|
||||
|
||||
try {
|
||||
await wait()
|
||||
} catch (error) {
|
||||
}
|
||||
catch (error) {
|
||||
await printComposeLogs(services)
|
||||
throw error
|
||||
}
|
||||
@ -134,7 +136,7 @@ export const ensureWebBuild = async () => {
|
||||
.then(() => true)
|
||||
.catch(() => false),
|
||||
readFile(webBuildEnvStampPath, 'utf8')
|
||||
.then((value) => value.trim())
|
||||
.then(value => value.trim())
|
||||
.catch(() => ''),
|
||||
])
|
||||
|
||||
@ -142,7 +144,8 @@ export const ensureWebBuild = async () => {
|
||||
console.log('Reusing existing web build artifact.')
|
||||
return
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
catch {
|
||||
// Fall through to rebuild when the existing build cannot be verified.
|
||||
}
|
||||
|
||||
@ -211,7 +214,8 @@ export const resetState = async () => {
|
||||
console.log('Stopping middleware services...')
|
||||
try {
|
||||
await stopMiddleware()
|
||||
} catch {
|
||||
}
|
||||
catch {
|
||||
// Reset should continue even if middleware is already stopped.
|
||||
}
|
||||
|
||||
@ -225,7 +229,7 @@ export const resetState = async () => {
|
||||
|
||||
console.log('Removing E2E local state...')
|
||||
await Promise.all(
|
||||
e2eStatePaths.map((targetPath) => rm(targetPath, { force: true, recursive: true })),
|
||||
e2eStatePaths.map(targetPath => rm(targetPath, { force: true, recursive: true })),
|
||||
)
|
||||
|
||||
console.log('E2E state reset complete.')
|
||||
|
||||
Reference in New Issue
Block a user