Skip to content

Commit

Permalink
fix: sls stage parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ServerlessLife committed May 9, 2024
1 parent 6a183f4 commit a60ff7d
Show file tree
Hide file tree
Showing 10 changed files with 390 additions and 437 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{
"name": "LLDebugger - SLS Simple",
"program": "${workspaceRoot}/node_modules/tsx/dist/cli.mjs",
"args": ["../../src/lldebugger.ts"],
"args": ["../../src/lldebugger.ts", "--stage=test"],
"request": "launch",
"skipFiles": [
"<node_internals>/**"
Expand Down
789 changes: 365 additions & 424 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
"workspaces": [
"src/extension/*",
"test",
"test/cdk-simple"
"test/cdk-simple",
"test/sls-simple",
"test/sls-esbuild"
]
}
2 changes: 2 additions & 0 deletions src/lldebugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export let argOptions: {
remove?: boolean;
verbose?: boolean;
context?: string;
stage?: string;
profile?: string;
region?: string;
role?: string;
Expand All @@ -47,6 +48,7 @@ async function run() {
program.option("-r, --remove", "Remove Lambda Live Debugger infrastructure");
program.option("-v, --verbose", "Verbose logs");
program.option("-c, --context <context>", "AWS CDK context");
program.option("-s, --stage <stage>", "Serverless Framework stage");
program.option("--profile <profile>", "AWS profile to use");
program.option("--region <region>", "AWS region to use");
program.option("--role <role>", "AWS role to use");
Expand Down
12 changes: 10 additions & 2 deletions src/slsResourcesDiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ import resolveConfigurationPath from "serverless/lib/cli/resolve-configuration-p
import readConfiguration from "serverless/lib/configuration/read.js";
import Serverless, { FunctionDefinitionHandler } from "serverless";
import { EsBuildOptions } from "./functionProps.js";
import { LlDebugger } from "./lldebugger.js";

//check if there is serverless.yaml or serverless.js or serverless.ts
export async function isSlsFramework() {
process.argv = []; // LLD arguments might conflict with serverless arguments
// LLD arguments might conflict with serverless arguments
process.argv = [];

const serverlessFiles = [
"serverless.yml",
"serverless.yaml",
Expand Down Expand Up @@ -45,7 +48,12 @@ export const resourcesDiscovery: ResourcesDiscovery = async () => {
const configurationFilename =
configuration && configurationPath.slice(serviceDir.length + 1);
const commands: string[] = [];
const options = {};
const options: any = {};

if (LlDebugger.argOptions.stage) {
options.stage = LlDebugger.argOptions.stage;
}

const variablesMeta = {};

const serverless = new Serverless({
Expand Down
4 changes: 2 additions & 2 deletions test/sls-esbuild/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "sls-simple",
"name": "sls-esbuild",
"version": "1.0.0",
"description": "",
"main": "index.js",
Expand All @@ -15,4 +15,4 @@
"serverless": "^3.38.0",
"serverless-esbuild": "^1.52.1"
}
}
}
4 changes: 2 additions & 2 deletions test/sls-simple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("sls-simple", () => {
await execAsync("npm run deploy", {
cwd: folder,
});
lldProcess = await startDebugger(folder);
lldProcess = await startDebugger(folder, ["--stage=test"]);
}
});

Expand Down Expand Up @@ -64,7 +64,7 @@ describe("sls-simple", () => {

test("remove infra", async () => {
if (process.env.CI === "true" || process.env.RUN_TEST_FROM_CLI === "true") {
await removeInfra(lldProcess, folder);
await removeInfra(lldProcess, folder, ["--stage=test"]);
const lambdaName = "lls-sls-simple-test-testJsCommonJs";
await expectInfraRemoved(lambdaName);
}
Expand Down
4 changes: 2 additions & 2 deletions test/sls-simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"deploy": "serverless deploy",
"destroy": "serverless remove"
"deploy": "serverless deploy --stage=test",
"destroy": "serverless remove --stage=test"
},
"keywords": [],
"author": "",
Expand Down
1 change: 0 additions & 1 deletion test/sls-simple/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ provider:
name: aws
runtime: nodejs20.x
region: eu-west-1
stage: test

functions:
testJsCommonJs:
Expand Down
5 changes: 3 additions & 2 deletions test/utils/removeInfra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { setTimeout } from "timers/promises";

export async function removeInfra(
lldProcess: ChildProcess | undefined,
folder: string
folder: string,
args: string[] = []
) {
lldProcess?.kill();

await execSync("node ../../dist/lldebugger.js --remove", {
await execSync(`node ../../dist/lldebugger.js --remove ${args?.join(" ")}`, {
cwd: folder,
});

Expand Down

0 comments on commit a60ff7d

Please sign in to comment.