@expo/steps 1.0.23 → 1.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/set-env +23 -0
- package/dist_commonjs/BuildConfig.cjs +21 -5
- package/dist_commonjs/BuildConfig.d.ts +2 -0
- package/dist_commonjs/BuildConfig.js.map +1 -1
- package/dist_commonjs/BuildConfigParser.cjs +6 -2
- package/dist_commonjs/BuildConfigParser.d.ts +2 -2
- package/dist_commonjs/BuildConfigParser.js.map +1 -1
- package/dist_commonjs/BuildFunction.cjs +2 -1
- package/dist_commonjs/BuildFunction.d.ts +4 -2
- package/dist_commonjs/BuildFunction.js.map +1 -1
- package/dist_commonjs/BuildStep.cjs +49 -22
- package/dist_commonjs/BuildStep.d.ts +7 -4
- package/dist_commonjs/BuildStep.js.map +1 -1
- package/dist_commonjs/BuildStepContext.cjs +50 -13
- package/dist_commonjs/BuildStepContext.d.ts +35 -10
- package/dist_commonjs/BuildStepContext.js.map +1 -1
- package/dist_commonjs/BuildStepInput.cjs +59 -5
- package/dist_commonjs/BuildStepInput.d.ts +11 -5
- package/dist_commonjs/BuildStepInput.js.map +1 -1
- package/dist_commonjs/BuildStepOutput.d.ts +3 -3
- package/dist_commonjs/BuildStepOutput.js.map +1 -1
- package/dist_commonjs/BuildTemporaryFiles.cjs +11 -2
- package/dist_commonjs/BuildTemporaryFiles.d.ts +5 -4
- package/dist_commonjs/BuildTemporaryFiles.js.map +1 -1
- package/dist_commonjs/BuildWorkflow.cjs +2 -2
- package/dist_commonjs/BuildWorkflow.d.ts +3 -4
- package/dist_commonjs/BuildWorkflow.js.map +1 -1
- package/dist_commonjs/BuildWorkflowValidator.cjs +10 -3
- package/dist_commonjs/BuildWorkflowValidator.js.map +1 -1
- package/dist_commonjs/cli/cli.cjs +22 -3
- package/dist_commonjs/cli/cli.d.ts +16 -1
- package/dist_commonjs/cli/cli.js.map +1 -1
- package/dist_commonjs/index.cjs +2 -2
- package/dist_commonjs/index.d.ts +2 -1
- package/dist_commonjs/index.js.map +1 -1
- package/dist_commonjs/utils/template.cjs +40 -8
- package/dist_commonjs/utils/template.d.ts +5 -1
- package/dist_commonjs/utils/template.js.map +1 -1
- package/dist_esm/BuildConfig.d.ts +2 -0
- package/dist_esm/BuildConfig.js +21 -5
- package/dist_esm/BuildConfig.js.map +1 -1
- package/dist_esm/BuildConfigParser.d.ts +2 -2
- package/dist_esm/BuildConfigParser.js +7 -3
- package/dist_esm/BuildConfigParser.js.map +1 -1
- package/dist_esm/BuildFunction.d.ts +4 -2
- package/dist_esm/BuildFunction.js +2 -1
- package/dist_esm/BuildFunction.js.map +1 -1
- package/dist_esm/BuildStep.d.ts +7 -4
- package/dist_esm/BuildStep.js +50 -23
- package/dist_esm/BuildStep.js.map +1 -1
- package/dist_esm/BuildStepContext.d.ts +35 -10
- package/dist_esm/BuildStepContext.js +49 -13
- package/dist_esm/BuildStepContext.js.map +1 -1
- package/dist_esm/BuildStepInput.d.ts +11 -5
- package/dist_esm/BuildStepInput.js +60 -6
- package/dist_esm/BuildStepInput.js.map +1 -1
- package/dist_esm/BuildStepOutput.d.ts +3 -3
- package/dist_esm/BuildStepOutput.js.map +1 -1
- package/dist_esm/BuildTemporaryFiles.d.ts +5 -4
- package/dist_esm/BuildTemporaryFiles.js +9 -1
- package/dist_esm/BuildTemporaryFiles.js.map +1 -1
- package/dist_esm/BuildWorkflow.d.ts +3 -4
- package/dist_esm/BuildWorkflow.js +2 -2
- package/dist_esm/BuildWorkflow.js.map +1 -1
- package/dist_esm/BuildWorkflowValidator.js +10 -3
- package/dist_esm/BuildWorkflowValidator.js.map +1 -1
- package/dist_esm/cli/cli.d.ts +16 -1
- package/dist_esm/cli/cli.js +21 -4
- package/dist_esm/cli/cli.js.map +1 -1
- package/dist_esm/index.d.ts +2 -1
- package/dist_esm/index.js +1 -1
- package/dist_esm/index.js.map +1 -1
- package/dist_esm/utils/template.d.ts +5 -1
- package/dist_esm/utils/template.js +35 -8
- package/dist_esm/utils/template.js.map +1 -1
- package/package.json +4 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildConfigParser.js","sourceRoot":"","sources":["../src/BuildConfigParser.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAYL,yBAAyB,EACzB,2BAA2B,EAC3B,qBAAqB,EACrB,+BAA+B,GAChC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAqB,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EACL,cAAc,GAGf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAA2B,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAEhD,MAAM,OAAO,iBAAiB;IAI5B,YACmB,GAAqB,EACtC,EAAE,UAAU,EAAE,iBAAiB,EAA+D;QAD7E,QAAG,GAAH,GAAG,CAAkB;QAGtC,IAAI,CAAC,yBAAyB,CAAC,iBAAiB,CAAC,CAAC;QAElD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;IAEM,KAAK,CAAC,UAAU;QACrB,MAAM,MAAM,GAAG,MAAM,+BAA+B,CAAC,IAAI,CAAC,UAAU,EAAE;YACpE,mBAAmB,EAAE,IAAI,CAAC,0BAA0B,EAAE;SACvD,CAAC,CAAC;QACH,MAAM,oBAAoB,GAAG,IAAI,CAAC,8BAA8B,CAAC,M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6BAA6B,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAC;QACtE,IAAI,6BAA6B,CAAC,MAAM,KAAK,CAAC,EAAE;YAC9C,OAAO;SACR;QACD,MAAM,IAAI,qBAAqB,CAC7B,oDAAoD,6BAA6B;aAC9E,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC;aACtB,IAAI,CAAC,IAAI,CAAC,EAAE,CAChB,CAAC;IACJ,CAAC;IAEO,0BAA0B;QAChC,IAAI,IAAI,CAAC,iBAAiB,KAAK,SAAS,EAAE;YACxC,OAAO,EAAE,CAAC;SACX;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;QAC7D,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;CACF","sourcesContent":["import assert from 'assert';\n\nimport {\n BuildConfig,\n BuildFunctionConfig,\n BuildFunctionInputs,\n BuildFunctionOutputs,\n BuildStepBareCommandRun,\n BuildStepBareFunctionCall,\n BuildStepCommandRun,\n BuildStepConfig,\n BuildStepFunctionCall,\n BuildStepInputs,\n BuildStepOutputs,\n isBuildStepBareCommandRun,\n isBuildStepBareFunctionCall,\n isBuildStepCommandRun,\n readAndValidateBuildConfigAsync,\n} from './BuildConfig.js';\nimport { BuildFunction, BuildFunctionById } from './BuildFunction.js';\nimport { BuildStep } from './BuildStep.js';\nimport { BuildStepContext } from './BuildStepContext.js';\nimport {\n BuildStepInput,\n BuildStepInputProvider,\n BuildStepInputValueTypeName,\n} from './BuildStepInput.js';\nimport { BuildStepOutput, BuildStepOutputProvider } from './BuildStepOutput.js';\nimport { BuildWorkflow } from './BuildWorkflow.js';\nimport { BuildWorkflowValidator } from './BuildWorkflowValidator.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { duplicates } from './utils/expodash/duplicates.js';\nimport { uniq } from './utils/expodash/uniq.js';\n\nexport class BuildConfigParser {\n private readonly configPath: string;\n private readonly externalFunctions?: BuildFunction[];\n\n constructor(\n private readonly ctx: BuildStepContext,\n { configPath, externalFunctions }: { configPath: string; externalFunctions?: BuildFunction[] }\n ) {\n this.validateExternalFunctions(externalFunctions);\n\n this.configPath = configPath;\n this.externalFunctions = externalFunctions;\n }\n\n public async parseAsync(): Promise<BuildWorkflow> {\n const config = await readAndValidateBuildConfigAsync(this.configPath, {\n externalFunctionIds: this.getExternalFunctionFullIds(),\n });\n const configBuildFunctions = this.createBuildFunctionsFromConfig(config.functions);\n const buildFunctions = this.mergeBuildFunctionsWithExternal(\n configBuildFunctions,\n this.externalFunctions\n );\n const buildSteps = config.build.steps.map((stepConfig) =>\n this.createBuildStepFromConfig(stepConfig, buildFunctions)\n );\n const workflow = new BuildWorkflow(this.ctx, { buildSteps, buildFunctions });\n new BuildWorkflowValidator(workflow).validate();\n return workflow;\n }\n\n private createBuildStepFromConfig(\n buildStepConfig: BuildStepConfig,\n buildFunctions: BuildFunctionById\n ): BuildStep {\n if (isBuildStepCommandRun(buildStepConfig)) {\n return this.createBuildStepFromBuildStepCommandRun(buildStepConfig);\n } else if (isBuildStepBareCommandRun(buildStepConfig)) {\n return this.createBuildStepFromBuildStepBareCommandRun(buildStepConfig);\n } else if (isBuildStepBareFunctionCall(buildStepConfig)) {\n return this.createBuildStepFromBuildStepBareFunctionCall(buildFunctions, buildStepConfig);\n } else {\n return this.createBuildStepFromBuildStepFunctionCall(buildFunctions, buildStepConfig);\n }\n }\n\n private createBuildStepFromBuildStepCommandRun({ run }: BuildStepCommandRun): BuildStep {\n const {\n id: maybeId,\n inputs: inputsConfig,\n outputs: outputsConfig,\n name,\n workingDirectory,\n shell,\n command,\n } = run;\n const id = BuildStep.getNewId(maybeId);\n const displayName = BuildStep.getDisplayName({ id, name, command });\n const inputs =\n inputsConfig && this.createBuildStepInputsFromDefinition(inputsConfig, displayName);\n const outputs =\n outputsConfig && this.createBuildStepOutputsFromDefinition(outputsConfig, displayName);\n return new BuildStep(this.ctx, {\n id,\n inputs,\n outputs,\n name,\n displayName,\n workingDirectory,\n shell,\n command,\n });\n }\n\n private createBuildStepFromBuildStepBareCommandRun({\n run: command,\n }: BuildStepBareCommandRun): BuildStep {\n const id = BuildStep.getNewId();\n const displayName = BuildStep.getDisplayName({ id, command });\n return new BuildStep(this.ctx, {\n id,\n displayName,\n command,\n });\n }\n\n private createBuildStepFromBuildStepBareFunctionCall(\n buildFunctions: BuildFunctionById,\n functionId: BuildStepBareFunctionCall\n ): BuildStep {\n const buildFunction = buildFunctions[functionId];\n return buildFunction.createBuildStepFromFunctionCall(this.ctx);\n }\n\n private createBuildStepFromBuildStepFunctionCall(\n buildFunctions: BuildFunctionById,\n buildStepFunctionCall: BuildStepFunctionCall\n ): BuildStep {\n const keys = Object.keys(buildStepFunctionCall);\n assert(\n keys.length === 1,\n 'There must be at most one function call in the step (enforced by joi).'\n );\n const functionId = keys[0];\n const buildFunctionCallConfig = buildStepFunctionCall[functionId];\n const buildFunction = buildFunctions[functionId];\n return buildFunction.createBuildStepFromFunctionCall(this.ctx, {\n id: buildFunctionCallConfig.id,\n name: buildFunctionCallConfig.name,\n callInputs: buildFunctionCallConfig.inputs,\n workingDirectory: buildFunctionCallConfig.workingDirectory,\n shell: buildFunctionCallConfig.shell,\n });\n }\n\n private createBuildFunctionsFromConfig(\n buildFunctionsConfig: BuildConfig['functions']\n ): BuildFunctionById {\n if (!buildFunctionsConfig) {\n return {};\n }\n const result: BuildFunctionById = {};\n for (const [functionId, buildFunctionConfig] of Object.entries(buildFunctionsConfig)) {\n const buildFunction = this.createBuildFunctionFromConfig({\n id: functionId,\n ...buildFunctionConfig,\n });\n result[buildFunction.getFullId()] = buildFunction;\n }\n return result;\n }\n\n private createBuildFunctionFromConfig({\n id,\n name,\n inputs: inputsConfig,\n outputs: outputsConfig,\n shell,\n command,\n supportedRuntimePlatforms,\n }: BuildFunctionConfig & { id: string }): BuildFunction {\n const inputProviders =\n inputsConfig && this.createBuildStepInputProvidersFromBuildFunctionInputs(inputsConfig);\n const outputProviders =\n outputsConfig && this.createBuildStepOutputProvidersFromBuildFunctionOutputs(outputsConfig);\n return new BuildFunction({\n id,\n name,\n inputProviders,\n outputProviders,\n shell,\n command,\n supportedRuntimePlatforms,\n });\n }\n\n private createBuildStepInputsFromDefinition(\n buildStepInputs: BuildStepInputs,\n stepDisplayName: string\n ): BuildStepInput[] {\n return Object.entries(buildStepInputs).map(\n ([key, value]) =>\n new BuildStepInput(this.ctx, {\n id: key,\n stepDisplayName,\n defaultValue: value,\n required: true,\n allowedValueTypeName: typeof value as BuildStepInputValueTypeName,\n })\n );\n }\n\n private createBuildStepInputProvidersFromBuildFunctionInputs(\n buildFunctionInputs: BuildFunctionInputs\n ): BuildStepInputProvider[] {\n return buildFunctionInputs.map((entry) => {\n return typeof entry === 'string'\n ? BuildStepInput.createProvider({ id: entry })\n : BuildStepInput.createProvider({\n id: entry.name,\n required: entry.required ?? true,\n defaultValue: entry.defaultValue,\n allowedValues: entry.allowedValues,\n allowedValueTypeName: entry.allowedValueType,\n });\n });\n }\n\n private createBuildStepOutputsFromDefinition(\n buildStepOutputs: BuildStepOutputs,\n stepDisplayName: string\n ): BuildStepOutput[] {\n return buildStepOutputs.map((entry) =>\n typeof entry === 'string'\n ? new BuildStepOutput(this.ctx, { id: entry, stepDisplayName, required: true })\n : new BuildStepOutput(this.ctx, {\n id: entry.name,\n stepDisplayName,\n required: entry.required ?? true,\n })\n );\n }\n\n private createBuildStepOutputProvidersFromBuildFunctionOutputs(\n buildFunctionOutputs: BuildFunctionOutputs\n ): BuildStepOutputProvider[] {\n return buildFunctionOutputs.map((entry) =>\n typeof entry === 'string'\n ? BuildStepOutput.createProvider({ id: entry, required: true })\n : BuildStepOutput.createProvider({ id: entry.name, required: entry.required ?? true })\n );\n }\n\n private mergeBuildFunctionsWithExternal(\n configFunctions: BuildFunctionById,\n externalFunctions?: BuildFunction[]\n ): BuildFunctionById {\n const result: BuildFunctionById = { ...configFunctions };\n if (externalFunctions === undefined) {\n return result;\n }\n for (const buildFunction of externalFunctions) {\n // functions defined in config shadow the external ones\n const fullId = buildFunction.getFullId();\n if (!(fullId in result)) {\n result[fullId] = buildFunction;\n }\n }\n return result;\n }\n\n private validateExternalFunctions(externalFunctions?: BuildFunction[]): void {\n if (externalFunctions === undefined) {\n return;\n }\n const externalFunctionIds = externalFunctions.map((f) => f.getFullId());\n const duplicatedExternalFunctionIds = duplicates(externalFunctionIds);\n if (duplicatedExternalFunctionIds.length === 0) {\n return;\n }\n throw new BuildStepRuntimeError(\n `Provided external functions with duplicated IDs: ${duplicatedExternalFunctionIds\n .map((id) => `\"${id}\"`)\n .join(', ')}`\n );\n }\n\n private getExternalFunctionFullIds(): string[] {\n if (this.externalFunctions === undefined) {\n return [];\n }\n const ids = this.externalFunctions.map((f) => f.getFullId());\n return uniq(ids);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BuildConfigParser.js","sourceRoot":"","sources":["../src/BuildConfigParser.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAYL,yBAAyB,EACzB,2BAA2B,EAC3B,qBAAqB,EACrB,+BAA+B,GAChC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAqB,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EACL,cAAc,EAEd,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,eAAe,EAA2B,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;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,GAAG,CAAC,CAAC;IACnB,CAAC;CACF","sourcesContent":["import assert from 'assert';\n\nimport {\n BuildConfig,\n BuildFunctionConfig,\n BuildFunctionInputs,\n BuildFunctionOutputs,\n BuildStepBareCommandRun,\n BuildStepBareFunctionCall,\n BuildStepCommandRun,\n BuildStepConfig,\n BuildStepFunctionCall,\n BuildStepInputs,\n BuildStepOutputs,\n isBuildStepBareCommandRun,\n isBuildStepBareFunctionCall,\n isBuildStepCommandRun,\n readAndValidateBuildConfigAsync,\n} from './BuildConfig.js';\nimport { BuildFunction, BuildFunctionById } from './BuildFunction.js';\nimport { BuildStep } from './BuildStep.js';\nimport {\n BuildStepInput,\n BuildStepInputProvider,\n BuildStepInputValueTypeName,\n} from './BuildStepInput.js';\nimport { BuildStepGlobalContext } from './BuildStepContext.js';\nimport { BuildStepOutput, BuildStepOutputProvider } from './BuildStepOutput.js';\nimport { BuildWorkflow } from './BuildWorkflow.js';\nimport { BuildWorkflowValidator } from './BuildWorkflowValidator.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { duplicates } from './utils/expodash/duplicates.js';\nimport { uniq } from './utils/expodash/uniq.js';\n\nexport class BuildConfigParser {\n private readonly configPath: string;\n private readonly externalFunctions?: BuildFunction[];\n\n constructor(\n private readonly ctx: BuildStepGlobalContext,\n { configPath, externalFunctions }: { configPath: string; externalFunctions?: BuildFunction[] }\n ) {\n this.validateExternalFunctions(externalFunctions);\n\n this.configPath = configPath;\n this.externalFunctions = externalFunctions;\n }\n\n public async parseAsync(): Promise<BuildWorkflow> {\n const config = await readAndValidateBuildConfigAsync(this.configPath, {\n externalFunctionIds: this.getExternalFunctionFullIds(),\n });\n const configBuildFunctions = this.createBuildFunctionsFromConfig(config.functions);\n const buildFunctions = this.mergeBuildFunctionsWithExternal(\n configBuildFunctions,\n this.externalFunctions\n );\n const buildSteps = config.build.steps.map((stepConfig) =>\n this.createBuildStepFromConfig(stepConfig, buildFunctions)\n );\n const workflow = new BuildWorkflow(this.ctx, { buildSteps, buildFunctions });\n new BuildWorkflowValidator(workflow).validate();\n return workflow;\n }\n\n private createBuildStepFromConfig(\n buildStepConfig: BuildStepConfig,\n buildFunctions: BuildFunctionById\n ): BuildStep {\n if (isBuildStepCommandRun(buildStepConfig)) {\n return this.createBuildStepFromBuildStepCommandRun(buildStepConfig);\n } else if (isBuildStepBareCommandRun(buildStepConfig)) {\n return this.createBuildStepFromBuildStepBareCommandRun(buildStepConfig);\n } else if (isBuildStepBareFunctionCall(buildStepConfig)) {\n return this.createBuildStepFromBuildStepBareFunctionCall(buildFunctions, buildStepConfig);\n } else {\n return this.createBuildStepFromBuildStepFunctionCall(buildFunctions, buildStepConfig);\n }\n }\n\n private createBuildStepFromBuildStepCommandRun({ run }: BuildStepCommandRun): BuildStep {\n const {\n id: maybeId,\n inputs: inputsConfig,\n outputs: outputsConfig,\n name,\n workingDirectory,\n shell,\n command,\n env,\n } = run;\n const id = BuildStep.getNewId(maybeId);\n const displayName = BuildStep.getDisplayName({ id, name, command });\n const inputs =\n inputsConfig && this.createBuildStepInputsFromDefinition(inputsConfig, displayName);\n const outputs =\n outputsConfig && this.createBuildStepOutputsFromDefinition(outputsConfig, displayName);\n return new BuildStep(this.ctx, {\n id,\n inputs,\n outputs,\n name,\n displayName,\n workingDirectory,\n shell,\n command,\n env,\n });\n }\n\n private createBuildStepFromBuildStepBareCommandRun({\n run: command,\n }: BuildStepBareCommandRun): BuildStep {\n const id = BuildStep.getNewId();\n const displayName = BuildStep.getDisplayName({ id, command });\n return new BuildStep(this.ctx, {\n id,\n displayName,\n command,\n });\n }\n\n private createBuildStepFromBuildStepBareFunctionCall(\n buildFunctions: BuildFunctionById,\n functionId: BuildStepBareFunctionCall\n ): BuildStep {\n const buildFunction = buildFunctions[functionId];\n return buildFunction.createBuildStepFromFunctionCall(this.ctx);\n }\n\n private createBuildStepFromBuildStepFunctionCall(\n buildFunctions: BuildFunctionById,\n buildStepFunctionCall: BuildStepFunctionCall\n ): BuildStep {\n const keys = Object.keys(buildStepFunctionCall);\n assert(\n keys.length === 1,\n 'There must be at most one function call in the step (enforced by joi).'\n );\n const functionId = keys[0];\n const buildFunctionCallConfig = buildStepFunctionCall[functionId];\n const buildFunction = buildFunctions[functionId];\n return buildFunction.createBuildStepFromFunctionCall(this.ctx, {\n id: buildFunctionCallConfig.id,\n name: buildFunctionCallConfig.name,\n callInputs: buildFunctionCallConfig.inputs,\n workingDirectory: buildFunctionCallConfig.workingDirectory,\n shell: buildFunctionCallConfig.shell,\n env: buildFunctionCallConfig.env,\n });\n }\n\n private createBuildFunctionsFromConfig(\n buildFunctionsConfig: BuildConfig['functions']\n ): BuildFunctionById {\n if (!buildFunctionsConfig) {\n return {};\n }\n const result: BuildFunctionById = {};\n for (const [functionId, buildFunctionConfig] of Object.entries(buildFunctionsConfig)) {\n const buildFunction = this.createBuildFunctionFromConfig({\n id: functionId,\n ...buildFunctionConfig,\n });\n result[buildFunction.getFullId()] = buildFunction;\n }\n return result;\n }\n\n private createBuildFunctionFromConfig({\n id,\n name,\n inputs: inputsConfig,\n outputs: outputsConfig,\n shell,\n command,\n supportedRuntimePlatforms,\n }: BuildFunctionConfig & { id: string }): BuildFunction {\n const inputProviders =\n inputsConfig && this.createBuildStepInputProvidersFromBuildFunctionInputs(inputsConfig);\n const outputProviders =\n outputsConfig && this.createBuildStepOutputProvidersFromBuildFunctionOutputs(outputsConfig);\n return new BuildFunction({\n id,\n name,\n inputProviders,\n outputProviders,\n shell,\n command,\n supportedRuntimePlatforms,\n });\n }\n\n private createBuildStepInputsFromDefinition(\n buildStepInputs: BuildStepInputs,\n stepDisplayName: string\n ): BuildStepInput[] {\n return Object.entries(buildStepInputs).map(\n ([key, value]) =>\n new BuildStepInput(this.ctx, {\n id: key,\n stepDisplayName,\n defaultValue: value,\n required: true,\n allowedValueTypeName:\n typeof value === 'object'\n ? BuildStepInputValueTypeName.JSON\n : (typeof value as BuildStepInputValueTypeName),\n })\n );\n }\n\n private createBuildStepInputProvidersFromBuildFunctionInputs(\n buildFunctionInputs: BuildFunctionInputs\n ): BuildStepInputProvider[] {\n return buildFunctionInputs.map((entry) => {\n return typeof entry === 'string'\n ? BuildStepInput.createProvider({ id: entry })\n : BuildStepInput.createProvider({\n id: entry.name,\n required: entry.required ?? true,\n defaultValue: entry.defaultValue,\n allowedValues: entry.allowedValues,\n allowedValueTypeName: entry.allowedValueType,\n });\n });\n }\n\n private createBuildStepOutputsFromDefinition(\n buildStepOutputs: BuildStepOutputs,\n stepDisplayName: string\n ): BuildStepOutput[] {\n return buildStepOutputs.map((entry) =>\n typeof entry === 'string'\n ? new BuildStepOutput(this.ctx, { id: entry, stepDisplayName, required: true })\n : new BuildStepOutput(this.ctx, {\n id: entry.name,\n stepDisplayName,\n required: entry.required ?? true,\n })\n );\n }\n\n private createBuildStepOutputProvidersFromBuildFunctionOutputs(\n buildFunctionOutputs: BuildFunctionOutputs\n ): BuildStepOutputProvider[] {\n return buildFunctionOutputs.map((entry) =>\n typeof entry === 'string'\n ? BuildStepOutput.createProvider({ id: entry, required: true })\n : BuildStepOutput.createProvider({ id: entry.name, required: entry.required ?? true })\n );\n }\n\n private mergeBuildFunctionsWithExternal(\n configFunctions: BuildFunctionById,\n externalFunctions?: BuildFunction[]\n ): BuildFunctionById {\n const result: BuildFunctionById = { ...configFunctions };\n if (externalFunctions === undefined) {\n return result;\n }\n for (const buildFunction of externalFunctions) {\n // functions defined in config shadow the external ones\n const fullId = buildFunction.getFullId();\n if (!(fullId in result)) {\n result[fullId] = buildFunction;\n }\n }\n return result;\n }\n\n private validateExternalFunctions(externalFunctions?: BuildFunction[]): void {\n if (externalFunctions === undefined) {\n return;\n }\n const externalFunctionIds = externalFunctions.map((f) => f.getFullId());\n const duplicatedExternalFunctionIds = duplicates(externalFunctionIds);\n if (duplicatedExternalFunctionIds.length === 0) {\n return;\n }\n throw new BuildStepRuntimeError(\n `Provided external functions with duplicated IDs: ${duplicatedExternalFunctionIds\n .map((id) => `\"${id}\"`)\n .join(', ')}`\n );\n }\n\n private getExternalFunctionFullIds(): string[] {\n if (this.externalFunctions === undefined) {\n return [];\n }\n const ids = this.externalFunctions.map((f) => f.getFullId());\n return uniq(ids);\n }\n}\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { BuildRuntimePlatform } from './BuildRuntimePlatform.js';
|
|
2
2
|
import { BuildStep, BuildStepFunction } from './BuildStep.js';
|
|
3
|
-
import {
|
|
3
|
+
import { BuildStepGlobalContext } from './BuildStepContext.js';
|
|
4
4
|
import { BuildStepInputProvider, BuildStepInputValueType } from './BuildStepInput.js';
|
|
5
5
|
import { BuildStepOutputProvider } from './BuildStepOutput.js';
|
|
6
|
+
import { BuildStepEnv } from './BuildStepEnv.js';
|
|
6
7
|
export type BuildFunctionById = Record<string, BuildFunction>;
|
|
7
8
|
export type BuildFunctionCallInputs = Record<string, BuildStepInputValueType>;
|
|
8
9
|
export declare class BuildFunction {
|
|
@@ -28,11 +29,12 @@ export declare class BuildFunction {
|
|
|
28
29
|
shell?: string;
|
|
29
30
|
});
|
|
30
31
|
getFullId(): string;
|
|
31
|
-
createBuildStepFromFunctionCall(ctx:
|
|
32
|
+
createBuildStepFromFunctionCall(ctx: BuildStepGlobalContext, { id, name, callInputs, workingDirectory, shell, env, }?: {
|
|
32
33
|
id?: string;
|
|
33
34
|
name?: string;
|
|
34
35
|
callInputs?: BuildFunctionCallInputs;
|
|
35
36
|
workingDirectory?: string;
|
|
36
37
|
shell?: string;
|
|
38
|
+
env?: BuildStepEnv;
|
|
37
39
|
}): BuildStep;
|
|
38
40
|
}
|
|
@@ -20,7 +20,7 @@ export class BuildFunction {
|
|
|
20
20
|
getFullId() {
|
|
21
21
|
return this.namespace === undefined ? this.id : `${this.namespace}/${this.id}`;
|
|
22
22
|
}
|
|
23
|
-
createBuildStepFromFunctionCall(ctx, { id, name, callInputs = {}, workingDirectory, shell, } = {}) {
|
|
23
|
+
createBuildStepFromFunctionCall(ctx, { id, name, callInputs = {}, workingDirectory, shell, env, } = {}) {
|
|
24
24
|
var _a, _b;
|
|
25
25
|
const buildStepId = BuildStep.getNewId(id);
|
|
26
26
|
const buildStepName = name !== null && name !== void 0 ? name : this.name;
|
|
@@ -48,6 +48,7 @@ export class BuildFunction {
|
|
|
48
48
|
outputs,
|
|
49
49
|
shell,
|
|
50
50
|
supportedRuntimePlatforms: this.supportedRuntimePlatforms,
|
|
51
|
+
env,
|
|
51
52
|
});
|
|
52
53
|
}
|
|
53
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildFunction.js","sourceRoot":"","sources":["../src/BuildFunction.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,OAAO,EAAE,SAAS,EAAqB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"BuildFunction.js","sourceRoot":"","sources":["../src/BuildFunction.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,OAAO,EAAE,SAAS,EAAqB,MAAM,gBAAgB,CAAC;AAS9D,MAAM,OAAO,aAAa;IAWjB,MAAM,CAAC,mBAAmB,CAAC,MAAc;QAC9C,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAED,YAAY,EACV,SAAS,EACT,EAAE,EACF,IAAI,EACJ,yBAAyB,EACzB,cAAc,EACd,eAAe,EACf,OAAO,EACP,EAAE,EACF,KAAK,GAWN;QACC,MAAM,CAAC,OAAO,KAAK,SAAS,IAAI,EAAE,KAAK,SAAS,EAAE,uCAAuC,CAAC,CAAC;QAC3F,MAAM,CAAC,CAAC,CAAC,OAAO,KAAK,SAAS,IAAI,EAAE,KAAK,SAAS,CAAC,EAAE,oCAAoC,CAAC,CAAC;QAE3F,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;Q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M,OAAO,GAAG,MAAA,IAAI,CAAC,eAAe,0CAAE,GAAG,CAAC,CAAC,cAAc,EAAE,EAAE,CAAC,cAAc,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC;QAEhG,OAAO,IAAI,SAAS,CAAC,GAAG,EAAE;YACxB,EAAE,EAAE,WAAW;YACf,IAAI,EAAE,aAAa;YACnB,WAAW,EAAE,oBAAoB;YACjC,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,gBAAgB;YAChB,MAAM;YACN,OAAO;YACP,KAAK;YACL,yBAAyB,EAAE,IAAI,CAAC,yBAAyB;YACzD,GAAG;SACJ,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import assert from 'assert';\n\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport { BuildStep, BuildStepFunction } from './BuildStep.js';\nimport { BuildStepGlobalContext } from './BuildStepContext.js';\nimport { BuildStepInputProvider, BuildStepInputValueType } from './BuildStepInput.js';\nimport { BuildStepOutputProvider } from './BuildStepOutput.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\n\nexport type BuildFunctionById = Record<string, BuildFunction>;\nexport type BuildFunctionCallInputs = Record<string, BuildStepInputValueType>;\n\nexport class BuildFunction {\n public readonly namespace?: string;\n public readonly id: string;\n public readonly name?: string;\n public readonly supportedRuntimePlatforms?: BuildRuntimePlatform[];\n public readonly inputProviders?: BuildStepInputProvider[];\n public readonly outputProviders?: BuildStepOutputProvider[];\n public readonly command?: string;\n public readonly fn?: BuildStepFunction;\n public readonly shell?: string;\n\n public static isFulldIdNamespaced(fullId: string): boolean {\n return fullId.includes('/');\n }\n\n constructor({\n namespace,\n id,\n name,\n supportedRuntimePlatforms,\n inputProviders,\n outputProviders,\n command,\n fn,\n shell,\n }: {\n namespace?: string;\n id: string;\n name?: string;\n supportedRuntimePlatforms?: BuildRuntimePlatform[];\n inputProviders?: BuildStepInputProvider[];\n outputProviders?: BuildStepOutputProvider[];\n command?: string;\n fn?: BuildStepFunction;\n shell?: string;\n }) {\n assert(command !== undefined || fn !== undefined, 'Either command or fn must be defined.');\n assert(!(command !== undefined && fn !== undefined), 'Command and fn cannot be both set.');\n\n this.namespace = namespace;\n this.id = id;\n this.name = name;\n this.supportedRuntimePlatforms = supportedRuntimePlatforms;\n this.inputProviders = inputProviders;\n this.outputProviders = outputProviders;\n this.command = command;\n this.fn = fn;\n this.shell = shell;\n }\n\n public getFullId(): string {\n return this.namespace === undefined ? this.id : `${this.namespace}/${this.id}`;\n }\n\n public createBuildStepFromFunctionCall(\n ctx: BuildStepGlobalContext,\n {\n id,\n name,\n callInputs = {},\n workingDirectory,\n shell,\n env,\n }: {\n id?: string;\n name?: string;\n callInputs?: BuildFunctionCallInputs;\n workingDirectory?: string;\n shell?: string;\n env?: BuildStepEnv;\n } = {}\n ): BuildStep {\n const buildStepId = BuildStep.getNewId(id);\n const buildStepName = name ?? this.name;\n const buildStepDisplayName = BuildStep.getDisplayName({\n id: buildStepId,\n command: this.command,\n name: buildStepName,\n });\n\n const inputs = this.inputProviders?.map((inputProvider) => {\n const input = inputProvider(ctx, buildStepId);\n if (input.id in callInputs) {\n input.set(callInputs[input.id]);\n }\n return input;\n });\n const outputs = this.outputProviders?.map((outputProvider) => outputProvider(ctx, buildStepId));\n\n return new BuildStep(ctx, {\n id: buildStepId,\n name: buildStepName,\n displayName: buildStepDisplayName,\n command: this.command,\n fn: this.fn,\n workingDirectory,\n inputs,\n outputs,\n shell,\n supportedRuntimePlatforms: this.supportedRuntimePlatforms,\n env,\n });\n }\n}\n"]}
|
package/dist_esm/BuildStep.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BuildStepContext } from './BuildStepContext.js';
|
|
1
|
+
import { BuildStepContext, BuildStepGlobalContext } from './BuildStepContext.js';
|
|
2
2
|
import { BuildStepInput, BuildStepInputById } from './BuildStepInput.js';
|
|
3
3
|
import { BuildStepOutput, BuildStepOutputById } from './BuildStepOutput.js';
|
|
4
4
|
import { BuildStepEnv } from './BuildStepEnv.js';
|
|
@@ -31,6 +31,7 @@ export declare class BuildStep {
|
|
|
31
31
|
readonly fn?: BuildStepFunction;
|
|
32
32
|
readonly shell: string;
|
|
33
33
|
readonly ctx: BuildStepContext;
|
|
34
|
+
readonly env: BuildStepEnv;
|
|
34
35
|
status: BuildStepStatus;
|
|
35
36
|
private readonly internalId;
|
|
36
37
|
private readonly inputById;
|
|
@@ -42,7 +43,7 @@ export declare class BuildStep {
|
|
|
42
43
|
name?: string;
|
|
43
44
|
command?: string;
|
|
44
45
|
}): string;
|
|
45
|
-
constructor(ctx:
|
|
46
|
+
constructor(ctx: BuildStepGlobalContext, { id, name, displayName, inputs, outputs, command, fn, workingDirectory: maybeWorkingDirectory, shell, supportedRuntimePlatforms: maybeSupportedRuntimePlatforms, env, }: {
|
|
46
47
|
id: string;
|
|
47
48
|
name?: string;
|
|
48
49
|
displayName: string;
|
|
@@ -53,14 +54,16 @@ export declare class BuildStep {
|
|
|
53
54
|
workingDirectory?: string;
|
|
54
55
|
shell?: string;
|
|
55
56
|
supportedRuntimePlatforms?: BuildRuntimePlatform[];
|
|
57
|
+
env?: BuildStepEnv;
|
|
56
58
|
});
|
|
57
|
-
executeAsync(
|
|
59
|
+
executeAsync(): Promise<void>;
|
|
58
60
|
hasOutputParameter(name: string): boolean;
|
|
59
61
|
getOutputValueByName(name: string): string | undefined;
|
|
60
62
|
canBeRunOnRuntimePlatform(): boolean;
|
|
61
63
|
private executeCommandAsync;
|
|
62
64
|
private exectuteFnAsync;
|
|
63
|
-
private
|
|
65
|
+
private interpolateInputsAndGlobalContextInCommand;
|
|
64
66
|
private collectAndValidateOutputsAsync;
|
|
67
|
+
private collectAndUpdateEnvsAsync;
|
|
65
68
|
private getScriptEnv;
|
|
66
69
|
}
|
package/dist_esm/BuildStep.js
CHANGED
|
@@ -6,7 +6,7 @@ import { makeBuildStepInputByIdMap } from './BuildStepInput.js';
|
|
|
6
6
|
import { makeBuildStepOutputByIdMap, } from './BuildStepOutput.js';
|
|
7
7
|
import { BIN_PATH } from './utils/shell/bin.js';
|
|
8
8
|
import { getDefaultShell, getShellCommandAndArgs } from './utils/shell/command.js';
|
|
9
|
-
import { cleanUpStepTemporaryDirectoriesAsync, createTemporaryOutputsDirectoryAsync, saveScriptToTemporaryFileAsync, } from './BuildTemporaryFiles.js';
|
|
9
|
+
import { cleanUpStepTemporaryDirectoriesAsync, createTemporaryEnvsDirectoryAsync, createTemporaryOutputsDirectoryAsync, saveScriptToTemporaryFileAsync, } from './BuildTemporaryFiles.js';
|
|
10
10
|
import { spawnAsync } from './utils/shell/spawn.js';
|
|
11
11
|
import { interpolateWithInputs } from './utils/template.js';
|
|
12
12
|
import { BuildStepRuntimeError } from './errors.js';
|
|
@@ -48,7 +48,7 @@ export class BuildStep {
|
|
|
48
48
|
}
|
|
49
49
|
return id;
|
|
50
50
|
}
|
|
51
|
-
constructor(ctx, { id, name, displayName, inputs, outputs, command, fn, workingDirectory: maybeWorkingDirectory, shell, supportedRuntimePlatforms: maybeSupportedRuntimePlatforms, }) {
|
|
51
|
+
constructor(ctx, { id, name, displayName, inputs, outputs, command, fn, workingDirectory: maybeWorkingDirectory, shell, supportedRuntimePlatforms: maybeSupportedRuntimePlatforms, env, }) {
|
|
52
52
|
this.executed = false;
|
|
53
53
|
assert(command !== undefined || fn !== undefined, 'Either command or fn must be defined.');
|
|
54
54
|
assert(!(command !== undefined && fn !== undefined), 'Command and fn cannot be both set.');
|
|
@@ -65,26 +65,27 @@ export class BuildStep {
|
|
|
65
65
|
this.shell = shell !== null && shell !== void 0 ? shell : getDefaultShell();
|
|
66
66
|
this.status = BuildStepStatus.NEW;
|
|
67
67
|
this.internalId = uuidv4();
|
|
68
|
-
const logger = ctx.
|
|
68
|
+
const logger = ctx.baseLogger.child({
|
|
69
69
|
buildStepInternalId: this.internalId,
|
|
70
70
|
buildStepId: this.id,
|
|
71
71
|
buildStepDisplayName: this.displayName,
|
|
72
72
|
});
|
|
73
73
|
const workingDirectory = maybeWorkingDirectory !== undefined
|
|
74
|
-
? path.resolve(ctx.
|
|
75
|
-
: ctx.
|
|
76
|
-
this.ctx = ctx.
|
|
74
|
+
? path.resolve(ctx.defaultWorkingDirectory, maybeWorkingDirectory)
|
|
75
|
+
: ctx.defaultWorkingDirectory;
|
|
76
|
+
this.ctx = ctx.stepCtx({ logger, workingDirectory });
|
|
77
|
+
this.env = env !== null && env !== void 0 ? env : {};
|
|
77
78
|
ctx.registerStep(this);
|
|
78
79
|
}
|
|
79
|
-
async executeAsync(
|
|
80
|
+
async executeAsync() {
|
|
80
81
|
try {
|
|
81
82
|
this.ctx.logger.info({ marker: BuildStepLogMarker.START_STEP }, `Executing build step "${this.displayName}"`);
|
|
82
83
|
this.status = BuildStepStatus.IN_PROGRESS;
|
|
83
84
|
if (this.command !== undefined) {
|
|
84
|
-
await this.executeCommandAsync(
|
|
85
|
+
await this.executeCommandAsync();
|
|
85
86
|
}
|
|
86
87
|
else {
|
|
87
|
-
await this.exectuteFnAsync(
|
|
88
|
+
await this.exectuteFnAsync();
|
|
88
89
|
}
|
|
89
90
|
this.ctx.logger.info({ marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.SUCCESS }, `Finished build step "${this.displayName}" successfully`);
|
|
90
91
|
this.status = BuildStepStatus.SUCCESS;
|
|
@@ -113,46 +114,60 @@ export class BuildStep {
|
|
|
113
114
|
}
|
|
114
115
|
canBeRunOnRuntimePlatform() {
|
|
115
116
|
return (!this.supportedRuntimePlatforms ||
|
|
116
|
-
this.supportedRuntimePlatforms.includes(this.ctx.runtimePlatform));
|
|
117
|
+
this.supportedRuntimePlatforms.includes(this.ctx.global.runtimePlatform));
|
|
117
118
|
}
|
|
118
|
-
async executeCommandAsync(
|
|
119
|
+
async executeCommandAsync() {
|
|
119
120
|
assert(this.command, 'Command must be defined.');
|
|
120
121
|
try {
|
|
121
|
-
const command = this.
|
|
122
|
+
const command = this.interpolateInputsAndGlobalContextInCommand(this.command, this.inputs);
|
|
122
123
|
this.ctx.logger.debug(`Interpolated inputs in the command template`);
|
|
123
|
-
const outputsDir = await createTemporaryOutputsDirectoryAsync(this.ctx, this.id);
|
|
124
|
+
const outputsDir = await createTemporaryOutputsDirectoryAsync(this.ctx.global, this.id);
|
|
124
125
|
this.ctx.logger.debug(`Created temporary directory for step outputs: ${outputsDir}`);
|
|
125
|
-
const
|
|
126
|
+
const envsDir = await createTemporaryEnvsDirectoryAsync(this.ctx.global, this.id);
|
|
127
|
+
this.ctx.logger.debug(`Created temporary directory for step environment variables: ${outputsDir}`);
|
|
128
|
+
const scriptPath = await saveScriptToTemporaryFileAsync(this.ctx.global, this.id, command);
|
|
126
129
|
this.ctx.logger.debug(`Saved script to ${scriptPath}`);
|
|
127
130
|
const { command: shellCommand, args } = getShellCommandAndArgs(this.shell, scriptPath);
|
|
128
131
|
this.ctx.logger.debug(`Executing script: ${shellCommand}${args !== undefined ? ` ${args.join(' ')}` : ''}`);
|
|
129
132
|
await spawnAsync(shellCommand, args !== null && args !== void 0 ? args : [], {
|
|
130
133
|
cwd: this.ctx.workingDirectory,
|
|
131
134
|
logger: this.ctx.logger,
|
|
132
|
-
env: this.getScriptEnv(
|
|
135
|
+
env: this.getScriptEnv({ outputsDir, envsDir }),
|
|
133
136
|
});
|
|
134
137
|
this.ctx.logger.debug(`Script completed successfully`);
|
|
135
138
|
await this.collectAndValidateOutputsAsync(outputsDir);
|
|
139
|
+
await this.collectAndUpdateEnvsAsync(envsDir);
|
|
136
140
|
this.ctx.logger.debug('Finished collecting output paramters');
|
|
137
141
|
}
|
|
138
142
|
finally {
|
|
139
|
-
await cleanUpStepTemporaryDirectoriesAsync(this.ctx, this.id);
|
|
143
|
+
await cleanUpStepTemporaryDirectoriesAsync(this.ctx.global, this.id);
|
|
140
144
|
}
|
|
141
145
|
}
|
|
142
|
-
async exectuteFnAsync(
|
|
146
|
+
async exectuteFnAsync() {
|
|
143
147
|
assert(this.fn, 'Function (fn) must be defined');
|
|
144
|
-
await this.fn(this.ctx, {
|
|
148
|
+
await this.fn(this.ctx, {
|
|
149
|
+
inputs: this.inputById,
|
|
150
|
+
outputs: this.outputById,
|
|
151
|
+
env: {
|
|
152
|
+
...this.ctx.global.env,
|
|
153
|
+
...this.env,
|
|
154
|
+
},
|
|
155
|
+
});
|
|
145
156
|
}
|
|
146
|
-
|
|
157
|
+
interpolateInputsAndGlobalContextInCommand(command, inputs) {
|
|
147
158
|
if (!inputs) {
|
|
148
159
|
return command;
|
|
149
160
|
}
|
|
150
161
|
const vars = inputs.reduce((acc, input) => {
|
|
151
162
|
var _a, _b;
|
|
152
|
-
acc[input.id] =
|
|
163
|
+
acc[input.id] =
|
|
164
|
+
typeof input.value === 'object'
|
|
165
|
+
? JSON.stringify(input.value)
|
|
166
|
+
: (_b = (_a = input.value) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '';
|
|
153
167
|
return acc;
|
|
154
168
|
}, {});
|
|
155
|
-
|
|
169
|
+
const valueInterpolatedWithGlobalContext = this.ctx.global.interpolate(command);
|
|
170
|
+
return interpolateWithInputs(valueInterpolatedWithGlobalContext, vars);
|
|
156
171
|
}
|
|
157
172
|
async collectAndValidateOutputsAsync(outputsDir) {
|
|
158
173
|
var _a;
|
|
@@ -191,14 +206,26 @@ export class BuildStep {
|
|
|
191
206
|
});
|
|
192
207
|
}
|
|
193
208
|
}
|
|
194
|
-
|
|
209
|
+
async collectAndUpdateEnvsAsync(envsDir) {
|
|
210
|
+
const filenames = await fs.readdir(envsDir);
|
|
211
|
+
const entries = await Promise.all(filenames.map(async (basename) => {
|
|
212
|
+
const rawContents = await fs.readFile(path.join(envsDir, basename), 'utf-8');
|
|
213
|
+
return [basename, rawContents];
|
|
214
|
+
}));
|
|
215
|
+
this.ctx.global.updateEnv({
|
|
216
|
+
...this.ctx.global.env,
|
|
217
|
+
...Object.fromEntries(entries),
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
getScriptEnv({ envsDir, outputsDir, }) {
|
|
195
221
|
var _a;
|
|
222
|
+
const env = { ...this.ctx.global.env, ...this.env };
|
|
196
223
|
const currentPath = (_a = env.PATH) !== null && _a !== void 0 ? _a : process.env.PATH;
|
|
197
224
|
const newPath = currentPath ? `${BIN_PATH}:${currentPath}` : BIN_PATH;
|
|
198
225
|
return {
|
|
199
226
|
...env,
|
|
200
|
-
__EXPO_STEPS_BUILD_ID: this.ctx.buildId,
|
|
201
227
|
__EXPO_STEPS_OUTPUTS_DIR: outputsDir,
|
|
228
|
+
__EXPO_STEPS_ENVS_DIR: envsDir,
|
|
202
229
|
__EXPO_STEPS_WORKING_DIRECTORY: this.ctx.workingDirectory,
|
|
203
230
|
PATH: newPath,
|
|
204
231
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildStep.js","sourceRoot":"","sources":["../src/BuildStep.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAGpC,OAAO,EAAsC,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACpG,OAAO,EAGL,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EACL,oCAAoC,EACpC,oCAAoC,EACpC,8BAA8B,GAC/B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAIpD,MAAM,CA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W,GAAG,MAAA,GAAG,CAAC,IAAI,mCAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;QACjD,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,WAAW,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;QACtE,OAAO;YACL,GAAG,GAAG;YACN,qBAAqB,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO;YACvC,wBAAwB,EAAE,UAAU;YACpC,8BAA8B,EAAE,IAAI,CAAC,GAAG,CAAC,gBAAgB;YACzD,IAAI,EAAE,OAAO;SACd,CAAC;IACJ,CAAC;CACF","sourcesContent":["import assert from 'assert';\nimport fs from 'fs/promises';\nimport path from 'path';\n\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { BuildStepContext } from './BuildStepContext.js';\nimport { BuildStepInput, BuildStepInputById, makeBuildStepInputByIdMap } from './BuildStepInput.js';\nimport {\n BuildStepOutput,\n BuildStepOutputById,\n makeBuildStepOutputByIdMap,\n} from './BuildStepOutput.js';\nimport { BIN_PATH } from './utils/shell/bin.js';\nimport { getDefaultShell, getShellCommandAndArgs } from './utils/shell/command.js';\nimport {\n cleanUpStepTemporaryDirectoriesAsync,\n createTemporaryOutputsDirectoryAsync,\n saveScriptToTemporaryFileAsync,\n} from './BuildTemporaryFiles.js';\nimport { spawnAsync } from './utils/shell/spawn.js';\nimport { interpolateWithInputs } from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\n\nexport enum BuildStepStatus {\n NEW = 'new',\n IN_PROGRESS = 'in-progress',\n CANCELED = 'canceled',\n FAIL = 'fail',\n WARNING = 'warning',\n SUCCESS = 'success',\n}\n\nexport enum BuildStepLogMarker {\n START_STEP = 'start-step',\n END_STEP = 'end-step',\n}\n\nexport type BuildStepFunction = (\n ctx: BuildStepContext,\n {\n inputs,\n outputs,\n env,\n }: { inputs: BuildStepInputById; outputs: BuildStepOutputById; env: BuildStepEnv }\n) => unknown;\n\n// TODO: move to a place common with tests\nconst UUID_REGEX =\n /^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$/;\n\nexport class BuildStep {\n public readonly id: string;\n public readonly name?: string;\n public readonly displayName: string;\n public readonly supportedRuntimePlatforms?: BuildRuntimePlatform[];\n public readonly inputs?: BuildStepInput[];\n public readonly outputs?: BuildStepOutput[];\n public readonly command?: string;\n public readonly fn?: BuildStepFunction;\n public readonly shell: string;\n public readonly ctx: BuildStepContext;\n public status: BuildStepStatus;\n\n private readonly internalId: string;\n private readonly inputById: BuildStepInputById;\n private readonly outputById: BuildStepOutputById;\n private executed = false;\n\n public static getNewId(userDefinedId?: string): string {\n return userDefinedId ?? uuidv4();\n }\n\n public static getDisplayName({\n id,\n name,\n command,\n }: {\n id: string;\n name?: string;\n command?: string;\n }): string {\n if (name) {\n return name;\n }\n if (!id.match(UUID_REGEX)) {\n return id;\n }\n if (command) {\n const splits = command.trim().split('\\n');\n for (const split of splits) {\n const trimmed = split.trim();\n if (trimmed && !trimmed.startsWith('#')) {\n return trimmed;\n }\n }\n }\n return id;\n }\n\n constructor(\n ctx: BuildStepContext,\n {\n id,\n name,\n displayName,\n inputs,\n outputs,\n command,\n fn,\n workingDirectory: maybeWorkingDirectory,\n shell,\n supportedRuntimePlatforms: maybeSupportedRuntimePlatforms,\n }: {\n id: string;\n name?: string;\n displayName: string;\n inputs?: BuildStepInput[];\n outputs?: BuildStepOutput[];\n command?: string;\n fn?: BuildStepFunction;\n workingDirectory?: string;\n shell?: string;\n supportedRuntimePlatforms?: BuildRuntimePlatform[];\n }\n ) {\n assert(command !== undefined || fn !== undefined, 'Either command or fn must be defined.');\n assert(!(command !== undefined && fn !== undefined), 'Command and fn cannot be both set.');\n\n this.id = id;\n this.name = name;\n this.displayName = displayName;\n this.supportedRuntimePlatforms = maybeSupportedRuntimePlatforms;\n this.inputs = inputs;\n this.outputs = outputs;\n this.inputById = makeBuildStepInputByIdMap(inputs);\n this.outputById = makeBuildStepOutputByIdMap(outputs);\n this.fn = fn;\n this.command = command;\n this.shell = shell ?? getDefaultShell();\n this.status = BuildStepStatus.NEW;\n\n this.internalId = uuidv4();\n\n const logger = ctx.logger.child({\n buildStepInternalId: this.internalId,\n buildStepId: this.id,\n buildStepDisplayName: this.displayName,\n });\n const workingDirectory =\n maybeWorkingDirectory !== undefined\n ? path.resolve(ctx.workingDirectory, maybeWorkingDirectory)\n : ctx.workingDirectory;\n this.ctx = ctx.child({ logger, workingDirectory });\n\n ctx.registerStep(this);\n }\n\n public async executeAsync(env: BuildStepEnv = process.env): Promise<void> {\n try {\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.START_STEP },\n `Executing build step \"${this.displayName}\"`\n );\n this.status = BuildStepStatus.IN_PROGRESS;\n\n if (this.command !== undefined) {\n await this.executeCommandAsync(env);\n } else {\n await this.exectuteFnAsync(env);\n }\n\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.SUCCESS },\n `Finished build step \"${this.displayName}\" successfully`\n );\n this.status = BuildStepStatus.SUCCESS;\n } catch (err) {\n this.ctx.logger.error({ err });\n this.ctx.logger.error(\n { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.FAIL },\n `Build step \"${this.displayName}\" failed`\n );\n this.status = BuildStepStatus.FAIL;\n throw err;\n } finally {\n this.executed = true;\n }\n }\n\n public hasOutputParameter(name: string): boolean {\n return name in this.outputById;\n }\n\n public getOutputValueByName(name: string): string | undefined {\n if (!this.executed) {\n throw new BuildStepRuntimeError(\n `Failed getting output \"${name}\" from step \"${this.displayName}\". The step has not been executed yet.`\n );\n }\n if (!this.hasOutputParameter(name)) {\n throw new BuildStepRuntimeError(`Step \"${this.displayName}\" does not have output \"${name}\".`);\n }\n return this.outputById[name].value;\n }\n\n public canBeRunOnRuntimePlatform(): boolean {\n return (\n !this.supportedRuntimePlatforms ||\n this.supportedRuntimePlatforms.includes(this.ctx.runtimePlatform)\n );\n }\n\n private async executeCommandAsync(env: BuildStepEnv): Promise<void> {\n assert(this.command, 'Command must be defined.');\n\n try {\n const command = this.interpolateInputsInCommand(this.command, this.inputs);\n this.ctx.logger.debug(`Interpolated inputs in the command template`);\n\n const outputsDir = await createTemporaryOutputsDirectoryAsync(this.ctx, this.id);\n this.ctx.logger.debug(`Created temporary directory for step outputs: ${outputsDir}`);\n\n const scriptPath = await saveScriptToTemporaryFileAsync(this.ctx, this.id, command);\n this.ctx.logger.debug(`Saved script to ${scriptPath}`);\n\n const { command: shellCommand, args } = getShellCommandAndArgs(this.shell, scriptPath);\n this.ctx.logger.debug(\n `Executing script: ${shellCommand}${args !== undefined ? ` ${args.join(' ')}` : ''}`\n );\n await spawnAsync(shellCommand, args ?? [], {\n cwd: this.ctx.workingDirectory,\n logger: this.ctx.logger,\n env: this.getScriptEnv(env, outputsDir),\n });\n this.ctx.logger.debug(`Script completed successfully`);\n\n await this.collectAndValidateOutputsAsync(outputsDir);\n this.ctx.logger.debug('Finished collecting output paramters');\n } finally {\n await cleanUpStepTemporaryDirectoriesAsync(this.ctx, this.id);\n }\n }\n\n private async exectuteFnAsync(env: BuildStepEnv): Promise<void> {\n assert(this.fn, 'Function (fn) must be defined');\n\n await this.fn(this.ctx, { inputs: this.inputById, outputs: this.outputById, env });\n }\n\n private interpolateInputsInCommand(command: string, inputs?: BuildStepInput[]): string {\n if (!inputs) {\n return command;\n }\n const vars = inputs.reduce((acc, input) => {\n acc[input.id] = input.value?.toString() ?? '';\n return acc;\n }, {} as Record<string, string>);\n return interpolateWithInputs(command, vars);\n }\n\n private async collectAndValidateOutputsAsync(outputsDir: string): Promise<void> {\n const files = await fs.readdir(outputsDir);\n\n const nonDefinedOutputIds: string[] = [];\n for (const outputId of files) {\n if (!(outputId in this.outputById)) {\n nonDefinedOutputIds.push(outputId);\n } else {\n const file = path.join(outputsDir, outputId);\n const rawContents = await fs.readFile(file, 'utf-8');\n const value = rawContents.trim();\n this.outputById[outputId].set(value);\n }\n }\n\n if (nonDefinedOutputIds.length > 0) {\n const idsString = nonDefinedOutputIds.map((i) => `\"${i}\"`).join(', ');\n this.ctx.logger.warn(`Some outputs are not defined in step config: ${idsString}`);\n }\n\n const nonSetRequiredOutputIds: string[] = [];\n for (const output of this.outputs ?? []) {\n try {\n const value = output.value;\n this.ctx.logger.debug(`Output parameter \"${output.id}\" is set to \"${value}\"`);\n } catch (err) {\n this.ctx.logger.debug({ err }, `Getting value for output parameter \"${output.id}\" failed.`);\n nonSetRequiredOutputIds.push(output.id);\n }\n }\n if (nonSetRequiredOutputIds.length > 0) {\n const idsString = nonSetRequiredOutputIds.map((i) => `\"${i}\"`).join(', ');\n throw new BuildStepRuntimeError(`Some required outputs have not been set: ${idsString}`, {\n metadata: { ids: nonSetRequiredOutputIds },\n });\n }\n }\n\n private getScriptEnv(env: BuildStepEnv, outputsDir: string): Record<string, string> {\n const currentPath = env.PATH ?? process.env.PATH;\n const newPath = currentPath ? `${BIN_PATH}:${currentPath}` : BIN_PATH;\n return {\n ...env,\n __EXPO_STEPS_BUILD_ID: this.ctx.buildId,\n __EXPO_STEPS_OUTPUTS_DIR: outputsDir,\n __EXPO_STEPS_WORKING_DIRECTORY: this.ctx.workingDirectory,\n PATH: newPath,\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BuildStep.js","sourceRoot":"","sources":["../src/BuildStep.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAGpC,OAAO,EAAsC,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACpG,OAAO,EAGL,0BAA0B,GAC3B,MAAM,sBAA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AE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC;YAC7E,OAAO,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QACjC,CAAC,CAAC,CACH,CAAC;QACF,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC;YACxB,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG;YACtB,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC;SAC/B,CAAC,CAAC;IACL,CAAC;IAEO,YAAY,CAAC,EACnB,OAAO,EACP,UAAU,GAIX;;QACC,MAAM,GAAG,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACpD,MAAM,WAAW,GAAG,MAAA,GAAG,CAAC,IAAI,mCAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;QACjD,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,WAAW,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;QACtE,OAAO;YACL,GAAG,GAAG;YACN,wBAAwB,EAAE,UAAU;YACpC,qBAAqB,EAAE,OAAO;YAC9B,8BAA8B,EAAE,IAAI,CAAC,GAAG,CAAC,gBAAgB;YACzD,IAAI,EAAE,OAAO;SACd,CAAC;IACJ,CAAC;CACF","sourcesContent":["import assert from 'assert';\nimport fs from 'fs/promises';\nimport path from 'path';\n\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { BuildStepContext, BuildStepGlobalContext } from './BuildStepContext.js';\nimport { BuildStepInput, BuildStepInputById, makeBuildStepInputByIdMap } from './BuildStepInput.js';\nimport {\n BuildStepOutput,\n BuildStepOutputById,\n makeBuildStepOutputByIdMap,\n} from './BuildStepOutput.js';\nimport { BIN_PATH } from './utils/shell/bin.js';\nimport { getDefaultShell, getShellCommandAndArgs } from './utils/shell/command.js';\nimport {\n cleanUpStepTemporaryDirectoriesAsync,\n createTemporaryEnvsDirectoryAsync,\n createTemporaryOutputsDirectoryAsync,\n saveScriptToTemporaryFileAsync,\n} from './BuildTemporaryFiles.js';\nimport { spawnAsync } from './utils/shell/spawn.js';\nimport { interpolateWithInputs } from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\n\nexport enum BuildStepStatus {\n NEW = 'new',\n IN_PROGRESS = 'in-progress',\n CANCELED = 'canceled',\n FAIL = 'fail',\n WARNING = 'warning',\n SUCCESS = 'success',\n}\n\nexport enum BuildStepLogMarker {\n START_STEP = 'start-step',\n END_STEP = 'end-step',\n}\n\nexport type BuildStepFunction = (\n ctx: BuildStepContext,\n {\n inputs,\n outputs,\n env,\n }: { inputs: BuildStepInputById; outputs: BuildStepOutputById; env: BuildStepEnv }\n) => unknown;\n\n// TODO: move to a place common with tests\nconst UUID_REGEX =\n /^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$/;\n\nexport class BuildStep {\n public readonly id: string;\n public readonly name?: string;\n public readonly displayName: string;\n public readonly supportedRuntimePlatforms?: BuildRuntimePlatform[];\n public readonly inputs?: BuildStepInput[];\n public readonly outputs?: BuildStepOutput[];\n public readonly command?: string;\n public readonly fn?: BuildStepFunction;\n public readonly shell: string;\n public readonly ctx: BuildStepContext;\n public readonly env: BuildStepEnv;\n public status: BuildStepStatus;\n\n private readonly internalId: string;\n private readonly inputById: BuildStepInputById;\n private readonly outputById: BuildStepOutputById;\n private executed = false;\n\n public static getNewId(userDefinedId?: string): string {\n return userDefinedId ?? uuidv4();\n }\n\n public static getDisplayName({\n id,\n name,\n command,\n }: {\n id: string;\n name?: string;\n command?: string;\n }): string {\n if (name) {\n return name;\n }\n if (!id.match(UUID_REGEX)) {\n return id;\n }\n if (command) {\n const splits = command.trim().split('\\n');\n for (const split of splits) {\n const trimmed = split.trim();\n if (trimmed && !trimmed.startsWith('#')) {\n return trimmed;\n }\n }\n }\n return id;\n }\n\n constructor(\n ctx: BuildStepGlobalContext,\n {\n id,\n name,\n displayName,\n inputs,\n outputs,\n command,\n fn,\n workingDirectory: maybeWorkingDirectory,\n shell,\n supportedRuntimePlatforms: maybeSupportedRuntimePlatforms,\n env,\n }: {\n id: string;\n name?: string;\n displayName: string;\n inputs?: BuildStepInput[];\n outputs?: BuildStepOutput[];\n command?: string;\n fn?: BuildStepFunction;\n workingDirectory?: string;\n shell?: string;\n supportedRuntimePlatforms?: BuildRuntimePlatform[];\n env?: BuildStepEnv;\n }\n ) {\n assert(command !== undefined || fn !== undefined, 'Either command or fn must be defined.');\n assert(!(command !== undefined && fn !== undefined), 'Command and fn cannot be both set.');\n\n this.id = id;\n this.name = name;\n this.displayName = displayName;\n this.supportedRuntimePlatforms = maybeSupportedRuntimePlatforms;\n this.inputs = inputs;\n this.outputs = outputs;\n this.inputById = makeBuildStepInputByIdMap(inputs);\n this.outputById = makeBuildStepOutputByIdMap(outputs);\n this.fn = fn;\n this.command = command;\n this.shell = shell ?? getDefaultShell();\n this.status = BuildStepStatus.NEW;\n\n this.internalId = uuidv4();\n\n const logger = ctx.baseLogger.child({\n buildStepInternalId: this.internalId,\n buildStepId: this.id,\n buildStepDisplayName: this.displayName,\n });\n const workingDirectory =\n maybeWorkingDirectory !== undefined\n ? path.resolve(ctx.defaultWorkingDirectory, maybeWorkingDirectory)\n : ctx.defaultWorkingDirectory;\n this.ctx = ctx.stepCtx({ logger, workingDirectory });\n this.env = env ?? {};\n\n ctx.registerStep(this);\n }\n\n public async executeAsync(): Promise<void> {\n try {\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.START_STEP },\n `Executing build step \"${this.displayName}\"`\n );\n this.status = BuildStepStatus.IN_PROGRESS;\n\n if (this.command !== undefined) {\n await this.executeCommandAsync();\n } else {\n await this.exectuteFnAsync();\n }\n\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.SUCCESS },\n `Finished build step \"${this.displayName}\" successfully`\n );\n this.status = BuildStepStatus.SUCCESS;\n } catch (err) {\n this.ctx.logger.error({ err });\n this.ctx.logger.error(\n { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.FAIL },\n `Build step \"${this.displayName}\" failed`\n );\n this.status = BuildStepStatus.FAIL;\n throw err;\n } finally {\n this.executed = true;\n }\n }\n\n public hasOutputParameter(name: string): boolean {\n return name in this.outputById;\n }\n\n public getOutputValueByName(name: string): string | undefined {\n if (!this.executed) {\n throw new BuildStepRuntimeError(\n `Failed getting output \"${name}\" from step \"${this.displayName}\". The step has not been executed yet.`\n );\n }\n if (!this.hasOutputParameter(name)) {\n throw new BuildStepRuntimeError(`Step \"${this.displayName}\" does not have output \"${name}\".`);\n }\n return this.outputById[name].value;\n }\n\n public canBeRunOnRuntimePlatform(): boolean {\n return (\n !this.supportedRuntimePlatforms ||\n this.supportedRuntimePlatforms.includes(this.ctx.global.runtimePlatform)\n );\n }\n\n private async executeCommandAsync(): Promise<void> {\n assert(this.command, 'Command must be defined.');\n\n try {\n const command = this.interpolateInputsAndGlobalContextInCommand(this.command, this.inputs);\n this.ctx.logger.debug(`Interpolated inputs in the command template`);\n\n const outputsDir = await createTemporaryOutputsDirectoryAsync(this.ctx.global, this.id);\n this.ctx.logger.debug(`Created temporary directory for step outputs: ${outputsDir}`);\n\n const envsDir = await createTemporaryEnvsDirectoryAsync(this.ctx.global, this.id);\n this.ctx.logger.debug(\n `Created temporary directory for step environment variables: ${outputsDir}`\n );\n\n const scriptPath = await saveScriptToTemporaryFileAsync(this.ctx.global, this.id, command);\n this.ctx.logger.debug(`Saved script to ${scriptPath}`);\n\n const { command: shellCommand, args } = getShellCommandAndArgs(this.shell, scriptPath);\n this.ctx.logger.debug(\n `Executing script: ${shellCommand}${args !== undefined ? ` ${args.join(' ')}` : ''}`\n );\n await spawnAsync(shellCommand, args ?? [], {\n cwd: this.ctx.workingDirectory,\n logger: this.ctx.logger,\n env: this.getScriptEnv({ outputsDir, envsDir }),\n });\n this.ctx.logger.debug(`Script completed successfully`);\n\n await this.collectAndValidateOutputsAsync(outputsDir);\n await this.collectAndUpdateEnvsAsync(envsDir);\n this.ctx.logger.debug('Finished collecting output paramters');\n } finally {\n await cleanUpStepTemporaryDirectoriesAsync(this.ctx.global, this.id);\n }\n }\n\n private async exectuteFnAsync(): Promise<void> {\n assert(this.fn, 'Function (fn) must be defined');\n\n await this.fn(this.ctx, {\n inputs: this.inputById,\n outputs: this.outputById,\n env: {\n ...this.ctx.global.env,\n ...this.env,\n },\n });\n }\n\n private interpolateInputsAndGlobalContextInCommand(\n command: string,\n inputs?: BuildStepInput[]\n ): string {\n if (!inputs) {\n return command;\n }\n const vars = inputs.reduce((acc, input) => {\n acc[input.id] =\n typeof input.value === 'object'\n ? JSON.stringify(input.value)\n : input.value?.toString() ?? '';\n return acc;\n }, {} as Record<string, string>);\n const valueInterpolatedWithGlobalContext = this.ctx.global.interpolate(command);\n return interpolateWithInputs(valueInterpolatedWithGlobalContext, vars);\n }\n\n private async collectAndValidateOutputsAsync(outputsDir: string): Promise<void> {\n const files = await fs.readdir(outputsDir);\n\n const nonDefinedOutputIds: string[] = [];\n for (const outputId of files) {\n if (!(outputId in this.outputById)) {\n nonDefinedOutputIds.push(outputId);\n } else {\n const file = path.join(outputsDir, outputId);\n const rawContents = await fs.readFile(file, 'utf-8');\n const value = rawContents.trim();\n this.outputById[outputId].set(value);\n }\n }\n\n if (nonDefinedOutputIds.length > 0) {\n const idsString = nonDefinedOutputIds.map((i) => `\"${i}\"`).join(', ');\n this.ctx.logger.warn(`Some outputs are not defined in step config: ${idsString}`);\n }\n\n const nonSetRequiredOutputIds: string[] = [];\n for (const output of this.outputs ?? []) {\n try {\n const value = output.value;\n this.ctx.logger.debug(`Output parameter \"${output.id}\" is set to \"${value}\"`);\n } catch (err) {\n this.ctx.logger.debug({ err }, `Getting value for output parameter \"${output.id}\" failed.`);\n nonSetRequiredOutputIds.push(output.id);\n }\n }\n if (nonSetRequiredOutputIds.length > 0) {\n const idsString = nonSetRequiredOutputIds.map((i) => `\"${i}\"`).join(', ');\n throw new BuildStepRuntimeError(`Some required outputs have not been set: ${idsString}`, {\n metadata: { ids: nonSetRequiredOutputIds },\n });\n }\n }\n\n private async collectAndUpdateEnvsAsync(envsDir: string): Promise<void> {\n const filenames = await fs.readdir(envsDir);\n\n const entries = await Promise.all(\n filenames.map(async (basename) => {\n const rawContents = await fs.readFile(path.join(envsDir, basename), 'utf-8');\n return [basename, rawContents];\n })\n );\n this.ctx.global.updateEnv({\n ...this.ctx.global.env,\n ...Object.fromEntries(entries),\n });\n }\n\n private getScriptEnv({\n envsDir,\n outputsDir,\n }: {\n envsDir: string;\n outputsDir: string;\n }): Record<string, string> {\n const env = { ...this.ctx.global.env, ...this.env };\n const currentPath = env.PATH ?? process.env.PATH;\n const newPath = currentPath ? `${BIN_PATH}:${currentPath}` : BIN_PATH;\n return {\n ...env,\n __EXPO_STEPS_OUTPUTS_DIR: outputsDir,\n __EXPO_STEPS_ENVS_DIR: envsDir,\n __EXPO_STEPS_WORKING_DIRECTORY: this.ctx.workingDirectory,\n PATH: newPath,\n };\n }\n}\n"]}
|
|
@@ -1,21 +1,46 @@
|
|
|
1
1
|
import { bunyan } from '@expo/logger';
|
|
2
2
|
import { BuildStep } from './BuildStep.js';
|
|
3
3
|
import { BuildRuntimePlatform } from './BuildRuntimePlatform.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
readonly logger: bunyan;
|
|
7
|
-
readonly skipCleanup: boolean;
|
|
8
|
-
readonly runtimePlatform: BuildRuntimePlatform;
|
|
4
|
+
import { BuildStepEnv } from './BuildStepEnv.js';
|
|
5
|
+
export interface ExternalBuildContextProvider {
|
|
9
6
|
readonly projectSourceDirectory: string;
|
|
10
7
|
readonly projectTargetDirectory: string;
|
|
8
|
+
readonly defaultWorkingDirectory: string;
|
|
9
|
+
readonly runtimePlatform: BuildRuntimePlatform;
|
|
10
|
+
readonly logger: bunyan;
|
|
11
|
+
readonly staticContext: any;
|
|
12
|
+
readonly env: BuildStepEnv;
|
|
13
|
+
updateEnv(env: BuildStepEnv): void;
|
|
14
|
+
}
|
|
15
|
+
export declare class BuildStepGlobalContext {
|
|
16
|
+
private readonly provider;
|
|
17
|
+
readonly skipCleanup: boolean;
|
|
11
18
|
readonly stepsInternalBuildDirectory: string;
|
|
12
|
-
readonly
|
|
19
|
+
readonly runtimePlatform: BuildRuntimePlatform;
|
|
20
|
+
readonly baseLogger: bunyan;
|
|
13
21
|
private stepById;
|
|
14
|
-
constructor(
|
|
22
|
+
constructor(provider: ExternalBuildContextProvider, skipCleanup: boolean);
|
|
23
|
+
get projectSourceDirectory(): string;
|
|
24
|
+
get projectTargetDirectory(): string;
|
|
25
|
+
get defaultWorkingDirectory(): string;
|
|
26
|
+
get env(): BuildStepEnv;
|
|
27
|
+
get staticContext(): Record<string, any>;
|
|
28
|
+
updateEnv(updatedEnv: BuildStepEnv): void;
|
|
15
29
|
registerStep(step: BuildStep): void;
|
|
16
30
|
getStepOutputValue(path: string): string | undefined;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
31
|
+
interpolate(value: string): string;
|
|
32
|
+
stepCtx(options: {
|
|
33
|
+
logger: bunyan;
|
|
34
|
+
workingDirectory: string;
|
|
20
35
|
}): BuildStepContext;
|
|
21
36
|
}
|
|
37
|
+
export declare class BuildStepContext {
|
|
38
|
+
private readonly ctx;
|
|
39
|
+
readonly logger: bunyan;
|
|
40
|
+
readonly workingDirectory: string;
|
|
41
|
+
constructor(ctx: BuildStepGlobalContext, { logger, workingDirectory, }: {
|
|
42
|
+
logger: bunyan;
|
|
43
|
+
workingDirectory: string;
|
|
44
|
+
});
|
|
45
|
+
get global(): BuildStepGlobalContext;
|
|
46
|
+
}
|
|
@@ -1,19 +1,34 @@
|
|
|
1
1
|
import os from 'os';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import {
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
+
import { getObjectValueForInterpolation, interpolateWithGlobalContext, parseOutputPath, } from './utils/template.js';
|
|
4
5
|
import { BuildStepRuntimeError } from './errors.js';
|
|
5
|
-
export class
|
|
6
|
-
constructor(
|
|
7
|
-
this.
|
|
8
|
-
this.logger = logger;
|
|
6
|
+
export class BuildStepGlobalContext {
|
|
7
|
+
constructor(provider, skipCleanup) {
|
|
8
|
+
this.provider = provider;
|
|
9
9
|
this.skipCleanup = skipCleanup;
|
|
10
|
-
this.runtimePlatform = runtimePlatform;
|
|
11
|
-
this.projectSourceDirectory = projectSourceDirectory;
|
|
12
|
-
this.projectTargetDirectory = projectTargetDirectory;
|
|
13
10
|
this.stepById = {};
|
|
14
|
-
this.stepsInternalBuildDirectory = path.join(os.tmpdir(), 'eas-build',
|
|
15
|
-
this.
|
|
16
|
-
|
|
11
|
+
this.stepsInternalBuildDirectory = path.join(os.tmpdir(), 'eas-build', uuidv4());
|
|
12
|
+
this.runtimePlatform = provider.runtimePlatform;
|
|
13
|
+
this.baseLogger = provider.logger;
|
|
14
|
+
}
|
|
15
|
+
get projectSourceDirectory() {
|
|
16
|
+
return this.provider.projectSourceDirectory;
|
|
17
|
+
}
|
|
18
|
+
get projectTargetDirectory() {
|
|
19
|
+
return this.provider.projectTargetDirectory;
|
|
20
|
+
}
|
|
21
|
+
get defaultWorkingDirectory() {
|
|
22
|
+
return this.provider.defaultWorkingDirectory;
|
|
23
|
+
}
|
|
24
|
+
get env() {
|
|
25
|
+
return this.provider.env;
|
|
26
|
+
}
|
|
27
|
+
get staticContext() {
|
|
28
|
+
return this.provider.staticContext();
|
|
29
|
+
}
|
|
30
|
+
updateEnv(updatedEnv) {
|
|
31
|
+
this.provider.updateEnv(updatedEnv);
|
|
17
32
|
}
|
|
18
33
|
registerStep(step) {
|
|
19
34
|
this.stepById[step.id] = step;
|
|
@@ -25,8 +40,29 @@ export class BuildStepContext {
|
|
|
25
40
|
}
|
|
26
41
|
return this.stepById[stepId].getOutputValueByName(outputId);
|
|
27
42
|
}
|
|
28
|
-
|
|
29
|
-
return
|
|
43
|
+
interpolate(value) {
|
|
44
|
+
return interpolateWithGlobalContext(value, (path) => {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
return ((_b = (_a = getObjectValueForInterpolation(path, {
|
|
47
|
+
eas: {
|
|
48
|
+
runtimePlatform: this.runtimePlatform,
|
|
49
|
+
...this.staticContext,
|
|
50
|
+
},
|
|
51
|
+
})) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '');
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
stepCtx(options) {
|
|
55
|
+
return new BuildStepContext(this, options);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export class BuildStepContext {
|
|
59
|
+
constructor(ctx, { logger, workingDirectory, }) {
|
|
60
|
+
this.ctx = ctx;
|
|
61
|
+
this.logger = logger !== null && logger !== void 0 ? logger : ctx.baseLogger;
|
|
62
|
+
this.workingDirectory = workingDirectory !== null && workingDirectory !== void 0 ? workingDirectory : ctx.defaultWorkingDirectory;
|
|
63
|
+
}
|
|
64
|
+
get global() {
|
|
65
|
+
return this.ctx;
|
|
30
66
|
}
|
|
31
67
|
}
|
|
32
68
|
//# sourceMappingURL=BuildStepContext.js.map
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"BuildStepContext.js","sourceRoot":"","sources":["../src/BuildStepContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,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/logger';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { BuildStep } 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\nexport interface ExternalBuildContextProvider {\n readonly projectSourceDirectory: string;\n readonly projectTargetDirectory: string;\n readonly defaultWorkingDirectory: string;\n readonly runtimePlatform: BuildRuntimePlatform;\n readonly logger: bunyan;\n\n readonly staticContext: any;\n\n readonly env: BuildStepEnv;\n updateEnv(env: BuildStepEnv): void;\n}\n\nexport class BuildStepGlobalContext {\n public readonly stepsInternalBuildDirectory: string;\n public readonly runtimePlatform: BuildRuntimePlatform;\n public readonly baseLogger: bunyan;\n\n private stepById: Record<string, BuildStep> = {};\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.provider.defaultWorkingDirectory;\n }\n\n public get env(): BuildStepEnv {\n return this.provider.env;\n }\n\n public get staticContext(): Record<string, any> {\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; workingDirectory: string }): BuildStepContext {\n return new BuildStepContext(this, options);\n }\n}\n\nexport class BuildStepContext {\n public readonly logger: bunyan;\n public readonly workingDirectory: string;\n\n constructor(\n private readonly ctx: BuildStepGlobalContext,\n {\n logger,\n workingDirectory,\n }: {\n logger: bunyan;\n workingDirectory: string;\n }\n ) {\n this.logger = logger ?? ctx.baseLogger;\n this.workingDirectory = workingDirectory ?? ctx.defaultWorkingDirectory;\n }\n\n public get global(): BuildStepGlobalContext {\n return this.ctx;\n }\n}\n"]}
|