mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
Migrate to pnpm
This commit is contained in:
parent
bbc1afada5
commit
906b5f7f2c
47 changed files with 24183 additions and 23477 deletions
|
@ -110,7 +110,7 @@ async function jimpProcessor (options: {
|
|||
}
|
||||
}
|
||||
|
||||
async function autoResize (options: {
|
||||
function autoResize (options: {
|
||||
sourceImage: Jimp
|
||||
newSize: { width: number, height: number }
|
||||
destination: string
|
||||
|
|
|
@ -33,11 +33,11 @@ const consoleLoggerFormat = format.printf(info => {
|
|||
return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}${additionalInfos}`
|
||||
})
|
||||
|
||||
export const jsonLoggerFormat = format.printf(info => {
|
||||
export const jsonLoggerFormat: ReturnType<typeof format.printf> = format.printf(info => {
|
||||
return JSON.stringify(info, removeCyclicValues())
|
||||
})
|
||||
|
||||
export const labelFormatter = (suffix?: string) => {
|
||||
export const labelFormatter: (suffix?: string) => ReturnType<typeof format.printf> = (suffix?: string) => {
|
||||
return format.label({
|
||||
label: suffix ? `${label} ${suffix}` : label
|
||||
})
|
||||
|
|
|
@ -15,6 +15,7 @@ import { applicationExist, clientsExist, usersExist } from './checker-after-init
|
|||
import { CONFIG } from './config.js'
|
||||
import { DIRECTORIES, FILES_CACHE, LAST_MIGRATION_VERSION } from './constants.js'
|
||||
import { sequelizeTypescript } from './database.js'
|
||||
import { initPNPM } from '@server/lib/plugins/package-manager.js'
|
||||
|
||||
async function installApplication () {
|
||||
try {
|
||||
|
@ -26,7 +27,8 @@ async function installApplication () {
|
|||
createApplicationIfNotExist(),
|
||||
createOAuthClientIfNotExist(),
|
||||
createOAuthAdminIfNotExist(),
|
||||
createRunnerRegistrationTokenIfNotExist()
|
||||
createRunnerRegistrationTokenIfNotExist(),
|
||||
initPNPM()
|
||||
])
|
||||
}),
|
||||
|
||||
|
@ -81,7 +83,7 @@ async function removeDirectoryOrContent (dir: string) {
|
|||
function createDirectoriesIfNotExist () {
|
||||
const storage = CONFIG.STORAGE
|
||||
const cacheDirectories = Object.keys(FILES_CACHE)
|
||||
.map(k => FILES_CACHE[k].DIRECTORY)
|
||||
.map(k => FILES_CACHE[k].DIRECTORY)
|
||||
|
||||
const tasks: Promise<void>[] = []
|
||||
for (const key of Object.keys(storage)) {
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
import { mapToJSON } from '@server/helpers/core-utils.js'
|
||||
import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
|
||||
import { MStreamingPlaylistVideo } from '@server/types/models/index.js'
|
||||
import { writeJson } from 'fs-extra/esm'
|
||||
import { rename } from 'fs/promises'
|
||||
import PQueue from 'p-queue'
|
||||
import { basename } from 'path'
|
||||
import { mapToJSON } from '@server/helpers/core-utils.js'
|
||||
import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
|
||||
import { MStreamingPlaylistVideo } from '@server/types/models/index.js'
|
||||
import { buildSha256Segment } from '../hls.js'
|
||||
import { storeHLSFileFromPath } from '../object-storage/index.js'
|
||||
import { JFWriteOptions } from 'jsonfile'
|
||||
|
||||
const lTags = loggerTagsFactory('live')
|
||||
|
||||
class LiveSegmentShaStore {
|
||||
|
||||
private readonly segmentsSha256 = new Map<string, string>()
|
||||
|
||||
private readonly videoUUID: string
|
||||
|
@ -62,7 +60,9 @@ class LiveSegmentShaStore {
|
|||
if (!this.segmentsSha256.has(segmentName)) {
|
||||
logger.warn(
|
||||
'Unknown segment in live segment hash store for video %s and segment %s.',
|
||||
this.videoUUID, segmentPath, lTags(this.videoUUID)
|
||||
this.videoUUID,
|
||||
segmentPath,
|
||||
lTags(this.videoUUID)
|
||||
)
|
||||
return
|
||||
}
|
||||
|
@ -77,7 +77,8 @@ class LiveSegmentShaStore {
|
|||
logger.debug(`Writing segment sha JSON ${this.sha256Path} of ${this.videoUUID} on disk.`, lTags(this.videoUUID))
|
||||
|
||||
// Atomic write: use rename instead of move that is not atomic
|
||||
await writeJson(this.sha256PathTMP, mapToJSON(this.segmentsSha256), { flush: true } as JFWriteOptions) // FIXME: jsonfile typings
|
||||
// FIXME: jsonfile typings
|
||||
await (writeJson(this.sha256PathTMP, mapToJSON(this.segmentsSha256), { flush: true } as any) as unknown as Promise<void>)
|
||||
await rename(this.sha256PathTMP, this.sha256Path)
|
||||
|
||||
if (this.sendToObjectStorage) {
|
||||
|
|
89
server/core/lib/plugins/package-manager.ts
Normal file
89
server/core/lib/plugins/package-manager.ts
Normal file
|
@ -0,0 +1,89 @@
|
|||
import { isStableOrUnstableVersionValid } from '@server/helpers/custom-validators/misc.js'
|
||||
import { outputJSON, pathExists, remove } from 'fs-extra/esm'
|
||||
import { writeFile } from 'fs/promises'
|
||||
import { join } from 'path'
|
||||
import { execShell } from '../../helpers/core-utils.js'
|
||||
import { isNpmPluginNameValid } from '../../helpers/custom-validators/plugins.js'
|
||||
import { logger } from '../../helpers/logger.js'
|
||||
import { CONFIG } from '../../initializers/config.js'
|
||||
import { getLatestPluginVersion } from './plugin-index.js'
|
||||
|
||||
export async function installNpmPlugin (npmName: string, versionArg?: string) {
|
||||
// Security check
|
||||
checkNpmPluginNameOrThrow(npmName)
|
||||
if (versionArg) checkPluginVersionOrThrow(versionArg)
|
||||
|
||||
const version = versionArg || await getLatestPluginVersion(npmName)
|
||||
|
||||
let toInstall = npmName
|
||||
if (version) toInstall += `@${version}`
|
||||
|
||||
const { stdout } = await execPNPM('add ' + toInstall)
|
||||
|
||||
logger.debug('Added a pnpm package.', { stdout })
|
||||
}
|
||||
|
||||
export async function installNpmPluginFromDisk (path: string) {
|
||||
await execPNPM('add file:' + path)
|
||||
}
|
||||
|
||||
export async function removeNpmPlugin (name: string) {
|
||||
checkNpmPluginNameOrThrow(name)
|
||||
|
||||
await execPNPM('remove ' + name)
|
||||
}
|
||||
|
||||
export async function rebuildNativePlugins () {
|
||||
await execPNPM('rebuild')
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function execPNPM (command: string) {
|
||||
try {
|
||||
const pluginDirectory = CONFIG.STORAGE.PLUGINS_DIR
|
||||
|
||||
return execShell(`pnpm ${command}`, { cwd: pluginDirectory })
|
||||
} catch (result) {
|
||||
logger.error('Cannot exec pnpm.', { command, err: result.err, stderr: result.stderr })
|
||||
|
||||
throw result.err as Error
|
||||
}
|
||||
}
|
||||
|
||||
function checkNpmPluginNameOrThrow (name: string) {
|
||||
if (!isNpmPluginNameValid(name)) throw new Error('Invalid NPM plugin name to install')
|
||||
}
|
||||
|
||||
function checkPluginVersionOrThrow (name: string) {
|
||||
if (!isStableOrUnstableVersionValid(name)) throw new Error('Invalid NPM plugin version to install')
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function initPNPM () {
|
||||
const pluginDirectory = CONFIG.STORAGE.PLUGINS_DIR
|
||||
|
||||
const pluginPackageJSON = join(pluginDirectory, 'package.json')
|
||||
|
||||
// Create empty package.json file if needed
|
||||
if (!await pathExists(pluginPackageJSON)) {
|
||||
logger.info('Init package.json in plugin directory')
|
||||
|
||||
await outputJSON(pluginPackageJSON, {})
|
||||
}
|
||||
|
||||
const pnpmWorkspace = join(pluginDirectory, 'pnpm-workspace.yaml')
|
||||
if (!await pathExists(pnpmWorkspace)) {
|
||||
logger.info('Init pnpm-workspace.yaml in plugin directory')
|
||||
|
||||
await writeFile(pnpmWorkspace, 'dangerouslyAllowAllBuilds: true\nnodeLinker: hoisted\n')
|
||||
}
|
||||
|
||||
if (await pathExists(join(pluginDirectory, 'yarn.lock'))) {
|
||||
logger.info('Migrate from yarn.lock in plugin directory')
|
||||
|
||||
await execPNPM('import yarn.lock')
|
||||
await remove(join(pluginDirectory, 'yarn.lock'))
|
||||
}
|
||||
}
|
|
@ -32,7 +32,7 @@ import {
|
|||
} from '../../types/plugins/index.js'
|
||||
import { ClientHtml } from '../html/client-html.js'
|
||||
import { RegisterHelpers } from './register-helpers.js'
|
||||
import { installNpmPlugin, installNpmPluginFromDisk, rebuildNativePlugins, removeNpmPlugin } from './yarn.js'
|
||||
import { installNpmPlugin, installNpmPluginFromDisk, rebuildNativePlugins, removeNpmPlugin } from './package-manager.js'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
|
||||
|
@ -452,6 +452,8 @@ export class PluginManager implements ServerHook {
|
|||
async rebuildNativePluginsIfNeeded () {
|
||||
if (!await ApplicationModel.nodeABIChanged()) return
|
||||
|
||||
logger.info('Node ABI has changed, rebuilding native plugins')
|
||||
|
||||
return rebuildNativePlugins()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
import { isStableOrUnstableVersionValid } from '@server/helpers/custom-validators/misc.js'
|
||||
import { outputJSON, pathExists } from 'fs-extra/esm'
|
||||
import { join } from 'path'
|
||||
import { execShell } from '../../helpers/core-utils.js'
|
||||
import { isNpmPluginNameValid } from '../../helpers/custom-validators/plugins.js'
|
||||
import { logger } from '../../helpers/logger.js'
|
||||
import { CONFIG } from '../../initializers/config.js'
|
||||
import { getLatestPluginVersion } from './plugin-index.js'
|
||||
|
||||
export async function installNpmPlugin (npmName: string, versionArg?: string) {
|
||||
// Security check
|
||||
checkNpmPluginNameOrThrow(npmName)
|
||||
if (versionArg) checkPluginVersionOrThrow(versionArg)
|
||||
|
||||
const version = versionArg || await getLatestPluginVersion(npmName)
|
||||
|
||||
let toInstall = npmName
|
||||
if (version) toInstall += `@${version}`
|
||||
|
||||
const { stdout } = await execYarn('add ' + toInstall)
|
||||
|
||||
logger.debug('Added a yarn package.', { yarnStdout: stdout })
|
||||
}
|
||||
|
||||
export async function installNpmPluginFromDisk (path: string) {
|
||||
await execYarn('add file:' + path)
|
||||
}
|
||||
|
||||
export async function removeNpmPlugin (name: string) {
|
||||
checkNpmPluginNameOrThrow(name)
|
||||
|
||||
await execYarn('remove ' + name)
|
||||
}
|
||||
|
||||
export async function rebuildNativePlugins () {
|
||||
await execYarn('install --pure-lockfile')
|
||||
}
|
||||
|
||||
// ############################################################################
|
||||
|
||||
async function execYarn (command: string) {
|
||||
try {
|
||||
const pluginDirectory = CONFIG.STORAGE.PLUGINS_DIR
|
||||
const pluginPackageJSON = join(pluginDirectory, 'package.json')
|
||||
|
||||
// Create empty package.json file if needed
|
||||
if (!await pathExists(pluginPackageJSON)) {
|
||||
await outputJSON(pluginPackageJSON, {})
|
||||
}
|
||||
|
||||
return execShell(`yarn ${command}`, { cwd: pluginDirectory })
|
||||
} catch (result) {
|
||||
logger.error('Cannot exec yarn.', { command, err: result.err, stderr: result.stderr })
|
||||
|
||||
throw result.err as Error
|
||||
}
|
||||
}
|
||||
|
||||
function checkNpmPluginNameOrThrow (name: string) {
|
||||
if (!isNpmPluginNameValid(name)) throw new Error('Invalid NPM plugin name to install')
|
||||
}
|
||||
|
||||
function checkPluginVersionOrThrow (name: string) {
|
||||
if (!isStableOrUnstableVersionValid(name)) throw new Error('Invalid NPM plugin version to install')
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue