@expo/steps 1.0.231 → 1.0.237
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist_commonjs/BuildStepContext.cjs +38 -0
- package/dist_commonjs/BuildStepContext.d.ts +1 -0
- package/dist_commonjs/BuildStepContext.js.map +1 -1
- package/dist_esm/BuildStepContext.d.ts +1 -0
- package/dist_esm/BuildStepContext.js +38 -0
- package/dist_esm/BuildStepContext.js.map +1 -1
- package/package.json +3 -3
|
@@ -6,6 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.BuildStepContext = exports.BuildStepGlobalContext = void 0;
|
|
7
7
|
const os_1 = __importDefault(require("os"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
9
12
|
const uuid_1 = require("uuid");
|
|
10
13
|
const BuildStep_js_1 = require("./BuildStep.cjs");
|
|
11
14
|
const template_js_1 = require("./utils/template.cjs");
|
|
@@ -77,6 +80,7 @@ class BuildStepGlobalContext {
|
|
|
77
80
|
contains: (value, substring) => value.includes(substring),
|
|
78
81
|
startsWith: (value, prefix) => value.startsWith(prefix),
|
|
79
82
|
endsWith: (value, suffix) => value.endsWith(suffix),
|
|
83
|
+
hashFiles: (...patterns) => this.hashFiles(...patterns),
|
|
80
84
|
};
|
|
81
85
|
}
|
|
82
86
|
interpolate(value) {
|
|
@@ -107,6 +111,40 @@ class BuildStepGlobalContext {
|
|
|
107
111
|
wasCheckedOut() {
|
|
108
112
|
return this.didCheckOut;
|
|
109
113
|
}
|
|
114
|
+
hashFiles(...patterns) {
|
|
115
|
+
const cwd = this.defaultWorkingDirectory;
|
|
116
|
+
const workspacePath = path_1.default.resolve(cwd);
|
|
117
|
+
// Use glob to find matching files across all patterns
|
|
118
|
+
const filePaths = fast_glob_1.default.sync(patterns, {
|
|
119
|
+
cwd,
|
|
120
|
+
absolute: true,
|
|
121
|
+
});
|
|
122
|
+
if (filePaths.length === 0) {
|
|
123
|
+
return '';
|
|
124
|
+
}
|
|
125
|
+
const result = crypto_1.default.createHash('sha256');
|
|
126
|
+
let fileFound = false;
|
|
127
|
+
for (const file of filePaths) {
|
|
128
|
+
if (!file.startsWith(`${workspacePath}${path_1.default.sep}`)) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (fs_1.default.statSync(file).isDirectory()) {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const fileHash = crypto_1.default.createHash('sha256');
|
|
135
|
+
const fileContent = fs_1.default.readFileSync(file);
|
|
136
|
+
fileHash.update(fileContent);
|
|
137
|
+
result.write(fileHash.digest());
|
|
138
|
+
fileFound = true;
|
|
139
|
+
}
|
|
140
|
+
result.end();
|
|
141
|
+
if (fileFound) {
|
|
142
|
+
return result.digest('hex');
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
return '';
|
|
146
|
+
}
|
|
147
|
+
}
|
|
110
148
|
serialize() {
|
|
111
149
|
return {
|
|
112
150
|
stepsInternalBuildDirectory: this.stepsInternalBuildDirectory,
|
|
@@ -58,6 +58,7 @@ export declare class BuildStepGlobalContext {
|
|
|
58
58
|
get hasAnyPreviousStepFailed(): boolean;
|
|
59
59
|
markAsFailed(): void;
|
|
60
60
|
wasCheckedOut(): boolean;
|
|
61
|
+
hashFiles(...patterns: string[]): string;
|
|
61
62
|
serialize(): SerializedBuildStepGlobalContext;
|
|
62
63
|
static deserialize(serialized: SerializedBuildStepGlobalContext, logger: bunyan): BuildStepGlobalContext;
|
|
63
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildStepContext.js","sourceRoot":"","sources":["../src/BuildStepContext.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAIxB,+BAAoC;AAEpC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F,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 { Env, JobInterpolationContext, StaticJobInterpolationContext } from '@expo/eas-build-job';\nimport { bunyan } from '@expo/logger';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport {\n BuildStep,\n BuildStepOutputAccessor,\n SerializedBuildStepOutputAccessor,\n} from './BuildStep.js';\nimport {\n getObjectValueForInterpolation,\n interpolateWithGlobalContext,\n parseOutputPath,\n} from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\n\ninterface SerializedExternalBuildContextProvider {\n projectSourceDirectory: string;\n projectTargetDirectory: string;\n defaultWorkingDirectory: string;\n buildLogsDirectory: string;\n runtimePlatform: BuildRuntimePlatform;\n // 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 };\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 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;AACxB,oDAA4B;AAC5B,4CAAoB;AAEpB,0DAA2B;AAG3B,+BAAoC;AAEpC,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;QA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';\nimport { Env, JobInterpolationContext, StaticJobInterpolationContext } from '@expo/eas-build-job';\nimport { bunyan } from '@expo/logger';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport {\n BuildStep,\n BuildStepOutputAccessor,\n SerializedBuildStepOutputAccessor,\n} from './BuildStep.js';\nimport {\n getObjectValueForInterpolation,\n interpolateWithGlobalContext,\n parseOutputPath,\n} from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\n\ninterface SerializedExternalBuildContextProvider {\n projectSourceDirectory: string;\n projectTargetDirectory: string;\n defaultWorkingDirectory: string;\n buildLogsDirectory: string;\n runtimePlatform: BuildRuntimePlatform;\n // 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 };\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 });\n\n if (filePaths.length === 0) {\n return '';\n }\n\n const result = crypto.createHash('sha256');\n let fileFound = false;\n\n for (const file of filePaths) {\n if (!file.startsWith(`${workspacePath}${path.sep}`)) {\n continue;\n }\n\n if (fs.statSync(file).isDirectory()) {\n continue;\n }\n\n const fileHash = crypto.createHash('sha256');\n const fileContent = fs.readFileSync(file);\n fileHash.update(fileContent);\n result.write(fileHash.digest());\n fileFound = true;\n }\n\n result.end();\n\n if (fileFound) {\n return result.digest('hex');\n } else {\n return '';\n }\n }\n\n public serialize(): SerializedBuildStepGlobalContext {\n return {\n stepsInternalBuildDirectory: this.stepsInternalBuildDirectory,\n stepById: Object.fromEntries(\n Object.entries(this.stepById).map(([id, step]) => [id, step.serialize()])\n ),\n provider: {\n projectSourceDirectory: this.provider.projectSourceDirectory,\n projectTargetDirectory: this.provider.projectTargetDirectory,\n defaultWorkingDirectory: this.provider.defaultWorkingDirectory,\n buildLogsDirectory: this.provider.buildLogsDirectory,\n runtimePlatform: this.provider.runtimePlatform,\n staticContext: this.provider.staticContext(),\n env: this.provider.env,\n },\n skipCleanup: this.skipCleanup,\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepGlobalContext,\n logger: bunyan\n ): BuildStepGlobalContext {\n const deserializedProvider: ExternalBuildContextProvider = {\n projectSourceDirectory: serialized.provider.projectSourceDirectory,\n projectTargetDirectory: serialized.provider.projectTargetDirectory,\n defaultWorkingDirectory: serialized.provider.defaultWorkingDirectory,\n buildLogsDirectory: serialized.provider.buildLogsDirectory,\n runtimePlatform: serialized.provider.runtimePlatform,\n logger,\n staticContext: () => serialized.provider.staticContext,\n env: serialized.provider.env,\n updateEnv: () => {},\n };\n const ctx = new BuildStepGlobalContext(deserializedProvider, serialized.skipCleanup);\n for (const [id, stepOutputAccessor] of Object.entries(serialized.stepById)) {\n ctx.stepById[id] = BuildStepOutputAccessor.deserialize(stepOutputAccessor);\n }\n ctx.stepsInternalBuildDirectory = serialized.stepsInternalBuildDirectory;\n\n return ctx;\n }\n}\n\nexport interface SerializedBuildStepContext {\n relativeWorkingDirectory?: string;\n global: SerializedBuildStepGlobalContext;\n}\n\nexport class BuildStepContext {\n public readonly logger: bunyan;\n public readonly relativeWorkingDirectory?: string;\n\n constructor(\n private readonly ctx: BuildStepGlobalContext,\n {\n logger,\n relativeWorkingDirectory,\n }: {\n logger: bunyan;\n relativeWorkingDirectory?: string;\n }\n ) {\n this.logger = logger ?? ctx.baseLogger;\n this.relativeWorkingDirectory = relativeWorkingDirectory;\n }\n\n public get global(): BuildStepGlobalContext {\n return this.ctx;\n }\n\n public get workingDirectory(): string {\n 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"]}
|
|
@@ -58,6 +58,7 @@ export declare class BuildStepGlobalContext {
|
|
|
58
58
|
get hasAnyPreviousStepFailed(): boolean;
|
|
59
59
|
markAsFailed(): void;
|
|
60
60
|
wasCheckedOut(): boolean;
|
|
61
|
+
hashFiles(...patterns: string[]): string;
|
|
61
62
|
serialize(): SerializedBuildStepGlobalContext;
|
|
62
63
|
static deserialize(serialized: SerializedBuildStepGlobalContext, logger: bunyan): BuildStepGlobalContext;
|
|
63
64
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import os from 'os';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import crypto from 'crypto';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import fg from 'fast-glob';
|
|
3
6
|
import { v4 as uuidv4 } from 'uuid';
|
|
4
7
|
import { BuildStepOutputAccessor, } from './BuildStep.js';
|
|
5
8
|
import { getObjectValueForInterpolation, interpolateWithGlobalContext, parseOutputPath, } from './utils/template.js';
|
|
@@ -71,6 +74,7 @@ export class BuildStepGlobalContext {
|
|
|
71
74
|
contains: (value, substring) => value.includes(substring),
|
|
72
75
|
startsWith: (value, prefix) => value.startsWith(prefix),
|
|
73
76
|
endsWith: (value, suffix) => value.endsWith(suffix),
|
|
77
|
+
hashFiles: (...patterns) => this.hashFiles(...patterns),
|
|
74
78
|
};
|
|
75
79
|
}
|
|
76
80
|
interpolate(value) {
|
|
@@ -101,6 +105,40 @@ export class BuildStepGlobalContext {
|
|
|
101
105
|
wasCheckedOut() {
|
|
102
106
|
return this.didCheckOut;
|
|
103
107
|
}
|
|
108
|
+
hashFiles(...patterns) {
|
|
109
|
+
const cwd = this.defaultWorkingDirectory;
|
|
110
|
+
const workspacePath = path.resolve(cwd);
|
|
111
|
+
// Use glob to find matching files across all patterns
|
|
112
|
+
const filePaths = fg.sync(patterns, {
|
|
113
|
+
cwd,
|
|
114
|
+
absolute: true,
|
|
115
|
+
});
|
|
116
|
+
if (filePaths.length === 0) {
|
|
117
|
+
return '';
|
|
118
|
+
}
|
|
119
|
+
const result = crypto.createHash('sha256');
|
|
120
|
+
let fileFound = false;
|
|
121
|
+
for (const file of filePaths) {
|
|
122
|
+
if (!file.startsWith(`${workspacePath}${path.sep}`)) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (fs.statSync(file).isDirectory()) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const fileHash = crypto.createHash('sha256');
|
|
129
|
+
const fileContent = fs.readFileSync(file);
|
|
130
|
+
fileHash.update(fileContent);
|
|
131
|
+
result.write(fileHash.digest());
|
|
132
|
+
fileFound = true;
|
|
133
|
+
}
|
|
134
|
+
result.end();
|
|
135
|
+
if (fileFound) {
|
|
136
|
+
return result.digest('hex');
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
return '';
|
|
140
|
+
}
|
|
141
|
+
}
|
|
104
142
|
serialize() {
|
|
105
143
|
return {
|
|
106
144
|
stepsInternalBuildDirectory: this.stepsInternalBuildDirectory,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BuildStepContext.js","sourceRoot":"","sources":["../src/BuildStepContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAEL,uBAAuB,GAExB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,EAC5B,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAA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,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","sourcesContent":["import os from 'os';\nimport path from 'path';\n\nimport { Env, JobInterpolationContext, StaticJobInterpolationContext } from '@expo/eas-build-job';\nimport { bunyan } from '@expo/logger';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport {\n BuildStep,\n BuildStepOutputAccessor,\n SerializedBuildStepOutputAccessor,\n} from './BuildStep.js';\nimport {\n getObjectValueForInterpolation,\n interpolateWithGlobalContext,\n parseOutputPath,\n} from './utils/template.js';\nimport { BuildStepRuntimeError } from './errors.js';\nimport { BuildRuntimePlatform } from './BuildRuntimePlatform.js';\nimport { BuildStepEnv } from './BuildStepEnv.js';\n\ninterface SerializedExternalBuildContextProvider {\n projectSourceDirectory: string;\n projectTargetDirectory: string;\n defaultWorkingDirectory: string;\n buildLogsDirectory: string;\n runtimePlatform: BuildRuntimePlatform;\n // 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 };\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 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;AACxB,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,MAAM,WAAW,CAAC;AAG3B,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,EAEL,uBAAuB,GAExB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,EAC5B,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;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,EAAE,MAAM,EAAE,CAAC,CAAC;QACjF,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC,eAAe,CAAC;QAChD,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC;QAClC,IAAI,CAAC,yBAAyB,GA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AAE;YAC9C,MAAM;YACN,wBAAwB,EAAE,UAAU,CAAC,wBAAwB;SAC9D,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import os from 'os';\nimport path from 'path';\nimport crypto from 'crypto';\nimport fs from 'fs';\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 {\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 };\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 });\n\n if (filePaths.length === 0) {\n return '';\n }\n\n const result = crypto.createHash('sha256');\n let fileFound = false;\n\n for (const file of filePaths) {\n if (!file.startsWith(`${workspacePath}${path.sep}`)) {\n continue;\n }\n\n if (fs.statSync(file).isDirectory()) {\n continue;\n }\n\n const fileHash = crypto.createHash('sha256');\n const fileContent = fs.readFileSync(file);\n fileHash.update(fileContent);\n result.write(fileHash.digest());\n fileFound = true;\n }\n\n result.end();\n\n if (fileFound) {\n return result.digest('hex');\n } else {\n return '';\n }\n }\n\n public serialize(): SerializedBuildStepGlobalContext {\n return {\n stepsInternalBuildDirectory: this.stepsInternalBuildDirectory,\n stepById: Object.fromEntries(\n Object.entries(this.stepById).map(([id, step]) => [id, step.serialize()])\n ),\n provider: {\n projectSourceDirectory: this.provider.projectSourceDirectory,\n projectTargetDirectory: this.provider.projectTargetDirectory,\n defaultWorkingDirectory: this.provider.defaultWorkingDirectory,\n buildLogsDirectory: this.provider.buildLogsDirectory,\n runtimePlatform: this.provider.runtimePlatform,\n staticContext: this.provider.staticContext(),\n env: this.provider.env,\n },\n skipCleanup: this.skipCleanup,\n };\n }\n\n public static deserialize(\n serialized: SerializedBuildStepGlobalContext,\n logger: bunyan\n ): BuildStepGlobalContext {\n const deserializedProvider: ExternalBuildContextProvider = {\n projectSourceDirectory: serialized.provider.projectSourceDirectory,\n projectTargetDirectory: serialized.provider.projectTargetDirectory,\n defaultWorkingDirectory: serialized.provider.defaultWorkingDirectory,\n buildLogsDirectory: serialized.provider.buildLogsDirectory,\n runtimePlatform: serialized.provider.runtimePlatform,\n logger,\n staticContext: () => serialized.provider.staticContext,\n env: serialized.provider.env,\n updateEnv: () => {},\n };\n const ctx = new BuildStepGlobalContext(deserializedProvider, serialized.skipCleanup);\n for (const [id, stepOutputAccessor] of Object.entries(serialized.stepById)) {\n ctx.stepById[id] = BuildStepOutputAccessor.deserialize(stepOutputAccessor);\n }\n ctx.stepsInternalBuildDirectory = serialized.stepsInternalBuildDirectory;\n\n return ctx;\n }\n}\n\nexport interface SerializedBuildStepContext {\n relativeWorkingDirectory?: string;\n global: SerializedBuildStepGlobalContext;\n}\n\nexport class BuildStepContext {\n public readonly logger: bunyan;\n public readonly relativeWorkingDirectory?: string;\n\n constructor(\n private readonly ctx: BuildStepGlobalContext,\n {\n logger,\n relativeWorkingDirectory,\n }: {\n logger: bunyan;\n relativeWorkingDirectory?: string;\n }\n ) {\n this.logger = logger ?? ctx.baseLogger;\n this.relativeWorkingDirectory = relativeWorkingDirectory;\n }\n\n public get global(): BuildStepGlobalContext {\n return this.ctx;\n }\n\n public get workingDirectory(): string {\n 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.237",
|
|
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.237",
|
|
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": "e971053c153f22c261478c05290b019de0017641"
|
|
69
69
|
}
|