Skip to content

Commit cbde1ef

Browse files
fix: handling the config
1 parent 5cc2c0e commit cbde1ef

File tree

5 files changed

+38
-17
lines changed

5 files changed

+38
-17
lines changed

src/configuration.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ let lambdasList: LambdaResource[] | undefined = undefined;
2020
*/
2121
async function readConfig() {
2222
const supportedFrameworks = ResourceDiscovery.getSupportedFrameworksNames();
23-
const currentFramework = await ResourceDiscovery.getCurrentFrameworkName();
24-
2523
const configFromCliArgs = await getConfigFromCliArgs(supportedFrameworks);
24+
Configuration.setConfig(configFromCliArgs as any); // not complete config
25+
26+
const currentFramework = await ResourceDiscovery.getCurrentFrameworkName();
2627

2728
Logger.setVerbose(configFromCliArgs.verbose === true);
2829

@@ -32,6 +33,7 @@ async function readConfig() {
3233

3334
if (configFromCliArgs.wizard) {
3435
const configFromWizard = await getConfigFromWizard({
36+
configFromCliArgs,
3537
supportedFrameworks,
3638
currentFramework,
3739
currentConfig: configFromConfigFile,

src/configuration/getConfigFromWizard.ts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ const configFileName = path.resolve(configFileDefaultName);
2626
* @returns
2727
*/
2828
export async function getConfigFromWizard({
29+
configFromCliArgs,
2930
supportedFrameworks,
3031
currentFramework,
3132
currentConfig,
3233
}: {
34+
configFromCliArgs: LldConfigCliArgs;
3335
supportedFrameworks: string[];
3436
currentFramework: string | undefined;
3537
currentConfig?: LldConfigTs;
@@ -42,7 +44,10 @@ export async function getConfigFromWizard({
4244
name: "framework",
4345
message: `Which framework are you using (detected: ${currentFramework ?? "?"})?`,
4446
choices: [...supportedFrameworks, "other"],
45-
default: currentConfig?.framework ?? currentFramework,
47+
default:
48+
configFromCliArgs.framework ??
49+
currentConfig?.framework ??
50+
currentFramework,
4651
},
4752
]);
4853

@@ -51,6 +56,9 @@ export async function getConfigFromWizard({
5156
}
5257

5358
const oldContext = currentConfig?.context ?? [];
59+
if (configFromCliArgs.context?.length) {
60+
oldContext.push(...configFromCliArgs.context);
61+
}
5462

5563
if (answers.framework === "cdk") {
5664
const cdkAnswers = await inquirer.prompt([
@@ -98,7 +106,7 @@ export async function getConfigFromWizard({
98106
type: "input",
99107
name: "stage",
100108
message: "Would you like to enter Serverless Framework stage?",
101-
default: currentConfig?.stage,
109+
default: configFromCliArgs.stage ?? currentConfig?.stage,
102110
},
103111
]);
104112

@@ -111,7 +119,7 @@ export async function getConfigFromWizard({
111119
type: "input",
112120
name: "configEnv",
113121
message: "Would you like to enter SAM environment?",
114-
default: currentConfig?.configEnv,
122+
default: configFromCliArgs.configEnv ?? currentConfig?.configEnv,
115123
},
116124
]);
117125

@@ -127,7 +135,7 @@ export async function getConfigFromWizard({
127135
name: "subfolder",
128136
message:
129137
"If you are using monorepo, enter subfolder where the framework is instaled.",
130-
default: currentConfig?.subfolder,
138+
default: configFromCliArgs.subfolder ?? currentConfig?.subfolder,
131139
},
132140
]);
133141

@@ -144,7 +152,10 @@ export async function getConfigFromWizard({
144152
name: "observable",
145153
message:
146154
"Do you want to use observable mode, which just sends events to the debugger and do not use the respose?",
147-
default: currentConfig?.observable ?? false,
155+
default:
156+
configFromCliArgs.observable !== undefined
157+
? configFromCliArgs.observable
158+
: currentConfig?.observable,
148159
},
149160
]);
150161

@@ -156,7 +167,12 @@ export async function getConfigFromWizard({
156167
type: "number",
157168
name: "interval",
158169
message: `Would you like to enter observable mode interval at which events are sent to the debugger? Default is ${defaultObservableInterval}`,
159-
default: currentConfig?.interval ?? defaultObservableInterval,
170+
default:
171+
configFromCliArgs.observable !== undefined
172+
? configFromCliArgs.observable
173+
: currentConfig?.interval !== undefined
174+
? currentConfig?.interval
175+
: defaultObservableInterval,
160176
},
161177
]);
162178

@@ -175,19 +191,19 @@ export async function getConfigFromWizard({
175191
type: "input",
176192
name: "profile",
177193
message: "Would you like to use named AWS profile?",
178-
default: currentConfig?.profile,
194+
default: configFromCliArgs.profile ?? currentConfig?.profile,
179195
},
180196
{
181197
type: "input",
182198
name: "region",
183199
message: "Would you like to specify AWS region?",
184-
default: currentConfig?.region,
200+
default: configFromCliArgs.region ?? currentConfig?.region,
185201
},
186202
{
187203
type: "input",
188204
name: "role",
189205
message: "Would you like to specify AWS role?",
190-
default: currentConfig?.role,
206+
default: configFromCliArgs.role ?? currentConfig?.role,
191207
},
192208
]);
193209

@@ -229,7 +245,7 @@ export async function getConfigFromWizard({
229245
name: "function",
230246
message: "Pick Lambda to debug",
231247
choices: lambdasList.map((l) => l.functionName),
232-
default: currentConfig?.function,
248+
default: currentConfig?.function ?? lambdasList[0].functionName,
233249
},
234250
]);
235251

@@ -244,7 +260,7 @@ export async function getConfigFromWizard({
244260
type: "input",
245261
name: "name",
246262
message: "Enter Lambda name to filter. Use * as wildcard",
247-
default: currentConfig?.function,
263+
default: configFromCliArgs.function ?? currentConfig?.function,
248264
},
249265
]);
250266

@@ -301,7 +317,10 @@ export async function getConfigFromWizard({
301317
},
302318
]);
303319

304-
answers.verbose = answersVerbose.verbose;
320+
answers.verbose =
321+
configFromCliArgs.verbose !== undefined
322+
? configFromCliArgs.verbose
323+
: answersVerbose.verbose;
305324
}
306325

