@expo/steps 1.0.252 → 1.0.260

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.
@@ -6,7 +6,7 @@ import { v4 as uuidv4 } from 'uuid';
6
6
  import { makeBuildStepInputByIdMap } from './BuildStepInput.js';
7
7
  import { BuildStepOutput, makeBuildStepOutputByIdMap, } from './BuildStepOutput.js';
8
8
  import { BIN_PATH } from './utils/shell/bin.js';
9
- import { getDefaultShell, getShellCommandAndArgs } from './utils/shell/command.js';
9
+ import { getShellCommandAndArgs } from './utils/shell/command.js';
10
10
  import { cleanUpStepTemporaryDirectoriesAsync, getTemporaryEnvsDirPath, getTemporaryOutputsDirPath, saveScriptToTemporaryFileAsync, } from './BuildTemporaryFiles.js';
11
11
  import { spawnAsync } from './utils/shell/spawn.js';
12
12
  import { interpolateWithInputs, interpolateWithOutputs } from './utils/template.js';
@@ -89,7 +89,7 @@ export class BuildStep extends BuildStepOutputAccessor {
89
89
  }
90
90
  return id;
91
91
  }
92
- constructor(ctx, { id, name, displayName, inputs, outputs, command, fn, workingDirectory: maybeWorkingDirectory, shell, supportedRuntimePlatforms: maybeSupportedRuntimePlatforms, env, ifCondition, }) {
92
+ constructor(ctx, { id, name, displayName, inputs, outputs, command, fn, workingDirectory: maybeWorkingDirectory, shell, supportedRuntimePlatforms: maybeSupportedRuntimePlatforms, env, ifCondition, timeoutMs, }) {
93
93
  assert(command !== undefined || fn !== undefined, 'Either command or fn must be defined.');
94
94
  assert(!(command !== undefined && fn !== undefined), 'Command and fn cannot be both set.');
95
95
  const outputById = makeBuildStepOutputByIdMap(outputs);
@@ -104,8 +104,9 @@ export class BuildStep extends BuildStepOutputAccessor {
104
104
  this.outputById = outputById;
105
105
  this.fn = fn;
106
106
  this.command = command;
107
- this.shell = shell !== null && shell !== void 0 ? shell : getDefaultShell();
107
+ this.shell = shell !== null && shell !== void 0 ? shell : '/bin/bash -eo pipefail';
108
108
  this.ifCondition = ifCondition;
109
+ this.timeoutMs = timeoutMs;
109
110
  this.status = BuildStepStatus.NEW;
110
111
  this.internalId = uuidv4();
111
112
  const logger = ctx.baseLogger.child({
@@ -127,11 +128,36 @@ export class BuildStep extends BuildStepOutputAccessor {
127
128
  this.ctx.logger.debug(`Created temporary directory for step outputs: ${this.outputsDir}`);
128
129
  await fs.mkdir(this.envsDir, { recursive: true });
129
130
  this.ctx.logger.debug(`Created temporary directory for step environment variables: ${this.envsDir}`);
130
- if (this.command !== undefined) {
131
- await this.executeCommandAsync();
131
+ if (this.timeoutMs !== undefined) {
132
+ const abortController = new AbortController();
133
+ let timeoutId;
134
+ const timeoutPromise = new Promise((_, reject) => {
135
+ timeoutId = setTimeout(() => {
136
+ // Reject with timeout error FIRST, before killing the process
137
+ // This ensures the timeout error wins the race
138
+ reject(new BuildStepRuntimeError(`Build step "${this.displayName}" timed out after ${this.timeoutMs}ms`));
139
+ abortController.abort();
140
+ }, this.timeoutMs);
141
+ });
142
+ try {
143
+ await Promise.race([
144
+ this.command !== undefined
145
+ ? this.executeCommandAsync({ signal: abortController.signal })
146
+ : this.executeFnAsync({ signal: abortController.signal }),
147
+ timeoutPromise,
148
+ ]);
149
+ }
150
+ finally {
151
+ if (timeoutId) {
152
+ clearTimeout(timeoutId);
153
+ }
154
+ }
132
155
  }
133
156
  else {
134
- await this.executeFnAsync();
157
+ const executionPromise = this.command !== undefined
158
+ ? this.executeCommandAsync({ signal: null })
159
+ : this.executeFnAsync({ signal: null });
160
+ await executionPromise;
135
161
  }
136
162
  this.ctx.logger.info({ marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.SUCCESS }, `Finished build step "${this.displayName}" successfully`);
137
163
  this.status = BuildStepStatus.SUCCESS;
@@ -203,7 +229,7 @@ export class BuildStep extends BuildStepOutputAccessor {
203
229
  env: this.getScriptEnv(),
204
230
  };
205
231
  }
206
- async executeCommandAsync() {
232
+ async executeCommandAsync({ signal }) {
207
233
  assert(this.command, 'Command must be defined.');
208
234
  const interpolatedCommand = interpolateJobContext({
209
235
  target: this.command,
@@ -235,10 +261,11 @@ export class BuildStep extends BuildStepOutputAccessor {
235
261
  env: this.getScriptEnv(),
236
262
  // stdin is /dev/null, std{out,err} are piped into logger.
237
263
  stdio: ['ignore', 'pipe', 'pipe'],
264
+ signal: signal !== null && signal !== void 0 ? signal : undefined,
238
265
  });
239
266
  this.ctx.logger.debug(`Script completed successfully`);
240
267
  }
241
- async executeFnAsync() {
268
+ async executeFnAsync({ signal }) {
242
269
  assert(this.fn, 'Function (fn) must be defined');
243
270
  await this.fn(this.ctx, {
244
271
  inputs: Object.fromEntries(Object.entries(this.inputById).map(([key, input]) => [
@@ -247,6 +274,7 @@ export class BuildStep extends BuildStepOutputAccessor {
247
274
  ])),
248
275
  outputs: this.outputById,
249
276
  env: this.getScriptEnv(),
277
+ signal: signal !== null && signal !== void 0 ? signal : undefined,
250
278
  });
251
279
  this.ctx.logger.debug(`Script completed successfully`);
252
280
  }
@@ -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;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAIpC,OAAO,EAAsC,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACpG,OAAO,EACL,eAAe,EAGf,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EACL,oCAAoC,EACpC,uBAAuB,EACvB,0BAA0B,EAC1B,8BAA8B,GAC/B,MAAM,0BAA0B,C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AAC;IACJ,CAAC;CACF","sourcesContent":["import assert from 'assert';\nimport fs from 'fs/promises';\nimport path from 'path';\nimport { Buffer } from 'buffer';\n\nimport { v4 as uuidv4 } from 'uuid';\nimport { JobInterpolationContext } from '@expo/eas-build-job';\n\nimport { BuildStepContext, BuildStepGlobalContext } from './BuildStepContext.js';\nimport { BuildStepInput, BuildStepInputById, makeBuildStepInputByIdMap } from './BuildStepInput.js';\nimport {\n BuildStepOutput,\n BuildStepOutputById,\n SerializedBuildStepOutput,\n makeBuildStepOutputByIdMap,\n} from './BuildStepOutput.js';\nimport { BIN_PATH } from './utils/shell/bin.js';\nimport { getDefaultShell, getShellCommandAndArgs } from './utils/shell/command.js';\nimport {\n cleanUpStepTemporaryDirectoriesAsync,\n getTemporaryEnvsDirPath,\n getTemporaryOutputsDirPath,\n saveScriptToTemporaryFileAsync,\n} from './BuildTemporaryFiles.js';\nimport { spawnAsync } from './utils/shell/spawn.js';\nimport { interpolateWithInputs, interpolateWithOutputs } from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport { jsepEval } from './utils/jsepEval.js';\nimport { interpolateJobContext } from './interpolation.js';\n\nexport enum BuildStepStatus {\n NEW = 'new',\n IN_PROGRESS = 'in-progress',\n SKIPPED = 'skipped',\n FAIL = 'fail',\n WARNING = 'warning',\n SUCCESS = 'success',\n}\n\nexport enum BuildStepLogMarker {\n START_STEP = 'start-step',\n END_STEP = 'end-step',\n}\n\nexport type BuildStepFunction = (\n ctx: BuildStepContext,\n {\n inputs,\n outputs,\n env,\n }: {\n inputs: { [key: string]: { value: unknown } };\n outputs: BuildStepOutputById;\n env: BuildStepEnv;\n }\n) => unknown;\n\n// TODO: move to a place common with tests\nconst UUID_REGEX =\n /^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$/;\n\nexport interface SerializedBuildStepOutputAccessor {\n id: string;\n executed: boolean;\n outputById: Record<string, SerializedBuildStepOutput>;\n displayName: string;\n}\n\nexport class BuildStepOutputAccessor {\n constructor(\n public readonly id: string,\n public readonly displayName: string,\n protected readonly executed: boolean,\n protected readonly outputById: BuildStepOutputById\n ) {}\n\n public get outputs(): BuildStepOutput[] {\n return Object.values(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 hasOutputParameter(name: string): boolean {\n return name in this.outputById;\n }\n\n public serialize(): SerializedBuildStepOutputAccessor {\n return {\n id: this.id,\n executed: this.executed,\n outputById: Object.fromEntries(\n Object.entries(this.outputById).map(([key, value]) => [key, value.serialize()])\n ),\n displayName: this.displayName,\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepOutputAccessor\n ): BuildStepOutputAccessor {\n const outputById = Object.fromEntries(\n Object.entries(serialized.outputById).map(([key, value]) => [\n key,\n BuildStepOutput.deserialize(value),\n ])\n );\n return new BuildStepOutputAccessor(\n serialized.id,\n serialized.displayName,\n serialized.executed,\n outputById\n );\n }\n}\n\nexport class BuildStep extends BuildStepOutputAccessor {\n public readonly id: string;\n public readonly name?: string;\n public readonly displayName: string;\n public readonly supportedRuntimePlatforms?: BuildRuntimePlatform[];\n public readonly inputs?: BuildStepInput[];\n public readonly outputById: BuildStepOutputById;\n public readonly command?: string;\n public readonly fn?: BuildStepFunction;\n public readonly shell: string;\n public readonly ctx: BuildStepContext;\n public readonly stepEnvOverrides: BuildStepEnv;\n public readonly ifCondition?: string;\n public status: BuildStepStatus;\n private readonly outputsDir: string;\n private readonly envsDir: string;\n\n private readonly internalId: string;\n private readonly inputById: BuildStepInputById;\n protected executed = false;\n\n public static getNewId(userDefinedId?: string): string {\n return userDefinedId ?? uuidv4();\n }\n\n public static getDisplayName({\n id,\n name,\n command,\n }: {\n id: string;\n name?: string;\n command?: string;\n }): string {\n if (name) {\n return name;\n }\n if (!id.match(UUID_REGEX)) {\n return id;\n }\n if (command) {\n const splits = command.trim().split('\\n');\n for (const split of splits) {\n const trimmed = split.trim();\n if (trimmed && !trimmed.startsWith('#')) {\n return trimmed;\n }\n }\n }\n return id;\n }\n\n constructor(\n ctx: BuildStepGlobalContext,\n {\n id,\n name,\n displayName,\n inputs,\n outputs,\n command,\n fn,\n workingDirectory: maybeWorkingDirectory,\n shell,\n supportedRuntimePlatforms: maybeSupportedRuntimePlatforms,\n env,\n ifCondition,\n }: {\n id: string;\n name?: string;\n displayName: string;\n inputs?: BuildStepInput[];\n outputs?: BuildStepOutput[];\n command?: string;\n fn?: BuildStepFunction;\n workingDirectory?: string;\n shell?: string;\n supportedRuntimePlatforms?: BuildRuntimePlatform[];\n env?: BuildStepEnv;\n ifCondition?: string;\n }\n ) {\n assert(command !== undefined || fn !== undefined, 'Either command or fn must be defined.');\n assert(!(command !== undefined && fn !== undefined), 'Command and fn cannot be both set.');\n const outputById = makeBuildStepOutputByIdMap(outputs);\n super(id, displayName, false, outputById);\n\n this.id = id;\n this.name = name;\n this.displayName = displayName;\n this.supportedRuntimePlatforms = maybeSupportedRuntimePlatforms;\n this.inputs = inputs;\n this.inputById = makeBuildStepInputByIdMap(inputs);\n this.outputById = outputById;\n this.fn = fn;\n this.command = command;\n this.shell = shell ?? getDefaultShell();\n this.ifCondition = ifCondition;\n this.status = BuildStepStatus.NEW;\n\n this.internalId = uuidv4();\n\n const logger = ctx.baseLogger.child({\n buildStepInternalId: this.internalId,\n buildStepId: this.id,\n buildStepDisplayName: this.displayName,\n });\n this.ctx = ctx.stepCtx({ logger, relativeWorkingDirectory: maybeWorkingDirectory });\n this.stepEnvOverrides = env ?? {};\n\n this.outputsDir = getTemporaryOutputsDirPath(ctx, this.id);\n this.envsDir = getTemporaryEnvsDirPath(ctx, this.id);\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 await fs.mkdir(this.outputsDir, { recursive: true });\n this.ctx.logger.debug(`Created temporary directory for step outputs: ${this.outputsDir}`);\n\n await fs.mkdir(this.envsDir, { recursive: true });\n this.ctx.logger.debug(\n `Created temporary directory for step environment variables: ${this.envsDir}`\n );\n\n if (this.command !== undefined) {\n await this.executeCommandAsync();\n } else {\n await this.executeFnAsync();\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 try {\n await this.collectAndValidateOutputsAsync(this.outputsDir);\n await this.collectAndUpdateEnvsAsync(this.envsDir);\n this.ctx.logger.debug('Finished collecting output parameters');\n } catch (error) {\n // If the step succeeded, we expect the outputs to be collected successfully.\n if (this.status === BuildStepStatus.SUCCESS) {\n throw error;\n }\n\n this.ctx.logger.debug({ err: error }, 'Failed to collect output parameters');\n }\n\n await cleanUpStepTemporaryDirectoriesAsync(this.ctx.global, this.id);\n }\n }\n\n public canBeRunOnRuntimePlatform(): boolean {\n return (\n !this.supportedRuntimePlatforms ||\n this.supportedRuntimePlatforms.includes(this.ctx.global.runtimePlatform)\n );\n }\n\n public shouldExecuteStep(): boolean {\n const hasAnyPreviousStepFailed = this.ctx.global.hasAnyPreviousStepFailed;\n\n if (!this.ifCondition) {\n return !hasAnyPreviousStepFailed;\n }\n\n let ifCondition = this.ifCondition;\n\n if (ifCondition.startsWith('${{') && ifCondition.endsWith('}}')) {\n ifCondition = ifCondition.slice(3, -2);\n } else if (ifCondition.startsWith('${') && ifCondition.endsWith('}')) {\n ifCondition = ifCondition.slice(2, -1);\n }\n\n return Boolean(\n jsepEval(ifCondition, {\n inputs:\n this.inputs?.reduce(\n (acc, input) => {\n acc[input.id] = input.getValue({\n interpolationContext: this.getInterpolationContext(),\n });\n return acc;\n },\n {} as Record<string, unknown>\n ) ?? {},\n eas: {\n runtimePlatform: this.ctx.global.runtimePlatform,\n ...this.ctx.global.staticContext,\n env: this.getScriptEnv(),\n },\n ...this.getInterpolationContext(),\n })\n );\n }\n\n public skip(): void {\n this.status = BuildStepStatus.SKIPPED;\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.START_STEP },\n 'Executing build step \"${this.displayName}\"'\n );\n this.ctx.logger.info(`Skipped build step \"${this.displayName}\"`);\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.SKIPPED },\n `Skipped build step \"${this.displayName}\"`\n );\n }\n\n private getInterpolationContext(): JobInterpolationContext {\n return {\n ...this.ctx.global.getInterpolationContext(),\n env: this.getScriptEnv(),\n };\n }\n\n private async executeCommandAsync(): Promise<void> {\n assert(this.command, 'Command must be defined.');\n\n const interpolatedCommand = interpolateJobContext({\n target: this.command,\n context: this.getInterpolationContext(),\n });\n\n const command = this.interpolateInputsOutputsAndGlobalContextInTemplate(\n `${interpolatedCommand}`,\n this.inputs\n );\n this.ctx.logger.debug(`Interpolated inputs in the command template`);\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\n try {\n const workingDirectoryStat = await fs.stat(this.ctx.workingDirectory);\n if (!workingDirectoryStat.isDirectory()) {\n this.ctx.logger.error(\n `Working directory \"${this.ctx.workingDirectory}\" exists, but is not a directory`\n );\n }\n } catch (err: any) {\n if (err?.code === 'ENOENT') {\n this.ctx.logger.error(\n { err },\n `Working directory \"${this.ctx.workingDirectory}\" does not exist`\n );\n } else {\n this.ctx.logger.error(\n { err },\n `Cannot access working directory \"${this.ctx.workingDirectory}\"`\n );\n }\n }\n\n await spawnAsync(shellCommand, args ?? [], {\n cwd: this.ctx.workingDirectory,\n logger: this.ctx.logger,\n env: this.getScriptEnv(),\n // stdin is /dev/null, std{out,err} are piped into logger.\n stdio: ['ignore', 'pipe', 'pipe'],\n });\n this.ctx.logger.debug(`Script completed successfully`);\n }\n\n private async executeFnAsync(): Promise<void> {\n assert(this.fn, 'Function (fn) must be defined');\n\n await this.fn(this.ctx, {\n inputs: Object.fromEntries(\n Object.entries(this.inputById).map(([key, input]) => [\n key,\n { value: input.getValue({ interpolationContext: this.getInterpolationContext() }) },\n ])\n ),\n outputs: this.outputById,\n env: this.getScriptEnv(),\n });\n\n this.ctx.logger.debug(`Script completed successfully`);\n }\n\n private interpolateInputsOutputsAndGlobalContextInTemplate(\n template: string,\n inputs?: BuildStepInput[]\n ): string {\n if (!inputs) {\n return interpolateWithOutputs(\n this.ctx.global.interpolate(template),\n (path) => this.ctx.global.getStepOutputValue(path) ?? ''\n );\n }\n const vars = inputs.reduce(\n (acc, input) => {\n const value = input.getValue({ interpolationContext: this.getInterpolationContext() });\n acc[input.id] = typeof value === 'object' ? JSON.stringify(value) : value?.toString() ?? '';\n return acc;\n },\n {} as Record<string, string>\n );\n return interpolateWithOutputs(\n interpolateWithInputs(this.ctx.global.interpolate(template), vars),\n (path) => this.ctx.global.getStepOutputValue(path) ?? ''\n );\n }\n\n private async collectAndValidateOutputsAsync(outputsDir: string): Promise<void> {\n const files = await fs.readdir(outputsDir);\n\n for (const outputId of files) {\n if (!(outputId in this.outputById)) {\n const newOutput = new BuildStepOutput(this.ctx.global, {\n id: outputId,\n stepDisplayName: this.displayName,\n required: false,\n });\n this.outputById[outputId] = newOutput;\n }\n\n const file = path.join(outputsDir, outputId);\n const rawContents = await fs.readFile(file, 'utf-8');\n const decodedContents = Buffer.from(rawContents, 'base64').toString('utf-8');\n this.outputById[outputId].set(decodedContents);\n }\n\n const nonSetRequiredOutputIds: string[] = [];\n for (const output of Object.values(this.outputById)) {\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 const decodedContents = Buffer.from(rawContents, 'base64').toString('utf-8');\n return [basename, decodedContents];\n })\n );\n this.ctx.global.updateEnv({\n ...this.ctx.global.env,\n ...Object.fromEntries(entries),\n });\n }\n\n private getScriptEnv(): Record<string, string> {\n const effectiveEnv = { ...this.ctx.global.env, ...this.stepEnvOverrides };\n const currentPath = effectiveEnv.PATH ?? process.env.PATH;\n const newPath = currentPath ? `${BIN_PATH}:${currentPath}` : BIN_PATH;\n return {\n ...effectiveEnv,\n __EXPO_STEPS_OUTPUTS_DIR: this.outputsDir,\n __EXPO_STEPS_ENVS_DIR: this.envsDir,\n __EXPO_STEPS_WORKING_DIRECTORY: this.ctx.workingDirectory,\n PATH: newPath,\n };\n }\n}\n"]}
1
+ {"version":3,"file":"BuildStep.js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,CAAC,MAAM,CAAC,GAAG;YACtB,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC;SAC/B,CAAC,CAAC;IACL,CAAC;IAEO,YAAY;;QAClB,MAAM,YAAY,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC1E,MAAM,WAAW,GAAG,MAAA,YAAY,CAAC,IAAI,mCAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;QAC1D,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,WAAW,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;QACtE,OAAO;YACL,GAAG,YAAY;YACf,wBAAwB,EAAE,IAAI,CAAC,UAAU;YACzC,qBAAqB,EAAE,IAAI,CAAC,OAAO;YACnC,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';\nimport { Buffer } from 'buffer';\n\nimport { v4 as uuidv4 } from 'uuid';\nimport { JobInterpolationContext } from '@expo/eas-build-job';\n\nimport { BuildStepContext, BuildStepGlobalContext } from './BuildStepContext.js';\nimport { BuildStepInput, BuildStepInputById, makeBuildStepInputByIdMap } from './BuildStepInput.js';\nimport {\n BuildStepOutput,\n BuildStepOutputById,\n SerializedBuildStepOutput,\n makeBuildStepOutputByIdMap,\n} from './BuildStepOutput.js';\nimport { BIN_PATH } from './utils/shell/bin.js';\nimport { getShellCommandAndArgs } from './utils/shell/command.js';\nimport {\n cleanUpStepTemporaryDirectoriesAsync,\n getTemporaryEnvsDirPath,\n getTemporaryOutputsDirPath,\n saveScriptToTemporaryFileAsync,\n} from './BuildTemporaryFiles.js';\nimport { spawnAsync } from './utils/shell/spawn.js';\nimport { interpolateWithInputs, interpolateWithOutputs } from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport { jsepEval } from './utils/jsepEval.js';\nimport { interpolateJobContext } from './interpolation.js';\n\nexport enum BuildStepStatus {\n NEW = 'new',\n IN_PROGRESS = 'in-progress',\n SKIPPED = 'skipped',\n FAIL = 'fail',\n WARNING = 'warning',\n SUCCESS = 'success',\n}\n\nexport enum BuildStepLogMarker {\n START_STEP = 'start-step',\n END_STEP = 'end-step',\n}\n\nexport type BuildStepFunction = (\n ctx: BuildStepContext,\n {\n inputs,\n outputs,\n env,\n }: {\n inputs: { [key: string]: { value: unknown } };\n outputs: BuildStepOutputById;\n env: BuildStepEnv;\n signal?: AbortSignal;\n }\n) => unknown;\n\n// TODO: move to a place common with tests\nconst UUID_REGEX =\n /^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$/;\n\nexport interface SerializedBuildStepOutputAccessor {\n id: string;\n executed: boolean;\n outputById: Record<string, SerializedBuildStepOutput>;\n displayName: string;\n}\n\nexport class BuildStepOutputAccessor {\n constructor(\n public readonly id: string,\n public readonly displayName: string,\n protected readonly executed: boolean,\n protected readonly outputById: BuildStepOutputById\n ) {}\n\n public get outputs(): BuildStepOutput[] {\n return Object.values(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 hasOutputParameter(name: string): boolean {\n return name in this.outputById;\n }\n\n public serialize(): SerializedBuildStepOutputAccessor {\n return {\n id: this.id,\n executed: this.executed,\n outputById: Object.fromEntries(\n Object.entries(this.outputById).map(([key, value]) => [key, value.serialize()])\n ),\n displayName: this.displayName,\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepOutputAccessor\n ): BuildStepOutputAccessor {\n const outputById = Object.fromEntries(\n Object.entries(serialized.outputById).map(([key, value]) => [\n key,\n BuildStepOutput.deserialize(value),\n ])\n );\n return new BuildStepOutputAccessor(\n serialized.id,\n serialized.displayName,\n serialized.executed,\n outputById\n );\n }\n}\n\nexport class BuildStep extends BuildStepOutputAccessor {\n public readonly id: string;\n public readonly name?: string;\n public readonly displayName: string;\n public readonly supportedRuntimePlatforms?: BuildRuntimePlatform[];\n public readonly inputs?: BuildStepInput[];\n public readonly outputById: BuildStepOutputById;\n public readonly command?: string;\n public readonly fn?: BuildStepFunction;\n public readonly shell: string;\n public readonly ctx: BuildStepContext;\n public readonly stepEnvOverrides: BuildStepEnv;\n public readonly ifCondition?: string;\n public readonly timeoutMs?: number;\n public status: BuildStepStatus;\n private readonly outputsDir: string;\n private readonly envsDir: string;\n\n private readonly internalId: string;\n private readonly inputById: BuildStepInputById;\n protected executed = false;\n\n public static getNewId(userDefinedId?: string): string {\n return userDefinedId ?? uuidv4();\n }\n\n public static getDisplayName({\n id,\n name,\n command,\n }: {\n id: string;\n name?: string;\n command?: string;\n }): string {\n if (name) {\n return name;\n }\n if (!id.match(UUID_REGEX)) {\n return id;\n }\n if (command) {\n const splits = command.trim().split('\\n');\n for (const split of splits) {\n const trimmed = split.trim();\n if (trimmed && !trimmed.startsWith('#')) {\n return trimmed;\n }\n }\n }\n return id;\n }\n\n constructor(\n ctx: BuildStepGlobalContext,\n {\n id,\n name,\n displayName,\n inputs,\n outputs,\n command,\n fn,\n workingDirectory: maybeWorkingDirectory,\n shell,\n supportedRuntimePlatforms: maybeSupportedRuntimePlatforms,\n env,\n ifCondition,\n timeoutMs,\n }: {\n id: string;\n name?: string;\n displayName: string;\n inputs?: BuildStepInput[];\n outputs?: BuildStepOutput[];\n command?: string;\n fn?: BuildStepFunction;\n workingDirectory?: string;\n shell?: string;\n supportedRuntimePlatforms?: BuildRuntimePlatform[];\n env?: BuildStepEnv;\n ifCondition?: string;\n timeoutMs?: number;\n }\n ) {\n assert(command !== undefined || fn !== undefined, 'Either command or fn must be defined.');\n assert(!(command !== undefined && fn !== undefined), 'Command and fn cannot be both set.');\n const outputById = makeBuildStepOutputByIdMap(outputs);\n super(id, displayName, false, outputById);\n\n this.id = id;\n this.name = name;\n this.displayName = displayName;\n this.supportedRuntimePlatforms = maybeSupportedRuntimePlatforms;\n this.inputs = inputs;\n this.inputById = makeBuildStepInputByIdMap(inputs);\n this.outputById = outputById;\n this.fn = fn;\n this.command = command;\n this.shell = shell ?? '/bin/bash -eo pipefail';\n this.ifCondition = ifCondition;\n this.timeoutMs = timeoutMs;\n this.status = BuildStepStatus.NEW;\n\n this.internalId = uuidv4();\n\n const logger = ctx.baseLogger.child({\n buildStepInternalId: this.internalId,\n buildStepId: this.id,\n buildStepDisplayName: this.displayName,\n });\n this.ctx = ctx.stepCtx({ logger, relativeWorkingDirectory: maybeWorkingDirectory });\n this.stepEnvOverrides = env ?? {};\n\n this.outputsDir = getTemporaryOutputsDirPath(ctx, this.id);\n this.envsDir = getTemporaryEnvsDirPath(ctx, this.id);\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 await fs.mkdir(this.outputsDir, { recursive: true });\n this.ctx.logger.debug(`Created temporary directory for step outputs: ${this.outputsDir}`);\n\n await fs.mkdir(this.envsDir, { recursive: true });\n this.ctx.logger.debug(\n `Created temporary directory for step environment variables: ${this.envsDir}`\n );\n\n if (this.timeoutMs !== undefined) {\n const abortController = new AbortController();\n\n let timeoutId: NodeJS.Timeout | undefined;\n const timeoutPromise = new Promise<void>((_, reject) => {\n timeoutId = setTimeout(() => {\n // Reject with timeout error FIRST, before killing the process\n // This ensures the timeout error wins the race\n reject(\n new BuildStepRuntimeError(\n `Build step \"${this.displayName}\" timed out after ${this.timeoutMs}ms`\n )\n );\n\n abortController.abort();\n }, this.timeoutMs);\n });\n\n try {\n await Promise.race([\n this.command !== undefined\n ? this.executeCommandAsync({ signal: abortController.signal })\n : this.executeFnAsync({ signal: abortController.signal }),\n timeoutPromise,\n ]);\n } finally {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n }\n } else {\n const executionPromise =\n this.command !== undefined\n ? this.executeCommandAsync({ signal: null })\n : this.executeFnAsync({ signal: null });\n await executionPromise;\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 try {\n await this.collectAndValidateOutputsAsync(this.outputsDir);\n await this.collectAndUpdateEnvsAsync(this.envsDir);\n this.ctx.logger.debug('Finished collecting output parameters');\n } catch (error) {\n // If the step succeeded, we expect the outputs to be collected successfully.\n if (this.status === BuildStepStatus.SUCCESS) {\n throw error;\n }\n\n this.ctx.logger.debug({ err: error }, 'Failed to collect output parameters');\n }\n\n await cleanUpStepTemporaryDirectoriesAsync(this.ctx.global, this.id);\n }\n }\n\n public canBeRunOnRuntimePlatform(): boolean {\n return (\n !this.supportedRuntimePlatforms ||\n this.supportedRuntimePlatforms.includes(this.ctx.global.runtimePlatform)\n );\n }\n\n public shouldExecuteStep(): boolean {\n const hasAnyPreviousStepFailed = this.ctx.global.hasAnyPreviousStepFailed;\n\n if (!this.ifCondition) {\n return !hasAnyPreviousStepFailed;\n }\n\n let ifCondition = this.ifCondition;\n\n if (ifCondition.startsWith('${{') && ifCondition.endsWith('}}')) {\n ifCondition = ifCondition.slice(3, -2);\n } else if (ifCondition.startsWith('${') && ifCondition.endsWith('}')) {\n ifCondition = ifCondition.slice(2, -1);\n }\n\n return Boolean(\n jsepEval(ifCondition, {\n inputs:\n this.inputs?.reduce(\n (acc, input) => {\n acc[input.id] = input.getValue({\n interpolationContext: this.getInterpolationContext(),\n });\n return acc;\n },\n {} as Record<string, unknown>\n ) ?? {},\n eas: {\n runtimePlatform: this.ctx.global.runtimePlatform,\n ...this.ctx.global.staticContext,\n env: this.getScriptEnv(),\n },\n ...this.getInterpolationContext(),\n })\n );\n }\n\n public skip(): void {\n this.status = BuildStepStatus.SKIPPED;\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.START_STEP },\n 'Executing build step \"${this.displayName}\"'\n );\n this.ctx.logger.info(`Skipped build step \"${this.displayName}\"`);\n this.ctx.logger.info(\n { marker: BuildStepLogMarker.END_STEP, result: BuildStepStatus.SKIPPED },\n `Skipped build step \"${this.displayName}\"`\n );\n }\n\n private getInterpolationContext(): JobInterpolationContext {\n return {\n ...this.ctx.global.getInterpolationContext(),\n env: this.getScriptEnv(),\n };\n }\n\n private async executeCommandAsync({ signal }: { signal: AbortSignal | null }): Promise<void> {\n assert(this.command, 'Command must be defined.');\n\n const interpolatedCommand = interpolateJobContext({\n target: this.command,\n context: this.getInterpolationContext(),\n });\n\n const command = this.interpolateInputsOutputsAndGlobalContextInTemplate(\n `${interpolatedCommand}`,\n this.inputs\n );\n this.ctx.logger.debug(`Interpolated inputs in the command template`);\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\n try {\n const workingDirectoryStat = await fs.stat(this.ctx.workingDirectory);\n if (!workingDirectoryStat.isDirectory()) {\n this.ctx.logger.error(\n `Working directory \"${this.ctx.workingDirectory}\" exists, but is not a directory`\n );\n }\n } catch (err: any) {\n if (err?.code === 'ENOENT') {\n this.ctx.logger.error(\n { err },\n `Working directory \"${this.ctx.workingDirectory}\" does not exist`\n );\n } else {\n this.ctx.logger.error(\n { err },\n `Cannot access working directory \"${this.ctx.workingDirectory}\"`\n );\n }\n }\n\n await spawnAsync(shellCommand, args ?? [], {\n cwd: this.ctx.workingDirectory,\n logger: this.ctx.logger,\n env: this.getScriptEnv(),\n // stdin is /dev/null, std{out,err} are piped into logger.\n stdio: ['ignore', 'pipe', 'pipe'],\n signal: signal ?? undefined,\n });\n this.ctx.logger.debug(`Script completed successfully`);\n }\n\n private async executeFnAsync({ signal }: { signal: AbortSignal | null }): Promise<void> {\n assert(this.fn, 'Function (fn) must be defined');\n\n await this.fn(this.ctx, {\n inputs: Object.fromEntries(\n Object.entries(this.inputById).map(([key, input]) => [\n key,\n { value: input.getValue({ interpolationContext: this.getInterpolationContext() }) },\n ])\n ),\n outputs: this.outputById,\n env: this.getScriptEnv(),\n signal: signal ?? undefined,\n });\n\n this.ctx.logger.debug(`Script completed successfully`);\n }\n\n private interpolateInputsOutputsAndGlobalContextInTemplate(\n template: string,\n inputs?: BuildStepInput[]\n ): string {\n if (!inputs) {\n return interpolateWithOutputs(\n this.ctx.global.interpolate(template),\n (path) => this.ctx.global.getStepOutputValue(path) ?? ''\n );\n }\n const vars = inputs.reduce(\n (acc, input) => {\n const value = input.getValue({ interpolationContext: this.getInterpolationContext() });\n acc[input.id] = typeof value === 'object' ? JSON.stringify(value) : value?.toString() ?? '';\n return acc;\n },\n {} as Record<string, string>\n );\n return interpolateWithOutputs(\n interpolateWithInputs(this.ctx.global.interpolate(template), vars),\n (path) => this.ctx.global.getStepOutputValue(path) ?? ''\n );\n }\n\n private async collectAndValidateOutputsAsync(outputsDir: string): Promise<void> {\n const files = await fs.readdir(outputsDir);\n\n for (const outputId of files) {\n if (!(outputId in this.outputById)) {\n const newOutput = new BuildStepOutput(this.ctx.global, {\n id: outputId,\n stepDisplayName: this.displayName,\n required: false,\n });\n this.outputById[outputId] = newOutput;\n }\n\n const file = path.join(outputsDir, outputId);\n const rawContents = await fs.readFile(file, 'utf-8');\n const decodedContents = Buffer.from(rawContents, 'base64').toString('utf-8');\n this.outputById[outputId].set(decodedContents);\n }\n\n const nonSetRequiredOutputIds: string[] = [];\n for (const output of Object.values(this.outputById)) {\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 const decodedContents = Buffer.from(rawContents, 'base64').toString('utf-8');\n return [basename, decodedContents];\n })\n );\n this.ctx.global.updateEnv({\n ...this.ctx.global.env,\n ...Object.fromEntries(entries),\n });\n }\n\n private getScriptEnv(): Record<string, string> {\n const effectiveEnv = { ...this.ctx.global.env, ...this.stepEnvOverrides };\n const currentPath = effectiveEnv.PATH ?? process.env.PATH;\n const newPath = currentPath ? `${BIN_PATH}:${currentPath}` : BIN_PATH;\n return {\n ...effectiveEnv,\n __EXPO_STEPS_OUTPUTS_DIR: this.outputsDir,\n __EXPO_STEPS_ENVS_DIR: this.envsDir,\n __EXPO_STEPS_WORKING_DIRECTORY: this.ctx.workingDirectory,\n PATH: newPath,\n };\n }\n}\n"]}
@@ -1,4 +1,3 @@
1
- export declare function getDefaultShell(platform?: NodeJS.Platform): string;
2
1
  export declare function getShellCommandAndArgs(shell: string, script?: string): {
3
2
  command: string;
4
3
  args?: string[];
@@ -1,18 +1,3 @@
1
- import os from 'os';
2
- // stolen from https://circleci.com/docs/configuration-reference/
3
- const DEFAULT_SHELL = '/bin/bash -eo pipefail';
4
- const SHELL_BY_PLATFORM = {
5
- darwin: '/bin/bash --login -eo pipefail',
6
- };
7
- export function getDefaultShell(platform = os.platform()) {
8
- const platformSpecificShell = SHELL_BY_PLATFORM[platform];
9
- if (platformSpecificShell) {
10
- return platformSpecificShell;
11
- }
12
- else {
13
- return DEFAULT_SHELL;
14
- }
15
- }
16
1
  export function getShellCommandAndArgs(shell, script) {
17
2
  const splits = shell.split(' ');
18
3
  const command = splits[0];
@@ -1 +1 @@
1
- {"version":3,"file":"command.js","sourceRoot":"","sources":["../../../src/utils/shell/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,iEAAiE;AACjE,MAAM,aAAa,GAAG,wBAAwB,CAAC;AAC/C,MAAM,iBAAiB,GAA6C;IAClE,MAAM,EAAE,gCAAgC;CACzC,CAAC;AAEF,MAAM,UAAU,eAAe,CAAC,WAA4B,EAAE,CAAC,QAAQ,EAAE;IACvE,MAAM,qBAAqB,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC1D,IAAI,qBAAqB,EAAE,CAAC;QAC1B,OAAO,qBAAqB,CAAC;IAC/B,CAAC;SAAM,CAAC;QACN,OAAO,aAAa,CAAC;IACvB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,KAAa,EACb,MAAe;IAEf,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChC,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC1B,MAAM,IAAI,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,IAAI,MAAM,EAAE,CAAC;QACX,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC;IACD,OAAO;QACL,OAAO;QACP,IAAI;KACL,CAAC;AACJ,CAAC","sourcesContent":["import os from 'os';\n\n// stolen from https://circleci.com/docs/configuration-reference/\nconst DEFAULT_SHELL = '/bin/bash -eo pipefail';\nconst SHELL_BY_PLATFORM: Partial<Record<NodeJS.Platform, string>> = {\n darwin: '/bin/bash --login -eo pipefail',\n};\n\nexport function getDefaultShell(platform: NodeJS.Platform = os.platform()): string {\n const platformSpecificShell = SHELL_BY_PLATFORM[platform];\n if (platformSpecificShell) {\n return platformSpecificShell;\n } else {\n return DEFAULT_SHELL;\n }\n}\n\nexport function getShellCommandAndArgs(\n shell: string,\n script?: string\n): { command: string; args?: string[] } {\n const splits = shell.split(' ');\n const command = splits[0];\n const args = [...splits.slice(1)];\n if (script) {\n args.push(script);\n }\n return {\n command,\n args,\n };\n}\n"]}
1
+ {"version":3,"file":"command.js","sourceRoot":"","sources":["../../../src/utils/shell/command.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,sBAAsB,CACpC,KAAa,EACb,MAAe;IAEf,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChC,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC1B,MAAM,IAAI,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,IAAI,MAAM,EAAE,CAAC;QACX,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC;IACD,OAAO;QACL,OAAO;QACP,IAAI;KACL,CAAC;AACJ,CAAC","sourcesContent":["export function getShellCommandAndArgs(\n shell: string,\n script?: string\n): { command: string; args?: string[] } {\n const splits = shell.split(' ');\n const command = splits[0];\n const args = [...splits.slice(1)];\n if (script) {\n args.push(script);\n }\n return {\n command,\n args,\n };\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "@expo/steps",
3
+ "repository": {
4
+ "type": "git",
5
+ "url": "https://github.com/expo/eas-build.git",
6
+ "directory": "packages/steps"
7
+ },
3
8
  "type": "module",
4
- "version": "1.0.252",
9
+ "version": "1.0.260",
5
10
  "main": "./dist_commonjs/index.cjs",
6
11
  "types": "./dist_esm/index.d.ts",
7
12
  "exports": {
@@ -48,8 +53,8 @@
48
53
  "node": ">=18"
49
54
  },
50
55
  "dependencies": {
51
- "@expo/eas-build-job": "1.0.252",
52
- "@expo/logger": "1.0.221",
56
+ "@expo/eas-build-job": "1.0.260",
57
+ "@expo/logger": "1.0.260",
53
58
  "@expo/spawn-async": "^1.7.2",
54
59
  "arg": "^5.0.2",
55
60
  "fs-extra": "^11.2.0",
@@ -65,5 +70,5 @@
65
70
  "node": "20.14.0",
66
71
  "yarn": "1.22.21"
67
72
  },
68
- "gitHead": "f729d1ec839100ebfdb45a05b63bf58b6800247b"
73
+ "gitHead": "86661f158977836b1cfd9643a690fc816a4f44e4"
69
74
  }