The swiss army knife of lossless video/audio editing
Access node:path in the renderer through a single util/path module
Claudea1020c8d5f0a
diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsxindex f18b001e..1be69368 100644--- a/src/renderer/src/App.tsx+++ b/src/renderer/src/App.tsx@@ -125,10 +125,10 @@ import WhatsNew from './components/WhatsNew';import mainApi from './mainApi.js';import type { AppEvent } from '../../main/index.js';import { appName } from '../../main/common.js';+import { parse as parsePath, join as pathJoin, basename, dirname } from './util/path';const { ipcRenderer, webUtils } = window.require('electron');const { lstat } = window.require('node:fs/promises');-const { parse: parsePath, join: pathJoin, basename, dirname } = window.require('node:path');const { hasDisabledNetworking, pathToFileURL, lossyMode, isLinux } = window.require('@electron/remote').require('./index.js');diff --git a/src/renderer/src/StreamsSelector.tsx b/src/renderer/src/StreamsSelector.tsxindex e235c189..ab6170a1 100644--- a/src/renderer/src/StreamsSelector.tsx+++ b/src/renderer/src/StreamsSelector.tsx@@ -29,10 +29,9 @@ import Json5Dialog from './components/Json5Dialog';import GpsMap from './components/GpsMap';import Switch from './components/Switch';import type { ConfirmDialog } from './components/GenericDialog';+import { basename } from './util/path';-const { basename } = window.require('node:path');-// for "Copy from": the source's metadata including the user's changes, without muxer-written keysfunction getCopyFromSource({ key, getLabel, existing, custom }: { key: string, getLabel: (metadata: Record<string, string>) => string, existing: Record<string, string> | undefined, custom: Record<string, string> | undefined }) {const metadata = getCopyableMetadata(getEffectiveMetadata(existing, custom));diff --git a/src/renderer/src/components/ConcatDialog.tsx b/src/renderer/src/components/ConcatDialog.tsxindex 7d11eb71..dde56502 100644--- a/src/renderer/src/components/ConcatDialog.tsx+++ b/src/renderer/src/components/ConcatDialog.tsx@@ -24,8 +24,7 @@ import FileNameTemplateEditor from './FileNameTemplateEditor';import HighlightedText from './HighlightedText';import type { FileStats } from '../types';import OutDirSelector from './OutDirSelector';--const { basename } = window.require('node:path');+import { basename } from '../util/path';const rowStyle: CSSProperties = {diff --git a/src/renderer/src/edlStore.ts b/src/renderer/src/edlStore.tsindex 4dece99c..e5d82fcf 100644--- a/src/renderer/src/edlStore.ts+++ b/src/renderer/src/edlStore.ts@@ -10,10 +10,10 @@ import type { EdlExportType, EdlFileType, EdlImportType, GetFrameCount, LlcProjeimport { llcProjectV1Schema, llcProjectV2Schema } from './types';import { mapSaveableSegments } from './segments';import isDev from './isDev';+import { basename } from './util/path';const { readFile, writeFile } = window.require('node:fs/promises');const cueParser = window.require('cue-parser');-const { basename } = window.require('node:path');const { dialog } = window.require('@electron/remote');diff --git a/src/renderer/src/hooks/useFfmpegOperations.ts b/src/renderer/src/hooks/useFfmpegOperations.tsindex ad3ab312..7136eca1 100644--- a/src/renderer/src/hooks/useFfmpegOperations.ts+++ b/src/renderer/src/hooks/useFfmpegOperations.ts@@ -16,8 +16,8 @@ import type { LossyMode } from '../../../main';import { UserFacingError } from '../../errors';import mainApi from '../mainApi';import { formatFfmpegNumber, getFixChannelLayoutFilter, getHwaccelArgs, hasCustomChannelLayout } from '../../../common/util';+import { join, resolve, dirname } from '../util/path';-const { join, resolve, dirname } = window.require('node:path');const { writeFile, mkdir, access, constants: { W_OK } } = window.require('node:fs/promises');diff --git a/src/renderer/src/util.ts b/src/renderer/src/util.tsindex d09a077f..49fb8196 100644--- a/src/renderer/src/util.ts+++ b/src/renderer/src/util.ts@@ -13,8 +13,8 @@ import { appName } from '../../main/common';import type { EnableImportChapters, Html5ifyMode } from '../../common/types';import { UserFacingError } from '../errors';import type { FFprobeFormat } from '../../common/ffprobe';+import { dirname, parse as parsePath, join, extname, isAbsolute, resolve, basename } from './util/path';-const { dirname, parse: parsePath, join, extname, isAbsolute, resolve, basename } = window.require('node:path');const { stat, lstat, readdir, utimes, unlink, open, access, constants: { R_OK, W_OK } } = window.require('node:fs/promises');const remote = window.require('@electron/remote');const { app } = remote;diff --git a/src/renderer/src/util/outputNameTemplate.ts b/src/renderer/src/util/outputNameTemplate.tsindex ab28d91d..1cba5fb2 100644--- a/src/renderer/src/util/outputNameTemplate.ts+++ b/src/renderer/src/util/outputNameTemplate.ts@@ -1,5 +1,4 @@import i18n from 'i18next';-import type { PlatformPath } from 'node:path';import pMap from 'p-map';import max from 'lodash/max';import invariant from 'tiny-invariant';@@ -14,6 +13,7 @@ import safeishEval from '../worker/eval';import { UserFacingError } from '../../errors';import type { FileFfprobeMeta } from '../ffmpeg';import { truncateFileName } from '../../../common/util';+import { parse as parsePath, sep as pathSep, join as pathJoin, normalize as pathNormalize, basename } from './path';export const segNumVariable = 'SEG_NUM';@@ -27,8 +27,6 @@ export const segTagsVariable = 'SEG_TAGS';// I don't remember why I set it to 200, but on Windows max length seems to be 256, on MacOS it seems to be 255.export const maxFileNameLength = 250;-const { parse: parsePath, sep: pathSep, join: pathJoin, normalize: pathNormalize, basename }: PlatformPath = window.require('node:path');-export interface GeneratedOutFileNames {fileNames: string[],diff --git a/src/renderer/src/util/path.ts b/src/renderer/src/util/path.tsnew file mode 100644index 00000000..e2adbf0f--- /dev/null+++ b/src/renderer/src/util/path.ts@@ -0,0 +1,7 @@+import type { PlatformPath } from 'node:path';++// All renderer access to node's path module goes through here,+// so that it can later be replaced (e.g. by a pure JS implementation or IPC)+const path: PlatformPath = window.require('node:path');++export const { basename, dirname, extname, isAbsolute, join, normalize, parse, resolve, sep } = path;