@expo/steps 1.0.75 → 1.0.81

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.
@@ -47,7 +47,7 @@ export declare class BuildStepGlobalContext {
47
47
  updateEnv(updatedEnv: BuildStepEnv): void;
48
48
  registerStep(step: BuildStep): void;
49
49
  getStepOutputValue(path: string): string | undefined;
50
- interpolate(value: string): string;
50
+ interpolate<InterpolableType extends string | object>(value: InterpolableType): InterpolableType;
51
51
  stepCtx(options: {
52
52
  logger: bunyan;
53
53
  relativeWorkingDirectory?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"BuildStepContext.js","sourceRoot":"","sources":["../src/BuildStepContext.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAIxB,+BAAoC;AAEpC,iDAIwB;AACxB,qDAI6B;AAC7B,2CAAoD;AAmCpD,MAAa,sBAAsB;IAQjC,YACmB,QAAsC,EACvC,WAAoB;QADnB,aAAQ,GAAR,QAAQ,CAA8B;QACvC,gBAAW,GAAX,WAAW,CAAS;QAN9B,gBAAW,GAAG,KAAK,CAAC;QAEpB,aAAQ,GAA4C,EAAE,CAAC;QAM7D,IAAI,CAAC,2BAA2B,GAAG,cAAI,CAAC,IAAI,CAAC,YAAE,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,IAAA,SAAM,GAAE,CAAC,CAAC;QACjF,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC,eAAe,CAAC;QAChD,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC;IACpC,CAAC;IAED,IAAW,sBAAsB;QAC/B,OAAO,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC;IAC9C,CAAC;IAED,IAAW,sBAAsB;QAC/B,OAAO,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC;IAC9C,CAAC;IAED,IAAW,uBAAuB;QAChC,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAA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AAC,uBAAuB,EAAE,IAAI,CAAC,wBAAwB,CAAC;YAC/E,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,uBAAuB,CAAC;IACvC,CAAC;IAEM,SAAS;QACd,OAAO;YACL,wBAAwB,EAAE,IAAI,CAAC,wBAAwB;YACvD,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE;SAC7B,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,WAAW,CACvB,UAAsC,EACtC,MAAc;QAEd,MAAM,kBAAkB,GAAG,sBAAsB,CAAC,WAAW,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACzF,OAAO,IAAI,gBAAgB,CAAC,kBAAkB,EAAE;YAC9C,MAAM;YACN,wBAAwB,EAAE,UAAU,CAAC,wBAAwB;SAC9D,CAAC,CAAC;IACL,CAAC;CACF;AA7CD,4CA6CC","sourcesContent":["import os from 'os';\nimport path from 'path';\n\nimport { BuildStaticContext } from '@expo/eas-build-job';\nimport { bunyan } from '@expo/logger';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport {\n BuildStep,\n BuildStepOutputAccessor,\n SerializedBuildStepOutputAccessor,\n} from './BuildStep.js';\nimport {\n getObjectValueForInterpolation,\n interpolateWithGlobalContext,\n parseOutputPath,\n} from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\n\ninterface SerializedExternalBuildContextProvider {\n projectSourceDirectory: string;\n projectTargetDirectory: string;\n defaultWorkingDirectory: string;\n buildLogsDirectory: string;\n runtimePlatform: BuildRuntimePlatform;\n staticContext: BuildStaticContext;\n env: BuildStepEnv;\n}\n\nexport interface ExternalBuildContextProvider {\n readonly projectSourceDirectory: string;\n readonly projectTargetDirectory: string;\n readonly defaultWorkingDirectory: string;\n readonly buildLogsDirectory: string;\n readonly runtimePlatform: BuildRuntimePlatform;\n readonly logger: bunyan;\n\n readonly staticContext: () => BuildStaticContext;\n\n readonly env: BuildStepEnv;\n updateEnv(env: BuildStepEnv): void;\n}\n\nexport interface SerializedBuildStepGlobalContext {\n stepsInternalBuildDirectory: string;\n stepById: Record<string, SerializedBuildStepOutputAccessor>;\n provider: SerializedExternalBuildContextProvider;\n skipCleanup: boolean;\n}\n\nexport class BuildStepGlobalContext {\n public stepsInternalBuildDirectory: string;\n public readonly runtimePlatform: BuildRuntimePlatform;\n public readonly baseLogger: bunyan;\n private didCheckOut = false;\n\n private stepById: Record<string, BuildStepOutputAccessor> = {};\n\n constructor(\n private readonly provider: ExternalBuildContextProvider,\n public readonly skipCleanup: boolean\n ) {\n this.stepsInternalBuildDirectory = path.join(os.tmpdir(), 'eas-build', uuidv4());\n this.runtimePlatform = provider.runtimePlatform;\n this.baseLogger = provider.logger;\n }\n\n public get projectSourceDirectory(): string {\n return this.provider.projectSourceDirectory;\n }\n\n public get projectTargetDirectory(): string {\n return this.provider.projectTargetDirectory;\n }\n\n public get defaultWorkingDirectory(): string {\n return this.didCheckOut ? this.provider.defaultWorkingDirectory : this.projectTargetDirectory;\n }\n\n public get buildLogsDirectory(): string {\n return this.provider.buildLogsDirectory;\n }\n\n public get env(): BuildStepEnv {\n return this.provider.env;\n }\n\n public get staticContext(): BuildStaticContext {\n return this.provider.staticContext();\n }\n\n public updateEnv(updatedEnv: BuildStepEnv): void {\n this.provider.updateEnv(updatedEnv);\n }\n\n public registerStep(step: BuildStep): void {\n this.stepById[step.id] = step;\n }\n\n public getStepOutputValue(path: string): string | undefined {\n const { stepId, outputId } = parseOutputPath(path);\n if (!(stepId in this.stepById)) {\n throw new BuildStepRuntimeError(`Step \"${stepId}\" does not exist.`);\n }\n return this.stepById[stepId].getOutputValueByName(outputId);\n }\n\n public interpolate(value: string): string {\n return interpolateWithGlobalContext(value, (path) => {\n return (\n getObjectValueForInterpolation(path, {\n eas: {\n runtimePlatform: this.runtimePlatform,\n ...this.staticContext,\n },\n })?.toString() ?? ''\n );\n });\n }\n\n public stepCtx(options: { logger: bunyan; relativeWorkingDirectory?: string }): BuildStepContext {\n return new BuildStepContext(this, options);\n }\n\n public markAsCheckedOut(logger: bunyan): void {\n this.didCheckOut = true;\n logger.info(\n `Changing default working directory to ${this.defaultWorkingDirectory} (was ${this.projectTargetDirectory})`\n );\n }\n\n public serialize(): SerializedBuildStepGlobalContext {\n return {\n stepsInternalBuildDirectory: this.stepsInternalBuildDirectory,\n stepById: Object.fromEntries(\n Object.entries(this.stepById).map(([id, step]) => [id, step.serialize()])\n ),\n provider: {\n projectSourceDirectory: this.provider.projectSourceDirectory,\n projectTargetDirectory: this.provider.projectTargetDirectory,\n defaultWorkingDirectory: this.provider.defaultWorkingDirectory,\n buildLogsDirectory: this.provider.buildLogsDirectory,\n runtimePlatform: this.provider.runtimePlatform,\n staticContext: this.provider.staticContext(),\n env: this.provider.env,\n },\n skipCleanup: this.skipCleanup,\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepGlobalContext,\n logger: bunyan\n ): BuildStepGlobalContext {\n const deserializedProvider: ExternalBuildContextProvider = {\n projectSourceDirectory: serialized.provider.projectSourceDirectory,\n projectTargetDirectory: serialized.provider.projectTargetDirectory,\n defaultWorkingDirectory: serialized.provider.defaultWorkingDirectory,\n buildLogsDirectory: serialized.provider.buildLogsDirectory,\n runtimePlatform: serialized.provider.runtimePlatform,\n logger,\n staticContext: () => serialized.provider.staticContext,\n env: serialized.provider.env,\n updateEnv: () => {},\n };\n const ctx = new BuildStepGlobalContext(deserializedProvider, serialized.skipCleanup);\n for (const [id, stepOutputAccessor] of Object.entries(serialized.stepById)) {\n ctx.stepById[id] = BuildStepOutputAccessor.deserialize(stepOutputAccessor);\n }\n ctx.stepsInternalBuildDirectory = serialized.stepsInternalBuildDirectory;\n\n return ctx;\n }\n}\n\nexport interface SerializedBuildStepContext {\n relativeWorkingDirectory?: string;\n global: SerializedBuildStepGlobalContext;\n}\n\nexport class BuildStepContext {\n public readonly logger: bunyan;\n public readonly relativeWorkingDirectory?: string;\n\n constructor(\n private readonly ctx: BuildStepGlobalContext,\n {\n logger,\n relativeWorkingDirectory,\n }: {\n logger: bunyan;\n relativeWorkingDirectory?: string;\n }\n ) {\n this.logger = logger ?? ctx.baseLogger;\n this.relativeWorkingDirectory = relativeWorkingDirectory;\n }\n\n public get global(): BuildStepGlobalContext {\n return this.ctx;\n }\n\n public get workingDirectory(): string {\n return this.relativeWorkingDirectory\n ? path.resolve(this.ctx.defaultWorkingDirectory, this.relativeWorkingDirectory)\n : this.ctx.defaultWorkingDirectory;\n }\n\n public serialize(): SerializedBuildStepContext {\n return {\n relativeWorkingDirectory: this.relativeWorkingDirectory,\n global: this.ctx.serialize(),\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepContext,\n logger: bunyan\n ): BuildStepContext {\n const deserializedGlobal = BuildStepGlobalContext.deserialize(serialized.global, logger);\n return new BuildStepContext(deserializedGlobal, {\n logger,\n relativeWorkingDirectory: serialized.relativeWorkingDirectory,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"BuildStepContext.js","sourceRoot":"","sources":["../src/BuildStepContext.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAIxB,+BAAoC;AAEpC,iDAIwB;AACxB,qDAI6B;AAC7B,2CAAoD;AAmCpD,MAAa,sBAAsB;IAQjC,YACmB,QAAsC,EACvC,WAAoB;QADnB,aAAQ,GAAR,QAAQ,CAA8B;QACvC,gBAAW,GAAX,WAAW,CAAS;QAN9B,gBAAW,GAAG,KAAK,CAAC;QAEpB,aAAQ,GAA4C,EAAE,CAAC;QAM7D,IAAI,CAAC,2BAA2B,GAAG,cAAI,CAAC,IAAI,CAAC,YAAE,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,IAAA,SAAM,GAAE,CAAC,CAAC;QACjF,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC,eAAe,CAAC;QAChD,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,MAAM,CA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AG,CAAC,UAAU,CAAC;QACvC,IAAI,CAAC,wBAAwB,GAAG,wBAAwB,CAAC;IAC3D,CAAC;IAED,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,IAAW,gBAAgB;QACzB,OAAO,IAAI,CAAC,wBAAwB;YAClC,CAAC,CAAC,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,uBAAuB,EAAE,IAAI,CAAC,wBAAwB,CAAC;YAC/E,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,uBAAuB,CAAC;IACvC,CAAC;IAEM,SAAS;QACd,OAAO;YACL,wBAAwB,EAAE,IAAI,CAAC,wBAAwB;YACvD,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE;SAC7B,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,WAAW,CACvB,UAAsC,EACtC,MAAc;QAEd,MAAM,kBAAkB,GAAG,sBAAsB,CAAC,WAAW,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACzF,OAAO,IAAI,gBAAgB,CAAC,kBAAkB,EAAE;YAC9C,MAAM;YACN,wBAAwB,EAAE,UAAU,CAAC,wBAAwB;SAC9D,CAAC,CAAC;IACL,CAAC;CACF;AA7CD,4CA6CC","sourcesContent":["import os from 'os';\nimport path from 'path';\n\nimport { BuildStaticContext } from '@expo/eas-build-job';\nimport { bunyan } from '@expo/logger';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport {\n BuildStep,\n BuildStepOutputAccessor,\n SerializedBuildStepOutputAccessor,\n} from './BuildStep.js';\nimport {\n getObjectValueForInterpolation,\n interpolateWithGlobalContext,\n parseOutputPath,\n} from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\n\ninterface SerializedExternalBuildContextProvider {\n projectSourceDirectory: string;\n projectTargetDirectory: string;\n defaultWorkingDirectory: string;\n buildLogsDirectory: string;\n runtimePlatform: BuildRuntimePlatform;\n staticContext: BuildStaticContext;\n env: BuildStepEnv;\n}\n\nexport interface ExternalBuildContextProvider {\n readonly projectSourceDirectory: string;\n readonly projectTargetDirectory: string;\n readonly defaultWorkingDirectory: string;\n readonly buildLogsDirectory: string;\n readonly runtimePlatform: BuildRuntimePlatform;\n readonly logger: bunyan;\n\n readonly staticContext: () => BuildStaticContext;\n\n readonly env: BuildStepEnv;\n updateEnv(env: BuildStepEnv): void;\n}\n\nexport interface SerializedBuildStepGlobalContext {\n stepsInternalBuildDirectory: string;\n stepById: Record<string, SerializedBuildStepOutputAccessor>;\n provider: SerializedExternalBuildContextProvider;\n skipCleanup: boolean;\n}\n\nexport class BuildStepGlobalContext {\n public stepsInternalBuildDirectory: string;\n public readonly runtimePlatform: BuildRuntimePlatform;\n public readonly baseLogger: bunyan;\n private didCheckOut = false;\n\n private stepById: Record<string, BuildStepOutputAccessor> = {};\n\n constructor(\n private readonly provider: ExternalBuildContextProvider,\n public readonly skipCleanup: boolean\n ) {\n this.stepsInternalBuildDirectory = path.join(os.tmpdir(), 'eas-build', uuidv4());\n this.runtimePlatform = provider.runtimePlatform;\n this.baseLogger = provider.logger;\n }\n\n public get projectSourceDirectory(): string {\n return this.provider.projectSourceDirectory;\n }\n\n public get projectTargetDirectory(): string {\n return this.provider.projectTargetDirectory;\n }\n\n public get defaultWorkingDirectory(): string {\n return this.didCheckOut ? this.provider.defaultWorkingDirectory : this.projectTargetDirectory;\n }\n\n public get buildLogsDirectory(): string {\n return this.provider.buildLogsDirectory;\n }\n\n public get env(): BuildStepEnv {\n return this.provider.env;\n }\n\n public get staticContext(): BuildStaticContext {\n return this.provider.staticContext();\n }\n\n public updateEnv(updatedEnv: BuildStepEnv): void {\n this.provider.updateEnv(updatedEnv);\n }\n\n public registerStep(step: BuildStep): void {\n this.stepById[step.id] = step;\n }\n\n public getStepOutputValue(path: string): string | undefined {\n const { stepId, outputId } = parseOutputPath(path);\n if (!(stepId in this.stepById)) {\n throw new BuildStepRuntimeError(`Step \"${stepId}\" does not exist.`);\n }\n return this.stepById[stepId].getOutputValueByName(outputId);\n }\n\n public interpolate<InterpolableType extends string | object>(\n value: InterpolableType\n ): InterpolableType {\n return interpolateWithGlobalContext(value, (path) => {\n return (\n getObjectValueForInterpolation(path, {\n eas: {\n runtimePlatform: this.runtimePlatform,\n ...this.staticContext,\n },\n })?.toString() ?? ''\n );\n });\n }\n\n public stepCtx(options: { logger: bunyan; relativeWorkingDirectory?: string }): BuildStepContext {\n return new BuildStepContext(this, options);\n }\n\n public markAsCheckedOut(logger: bunyan): void {\n this.didCheckOut = true;\n logger.info(\n `Changing default working directory to ${this.defaultWorkingDirectory} (was ${this.projectTargetDirectory})`\n );\n }\n\n public serialize(): SerializedBuildStepGlobalContext {\n return {\n stepsInternalBuildDirectory: this.stepsInternalBuildDirectory,\n stepById: Object.fromEntries(\n Object.entries(this.stepById).map(([id, step]) => [id, step.serialize()])\n ),\n provider: {\n projectSourceDirectory: this.provider.projectSourceDirectory,\n projectTargetDirectory: this.provider.projectTargetDirectory,\n defaultWorkingDirectory: this.provider.defaultWorkingDirectory,\n buildLogsDirectory: this.provider.buildLogsDirectory,\n runtimePlatform: this.provider.runtimePlatform,\n staticContext: this.provider.staticContext(),\n env: this.provider.env,\n },\n skipCleanup: this.skipCleanup,\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepGlobalContext,\n logger: bunyan\n ): BuildStepGlobalContext {\n const deserializedProvider: ExternalBuildContextProvider = {\n projectSourceDirectory: serialized.provider.projectSourceDirectory,\n projectTargetDirectory: serialized.provider.projectTargetDirectory,\n defaultWorkingDirectory: serialized.provider.defaultWorkingDirectory,\n buildLogsDirectory: serialized.provider.buildLogsDirectory,\n runtimePlatform: serialized.provider.runtimePlatform,\n logger,\n staticContext: () => serialized.provider.staticContext,\n env: serialized.provider.env,\n updateEnv: () => {},\n };\n const ctx = new BuildStepGlobalContext(deserializedProvider, serialized.skipCleanup);\n for (const [id, stepOutputAccessor] of Object.entries(serialized.stepById)) {\n ctx.stepById[id] = BuildStepOutputAccessor.deserialize(stepOutputAccessor);\n }\n ctx.stepsInternalBuildDirectory = serialized.stepsInternalBuildDirectory;\n\n return ctx;\n }\n}\n\nexport interface SerializedBuildStepContext {\n relativeWorkingDirectory?: string;\n global: SerializedBuildStepGlobalContext;\n}\n\nexport class BuildStepContext {\n public readonly logger: bunyan;\n public readonly relativeWorkingDirectory?: string;\n\n constructor(\n private readonly ctx: BuildStepGlobalContext,\n {\n logger,\n relativeWorkingDirectory,\n }: {\n logger: bunyan;\n relativeWorkingDirectory?: string;\n }\n ) {\n this.logger = logger ?? ctx.baseLogger;\n this.relativeWorkingDirectory = relativeWorkingDirectory;\n }\n\n public get global(): BuildStepGlobalContext {\n return this.ctx;\n }\n\n public get workingDirectory(): string {\n return this.relativeWorkingDirectory\n ? path.resolve(this.ctx.defaultWorkingDirectory, this.relativeWorkingDirectory)\n : this.ctx.defaultWorkingDirectory;\n }\n\n public serialize(): SerializedBuildStepContext {\n return {\n relativeWorkingDirectory: this.relativeWorkingDirectory,\n global: this.ctx.serialize(),\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepContext,\n logger: bunyan\n ): BuildStepContext {\n const deserializedGlobal = BuildStepGlobalContext.deserialize(serialized.global, logger);\n return new BuildStepContext(deserializedGlobal, {\n logger,\n relativeWorkingDirectory: serialized.relativeWorkingDirectory,\n });\n }\n}\n"]}
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.makeBuildStepInputByIdMap = exports.BuildStepInput = exports.BuildStepInputValueTypeName = void 0;
7
+ const assert_1 = __importDefault(require("assert"));
4
8
  const BuildStepContext_js_1 = require("./BuildStepContext.cjs");
5
9
  const errors_js_1 = require("./errors.cjs");
6
10
  const template_js_1 = require("./utils/template.cjs");
@@ -30,18 +34,17 @@ class BuildStepInput {
30
34
  if (this.required && rawValue === undefined) {
31
35
  throw new errors_js_1.BuildStepRuntimeError(`Input parameter "${this.id}" for step "${this.stepDisplayName}" is required but it was not set.`);
32
36
  }
33
- const valueDoesNotRequireInterpolation = rawValue === undefined ||
34
- typeof rawValue === 'boolean' ||
35
- typeof rawValue === 'number' ||
36
- typeof rawValue === 'object';
37
+ const valueDoesNotRequireInterpolation = rawValue === undefined || typeof rawValue === 'boolean' || typeof rawValue === 'number';
37
38
  if (valueDoesNotRequireInterpolation) {
38
- const currentTypeName = typeof rawValue === 'object' ? BuildStepInputValueTypeName.JSON : typeof rawValue;
39
- if (currentTypeName !== this.allowedValueTypeName && rawValue !== undefined) {
39
+ if (typeof rawValue !== this.allowedValueTypeName && rawValue !== undefined) {
40
40
  throw new errors_js_1.BuildStepRuntimeError(`Input parameter "${this.id}" for step "${this.stepDisplayName}" must be of type "${this.allowedValueTypeName}".`);
41
41
  }
42
42
  return rawValue;
43
43
  }
44
44
  else {
45
+ // `valueDoesNotRequireInterpolation` checks that `rawValue` is not undefined
46
+ // so this will never be true.
47
+ (0, assert_1.default)(rawValue !== undefined);
45
48
  const valueInterpolatedWithGlobalContext = this.ctx.interpolate(rawValue);
46
49
  const valueInterpolatedWithOutputsAndGlobalContext = (0, template_js_1.interpolateWithOutputs)(valueInterpolatedWithGlobalContext, (path) => { var _a; return (_a = this.ctx.getStepOutputValue(path)) !== null && _a !== void 0 ? _a : ''; });
47
50
  return this.parseInputValueToAllowedType(valueInterpolatedWithOutputsAndGlobalContext);
@@ -96,6 +99,9 @@ class BuildStepInput {
96
99
  return input;
97
100
  }
98
101
  parseInputValueToAllowedType(value) {
102
+ if (typeof value === 'object') {
103
+ return value;
104
+ }
99
105
  if (this.allowedValueTypeName === BuildStepInputValueTypeName.STRING) {
100
106
  return value;
101
107
  }
@@ -1 +1 @@
1
- {"version":3,"file":"BuildSt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AAe,IAAI,CAAC,eAAe,sBAAsB,IAAI,CAAC,oBAAoB,IAAI,CAClH,CAAC;QACJ,CAAC;IACH,CAAC;IAEO,uBAAuB,CAAC,KAAa;QAC3C,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,MAAM,IAAI,iCAAqB,CAC7B,oBAAoB,IAAI,CAAC,EAAE,eAAe,IAAI,CAAC,eAAe,sBAAsB,IAAI,CAAC,oBAAoB,IAAI,EACjH;gBACE,KAAK,EAAE,CAAC;aACT,CACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AA9KD,wCA8KC;AAED,SAAgB,yBAAyB,CAAC,MAAyB;IACjE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAClC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC;QACtB,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAwB,CAAC,CAAC;AAC/B,CAAC;AARD,8DAQC","sourcesContent":["import { bunyan } from '@expo/logger';\n\nimport { BuildStepGlobalContext, SerializedBuildStepGlobalContext } from './BuildStepContext.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport {\n BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX,\n interpolateWithOutputs,\n} from './utils/template.js';\n\nexport enum BuildStepInputValueTypeName {\n STRING = 'string',\n BOOLEAN = 'boolean',\n NUMBER = 'number',\n JSON = 'json',\n}\n\nexport type BuildStepInputValueType<\n T extends BuildStepInputValueTypeName = BuildStepInputValueTypeName,\n> = T extends BuildStepInputValueTypeName.STRING\n ? string\n : T extends BuildStepInputValueTypeName.BOOLEAN\n ? boolean\n : T extends BuildStepInputValueTypeName.NUMBER\n ? number\n : Record<string, any>;\n\nexport type BuildStepInputValueTypeWithRequired<\n T extends BuildStepInputValueTypeName = BuildStepInputValueTypeName,\n R extends boolean = boolean,\n> = R extends true ? BuildStepInputValueType<T> : BuildStepInputValueType<T> | undefined;\n\nexport type BuildStepInputById = Record<string, BuildStepInput>;\nexport type BuildStepInputProvider = (\n ctx: BuildStepGlobalContext,\n stepId: string\n) => BuildStepInput;\n\ninterface BuildStepInputProviderParams<\n T extends BuildStepInputValueTypeName = BuildStepInputValueTypeName,\n R extends boolean = boolean,\n> {\n id: string;\n allowedValues?: BuildStepInputValueType<T>[];\n defaultValue?: BuildStepInputValueType<T>;\n required: R;\n allowedValueTypeName: T;\n}\n\ninterface BuildStepInputParams<T extends BuildStepInputValueTypeName, R extends boolean>\n extends BuildStepInputProviderParams<T, R> {\n stepDisplayName: string;\n}\n\nexport interface SerializedBuildStepInput<\n T extends BuildStepInputValueTypeName = BuildStepInputValueTypeName,\n R extends boolean = boolean,\n> {\n id: string;\n stepDisplayName: string;\n defaultValue?: BuildStepInputValueType<T>;\n allowedValues?: BuildStepInputValueType<T>[];\n allowedValueTypeName: BuildStepInputValueTypeName;\n required: R;\n value?: BuildStepInputValueType<T>;\n ctx: SerializedBuildStepGlobalContext;\n}\n\nexport class BuildStepInput<\n T extends BuildStepInputValueTypeName = BuildStepInputValueTypeName,\n R extends boolean = boolean,\n> {\n public readonly id: string;\n public readonly stepDisplayName: string;\n public readonly defaultValue?: BuildStepInputValueType<T>;\n public readonly allowedValues?: BuildStepInputValueType<T>[];\n public readonly allowedValueTypeName: T;\n public readonly required: R;\n\n private _value?: BuildStepInputValueType<T>;\n\n public static createProvider(params: BuildStepInputProviderParams): BuildStepInputProvider {\n return (ctx, stepDisplayName) => new BuildStepInput(ctx, { ...params, stepDisplayName });\n }\n\n constructor(\n private readonly ctx: BuildStepGlobalContext,\n {\n id,\n stepDisplayName,\n allowedValues,\n defaultValue,\n required,\n allowedValueTypeName,\n }: BuildStepInputParams<T, R>\n ) {\n this.id = id;\n this.stepDisplayName = stepDisplayName;\n this.allowedValues = allowedValues;\n this.defaultValue = defaultValue;\n this.required = required;\n this.allowedValueTypeName = allowedValueTypeName;\n }\n\n public get value(): BuildStepInputValueTypeWithRequired<T, R> {\n const rawValue = this._value ?? this.defaultValue;\n if (this.required && rawValue === undefined) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" is required but it was not set.`\n );\n }\n\n const valueDoesNotRequireInterpolation =\n rawValue === undefined ||\n typeof rawValue === 'boolean' ||\n typeof rawValue === 'number' ||\n typeof rawValue === 'object';\n if (valueDoesNotRequireInterpolation) {\n const currentTypeName =\n typeof rawValue === 'object' ? BuildStepInputValueTypeName.JSON : typeof rawValue;\n if (currentTypeName !== this.allowedValueTypeName && rawValue !== undefined) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" must be of type \"${this.allowedValueTypeName}\".`\n );\n }\n return rawValue as BuildStepInputValueTypeWithRequired<T, R>;\n } else {\n const valueInterpolatedWithGlobalContext = this.ctx.interpolate(rawValue);\n const valueInterpolatedWithOutputsAndGlobalContext = interpolateWithOutputs(\n valueInterpolatedWithGlobalContext,\n (path) => this.ctx.getStepOutputValue(path) ?? ''\n );\n return this.parseInputValueToAllowedType(valueInterpolatedWithOutputsAndGlobalContext);\n }\n }\n\n public get rawValue(): BuildStepInputValueType<T> | undefined {\n return this._value ?? this.defaultValue;\n }\n\n public set(value: BuildStepInputValueType<T> | undefined): BuildStepInput {\n if (this.required && value === undefined) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" is required.`\n );\n }\n\n this._value = value;\n return this;\n }\n\n public isValueOneOfAllowedValues(): boolean {\n const value = this._value ?? this.defaultValue;\n if (this.allowedValues === undefined || value === undefined) {\n return true;\n }\n return this.allowedValues.includes(value);\n }\n\n public isRawValueStepOrContextReference(): boolean {\n return (\n typeof this.rawValue === 'string' &&\n !!BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX.exec(this.rawValue)\n );\n }\n\n public serialize(): SerializedBuildStepInput<T, R> {\n return {\n id: this.id,\n stepDisplayName: this.stepDisplayName,\n defaultValue: this.defaultValue,\n allowedValues: this.allowedValues,\n allowedValueTypeName: this.allowedValueTypeName,\n required: this.required,\n value: this._value,\n ctx: this.ctx.serialize(),\n };\n }\n\n public static deserialize(\n serializedInput: SerializedBuildStepInput,\n logger: bunyan\n ): BuildStepInput {\n const deserializedContext = BuildStepGlobalContext.deserialize(serializedInput.ctx, logger);\n const input = new BuildStepInput(deserializedContext, {\n id: serializedInput.id,\n stepDisplayName: serializedInput.stepDisplayName,\n defaultValue: serializedInput.defaultValue,\n allowedValues: serializedInput.allowedValues,\n allowedValueTypeName: serializedInput.allowedValueTypeName,\n required: serializedInput.required,\n });\n input._value = serializedInput.value;\n return input;\n }\n\n private parseInputValueToAllowedType(value: string): BuildStepInputValueTypeWithRequired<T, R> {\n if (this.allowedValueTypeName === BuildStepInputValueTypeName.STRING) {\n return value as BuildStepInputValueTypeWithRequired<T, R>;\n } else if (this.allowedValueTypeName === BuildStepInputValueTypeName.NUMBER) {\n return this.parseInputValueToNumber(value) as BuildStepInputValueTypeWithRequired<T, R>;\n } else if (this.allowedValueTypeName === BuildStepInputValueTypeName.BOOLEAN) {\n return this.parseInputValueToBoolean(value) as BuildStepInputValueTypeWithRequired<T, R>;\n } else {\n return this.parseInputValueToObject(value) as BuildStepInputValueTypeWithRequired<T, R>;\n }\n }\n\n private parseInputValueToNumber(value: string): number {\n const numberValue = Number(value);\n if (Number.isNaN(numberValue)) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" must be of type \"${this.allowedValueTypeName}\".`\n );\n }\n return numberValue;\n }\n\n private parseInputValueToBoolean(value: string): boolean {\n if (value === 'true') {\n return true;\n } else if (value === 'false') {\n return false;\n } else {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" must be of type \"${this.allowedValueTypeName}\".`\n );\n }\n }\n\n private parseInputValueToObject(value: string): Record<string, any> {\n try {\n return JSON.parse(value);\n } catch (e: any) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" must be of type \"${this.allowedValueTypeName}\".`,\n {\n cause: e,\n }\n );\n }\n }\n}\n\nexport function makeBuildStepInputByIdMap(inputs?: BuildStepInput[]): BuildStepInputById {\n if (inputs === undefined) {\n return {};\n }\n return inputs.reduce((acc, input) => {\n acc[input.id] = input;\n return acc;\n }, {} as BuildStepInputById);\n}\n"]}
1
+ {"version":3,"file":"BuildStepInput.js","sourceRoot":"","sources":["../src/BuildStepInput.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAI5B,+DAAiG;AACjG,2CAAoD;AACpD,qDAG6B;AAE7B,IAAY,2BAKX;AALD,WAAY,2BAA2B;IACrC,gDAAiB,CAAA;IACjB,kDAAmB,CAAA;IACnB,gDAAiB,CAAA;IACjB,4CAAa,CAAA;AACf,CAAC,EALW,2BAA2B,2CAA3B,2BAA2B,QAKtC;AAqDD,MAAa,cAAc;IAalB,MAAM,CAAC,cAAc,CAAC,MAAoC;QAC/D,OAAO,CAAC,GAAG,EAAE,eAAe,EAAE,EAAE,CAAC,IAAI,cAAc,CAAC,GAAG,EAAE,EAAE,GAAG,MAAM,EAAE,eAAe,EAAE,CAAC,CAAC;IAC3F,CAAC;IAED,YACmB,GAA2B,EAC5C,EACE,EAAE,EACF,eAAe,EACf,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,oBAAoB,GACO;QARZ,QAAG,GAAH,GAAG,CAAwB;QAU5C,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC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;AAC/B,CAAC;AARD,8DAQC","sourcesContent":["import assert from 'assert';\n\nimport { bunyan } from '@expo/logger';\n\nimport { BuildStepGlobalContext, SerializedBuildStepGlobalContext } from './BuildStepContext.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport {\n BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX,\n interpolateWithOutputs,\n} from './utils/template.js';\n\nexport enum BuildStepInputValueTypeName {\n STRING = 'string',\n BOOLEAN = 'boolean',\n NUMBER = 'number',\n JSON = 'json',\n}\n\nexport type BuildStepInputValueType<\n T extends BuildStepInputValueTypeName = BuildStepInputValueTypeName,\n> = T extends BuildStepInputValueTypeName.STRING\n ? string\n : T extends BuildStepInputValueTypeName.BOOLEAN\n ? boolean\n : T extends BuildStepInputValueTypeName.NUMBER\n ? number\n : Record<string, any>;\n\nexport type BuildStepInputValueTypeWithRequired<\n T extends BuildStepInputValueTypeName = BuildStepInputValueTypeName,\n R extends boolean = boolean,\n> = R extends true ? BuildStepInputValueType<T> : BuildStepInputValueType<T> | undefined;\n\nexport type BuildStepInputById = Record<string, BuildStepInput>;\nexport type BuildStepInputProvider = (\n ctx: BuildStepGlobalContext,\n stepId: string\n) => BuildStepInput;\n\ninterface BuildStepInputProviderParams<\n T extends BuildStepInputValueTypeName = BuildStepInputValueTypeName,\n R extends boolean = boolean,\n> {\n id: string;\n allowedValues?: BuildStepInputValueType<T>[];\n defaultValue?: BuildStepInputValueType<T>;\n required: R;\n allowedValueTypeName: T;\n}\n\ninterface BuildStepInputParams<T extends BuildStepInputValueTypeName, R extends boolean>\n extends BuildStepInputProviderParams<T, R> {\n stepDisplayName: string;\n}\n\nexport interface SerializedBuildStepInput<\n T extends BuildStepInputValueTypeName = BuildStepInputValueTypeName,\n R extends boolean = boolean,\n> {\n id: string;\n stepDisplayName: string;\n defaultValue?: BuildStepInputValueType<T>;\n allowedValues?: BuildStepInputValueType<T>[];\n allowedValueTypeName: BuildStepInputValueTypeName;\n required: R;\n value?: BuildStepInputValueType<T>;\n ctx: SerializedBuildStepGlobalContext;\n}\n\nexport class BuildStepInput<\n T extends BuildStepInputValueTypeName = BuildStepInputValueTypeName,\n R extends boolean = boolean,\n> {\n public readonly id: string;\n public readonly stepDisplayName: string;\n public readonly defaultValue?: BuildStepInputValueType<T>;\n public readonly allowedValues?: BuildStepInputValueType<T>[];\n public readonly allowedValueTypeName: T;\n public readonly required: R;\n\n private _value?: BuildStepInputValueType<T>;\n\n public static createProvider(params: BuildStepInputProviderParams): BuildStepInputProvider {\n return (ctx, stepDisplayName) => new BuildStepInput(ctx, { ...params, stepDisplayName });\n }\n\n constructor(\n private readonly ctx: BuildStepGlobalContext,\n {\n id,\n stepDisplayName,\n allowedValues,\n defaultValue,\n required,\n allowedValueTypeName,\n }: BuildStepInputParams<T, R>\n ) {\n this.id = id;\n this.stepDisplayName = stepDisplayName;\n this.allowedValues = allowedValues;\n this.defaultValue = defaultValue;\n this.required = required;\n this.allowedValueTypeName = allowedValueTypeName;\n }\n\n public get value(): BuildStepInputValueTypeWithRequired<T, R> {\n const rawValue = this._value ?? this.defaultValue;\n if (this.required && rawValue === undefined) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" is required but it was not set.`\n );\n }\n\n const valueDoesNotRequireInterpolation =\n rawValue === undefined || typeof rawValue === 'boolean' || typeof rawValue === 'number';\n if (valueDoesNotRequireInterpolation) {\n if (typeof rawValue !== this.allowedValueTypeName && rawValue !== undefined) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" must be of type \"${this.allowedValueTypeName}\".`\n );\n }\n return rawValue as BuildStepInputValueTypeWithRequired<T, R>;\n } else {\n // `valueDoesNotRequireInterpolation` checks that `rawValue` is not undefined\n // so this will never be true.\n assert(rawValue !== undefined);\n const valueInterpolatedWithGlobalContext = this.ctx.interpolate(rawValue);\n const valueInterpolatedWithOutputsAndGlobalContext = interpolateWithOutputs(\n valueInterpolatedWithGlobalContext,\n (path) => this.ctx.getStepOutputValue(path) ?? ''\n );\n return this.parseInputValueToAllowedType(valueInterpolatedWithOutputsAndGlobalContext);\n }\n }\n\n public get rawValue(): BuildStepInputValueType<T> | undefined {\n return this._value ?? this.defaultValue;\n }\n\n public set(value: BuildStepInputValueType<T> | undefined): BuildStepInput {\n if (this.required && value === undefined) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" is required.`\n );\n }\n\n this._value = value;\n return this;\n }\n\n public isValueOneOfAllowedValues(): boolean {\n const value = this._value ?? this.defaultValue;\n if (this.allowedValues === undefined || value === undefined) {\n return true;\n }\n return this.allowedValues.includes(value);\n }\n\n public isRawValueStepOrContextReference(): boolean {\n return (\n typeof this.rawValue === 'string' &&\n !!BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX.exec(this.rawValue)\n );\n }\n\n public serialize(): SerializedBuildStepInput<T, R> {\n return {\n id: this.id,\n stepDisplayName: this.stepDisplayName,\n defaultValue: this.defaultValue,\n allowedValues: this.allowedValues,\n allowedValueTypeName: this.allowedValueTypeName,\n required: this.required,\n value: this._value,\n ctx: this.ctx.serialize(),\n };\n }\n\n public static deserialize(\n serializedInput: SerializedBuildStepInput,\n logger: bunyan\n ): BuildStepInput {\n const deserializedContext = BuildStepGlobalContext.deserialize(serializedInput.ctx, logger);\n const input = new BuildStepInput(deserializedContext, {\n id: serializedInput.id,\n stepDisplayName: serializedInput.stepDisplayName,\n defaultValue: serializedInput.defaultValue,\n allowedValues: serializedInput.allowedValues,\n allowedValueTypeName: serializedInput.allowedValueTypeName,\n required: serializedInput.required,\n });\n input._value = serializedInput.value;\n return input;\n }\n\n private parseInputValueToAllowedType(\n value: string | object\n ): BuildStepInputValueTypeWithRequired<T, R> {\n if (typeof value === 'object') {\n return value as BuildStepInputValueTypeWithRequired<T, R>;\n }\n if (this.allowedValueTypeName === BuildStepInputValueTypeName.STRING) {\n return value as BuildStepInputValueTypeWithRequired<T, R>;\n } else if (this.allowedValueTypeName === BuildStepInputValueTypeName.NUMBER) {\n return this.parseInputValueToNumber(value) as BuildStepInputValueTypeWithRequired<T, R>;\n } else if (this.allowedValueTypeName === BuildStepInputValueTypeName.BOOLEAN) {\n return this.parseInputValueToBoolean(value) as BuildStepInputValueTypeWithRequired<T, R>;\n } else {\n return this.parseInputValueToObject(value) as BuildStepInputValueTypeWithRequired<T, R>;\n }\n }\n\n private parseInputValueToNumber(value: string): number {\n const numberValue = Number(value);\n if (Number.isNaN(numberValue)) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" must be of type \"${this.allowedValueTypeName}\".`\n );\n }\n return numberValue;\n }\n\n private parseInputValueToBoolean(value: string): boolean {\n if (value === 'true') {\n return true;\n } else if (value === 'false') {\n return false;\n } else {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" must be of type \"${this.allowedValueTypeName}\".`\n );\n }\n }\n\n private parseInputValueToObject(value: string): Record<string, any> {\n try {\n return JSON.parse(value);\n } catch (e: any) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" must be of type \"${this.allowedValueTypeName}\".`,\n {\n cause: e,\n }\n );\n }\n }\n}\n\nexport function makeBuildStepInputByIdMap(inputs?: BuildStepInput[]): BuildStepInputById {\n if (inputs === undefined) {\n return {};\n }\n return inputs.reduce((acc, input) => {\n acc[input.id] = input;\n return acc;\n }, {} as BuildStepInputById);\n}\n"]}
@@ -3,8 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.parseOutputPath = exports.findOutputPaths = exports.interpolateWithGlobalContext = exports.getObjectValueForInterpolation = exports.getSelectedStatusCheckFromIfStatementTemplate = exports.interpolateWithOutputs = exports.interpolateWithInputs = exports.BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP = exports.BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX = exports.BUILD_GLOBAL_CONTEXT_EXPRESSION_REGEXP = exports.BUILD_STEP_OUTPUT_EXPRESSION_REGEXP = exports.BUILD_STEP_INPUT_EXPRESSION_REGEXP = void 0;
6
+ exports.parseOutputPath = exports.findOutputPaths = exports.interpolateObjectWithGlobalContext = exports.interpolateStringWithGlobalContext = exports.interpolateWithGlobalContext = exports.getObjectValueForInterpolation = exports.getSelectedStatusCheckFromIfStatementTemplate = exports.interpolateObjectWithOutputs = exports.interpolateStringWithOutputs = exports.interpolateWithOutputs = exports.interpolateWithInputs = exports.BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP = exports.BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX = exports.BUILD_GLOBAL_CONTEXT_EXPRESSION_REGEXP = exports.BUILD_STEP_OUTPUT_EXPRESSION_REGEXP = exports.BUILD_STEP_INPUT_EXPRESSION_REGEXP = void 0;
7
7
  const lodash_get_1 = __importDefault(require("lodash.get"));
8
+ const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
8
9
  const BuildStepInput_js_1 = require("../BuildStepInput.cjs");
9
10
  const errors_js_1 = require("../errors.cjs");
10
11
  const nullthrows_js_1 = require("./nullthrows.cjs");
@@ -17,10 +18,31 @@ function interpolateWithInputs(templateString, inputs) {
17
18
  return interpolate(templateString, exports.BUILD_STEP_INPUT_EXPRESSION_REGEXP, inputs);
18
19
  }
19
20
  exports.interpolateWithInputs = interpolateWithInputs;
20
- function interpolateWithOutputs(templateString, fn) {
21
- return interpolate(templateString, exports.BUILD_STEP_OUTPUT_EXPRESSION_REGEXP, fn);
21
+ function interpolateWithOutputs(interpolableValue, fn) {
22
+ if (typeof interpolableValue === 'string') {
23
+ return interpolateStringWithOutputs(interpolableValue, fn);
24
+ }
25
+ else {
26
+ return interpolateObjectWithOutputs(interpolableValue, fn);
27
+ }
22
28
  }
23
29
  exports.interpolateWithOutputs = interpolateWithOutputs;
30
+ function interpolateStringWithOutputs(templateString, fn) {
31
+ return interpolate(templateString, exports.BUILD_STEP_OUTPUT_EXPRESSION_REGEXP, fn);
32
+ }
33
+ exports.interpolateStringWithOutputs = interpolateStringWithOutputs;
34
+ function interpolateObjectWithOutputs(interpolableObject, fn) {
35
+ const interpolableObjectCopy = (0, lodash_clonedeep_1.default)(interpolableObject);
36
+ Object.keys(interpolableObject).forEach((property) => {
37
+ const propertyValue = interpolableObject[property];
38
+ if (['string', 'object'].includes(typeof propertyValue)) {
39
+ interpolableObjectCopy[property] =
40
+ interpolateWithOutputs(propertyValue, fn);
41
+ }
42
+ });
43
+ return interpolableObjectCopy;
44
+ }
45
+ exports.interpolateObjectWithOutputs = interpolateObjectWithOutputs;
24
46
  /**
25
47
  * Returns the selected status check from the if statement template.
26
48
  * Example: `${ success() }` -> `success`
@@ -49,10 +71,31 @@ function getObjectValueForInterpolation(path, obj) {
49
71
  return value;
50
72
  }
51
73
  exports.getObjectValueForInterpolation = getObjectValueForInterpolation;
52
- function interpolateWithGlobalContext(templateString, fn) {
53
- return interpolate(templateString, exports.BUILD_GLOBAL_CONTEXT_EXPRESSION_REGEXP, fn);
74
+ function interpolateWithGlobalContext(interpolableValue, fn) {
75
+ if (typeof interpolableValue === 'string') {
76
+ return interpolateStringWithGlobalContext(interpolableValue, fn);
77
+ }
78
+ else {
79
+ return interpolateObjectWithGlobalContext(interpolableValue, fn);
80
+ }
54
81
  }
55
82
  exports.interpolateWithGlobalContext = interpolateWithGlobalContext;
83
+ function interpolateStringWithGlobalContext(templateString, fn) {
84
+ return interpolate(templateString, exports.BUILD_GLOBAL_CONTEXT_EXPRESSION_REGEXP, fn);
85
+ }
86
+ exports.interpolateStringWithGlobalContext = interpolateStringWithGlobalContext;
87
+ function interpolateObjectWithGlobalContext(templateObject, fn) {
88
+ const templateObjectCopy = (0, lodash_clonedeep_1.default)(templateObject);
89
+ Object.keys(templateObject).forEach((property) => {
90
+ const propertyValue = templateObject[property];
91
+ if (['string', 'object'].includes(typeof propertyValue)) {
92
+ templateObjectCopy[property] =
93
+ interpolateWithGlobalContext(propertyValue, fn);
94
+ }
95
+ });
96
+ return templateObjectCopy;
97
+ }
98
+ exports.interpolateObjectWithGlobalContext = interpolateObjectWithGlobalContext;
56
99
  function interpolate(templateString, regex, varsOrFn) {
57
100
  const matched = templateString.match(new RegExp(regex, 'g'));
58
101
  if (!matched) {
@@ -4,14 +4,18 @@ export declare const BUILD_GLOBAL_CONTEXT_EXPRESSION_REGEXP: RegExp;
4
4
  export declare const BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX: RegExp;
5
5
  export declare const BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP: RegExp;
6
6
  export declare function interpolateWithInputs(templateString: string, inputs: Record<string, string>): string;
7
- export declare function interpolateWithOutputs(templateString: string, fn: (path: string) => string): string;
7
+ export declare function interpolateWithOutputs<InterpolableType extends string | object>(interpolableValue: InterpolableType, fn: (path: string) => string): InterpolableType;
8
+ export declare function interpolateStringWithOutputs(templateString: string, fn: (path: string) => string): string;
9
+ export declare function interpolateObjectWithOutputs(interpolableObject: object, fn: (path: string) => string): object;
8
10
  /**
9
11
  * Returns the selected status check from the if statement template.
10
12
  * Example: `${ success() }` -> `success`
11
13
  */
12
14
  export declare function getSelectedStatusCheckFromIfStatementTemplate(ifCondition: string): 'success' | 'failure' | 'always' | 'never';
13
15
  export declare function getObjectValueForInterpolation(path: string, obj: Record<string, unknown>): string | number | boolean | null;
14
- export declare function interpolateWithGlobalContext(templateString: string, fn: (path: string) => string): string;
16
+ export declare function interpolateWithGlobalContext<InterpolableType extends string | object>(interpolableValue: InterpolableType, fn: (path: string) => string): InterpolableType;
17
+ export declare function interpolateStringWithGlobalContext(templateString: string, fn: (path: string) => string): string;
18
+ export declare function interpolateObjectWithGlobalContext(templateObject: object, fn: (path: string) => string): object;
15
19
  interface BuildOutputPath {
16
20
  stepId: string;
17
21
  outputId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/utils/template.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA6B;AAE7B,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,cAAsB,EACtB,EAA4B;IAE5B,OAAO,WAAW,CAAC,cAAc,EAAE,2CAAmC,EAAE,EAAE,CAAC,CAAC;AAC9E,CAAC;AALD,wDAKC;AAED;;;GAGG;AACH,SAAgB,6CAA6C,CAC3D,WAAmB;IAEnB,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,iDAAyC,EAAE,GAAG,CAAC,CAAC,CAAC;IAC9F,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,+DAA+D;QAC/D,MAAM,IAAI,4BAAgB,CAAC,gCAAgC,CAAC,CAAC;IAC/D,CAAC;IACD,MAAM,CAAC,EAAE,mBAAmB,CAAC,GAAG,IAAA,0BAAU,EACxC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,iDAAyC,CAAC,CAC5D,CAAC;IACF,OAAO,mBAAiE,CAAC;AAC3E,CAAC;AAZD,sGAYC;AAED,SAAgB,8BAA8B,CAC5C,IAAY,EACZ,GAA4B;IAE5B,MAAM,KAAK,GAAG,IAAA,oBAAG,EAAC,GA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\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(\n templateString: string,\n fn: (path: string) => string\n): string {\n return interpolate(templateString, BUILD_STEP_OUTPUT_EXPRESSION_REGEXP, fn);\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(\n templateString: string,\n fn: (path: string) => string\n): string {\n return interpolate(templateString, BUILD_GLOBAL_CONTEXT_EXPRESSION_REGEXP, fn);\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;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,CAAC;IACjF,CAAC;SAAM,CAAC;QACN,OAAO,4BAA4B,CAAC,iBAAiB,EAAE,EAAE,CAAqB,CAAC;IACjF,CAAC;AACH,CAAC;AATD,wDASC;AAED,SAAgB,4BAA4B,CAC1C,cAAsB,EACtB,EAA4B;IAE5B,OAAO,WAAW,CAAC,cAAc,EAAE,2CAAmC,EAAE,EAAE,CAAC,CAAC;AAC9E,CAAC;AALD,oEAKC;AAED,SAAgB,4BAA4B,CAC1C,kBAA0B,EAC1B,EAA4B;IAE5B,MAAM,sBAAsB,GAAG,IAAA,0BAAS,EAAC,kBAAkB,CAAC,CAAC;IAC7D,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;QACnD,MAAM,aAAa,GAAG,kBAAkB,CAAC,QAA2C,CAAC,CAAC;QACtF,IAAI,C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G,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"]}
@@ -47,7 +47,7 @@ export declare class BuildStepGlobalContext {
47
47
  updateEnv(updatedEnv: BuildStepEnv): void;
48
48
  registerStep(step: BuildStep): void;
49
49
  getStepOutputValue(path: string): string | undefined;
50
- interpolate(value: string): string;
50
+ interpolate<InterpolableType extends string | object>(value: InterpolableType): InterpolableType;
51
51
  stepCtx(options: {
52
52
  logger: bunyan;
53
53
  relativeWorkingDirectory?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"BuildStepContext.js","sourceRoot":"","sources":["../src/BuildStepContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAEL,uBAAuB,GAExB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,EAC5B,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAmCpD,MAAM,OAAO,sBAAsB;IAQjC,YACmB,QAAsC,EACvC,WAAoB;QADnB,aAAQ,GAAR,QAAQ,CAA8B;QACvC,gBAAW,GAAX,WAAW,CAAS;QAN9B,gBAAW,GAAG,KAAK,CAAC;QAEpB,aAAQ,GAA4C,EAAE,CAAC;QAM7D,IAAI,CAAC,2BAA2B,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;QACjF,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC,eAAe,CAAC;QAChD,IAAI,CAAC,UAAU,GA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AAC,UAAU,CAAC;QACvC,IAAI,CAAC,wBAAwB,GAAG,wBAAwB,CAAC;IAC3D,CAAC;IAED,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,IAAW,gBAAgB;QACzB,OAAO,IAAI,CAAC,wBAAwB;YAClC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,uBAAuB,EAAE,IAAI,CAAC,wBAAwB,CAAC;YAC/E,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,uBAAuB,CAAC;IACvC,CAAC;IAEM,SAAS;QACd,OAAO;YACL,wBAAwB,EAAE,IAAI,CAAC,wBAAwB;YACvD,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE;SAC7B,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,WAAW,CACvB,UAAsC,EACtC,MAAc;QAEd,MAAM,kBAAkB,GAAG,sBAAsB,CAAC,WAAW,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACzF,OAAO,IAAI,gBAAgB,CAAC,kBAAkB,EAAE;YAC9C,MAAM;YACN,wBAAwB,EAAE,UAAU,CAAC,wBAAwB;SAC9D,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import os from 'os';\nimport path from 'path';\n\nimport { BuildStaticContext } from '@expo/eas-build-job';\nimport { bunyan } from '@expo/logger';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport {\n BuildStep,\n BuildStepOutputAccessor,\n SerializedBuildStepOutputAccessor,\n} from './BuildStep.js';\nimport {\n getObjectValueForInterpolation,\n interpolateWithGlobalContext,\n parseOutputPath,\n} from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\n\ninterface SerializedExternalBuildContextProvider {\n projectSourceDirectory: string;\n projectTargetDirectory: string;\n defaultWorkingDirectory: string;\n buildLogsDirectory: string;\n runtimePlatform: BuildRuntimePlatform;\n staticContext: BuildStaticContext;\n env: BuildStepEnv;\n}\n\nexport interface ExternalBuildContextProvider {\n readonly projectSourceDirectory: string;\n readonly projectTargetDirectory: string;\n readonly defaultWorkingDirectory: string;\n readonly buildLogsDirectory: string;\n readonly runtimePlatform: BuildRuntimePlatform;\n readonly logger: bunyan;\n\n readonly staticContext: () => BuildStaticContext;\n\n readonly env: BuildStepEnv;\n updateEnv(env: BuildStepEnv): void;\n}\n\nexport interface SerializedBuildStepGlobalContext {\n stepsInternalBuildDirectory: string;\n stepById: Record<string, SerializedBuildStepOutputAccessor>;\n provider: SerializedExternalBuildContextProvider;\n skipCleanup: boolean;\n}\n\nexport class BuildStepGlobalContext {\n public stepsInternalBuildDirectory: string;\n public readonly runtimePlatform: BuildRuntimePlatform;\n public readonly baseLogger: bunyan;\n private didCheckOut = false;\n\n private stepById: Record<string, BuildStepOutputAccessor> = {};\n\n constructor(\n private readonly provider: ExternalBuildContextProvider,\n public readonly skipCleanup: boolean\n ) {\n this.stepsInternalBuildDirectory = path.join(os.tmpdir(), 'eas-build', uuidv4());\n this.runtimePlatform = provider.runtimePlatform;\n this.baseLogger = provider.logger;\n }\n\n public get projectSourceDirectory(): string {\n return this.provider.projectSourceDirectory;\n }\n\n public get projectTargetDirectory(): string {\n return this.provider.projectTargetDirectory;\n }\n\n public get defaultWorkingDirectory(): string {\n return this.didCheckOut ? this.provider.defaultWorkingDirectory : this.projectTargetDirectory;\n }\n\n public get buildLogsDirectory(): string {\n return this.provider.buildLogsDirectory;\n }\n\n public get env(): BuildStepEnv {\n return this.provider.env;\n }\n\n public get staticContext(): BuildStaticContext {\n return this.provider.staticContext();\n }\n\n public updateEnv(updatedEnv: BuildStepEnv): void {\n this.provider.updateEnv(updatedEnv);\n }\n\n public registerStep(step: BuildStep): void {\n this.stepById[step.id] = step;\n }\n\n public getStepOutputValue(path: string): string | undefined {\n const { stepId, outputId } = parseOutputPath(path);\n if (!(stepId in this.stepById)) {\n throw new BuildStepRuntimeError(`Step \"${stepId}\" does not exist.`);\n }\n return this.stepById[stepId].getOutputValueByName(outputId);\n }\n\n public interpolate(value: string): string {\n return interpolateWithGlobalContext(value, (path) => {\n return (\n getObjectValueForInterpolation(path, {\n eas: {\n runtimePlatform: this.runtimePlatform,\n ...this.staticContext,\n },\n })?.toString() ?? ''\n );\n });\n }\n\n public stepCtx(options: { logger: bunyan; relativeWorkingDirectory?: string }): BuildStepContext {\n return new BuildStepContext(this, options);\n }\n\n public markAsCheckedOut(logger: bunyan): void {\n this.didCheckOut = true;\n logger.info(\n `Changing default working directory to ${this.defaultWorkingDirectory} (was ${this.projectTargetDirectory})`\n );\n }\n\n public serialize(): SerializedBuildStepGlobalContext {\n return {\n stepsInternalBuildDirectory: this.stepsInternalBuildDirectory,\n stepById: Object.fromEntries(\n Object.entries(this.stepById).map(([id, step]) => [id, step.serialize()])\n ),\n provider: {\n projectSourceDirectory: this.provider.projectSourceDirectory,\n projectTargetDirectory: this.provider.projectTargetDirectory,\n defaultWorkingDirectory: this.provider.defaultWorkingDirectory,\n buildLogsDirectory: this.provider.buildLogsDirectory,\n runtimePlatform: this.provider.runtimePlatform,\n staticContext: this.provider.staticContext(),\n env: this.provider.env,\n },\n skipCleanup: this.skipCleanup,\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepGlobalContext,\n logger: bunyan\n ): BuildStepGlobalContext {\n const deserializedProvider: ExternalBuildContextProvider = {\n projectSourceDirectory: serialized.provider.projectSourceDirectory,\n projectTargetDirectory: serialized.provider.projectTargetDirectory,\n defaultWorkingDirectory: serialized.provider.defaultWorkingDirectory,\n buildLogsDirectory: serialized.provider.buildLogsDirectory,\n runtimePlatform: serialized.provider.runtimePlatform,\n logger,\n staticContext: () => serialized.provider.staticContext,\n env: serialized.provider.env,\n updateEnv: () => {},\n };\n const ctx = new BuildStepGlobalContext(deserializedProvider, serialized.skipCleanup);\n for (const [id, stepOutputAccessor] of Object.entries(serialized.stepById)) {\n ctx.stepById[id] = BuildStepOutputAccessor.deserialize(stepOutputAccessor);\n }\n ctx.stepsInternalBuildDirectory = serialized.stepsInternalBuildDirectory;\n\n return ctx;\n }\n}\n\nexport interface SerializedBuildStepContext {\n relativeWorkingDirectory?: string;\n global: SerializedBuildStepGlobalContext;\n}\n\nexport class BuildStepContext {\n public readonly logger: bunyan;\n public readonly relativeWorkingDirectory?: string;\n\n constructor(\n private readonly ctx: BuildStepGlobalContext,\n {\n logger,\n relativeWorkingDirectory,\n }: {\n logger: bunyan;\n relativeWorkingDirectory?: string;\n }\n ) {\n this.logger = logger ?? ctx.baseLogger;\n this.relativeWorkingDirectory = relativeWorkingDirectory;\n }\n\n public get global(): BuildStepGlobalContext {\n return this.ctx;\n }\n\n public get workingDirectory(): string {\n return this.relativeWorkingDirectory\n ? path.resolve(this.ctx.defaultWorkingDirectory, this.relativeWorkingDirectory)\n : this.ctx.defaultWorkingDirectory;\n }\n\n public serialize(): SerializedBuildStepContext {\n return {\n relativeWorkingDirectory: this.relativeWorkingDirectory,\n global: this.ctx.serialize(),\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepContext,\n logger: bunyan\n ): BuildStepContext {\n const deserializedGlobal = BuildStepGlobalContext.deserialize(serialized.global, logger);\n return new BuildStepContext(deserializedGlobal, {\n logger,\n relativeWorkingDirectory: serialized.relativeWorkingDirectory,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"BuildStepContext.js","sourceRoot":"","sources":["../src/BuildStepContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAEL,uBAAuB,GAExB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,EAC5B,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,E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esContent":["import os from 'os';\nimport path from 'path';\n\nimport { BuildStaticContext } from '@expo/eas-build-job';\nimport { bunyan } from '@expo/logger';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport {\n BuildStep,\n BuildStepOutputAccessor,\n SerializedBuildStepOutputAccessor,\n} from './BuildStep.js';\nimport {\n getObjectValueForInterpolation,\n interpolateWithGlobalContext,\n parseOutputPath,\n} from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\n\ninterface SerializedExternalBuildContextProvider {\n projectSourceDirectory: string;\n projectTargetDirectory: string;\n defaultWorkingDirectory: string;\n buildLogsDirectory: string;\n runtimePlatform: BuildRuntimePlatform;\n staticContext: BuildStaticContext;\n env: BuildStepEnv;\n}\n\nexport interface ExternalBuildContextProvider {\n readonly projectSourceDirectory: string;\n readonly projectTargetDirectory: string;\n readonly defaultWorkingDirectory: string;\n readonly buildLogsDirectory: string;\n readonly runtimePlatform: BuildRuntimePlatform;\n readonly logger: bunyan;\n\n readonly staticContext: () => BuildStaticContext;\n\n readonly env: BuildStepEnv;\n updateEnv(env: BuildStepEnv): void;\n}\n\nexport interface SerializedBuildStepGlobalContext {\n stepsInternalBuildDirectory: string;\n stepById: Record<string, SerializedBuildStepOutputAccessor>;\n provider: SerializedExternalBuildContextProvider;\n skipCleanup: boolean;\n}\n\nexport class BuildStepGlobalContext {\n public stepsInternalBuildDirectory: string;\n public readonly runtimePlatform: BuildRuntimePlatform;\n public readonly baseLogger: bunyan;\n private didCheckOut = false;\n\n private stepById: Record<string, BuildStepOutputAccessor> = {};\n\n constructor(\n private readonly provider: ExternalBuildContextProvider,\n public readonly skipCleanup: boolean\n ) {\n this.stepsInternalBuildDirectory = path.join(os.tmpdir(), 'eas-build', uuidv4());\n this.runtimePlatform = provider.runtimePlatform;\n this.baseLogger = provider.logger;\n }\n\n public get projectSourceDirectory(): string {\n return this.provider.projectSourceDirectory;\n }\n\n public get projectTargetDirectory(): string {\n return this.provider.projectTargetDirectory;\n }\n\n public get defaultWorkingDirectory(): string {\n return this.didCheckOut ? this.provider.defaultWorkingDirectory : this.projectTargetDirectory;\n }\n\n public get buildLogsDirectory(): string {\n return this.provider.buildLogsDirectory;\n }\n\n public get env(): BuildStepEnv {\n return this.provider.env;\n }\n\n public get staticContext(): BuildStaticContext {\n return this.provider.staticContext();\n }\n\n public updateEnv(updatedEnv: BuildStepEnv): void {\n this.provider.updateEnv(updatedEnv);\n }\n\n public registerStep(step: BuildStep): void {\n this.stepById[step.id] = step;\n }\n\n public getStepOutputValue(path: string): string | undefined {\n const { stepId, outputId } = parseOutputPath(path);\n if (!(stepId in this.stepById)) {\n throw new BuildStepRuntimeError(`Step \"${stepId}\" does not exist.`);\n }\n return this.stepById[stepId].getOutputValueByName(outputId);\n }\n\n public interpolate<InterpolableType extends string | object>(\n value: InterpolableType\n ): InterpolableType {\n return interpolateWithGlobalContext(value, (path) => {\n return (\n getObjectValueForInterpolation(path, {\n eas: {\n runtimePlatform: this.runtimePlatform,\n ...this.staticContext,\n },\n })?.toString() ?? ''\n );\n });\n }\n\n public stepCtx(options: { logger: bunyan; relativeWorkingDirectory?: string }): BuildStepContext {\n return new BuildStepContext(this, options);\n }\n\n public markAsCheckedOut(logger: bunyan): void {\n this.didCheckOut = true;\n logger.info(\n `Changing default working directory to ${this.defaultWorkingDirectory} (was ${this.projectTargetDirectory})`\n );\n }\n\n public serialize(): SerializedBuildStepGlobalContext {\n return {\n stepsInternalBuildDirectory: this.stepsInternalBuildDirectory,\n stepById: Object.fromEntries(\n Object.entries(this.stepById).map(([id, step]) => [id, step.serialize()])\n ),\n provider: {\n projectSourceDirectory: this.provider.projectSourceDirectory,\n projectTargetDirectory: this.provider.projectTargetDirectory,\n defaultWorkingDirectory: this.provider.defaultWorkingDirectory,\n buildLogsDirectory: this.provider.buildLogsDirectory,\n runtimePlatform: this.provider.runtimePlatform,\n staticContext: this.provider.staticContext(),\n env: this.provider.env,\n },\n skipCleanup: this.skipCleanup,\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepGlobalContext,\n logger: bunyan\n ): BuildStepGlobalContext {\n const deserializedProvider: ExternalBuildContextProvider = {\n projectSourceDirectory: serialized.provider.projectSourceDirectory,\n projectTargetDirectory: serialized.provider.projectTargetDirectory,\n defaultWorkingDirectory: serialized.provider.defaultWorkingDirectory,\n buildLogsDirectory: serialized.provider.buildLogsDirectory,\n runtimePlatform: serialized.provider.runtimePlatform,\n logger,\n staticContext: () => serialized.provider.staticContext,\n env: serialized.provider.env,\n updateEnv: () => {},\n };\n const ctx = new BuildStepGlobalContext(deserializedProvider, serialized.skipCleanup);\n for (const [id, stepOutputAccessor] of Object.entries(serialized.stepById)) {\n ctx.stepById[id] = BuildStepOutputAccessor.deserialize(stepOutputAccessor);\n }\n ctx.stepsInternalBuildDirectory = serialized.stepsInternalBuildDirectory;\n\n return ctx;\n }\n}\n\nexport interface SerializedBuildStepContext {\n relativeWorkingDirectory?: string;\n global: SerializedBuildStepGlobalContext;\n}\n\nexport class BuildStepContext {\n public readonly logger: bunyan;\n public readonly relativeWorkingDirectory?: string;\n\n constructor(\n private readonly ctx: BuildStepGlobalContext,\n {\n logger,\n relativeWorkingDirectory,\n }: {\n logger: bunyan;\n relativeWorkingDirectory?: string;\n }\n ) {\n this.logger = logger ?? ctx.baseLogger;\n this.relativeWorkingDirectory = relativeWorkingDirectory;\n }\n\n public get global(): BuildStepGlobalContext {\n return this.ctx;\n }\n\n public get workingDirectory(): string {\n return this.relativeWorkingDirectory\n ? path.resolve(this.ctx.defaultWorkingDirectory, this.relativeWorkingDirectory)\n : this.ctx.defaultWorkingDirectory;\n }\n\n public serialize(): SerializedBuildStepContext {\n return {\n relativeWorkingDirectory: this.relativeWorkingDirectory,\n global: this.ctx.serialize(),\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepContext,\n logger: bunyan\n ): BuildStepContext {\n const deserializedGlobal = BuildStepGlobalContext.deserialize(serialized.global, logger);\n return new BuildStepContext(deserializedGlobal, {\n logger,\n relativeWorkingDirectory: serialized.relativeWorkingDirectory,\n });\n }\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import assert from 'assert';
1
2
  import { BuildStepGlobalContext } from './BuildStepContext.js';
2
3
  import { BuildStepRuntimeError } from './errors.js';
3
4
  import { BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX, interpolateWithOutputs, } from './utils/template.js';
@@ -27,18 +28,17 @@ export class BuildStepInput {
27
28
  if (this.required && rawValue === undefined) {
28
29
  throw new BuildStepRuntimeError(`Input parameter "${this.id}" for step "${this.stepDisplayName}" is required but it was not set.`);
29
30
  }
30
- const valueDoesNotRequireInterpolation = rawValue === undefined ||
31
- typeof rawValue === 'boolean' ||
32
- typeof rawValue === 'number' ||
33
- typeof rawValue === 'object';
31
+ const valueDoesNotRequireInterpolation = rawValue === undefined || typeof rawValue === 'boolean' || typeof rawValue === 'number';
34
32
  if (valueDoesNotRequireInterpolation) {
35
- const currentTypeName = typeof rawValue === 'object' ? BuildStepInputValueTypeName.JSON : typeof rawValue;
36
- if (currentTypeName !== this.allowedValueTypeName && rawValue !== undefined) {
33
+ if (typeof rawValue !== this.allowedValueTypeName && rawValue !== undefined) {
37
34
  throw new BuildStepRuntimeError(`Input parameter "${this.id}" for step "${this.stepDisplayName}" must be of type "${this.allowedValueTypeName}".`);
38
35
  }
39
36
  return rawValue;
40
37
  }
41
38
  else {
39
+ // `valueDoesNotRequireInterpolation` checks that `rawValue` is not undefined
40
+ // so this will never be true.
41
+ assert(rawValue !== undefined);
42
42
  const valueInterpolatedWithGlobalContext = this.ctx.interpolate(rawValue);
43
43
  const valueInterpolatedWithOutputsAndGlobalContext = interpolateWithOutputs(valueInterpolatedWithGlobalContext, (path) => { var _a; return (_a = this.ctx.getStepOutputValue(path)) !== null && _a !== void 0 ? _a : ''; });
44
44
  return this.parseInputValueToAllowedType(valueInterpolatedWithOutputsAndGlobalContext);
@@ -93,6 +93,9 @@ export class BuildStepInput {
93
93
  return input;
94
94
  }
95
95
  parseInputValueToAllowedType(value) {
96
+ if (typeof value === 'object') {
97
+ return value;
98
+ }
96
99
  if (this.allowedValueTypeName === BuildStepInputValueTypeName.STRING) {
97
100
  return value;
98
101
  }
@@ -1 +1 @@
1
- {"version":3,"file":"BuildStepInput.js","sourceRoot":"","sources":["../src/BuildStepInput.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAoC,MAAM,uBAAuB,CAAC;AACjG,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,kDAAkD,EAClD,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,CAAN,IAAY,2BAKX;AALD,WAAY,2BAA2B;IACrC,gDAAiB,CAAA;IACjB,kDAAmB,CAAA;IACnB,gDAAiB,CAAA;IACjB,4CAAa,CAAA;AACf,CAAC,EALW,2BAA2B,KAA3B,2BAA2B,QAKtC;AAqDD,MAAM,OAAO,cAAc;IAalB,MAAM,CAAC,cAAc,CAAC,MAAoC;QAC/D,OAAO,CAAC,GAAG,EAAE,eAAe,EAAE,EAAE,CAAC,IAAI,cAAc,CAAC,GAAG,EAAE,EAAE,GAAG,MAAM,EAAE,eAAe,EAAE,CAAC,CAAC;IAC3F,CAAC;IAED,YACmB,GAA2B,EAC5C,EACE,EAAE,EACF,eAAe,EACf,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,oBAAoB,GACO;QARZ,QAAG,GAAH,GAAG,CAAwB;QAU5C,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC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AI,CAAC,eAAe,sBAAsB,IAAI,CAAC,oBAAoB,IAAI,CAClH,CAAC;QACJ,CAAC;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IAEO,wBAAwB,CAAC,KAAa;QAC5C,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC;QACd,CAAC;aAAM,IAAI,KAAK,KAAK,OAAO,EAAE,CAAC;YAC7B,OAAO,KAAK,CAAC;QACf,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,qBAAqB,CAC7B,oBAAoB,IAAI,CAAC,EAAE,eAAe,IAAI,CAAC,eAAe,sBAAsB,IAAI,CAAC,oBAAoB,IAAI,CAClH,CAAC;QACJ,CAAC;IACH,CAAC;IAEO,uBAAuB,CAAC,KAAa;QAC3C,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,MAAM,IAAI,qBAAqB,CAC7B,oBAAoB,IAAI,CAAC,EAAE,eAAe,IAAI,CAAC,eAAe,sBAAsB,IAAI,CAAC,oBAAoB,IAAI,EACjH;gBACE,KAAK,EAAE,CAAC;aACT,CACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAED,MAAM,UAAU,yBAAyB,CAAC,MAAyB;IACjE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAClC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC;QACtB,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAwB,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import { bunyan } from '@expo/logger';\n\nimport { BuildStepGlobalContext, SerializedBuildStepGlobalContext } from './BuildStepContext.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport {\n BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX,\n interpolateWithOutputs,\n} from './utils/template.js';\n\nexport enum BuildStepInputValueTypeName {\n STRING = 'string',\n BOOLEAN = 'boolean',\n NUMBER = 'number',\n JSON = 'json',\n}\n\nexport type BuildStepInputValueType<\n T extends BuildStepInputValueTypeName = BuildStepInputValueTypeName,\n> = T extends BuildStepInputValueTypeName.STRING\n ? string\n : T extends BuildStepInputValueTypeName.BOOLEAN\n ? boolean\n : T extends BuildStepInputValueTypeName.NUMBER\n ? number\n : Record<string, any>;\n\nexport type BuildStepInputValueTypeWithRequired<\n T extends BuildStepInputValueTypeName = BuildStepInputValueTypeName,\n R extends boolean = boolean,\n> = R extends true ? BuildStepInputValueType<T> : BuildStepInputValueType<T> | undefined;\n\nexport type BuildStepInputById = Record<string, BuildStepInput>;\nexport type BuildStepInputProvider = (\n ctx: BuildStepGlobalContext,\n stepId: string\n) => BuildStepInput;\n\ninterface BuildStepInputProviderParams<\n T extends BuildStepInputValueTypeName = BuildStepInputValueTypeName,\n R extends boolean = boolean,\n> {\n id: string;\n allowedValues?: BuildStepInputValueType<T>[];\n defaultValue?: BuildStepInputValueType<T>;\n required: R;\n allowedValueTypeName: T;\n}\n\ninterface BuildStepInputParams<T extends BuildStepInputValueTypeName, R extends boolean>\n extends BuildStepInputProviderParams<T, R> {\n stepDisplayName: string;\n}\n\nexport interface SerializedBuildStepInput<\n T extends BuildStepInputValueTypeName = BuildStepInputValueTypeName,\n R extends boolean = boolean,\n> {\n id: string;\n stepDisplayName: string;\n defaultValue?: BuildStepInputValueType<T>;\n allowedValues?: BuildStepInputValueType<T>[];\n allowedValueTypeName: BuildStepInputValueTypeName;\n required: R;\n value?: BuildStepInputValueType<T>;\n ctx: SerializedBuildStepGlobalContext;\n}\n\nexport class BuildStepInput<\n T extends BuildStepInputValueTypeName = BuildStepInputValueTypeName,\n R extends boolean = boolean,\n> {\n public readonly id: string;\n public readonly stepDisplayName: string;\n public readonly defaultValue?: BuildStepInputValueType<T>;\n public readonly allowedValues?: BuildStepInputValueType<T>[];\n public readonly allowedValueTypeName: T;\n public readonly required: R;\n\n private _value?: BuildStepInputValueType<T>;\n\n public static createProvider(params: BuildStepInputProviderParams): BuildStepInputProvider {\n return (ctx, stepDisplayName) => new BuildStepInput(ctx, { ...params, stepDisplayName });\n }\n\n constructor(\n private readonly ctx: BuildStepGlobalContext,\n {\n id,\n stepDisplayName,\n allowedValues,\n defaultValue,\n required,\n allowedValueTypeName,\n }: BuildStepInputParams<T, R>\n ) {\n this.id = id;\n this.stepDisplayName = stepDisplayName;\n this.allowedValues = allowedValues;\n this.defaultValue = defaultValue;\n this.required = required;\n this.allowedValueTypeName = allowedValueTypeName;\n }\n\n public get value(): BuildStepInputValueTypeWithRequired<T, R> {\n const rawValue = this._value ?? this.defaultValue;\n if (this.required && rawValue === undefined) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" is required but it was not set.`\n );\n }\n\n const valueDoesNotRequireInterpolation =\n rawValue === undefined ||\n typeof rawValue === 'boolean' ||\n typeof rawValue === 'number' ||\n typeof rawValue === 'object';\n if (valueDoesNotRequireInterpolation) {\n const currentTypeName =\n typeof rawValue === 'object' ? BuildStepInputValueTypeName.JSON : typeof rawValue;\n if (currentTypeName !== this.allowedValueTypeName && rawValue !== undefined) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" must be of type \"${this.allowedValueTypeName}\".`\n );\n }\n return rawValue as BuildStepInputValueTypeWithRequired<T, R>;\n } else {\n const valueInterpolatedWithGlobalContext = this.ctx.interpolate(rawValue);\n const valueInterpolatedWithOutputsAndGlobalContext = interpolateWithOutputs(\n valueInterpolatedWithGlobalContext,\n (path) => this.ctx.getStepOutputValue(path) ?? ''\n );\n return this.parseInputValueToAllowedType(valueInterpolatedWithOutputsAndGlobalContext);\n }\n }\n\n public get rawValue(): BuildStepInputValueType<T> | undefined {\n return this._value ?? this.defaultValue;\n }\n\n public set(value: BuildStepInputValueType<T> | undefined): BuildStepInput {\n if (this.required && value === undefined) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" is required.`\n );\n }\n\n this._value = value;\n return this;\n }\n\n public isValueOneOfAllowedValues(): boolean {\n const value = this._value ?? this.defaultValue;\n if (this.allowedValues === undefined || value === undefined) {\n return true;\n }\n return this.allowedValues.includes(value);\n }\n\n public isRawValueStepOrContextReference(): boolean {\n return (\n typeof this.rawValue === 'string' &&\n !!BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX.exec(this.rawValue)\n );\n }\n\n public serialize(): SerializedBuildStepInput<T, R> {\n return {\n id: this.id,\n stepDisplayName: this.stepDisplayName,\n defaultValue: this.defaultValue,\n allowedValues: this.allowedValues,\n allowedValueTypeName: this.allowedValueTypeName,\n required: this.required,\n value: this._value,\n ctx: this.ctx.serialize(),\n };\n }\n\n public static deserialize(\n serializedInput: SerializedBuildStepInput,\n logger: bunyan\n ): BuildStepInput {\n const deserializedContext = BuildStepGlobalContext.deserialize(serializedInput.ctx, logger);\n const input = new BuildStepInput(deserializedContext, {\n id: serializedInput.id,\n stepDisplayName: serializedInput.stepDisplayName,\n defaultValue: serializedInput.defaultValue,\n allowedValues: serializedInput.allowedValues,\n allowedValueTypeName: serializedInput.allowedValueTypeName,\n required: serializedInput.required,\n });\n input._value = serializedInput.value;\n return input;\n }\n\n private parseInputValueToAllowedType(value: string): BuildStepInputValueTypeWithRequired<T, R> {\n if (this.allowedValueTypeName === BuildStepInputValueTypeName.STRING) {\n return value as BuildStepInputValueTypeWithRequired<T, R>;\n } else if (this.allowedValueTypeName === BuildStepInputValueTypeName.NUMBER) {\n return this.parseInputValueToNumber(value) as BuildStepInputValueTypeWithRequired<T, R>;\n } else if (this.allowedValueTypeName === BuildStepInputValueTypeName.BOOLEAN) {\n return this.parseInputValueToBoolean(value) as BuildStepInputValueTypeWithRequired<T, R>;\n } else {\n return this.parseInputValueToObject(value) as BuildStepInputValueTypeWithRequired<T, R>;\n }\n }\n\n private parseInputValueToNumber(value: string): number {\n const numberValue = Number(value);\n if (Number.isNaN(numberValue)) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" must be of type \"${this.allowedValueTypeName}\".`\n );\n }\n return numberValue;\n }\n\n private parseInputValueToBoolean(value: string): boolean {\n if (value === 'true') {\n return true;\n } else if (value === 'false') {\n return false;\n } else {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" must be of type \"${this.allowedValueTypeName}\".`\n );\n }\n }\n\n private parseInputValueToObject(value: string): Record<string, any> {\n try {\n return JSON.parse(value);\n } catch (e: any) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" must be of type \"${this.allowedValueTypeName}\".`,\n {\n cause: e,\n }\n );\n }\n }\n}\n\nexport function makeBuildStepInputByIdMap(inputs?: BuildStepInput[]): BuildStepInputById {\n if (inputs === undefined) {\n return {};\n }\n return inputs.reduce((acc, input) => {\n acc[input.id] = input;\n return acc;\n }, {} as BuildStepInputById);\n}\n"]}
1
+ {"version":3,"file":"BuildStepInput.js","sourceRoot":"","sources":["../src/BuildStepInput.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAI5B,OAAO,EAAE,sBAAsB,EAAoC,MAAM,uBAAuB,CAAC;AACjG,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,kDAAkD,EAClD,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,CAAN,IAAY,2BAKX;AALD,WAAY,2BAA2B;IACrC,gDAAiB,CAAA;IACjB,kDAAmB,CAAA;IACnB,gDAAiB,CAAA;IACjB,4CAAa,CAAA;AACf,CAAC,EALW,2BAA2B,KAA3B,2BAA2B,QAKtC;AAqD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AAqB,CAC7B,oBAAoB,IAAI,CAAC,EAAE,eAAe,IAAI,CAAC,eAAe,sBAAsB,IAAI,CAAC,oBAAoB,IAAI,EACjH;gBACE,KAAK,EAAE,CAAC;aACT,CACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAED,MAAM,UAAU,yBAAyB,CAAC,MAAyB;IACjE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAClC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC;QACtB,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAwB,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import assert from 'assert';\n\nimport { bunyan } from '@expo/logger';\n\nimport { BuildStepGlobalContext, SerializedBuildStepGlobalContext } from './BuildStepContext.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport {\n BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX,\n interpolateWithOutputs,\n} from './utils/template.js';\n\nexport enum BuildStepInputValueTypeName {\n STRING = 'string',\n BOOLEAN = 'boolean',\n NUMBER = 'number',\n JSON = 'json',\n}\n\nexport type BuildStepInputValueType<\n T extends BuildStepInputValueTypeName = BuildStepInputValueTypeName,\n> = T extends BuildStepInputValueTypeName.STRING\n ? string\n : T extends BuildStepInputValueTypeName.BOOLEAN\n ? boolean\n : T extends BuildStepInputValueTypeName.NUMBER\n ? number\n : Record<string, any>;\n\nexport type BuildStepInputValueTypeWithRequired<\n T extends BuildStepInputValueTypeName = BuildStepInputValueTypeName,\n R extends boolean = boolean,\n> = R extends true ? BuildStepInputValueType<T> : BuildStepInputValueType<T> | undefined;\n\nexport type BuildStepInputById = Record<string, BuildStepInput>;\nexport type BuildStepInputProvider = (\n ctx: BuildStepGlobalContext,\n stepId: string\n) => BuildStepInput;\n\ninterface BuildStepInputProviderParams<\n T extends BuildStepInputValueTypeName = BuildStepInputValueTypeName,\n R extends boolean = boolean,\n> {\n id: string;\n allowedValues?: BuildStepInputValueType<T>[];\n defaultValue?: BuildStepInputValueType<T>;\n required: R;\n allowedValueTypeName: T;\n}\n\ninterface BuildStepInputParams<T extends BuildStepInputValueTypeName, R extends boolean>\n extends BuildStepInputProviderParams<T, R> {\n stepDisplayName: string;\n}\n\nexport interface SerializedBuildStepInput<\n T extends BuildStepInputValueTypeName = BuildStepInputValueTypeName,\n R extends boolean = boolean,\n> {\n id: string;\n stepDisplayName: string;\n defaultValue?: BuildStepInputValueType<T>;\n allowedValues?: BuildStepInputValueType<T>[];\n allowedValueTypeName: BuildStepInputValueTypeName;\n required: R;\n value?: BuildStepInputValueType<T>;\n ctx: SerializedBuildStepGlobalContext;\n}\n\nexport class BuildStepInput<\n T extends BuildStepInputValueTypeName = BuildStepInputValueTypeName,\n R extends boolean = boolean,\n> {\n public readonly id: string;\n public readonly stepDisplayName: string;\n public readonly defaultValue?: BuildStepInputValueType<T>;\n public readonly allowedValues?: BuildStepInputValueType<T>[];\n public readonly allowedValueTypeName: T;\n public readonly required: R;\n\n private _value?: BuildStepInputValueType<T>;\n\n public static createProvider(params: BuildStepInputProviderParams): BuildStepInputProvider {\n return (ctx, stepDisplayName) => new BuildStepInput(ctx, { ...params, stepDisplayName });\n }\n\n constructor(\n private readonly ctx: BuildStepGlobalContext,\n {\n id,\n stepDisplayName,\n allowedValues,\n defaultValue,\n required,\n allowedValueTypeName,\n }: BuildStepInputParams<T, R>\n ) {\n this.id = id;\n this.stepDisplayName = stepDisplayName;\n this.allowedValues = allowedValues;\n this.defaultValue = defaultValue;\n this.required = required;\n this.allowedValueTypeName = allowedValueTypeName;\n }\n\n public get value(): BuildStepInputValueTypeWithRequired<T, R> {\n const rawValue = this._value ?? this.defaultValue;\n if (this.required && rawValue === undefined) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" is required but it was not set.`\n );\n }\n\n const valueDoesNotRequireInterpolation =\n rawValue === undefined || typeof rawValue === 'boolean' || typeof rawValue === 'number';\n if (valueDoesNotRequireInterpolation) {\n if (typeof rawValue !== this.allowedValueTypeName && rawValue !== undefined) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" must be of type \"${this.allowedValueTypeName}\".`\n );\n }\n return rawValue as BuildStepInputValueTypeWithRequired<T, R>;\n } else {\n // `valueDoesNotRequireInterpolation` checks that `rawValue` is not undefined\n // so this will never be true.\n assert(rawValue !== undefined);\n const valueInterpolatedWithGlobalContext = this.ctx.interpolate(rawValue);\n const valueInterpolatedWithOutputsAndGlobalContext = interpolateWithOutputs(\n valueInterpolatedWithGlobalContext,\n (path) => this.ctx.getStepOutputValue(path) ?? ''\n );\n return this.parseInputValueToAllowedType(valueInterpolatedWithOutputsAndGlobalContext);\n }\n }\n\n public get rawValue(): BuildStepInputValueType<T> | undefined {\n return this._value ?? this.defaultValue;\n }\n\n public set(value: BuildStepInputValueType<T> | undefined): BuildStepInput {\n if (this.required && value === undefined) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" is required.`\n );\n }\n\n this._value = value;\n return this;\n }\n\n public isValueOneOfAllowedValues(): boolean {\n const value = this._value ?? this.defaultValue;\n if (this.allowedValues === undefined || value === undefined) {\n return true;\n }\n return this.allowedValues.includes(value);\n }\n\n public isRawValueStepOrContextReference(): boolean {\n return (\n typeof this.rawValue === 'string' &&\n !!BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX.exec(this.rawValue)\n );\n }\n\n public serialize(): SerializedBuildStepInput<T, R> {\n return {\n id: this.id,\n stepDisplayName: this.stepDisplayName,\n defaultValue: this.defaultValue,\n allowedValues: this.allowedValues,\n allowedValueTypeName: this.allowedValueTypeName,\n required: this.required,\n value: this._value,\n ctx: this.ctx.serialize(),\n };\n }\n\n public static deserialize(\n serializedInput: SerializedBuildStepInput,\n logger: bunyan\n ): BuildStepInput {\n const deserializedContext = BuildStepGlobalContext.deserialize(serializedInput.ctx, logger);\n const input = new BuildStepInput(deserializedContext, {\n id: serializedInput.id,\n stepDisplayName: serializedInput.stepDisplayName,\n defaultValue: serializedInput.defaultValue,\n allowedValues: serializedInput.allowedValues,\n allowedValueTypeName: serializedInput.allowedValueTypeName,\n required: serializedInput.required,\n });\n input._value = serializedInput.value;\n return input;\n }\n\n private parseInputValueToAllowedType(\n value: string | object\n ): BuildStepInputValueTypeWithRequired<T, R> {\n if (typeof value === 'object') {\n return value as BuildStepInputValueTypeWithRequired<T, R>;\n }\n if (this.allowedValueTypeName === BuildStepInputValueTypeName.STRING) {\n return value as BuildStepInputValueTypeWithRequired<T, R>;\n } else if (this.allowedValueTypeName === BuildStepInputValueTypeName.NUMBER) {\n return this.parseInputValueToNumber(value) as BuildStepInputValueTypeWithRequired<T, R>;\n } else if (this.allowedValueTypeName === BuildStepInputValueTypeName.BOOLEAN) {\n return this.parseInputValueToBoolean(value) as BuildStepInputValueTypeWithRequired<T, R>;\n } else {\n return this.parseInputValueToObject(value) as BuildStepInputValueTypeWithRequired<T, R>;\n }\n }\n\n private parseInputValueToNumber(value: string): number {\n const numberValue = Number(value);\n if (Number.isNaN(numberValue)) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" must be of type \"${this.allowedValueTypeName}\".`\n );\n }\n return numberValue;\n }\n\n private parseInputValueToBoolean(value: string): boolean {\n if (value === 'true') {\n return true;\n } else if (value === 'false') {\n return false;\n } else {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" must be of type \"${this.allowedValueTypeName}\".`\n );\n }\n }\n\n private parseInputValueToObject(value: string): Record<string, any> {\n try {\n return JSON.parse(value);\n } catch (e: any) {\n throw new BuildStepRuntimeError(\n `Input parameter \"${this.id}\" for step \"${this.stepDisplayName}\" must be of type \"${this.allowedValueTypeName}\".`,\n {\n cause: e,\n }\n );\n }\n }\n}\n\nexport function makeBuildStepInputByIdMap(inputs?: BuildStepInput[]): BuildStepInputById {\n if (inputs === undefined) {\n return {};\n }\n return inputs.reduce((acc, input) => {\n acc[input.id] = input;\n return acc;\n }, {} as BuildStepInputById);\n}\n"]}
@@ -4,14 +4,18 @@ export declare const BUILD_GLOBAL_CONTEXT_EXPRESSION_REGEXP: RegExp;
4
4
  export declare const BUILD_STEP_OR_BUILD_GLOBAL_CONTEXT_REFERENCE_REGEX: RegExp;
5
5
  export declare const BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP: RegExp;
6
6
  export declare function interpolateWithInputs(templateString: string, inputs: Record<string, string>): string;
7
- export declare function interpolateWithOutputs(templateString: string, fn: (path: string) => string): string;
7
+ export declare function interpolateWithOutputs<InterpolableType extends string | object>(interpolableValue: InterpolableType, fn: (path: string) => string): InterpolableType;
8
+ export declare function interpolateStringWithOutputs(templateString: string, fn: (path: string) => string): string;
9
+ export declare function interpolateObjectWithOutputs(interpolableObject: object, fn: (path: string) => string): object;
8
10
  /**
9
11
  * Returns the selected status check from the if statement template.
10
12
  * Example: `${ success() }` -> `success`
11
13
  */
12
14
  export declare function getSelectedStatusCheckFromIfStatementTemplate(ifCondition: string): 'success' | 'failure' | 'always' | 'never';
13
15
  export declare function getObjectValueForInterpolation(path: string, obj: Record<string, unknown>): string | number | boolean | null;
14
- export declare function interpolateWithGlobalContext(templateString: string, fn: (path: string) => string): string;
16
+ export declare function interpolateWithGlobalContext<InterpolableType extends string | object>(interpolableValue: InterpolableType, fn: (path: string) => string): InterpolableType;
17
+ export declare function interpolateStringWithGlobalContext(templateString: string, fn: (path: string) => string): string;
18
+ export declare function interpolateObjectWithGlobalContext(templateObject: object, fn: (path: string) => string): object;
15
19
  interface BuildOutputPath {
16
20
  stepId: string;
17
21
  outputId: string;
@@ -1,4 +1,5 @@
1
1
  import get from 'lodash.get';
2
+ import cloneDeep from 'lodash.clonedeep';
2
3
  import { BuildStepInputValueTypeName } from '../BuildStepInput.js';
3
4
  import { BuildConfigError, BuildStepRuntimeError } from '../errors.js';
4
5
  import { nullthrows } from './nullthrows.js';
@@ -10,9 +11,28 @@ export const BUILD_STEP_IF_CONDITION_EXPRESSION_REGEXP = /\${\s*(always|success|
10
11
  export function interpolateWithInputs(templateString, inputs) {
11
12
  return interpolate(templateString, BUILD_STEP_INPUT_EXPRESSION_REGEXP, inputs);
12
13
  }
13
- export function interpolateWithOutputs(templateString, fn) {
14
+ export function interpolateWithOutputs(interpolableValue, fn) {
15
+ if (typeof interpolableValue === 'string') {
16
+ return interpolateStringWithOutputs(interpolableValue, fn);
17
+ }
18
+ else {
19
+ return interpolateObjectWithOutputs(interpolableValue, fn);
20
+ }
21
+ }
22
+ export function interpolateStringWithOutputs(templateString, fn) {
14
23
  return interpolate(templateString, BUILD_STEP_OUTPUT_EXPRESSION_REGEXP, fn);
15
24
  }
25
+ export function interpolateObjectWithOutputs(interpolableObject, fn) {
26
+ const interpolableObjectCopy = cloneDeep(interpolableObject);
27
+ Object.keys(interpolableObject).forEach((property) => {
28
+ const propertyValue = interpolableObject[property];
29
+ if (['string', 'object'].includes(typeof propertyValue)) {
30
+ interpolableObjectCopy[property] =
31
+ interpolateWithOutputs(propertyValue, fn);
32
+ }
33
+ });
34
+ return interpolableObjectCopy;
35
+ }
16
36
  /**
17
37
  * Returns the selected status check from the if statement template.
18
38
  * Example: `${ success() }` -> `success`
@@ -39,9 +59,28 @@ export function getObjectValueForInterpolation(path, obj) {
39
59
  }
40
60
  return value;
41
61
  }
42
- export function interpolateWithGlobalContext(templateString, fn) {
62
+ export function interpolateWithGlobalContext(interpolableValue, fn) {
63
+ if (typeof interpolableValue === 'string') {
64
+ return interpolateStringWithGlobalContext(interpolableValue, fn);
65
+ }
66
+ else {
67
+ return interpolateObjectWithGlobalContext(interpolableValue, fn);
68
+ }
69
+ }
70
+ export function interpolateStringWithGlobalContext(templateString, fn) {
43
71
  return interpolate(templateString, BUILD_GLOBAL_CONTEXT_EXPRESSION_REGEXP, fn);
44
72
  }
73
+ export function interpolateObjectWithGlobalContext(templateObject, fn) {
74
+ const templateObjectCopy = cloneDeep(templateObject);
75
+ Object.keys(templateObject).forEach((property) => {
76
+ const propertyValue = templateObject[property];
77
+ if (['string', 'object'].includes(typeof propertyValue)) {
78
+ templateObjectCopy[property] =
79
+ interpolateWithGlobalContext(propertyValue, fn);
80
+ }
81
+ });
82
+ return templateObjectCopy;
83
+ }
45
84
  function interpolate(templateString, regex, varsOrFn) {
46
85
  const matched = templateString.match(new RegExp(regex, 'g'));
47
86
  if (!matched) {
@@ -1 +1 @@
1
- {"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/utils/template.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAEvE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,MAAM,CAAC,MAAM,kCAAkC,GAAG,2BAA2B,CAAC;AAC9E,MAAM,CAAC,MAAM,mCAAmC,GAAG,0BAA0B,CAAC;AAC9E,MAAM,CAAC,MAAM,sCAAsC,GAAG,wBAAwB,CAAC;AAC/E,MAAM,CAAC,MAAM,kDAAkD,GAAG,gCAAgC,CAAC;AACnG,MAAM,CAAC,MAAM,yCAAyC,GACpD,8CAA8C,CAAC;AAEjD,MAAM,UAAU,qBAAqB,CACnC,cAAsB,EACtB,MAA8B;IAE9B,OAAO,WAAW,CAAC,cAAc,EAAE,kCAAkC,EAAE,MAAM,CAAC,CAAC;AACjF,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,cAAsB,EACtB,EAA4B;IAE5B,OAAO,WAAW,CAAC,cAAc,EAAE,mCAAmC,EAAE,EAAE,CAAC,CAAC;AAC9E,CAAC;AAED;;;GA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AC,CAAC;IACzC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,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,gBAAgB,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","sourcesContent":["import get from 'lodash.get';\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(\n templateString: string,\n fn: (path: string) => string\n): string {\n return interpolate(templateString, BUILD_STEP_OUTPUT_EXPRESSION_REGEXP, fn);\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(\n templateString: string,\n fn: (path: string) => string\n): string {\n return interpolate(templateString, BUILD_GLOBAL_CONTEXT_EXPRESSION_REGEXP, fn);\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,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,SAAS,MAAM,kBAAkB,CAAC;AAEzC,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAEvE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,MAAM,CAAC,MAAM,kCAAkC,GAAG,2BAA2B,CAAC;AAC9E,MAAM,CAAC,MAAM,mCAAmC,GAAG,0BAA0B,CAAC;AAC9E,MAAM,CAAC,MAAM,sCAAsC,GAAG,wBAAwB,CAAC;AAC/E,MAAM,CAAC,MAAM,kDAAkD,GAAG,gCAAgC,CAAC;AACnG,MAAM,CAAC,MAAM,yCAAyC,GACpD,8CAA8C,CAAC;AAEjD,MAAM,UAAU,qBAAqB,CACnC,cAAsB,EACtB,MAA8B;IAE9B,OAAO,WAAW,CAAC,cAAc,EAAE,kCAAkC,EAAE,MAAM,CAAC,CAAC;AACjF,CAAC;A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AO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAO,KAAK,KAAK,SAAS;QAC1B,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI,CACf,CAAC;AACJ,CAAC;AAOD,MAAM,UAAU,eAAe,CAAC,cAAsB;IACpD,MAAM,MAAM,GAAsB,EAAE,CAAC;IACrC,MAAM,OAAO,GAAG,cAAc,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,mCAAmC,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;AAED,MAAM,UAAU,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,gBAAgB,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","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"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@expo/steps",
3
3
  "type": "module",
4
- "version": "1.0.75",
4
+ "version": "1.0.81",
5
5
  "main": "./dist_commonjs/index.cjs",
6
6
  "types": "./dist_esm/index.d.ts",
7
7
  "exports": {
@@ -48,7 +48,7 @@
48
48
  "node": ">=16.0.0"
49
49
  },
50
50
  "dependencies": {
51
- "@expo/eas-build-job": "1.0.74",
51
+ "@expo/eas-build-job": "1.0.78",
52
52
  "@expo/logger": "1.0.57",
53
53
  "@expo/spawn-async": "^1.7.2",
54
54
  "arg": "^5.0.2",
@@ -64,5 +64,5 @@
64
64
  "node": "20.11.0",
65
65
  "yarn": "1.22.21"
66
66
  },
67
- "gitHead": "42caea442b483c259ae7c7cc799a849ab29e152f"
67
+ "gitHead": "088c9a1c341378a09043d27099d769517920e3f8"
68
68
  }