Skip to content

Commit 2eb42bc

Browse files
authored
Misc fixes for VS Code Extension (#5712)
1 parent f2592d5 commit 2eb42bc

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

src/command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export class Command {
258258
* @param options the command options object.
259259
*/
260260
// eslint-disable-next-line @typescript-eslint/no-explicit-any
261-
private async prepare(options: any): Promise<void> {
261+
public async prepare(options: any): Promise<void> {
262262
options = options || {};
263263
options.project = getInheritedOption(options, "project");
264264

src/emulator/functionsEmulator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,7 @@ export class FunctionsEmulator implements EmulatorInstance {
15361536
path,
15371537
headers: req.headers,
15381538
},
1539-
res,
1539+
res as http.ServerResponse,
15401540
reqBody,
15411541
debugBundle
15421542
);

src/frameworks/index.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,22 @@ const DEFAULT_FIND_DEP_OPTIONS: FindDepOptions = {
128128
export const WebFrameworks: Record<string, Framework> = Object.fromEntries(
129129
readdirSync(__dirname)
130130
.filter((path) => statSync(join(__dirname, path)).isDirectory())
131-
.map((path) => [path, require(join(__dirname, path))])
131+
.map((path) => {
132+
// If not called by the CLI, (e.g., by the VS Code Extension)
133+
// __dirname won't refer to this folder and these files won't be available.
134+
// Instead it may find sibling folders that aren't modules, and this
135+
// require will throw.
136+
// Long term fix may be to bundle this instead of reading files at runtime
137+
// but for now, this prevents crashing.
138+
try {
139+
return [path, require(join(__dirname, path))];
140+
} catch (e) {
141+
return [];
142+
}
143+
})
132144
.filter(
133-
([, obj]) => obj.name && obj.discover && obj.build && obj.type !== undefined && obj.support
145+
([, obj]) =>
146+
obj && obj.name && obj.discover && obj.build && obj.type !== undefined && obj.support
134147
)
135148
);
136149

src/options.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { RC } from "./rc";
33

44
// Options come from command-line options and stored config values
55
// TODO: actually define all of this stuff in command.ts and import it from there.
6-
export interface Options {
6+
export interface BaseOptions {
77
cwd: string;
88
configPath: string;
99
only: string;
@@ -25,7 +25,9 @@ export interface Options {
2525
debug: boolean;
2626

2727
rc: RC;
28+
}
2829

30+
export interface Options extends BaseOptions {
2931
// TODO(samstern): Remove this once options is better typed
3032
[key: string]: unknown;
3133
}

0 commit comments

Comments
 (0)