Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
fix: Invoke offline without requiring global install (#322)
Browse files Browse the repository at this point in the history
Eliminates need for `azure-functions-core-tools` to be installed globally in order to run offline
  • Loading branch information
tbarlow12 committed Sep 13, 2019
1 parent 51dc106 commit 1a77ff5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/services/offlineService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe("Offline Service", () => {
const calls = mySpawn.calls;
expect(calls).toHaveLength(1);
const call = calls[0];
expect(call.command).toEqual("func");
expect(call.command).toEqual(path.join("node_modules", ".bin", "func"));
expect(call.args).toEqual(["host", "start"]);
});

Expand All @@ -142,7 +142,7 @@ describe("Offline Service", () => {
const calls = mySpawn.calls;
expect(calls).toHaveLength(1);
const call = calls[0];
expect(call.command).toEqual("func.cmd");
expect(call.command).toEqual(path.join("node_modules", ".bin", "func.cmd"));
expect(call.args).toEqual(["host", "start"]);
});

Expand Down Expand Up @@ -174,7 +174,7 @@ describe("Offline Service", () => {
const calls = mySpawn.calls;
expect(calls).toHaveLength(1);
const call = calls[0];
expect(call.command).toEqual("func.cmd");
expect(call.command).toEqual(path.join("node_modules", ".bin", "func.cmd"));
expect(call.args).toEqual(["host", "start"]);

const processOnCalls = processOnSpy.mock.calls;
Expand Down Expand Up @@ -230,7 +230,7 @@ describe("Offline Service", () => {
const calls = mySpawn.calls;
expect(calls).toHaveLength(1);
const call = calls[0];
expect(call.command).toEqual("func.cmd");
expect(call.command).toEqual(path.join("node_modules", ".bin", "func.cmd"));
expect(call.args).toEqual(["host", "start"]);

const processOnCalls = processOnSpy.mock.calls;
Expand Down
10 changes: 10 additions & 0 deletions src/services/offlineService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Serverless from "serverless";
import configConstants from "../config";
import { BaseService } from "./baseService";
import { PackageService } from "./packageService";
import path from "path";

export class OfflineService extends BaseService {

Expand Down Expand Up @@ -58,6 +59,15 @@ export class OfflineService extends BaseService {
* @param spawnArgs Array of arguments for CLI command
*/
private spawn(command: string, spawnArgs?: string[]): Promise<void> {
// Run command from local node_modules
command = path.join(
this.serverless.config.servicePath,
"node_modules",
".bin",
command
);

// Append .cmd if running on windows
if (process.platform === "win32") {
command += ".cmd";
}
Expand Down

0 comments on commit 1a77ff5

Please sign in to comment.