🎥 Make videos programmatically with React
fix crash on startup
Jonny Burger36ad52473202
diff --git a/packages/cli/src/preview-server/error-overlay/react-overlay/utils/open-in-editor.ts b/packages/cli/src/preview-server/error-overlay/react-overlay/utils/open-in-editor.tsindex cae1243638..ed56221766 100644--- a/packages/cli/src/preview-server/error-overlay/react-overlay/utils/open-in-editor.ts+++ b/packages/cli/src/preview-server/error-overlay/react-overlay/utils/open-in-editor.ts@@ -162,7 +162,7 @@ const displayNameForEditor: {[key in Editor]: string} = {};export const getDisplayNameForEditor = (- editor: Editor | undefined+ editor: Editor | null): string | null => {if (!editor) {return null;diff --git a/packages/cli/src/preview-server/routes.ts b/packages/cli/src/preview-server/routes.tsindex b0df1a3aa1..4fe684d28b 100644--- a/packages/cli/src/preview-server/routes.ts+++ b/packages/cli/src/preview-server/routes.ts@@ -37,8 +37,8 @@ const handleFallback = async (response: ServerResponse,getCurrentInputProps: () => object) => {- const edit = await editorGuess;- const displayName = getDisplayNameForEditor(edit[0].command);+ const [edit] = await editorGuess;+ const displayName = getDisplayNameForEditor(edit ? edit.command : null);response.setHeader('content-type', 'text/html');response.writeHead(200);diff --git a/packages/create-video/src/open-in-editor.ts b/packages/create-video/src/open-in-editor.tsindex 90e08a4e4e..a1b91412fe 100644--- a/packages/create-video/src/open-in-editor.ts+++ b/packages/create-video/src/open-in-editor.ts@@ -160,13 +160,7 @@ const displayNameForEditor: {[key in Editor]: string} = {nano: 'nano',};-export const getDisplayNameForEditor = (- editor: Editor | undefined-): string | null => {- if (!editor) {- return null;- }-+export const getDisplayNameForEditor = (editor: Editor): string => {const endsIn = Object.keys(displayNameForEditor).find((displayNameKey) => {return editor.endsWith(displayNameKey);});@@ -352,11 +346,11 @@ export async function guessEditor(): Promise<ProcessAndCommand[]> {const output = (await execProm('ps x')).stdout.toString();const processNames = Object.keys(COMMON_EDITORS_OSX);for (let i = 0; i < processNames.length; i++) {- const processName = processNames[i];+ const processName = processNames[i] as string;if (output.indexOf(processName) !== -1) {availableEditors.push({process: processName,- command: COMMON_EDITORS_OSX[processName],+ command: COMMON_EDITORS_OSX[processName] as Editor,});}}@@ -374,7 +368,7 @@ export async function guessEditor(): Promise<ProcessAndCommand[]> {).stdout.toString();const runningProcesses = output.split('\r\n');for (let i = 0; i < runningProcesses.length; i++) {- const processPath = runningProcesses[i].trim();+ const processPath = (runningProcesses[i] as string).trim();const processName = path.basename(processPath);if (COMMON_EDITORS_WIN.indexOf(processName as Editor) !== -1) {availableEditors.push({@@ -396,11 +390,11 @@ export async function guessEditor(): Promise<ProcessAndCommand[]> {).stdout.toString();const processNames = Object.keys(COMMON_EDITORS_LINUX);for (let i = 0; i < processNames.length; i++) {- const processName = processNames[i];+ const processName = processNames[i] as string;if (output.indexOf(processName) !== -1) {availableEditors.push({process: processName,- command: COMMON_EDITORS_LINUX[processName],+ command: COMMON_EDITORS_LINUX[processName] as Editor,});}}diff --git a/packages/create-video/src/prompts.ts b/packages/create-video/src/prompts.tsindex ee2393e04c..fdd02e7690 100644--- a/packages/create-video/src/prompts.ts+++ b/packages/create-video/src/prompts.ts@@ -1,4 +1,4 @@-import type {Options, PromptObject} from 'prompts';+import type {Choice, Options, PromptObject} from 'prompts';import prompts from 'prompts';export type Question<V extends string = string> = PromptObject<V> & {@@ -50,7 +50,7 @@ export async function selectAsync(}) {if (this.firstRender) {// Ensure the initial state isn't on a disabled item.- while (this.choices[this.cursor].disabled) {+ while ((this.choices[this.cursor] as Choice).disabled) {this.cursor++;if (this.cursor > this.choices.length - 1) break;}@@ -67,10 +67,13 @@ export async function selectAsync(while (true) {if (next <= 0) break;next--;- if (!this.choices[next].disabled) break;+ if (!(this.choices[next] as Choice).disabled) break;}- if (!this.choices[next].disabled && next !== this.cursor) {+ if (+ !(this.choices[next] as Choice).disabled &&+ next !== this.cursor+ ) {this.moveCursor(next);this.render();} else {@@ -85,10 +88,13 @@ export async function selectAsync(while (true) {if (next >= this.choices.length - 1) break;next++;- if (!this.choices[next].disabled) break;+ if (!(this.choices[next] as Choice).disabled) break;}- if (!this.choices[next].disabled && next !== this.cursor) {+ if (+ !(this.choices[next] as Choice).disabled &&+ next !== this.cursor+ ) {this.moveCursor(next);this.render();} else {@@ -103,10 +109,10 @@ export async function selectAsync(while (i < this.choices.length) {i++;next = (next + 1) % this.choices.length;- if (!this.choices[next].disabled) break;+ if (!(this.choices[next] as Choice).disabled) break;}- if (this.choices[next].disabled) {+ if ((this.choices[next] as Choice).disabled) {// unexpectedthis.bell();} else {diff --git a/packages/create-video/tsconfig.json b/packages/create-video/tsconfig.jsonindex a1591f1f6a..42b83a3499 100644--- a/packages/create-video/tsconfig.json+++ b/packages/create-video/tsconfig.json@@ -2,7 +2,8 @@"extends": "../tsconfig.settings.json","compilerOptions": {"outDir": "./dist",- "rootDir": "./src"+ "rootDir": "./src",+ "noUncheckedIndexedAccess": true},"include": ["./src"]}