307326
/*

src/nodeEsBuild.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ async function getBuild(functionId: string) {
7979
throw new Error(`Artifact file not found for function ${functionId}`);
8080
}
8181

82-
return artifactFile;
82+
return path.join(getProjectDirname(), artifactFile);
8383
} catch (error: any) {
8484
throw new Error(`Error building function ${functionId}: ${error.message}`, {
8585
cause: error,

src/nodeWorker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ type WorkerRequest = {
8484
*/
8585
function startWorker(input: WorkerRequest) {
8686
Logger.verbose(
87-
`[Function ${input.functionId}] [Worker ${input.workerId}] Starting worker`
87+
`[Function ${input.functionId}] [Worker ${input.workerId}] Starting worker. Artifact: ${input.artifactFile}`
8888
);
8989

9090
let localProjectDir = getProjectDirname();

src/nodeWorkerRunner.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Logger } from "./logger.mjs";
66

77
Logger.setVerbose(workerData.verbose);
88
Logger.verbose(
9-
`[Function ${workerData.functionId}] [Worker ${workerData.workerId}] Worker started. File: ${workerData.artifactFile}, Handler: ${workerData.handler}`
9+
`[Function ${workerData.functionId}] [Worker ${workerData.workerId}] Worker started.`
1010
);
1111

1212
parentPort.on("message", async (data) => {

0 commit comments

Comments
 (0)