Skip to content

Commit 9da4813

Browse files
Merge pull request #90 from contentstack/cl-2273
fix: use runtime cwd for data-dir flag
2 parents 1a254d5 + 5da501a commit 9da4813

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/commands/launch/functions.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ describe('Functions Command', () => {
4040
});
4141
});
4242

43+
it('should fall back to process.cwd() when data-dir flag is not provided', async () => {
44+
Functions.prototype['parse'] = jest
45+
.fn()
46+
.mockResolvedValueOnce({ flags: { 'data-dir': undefined, port: '3000' } });
47+
const functionsCommand = new Functions([], {} as any);
48+
49+
await functionsCommand.init();
50+
51+
expect(Functions.prototype['parse']).toHaveBeenCalledWith(Functions);
52+
expect(functionsCommand['sharedConfig']).toEqual({
53+
projectBasePath: process.cwd(),
54+
port: 3000,
55+
});
56+
});
57+
4358
it.each([{ portFlagInput: 'invalidPortInput' }, { portFlagInput: '999999' }, { portFlagInput: '-200' }])(
4459
'should log an error and exit if the "port" flag input is invalid -> $portFlagInput',
4560
async ({ portFlagInput }) => {

src/commands/launch/functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export default class Functions extends Command {
2222
}),
2323
'data-dir': Flags.string({
2424
char: 'd',
25-
default: process.cwd(),
2625
description: 'Current working directory',
2726
}),
2827
};
@@ -34,7 +33,8 @@ export default class Functions extends Command {
3433

3534
async init(): Promise<void> {
3635
const { flags } = await this.parse(Functions);
37-
const projectBasePath = flags['data-dir'];
36+
const currentWorkingDirectory = process.cwd();
37+
const projectBasePath = flags['data-dir'] || currentWorkingDirectory;
3838

3939
const logger = new Logger({ projectBasePath });
4040
this.log = logger.log.bind(logger);

0 commit comments

Comments
 (0)