@expo/steps 1.0.246 → 1.0.252
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildStepContext.js","sourceRoot":"","sources":["../src/BuildStepContext.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAExB,0DAA2B;AAG3B,+BAAoC;AAEpC,uDAAiD;AACjD,iDAIwB;AACxB,qDAI6B;AAC7B,2CAAoD;AAoCpD,MAAa,sBAAsB;IAQjC,YACmB,QAAsC,EACvC,WAAoB;QADnB,aAAQ,GAAR,QAAQ,CAA8B;QACvC,gBAAW,GAAX,WAAW,CAAS;QAN9B,gBAAW,GAAG,KAAK,CAAC;QACpB,8BAAyB,GAAG,KAAK,CAAC;QAClC,aAAQ,GAA4C,EAAE,CAAC;QAM7D,IAAI,CAAC,2BAA2B,GAAG,cAAI,CAAC,IAAI,CAAC,YAAE,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,IAAA,SAAM,GAAE,CAAC,CAAC;QACjF,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC,eAAe,CAAC;QAChD,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC;QAClC,IAAI,CAAC,yBAAyB,GAAG,KAAK,CAAC;IACzC,CAAC;IAED,IAAW,sBAAsB;QAC/B,OAAO,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC;IAC9C,CAAC;IAED,IAAW,sBAAsB;QAC/B,OAAO,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC;IAC9C,CAAC;IAED,IAAW,uBAAuB;QAChC,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CAAC,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC;IAChG,CAAC;IAED,IAAW,kBAAkB;QAC3B,OAAO,IAAI,CAAC,QAAQ,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AC,EAAE,CAAC;YACnD,OAAO,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,sBAAsB,EAAE,IAAI,CAAC,wBAAwB,CAAC,CAAC;QACnF,CAAC;QAED,OAAO,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,uBAAuB,EAAE,IAAI,CAAC,wBAAwB,CAAC,CAAC;IACpF,CAAC;IAEM,SAAS;QACd,OAAO;YACL,wBAAwB,EAAE,IAAI,CAAC,wBAAwB;YACvD,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE;SAC7B,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,WAAW,CACvB,UAAsC,EACtC,MAAc;QAEd,MAAM,kBAAkB,GAAG,sBAAsB,CAAC,WAAW,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACzF,OAAO,IAAI,gBAAgB,CAAC,kBAAkB,EAAE;YAC9C,MAAM;YACN,wBAAwB,EAAE,UAAU,CAAC,wBAAwB;SAC9D,CAAC,CAAC;IACL,CAAC;CACF;AAnDD,4CAmDC","sourcesContent":["import os from 'os';\nimport path from 'path';\n\nimport fg from 'fast-glob';\nimport { Env, JobInterpolationContext, StaticJobInterpolationContext } from '@expo/eas-build-job';\nimport { bunyan } from '@expo/logger';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { hashFiles } from './utils/hashFiles.js';\nimport {\n BuildStep,\n BuildStepOutputAccessor,\n SerializedBuildStepOutputAccessor,\n} from './BuildStep.js';\nimport {\n getObjectValueForInterpolation,\n interpolateWithGlobalContext,\n parseOutputPath,\n} from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\n\ninterface SerializedExternalBuildContextProvider {\n projectSourceDirectory: string;\n projectTargetDirectory: string;\n defaultWorkingDirectory: string;\n buildLogsDirectory: string;\n runtimePlatform: BuildRuntimePlatform;\n // We omit steps, because they should be calculated live based on global context.\n staticContext: Omit<StaticJobInterpolationContext, 'steps'>;\n env: BuildStepEnv;\n}\n\nexport interface ExternalBuildContextProvider {\n readonly projectSourceDirectory: string;\n readonly projectTargetDirectory: string;\n readonly defaultWorkingDirectory: string;\n readonly buildLogsDirectory: string;\n readonly runtimePlatform: BuildRuntimePlatform;\n readonly logger: bunyan;\n\n readonly staticContext: () => Omit<StaticJobInterpolationContext, 'steps'>;\n\n readonly env: BuildStepEnv;\n updateEnv(env: BuildStepEnv): void;\n}\n\nexport interface SerializedBuildStepGlobalContext {\n stepsInternalBuildDirectory: string;\n stepById: Record<string, SerializedBuildStepOutputAccessor>;\n provider: SerializedExternalBuildContextProvider;\n skipCleanup: boolean;\n}\n\nexport class BuildStepGlobalContext {\n public stepsInternalBuildDirectory: string;\n public readonly runtimePlatform: BuildRuntimePlatform;\n public readonly baseLogger: bunyan;\n private didCheckOut = false;\n private _hasAnyPreviousStepFailed = false;\n private stepById: Record<string, BuildStepOutputAccessor> = {};\n\n constructor(\n private readonly provider: ExternalBuildContextProvider,\n public readonly skipCleanup: boolean\n ) {\n this.stepsInternalBuildDirectory = path.join(os.tmpdir(), 'eas-build', uuidv4());\n this.runtimePlatform = provider.runtimePlatform;\n this.baseLogger = provider.logger;\n this._hasAnyPreviousStepFailed = false;\n }\n\n public get projectSourceDirectory(): string {\n return this.provider.projectSourceDirectory;\n }\n\n public get projectTargetDirectory(): string {\n return this.provider.projectTargetDirectory;\n }\n\n public get defaultWorkingDirectory(): string {\n return this.didCheckOut ? this.provider.defaultWorkingDirectory : this.projectTargetDirectory;\n }\n\n public get buildLogsDirectory(): string {\n return this.provider.buildLogsDirectory;\n }\n\n public get env(): BuildStepEnv {\n return this.provider.env;\n }\n\n public get staticContext(): StaticJobInterpolationContext {\n return {\n ...this.provider.staticContext(),\n steps: Object.fromEntries(\n Object.values(this.stepById).map((step) => [\n step.id,\n {\n outputs: Object.fromEntries(\n step.outputs.map((output) => {\n return [output.id, output.rawValue];\n })\n ),\n },\n ])\n ),\n };\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 getInterpolationContext(): JobInterpolationContext {\n const hasAnyPreviousStepFailed = this.hasAnyPreviousStepFailed;\n\n return {\n ...this.staticContext,\n always: () => true,\n never: () => false,\n success: () => !hasAnyPreviousStepFailed,\n failure: () => hasAnyPreviousStepFailed,\n env: this.env as Env,\n fromJSON: (json: string) => JSON.parse(json),\n toJSON: (value: unknown) => JSON.stringify(value),\n contains: (value, substring) => value.includes(substring),\n startsWith: (value, prefix) => value.startsWith(prefix),\n endsWith: (value, suffix) => value.endsWith(suffix),\n hashFiles: (...patterns: string[]) => this.hashFiles(...patterns),\n replaceAll: (input: string, stringToReplace: string, replacementString: string) => {\n while (input.includes(stringToReplace)) {\n input = input.replace(stringToReplace, replacementString);\n }\n return input;\n },\n };\n }\n\n public interpolate<InterpolableType extends string | object>(\n value: InterpolableType\n ): InterpolableType {\n return interpolateWithGlobalContext(value, (path) => {\n return (\n getObjectValueForInterpolation(path, {\n eas: {\n runtimePlatform: this.runtimePlatform,\n ...this.staticContext,\n env: this.env,\n },\n })?.toString() ?? ''\n );\n });\n }\n\n public stepCtx(options: { logger: bunyan; relativeWorkingDirectory?: string }): BuildStepContext {\n return new BuildStepContext(this, options);\n }\n\n public markAsCheckedOut(logger: bunyan): void {\n this.didCheckOut = true;\n logger.info(\n `Changing default working directory to ${this.defaultWorkingDirectory} (was ${this.projectTargetDirectory})`\n );\n }\n\n public get hasAnyPreviousStepFailed(): boolean {\n return this._hasAnyPreviousStepFailed;\n }\n\n public markAsFailed(): void {\n this._hasAnyPreviousStepFailed = true;\n }\n\n public wasCheckedOut(): boolean {\n return this.didCheckOut;\n }\n\n public hashFiles(...patterns: string[]): string {\n const cwd = this.defaultWorkingDirectory;\n const workspacePath = path.resolve(cwd);\n\n // Use glob to find matching files across all patterns\n const filePaths = fg.sync(patterns, {\n cwd,\n absolute: true,\n onlyFiles: true,\n });\n\n if (filePaths.length === 0) {\n return '';\n }\n\n const validFilePaths = filePaths.filter((file) =>\n file.startsWith(`${workspacePath}${path.sep}`)\n );\n\n if (validFilePaths.length === 0) {\n return '';\n }\n\n return hashFiles(validFilePaths);\n }\n\n public serialize(): SerializedBuildStepGlobalContext {\n return {\n stepsInternalBuildDirectory: this.stepsInternalBuildDirectory,\n stepById: Object.fromEntries(\n Object.entries(this.stepById).map(([id, step]) => [id, step.serialize()])\n ),\n provider: {\n projectSourceDirectory: this.provider.projectSourceDirectory,\n projectTargetDirectory: this.provider.projectTargetDirectory,\n defaultWorkingDirectory: this.provider.defaultWorkingDirectory,\n buildLogsDirectory: this.provider.buildLogsDirectory,\n runtimePlatform: this.provider.runtimePlatform,\n staticContext: this.provider.staticContext(),\n env: this.provider.env,\n },\n skipCleanup: this.skipCleanup,\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepGlobalContext,\n logger: bunyan\n ): BuildStepGlobalContext {\n const deserializedProvider: ExternalBuildContextProvider = {\n projectSourceDirectory: serialized.provider.projectSourceDirectory,\n projectTargetDirectory: serialized.provider.projectTargetDirectory,\n defaultWorkingDirectory: serialized.provider.defaultWorkingDirectory,\n buildLogsDirectory: serialized.provider.buildLogsDirectory,\n runtimePlatform: serialized.provider.runtimePlatform,\n logger,\n staticContext: () => serialized.provider.staticContext,\n env: serialized.provider.env,\n updateEnv: () => {},\n };\n const ctx = new BuildStepGlobalContext(deserializedProvider, serialized.skipCleanup);\n for (const [id, stepOutputAccessor] of Object.entries(serialized.stepById)) {\n ctx.stepById[id] = BuildStepOutputAccessor.deserialize(stepOutputAccessor);\n }\n ctx.stepsInternalBuildDirectory = serialized.stepsInternalBuildDirectory;\n\n return ctx;\n }\n}\n\nexport interface SerializedBuildStepContext {\n relativeWorkingDirectory?: string;\n global: SerializedBuildStepGlobalContext;\n}\n\nexport class BuildStepContext {\n public readonly logger: bunyan;\n public readonly relativeWorkingDirectory?: string;\n\n constructor(\n private readonly ctx: BuildStepGlobalContext,\n {\n logger,\n relativeWorkingDirectory,\n }: {\n logger: bunyan;\n relativeWorkingDirectory?: string;\n }\n ) {\n this.logger = logger ?? ctx.baseLogger;\n this.relativeWorkingDirectory = relativeWorkingDirectory;\n }\n\n public get global(): BuildStepGlobalContext {\n return this.ctx;\n }\n\n public get workingDirectory(): string {\n if (!this.relativeWorkingDirectory) {\n return this.ctx.defaultWorkingDirectory;\n }\n\n if (path.isAbsolute(this.relativeWorkingDirectory)) {\n return path.join(this.ctx.projectTargetDirectory, this.relativeWorkingDirectory);\n }\n\n return path.join(this.ctx.defaultWorkingDirectory, this.relativeWorkingDirectory);\n }\n\n public serialize(): SerializedBuildStepContext {\n return {\n relativeWorkingDirectory: this.relativeWorkingDirectory,\n global: this.ctx.serialize(),\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepContext,\n logger: bunyan\n ): BuildStepContext {\n const deserializedGlobal = BuildStepGlobalContext.deserialize(serialized.global, logger);\n return new BuildStepContext(deserializedGlobal, {\n logger,\n relativeWorkingDirectory: serialized.relativeWorkingDirectory,\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BuildStepContext.js","sourceRoot":"","sources":["../src/BuildStepContext.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAExB,0DAA2B;AAG3B,+BAAoC;AAEpC,uDAAiD;AACjD,iDAIwB;AACxB,qDAI6B;AAC7B,2CAAoD;AAoCpD,MAAa,sBAAsB;IAQjC,YACmB,QAAsC,EACvC,WAAoB;QADnB,aAAQ,GAAR,QAAQ,CAA8B;QACvC,gBAAW,GAAX,WA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EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE;SAC7B,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,WAAW,CACvB,UAAsC,EACtC,MAAc;QAEd,MAAM,kBAAkB,GAAG,sBAAsB,CAAC,WAAW,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACzF,OAAO,IAAI,gBAAgB,CAAC,kBAAkB,EAAE;YAC9C,MAAM;YACN,wBAAwB,EAAE,UAAU,CAAC,wBAAwB;SAC9D,CAAC,CAAC;IACL,CAAC;CACF;AAnDD,4CAmDC","sourcesContent":["import os from 'os';\nimport path from 'path';\n\nimport fg from 'fast-glob';\nimport { Env, JobInterpolationContext, StaticJobInterpolationContext } from '@expo/eas-build-job';\nimport { bunyan } from '@expo/logger';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { hashFiles } from './utils/hashFiles.js';\nimport {\n BuildStep,\n BuildStepOutputAccessor,\n SerializedBuildStepOutputAccessor,\n} from './BuildStep.js';\nimport {\n getObjectValueForInterpolation,\n interpolateWithGlobalContext,\n parseOutputPath,\n} from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\n\ninterface SerializedExternalBuildContextProvider {\n projectSourceDirectory: string;\n projectTargetDirectory: string;\n defaultWorkingDirectory: string;\n buildLogsDirectory: string;\n runtimePlatform: BuildRuntimePlatform;\n // We omit steps, because they should be calculated live based on global context.\n staticContext: Omit<StaticJobInterpolationContext, 'steps'>;\n env: BuildStepEnv;\n}\n\nexport interface ExternalBuildContextProvider {\n readonly projectSourceDirectory: string;\n readonly projectTargetDirectory: string;\n readonly defaultWorkingDirectory: string;\n readonly buildLogsDirectory: string;\n readonly runtimePlatform: BuildRuntimePlatform;\n readonly logger: bunyan;\n\n readonly staticContext: () => Omit<StaticJobInterpolationContext, 'steps'>;\n\n readonly env: BuildStepEnv;\n updateEnv(env: BuildStepEnv): void;\n}\n\nexport interface SerializedBuildStepGlobalContext {\n stepsInternalBuildDirectory: string;\n stepById: Record<string, SerializedBuildStepOutputAccessor>;\n provider: SerializedExternalBuildContextProvider;\n skipCleanup: boolean;\n}\n\nexport class BuildStepGlobalContext {\n public stepsInternalBuildDirectory: string;\n public readonly runtimePlatform: BuildRuntimePlatform;\n public readonly baseLogger: bunyan;\n private didCheckOut = false;\n private _hasAnyPreviousStepFailed = false;\n private stepById: Record<string, BuildStepOutputAccessor> = {};\n\n constructor(\n private readonly provider: ExternalBuildContextProvider,\n public readonly skipCleanup: boolean\n ) {\n this.stepsInternalBuildDirectory = path.join(os.tmpdir(), 'eas-build', uuidv4());\n this.runtimePlatform = provider.runtimePlatform;\n this.baseLogger = provider.logger;\n this._hasAnyPreviousStepFailed = false;\n }\n\n public get projectSourceDirectory(): string {\n return this.provider.projectSourceDirectory;\n }\n\n public get projectTargetDirectory(): string {\n return this.provider.projectTargetDirectory;\n }\n\n public get defaultWorkingDirectory(): string {\n return this.didCheckOut ? this.provider.defaultWorkingDirectory : this.projectTargetDirectory;\n }\n\n public get buildLogsDirectory(): string {\n return this.provider.buildLogsDirectory;\n }\n\n public get env(): BuildStepEnv {\n return this.provider.env;\n }\n\n public get staticContext(): StaticJobInterpolationContext {\n return {\n ...this.provider.staticContext(),\n steps: Object.fromEntries(\n Object.values(this.stepById).map((step) => [\n step.id,\n {\n outputs: Object.fromEntries(\n step.outputs.map((output) => {\n return [output.id, output.rawValue];\n })\n ),\n },\n ])\n ),\n };\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 getInterpolationContext(): JobInterpolationContext {\n const hasAnyPreviousStepFailed = this.hasAnyPreviousStepFailed;\n\n return {\n ...this.staticContext,\n always: () => true,\n never: () => false,\n success: () => !hasAnyPreviousStepFailed,\n failure: () => hasAnyPreviousStepFailed,\n env: this.env as Env,\n fromJSON: (json: string) => JSON.parse(json),\n toJSON: (value: unknown) => JSON.stringify(value),\n contains: (value, substring) => value.includes(substring),\n startsWith: (value, prefix) => value.startsWith(prefix),\n endsWith: (value, suffix) => value.endsWith(suffix),\n hashFiles: (...patterns: string[]) => this.hashFiles(...patterns),\n replaceAll: (input: string, stringToReplace: string, replacementString: string) => {\n while (input.includes(stringToReplace)) {\n input = input.replace(stringToReplace, replacementString);\n }\n return input;\n },\n substring: (input: string, start: number, end?: number) => input.substring(start, end),\n };\n }\n\n public interpolate<InterpolableType extends string | object>(\n value: InterpolableType\n ): InterpolableType {\n return interpolateWithGlobalContext(value, (path) => {\n return (\n getObjectValueForInterpolation(path, {\n eas: {\n runtimePlatform: this.runtimePlatform,\n ...this.staticContext,\n env: this.env,\n },\n })?.toString() ?? ''\n );\n });\n }\n\n public stepCtx(options: { logger: bunyan; relativeWorkingDirectory?: string }): BuildStepContext {\n return new BuildStepContext(this, options);\n }\n\n public markAsCheckedOut(logger: bunyan): void {\n this.didCheckOut = true;\n logger.info(\n `Changing default working directory to ${this.defaultWorkingDirectory} (was ${this.projectTargetDirectory})`\n );\n }\n\n public get hasAnyPreviousStepFailed(): boolean {\n return this._hasAnyPreviousStepFailed;\n }\n\n public markAsFailed(): void {\n this._hasAnyPreviousStepFailed = true;\n }\n\n public wasCheckedOut(): boolean {\n return this.didCheckOut;\n }\n\n public hashFiles(...patterns: string[]): string {\n const cwd = this.defaultWorkingDirectory;\n const workspacePath = path.resolve(cwd);\n\n // Use glob to find matching files across all patterns\n const filePaths = fg.sync(patterns, {\n cwd,\n absolute: true,\n onlyFiles: true,\n });\n\n if (filePaths.length === 0) {\n return '';\n }\n\n const validFilePaths = filePaths.filter((file) =>\n file.startsWith(`${workspacePath}${path.sep}`)\n );\n\n if (validFilePaths.length === 0) {\n return '';\n }\n\n return hashFiles(validFilePaths);\n }\n\n public serialize(): SerializedBuildStepGlobalContext {\n return {\n stepsInternalBuildDirectory: this.stepsInternalBuildDirectory,\n stepById: Object.fromEntries(\n Object.entries(this.stepById).map(([id, step]) => [id, step.serialize()])\n ),\n provider: {\n projectSourceDirectory: this.provider.projectSourceDirectory,\n projectTargetDirectory: this.provider.projectTargetDirectory,\n defaultWorkingDirectory: this.provider.defaultWorkingDirectory,\n buildLogsDirectory: this.provider.buildLogsDirectory,\n runtimePlatform: this.provider.runtimePlatform,\n staticContext: this.provider.staticContext(),\n env: this.provider.env,\n },\n skipCleanup: this.skipCleanup,\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepGlobalContext,\n logger: bunyan\n ): BuildStepGlobalContext {\n const deserializedProvider: ExternalBuildContextProvider = {\n projectSourceDirectory: serialized.provider.projectSourceDirectory,\n projectTargetDirectory: serialized.provider.projectTargetDirectory,\n defaultWorkingDirectory: serialized.provider.defaultWorkingDirectory,\n buildLogsDirectory: serialized.provider.buildLogsDirectory,\n runtimePlatform: serialized.provider.runtimePlatform,\n logger,\n staticContext: () => serialized.provider.staticContext,\n env: serialized.provider.env,\n updateEnv: () => {},\n };\n const ctx = new BuildStepGlobalContext(deserializedProvider, serialized.skipCleanup);\n for (const [id, stepOutputAccessor] of Object.entries(serialized.stepById)) {\n ctx.stepById[id] = BuildStepOutputAccessor.deserialize(stepOutputAccessor);\n }\n ctx.stepsInternalBuildDirectory = serialized.stepsInternalBuildDirectory;\n\n return ctx;\n }\n}\n\nexport interface SerializedBuildStepContext {\n relativeWorkingDirectory?: string;\n global: SerializedBuildStepGlobalContext;\n}\n\nexport class BuildStepContext {\n public readonly logger: bunyan;\n public readonly relativeWorkingDirectory?: string;\n\n constructor(\n private readonly ctx: BuildStepGlobalContext,\n {\n logger,\n relativeWorkingDirectory,\n }: {\n logger: bunyan;\n relativeWorkingDirectory?: string;\n }\n ) {\n this.logger = logger ?? ctx.baseLogger;\n this.relativeWorkingDirectory = relativeWorkingDirectory;\n }\n\n public get global(): BuildStepGlobalContext {\n return this.ctx;\n }\n\n public get workingDirectory(): string {\n if (!this.relativeWorkingDirectory) {\n return this.ctx.defaultWorkingDirectory;\n }\n\n if (path.isAbsolute(this.relativeWorkingDirectory)) {\n return path.join(this.ctx.projectTargetDirectory, this.relativeWorkingDirectory);\n }\n\n return path.join(this.ctx.defaultWorkingDirectory, this.relativeWorkingDirectory);\n }\n\n public serialize(): SerializedBuildStepContext {\n return {\n relativeWorkingDirectory: this.relativeWorkingDirectory,\n global: this.ctx.serialize(),\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepContext,\n logger: bunyan\n ): BuildStepContext {\n const deserializedGlobal = BuildStepGlobalContext.deserialize(serialized.global, logger);\n return new BuildStepContext(deserializedGlobal, {\n logger,\n relativeWorkingDirectory: serialized.relativeWorkingDirectory,\n });\n }\n}\n"]}
|
|
@@ -1 +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;AAExB,OAAO,EAAE,MAAM,WAAW,CAAC;AAG3B,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAEL,uBAAuB,GAExB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,EAC5B,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAoCpD,MAAM,OAAO,sBAAsB;IAQjC,YACmB,QAAsC,EACvC,WAAoB;QADnB,aAAQ,GAAR,QAAQ,CAA8B;QACvC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AsB,CAAC,WAAW,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACzF,OAAO,IAAI,gBAAgB,CAAC,kBAAkB,EAAE;YAC9C,MAAM;YACN,wBAAwB,EAAE,UAAU,CAAC,wBAAwB;SAC9D,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import os from 'os';\nimport path from 'path';\n\nimport fg from 'fast-glob';\nimport { Env, JobInterpolationContext, StaticJobInterpolationContext } from '@expo/eas-build-job';\nimport { bunyan } from '@expo/logger';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { hashFiles } from './utils/hashFiles.js';\nimport {\n BuildStep,\n BuildStepOutputAccessor,\n SerializedBuildStepOutputAccessor,\n} from './BuildStep.js';\nimport {\n getObjectValueForInterpolation,\n interpolateWithGlobalContext,\n parseOutputPath,\n} from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\n\ninterface SerializedExternalBuildContextProvider {\n projectSourceDirectory: string;\n projectTargetDirectory: string;\n defaultWorkingDirectory: string;\n buildLogsDirectory: string;\n runtimePlatform: BuildRuntimePlatform;\n // We omit steps, because they should be calculated live based on global context.\n staticContext: Omit<StaticJobInterpolationContext, 'steps'>;\n env: BuildStepEnv;\n}\n\nexport interface ExternalBuildContextProvider {\n readonly projectSourceDirectory: string;\n readonly projectTargetDirectory: string;\n readonly defaultWorkingDirectory: string;\n readonly buildLogsDirectory: string;\n readonly runtimePlatform: BuildRuntimePlatform;\n readonly logger: bunyan;\n\n readonly staticContext: () => Omit<StaticJobInterpolationContext, 'steps'>;\n\n readonly env: BuildStepEnv;\n updateEnv(env: BuildStepEnv): void;\n}\n\nexport interface SerializedBuildStepGlobalContext {\n stepsInternalBuildDirectory: string;\n stepById: Record<string, SerializedBuildStepOutputAccessor>;\n provider: SerializedExternalBuildContextProvider;\n skipCleanup: boolean;\n}\n\nexport class BuildStepGlobalContext {\n public stepsInternalBuildDirectory: string;\n public readonly runtimePlatform: BuildRuntimePlatform;\n public readonly baseLogger: bunyan;\n private didCheckOut = false;\n private _hasAnyPreviousStepFailed = false;\n private stepById: Record<string, BuildStepOutputAccessor> = {};\n\n constructor(\n private readonly provider: ExternalBuildContextProvider,\n public readonly skipCleanup: boolean\n ) {\n this.stepsInternalBuildDirectory = path.join(os.tmpdir(), 'eas-build', uuidv4());\n this.runtimePlatform = provider.runtimePlatform;\n this.baseLogger = provider.logger;\n this._hasAnyPreviousStepFailed = false;\n }\n\n public get projectSourceDirectory(): string {\n return this.provider.projectSourceDirectory;\n }\n\n public get projectTargetDirectory(): string {\n return this.provider.projectTargetDirectory;\n }\n\n public get defaultWorkingDirectory(): string {\n return this.didCheckOut ? this.provider.defaultWorkingDirectory : this.projectTargetDirectory;\n }\n\n public get buildLogsDirectory(): string {\n return this.provider.buildLogsDirectory;\n }\n\n public get env(): BuildStepEnv {\n return this.provider.env;\n }\n\n public get staticContext(): StaticJobInterpolationContext {\n return {\n ...this.provider.staticContext(),\n steps: Object.fromEntries(\n Object.values(this.stepById).map((step) => [\n step.id,\n {\n outputs: Object.fromEntries(\n step.outputs.map((output) => {\n return [output.id, output.rawValue];\n })\n ),\n },\n ])\n ),\n };\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 getInterpolationContext(): JobInterpolationContext {\n const hasAnyPreviousStepFailed = this.hasAnyPreviousStepFailed;\n\n return {\n ...this.staticContext,\n always: () => true,\n never: () => false,\n success: () => !hasAnyPreviousStepFailed,\n failure: () => hasAnyPreviousStepFailed,\n env: this.env as Env,\n fromJSON: (json: string) => JSON.parse(json),\n toJSON: (value: unknown) => JSON.stringify(value),\n contains: (value, substring) => value.includes(substring),\n startsWith: (value, prefix) => value.startsWith(prefix),\n endsWith: (value, suffix) => value.endsWith(suffix),\n hashFiles: (...patterns: string[]) => this.hashFiles(...patterns),\n replaceAll: (input: string, stringToReplace: string, replacementString: string) => {\n while (input.includes(stringToReplace)) {\n input = input.replace(stringToReplace, replacementString);\n }\n return input;\n },\n };\n }\n\n public interpolate<InterpolableType extends string | object>(\n value: InterpolableType\n ): InterpolableType {\n return interpolateWithGlobalContext(value, (path) => {\n return (\n getObjectValueForInterpolation(path, {\n eas: {\n runtimePlatform: this.runtimePlatform,\n ...this.staticContext,\n env: this.env,\n },\n })?.toString() ?? ''\n );\n });\n }\n\n public stepCtx(options: { logger: bunyan; relativeWorkingDirectory?: string }): BuildStepContext {\n return new BuildStepContext(this, options);\n }\n\n public markAsCheckedOut(logger: bunyan): void {\n this.didCheckOut = true;\n logger.info(\n `Changing default working directory to ${this.defaultWorkingDirectory} (was ${this.projectTargetDirectory})`\n );\n }\n\n public get hasAnyPreviousStepFailed(): boolean {\n return this._hasAnyPreviousStepFailed;\n }\n\n public markAsFailed(): void {\n this._hasAnyPreviousStepFailed = true;\n }\n\n public wasCheckedOut(): boolean {\n return this.didCheckOut;\n }\n\n public hashFiles(...patterns: string[]): string {\n const cwd = this.defaultWorkingDirectory;\n const workspacePath = path.resolve(cwd);\n\n // Use glob to find matching files across all patterns\n const filePaths = fg.sync(patterns, {\n cwd,\n absolute: true,\n onlyFiles: true,\n });\n\n if (filePaths.length === 0) {\n return '';\n }\n\n const validFilePaths = filePaths.filter((file) =>\n file.startsWith(`${workspacePath}${path.sep}`)\n );\n\n if (validFilePaths.length === 0) {\n return '';\n }\n\n return hashFiles(validFilePaths);\n }\n\n public serialize(): SerializedBuildStepGlobalContext {\n return {\n stepsInternalBuildDirectory: this.stepsInternalBuildDirectory,\n stepById: Object.fromEntries(\n Object.entries(this.stepById).map(([id, step]) => [id, step.serialize()])\n ),\n provider: {\n projectSourceDirectory: this.provider.projectSourceDirectory,\n projectTargetDirectory: this.provider.projectTargetDirectory,\n defaultWorkingDirectory: this.provider.defaultWorkingDirectory,\n buildLogsDirectory: this.provider.buildLogsDirectory,\n runtimePlatform: this.provider.runtimePlatform,\n staticContext: this.provider.staticContext(),\n env: this.provider.env,\n },\n skipCleanup: this.skipCleanup,\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepGlobalContext,\n logger: bunyan\n ): BuildStepGlobalContext {\n const deserializedProvider: ExternalBuildContextProvider = {\n projectSourceDirectory: serialized.provider.projectSourceDirectory,\n projectTargetDirectory: serialized.provider.projectTargetDirectory,\n defaultWorkingDirectory: serialized.provider.defaultWorkingDirectory,\n buildLogsDirectory: serialized.provider.buildLogsDirectory,\n runtimePlatform: serialized.provider.runtimePlatform,\n logger,\n staticContext: () => serialized.provider.staticContext,\n env: serialized.provider.env,\n updateEnv: () => {},\n };\n const ctx = new BuildStepGlobalContext(deserializedProvider, serialized.skipCleanup);\n for (const [id, stepOutputAccessor] of Object.entries(serialized.stepById)) {\n ctx.stepById[id] = BuildStepOutputAccessor.deserialize(stepOutputAccessor);\n }\n ctx.stepsInternalBuildDirectory = serialized.stepsInternalBuildDirectory;\n\n return ctx;\n }\n}\n\nexport interface SerializedBuildStepContext {\n relativeWorkingDirectory?: string;\n global: SerializedBuildStepGlobalContext;\n}\n\nexport class BuildStepContext {\n public readonly logger: bunyan;\n public readonly relativeWorkingDirectory?: string;\n\n constructor(\n private readonly ctx: BuildStepGlobalContext,\n {\n logger,\n relativeWorkingDirectory,\n }: {\n logger: bunyan;\n relativeWorkingDirectory?: string;\n }\n ) {\n this.logger = logger ?? ctx.baseLogger;\n this.relativeWorkingDirectory = relativeWorkingDirectory;\n }\n\n public get global(): BuildStepGlobalContext {\n return this.ctx;\n }\n\n public get workingDirectory(): string {\n if (!this.relativeWorkingDirectory) {\n return this.ctx.defaultWorkingDirectory;\n }\n\n if (path.isAbsolute(this.relativeWorkingDirectory)) {\n return path.join(this.ctx.projectTargetDirectory, this.relativeWorkingDirectory);\n }\n\n return path.join(this.ctx.defaultWorkingDirectory, this.relativeWorkingDirectory);\n }\n\n public serialize(): SerializedBuildStepContext {\n return {\n relativeWorkingDirectory: this.relativeWorkingDirectory,\n global: this.ctx.serialize(),\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepContext,\n logger: bunyan\n ): BuildStepContext {\n const deserializedGlobal = BuildStepGlobalContext.deserialize(serialized.global, logger);\n return new BuildStepContext(deserializedGlobal, {\n logger,\n relativeWorkingDirectory: serialized.relativeWorkingDirectory,\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BuildStepContext.js","sourceRoot":"","sources":["../src/BuildStepContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,MAAM,WAAW,CAAC;AAG3B,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAEL,uBAAuB,GAExB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,EAC5B,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAoCpD,MAAM,OAAO,sBAAsB;IAQjC,YACmB,QAAsC,EACvC,WAAoB;QADnB,aAAQ,GAAR,QAAQ,CAA8B;QACvC,gBAAW,GAAX,WAAW,CAAS;QAN9B,gBAAW,GAAG,KAAK,CAAC;QACpB,8BAAyB,GAAG,KAAK,CAAC;QAClC,aAAQ,GAA4C,EAAE,CAAC;QAM7D,IAAI,CAAC,2BAA2B,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,WAAW,E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BAAkB,EAAE;YAC9C,MAAM;YACN,wBAAwB,EAAE,UAAU,CAAC,wBAAwB;SAC9D,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import os from 'os';\nimport path from 'path';\n\nimport fg from 'fast-glob';\nimport { Env, JobInterpolationContext, StaticJobInterpolationContext } from '@expo/eas-build-job';\nimport { bunyan } from '@expo/logger';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { hashFiles } from './utils/hashFiles.js';\nimport {\n BuildStep,\n BuildStepOutputAccessor,\n SerializedBuildStepOutputAccessor,\n} from './BuildStep.js';\nimport {\n getObjectValueForInterpolation,\n interpolateWithGlobalContext,\n parseOutputPath,\n} from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\n\ninterface SerializedExternalBuildContextProvider {\n projectSourceDirectory: string;\n projectTargetDirectory: string;\n defaultWorkingDirectory: string;\n buildLogsDirectory: string;\n runtimePlatform: BuildRuntimePlatform;\n // We omit steps, because they should be calculated live based on global context.\n staticContext: Omit<StaticJobInterpolationContext, 'steps'>;\n env: BuildStepEnv;\n}\n\nexport interface ExternalBuildContextProvider {\n readonly projectSourceDirectory: string;\n readonly projectTargetDirectory: string;\n readonly defaultWorkingDirectory: string;\n readonly buildLogsDirectory: string;\n readonly runtimePlatform: BuildRuntimePlatform;\n readonly logger: bunyan;\n\n readonly staticContext: () => Omit<StaticJobInterpolationContext, 'steps'>;\n\n readonly env: BuildStepEnv;\n updateEnv(env: BuildStepEnv): void;\n}\n\nexport interface SerializedBuildStepGlobalContext {\n stepsInternalBuildDirectory: string;\n stepById: Record<string, SerializedBuildStepOutputAccessor>;\n provider: SerializedExternalBuildContextProvider;\n skipCleanup: boolean;\n}\n\nexport class BuildStepGlobalContext {\n public stepsInternalBuildDirectory: string;\n public readonly runtimePlatform: BuildRuntimePlatform;\n public readonly baseLogger: bunyan;\n private didCheckOut = false;\n private _hasAnyPreviousStepFailed = false;\n private stepById: Record<string, BuildStepOutputAccessor> = {};\n\n constructor(\n private readonly provider: ExternalBuildContextProvider,\n public readonly skipCleanup: boolean\n ) {\n this.stepsInternalBuildDirectory = path.join(os.tmpdir(), 'eas-build', uuidv4());\n this.runtimePlatform = provider.runtimePlatform;\n this.baseLogger = provider.logger;\n this._hasAnyPreviousStepFailed = false;\n }\n\n public get projectSourceDirectory(): string {\n return this.provider.projectSourceDirectory;\n }\n\n public get projectTargetDirectory(): string {\n return this.provider.projectTargetDirectory;\n }\n\n public get defaultWorkingDirectory(): string {\n return this.didCheckOut ? this.provider.defaultWorkingDirectory : this.projectTargetDirectory;\n }\n\n public get buildLogsDirectory(): string {\n return this.provider.buildLogsDirectory;\n }\n\n public get env(): BuildStepEnv {\n return this.provider.env;\n }\n\n public get staticContext(): StaticJobInterpolationContext {\n return {\n ...this.provider.staticContext(),\n steps: Object.fromEntries(\n Object.values(this.stepById).map((step) => [\n step.id,\n {\n outputs: Object.fromEntries(\n step.outputs.map((output) => {\n return [output.id, output.rawValue];\n })\n ),\n },\n ])\n ),\n };\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 getInterpolationContext(): JobInterpolationContext {\n const hasAnyPreviousStepFailed = this.hasAnyPreviousStepFailed;\n\n return {\n ...this.staticContext,\n always: () => true,\n never: () => false,\n success: () => !hasAnyPreviousStepFailed,\n failure: () => hasAnyPreviousStepFailed,\n env: this.env as Env,\n fromJSON: (json: string) => JSON.parse(json),\n toJSON: (value: unknown) => JSON.stringify(value),\n contains: (value, substring) => value.includes(substring),\n startsWith: (value, prefix) => value.startsWith(prefix),\n endsWith: (value, suffix) => value.endsWith(suffix),\n hashFiles: (...patterns: string[]) => this.hashFiles(...patterns),\n replaceAll: (input: string, stringToReplace: string, replacementString: string) => {\n while (input.includes(stringToReplace)) {\n input = input.replace(stringToReplace, replacementString);\n }\n return input;\n },\n substring: (input: string, start: number, end?: number) => input.substring(start, end),\n };\n }\n\n public interpolate<InterpolableType extends string | object>(\n value: InterpolableType\n ): InterpolableType {\n return interpolateWithGlobalContext(value, (path) => {\n return (\n getObjectValueForInterpolation(path, {\n eas: {\n runtimePlatform: this.runtimePlatform,\n ...this.staticContext,\n env: this.env,\n },\n })?.toString() ?? ''\n );\n });\n }\n\n public stepCtx(options: { logger: bunyan; relativeWorkingDirectory?: string }): BuildStepContext {\n return new BuildStepContext(this, options);\n }\n\n public markAsCheckedOut(logger: bunyan): void {\n this.didCheckOut = true;\n logger.info(\n `Changing default working directory to ${this.defaultWorkingDirectory} (was ${this.projectTargetDirectory})`\n );\n }\n\n public get hasAnyPreviousStepFailed(): boolean {\n return this._hasAnyPreviousStepFailed;\n }\n\n public markAsFailed(): void {\n this._hasAnyPreviousStepFailed = true;\n }\n\n public wasCheckedOut(): boolean {\n return this.didCheckOut;\n }\n\n public hashFiles(...patterns: string[]): string {\n const cwd = this.defaultWorkingDirectory;\n const workspacePath = path.resolve(cwd);\n\n // Use glob to find matching files across all patterns\n const filePaths = fg.sync(patterns, {\n cwd,\n absolute: true,\n onlyFiles: true,\n });\n\n if (filePaths.length === 0) {\n return '';\n }\n\n const validFilePaths = filePaths.filter((file) =>\n file.startsWith(`${workspacePath}${path.sep}`)\n );\n\n if (validFilePaths.length === 0) {\n return '';\n }\n\n return hashFiles(validFilePaths);\n }\n\n public serialize(): SerializedBuildStepGlobalContext {\n return {\n stepsInternalBuildDirectory: this.stepsInternalBuildDirectory,\n stepById: Object.fromEntries(\n Object.entries(this.stepById).map(([id, step]) => [id, step.serialize()])\n ),\n provider: {\n projectSourceDirectory: this.provider.projectSourceDirectory,\n projectTargetDirectory: this.provider.projectTargetDirectory,\n defaultWorkingDirectory: this.provider.defaultWorkingDirectory,\n buildLogsDirectory: this.provider.buildLogsDirectory,\n runtimePlatform: this.provider.runtimePlatform,\n staticContext: this.provider.staticContext(),\n env: this.provider.env,\n },\n skipCleanup: this.skipCleanup,\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepGlobalContext,\n logger: bunyan\n ): BuildStepGlobalContext {\n const deserializedProvider: ExternalBuildContextProvider = {\n projectSourceDirectory: serialized.provider.projectSourceDirectory,\n projectTargetDirectory: serialized.provider.projectTargetDirectory,\n defaultWorkingDirectory: serialized.provider.defaultWorkingDirectory,\n buildLogsDirectory: serialized.provider.buildLogsDirectory,\n runtimePlatform: serialized.provider.runtimePlatform,\n logger,\n staticContext: () => serialized.provider.staticContext,\n env: serialized.provider.env,\n updateEnv: () => {},\n };\n const ctx = new BuildStepGlobalContext(deserializedProvider, serialized.skipCleanup);\n for (const [id, stepOutputAccessor] of Object.entries(serialized.stepById)) {\n ctx.stepById[id] = BuildStepOutputAccessor.deserialize(stepOutputAccessor);\n }\n ctx.stepsInternalBuildDirectory = serialized.stepsInternalBuildDirectory;\n\n return ctx;\n }\n}\n\nexport interface SerializedBuildStepContext {\n relativeWorkingDirectory?: string;\n global: SerializedBuildStepGlobalContext;\n}\n\nexport class BuildStepContext {\n public readonly logger: bunyan;\n public readonly relativeWorkingDirectory?: string;\n\n constructor(\n private readonly ctx: BuildStepGlobalContext,\n {\n logger,\n relativeWorkingDirectory,\n }: {\n logger: bunyan;\n relativeWorkingDirectory?: string;\n }\n ) {\n this.logger = logger ?? ctx.baseLogger;\n this.relativeWorkingDirectory = relativeWorkingDirectory;\n }\n\n public get global(): BuildStepGlobalContext {\n return this.ctx;\n }\n\n public get workingDirectory(): string {\n if (!this.relativeWorkingDirectory) {\n return this.ctx.defaultWorkingDirectory;\n }\n\n if (path.isAbsolute(this.relativeWorkingDirectory)) {\n return path.join(this.ctx.projectTargetDirectory, this.relativeWorkingDirectory);\n }\n\n return path.join(this.ctx.defaultWorkingDirectory, this.relativeWorkingDirectory);\n }\n\n public serialize(): SerializedBuildStepContext {\n return {\n relativeWorkingDirectory: this.relativeWorkingDirectory,\n global: this.ctx.serialize(),\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepContext,\n logger: bunyan\n ): BuildStepContext {\n const deserializedGlobal = BuildStepGlobalContext.deserialize(serialized.global, logger);\n return new BuildStepContext(deserializedGlobal, {\n logger,\n relativeWorkingDirectory: serialized.relativeWorkingDirectory,\n });\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/steps",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.252",
|
|
5
5
|
"main": "./dist_commonjs/index.cjs",
|
|
6
6
|
"types": "./dist_esm/index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"node": ">=18"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@expo/eas-build-job": "1.0.
|
|
51
|
+
"@expo/eas-build-job": "1.0.252",
|
|
52
52
|
"@expo/logger": "1.0.221",
|
|
53
53
|
"@expo/spawn-async": "^1.7.2",
|
|
54
54
|
"arg": "^5.0.2",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"node": "20.14.0",
|
|
66
66
|
"yarn": "1.22.21"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "f729d1ec839100ebfdb45a05b63bf58b6800247b"
|
|
69
69
|
}
|