From 5ce034c156fc26cd255c55c2a637892703390c29 Mon Sep 17 00:00:00 2001 From: damiantarnawsky Date: Tue, 6 Jan 2026 16:30:24 -0800 Subject: [PATCH] Add error handling for unknown serve commands in serveCmd function --- CHANGELOG.md | 4 ++++ package-lock.json | 4 ++-- package.json | 2 +- src/web-run.ts | 19 +++++++++++++++---- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7055498..821a217 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog +### Version 2.1.3 + +- Handle where the serve command cannot be determined. + ### Version 2.1.2 - When you change package.json outside of the extension the UI will automatically update. diff --git a/package-lock.json b/package-lock.json index 1b3ea20..41f5b0b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "webnative", - "version": "2.1.0", + "version": "2.1.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "webnative", - "version": "2.1.0", + "version": "2.1.2", "license": "MIT", "dependencies": { "fast-xml-parser": "^3.21.1", diff --git a/package.json b/package.json index eee6aaa..5c9f3af 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "webnative", "displayName": "WebNative", "description": "Create and maintain web and native projects", - "version": "2.1.2", + "version": "2.1.3", "whatsNewRevision": 1, "icon": "media/webnative.png", "publisher": "WebNative", diff --git a/src/web-run.ts b/src/web-run.ts index c0b458c..e1841fe 100755 --- a/src/web-run.ts +++ b/src/web-run.ts @@ -19,7 +19,7 @@ import { } from './workspace-state'; import { getWebConfiguration, WebConfigSetting } from './web-configuration'; import { window, workspace } from 'vscode'; -import { write, writeError } from './logging'; +import { showOutput, write, writeError } from './logging'; import { createServer } from 'http'; import { join } from 'path'; import { viewInEditor } from './preview'; @@ -121,6 +121,8 @@ async function runServe( return `${preop}${npx(project)} ${serveCmd(project)}${serveFlags}`; } +let serveUnknownMsg = false; + function serveCmd(project: Project): string { switch (project.frameworkType) { case 'angular': @@ -134,11 +136,20 @@ function serveCmd(project: Project): string { case 'vue': return 'vue-cli-service serve'; default: { - const cmd = guessServeCommand(project) + ' -- '; + const cmd = guessServeCommand(project); if (cmd) { - return cmd; + return cmd + ' -- '; + } + if (!serveUnknownMsg) { + window.showErrorMessage( + `Unable to determine the command used to serve your web application. Please add a "serve" script to your package.json to define this.`, + ); + serveUnknownMsg = true; } - writeError(`serve command is not know for this project type`); + writeError( + `Unable to determine the command used to serve your web application (start, dev and serve scripts were not found in package.json). Please add a "serve" script to your package.json to define this.`, + ); + showOutput(); } } }