Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 39 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,56 @@ class ServerlessStepFunctionsLocal {
}

async getStepFunctionsFromConfig() {
const {servicePath} = this.serverless.config;
const fromYamlFile = (serverlessYmlPath) =>
this.serverless.yamlParser.parse(serverlessYmlPath);

if (!servicePath) {
throw new Error('service path not found');
}
let parsed = {};
let parser = null;

const configPath = path.join(servicePath, 'serverless.yml');
if (!this.serverless.service.stepFunctions) {
const { servicePath } = this.serverless.config;

const parsed = await this.serverless.yamlParser.parse(configPath);
if (!servicePath) {
throw new Error('service path not found');
}
const serviceFileName =
this.options.config ||
this.serverless.config.serverless.service.serviceFilename ||
'serverless.yml';
const configPath = path.join(servicePath, serviceFileName);
if (['.js', '.json', '.ts'].includes(path.extname(configPath))) {
parser = this.loadFromRequiredFile;
} else {
parser = fromYamlFile;
}
parsed = await parser(configPath);
} else {
parsed = this.serverless.service;
}

this.stateMachines = parsed.stepFunctions.stateMachines;

if (parsed.custom &&
parsed.custom.stepFunctionsLocal &&
parsed.custom.stepFunctionsLocal.TaskResourceMapping) {
this.replaceTaskResourceMappings(parsed.stepFunctions.stateMachines, parsed.custom.stepFunctionsLocal.TaskResourceMapping);
parsed.custom.stepFunctionsLocal.TaskResourceMapping
) {
this.replaceTaskResourceMappings(
parsed.stepFunctions.stateMachines,
parsed.custom.stepFunctionsLocal.TaskResourceMapping
);
}
}

// This function must be ignored since mocking the require system is more
// dangerous than beneficial
loadFromRequiredFile(serverlessYmlPath) {
/* istanbul ignore next */
// eslint-disable-next-line global-require, import/no-dynamic-require
const fileContents = require(serverlessYmlPath);
/* istanbul ignore next */
return Promise.resolve(fileContents);
}

/**
* Replaces Resource properties with values mapped in TaskResourceMapping
*/
Expand Down