@expo/steps 1.0.88 → 1.0.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist_commonjs/BuildConfig.cjs +1 -1
- package/dist_commonjs/BuildConfig.js.map +1 -1
- package/dist_commonjs/BuildStep.cjs +27 -17
- package/dist_commonjs/BuildStep.d.ts +1 -1
- package/dist_commonjs/BuildStep.js.map +1 -1
- package/dist_commonjs/utils/jsepEval.cjs +159 -0
- package/dist_commonjs/utils/jsepEval.d.ts +1 -0
- package/dist_commonjs/utils/jsepEval.js.map +1 -0
- package/dist_commonjs/utils/template.cjs +1 -16
- package/dist_commonjs/utils/template.d.ts +0 -6
- package/dist_commonjs/utils/template.js.map +1 -1
- package/dist_esm/BuildConfig.js +2 -2
- package/dist_esm/BuildConfig.js.map +1 -1
- package/dist_esm/BuildStep.d.ts +1 -1
- package/dist_esm/BuildStep.js +28 -18
- package/dist_esm/BuildStep.js.map +1 -1
- package/dist_esm/utils/jsepEval.d.ts +1 -0
- package/dist_esm/utils/jsepEval.js +152 -0
- package/dist_esm/utils/jsepEval.js.map +1 -0
- package/dist_esm/utils/template.d.ts +0 -6
- package/dist_esm/utils/template.js +0 -14
- package/dist_esm/utils/template.js.map +1 -1
- package/package.json +3 -2
|
@@ -2,16 +2,10 @@ export declare const BUILD_STEP_INPUT_EXPRESSION_REGEXP: RegExp;
|
|
|
2
2
|
export declare const BUILD_STEP_OUTPUT_EXPRESSION_REGEXP: RegExp;
|
|
3
3
|
export declare const BUILD_GLOBAL_CONTEXT_EXPRESSION_REGEXP: RegExp;
|
|
4
4
|
export declare const BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX: RegExp;
|
|
5
|
-
export declare const BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP: RegExp;
|
|
6
5
|
export declare function interpolateWithInputs(templateString: string, inputs: Record<string, string>): string;
|
|
7
6
|
export declare function interpolateWithOutputs<InterpolableType extends string | object>(interpolableValue: InterpolableType, fn: (path: string) => string): InterpolableType;
|
|
8
7
|
export declare function interpolateStringWithOutputs(templateString: string, fn: (path: string) => string): string;
|
|
9
8
|
export declare function interpolateObjectWithOutputs(interpolableObject: object, fn: (path: string) => string): object;
|
|
10
|
-
/**
|
|
11
|
-
* Returns the selected status check from the if statement template.
|
|
12
|
-
* Example: `${ success() }` -> `success`
|
|
13
|
-
*/
|
|
14
|
-
export declare function getSelectedStatusCheckFromIfStatementTemplate(ifCondition: string): 'success' | 'failure' | 'always' | 'never';
|
|
15
9
|
export declare function getObjectValueForInterpolation(path: string, obj: Record<string, unknown>): string | number | boolean | null;
|
|
16
10
|
export declare function interpolateWithGlobalContext<InterpolableType extends string | object>(interpolableValue: InterpolableType, fn: (path: string) => string): InterpolableType;
|
|
17
11
|
export declare function interpolateStringWithGlobalContext(templateString: string, fn: (path: string) => string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/utils/template.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA6B;AAC7B,wEAAyC;AAEzC,4DAAmE;AACnE,4CAAuE;AAEvE,mDAA6C;AAEhC,QAAA,kCAAkC,GAAG,2BAA2B,CAAC;AACjE,QAAA,mCAAmC,GAAG,0BAA0B,CAAC;AACjE,QAAA,sCAAsC,GAAG,wBAAwB,CAAC;AAClE,QAAA,kDAAkD,GAAG,gCAAgC,CAAC;AACtF,QAAA,yCAAyC,GACpD,8CAA8C,CAAC;AAEjD,SAAgB,qBAAqB,CACnC,cAAsB,EACtB,MAA8B;IAE9B,OAAO,WAAW,CAAC,cAAc,EAAE,0CAAkC,EAAE,MAAM,CAAC,CAAC;AACjF,CAAC;AALD,sDAKC;AAED,SAAgB,sBAAsB,CACpC,iBAAmC,EACnC,EAA4B;IAE5B,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE,CAAC;QAC1C,OAAO,4BAA4B,CAAC,iBAAiB,EAAE,EAAE,CAAqB,CA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AAQ;QACzB,OAAO,KAAK,KAAK,SAAS;QAC1B,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI,CACf,CAAC;AACJ,CAAC;AAOD,SAAgB,eAAe,CAAC,cAAsB;IACpD,MAAM,MAAM,GAAsB,EAAE,CAAC;IACrC,MAAM,OAAO,GAAG,cAAc,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,2CAAmC,EAAE,GAAG,CAAC,CAAC,CAAC;IAC9F,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAPD,0CAOC;AAED,SAAgB,eAAe,CAAC,wBAAgC;IAC9D,MAAM,MAAM,GAAG,wBAAwB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC5D,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,4BAAgB,CACxB,gKAAgK,wBAAwB,GAAG,CAC5L,CAAC;IACJ,CAAC;IACD,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,MAAM,CAAC;IAClC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AAC9B,CAAC;AATD,0CASC","sourcesContent":["import get from 'lodash.get';\nimport cloneDeep from 'lodash.clonedeep';\n\nimport { BuildStepInputValueTypeName } from '../BuildStepInput.js';\nimport { BuildConfigError, BuildStepRuntimeError } from '../errors.js';\n\nimport { nullthrows } from './nullthrows.js';\n\nexport const BUILD_STEP_INPUT_EXPRESSION_REGEXP = /\\${\\s*(inputs\\.[\\S]+)\\s*}/;\nexport const BUILD_STEP_OUTPUT_EXPRESSION_REGEXP = /\\${\\s*(steps\\.[\\S]+)\\s*}/;\nexport const BUILD_GLOBAL_CONTEXT_EXPRESSION_REGEXP = /\\${\\s*(eas\\.[\\S]+)\\s*}/;\nexport const BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX = /\\${\\s*((steps|eas)\\.[\\S]+)\\s*}/;\nexport const BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP =\n /\\${\\s*(always|success|failure|never)\\(\\)\\s*}/;\n\nexport function interpolateWithInputs(\n templateString: string,\n inputs: Record<string, string>\n): string {\n return interpolate(templateString, BUILD_STEP_INPUT_EXPRESSION_REGEXP, inputs);\n}\n\nexport function interpolateWithOutputs<InterpolableType extends string | object>(\n interpolableValue: InterpolableType,\n fn: (path: string) => string\n): InterpolableType {\n if (typeof interpolableValue === 'string') {\n return interpolateStringWithOutputs(interpolableValue, fn) as InterpolableType;\n } else {\n return interpolateObjectWithOutputs(interpolableValue, fn) as InterpolableType;\n }\n}\n\nexport function interpolateStringWithOutputs(\n templateString: string,\n fn: (path: string) => string\n): string {\n return interpolate(templateString, BUILD_STEP_OUTPUT_EXPRESSION_REGEXP, fn);\n}\n\nexport function interpolateObjectWithOutputs(\n interpolableObject: object,\n fn: (path: string) => string\n): object {\n const interpolableObjectCopy = cloneDeep(interpolableObject);\n Object.keys(interpolableObject).forEach((property) => {\n const propertyValue = interpolableObject[property as keyof typeof interpolableObject];\n if (['string', 'object'].includes(typeof propertyValue)) {\n interpolableObjectCopy[property as keyof typeof interpolableObjectCopy] =\n interpolateWithOutputs(propertyValue, fn);\n }\n });\n return interpolableObjectCopy;\n}\n\n/**\n * Returns the selected status check from the if statement template.\n * Example: `${ success() }` -> `success`\n */\nexport function getSelectedStatusCheckFromIfStatementTemplate(\n ifCondition: string\n): 'success' | 'failure' | 'always' | 'never' {\n const matched = ifCondition.match(new RegExp(BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP, 'g'));\n if (!matched) {\n // this should never happen because of regex pattern validation\n throw new BuildConfigError(`Invalid if condition template.`);\n }\n const [, selectedStatusCheck] = nullthrows(\n matched[0].match(BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP)\n );\n return selectedStatusCheck as 'success' | 'failure' | 'always' | 'never';\n}\n\nexport function getObjectValueForInterpolation(\n path: string,\n obj: Record<string, unknown>\n): string | number | boolean | null {\n const value = get(obj, path);\n\n if (value === undefined) {\n throw new BuildStepRuntimeError(\n `Object field \"${path}\" does not exist. Ensure you are using the correct field name.`\n );\n }\n\n if (!isAllowedValueTypeForObjectInterpolation(value)) {\n throw new BuildStepRuntimeError(\n `EAS context field \"${path}\" is not of type ${Object.values(BuildStepInputValueTypeName).join(\n ', '\n )}, or undefined. It is of type \"${typeof value}\". We currently only support accessing string or undefined values from the EAS context.`\n );\n }\n\n if (value !== null && typeof value === 'object') {\n return JSON.stringify(value);\n }\n\n return value;\n}\n\nexport function interpolateWithGlobalContext<InterpolableType extends string | object>(\n interpolableValue: InterpolableType,\n fn: (path: string) => string\n): InterpolableType {\n if (typeof interpolableValue === 'string') {\n return interpolateStringWithGlobalContext(interpolableValue, fn) as InterpolableType;\n } else {\n return interpolateObjectWithGlobalContext(interpolableValue, fn) as InterpolableType;\n }\n}\n\nexport function interpolateStringWithGlobalContext(\n templateString: string,\n fn: (path: string) => string\n): string {\n return interpolate(templateString, BUILD_GLOBAL_CONTEXT_EXPRESSION_REGEXP, fn);\n}\n\nexport function interpolateObjectWithGlobalContext(\n templateObject: object,\n fn: (path: string) => string\n): object {\n const templateObjectCopy = cloneDeep(templateObject);\n Object.keys(templateObject).forEach((property) => {\n const propertyValue = templateObject[property as keyof typeof templateObject];\n if (['string', 'object'].includes(typeof propertyValue)) {\n templateObjectCopy[property as keyof typeof templateObjectCopy] =\n interpolateWithGlobalContext(propertyValue, fn);\n }\n });\n return templateObjectCopy;\n}\n\nfunction interpolate(\n templateString: string,\n regex: RegExp,\n varsOrFn: Record<string, string> | ((key: string) => string)\n): string {\n const matched = templateString.match(new RegExp(regex, 'g'));\n if (!matched) {\n return templateString;\n }\n let result = templateString;\n for (const match of matched) {\n const [, path] = nullthrows(match.match(regex));\n const value = typeof varsOrFn === 'function' ? varsOrFn(path) : varsOrFn[path.split('.')[1]];\n result = result.replace(match, value);\n }\n return result;\n}\n\nfunction isAllowedValueTypeForObjectInterpolation(\n value: unknown\n): value is string | number | boolean | object | null {\n return (\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean' ||\n typeof value === 'object' ||\n value === null\n );\n}\n\ninterface BuildOutputPath {\n stepId: string;\n outputId: string;\n}\n\nexport function findOutputPaths(templateString: string): BuildOutputPath[] {\n const result: BuildOutputPath[] = [];\n const matches = templateString.matchAll(new RegExp(BUILD_STEP_OUTPUT_EXPRESSION_REGEXP, 'g'));\n for (const match of matches) {\n result.push(parseOutputPath(match[1]));\n }\n return result;\n}\n\nexport function parseOutputPath(outputPathWithObjectName: string): BuildOutputPath {\n const splits = outputPathWithObjectName.split('.').slice(1);\n if (splits.length !== 2) {\n throw new BuildConfigError(\n `Step output path must consist of two components joined with a dot, where first is the step ID, and second is the output name, e.g. \"step3.output1\". Passed: \"${outputPathWithObjectName}\"`\n );\n }\n const [stepId, outputId] = splits;\n return { stepId, outputId };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/utils/template.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA6B;AAC7B,wEAAyC;AAEzC,4DAAmE;AACnE,4CAAuE;AAEvE,mDAA6C;AAEhC,QAAA,kCAAkC,GAAG,2BAA2B,CAAC;AACjE,QAAA,mCAAmC,GAAG,0BAA0B,CAAC;AACjE,QAAA,sCAAsC,GAAG,wBAAwB,CAAC;AAClE,QAAA,kDAAkD,GAAG,gCAAgC,CAAC;AAEnG,SAAgB,qBAAqB,CACnC,cAAsB,EACtB,MAA8B;IAE9B,OAAO,WAAW,CAAC,cAAc,EAAE,0CAAkC,EAAE,MAAM,CAAC,CAAC;AACjF,CAAC;AALD,sDAKC;AAED,SAAgB,sBAAsB,CACpC,iBAAmC,EACnC,EAA4B;IAE5B,IAAI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C,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAPD,0CAOC;AAED,SAAgB,eAAe,CAAC,wBAAgC;IAC9D,MAAM,MAAM,GAAG,wBAAwB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC5D,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,4BAAgB,CACxB,gKAAgK,wBAAwB,GAAG,CAC5L,CAAC;IACJ,CAAC;IACD,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,MAAM,CAAC;IAClC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AAC9B,CAAC;AATD,0CASC","sourcesContent":["import get from 'lodash.get';\nimport cloneDeep from 'lodash.clonedeep';\n\nimport { BuildStepInputValueTypeName } from '../BuildStepInput.js';\nimport { BuildConfigError, BuildStepRuntimeError } from '../errors.js';\n\nimport { nullthrows } from './nullthrows.js';\n\nexport const BUILD_STEP_INPUT_EXPRESSION_REGEXP = /\\${\\s*(inputs\\.[\\S]+)\\s*}/;\nexport const BUILD_STEP_OUTPUT_EXPRESSION_REGEXP = /\\${\\s*(steps\\.[\\S]+)\\s*}/;\nexport const BUILD_GLOBAL_CONTEXT_EXPRESSION_REGEXP = /\\${\\s*(eas\\.[\\S]+)\\s*}/;\nexport const BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX = /\\${\\s*((steps|eas)\\.[\\S]+)\\s*}/;\n\nexport function interpolateWithInputs(\n templateString: string,\n inputs: Record<string, string>\n): string {\n return interpolate(templateString, BUILD_STEP_INPUT_EXPRESSION_REGEXP, inputs);\n}\n\nexport function interpolateWithOutputs<InterpolableType extends string | object>(\n interpolableValue: InterpolableType,\n fn: (path: string) => string\n): InterpolableType {\n if (typeof interpolableValue === 'string') {\n return interpolateStringWithOutputs(interpolableValue, fn) as InterpolableType;\n } else {\n return interpolateObjectWithOutputs(interpolableValue, fn) as InterpolableType;\n }\n}\n\nexport function interpolateStringWithOutputs(\n templateString: string,\n fn: (path: string) => string\n): string {\n return interpolate(templateString, BUILD_STEP_OUTPUT_EXPRESSION_REGEXP, fn);\n}\n\nexport function interpolateObjectWithOutputs(\n interpolableObject: object,\n fn: (path: string) => string\n): object {\n const interpolableObjectCopy = cloneDeep(interpolableObject);\n Object.keys(interpolableObject).forEach((property) => {\n const propertyValue = interpolableObject[property as keyof typeof interpolableObject];\n if (['string', 'object'].includes(typeof propertyValue)) {\n interpolableObjectCopy[property as keyof typeof interpolableObjectCopy] =\n interpolateWithOutputs(propertyValue, fn);\n }\n });\n return interpolableObjectCopy;\n}\n\nexport function getObjectValueForInterpolation(\n path: string,\n obj: Record<string, unknown>\n): string | number | boolean | null {\n const value = get(obj, path);\n\n if (value === undefined) {\n throw new BuildStepRuntimeError(\n `Object field \"${path}\" does not exist. Ensure you are using the correct field name.`\n );\n }\n\n if (!isAllowedValueTypeForObjectInterpolation(value)) {\n throw new BuildStepRuntimeError(\n `EAS context field \"${path}\" is not of type ${Object.values(BuildStepInputValueTypeName).join(\n ', '\n )}, or undefined. It is of type \"${typeof value}\". We currently only support accessing string or undefined values from the EAS context.`\n );\n }\n\n if (value !== null && typeof value === 'object') {\n return JSON.stringify(value);\n }\n\n return value;\n}\n\nexport function interpolateWithGlobalContext<InterpolableType extends string | object>(\n interpolableValue: InterpolableType,\n fn: (path: string) => string\n): InterpolableType {\n if (typeof interpolableValue === 'string') {\n return interpolateStringWithGlobalContext(interpolableValue, fn) as InterpolableType;\n } else {\n return interpolateObjectWithGlobalContext(interpolableValue, fn) as InterpolableType;\n }\n}\n\nexport function interpolateStringWithGlobalContext(\n templateString: string,\n fn: (path: string) => string\n): string {\n return interpolate(templateString, BUILD_GLOBAL_CONTEXT_EXPRESSION_REGEXP, fn);\n}\n\nexport function interpolateObjectWithGlobalContext(\n templateObject: object,\n fn: (path: string) => string\n): object {\n const templateObjectCopy = cloneDeep(templateObject);\n Object.keys(templateObject).forEach((property) => {\n const propertyValue = templateObject[property as keyof typeof templateObject];\n if (['string', 'object'].includes(typeof propertyValue)) {\n templateObjectCopy[property as keyof typeof templateObjectCopy] =\n interpolateWithGlobalContext(propertyValue, fn);\n }\n });\n return templateObjectCopy;\n}\n\nfunction interpolate(\n templateString: string,\n regex: RegExp,\n varsOrFn: Record<string, string> | ((key: string) => string)\n): string {\n const matched = templateString.match(new RegExp(regex, 'g'));\n if (!matched) {\n return templateString;\n }\n let result = templateString;\n for (const match of matched) {\n const [, path] = nullthrows(match.match(regex));\n const value = typeof varsOrFn === 'function' ? varsOrFn(path) : varsOrFn[path.split('.')[1]];\n result = result.replace(match, value);\n }\n return result;\n}\n\nfunction isAllowedValueTypeForObjectInterpolation(\n value: unknown\n): value is string | number | boolean | object | null {\n return (\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean' ||\n typeof value === 'object' ||\n value === null\n );\n}\n\ninterface BuildOutputPath {\n stepId: string;\n outputId: string;\n}\n\nexport function findOutputPaths(templateString: string): BuildOutputPath[] {\n const result: BuildOutputPath[] = [];\n const matches = templateString.matchAll(new RegExp(BUILD_STEP_OUTPUT_EXPRESSION_REGEXP, 'g'));\n for (const match of matches) {\n result.push(parseOutputPath(match[1]));\n }\n return result;\n}\n\nexport function parseOutputPath(outputPathWithObjectName: string): BuildOutputPath {\n const splits = outputPathWithObjectName.split('.').slice(1);\n if (splits.length !== 2) {\n throw new BuildConfigError(\n `Step output path must consist of two components joined with a dot, where first is the step ID, and second is the output name, e.g. \"step3.output1\". Passed: \"${outputPathWithObjectName}\"`\n );\n }\n const [stepId, outputId] = splits;\n return { stepId, outputId };\n}\n"]}
|
package/dist_esm/BuildConfig.js
CHANGED
|
@@ -6,7 +6,7 @@ import YAML from 'yaml';
|
|
|
6
6
|
import { BuildConfigError, BuildWorkflowError } from './errors.js';
|
|
7
7
|
import { BuildRuntimePlatform } from './BuildRuntimePlatform.js';
|
|
8
8
|
import { BuildStepInputValueTypeName, } from './BuildStepInput.js';
|
|
9
|
-
import {
|
|
9
|
+
import { BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX } from './utils/template.js';
|
|
10
10
|
const BuildFunctionInputsSchema = Joi.array().items(Joi.alternatives().conditional(Joi.ref('.'), {
|
|
11
11
|
is: Joi.string(),
|
|
12
12
|
then: Joi.string().required(),
|
|
@@ -77,7 +77,7 @@ const BuildFunctionCallSchema = Joi.object({
|
|
|
77
77
|
workingDirectory: Joi.string(),
|
|
78
78
|
shell: Joi.string(),
|
|
79
79
|
env: Joi.object().pattern(Joi.string(), Joi.string().allow('')),
|
|
80
|
-
if: Joi.string()
|
|
80
|
+
if: Joi.string(),
|
|
81
81
|
}).rename('working_directory', 'workingDirectory');
|
|
82
82
|
const BuildStepConfigSchema = Joi.any()
|
|
83
83
|
.invalid(null)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildConfig.js","sourceRoot":"","sources":["../src/BuildConfig.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAEL,2BAA2B,GAE5B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,yCAAyC,EACzC,kDAAkD,GACnD,MAAM,qBAAqB,CAAC;AA2E7B,MAAM,yBAAyB,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC,KAAK,CACjD,GAAG,CAAC,YAAY,EAAE,CAAC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AAM,oCAAoC,GAAG,8BAA8B,CAAC,MAAM,CAChF,CAAC,6BAA6B,EAAE,EAAE;;QAChC,IACE,kBAAkB,CAAC,6BAA6B,CAAC;YACjD,4CAA4C,EAC5C,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,CACL,CAAC,CAAC,6BAA6B,IAAI,CAAC,MAAA,MAAM,CAAC,SAAS,mCAAI,EAAE,CAAC,CAAC;YAC5D,CAAC,sBAAsB,CAAC,GAAG,CAAC,6BAA6B,CAAC;YAC1D,CAAC,4BAA4B,CAAC,GAAG,CAAC,6BAA6B,CAAC,CACjE,CAAC;IACJ,CAAC,CACF,CAAC;IACF,IAAI,oCAAoC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,gBAAgB,CACxB,mCAAmC,oCAAoC;aACpE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;aACpB,IAAI,CAAC,IAAI,CAAC,GAAG,CACjB,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,sCAAsC,CAAC,GAAW,EAAE,kBAA0B;IACrF,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACzC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAED,SAAS,kBAAkB,CAAC,MAAc;IACxC,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import assert from 'assert';\nimport fs from 'fs/promises';\nimport path from 'path';\n\nimport Joi from 'joi';\nimport YAML from 'yaml';\n\nimport { BuildConfigError, BuildWorkflowError } from './errors.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport {\n BuildStepInputValueTypeWithRequired,\n BuildStepInputValueTypeName,\n BuildStepInputValueType,\n} from './BuildStepInput.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\nimport {\n BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP,\n BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX,\n} from './utils/template.js';\n\nexport type BuildFunctions = Record<string, BuildFunctionConfig>;\n\ninterface BuildFunctionsConfigFile {\n configFilesToImport?: string[];\n functions?: BuildFunctions;\n}\n\nexport interface BuildConfig extends BuildFunctionsConfigFile {\n build: {\n name?: string;\n steps: BuildStepConfig[];\n };\n}\n\nexport type BuildStepConfig =\n | BuildStepCommandRun\n | BuildStepBareCommandRun\n | BuildStepFunctionCall\n | BuildStepBareFunctionOrFunctionGroupCall;\n\nexport type BuildStepCommandRun = {\n run: BuildFunctionCallConfig & {\n outputs?: BuildStepOutputs;\n command: string;\n };\n};\nexport type BuildStepBareCommandRun = { run: string };\nexport type BuildStepFunctionCall = {\n [functionId: string]: BuildFunctionCallConfig;\n};\nexport type BuildStepBareFunctionOrFunctionGroupCall = string;\n\nexport type BuildFunctionCallConfig = {\n id?: string;\n inputs?: BuildStepInputs;\n name?: string;\n workingDirectory?: string;\n shell?: string;\n env?: BuildStepEnv;\n if?: string;\n};\n\nexport type BuildStepInputs = Record<string, BuildStepInputValueTypeWithRequired>;\nexport type BuildStepOutputs = (\n | string\n | {\n name: string;\n required?: boolean;\n }\n)[];\n\nexport interface BuildFunctionConfig {\n inputs?: BuildFunctionInputs;\n outputs?: BuildFunctionOutputs;\n name?: string;\n supportedRuntimePlatforms?: BuildRuntimePlatform[];\n shell?: string;\n command?: string;\n path?: string;\n}\n\nexport type BuildFunctionInputs = (\n | string\n | {\n name: string;\n defaultValue?: BuildStepInputValueType;\n allowedValues?: BuildStepInputValueType[];\n required?: boolean;\n allowedValueType: BuildStepInputValueTypeName;\n }\n)[];\nexport type BuildFunctionOutputs = BuildStepOutputs;\n\nconst BuildFunctionInputsSchema = Joi.array().items(\n Joi.alternatives().conditional(Joi.ref('.'), {\n is: Joi.string(),\n then: Joi.string().required(),\n otherwise: Joi.object({\n name: Joi.string().required(),\n defaultValue: Joi.when('allowedValues', {\n is: Joi.exist(),\n then: Joi.valid(Joi.in('allowedValues')).messages({\n 'any.only': '{{#label}} must be one of allowed values',\n }),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.STRING,\n then: Joi.string().allow(''),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.BOOLEAN,\n then: Joi.alternatives(\n Joi.boolean(),\n Joi.string().pattern(\n BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX,\n 'context or output reference regex pattern'\n )\n ).messages({\n 'alternatives.types':\n '{{#label}} must be a boolean or reference to output or context value',\n }),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.NUMBER,\n then: Joi.alternatives(\n Joi.number(),\n Joi.string().pattern(\n BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX,\n 'context or output reference regex pattern'\n )\n ).messages({\n 'alternatives.types':\n '{{#label}} must be a number or reference to output or context value',\n }),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.JSON,\n then: Joi.alternatives(\n Joi.object(),\n Joi.string().pattern(\n BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX,\n 'context or output reference regex pattern'\n )\n ).messages({\n 'alternatives.types':\n '{{#label}} must be a object or reference to output or context value',\n }),\n }),\n allowedValues: Joi.when('allowedValueType', {\n is: BuildStepInputValueTypeName.STRING,\n then: Joi.array().items(Joi.string().allow('')),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.BOOLEAN,\n then: Joi.array().items(Joi.boolean()),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.NUMBER,\n then: Joi.array().items(Joi.number()),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.JSON,\n then: Joi.array().items(Joi.object()),\n }),\n allowedValueType: Joi.string()\n .valid(...Object.values(BuildStepInputValueTypeName))\n .default(BuildStepInputValueTypeName.STRING),\n required: Joi.boolean(),\n })\n .rename('allowed_values', 'allowedValues')\n .rename('default_value', 'defaultValue')\n .rename('type', 'allowedValueType')\n .required(),\n })\n);\n\nconst BuildStepOutputsSchema = Joi.array().items(\n Joi.alternatives().try(\n Joi.string().required(),\n Joi.object({\n name: Joi.string().required(),\n required: Joi.boolean(),\n }).required()\n )\n);\n\nconst BuildFunctionCallSchema = Joi.object({\n id: Joi.string(),\n inputs: Joi.object().pattern(\n Joi.string(),\n Joi.alternatives().try(Joi.string().allow(''), Joi.boolean(), Joi.number(), Joi.object())\n ),\n name: Joi.string(),\n workingDirectory: Joi.string(),\n shell: Joi.string(),\n env: Joi.object().pattern(Joi.string(), Joi.string().allow('')),\n if: Joi.string().pattern(\n BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP,\n 'allowed \"if\" condition values regex'\n ),\n}).rename('working_directory', 'workingDirectory');\n\nconst BuildStepConfigSchema = Joi.any<BuildStepConfig>()\n .invalid(null)\n .when(\n Joi.object().pattern(\n Joi.string().disallow('run').required(),\n Joi.object().unknown().required()\n ),\n {\n then: Joi.object().pattern(\n Joi.string().disallow('run').min(1).required(),\n BuildFunctionCallSchema.required(),\n { matches: Joi.array().length(1) }\n ),\n }\n )\n .when(Joi.object({ run: Joi.object().unknown().required() }), {\n then: Joi.object({\n run: BuildFunctionCallSchema.keys({\n outputs: BuildStepOutputsSchema,\n command: Joi.string().required(),\n }),\n }),\n })\n .when(Joi.object({ run: Joi.string().required() }), {\n then: Joi.object({\n run: Joi.string().min(1).required(),\n }),\n })\n .when(Joi.string(), {\n then: Joi.string().min(1),\n });\n\nconst BuildFunctionConfigSchema = Joi.object({\n name: Joi.string(),\n supportedRuntimePlatforms: Joi.array().items(...Object.values(BuildRuntimePlatform)),\n inputs: BuildFunctionInputsSchema,\n outputs: BuildStepOutputsSchema,\n command: Joi.string(),\n path: Joi.string(),\n shell: Joi.string(),\n})\n .rename('supported_platforms', 'supportedRuntimePlatforms')\n .xor('command', 'path')\n .nand('command', 'path');\n\nexport const BuildFunctionsConfigFileSchema = Joi.object<BuildFunctionsConfigFile>({\n configFilesToImport: Joi.array().items(Joi.string().pattern(/\\.y(a)?ml$/)),\n functions: Joi.object().pattern(\n Joi.string()\n .pattern(/^[\\w-]+$/, 'function names')\n .min(1)\n .required()\n .disallow('run'),\n BuildFunctionConfigSchema.required()\n ),\n})\n .rename('import', 'configFilesToImport')\n .required();\n\nexport const BuildConfigSchema = BuildFunctionsConfigFileSchema.append<BuildConfig>({\n build: Joi.object({\n name: Joi.string(),\n steps: Joi.array().items(BuildStepConfigSchema.required()).required(),\n }).required(),\n}).required();\n\ninterface BuildConfigValidationParams {\n externalFunctionIds?: string[];\n externalFunctionGroupsIds?: string[];\n skipNamespacedFunctionsOrFunctionGroupsCheck?: boolean;\n}\n\nexport async function readAndValidateBuildConfigAsync(\n configPath: string,\n params: BuildConfigValidationParams = {}\n): Promise<BuildConfig> {\n const rawConfig = await readRawBuildConfigAsync(configPath);\n\n const config = validateConfig(BuildConfigSchema, rawConfig);\n for (const functionName in config.functions) {\n const customFunctionPath = config.functions[functionName].path;\n if (customFunctionPath) {\n config.functions[functionName].path = maybeResolveCustomFunctionRelativePath(\n path.dirname(configPath),\n customFunctionPath\n );\n }\n }\n\n const importedFunctions = await importFunctionsAsync(configPath, config.configFilesToImport);\n mergeConfigWithImportedFunctions(config, importedFunctions);\n validateAllFunctionsExist(config, params);\n return config;\n}\n\nasync function importFunctionsAsync(\n baseConfigPath: string,\n configPathsToImport?: string[]\n): Promise<BuildFunctions> {\n if (!configPathsToImport) {\n return {};\n }\n\n const baseConfigDir = path.dirname(baseConfigPath);\n\n const errors: BuildConfigError[] = [];\n const importedFunctions: BuildFunctions = {};\n // this is a set of visited files identified by ABSOLUTE paths\n const visitedFiles = new Set<string>([baseConfigPath]);\n const configFilesToVisit = (configPathsToImport ?? []).map((childConfigRelativePath) =>\n path.resolve(baseConfigDir, childConfigRelativePath)\n );\n while (configFilesToVisit.length > 0) {\n const childConfigPath = configFilesToVisit.shift();\n assert(childConfigPath, 'Guaranteed by loop condition');\n if (visitedFiles.has(childConfigPath)) {\n continue;\n }\n visitedFiles.add(childConfigPath);\n try {\n const childConfig = await readAndValidateBuildFunctionsConfigFileAsync(childConfigPath);\n const childDir = path.dirname(childConfigPath);\n for (const functionName in childConfig.functions) {\n if (!(functionName in importedFunctions)) {\n const f = childConfig.functions[functionName];\n if (f.path) {\n f.path = maybeResolveCustomFunctionRelativePath(childDir, f.path);\n }\n importedFunctions[functionName] = f;\n }\n }\n if (childConfig.configFilesToImport) {\n configFilesToVisit.push(\n ...childConfig.configFilesToImport.map((relativePath) =>\n path.resolve(childDir, relativePath)\n )\n );\n }\n } catch (err) {\n if (err instanceof BuildConfigError) {\n errors.push(err);\n } else {\n throw err;\n }\n }\n }\n if (errors.length > 0) {\n throw new BuildWorkflowError(`Detected build config errors in imported files.`, errors);\n }\n return importedFunctions;\n}\n\nexport async function readAndValidateBuildFunctionsConfigFileAsync(\n configPath: string\n): Promise<BuildFunctionsConfigFile> {\n const rawConfig = await readRawBuildConfigAsync(configPath);\n return validateConfig(BuildFunctionsConfigFileSchema, rawConfig);\n}\n\nexport async function readRawBuildConfigAsync(configPath: string): Promise<any> {\n const contents = await fs.readFile(configPath, 'utf-8');\n return YAML.parse(contents);\n}\n\nexport function validateConfig<T>(\n schema: Joi.ObjectSchema<T>,\n config: object,\n configFilePath?: string\n): T {\n const { error, value } = schema.validate(config, {\n allowUnknown: false,\n abortEarly: false,\n });\n if (error) {\n const errorMessage = error.details.map(({ message }) => message).join(', ');\n throw new BuildConfigError(errorMessage, {\n cause: error,\n ...(configFilePath && { metadata: { configFilePath } }),\n });\n }\n return value;\n}\n\nexport function mergeConfigWithImportedFunctions(\n config: BuildConfig,\n importedFunctions: BuildFunctions\n): void {\n if (Object.keys(importedFunctions).length === 0) {\n return;\n }\n config.functions = config.functions ?? {};\n for (const functionName in importedFunctions) {\n if (!(functionName in config.functions)) {\n config.functions[functionName] = importedFunctions[functionName];\n }\n }\n}\n\nexport function isBuildStepCommandRun(step: BuildStepConfig): step is BuildStepCommandRun {\n return Boolean(step) && typeof step === 'object' && typeof step.run === 'object';\n}\n\nexport function isBuildStepBareCommandRun(step: BuildStepConfig): step is BuildStepBareCommandRun {\n return Boolean(step) && typeof step === 'object' && typeof step.run === 'string';\n}\n\nexport function isBuildStepFunctionCall(step: BuildStepConfig): step is BuildStepFunctionCall {\n return Boolean(step) && typeof step === 'object' && !('run' in step);\n}\n\nexport function isBuildStepBareFunctionOrFunctionGroupCall(\n step: BuildStepConfig\n): step is BuildStepBareFunctionOrFunctionGroupCall {\n return typeof step === 'string';\n}\n\nexport function validateAllFunctionsExist(\n config: BuildConfig,\n {\n externalFunctionIds = [],\n externalFunctionGroupsIds = [],\n skipNamespacedFunctionsOrFunctionGroupsCheck,\n }: BuildConfigValidationParams\n): void {\n const calledFunctionsOrFunctionGroupsSet = new Set<string>();\n for (const step of config.build.steps) {\n if (typeof step === 'string') {\n calledFunctionsOrFunctionGroupsSet.add(step);\n } else if (step !== null && !('run' in step)) {\n const keys = Object.keys(step);\n assert(\n keys.length === 1,\n 'There must be at most one function call in the step (enforced by joi).'\n );\n calledFunctionsOrFunctionGroupsSet.add(keys[0]);\n }\n }\n const calledFunctionsOrFunctionGroup = Array.from(calledFunctionsOrFunctionGroupsSet);\n const externalFunctionIdsSet = new Set(externalFunctionIds);\n const externalFunctionGroupsIdsSet = new Set(externalFunctionGroupsIds);\n const nonExistentFunctionsOrFunctionGroups = calledFunctionsOrFunctionGroup.filter(\n (calledFunctionOrFunctionGroup) => {\n if (\n isFullIdNamespaced(calledFunctionOrFunctionGroup) &&\n skipNamespacedFunctionsOrFunctionGroupsCheck\n ) {\n return false;\n }\n return (\n !(calledFunctionOrFunctionGroup in (config.functions ?? {})) &&\n !externalFunctionIdsSet.has(calledFunctionOrFunctionGroup) &&\n !externalFunctionGroupsIdsSet.has(calledFunctionOrFunctionGroup)\n );\n }\n );\n if (nonExistentFunctionsOrFunctionGroups.length > 0) {\n throw new BuildConfigError(\n `Calling non-existent functions: ${nonExistentFunctionsOrFunctionGroups\n .map((f) => `\"${f}\"`)\n .join(', ')}.`\n );\n }\n}\n\nfunction maybeResolveCustomFunctionRelativePath(dir: string, customFunctionPath: string): string {\n if (!path.isAbsolute(customFunctionPath)) {\n return path.resolve(dir, customFunctionPath);\n }\n return customFunctionPath;\n}\n\nfunction isFullIdNamespaced(fullId: string): boolean {\n return fullId.includes('/');\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BuildConfig.js","sourceRoot":"","sources":["../src/BuildConfig.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAEL,2BAA2B,GAE5B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,kDAAkD,EAAE,MAAM,qBAAqB,CAAC;AA2EzF,MAAM,yBAAyB,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC,KAAK,CACjD,GAAG,CAAC,YAAY,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;IAC3C,EAAE,EAAE,GAAG,CAAC,MAAM,EAAE;IAChB,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC;QACpB,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QAC7B,YAAY,EAAE,GAAG,CAAC,IAAI,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CAAC,GAAG,CAAC,6BAA6B,CAAC,CACjE,CAAC;IACJ,CAAC,CACF,CAAC;IACF,IAAI,oCAAoC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,gBAAgB,CACxB,mCAAmC,oCAAoC;aACpE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;aACpB,IAAI,CAAC,IAAI,CAAC,GAAG,CACjB,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,sCAAsC,CAAC,GAAW,EAAE,kBAA0B;IACrF,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACzC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAED,SAAS,kBAAkB,CAAC,MAAc;IACxC,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import assert from 'assert';\nimport fs from 'fs/promises';\nimport path from 'path';\n\nimport Joi from 'joi';\nimport YAML from 'yaml';\n\nimport { BuildConfigError, BuildWorkflowError } from './errors.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport {\n BuildStepInputValueTypeWithRequired,\n BuildStepInputValueTypeName,\n BuildStepInputValueType,\n} from './BuildStepInput.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\nimport { BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX } from './utils/template.js';\n\nexport type BuildFunctions = Record<string, BuildFunctionConfig>;\n\ninterface BuildFunctionsConfigFile {\n configFilesToImport?: string[];\n functions?: BuildFunctions;\n}\n\nexport interface BuildConfig extends BuildFunctionsConfigFile {\n build: {\n name?: string;\n steps: BuildStepConfig[];\n };\n}\n\nexport type BuildStepConfig =\n | BuildStepCommandRun\n | BuildStepBareCommandRun\n | BuildStepFunctionCall\n | BuildStepBareFunctionOrFunctionGroupCall;\n\nexport type BuildStepCommandRun = {\n run: BuildFunctionCallConfig & {\n outputs?: BuildStepOutputs;\n command: string;\n };\n};\nexport type BuildStepBareCommandRun = { run: string };\nexport type BuildStepFunctionCall = {\n [functionId: string]: BuildFunctionCallConfig;\n};\nexport type BuildStepBareFunctionOrFunctionGroupCall = string;\n\nexport type BuildFunctionCallConfig = {\n id?: string;\n inputs?: BuildStepInputs;\n name?: string;\n workingDirectory?: string;\n shell?: string;\n env?: BuildStepEnv;\n if?: string;\n};\n\nexport type BuildStepInputs = Record<string, BuildStepInputValueTypeWithRequired>;\nexport type BuildStepOutputs = (\n | string\n | {\n name: string;\n required?: boolean;\n }\n)[];\n\nexport interface BuildFunctionConfig {\n inputs?: BuildFunctionInputs;\n outputs?: BuildFunctionOutputs;\n name?: string;\n supportedRuntimePlatforms?: BuildRuntimePlatform[];\n shell?: string;\n command?: string;\n path?: string;\n}\n\nexport type BuildFunctionInputs = (\n | string\n | {\n name: string;\n defaultValue?: BuildStepInputValueType;\n allowedValues?: BuildStepInputValueType[];\n required?: boolean;\n allowedValueType: BuildStepInputValueTypeName;\n }\n)[];\nexport type BuildFunctionOutputs = BuildStepOutputs;\n\nconst BuildFunctionInputsSchema = Joi.array().items(\n Joi.alternatives().conditional(Joi.ref('.'), {\n is: Joi.string(),\n then: Joi.string().required(),\n otherwise: Joi.object({\n name: Joi.string().required(),\n defaultValue: Joi.when('allowedValues', {\n is: Joi.exist(),\n then: Joi.valid(Joi.in('allowedValues')).messages({\n 'any.only': '{{#label}} must be one of allowed values',\n }),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.STRING,\n then: Joi.string().allow(''),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.BOOLEAN,\n then: Joi.alternatives(\n Joi.boolean(),\n Joi.string().pattern(\n BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX,\n 'context or output reference regex pattern'\n )\n ).messages({\n 'alternatives.types':\n '{{#label}} must be a boolean or reference to output or context value',\n }),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.NUMBER,\n then: Joi.alternatives(\n Joi.number(),\n Joi.string().pattern(\n BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX,\n 'context or output reference regex pattern'\n )\n ).messages({\n 'alternatives.types':\n '{{#label}} must be a number or reference to output or context value',\n }),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.JSON,\n then: Joi.alternatives(\n Joi.object(),\n Joi.string().pattern(\n BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX,\n 'context or output reference regex pattern'\n )\n ).messages({\n 'alternatives.types':\n '{{#label}} must be a object or reference to output or context value',\n }),\n }),\n allowedValues: Joi.when('allowedValueType', {\n is: BuildStepInputValueTypeName.STRING,\n then: Joi.array().items(Joi.string().allow('')),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.BOOLEAN,\n then: Joi.array().items(Joi.boolean()),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.NUMBER,\n then: Joi.array().items(Joi.number()),\n })\n .when('allowedValueType', {\n is: BuildStepInputValueTypeName.JSON,\n then: Joi.array().items(Joi.object()),\n }),\n allowedValueType: Joi.string()\n .valid(...Object.values(BuildStepInputValueTypeName))\n .default(BuildStepInputValueTypeName.STRING),\n required: Joi.boolean(),\n })\n .rename('allowed_values', 'allowedValues')\n .rename('default_value', 'defaultValue')\n .rename('type', 'allowedValueType')\n .required(),\n })\n);\n\nconst BuildStepOutputsSchema = Joi.array().items(\n Joi.alternatives().try(\n Joi.string().required(),\n Joi.object({\n name: Joi.string().required(),\n required: Joi.boolean(),\n }).required()\n )\n);\n\nconst BuildFunctionCallSchema = Joi.object({\n id: Joi.string(),\n inputs: Joi.object().pattern(\n Joi.string(),\n Joi.alternatives().try(Joi.string().allow(''), Joi.boolean(), Joi.number(), Joi.object())\n ),\n name: Joi.string(),\n workingDirectory: Joi.string(),\n shell: Joi.string(),\n env: Joi.object().pattern(Joi.string(), Joi.string().allow('')),\n if: Joi.string(),\n}).rename('working_directory', 'workingDirectory');\n\nconst BuildStepConfigSchema = Joi.any<BuildStepConfig>()\n .invalid(null)\n .when(\n Joi.object().pattern(\n Joi.string().disallow('run').required(),\n Joi.object().unknown().required()\n ),\n {\n then: Joi.object().pattern(\n Joi.string().disallow('run').min(1).required(),\n BuildFunctionCallSchema.required(),\n { matches: Joi.array().length(1) }\n ),\n }\n )\n .when(Joi.object({ run: Joi.object().unknown().required() }), {\n then: Joi.object({\n run: BuildFunctionCallSchema.keys({\n outputs: BuildStepOutputsSchema,\n command: Joi.string().required(),\n }),\n }),\n })\n .when(Joi.object({ run: Joi.string().required() }), {\n then: Joi.object({\n run: Joi.string().min(1).required(),\n }),\n })\n .when(Joi.string(), {\n then: Joi.string().min(1),\n });\n\nconst BuildFunctionConfigSchema = Joi.object({\n name: Joi.string(),\n supportedRuntimePlatforms: Joi.array().items(...Object.values(BuildRuntimePlatform)),\n inputs: BuildFunctionInputsSchema,\n outputs: BuildStepOutputsSchema,\n command: Joi.string(),\n path: Joi.string(),\n shell: Joi.string(),\n})\n .rename('supported_platforms', 'supportedRuntimePlatforms')\n .xor('command', 'path')\n .nand('command', 'path');\n\nexport const BuildFunctionsConfigFileSchema = Joi.object<BuildFunctionsConfigFile>({\n configFilesToImport: Joi.array().items(Joi.string().pattern(/\\.y(a)?ml$/)),\n functions: Joi.object().pattern(\n Joi.string()\n .pattern(/^[\\w-]+$/, 'function names')\n .min(1)\n .required()\n .disallow('run'),\n BuildFunctionConfigSchema.required()\n ),\n})\n .rename('import', 'configFilesToImport')\n .required();\n\nexport const BuildConfigSchema = BuildFunctionsConfigFileSchema.append<BuildConfig>({\n build: Joi.object({\n name: Joi.string(),\n steps: Joi.array().items(BuildStepConfigSchema.required()).required(),\n }).required(),\n}).required();\n\ninterface BuildConfigValidationParams {\n externalFunctionIds?: string[];\n externalFunctionGroupsIds?: string[];\n skipNamespacedFunctionsOrFunctionGroupsCheck?: boolean;\n}\n\nexport async function readAndValidateBuildConfigAsync(\n configPath: string,\n params: BuildConfigValidationParams = {}\n): Promise<BuildConfig> {\n const rawConfig = await readRawBuildConfigAsync(configPath);\n\n const config = validateConfig(BuildConfigSchema, rawConfig);\n for (const functionName in config.functions) {\n const customFunctionPath = config.functions[functionName].path;\n if (customFunctionPath) {\n config.functions[functionName].path = maybeResolveCustomFunctionRelativePath(\n path.dirname(configPath),\n customFunctionPath\n );\n }\n }\n\n const importedFunctions = await importFunctionsAsync(configPath, config.configFilesToImport);\n mergeConfigWithImportedFunctions(config, importedFunctions);\n validateAllFunctionsExist(config, params);\n return config;\n}\n\nasync function importFunctionsAsync(\n baseConfigPath: string,\n configPathsToImport?: string[]\n): Promise<BuildFunctions> {\n if (!configPathsToImport) {\n return {};\n }\n\n const baseConfigDir = path.dirname(baseConfigPath);\n\n const errors: BuildConfigError[] = [];\n const importedFunctions: BuildFunctions = {};\n // this is a set of visited files identified by ABSOLUTE paths\n const visitedFiles = new Set<string>([baseConfigPath]);\n const configFilesToVisit = (configPathsToImport ?? []).map((childConfigRelativePath) =>\n path.resolve(baseConfigDir, childConfigRelativePath)\n );\n while (configFilesToVisit.length > 0) {\n const childConfigPath = configFilesToVisit.shift();\n assert(childConfigPath, 'Guaranteed by loop condition');\n if (visitedFiles.has(childConfigPath)) {\n continue;\n }\n visitedFiles.add(childConfigPath);\n try {\n const childConfig = await readAndValidateBuildFunctionsConfigFileAsync(childConfigPath);\n const childDir = path.dirname(childConfigPath);\n for (const functionName in childConfig.functions) {\n if (!(functionName in importedFunctions)) {\n const f = childConfig.functions[functionName];\n if (f.path) {\n f.path = maybeResolveCustomFunctionRelativePath(childDir, f.path);\n }\n importedFunctions[functionName] = f;\n }\n }\n if (childConfig.configFilesToImport) {\n configFilesToVisit.push(\n ...childConfig.configFilesToImport.map((relativePath) =>\n path.resolve(childDir, relativePath)\n )\n );\n }\n } catch (err) {\n if (err instanceof BuildConfigError) {\n errors.push(err);\n } else {\n throw err;\n }\n }\n }\n if (errors.length > 0) {\n throw new BuildWorkflowError(`Detected build config errors in imported files.`, errors);\n }\n return importedFunctions;\n}\n\nexport async function readAndValidateBuildFunctionsConfigFileAsync(\n configPath: string\n): Promise<BuildFunctionsConfigFile> {\n const rawConfig = await readRawBuildConfigAsync(configPath);\n return validateConfig(BuildFunctionsConfigFileSchema, rawConfig);\n}\n\nexport async function readRawBuildConfigAsync(configPath: string): Promise<any> {\n const contents = await fs.readFile(configPath, 'utf-8');\n return YAML.parse(contents);\n}\n\nexport function validateConfig<T>(\n schema: Joi.ObjectSchema<T>,\n config: object,\n configFilePath?: string\n): T {\n const { error, value } = schema.validate(config, {\n allowUnknown: false,\n abortEarly: false,\n });\n if (error) {\n const errorMessage = error.details.map(({ message }) => message).join(', ');\n throw new BuildConfigError(errorMessage, {\n cause: error,\n ...(configFilePath && { metadata: { configFilePath } }),\n });\n }\n return value;\n}\n\nexport function mergeConfigWithImportedFunctions(\n config: BuildConfig,\n importedFunctions: BuildFunctions\n): void {\n if (Object.keys(importedFunctions).length === 0) {\n return;\n }\n config.functions = config.functions ?? {};\n for (const functionName in importedFunctions) {\n if (!(functionName in config.functions)) {\n config.functions[functionName] = importedFunctions[functionName];\n }\n }\n}\n\nexport function isBuildStepCommandRun(step: BuildStepConfig): step is BuildStepCommandRun {\n return Boolean(step) && typeof step === 'object' && typeof step.run === 'object';\n}\n\nexport function isBuildStepBareCommandRun(step: BuildStepConfig): step is BuildStepBareCommandRun {\n return Boolean(step) && typeof step === 'object' && typeof step.run === 'string';\n}\n\nexport function isBuildStepFunctionCall(step: BuildStepConfig): step is BuildStepFunctionCall {\n return Boolean(step) && typeof step === 'object' && !('run' in step);\n}\n\nexport function isBuildStepBareFunctionOrFunctionGroupCall(\n step: BuildStepConfig\n): step is BuildStepBareFunctionOrFunctionGroupCall {\n return typeof step === 'string';\n}\n\nexport function validateAllFunctionsExist(\n config: BuildConfig,\n {\n externalFunctionIds = [],\n externalFunctionGroupsIds = [],\n skipNamespacedFunctionsOrFunctionGroupsCheck,\n }: BuildConfigValidationParams\n): void {\n const calledFunctionsOrFunctionGroupsSet = new Set<string>();\n for (const step of config.build.steps) {\n if (typeof step === 'string') {\n calledFunctionsOrFunctionGroupsSet.add(step);\n } else if (step !== null && !('run' in step)) {\n const keys = Object.keys(step);\n assert(\n keys.length === 1,\n 'There must be at most one function call in the step (enforced by joi).'\n );\n calledFunctionsOrFunctionGroupsSet.add(keys[0]);\n }\n }\n const calledFunctionsOrFunctionGroup = Array.from(calledFunctionsOrFunctionGroupsSet);\n const externalFunctionIdsSet = new Set(externalFunctionIds);\n const externalFunctionGroupsIdsSet = new Set(externalFunctionGroupsIds);\n const nonExistentFunctionsOrFunctionGroups = calledFunctionsOrFunctionGroup.filter(\n (calledFunctionOrFunctionGroup) => {\n if (\n isFullIdNamespaced(calledFunctionOrFunctionGroup) &&\n skipNamespacedFunctionsOrFunctionGroupsCheck\n ) {\n return false;\n }\n return (\n !(calledFunctionOrFunctionGroup in (config.functions ?? {})) &&\n !externalFunctionIdsSet.has(calledFunctionOrFunctionGroup) &&\n !externalFunctionGroupsIdsSet.has(calledFunctionOrFunctionGroup)\n );\n }\n );\n if (nonExistentFunctionsOrFunctionGroups.length > 0) {\n throw new BuildConfigError(\n `Calling non-existent functions: ${nonExistentFunctionsOrFunctionGroups\n .map((f) => `\"${f}\"`)\n .join(', ')}.`\n );\n }\n}\n\nfunction maybeResolveCustomFunctionRelativePath(dir: string, customFunctionPath: string): string {\n if (!path.isAbsolute(customFunctionPath)) {\n return path.resolve(dir, customFunctionPath);\n }\n return customFunctionPath;\n}\n\nfunction isFullIdNamespaced(fullId: string): boolean {\n return fullId.includes('/');\n}\n"]}
|
package/dist_esm/BuildStep.d.ts
CHANGED
|
@@ -83,7 +83,7 @@ export declare class BuildStep extends BuildStepOutputAccessor {
|
|
|
83
83
|
skip(): void;
|
|
84
84
|
private executeCommandAsync;
|
|
85
85
|
private exectuteFnAsync;
|
|
86
|
-
private
|
|
86
|
+
private interpolateInputsAndGlobalContextInTemplate;
|
|
87
87
|
private collectAndValidateOutputsAsync;
|
|
88
88
|
private collectAndUpdateEnvsAsync;
|
|
89
89
|
private getScriptEnv;
|
package/dist_esm/BuildStep.js
CHANGED
|
@@ -8,8 +8,9 @@ import { BIN_PATH } from './utils/shell/bin.js';
|
|
|
8
8
|
import { getDefaultShell, getShellCommandAndArgs } from './utils/shell/command.js';
|
|
9
9
|
import { cleanUpStepTemporaryDirectoriesAsync, createTemporaryEnvsDirectoryAsync, createTemporaryOutputsDirectoryAsync, saveScriptToTemporaryFileAsync, } from './BuildTemporaryFiles.js';
|
|
10
10
|
import { spawnAsync } from './utils/shell/spawn.js';
|
|
11
|
-
import {
|
|
11
|
+
import { interpolateWithInputs } from './utils/template.js';
|
|
12
12
|
import { BuildStepRuntimeError } from './errors.js';
|
|
13
|
+
import { jsepEval } from './utils/jsepEval.js';
|
|
13
14
|
export var BuildStepStatus;
|
|
14
15
|
(function (BuildStepStatus) {
|
|
15
16
|
BuildStepStatus["NEW"] = "new";
|
|
@@ -152,20 +153,29 @@ export class BuildStep extends BuildStepOutputAccessor {
|
|
|
152
153
|
this.supportedRuntimePlatforms.includes(this.ctx.global.runtimePlatform));
|
|
153
154
|
}
|
|
154
155
|
shouldExecuteStep(hasAnyPreviousStepsFailed) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
: defaultStatusCheck;
|
|
159
|
-
switch (statusCheck) {
|
|
160
|
-
case 'success':
|
|
161
|
-
return !hasAnyPreviousStepsFailed;
|
|
162
|
-
case 'failure':
|
|
163
|
-
return hasAnyPreviousStepsFailed;
|
|
164
|
-
case 'always':
|
|
165
|
-
return true;
|
|
166
|
-
case 'never':
|
|
167
|
-
return false;
|
|
156
|
+
var _a, _b;
|
|
157
|
+
if (!this.ifCondition) {
|
|
158
|
+
return !hasAnyPreviousStepsFailed;
|
|
168
159
|
}
|
|
160
|
+
let ifCondition = this.ifCondition;
|
|
161
|
+
if (ifCondition.startsWith('${') && ifCondition.endsWith('}')) {
|
|
162
|
+
ifCondition = ifCondition.slice(2, -1);
|
|
163
|
+
}
|
|
164
|
+
return Boolean(jsepEval(ifCondition, {
|
|
165
|
+
success: () => !hasAnyPreviousStepsFailed,
|
|
166
|
+
failure: () => hasAnyPreviousStepsFailed,
|
|
167
|
+
always: () => true,
|
|
168
|
+
never: () => false,
|
|
169
|
+
env: this.env,
|
|
170
|
+
inputs: (_b = (_a = this.inputs) === null || _a === void 0 ? void 0 : _a.reduce((acc, input) => {
|
|
171
|
+
acc[input.id] = input.value;
|
|
172
|
+
return acc;
|
|
173
|
+
}, {})) !== null && _b !== void 0 ? _b : {},
|
|
174
|
+
eas: {
|
|
175
|
+
runtimePlatform: this.ctx.global.runtimePlatform,
|
|
176
|
+
...this.ctx.global.staticContext,
|
|
177
|
+
},
|
|
178
|
+
}));
|
|
169
179
|
}
|
|
170
180
|
skip() {
|
|
171
181
|
this.status = BuildStepStatus.SKIPPED;
|
|
@@ -176,7 +186,7 @@ export class BuildStep extends BuildStepOutputAccessor {
|
|
|
176
186
|
async executeCommandAsync() {
|
|
177
187
|
assert(this.command, 'Command must be defined.');
|
|
178
188
|
try {
|
|
179
|
-
const command = this.
|
|
189
|
+
const command = this.interpolateInputsAndGlobalContextInTemplate(this.command, this.inputs);
|
|
180
190
|
this.ctx.logger.debug(`Interpolated inputs in the command template`);
|
|
181
191
|
const outputsDir = await createTemporaryOutputsDirectoryAsync(this.ctx.global, this.id);
|
|
182
192
|
this.ctx.logger.debug(`Created temporary directory for step outputs: ${outputsDir}`);
|
|
@@ -223,9 +233,9 @@ export class BuildStep extends BuildStepOutputAccessor {
|
|
|
223
233
|
await cleanUpStepTemporaryDirectoriesAsync(this.ctx.global, this.id);
|
|
224
234
|
}
|
|
225
235
|
}
|
|
226
|
-
|
|
236
|
+
interpolateInputsAndGlobalContextInTemplate(template, inputs) {
|
|
227
237
|
if (!inputs) {
|
|
228
|
-
return this.ctx.global.interpolate(
|
|
238
|
+
return this.ctx.global.interpolate(template);
|
|
229
239
|
}
|
|
230
240
|
const vars = inputs.reduce((acc, input) => {
|
|
231
241
|
var _a, _b;
|
|
@@ -235,7 +245,7 @@ export class BuildStep extends BuildStepOutputAccessor {
|
|
|
235
245
|
: (_b = (_a = input.value) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '';
|
|
236
246
|
return acc;
|
|
237
247
|
}, {});
|
|
238
|
-
const valueInterpolatedWithGlobalContext = this.ctx.global.interpolate(
|
|
248
|
+
const valueInterpolatedWithGlobalContext = this.ctx.global.interpolate(template);
|
|
239
249
|
return interpolateWithInputs(valueInterpolatedWithGlobalContext, vars);
|
|
240
250
|
}
|
|
241
251
|
async collectAndValidateOutputsAsync(outputsDir) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildStep.js","sourceRoot":"","sources":["../src/BuildStep.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAGpC,OAAO,EAAsC,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACpG,OAAO,EACL,eAAe,EAGf,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EACL,oCAAoC,EACpC,iCAAiC,EACjC,oCAAoC,EACpC,8BAA8B,GAC/B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EACL,6CAA6C,EAC7C,qBAAq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,CAAC;SAC/B,CAAC,CAAC;IACL,CAAC;IAEO,YAAY,CAAC,EACnB,OAAO,EACP,UAAU,GAIX;;QACC,MAAM,GAAG,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACpD,MAAM,WAAW,GAAG,MAAA,GAAG,CAAC,IAAI,mCAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;QACjD,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,WAAW,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;QACtE,OAAO;YACL,GAAG,GAAG;YACN,wBAAwB,EAAE,UAAU;YACpC,qBAAqB,EAAE,OAAO;YAC9B,8BAA8B,EAAE,IAAI,CAAC,GAAG,CAAC,gBAAgB;YACzD,IAAI,EAAE,OAAO;SACd,CAAC;IACJ,CAAC;CACF","sourcesContent":["import assert from 'assert';\nimport fs from 'fs/promises';\nimport path from 'path';\n\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { BuildStepContext, BuildStepGlobalContext } from './BuildStepContext.js';\nimport { BuildStepInput, BuildStepInputById, makeBuildStepInputByIdMap } from './BuildStepInput.js';\nimport {\n BuildStepOutput,\n BuildStepOutputById,\n SerializedBuildStepOutput,\n makeBuildStepOutputByIdMap,\n} from './BuildStepOutput.js';\nimport { BIN_PATH } from './utils/shell/bin.js';\nimport { getDefaultShell, getShellCommandAndArgs } from './utils/shell/command.js';\nimport {\n cleanUpStepTemporaryDirectoriesAsync,\n createTemporaryEnvsDirectoryAsync,\n createTemporaryOutputsDirectoryAsync,\n saveScriptToTemporaryFileAsync,\n} from './BuildTemporaryFiles.js';\nimport { spawnAsync } from './utils/shell/spawn.js';\nimport {\n getSelectedStatusCheckFromIfStatementTemplate,\n interpolateWithInputs,\n} from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\n\nexport enum BuildStepStatus {\n NEW = 'new',\n IN_PROGRESS = 'in-progress',\n SKIPPED = 'skipped',\n FAIL = 'fail',\n WARNING = 'warning',\n SUCCESS = 'success',\n}\n\nexport enum BuildStepLogMarker {\n START_STEP = 'start-step',\n END_STEP = 'end-step',\n}\n\nexport type BuildStepFunction = (\n ctx: BuildStepContext,\n {\n inputs,\n outputs,\n env,\n }: { inputs: BuildStepInputById; outputs: BuildStepOutputById; env: BuildStepEnv }\n) => unknown;\n\n// TODO: move to a place common with tests\nconst UUID_REGEX =\n /^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$/;\n\nexport interface SerializedBuildStepOutputAccessor {\n id: string;\n executed: boolean;\n outputById: Record<string, SerializedBuildStepOutput>;\n displayName: string;\n}\n\nexport class BuildStepOutputAccessor {\n constructor(\n public readonly id: string,\n public readonly displayName: string,\n protected readonly executed: boolean,\n protected readonly outputById: BuildStepOutputById\n ) {}\n\n public getOutputValueByName(name: string): string | undefined {\n if (!this.executed) {\n throw new BuildStepRuntimeError(\n `Failed getting output \"${name}\" from step \"${this.displayName}\". The step has not been executed yet.`\n );\n }\n if (!this.hasOutputParameter(name)) {\n throw new BuildStepRuntimeError(`Step \"${this.displayName}\" does not have output \"${name}\".`);\n }\n return this.outputById[name].value;\n }\n\n public hasOutputParameter(name: string): boolean {\n return name in this.outputById;\n }\n\n public serialize(): SerializedBuildStepOutputAccessor {\n return {\n id: this.id,\n executed: this.executed,\n outputById: Object.fromEntries(\n Object.entries(this.outputById).map(([key, value]) => [key, value.serialize()])\n ),\n displayName: this.displayName,\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepOutputAccessor\n ): BuildStepOutputAccessor {\n const outputById = Object.fromEntries(\n Object.entries(serialized.outputById).map(([key, value]) => [\n key,\n BuildStepOutput.deserialize(value),\n ])\n );\n return new BuildStepOutputAccessor(\n serialized.id,\n serialized.displayName,\n serialized.executed,\n outputById\n );\n }\n}\n\nexport class BuildStep extends BuildStepOutputAccessor {\n public readonly id: string;\n public readonly name?: string;\n public readonly displayName: string;\n public readonly supportedRuntimePlatforms?: BuildRuntimePlatform[];\n public readonly inputs?: BuildStepInput[];\n public readonly outputs?: BuildStepOutput[];\n public readonly command?: string;\n public readonly fn?: BuildStepFunction;\n public readonly shell: string;\n public readonly ctx: BuildStepContext;\n public readonly env: BuildStepEnv;\n public readonly ifCondition?: string;\n public status: BuildStepStatus;\n\n private readonly internalId: string;\n private readonly inputById: BuildStepInputById;\n protected readonly outputById: BuildStepOutputById;\n protected executed = false;\n\n public static getNewId(userDefinedId?: string): string {\n return userDefinedId ?? uuidv4();\n }\n\n public static getDisplayName({\n id,\n name,\n command,\n }: {\n id: string;\n name?: string;\n command?: string;\n }): string {\n if (name) {\n return name;\n }\n if (!id.match(UUID_REGEX)) {\n return id;\n }\n if (command) {\n const splits = command.trim().split('\\n');\n for (const split of splits) {\n const trimmed = split.trim();\n if (trimmed && !trimmed.startsWith('#')) {\n return trimmed;\n }\n }\n }\n return id;\n }\n\n constructor(\n ctx: BuildStepGlobalContext,\n {\n id,\n name,\n displayName,\n inputs,\n outputs,\n command,\n fn,\n workingDirectory: maybeWorkingDirectory,\n shell,\n supportedRuntimePlatforms: maybeSupportedRuntimePlatforms,\n env,\n ifCondition,\n }: {\n id: string;\n name?: string;\n displayName: string;\n inputs?: BuildStepInput[];\n outputs?: BuildStepOutput[];\n command?: string;\n fn?: BuildStepFunction;\n workingDirectory?: string;\n shell?: string;\n supportedRuntimePlatforms?: BuildRuntimePlatform[];\n env?: BuildStepEnv;\n ifCondition?: string;\n }\n ) {\n assert(command !== undefined || fn !== undefined, 'Either command or fn must be defined.');\n assert(!(command !== undefined && fn !== undefined), 'Command and fn cannot be both set.');\n const outputById = makeBuildStepOutputByIdMap(outputs);\n super(id, displayName, false, outputById);\n\n this.id = id;\n this.name = name;\n this.displayName = displayName;\n this.supportedRuntimePlatforms = maybeSupportedRuntimePlatforms;\n this.inputs = inputs;\n this.outputs = outputs;\n this.inputById = makeBuildStepInputByIdMap(inputs);\n this.outputById = outputById;\n this.fn = fn;\n this.command = command;\n this.shell = shell ?? getDefaultShell();\n this.ifCondition = ifCondition;\n this.status = BuildStepStatus.NEW;\n\n this.internalId = uuidv4();\n\n const logger = ctx.baseLogger.child({\n buildStepInternalId: this.internalId,\n buildStepId: this.id,\n buildStepDisplayName: this.displayName,\n });\n this.ctx = ctx.stepCtx({ logger, relativeWorkingDirectory: maybeWorkingDirectory });\n this.env = env ?? {};\n\n ctx.registerStep(this);\n }\n\n public async executeAsync(): Promise<void> {\n try {\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.START_STEP },\n `Executing build step \"${this.displayName}\"`\n );\n this.status = BuildStepStatus.IN_PROGRESS;\n\n if (this.command !== undefined) {\n await this.executeCommandAsync();\n } else {\n await this.exectuteFnAsync();\n }\n\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.SUCCESS },\n `Finished build step \"${this.displayName}\" successfully`\n );\n this.status = BuildStepStatus.SUCCESS;\n } catch (err) {\n this.ctx.logger.error({ err });\n this.ctx.logger.error(\n { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.FAIL },\n `Build step \"${this.displayName}\" failed`\n );\n this.status = BuildStepStatus.FAIL;\n throw err;\n } finally {\n this.executed = true;\n }\n }\n\n public hasOutputParameter(name: string): boolean {\n return name in this.outputById;\n }\n\n public getOutputValueByName(name: string): string | undefined {\n if (!this.executed) {\n throw new BuildStepRuntimeError(\n `Failed getting output \"${name}\" from step \"${this.displayName}\". The step has not been executed yet.`\n );\n }\n if (!this.hasOutputParameter(name)) {\n throw new BuildStepRuntimeError(`Step \"${this.displayName}\" does not have output \"${name}\".`);\n }\n return this.outputById[name].value;\n }\n\n public canBeRunOnRuntimePlatform(): boolean {\n return (\n !this.supportedRuntimePlatforms ||\n this.supportedRuntimePlatforms.includes(this.ctx.global.runtimePlatform)\n );\n }\n\n public shouldExecuteStep(hasAnyPreviousStepsFailed: boolean): boolean {\n const defaultStatusCheck = 'success';\n const statusCheck = this.ifCondition\n ? getSelectedStatusCheckFromIfStatementTemplate(this.ifCondition)\n : defaultStatusCheck;\n\n switch (statusCheck) {\n case 'success':\n return !hasAnyPreviousStepsFailed;\n case 'failure':\n return hasAnyPreviousStepsFailed;\n case 'always':\n return true;\n case 'never':\n return false;\n }\n }\n\n public skip(): void {\n this.status = BuildStepStatus.SKIPPED;\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.START_STEP },\n 'Executing build step \"${this.displayName}\"'\n );\n this.ctx.logger.info(`Skipped build step \"${this.displayName}\"`);\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.SKIPPED },\n `Skipped build step \"${this.displayName}\"`\n );\n }\n\n private async executeCommandAsync(): Promise<void> {\n assert(this.command, 'Command must be defined.');\n\n try {\n const command = this.interpolateInputsAndGlobalContextInCommand(this.command, this.inputs);\n this.ctx.logger.debug(`Interpolated inputs in the command template`);\n\n const outputsDir = await createTemporaryOutputsDirectoryAsync(this.ctx.global, this.id);\n this.ctx.logger.debug(`Created temporary directory for step outputs: ${outputsDir}`);\n\n const envsDir = await createTemporaryEnvsDirectoryAsync(this.ctx.global, this.id);\n this.ctx.logger.debug(\n `Created temporary directory for step environment variables: ${outputsDir}`\n );\n\n const scriptPath = await saveScriptToTemporaryFileAsync(this.ctx.global, this.id, command);\n this.ctx.logger.debug(`Saved script to ${scriptPath}`);\n\n const { command: shellCommand, args } = getShellCommandAndArgs(this.shell, scriptPath);\n this.ctx.logger.debug(\n `Executing script: ${shellCommand}${args !== undefined ? ` ${args.join(' ')}` : ''}`\n );\n await spawnAsync(shellCommand, args ?? [], {\n cwd: this.ctx.workingDirectory,\n logger: this.ctx.logger,\n env: this.getScriptEnv({ outputsDir, envsDir }),\n // stdin is /dev/null, std{out,err} are piped into logger.\n stdio: ['ignore', 'pipe', 'pipe'],\n });\n this.ctx.logger.debug(`Script completed successfully`);\n\n await this.collectAndValidateOutputsAsync(outputsDir);\n await this.collectAndUpdateEnvsAsync(envsDir);\n this.ctx.logger.debug('Finished collecting output paramters');\n } finally {\n await cleanUpStepTemporaryDirectoriesAsync(this.ctx.global, this.id);\n }\n }\n\n private async exectuteFnAsync(): Promise<void> {\n assert(this.fn, 'Function (fn) must be defined');\n\n try {\n const outputsDir = await createTemporaryOutputsDirectoryAsync(this.ctx.global, this.id);\n this.ctx.logger.debug(`Created temporary directory for step outputs: ${outputsDir}`);\n\n const envsDir = await createTemporaryEnvsDirectoryAsync(this.ctx.global, this.id);\n this.ctx.logger.debug(\n `Created temporary directory for step environment variables: ${outputsDir}`\n );\n\n await this.fn(this.ctx, {\n inputs: this.inputById,\n outputs: this.outputById,\n env: this.getScriptEnv({ outputsDir, envsDir }),\n });\n\n this.ctx.logger.debug(`Script completed successfully`);\n\n await this.collectAndValidateOutputsAsync(outputsDir);\n await this.collectAndUpdateEnvsAsync(envsDir);\n this.ctx.logger.debug('Finished collecting output paramters');\n } finally {\n await cleanUpStepTemporaryDirectoriesAsync(this.ctx.global, this.id);\n }\n }\n\n private interpolateInputsAndGlobalContextInCommand(\n command: string,\n inputs?: BuildStepInput[]\n ): string {\n if (!inputs) {\n return this.ctx.global.interpolate(command);\n }\n const vars = inputs.reduce(\n (acc, input) => {\n acc[input.id] =\n typeof input.value === 'object'\n ? JSON.stringify(input.value)\n : input.value?.toString() ?? '';\n return acc;\n },\n {} as Record<string, string>\n );\n const valueInterpolatedWithGlobalContext = this.ctx.global.interpolate(command);\n return interpolateWithInputs(valueInterpolatedWithGlobalContext, vars);\n }\n\n private async collectAndValidateOutputsAsync(outputsDir: string): Promise<void> {\n const files = await fs.readdir(outputsDir);\n\n const nonDefinedOutputIds: string[] = [];\n for (const outputId of files) {\n if (!(outputId in this.outputById)) {\n nonDefinedOutputIds.push(outputId);\n } else {\n const file = path.join(outputsDir, outputId);\n const rawContents = await fs.readFile(file, 'utf-8');\n const value = rawContents.trim();\n this.outputById[outputId].set(value);\n }\n }\n\n if (nonDefinedOutputIds.length > 0) {\n const idsString = nonDefinedOutputIds.map((i) => `\"${i}\"`).join(', ');\n this.ctx.logger.warn(`Some outputs are not defined in step config: ${idsString}`);\n }\n\n const nonSetRequiredOutputIds: string[] = [];\n for (const output of this.outputs ?? []) {\n try {\n const value = output.value;\n this.ctx.logger.debug(`Output parameter \"${output.id}\" is set to \"${value}\"`);\n } catch (err) {\n this.ctx.logger.debug({ err }, `Getting value for output parameter \"${output.id}\" failed.`);\n nonSetRequiredOutputIds.push(output.id);\n }\n }\n if (nonSetRequiredOutputIds.length > 0) {\n const idsString = nonSetRequiredOutputIds.map((i) => `\"${i}\"`).join(', ');\n throw new BuildStepRuntimeError(`Some required outputs have not been set: ${idsString}`, {\n metadata: { ids: nonSetRequiredOutputIds },\n });\n }\n }\n\n private async collectAndUpdateEnvsAsync(envsDir: string): Promise<void> {\n const filenames = await fs.readdir(envsDir);\n\n const entries = await Promise.all(\n filenames.map(async (basename) => {\n const rawContents = await fs.readFile(path.join(envsDir, basename), 'utf-8');\n return [basename, rawContents];\n })\n );\n this.ctx.global.updateEnv({\n ...this.ctx.global.env,\n ...Object.fromEntries(entries),\n });\n }\n\n private getScriptEnv({\n envsDir,\n outputsDir,\n }: {\n envsDir: string;\n outputsDir: string;\n }): Record<string, string> {\n const env = { ...this.ctx.global.env, ...this.env };\n const currentPath = env.PATH ?? process.env.PATH;\n const newPath = currentPath ? `${BIN_PATH}:${currentPath}` : BIN_PATH;\n return {\n ...env,\n __EXPO_STEPS_OUTPUTS_DIR: outputsDir,\n __EXPO_STEPS_ENVS_DIR: envsDir,\n __EXPO_STEPS_WORKING_DIRECTORY: this.ctx.workingDirectory,\n PATH: newPath,\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BuildStep.js","sourceRoot":"","sources":["../src/BuildStep.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GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC;SAC/B,CAAC,CAAC;IACL,CAAC;IAEO,YAAY,CAAC,EACnB,OAAO,EACP,UAAU,GAIX;;QACC,MAAM,GAAG,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACpD,MAAM,WAAW,GAAG,MAAA,GAAG,CAAC,IAAI,mCAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;QACjD,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,WAAW,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;QACtE,OAAO;YACL,GAAG,GAAG;YACN,wBAAwB,EAAE,UAAU;YACpC,qBAAqB,EAAE,OAAO;YAC9B,8BAA8B,EAAE,IAAI,CAAC,GAAG,CAAC,gBAAgB;YACzD,IAAI,EAAE,OAAO;SACd,CAAC;IACJ,CAAC;CACF","sourcesContent":["import assert from 'assert';\nimport fs from 'fs/promises';\nimport path from 'path';\n\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { BuildStepContext, BuildStepGlobalContext } from './BuildStepContext.js';\nimport { BuildStepInput, BuildStepInputById, makeBuildStepInputByIdMap } from './BuildStepInput.js';\nimport {\n BuildStepOutput,\n BuildStepOutputById,\n SerializedBuildStepOutput,\n makeBuildStepOutputByIdMap,\n} from './BuildStepOutput.js';\nimport { BIN_PATH } from './utils/shell/bin.js';\nimport { getDefaultShell, getShellCommandAndArgs } from './utils/shell/command.js';\nimport {\n cleanUpStepTemporaryDirectoriesAsync,\n createTemporaryEnvsDirectoryAsync,\n createTemporaryOutputsDirectoryAsync,\n saveScriptToTemporaryFileAsync,\n} from './BuildTemporaryFiles.js';\nimport { spawnAsync } from './utils/shell/spawn.js';\nimport { interpolateWithInputs } from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport { jsepEval } from './utils/jsepEval.js';\n\nexport enum BuildStepStatus {\n NEW = 'new',\n IN_PROGRESS = 'in-progress',\n SKIPPED = 'skipped',\n FAIL = 'fail',\n WARNING = 'warning',\n SUCCESS = 'success',\n}\n\nexport enum BuildStepLogMarker {\n START_STEP = 'start-step',\n END_STEP = 'end-step',\n}\n\nexport type BuildStepFunction = (\n ctx: BuildStepContext,\n {\n inputs,\n outputs,\n env,\n }: { inputs: BuildStepInputById; outputs: BuildStepOutputById; env: BuildStepEnv }\n) => unknown;\n\n// TODO: move to a place common with tests\nconst UUID_REGEX =\n /^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$/;\n\nexport interface SerializedBuildStepOutputAccessor {\n id: string;\n executed: boolean;\n outputById: Record<string, SerializedBuildStepOutput>;\n displayName: string;\n}\n\nexport class BuildStepOutputAccessor {\n constructor(\n public readonly id: string,\n public readonly displayName: string,\n protected readonly executed: boolean,\n protected readonly outputById: BuildStepOutputById\n ) {}\n\n public getOutputValueByName(name: string): string | undefined {\n if (!this.executed) {\n throw new BuildStepRuntimeError(\n `Failed getting output \"${name}\" from step \"${this.displayName}\". The step has not been executed yet.`\n );\n }\n if (!this.hasOutputParameter(name)) {\n throw new BuildStepRuntimeError(`Step \"${this.displayName}\" does not have output \"${name}\".`);\n }\n return this.outputById[name].value;\n }\n\n public hasOutputParameter(name: string): boolean {\n return name in this.outputById;\n }\n\n public serialize(): SerializedBuildStepOutputAccessor {\n return {\n id: this.id,\n executed: this.executed,\n outputById: Object.fromEntries(\n Object.entries(this.outputById).map(([key, value]) => [key, value.serialize()])\n ),\n displayName: this.displayName,\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepOutputAccessor\n ): BuildStepOutputAccessor {\n const outputById = Object.fromEntries(\n Object.entries(serialized.outputById).map(([key, value]) => [\n key,\n BuildStepOutput.deserialize(value),\n ])\n );\n return new BuildStepOutputAccessor(\n serialized.id,\n serialized.displayName,\n serialized.executed,\n outputById\n );\n }\n}\n\nexport class BuildStep extends BuildStepOutputAccessor {\n public readonly id: string;\n public readonly name?: string;\n public readonly displayName: string;\n public readonly supportedRuntimePlatforms?: BuildRuntimePlatform[];\n public readonly inputs?: BuildStepInput[];\n public readonly outputs?: BuildStepOutput[];\n public readonly command?: string;\n public readonly fn?: BuildStepFunction;\n public readonly shell: string;\n public readonly ctx: BuildStepContext;\n public readonly env: BuildStepEnv;\n public readonly ifCondition?: string;\n public status: BuildStepStatus;\n\n private readonly internalId: string;\n private readonly inputById: BuildStepInputById;\n protected readonly outputById: BuildStepOutputById;\n protected executed = false;\n\n public static getNewId(userDefinedId?: string): string {\n return userDefinedId ?? uuidv4();\n }\n\n public static getDisplayName({\n id,\n name,\n command,\n }: {\n id: string;\n name?: string;\n command?: string;\n }): string {\n if (name) {\n return name;\n }\n if (!id.match(UUID_REGEX)) {\n return id;\n }\n if (command) {\n const splits = command.trim().split('\\n');\n for (const split of splits) {\n const trimmed = split.trim();\n if (trimmed && !trimmed.startsWith('#')) {\n return trimmed;\n }\n }\n }\n return id;\n }\n\n constructor(\n ctx: BuildStepGlobalContext,\n {\n id,\n name,\n displayName,\n inputs,\n outputs,\n command,\n fn,\n workingDirectory: maybeWorkingDirectory,\n shell,\n supportedRuntimePlatforms: maybeSupportedRuntimePlatforms,\n env,\n ifCondition,\n }: {\n id: string;\n name?: string;\n displayName: string;\n inputs?: BuildStepInput[];\n outputs?: BuildStepOutput[];\n command?: string;\n fn?: BuildStepFunction;\n workingDirectory?: string;\n shell?: string;\n supportedRuntimePlatforms?: BuildRuntimePlatform[];\n env?: BuildStepEnv;\n ifCondition?: string;\n }\n ) {\n assert(command !== undefined || fn !== undefined, 'Either command or fn must be defined.');\n assert(!(command !== undefined && fn !== undefined), 'Command and fn cannot be both set.');\n const outputById = makeBuildStepOutputByIdMap(outputs);\n super(id, displayName, false, outputById);\n\n this.id = id;\n this.name = name;\n this.displayName = displayName;\n this.supportedRuntimePlatforms = maybeSupportedRuntimePlatforms;\n this.inputs = inputs;\n this.outputs = outputs;\n this.inputById = makeBuildStepInputByIdMap(inputs);\n this.outputById = outputById;\n this.fn = fn;\n this.command = command;\n this.shell = shell ?? getDefaultShell();\n this.ifCondition = ifCondition;\n this.status = BuildStepStatus.NEW;\n\n this.internalId = uuidv4();\n\n const logger = ctx.baseLogger.child({\n buildStepInternalId: this.internalId,\n buildStepId: this.id,\n buildStepDisplayName: this.displayName,\n });\n this.ctx = ctx.stepCtx({ logger, relativeWorkingDirectory: maybeWorkingDirectory });\n this.env = env ?? {};\n\n ctx.registerStep(this);\n }\n\n public async executeAsync(): Promise<void> {\n try {\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.START_STEP },\n `Executing build step \"${this.displayName}\"`\n );\n this.status = BuildStepStatus.IN_PROGRESS;\n\n if (this.command !== undefined) {\n await this.executeCommandAsync();\n } else {\n await this.exectuteFnAsync();\n }\n\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.SUCCESS },\n `Finished build step \"${this.displayName}\" successfully`\n );\n this.status = BuildStepStatus.SUCCESS;\n } catch (err) {\n this.ctx.logger.error({ err });\n this.ctx.logger.error(\n { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.FAIL },\n `Build step \"${this.displayName}\" failed`\n );\n this.status = BuildStepStatus.FAIL;\n throw err;\n } finally {\n this.executed = true;\n }\n }\n\n public hasOutputParameter(name: string): boolean {\n return name in this.outputById;\n }\n\n public getOutputValueByName(name: string): string | undefined {\n if (!this.executed) {\n throw new BuildStepRuntimeError(\n `Failed getting output \"${name}\" from step \"${this.displayName}\". The step has not been executed yet.`\n );\n }\n if (!this.hasOutputParameter(name)) {\n throw new BuildStepRuntimeError(`Step \"${this.displayName}\" does not have output \"${name}\".`);\n }\n return this.outputById[name].value;\n }\n\n public canBeRunOnRuntimePlatform(): boolean {\n return (\n !this.supportedRuntimePlatforms ||\n this.supportedRuntimePlatforms.includes(this.ctx.global.runtimePlatform)\n );\n }\n\n public shouldExecuteStep(hasAnyPreviousStepsFailed: boolean): boolean {\n if (!this.ifCondition) {\n return !hasAnyPreviousStepsFailed;\n }\n\n let ifCondition = this.ifCondition;\n\n if (ifCondition.startsWith('${') && ifCondition.endsWith('}')) {\n ifCondition = ifCondition.slice(2, -1);\n }\n\n return Boolean(\n jsepEval(ifCondition, {\n success: () => !hasAnyPreviousStepsFailed,\n failure: () => hasAnyPreviousStepsFailed,\n always: () => true,\n never: () => false,\n env: this.env,\n inputs:\n this.inputs?.reduce(\n (acc, input) => {\n acc[input.id] = input.value;\n return acc;\n },\n {} as Record<string, unknown>\n ) ?? {},\n eas: {\n runtimePlatform: this.ctx.global.runtimePlatform,\n ...this.ctx.global.staticContext,\n },\n })\n );\n }\n\n public skip(): void {\n this.status = BuildStepStatus.SKIPPED;\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.START_STEP },\n 'Executing build step \"${this.displayName}\"'\n );\n this.ctx.logger.info(`Skipped build step \"${this.displayName}\"`);\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.SKIPPED },\n `Skipped build step \"${this.displayName}\"`\n );\n }\n\n private async executeCommandAsync(): Promise<void> {\n assert(this.command, 'Command must be defined.');\n\n try {\n const command = this.interpolateInputsAndGlobalContextInTemplate(this.command, this.inputs);\n this.ctx.logger.debug(`Interpolated inputs in the command template`);\n\n const outputsDir = await createTemporaryOutputsDirectoryAsync(this.ctx.global, this.id);\n this.ctx.logger.debug(`Created temporary directory for step outputs: ${outputsDir}`);\n\n const envsDir = await createTemporaryEnvsDirectoryAsync(this.ctx.global, this.id);\n this.ctx.logger.debug(\n `Created temporary directory for step environment variables: ${outputsDir}`\n );\n\n const scriptPath = await saveScriptToTemporaryFileAsync(this.ctx.global, this.id, command);\n this.ctx.logger.debug(`Saved script to ${scriptPath}`);\n\n const { command: shellCommand, args } = getShellCommandAndArgs(this.shell, scriptPath);\n this.ctx.logger.debug(\n `Executing script: ${shellCommand}${args !== undefined ? ` ${args.join(' ')}` : ''}`\n );\n await spawnAsync(shellCommand, args ?? [], {\n cwd: this.ctx.workingDirectory,\n logger: this.ctx.logger,\n env: this.getScriptEnv({ outputsDir, envsDir }),\n // stdin is /dev/null, std{out,err} are piped into logger.\n stdio: ['ignore', 'pipe', 'pipe'],\n });\n this.ctx.logger.debug(`Script completed successfully`);\n\n await this.collectAndValidateOutputsAsync(outputsDir);\n await this.collectAndUpdateEnvsAsync(envsDir);\n this.ctx.logger.debug('Finished collecting output paramters');\n } finally {\n await cleanUpStepTemporaryDirectoriesAsync(this.ctx.global, this.id);\n }\n }\n\n private async exectuteFnAsync(): Promise<void> {\n assert(this.fn, 'Function (fn) must be defined');\n\n try {\n const outputsDir = await createTemporaryOutputsDirectoryAsync(this.ctx.global, this.id);\n this.ctx.logger.debug(`Created temporary directory for step outputs: ${outputsDir}`);\n\n const envsDir = await createTemporaryEnvsDirectoryAsync(this.ctx.global, this.id);\n this.ctx.logger.debug(\n `Created temporary directory for step environment variables: ${outputsDir}`\n );\n\n await this.fn(this.ctx, {\n inputs: this.inputById,\n outputs: this.outputById,\n env: this.getScriptEnv({ outputsDir, envsDir }),\n });\n\n this.ctx.logger.debug(`Script completed successfully`);\n\n await this.collectAndValidateOutputsAsync(outputsDir);\n await this.collectAndUpdateEnvsAsync(envsDir);\n this.ctx.logger.debug('Finished collecting output paramters');\n } finally {\n await cleanUpStepTemporaryDirectoriesAsync(this.ctx.global, this.id);\n }\n }\n\n private interpolateInputsAndGlobalContextInTemplate(\n template: string,\n inputs?: BuildStepInput[]\n ): string {\n if (!inputs) {\n return this.ctx.global.interpolate(template);\n }\n const vars = inputs.reduce(\n (acc, input) => {\n acc[input.id] =\n typeof input.value === 'object'\n ? JSON.stringify(input.value)\n : input.value?.toString() ?? '';\n return acc;\n },\n {} as Record<string, string>\n );\n const valueInterpolatedWithGlobalContext = this.ctx.global.interpolate(template);\n return interpolateWithInputs(valueInterpolatedWithGlobalContext, vars);\n }\n\n private async collectAndValidateOutputsAsync(outputsDir: string): Promise<void> {\n const files = await fs.readdir(outputsDir);\n\n const nonDefinedOutputIds: string[] = [];\n for (const outputId of files) {\n if (!(outputId in this.outputById)) {\n nonDefinedOutputIds.push(outputId);\n } else {\n const file = path.join(outputsDir, outputId);\n const rawContents = await fs.readFile(file, 'utf-8');\n const value = rawContents.trim();\n this.outputById[outputId].set(value);\n }\n }\n\n if (nonDefinedOutputIds.length > 0) {\n const idsString = nonDefinedOutputIds.map((i) => `\"${i}\"`).join(', ');\n this.ctx.logger.warn(`Some outputs are not defined in step config: ${idsString}`);\n }\n\n const nonSetRequiredOutputIds: string[] = [];\n for (const output of this.outputs ?? []) {\n try {\n const value = output.value;\n this.ctx.logger.debug(`Output parameter \"${output.id}\" is set to \"${value}\"`);\n } catch (err) {\n this.ctx.logger.debug({ err }, `Getting value for output parameter \"${output.id}\" failed.`);\n nonSetRequiredOutputIds.push(output.id);\n }\n }\n if (nonSetRequiredOutputIds.length > 0) {\n const idsString = nonSetRequiredOutputIds.map((i) => `\"${i}\"`).join(', ');\n throw new BuildStepRuntimeError(`Some required outputs have not been set: ${idsString}`, {\n metadata: { ids: nonSetRequiredOutputIds },\n });\n }\n }\n\n private async collectAndUpdateEnvsAsync(envsDir: string): Promise<void> {\n const filenames = await fs.readdir(envsDir);\n\n const entries = await Promise.all(\n filenames.map(async (basename) => {\n const rawContents = await fs.readFile(path.join(envsDir, basename), 'utf-8');\n return [basename, rawContents];\n })\n );\n this.ctx.global.updateEnv({\n ...this.ctx.global.env,\n ...Object.fromEntries(entries),\n });\n }\n\n private getScriptEnv({\n envsDir,\n outputsDir,\n }: {\n envsDir: string;\n outputsDir: string;\n }): Record<string, string> {\n const env = { ...this.ctx.global.env, ...this.env };\n const currentPath = env.PATH ?? process.env.PATH;\n const newPath = currentPath ? `${BIN_PATH}:${currentPath}` : BIN_PATH;\n return {\n ...env,\n __EXPO_STEPS_OUTPUTS_DIR: outputsDir,\n __EXPO_STEPS_ENVS_DIR: envsDir,\n __EXPO_STEPS_WORKING_DIRECTORY: this.ctx.workingDirectory,\n PATH: newPath,\n };\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const jsepEval: (expression: string, context?: Record<string, unknown>) => any;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// https://github.com/Sensative/jsep-eval/blob/master/src/jsep-eval.js
|
|
2
|
+
import assert from 'assert';
|
|
3
|
+
import get from 'lodash.get';
|
|
4
|
+
import jsep from 'jsep';
|
|
5
|
+
const binaryOperatorFunctions = {
|
|
6
|
+
'===': (a, b) => a === b,
|
|
7
|
+
'!==': (a, b) => a !== b,
|
|
8
|
+
'==': (a, b) => a == b, // eslint-disable-line
|
|
9
|
+
'!=': (a, b) => a != b, // eslint-disable-line
|
|
10
|
+
'>': (a, b) => a > b,
|
|
11
|
+
'<': (a, b) => a < b,
|
|
12
|
+
'>=': (a, b) => a >= b,
|
|
13
|
+
'<=': (a, b) => a <= b,
|
|
14
|
+
'+': (a, b) => a + b,
|
|
15
|
+
'-': (a, b) => a - b,
|
|
16
|
+
'*': (a, b) => a * b,
|
|
17
|
+
'/': (a, b) => a / b,
|
|
18
|
+
'%': (a, b) => a % b, // remainder
|
|
19
|
+
'**': (a, b) => a ** b, // exponentiation
|
|
20
|
+
'&': (a, b) => a & b, // bitwise AND
|
|
21
|
+
'|': (a, b) => a | b, // bitwise OR
|
|
22
|
+
'^': (a, b) => a ^ b, // bitwise XOR
|
|
23
|
+
'<<': (a, b) => a << b, // left shift
|
|
24
|
+
'>>': (a, b) => a >> b, // sign-propagating right shift
|
|
25
|
+
'>>>': (a, b) => a >>> b, // zero-fill right shift
|
|
26
|
+
// Let's make a home for the logical operators here as well
|
|
27
|
+
'||': (a, b) => a || b,
|
|
28
|
+
'&&': (a, b) => a && b,
|
|
29
|
+
};
|
|
30
|
+
const unaryOperatorFunctions = {
|
|
31
|
+
'!': (a) => !a,
|
|
32
|
+
'~': (a) => ~a, // bitwise NOT
|
|
33
|
+
'+': (a) => +a, // unary plus
|
|
34
|
+
'-': (a) => -a, // unary negation
|
|
35
|
+
'++': (a) => ++a, // increment
|
|
36
|
+
'--': (a) => --a, // decrement
|
|
37
|
+
};
|
|
38
|
+
function isValid(expression, types) {
|
|
39
|
+
return types.includes(expression.type);
|
|
40
|
+
}
|
|
41
|
+
const getParameterPath = (node, context) => {
|
|
42
|
+
// it's a MEMBER expression
|
|
43
|
+
// EXAMPLES: a[b] (computed)
|
|
44
|
+
// a.b (not computed)
|
|
45
|
+
const computed = node.computed;
|
|
46
|
+
const object = node.object;
|
|
47
|
+
const property = node.property;
|
|
48
|
+
// object is either 'IDENTIFIER', 'MEMBER', or 'THIS'
|
|
49
|
+
assert(isValid(object, ['MemberExpression', 'Identifier', 'ThisExpression']), 'Invalid object type');
|
|
50
|
+
assert(property, 'Member expression property is missing');
|
|
51
|
+
let objectPath = '';
|
|
52
|
+
if (object.type === 'ThisExpression') {
|
|
53
|
+
objectPath = '';
|
|
54
|
+
}
|
|
55
|
+
else if (isValid(object, ['Identifier'])) {
|
|
56
|
+
objectPath = object.name;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
objectPath = getParameterPath(object, context);
|
|
60
|
+
}
|
|
61
|
+
if (computed) {
|
|
62
|
+
// if computed -> evaluate anew
|
|
63
|
+
const propertyPath = evaluateExpressionNode(property, context);
|
|
64
|
+
return objectPath + '[' + propertyPath + ']';
|
|
65
|
+
}
|
|
66
|
+
else if (isValid(property, ['Identifier'])) {
|
|
67
|
+
return (objectPath ? objectPath + '.' : '') + property.name;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
assert(isValid(property, ['MemberExpression']), 'Invalid object type');
|
|
71
|
+
const propertyPath = getParameterPath(property, context);
|
|
72
|
+
return (objectPath ? objectPath + '.' : '') + propertyPath;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const evaluateExpressionNode = (node, context) => {
|
|
76
|
+
switch (node.type) {
|
|
77
|
+
case 'Literal': {
|
|
78
|
+
return node.value;
|
|
79
|
+
}
|
|
80
|
+
case 'ThisExpression': {
|
|
81
|
+
return context;
|
|
82
|
+
}
|
|
83
|
+
case 'Compound': {
|
|
84
|
+
const compoundNode = node;
|
|
85
|
+
const expressions = compoundNode.body.map((el) => evaluateExpressionNode(el, context));
|
|
86
|
+
return expressions.pop();
|
|
87
|
+
}
|
|
88
|
+
case 'UnaryExpression': {
|
|
89
|
+
const unaryNode = node;
|
|
90
|
+
if (!(unaryNode.operator in unaryOperatorFunctions)) {
|
|
91
|
+
throw new Error(`Unsupported unary operator: ${unaryNode.operator}`);
|
|
92
|
+
}
|
|
93
|
+
const operatorFn = unaryOperatorFunctions[unaryNode.operator];
|
|
94
|
+
const argument = evaluateExpressionNode(unaryNode.argument, context);
|
|
95
|
+
return operatorFn(argument);
|
|
96
|
+
}
|
|
97
|
+
case 'BinaryExpression': {
|
|
98
|
+
const binaryNode = node;
|
|
99
|
+
if (!(binaryNode.operator in binaryOperatorFunctions)) {
|
|
100
|
+
throw new Error(`Unsupported binary operator: ${binaryNode.operator}`);
|
|
101
|
+
}
|
|
102
|
+
const operator = binaryOperatorFunctions[binaryNode.operator];
|
|
103
|
+
const left = evaluateExpressionNode(binaryNode.left, context);
|
|
104
|
+
const right = evaluateExpressionNode(binaryNode.right, context);
|
|
105
|
+
return operator(left, right);
|
|
106
|
+
}
|
|
107
|
+
case 'ConditionalExpression': {
|
|
108
|
+
const conditionalNode = node;
|
|
109
|
+
const test = evaluateExpressionNode(conditionalNode.test, context);
|
|
110
|
+
const consequent = evaluateExpressionNode(conditionalNode.consequent, context);
|
|
111
|
+
const alternate = evaluateExpressionNode(conditionalNode.alternate, context);
|
|
112
|
+
return test ? consequent : alternate;
|
|
113
|
+
}
|
|
114
|
+
case 'CallExpression': {
|
|
115
|
+
const allowedCalleeTypes = [
|
|
116
|
+
'MemberExpression',
|
|
117
|
+
'Identifier',
|
|
118
|
+
'ThisExpression',
|
|
119
|
+
];
|
|
120
|
+
const callNode = node;
|
|
121
|
+
if (!allowedCalleeTypes.includes(callNode.callee.type)) {
|
|
122
|
+
throw new Error(`Invalid function callee type: ${callNode.callee.type}. Expected one of ${allowedCalleeTypes.join(', ')}.`);
|
|
123
|
+
}
|
|
124
|
+
const callee = evaluateExpressionNode(callNode.callee, context);
|
|
125
|
+
const args = callNode.arguments.map((arg) => evaluateExpressionNode(arg, context));
|
|
126
|
+
// eslint-disable-next-line prefer-spread
|
|
127
|
+
return callee.apply(null, args);
|
|
128
|
+
}
|
|
129
|
+
case 'Identifier': {
|
|
130
|
+
const identifier = node.name;
|
|
131
|
+
if (!(identifier in context)) {
|
|
132
|
+
throw new Error(`Invalid identifier "${identifier}". Expected one of ${Object.keys(context).join(', ')}`);
|
|
133
|
+
}
|
|
134
|
+
return get(context, identifier);
|
|
135
|
+
}
|
|
136
|
+
case 'MemberExpression': {
|
|
137
|
+
const path = getParameterPath(node, context);
|
|
138
|
+
return get(context, path);
|
|
139
|
+
}
|
|
140
|
+
case 'ArrayExpression': {
|
|
141
|
+
const elements = node.elements.map((el) => evaluateExpressionNode(el, context));
|
|
142
|
+
return elements;
|
|
143
|
+
}
|
|
144
|
+
default:
|
|
145
|
+
throw new Error(`Unsupported expression type: ${node.type}`);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
export const jsepEval = (expression, context) => {
|
|
149
|
+
const tree = jsep(expression);
|
|
150
|
+
return evaluateExpressionNode(tree, context !== null && context !== void 0 ? context : {});
|
|
151
|
+
};
|
|
152
|
+
//# sourceMappingURL=jsepEval.js.map
|